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.

263 lines
9.9KB

  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 FFmpeg.
  7. *
  8. * FFmpeg 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. * FFmpeg 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 FFmpeg; 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. /* minimum alignment rules ;)
  36. * If you notice errors in the align stuff, need more alignment for some ASM code
  37. * for some CPU or need to use a function with less aligned data then send a mail
  38. * to the ffmpeg-devel mailing list, ...
  39. *
  40. * !warning These alignments might not match reality, (missing attribute((align))
  41. * stuff somewhere possible).
  42. * I (Michael) did not check them, these are just the alignments which I think
  43. * could be reached easily ...
  44. *
  45. * !future video codecs might need functions with less strict alignment
  46. */
  47. /* add and put pixel (decoding)
  48. * Block sizes for op_pixels_func are 8x4,8x8 16x8 16x16.
  49. * h for op_pixels_func is limited to { width / 2, width },
  50. * but never larger than 16 and never smaller than 4. */
  51. typedef void (*op_fill_func)(uint8_t *block /* align width (8 or 16) */,
  52. uint8_t value, int line_size, int h);
  53. struct MpegEncContext;
  54. /* Motion estimation:
  55. * h is limited to { width / 2, width, 2 * width },
  56. * but never larger than 16 and never smaller than 2.
  57. * Although currently h < 4 is not used as functions with
  58. * width < 8 are neither used nor implemented. */
  59. typedef int (*me_cmp_func)(struct MpegEncContext *c,
  60. uint8_t *blk1 /* align width (8 or 16) */,
  61. uint8_t *blk2 /* align 1 */, int line_size, int h);
  62. /**
  63. * Scantable.
  64. */
  65. typedef struct ScanTable {
  66. const uint8_t *scantable;
  67. uint8_t permutated[64];
  68. uint8_t raster_end[64];
  69. } ScanTable;
  70. void ff_init_scantable(uint8_t *permutation, ScanTable *st,
  71. const uint8_t *src_scantable);
  72. void ff_init_scantable_permutation(uint8_t *idct_permutation,
  73. int idct_permutation_type);
  74. /**
  75. * DSPContext.
  76. */
  77. typedef struct DSPContext {
  78. /* pixel ops : interface with DCT */
  79. void (*get_pixels)(int16_t *block /* align 16 */,
  80. const uint8_t *pixels /* align 8 */,
  81. int line_size);
  82. void (*diff_pixels)(int16_t *block /* align 16 */,
  83. const uint8_t *s1 /* align 8 */,
  84. const uint8_t *s2 /* align 8 */,
  85. int stride);
  86. void (*put_pixels_clamped)(const int16_t *block /* align 16 */,
  87. uint8_t *pixels /* align 8 */,
  88. int line_size);
  89. void (*put_signed_pixels_clamped)(const int16_t *block /* align 16 */,
  90. uint8_t *pixels /* align 8 */,
  91. int line_size);
  92. void (*add_pixels_clamped)(const int16_t *block /* align 16 */,
  93. uint8_t *pixels /* align 8 */,
  94. int line_size);
  95. int (*sum_abs_dctelem)(int16_t *block /* align 16 */);
  96. /**
  97. * translational global motion compensation.
  98. */
  99. void (*gmc1)(uint8_t *dst /* align 8 */, uint8_t *src /* align 1 */,
  100. int srcStride, int h, int x16, int y16, int rounder);
  101. /**
  102. * global motion compensation.
  103. */
  104. void (*gmc)(uint8_t *dst /* align 8 */, uint8_t *src /* align 1 */,
  105. int stride, int h, int ox, int oy,
  106. int dxx, int dxy, int dyx, int dyy,
  107. int shift, int r, int width, int height);
  108. void (*clear_block)(int16_t *block /* align 16 */);
  109. void (*clear_blocks)(int16_t *blocks /* align 16 */);
  110. int (*pix_sum)(uint8_t *pix, int line_size);
  111. int (*pix_norm1)(uint8_t *pix, int line_size);
  112. me_cmp_func sad[6]; /* identical to pix_absAxA except additional void * */
  113. me_cmp_func sse[6];
  114. me_cmp_func hadamard8_diff[6];
  115. me_cmp_func dct_sad[6];
  116. me_cmp_func quant_psnr[6];
  117. me_cmp_func bit[6];
  118. me_cmp_func rd[6];
  119. me_cmp_func vsad[6];
  120. me_cmp_func vsse[6];
  121. me_cmp_func nsse[6];
  122. me_cmp_func w53[6];
  123. me_cmp_func w97[6];
  124. me_cmp_func dct_max[6];
  125. me_cmp_func dct264_sad[6];
  126. me_cmp_func me_pre_cmp[6];
  127. me_cmp_func me_cmp[6];
  128. me_cmp_func me_sub_cmp[6];
  129. me_cmp_func mb_cmp[6];
  130. me_cmp_func ildct_cmp[6]; // only width 16 used
  131. me_cmp_func frame_skip_cmp[6]; // only width 8 used
  132. me_cmp_func pix_abs[2][4];
  133. void (*bswap_buf)(uint32_t *dst, const uint32_t *src, int w);
  134. void (*bswap16_buf)(uint16_t *dst, const uint16_t *src, int len);
  135. /* assume len is a multiple of 8, and arrays are 16-byte aligned */
  136. void (*vector_clipf)(float *dst /* align 16 */,
  137. const float *src /* align 16 */,
  138. float min, float max, int len /* align 16 */);
  139. /* (I)DCT */
  140. void (*fdct)(int16_t *block /* align 16 */);
  141. void (*fdct248)(int16_t *block /* align 16 */);
  142. /* IDCT really */
  143. void (*idct)(int16_t *block /* align 16 */);
  144. /**
  145. * block -> idct -> clip to unsigned 8 bit -> dest.
  146. * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...)
  147. * @param line_size size in bytes of a horizontal line of dest
  148. */
  149. void (*idct_put)(uint8_t *dest /* align 8 */,
  150. int line_size, int16_t *block /* align 16 */);
  151. /**
  152. * block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
  153. * @param line_size size in bytes of a horizontal line of dest
  154. */
  155. void (*idct_add)(uint8_t *dest /* align 8 */,
  156. int line_size, int16_t *block /* align 16 */);
  157. /**
  158. * IDCT input permutation.
  159. * Several optimized IDCTs need a permutated input (relative to the
  160. * normal order of the reference IDCT).
  161. * This permutation must be performed before the idct_put/add.
  162. * Note, normally this can be merged with the zigzag/alternate scan<br>
  163. * An example to avoid confusion:
  164. * - (->decode coeffs -> zigzag reorder -> dequant -> reference IDCT -> ...)
  165. * - (x -> reference DCT -> reference IDCT -> x)
  166. * - (x -> reference DCT -> simple_mmx_perm = idct_permutation
  167. * -> simple_idct_mmx -> x)
  168. * - (-> decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant
  169. * -> simple_idct_mmx -> ...)
  170. */
  171. uint8_t idct_permutation[64];
  172. int idct_permutation_type;
  173. #define FF_NO_IDCT_PERM 1
  174. #define FF_LIBMPEG2_IDCT_PERM 2
  175. #define FF_SIMPLE_IDCT_PERM 3
  176. #define FF_TRANSPOSE_IDCT_PERM 4
  177. #define FF_PARTTRANS_IDCT_PERM 5
  178. #define FF_SSE2_IDCT_PERM 6
  179. int (*try_8x8basis)(int16_t rem[64], int16_t weight[64],
  180. int16_t basis[64], int scale);
  181. void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale);
  182. #define BASIS_SHIFT 16
  183. #define RECON_SHIFT 6
  184. void (*draw_edges)(uint8_t *buf, int wrap, int width, int height,
  185. int w, int h, int sides);
  186. #define EDGE_WIDTH 16
  187. #define EDGE_TOP 1
  188. #define EDGE_BOTTOM 2
  189. void (*shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src,
  190. int src_wrap, int width, int height);
  191. /**
  192. * Calculate scalar product of two vectors.
  193. * @param len length of vectors, should be multiple of 16
  194. */
  195. int32_t (*scalarproduct_int16)(const int16_t *v1,
  196. const int16_t *v2 /* align 16 */, int len);
  197. /**
  198. * Clip each element in an array of int32_t to a given minimum and
  199. * maximum value.
  200. * @param dst destination array
  201. * constraints: 16-byte aligned
  202. * @param src source array
  203. * constraints: 16-byte aligned
  204. * @param min minimum value
  205. * constraints: must be in the range [-(1 << 24), 1 << 24]
  206. * @param max maximum value
  207. * constraints: must be in the range [-(1 << 24), 1 << 24]
  208. * @param len number of elements in the array
  209. * constraints: multiple of 32 greater than zero
  210. */
  211. void (*vector_clip_int32)(int32_t *dst, const int32_t *src, int32_t min,
  212. int32_t max, unsigned int len);
  213. op_fill_func fill_block_tab[2];
  214. } DSPContext;
  215. void ff_dsputil_static_init(void);
  216. void ff_dsputil_init(DSPContext *p, AVCodecContext *avctx);
  217. void avpriv_dsputil_init(DSPContext* p, AVCodecContext *avctx);
  218. attribute_deprecated void dsputil_init(DSPContext* c, AVCodecContext *avctx);
  219. int ff_check_alignment(void);
  220. void ff_set_cmp(DSPContext *c, me_cmp_func *cmp, int type);
  221. void ff_dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx);
  222. void ff_dsputil_init_arm(DSPContext *c, AVCodecContext *avctx,
  223. unsigned high_bit_depth);
  224. void ff_dsputil_init_ppc(DSPContext *c, AVCodecContext *avctx,
  225. unsigned high_bit_depth);
  226. void ff_dsputil_init_x86(DSPContext *c, AVCodecContext *avctx,
  227. unsigned high_bit_depth);
  228. void ff_dsputil_init_dwt(DSPContext *c);
  229. #endif /* AVCODEC_DSPUTIL_H */