You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

202 lines
7.3KB

  1. /*
  2. * DSP utils
  3. * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
  4. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  5. *
  6. * This file is part of Libav.
  7. *
  8. * Libav is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * Libav is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with Libav; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. /**
  23. * @file
  24. * DSP utils.
  25. * Note, many functions in here may use MMX which trashes the FPU state, it is
  26. * absolutely necessary to call emms_c() between DSP & float/double code.
  27. */
  28. #ifndef AVCODEC_DSPUTIL_H
  29. #define AVCODEC_DSPUTIL_H
  30. #include "avcodec.h"
  31. extern uint32_t ff_square_tab[512];
  32. void ff_gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
  33. int dxx, int dxy, int dyx, int dyy, int shift, int r,
  34. int width, int height);
  35. struct MpegEncContext;
  36. /* Motion estimation:
  37. * h is limited to { width / 2, width, 2 * width },
  38. * but never larger than 16 and never smaller than 2.
  39. * Although currently h < 4 is not used as functions with
  40. * width < 8 are neither used nor implemented. */
  41. typedef int (*me_cmp_func)(struct MpegEncContext *c,
  42. uint8_t *blk1 /* align width (8 or 16) */,
  43. uint8_t *blk2 /* align 1 */, int line_size, int h);
  44. /**
  45. * Scantable.
  46. */
  47. typedef struct ScanTable {
  48. const uint8_t *scantable;
  49. uint8_t permutated[64];
  50. uint8_t raster_end[64];
  51. } ScanTable;
  52. void ff_init_scantable(uint8_t *permutation, ScanTable *st,
  53. const uint8_t *src_scantable);
  54. void ff_init_scantable_permutation(uint8_t *idct_permutation,
  55. int idct_permutation_type);
  56. /**
  57. * DSPContext.
  58. */
  59. typedef struct DSPContext {
  60. /* pixel ops : interface with DCT */
  61. void (*get_pixels)(int16_t *block /* align 16 */,
  62. const uint8_t *pixels /* align 8 */,
  63. int line_size);
  64. void (*diff_pixels)(int16_t *block /* align 16 */,
  65. const uint8_t *s1 /* align 8 */,
  66. const uint8_t *s2 /* align 8 */,
  67. int stride);
  68. void (*put_pixels_clamped)(const int16_t *block /* align 16 */,
  69. uint8_t *pixels /* align 8 */,
  70. int line_size);
  71. void (*put_signed_pixels_clamped)(const int16_t *block /* align 16 */,
  72. uint8_t *pixels /* align 8 */,
  73. int line_size);
  74. void (*add_pixels_clamped)(const int16_t *block /* align 16 */,
  75. uint8_t *pixels /* align 8 */,
  76. int line_size);
  77. int (*sum_abs_dctelem)(int16_t *block /* align 16 */);
  78. /**
  79. * translational global motion compensation.
  80. */
  81. void (*gmc1)(uint8_t *dst /* align 8 */, uint8_t *src /* align 1 */,
  82. int srcStride, int h, int x16, int y16, int rounder);
  83. /**
  84. * global motion compensation.
  85. */
  86. void (*gmc)(uint8_t *dst /* align 8 */, uint8_t *src /* align 1 */,
  87. int stride, int h, int ox, int oy,
  88. int dxx, int dxy, int dyx, int dyy,
  89. int shift, int r, int width, int height);
  90. int (*pix_sum)(uint8_t *pix, int line_size);
  91. int (*pix_norm1)(uint8_t *pix, int line_size);
  92. me_cmp_func sad[6]; /* identical to pix_absAxA except additional void * */
  93. me_cmp_func sse[6];
  94. me_cmp_func hadamard8_diff[6];
  95. me_cmp_func dct_sad[6];
  96. me_cmp_func quant_psnr[6];
  97. me_cmp_func bit[6];
  98. me_cmp_func rd[6];
  99. me_cmp_func vsad[6];
  100. me_cmp_func vsse[6];
  101. me_cmp_func nsse[6];
  102. me_cmp_func dct_max[6];
  103. me_cmp_func dct264_sad[6];
  104. me_cmp_func me_pre_cmp[6];
  105. me_cmp_func me_cmp[6];
  106. me_cmp_func me_sub_cmp[6];
  107. me_cmp_func mb_cmp[6];
  108. me_cmp_func ildct_cmp[6]; // only width 16 used
  109. me_cmp_func frame_skip_cmp[6]; // only width 8 used
  110. me_cmp_func pix_abs[2][4];
  111. void (*bswap_buf)(uint32_t *dst, const uint32_t *src, int w);
  112. void (*bswap16_buf)(uint16_t *dst, const uint16_t *src, int len);
  113. /* (I)DCT */
  114. void (*fdct)(int16_t *block /* align 16 */);
  115. void (*fdct248)(int16_t *block /* align 16 */);
  116. /* IDCT really */
  117. void (*idct)(int16_t *block /* align 16 */);
  118. /**
  119. * block -> idct -> clip to unsigned 8 bit -> dest.
  120. * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...)
  121. * @param line_size size in bytes of a horizontal line of dest
  122. */
  123. void (*idct_put)(uint8_t *dest /* align 8 */,
  124. int line_size, int16_t *block /* align 16 */);
  125. /**
  126. * block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
  127. * @param line_size size in bytes of a horizontal line of dest
  128. */
  129. void (*idct_add)(uint8_t *dest /* align 8 */,
  130. int line_size, int16_t *block /* align 16 */);
  131. /**
  132. * IDCT input permutation.
  133. * Several optimized IDCTs need a permutated input (relative to the
  134. * normal order of the reference IDCT).
  135. * This permutation must be performed before the idct_put/add.
  136. * Note, normally this can be merged with the zigzag/alternate scan<br>
  137. * An example to avoid confusion:
  138. * - (->decode coeffs -> zigzag reorder -> dequant -> reference IDCT -> ...)
  139. * - (x -> reference DCT -> reference IDCT -> x)
  140. * - (x -> reference DCT -> simple_mmx_perm = idct_permutation
  141. * -> simple_idct_mmx -> x)
  142. * - (-> decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant
  143. * -> simple_idct_mmx -> ...)
  144. */
  145. uint8_t idct_permutation[64];
  146. int idct_permutation_type;
  147. #define FF_NO_IDCT_PERM 1
  148. #define FF_LIBMPEG2_IDCT_PERM 2
  149. #define FF_SIMPLE_IDCT_PERM 3
  150. #define FF_TRANSPOSE_IDCT_PERM 4
  151. #define FF_PARTTRANS_IDCT_PERM 5
  152. #define FF_SSE2_IDCT_PERM 6
  153. int (*try_8x8basis)(int16_t rem[64], int16_t weight[64],
  154. int16_t basis[64], int scale);
  155. void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale);
  156. #define BASIS_SHIFT 16
  157. #define RECON_SHIFT 6
  158. void (*draw_edges)(uint8_t *buf, int wrap, int width, int height,
  159. int w, int h, int sides);
  160. #define EDGE_WIDTH 16
  161. #define EDGE_TOP 1
  162. #define EDGE_BOTTOM 2
  163. void (*shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src,
  164. int src_wrap, int width, int height);
  165. } DSPContext;
  166. void ff_dsputil_static_init(void);
  167. void ff_dsputil_init(DSPContext *p, AVCodecContext *avctx);
  168. void ff_set_cmp(DSPContext *c, me_cmp_func *cmp, int type);
  169. void ff_dsputil_init_arm(DSPContext *c, AVCodecContext *avctx,
  170. unsigned high_bit_depth);
  171. void ff_dsputil_init_ppc(DSPContext *c, AVCodecContext *avctx,
  172. unsigned high_bit_depth);
  173. void ff_dsputil_init_x86(DSPContext *c, AVCodecContext *avctx,
  174. unsigned high_bit_depth);
  175. #endif /* AVCODEC_DSPUTIL_H */