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.

650 lines
24KB

  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 "libavutil/intreadwrite.h"
  31. #include "avcodec.h"
  32. //#define DEBUG
  33. /* dct code */
  34. typedef short DCTELEM;
  35. void ff_fdct_ifast (DCTELEM *data);
  36. void ff_fdct_ifast248 (DCTELEM *data);
  37. void ff_jpeg_fdct_islow_8(DCTELEM *data);
  38. void ff_jpeg_fdct_islow_10(DCTELEM *data);
  39. void ff_fdct248_islow_8(DCTELEM *data);
  40. void ff_fdct248_islow_10(DCTELEM *data);
  41. void ff_j_rev_dct (DCTELEM *data);
  42. void ff_j_rev_dct4 (DCTELEM *data);
  43. void ff_j_rev_dct2 (DCTELEM *data);
  44. void ff_j_rev_dct1 (DCTELEM *data);
  45. void ff_fdct_mmx(DCTELEM *block);
  46. void ff_fdct_mmxext(DCTELEM *block);
  47. void ff_fdct_sse2(DCTELEM *block);
  48. #define H264_IDCT(depth) \
  49. void ff_h264_idct8_add_ ## depth ## _c(uint8_t *dst, DCTELEM *block, int stride);\
  50. void ff_h264_idct_add_ ## depth ## _c(uint8_t *dst, DCTELEM *block, int stride);\
  51. void ff_h264_idct8_dc_add_ ## depth ## _c(uint8_t *dst, DCTELEM *block, int stride);\
  52. void ff_h264_idct_dc_add_ ## depth ## _c(uint8_t *dst, DCTELEM *block, int stride);\
  53. void ff_h264_idct_add16_ ## depth ## _c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);\
  54. void ff_h264_idct_add16intra_ ## depth ## _c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);\
  55. void ff_h264_idct8_add4_ ## depth ## _c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);\
  56. void ff_h264_idct_add8_422_ ## depth ## _c(uint8_t **dest, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);\
  57. void ff_h264_idct_add8_ ## depth ## _c(uint8_t **dest, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);\
  58. void ff_h264_luma_dc_dequant_idct_ ## depth ## _c(DCTELEM *output, DCTELEM *input, int qmul);\
  59. void ff_h264_chroma422_dc_dequant_idct_ ## depth ## _c(DCTELEM *block, int qmul);\
  60. void ff_h264_chroma_dc_dequant_idct_ ## depth ## _c(DCTELEM *block, int qmul);
  61. H264_IDCT( 8)
  62. H264_IDCT( 9)
  63. H264_IDCT(10)
  64. H264_IDCT(12)
  65. H264_IDCT(14)
  66. void ff_svq3_luma_dc_dequant_idct_c(DCTELEM *output, DCTELEM *input, int qp);
  67. void ff_svq3_add_idct_c(uint8_t *dst, DCTELEM *block, int stride, int qp, int dc);
  68. /* encoding scans */
  69. extern const uint8_t ff_alternate_horizontal_scan[64];
  70. extern const uint8_t ff_alternate_vertical_scan[64];
  71. extern const uint8_t ff_zigzag_direct[64];
  72. extern const uint8_t ff_zigzag248_direct[64];
  73. /* pixel operations */
  74. #define MAX_NEG_CROP 1024
  75. /* temporary */
  76. extern uint32_t ff_squareTbl[512];
  77. extern uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP];
  78. #define PUTAVG_PIXELS(depth)\
  79. void ff_put_pixels8x8_ ## depth ## _c(uint8_t *dst, uint8_t *src, int stride);\
  80. void ff_avg_pixels8x8_ ## depth ## _c(uint8_t *dst, uint8_t *src, int stride);\
  81. void ff_put_pixels16x16_ ## depth ## _c(uint8_t *dst, uint8_t *src, int stride);\
  82. void ff_avg_pixels16x16_ ## depth ## _c(uint8_t *dst, uint8_t *src, int stride);
  83. PUTAVG_PIXELS( 8)
  84. PUTAVG_PIXELS( 9)
  85. PUTAVG_PIXELS(10)
  86. PUTAVG_PIXELS(12)
  87. PUTAVG_PIXELS(14)
  88. #define ff_put_pixels8x8_c ff_put_pixels8x8_8_c
  89. #define ff_avg_pixels8x8_c ff_avg_pixels8x8_8_c
  90. #define ff_put_pixels16x16_c ff_put_pixels16x16_8_c
  91. #define ff_avg_pixels16x16_c ff_avg_pixels16x16_8_c
  92. /* RV40 functions */
  93. void ff_put_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride);
  94. void ff_avg_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride);
  95. void ff_put_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride);
  96. void ff_avg_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride);
  97. /* 1/2^n downscaling functions from imgconvert.c */
  98. void ff_shrink22(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
  99. void ff_shrink44(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
  100. void ff_shrink88(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
  101. void ff_gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
  102. int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height);
  103. /* minimum alignment rules ;)
  104. If you notice errors in the align stuff, need more alignment for some ASM code
  105. for some CPU or need to use a function with less aligned data then send a mail
  106. to the ffmpeg-devel mailing list, ...
  107. !warning These alignments might not match reality, (missing attribute((align))
  108. stuff somewhere possible).
  109. I (Michael) did not check them, these are just the alignments which I think
  110. could be reached easily ...
  111. !future video codecs might need functions with less strict alignment
  112. */
  113. /*
  114. void get_pixels_c(DCTELEM *block, const uint8_t *pixels, int line_size);
  115. void diff_pixels_c(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride);
  116. void put_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
  117. void add_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
  118. void clear_blocks_c(DCTELEM *blocks);
  119. */
  120. /* add and put pixel (decoding) */
  121. // blocksizes for op_pixels_func are 8x4,8x8 16x8 16x16
  122. //h for op_pixels_func is limited to {width/2, width} but never larger than 16 and never smaller than 4
  123. typedef void (*op_pixels_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int h);
  124. typedef void (*tpel_mc_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int w, int h);
  125. typedef void (*qpel_mc_func)(uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);
  126. typedef void (*h264_chroma_mc_func)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x, int y);
  127. typedef void (*op_fill_func)(uint8_t *block/*align width (8 or 16)*/, uint8_t value, int line_size, int h);
  128. #define DEF_OLD_QPEL(name)\
  129. void ff_put_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
  130. void ff_put_no_rnd_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
  131. void ff_avg_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);
  132. DEF_OLD_QPEL(qpel16_mc11_old_c)
  133. DEF_OLD_QPEL(qpel16_mc31_old_c)
  134. DEF_OLD_QPEL(qpel16_mc12_old_c)
  135. DEF_OLD_QPEL(qpel16_mc32_old_c)
  136. DEF_OLD_QPEL(qpel16_mc13_old_c)
  137. DEF_OLD_QPEL(qpel16_mc33_old_c)
  138. DEF_OLD_QPEL(qpel8_mc11_old_c)
  139. DEF_OLD_QPEL(qpel8_mc31_old_c)
  140. DEF_OLD_QPEL(qpel8_mc12_old_c)
  141. DEF_OLD_QPEL(qpel8_mc32_old_c)
  142. DEF_OLD_QPEL(qpel8_mc13_old_c)
  143. DEF_OLD_QPEL(qpel8_mc33_old_c)
  144. #define CALL_2X_PIXELS(a, b, n)\
  145. static void a(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  146. b(block , pixels , line_size, h);\
  147. b(block+n, pixels+n, line_size, h);\
  148. }
  149. /* motion estimation */
  150. // h is limited to {width/2, width, 2*width} but never larger than 16 and never smaller than 2
  151. // although currently h<4 is not used as functions with width <8 are neither used nor implemented
  152. typedef int (*me_cmp_func)(void /*MpegEncContext*/ *s, uint8_t *blk1/*align width (8 or 16)*/, uint8_t *blk2/*align 1*/, int line_size, int h)/* __attribute__ ((const))*/;
  153. /**
  154. * Scantable.
  155. */
  156. typedef struct ScanTable{
  157. const uint8_t *scantable;
  158. uint8_t permutated[64];
  159. uint8_t raster_end[64];
  160. } ScanTable;
  161. void ff_init_scantable(uint8_t *, ScanTable *st, const uint8_t *src_scantable);
  162. void ff_init_scantable_permutation(uint8_t *idct_permutation,
  163. int idct_permutation_type);
  164. #define EMULATED_EDGE(depth) \
  165. void ff_emulated_edge_mc_ ## depth (uint8_t *buf, const uint8_t *src, ptrdiff_t linesize,\
  166. int block_w, int block_h,\
  167. int src_x, int src_y, int w, int h);
  168. EMULATED_EDGE(8)
  169. EMULATED_EDGE(16)
  170. /**
  171. * DSPContext.
  172. */
  173. typedef struct DSPContext {
  174. /**
  175. * Size of DCT coefficients.
  176. */
  177. int dct_bits;
  178. /* pixel ops : interface with DCT */
  179. void (*get_pixels)(DCTELEM *block/*align 16*/, const uint8_t *pixels/*align 8*/, int line_size);
  180. void (*diff_pixels)(DCTELEM *block/*align 16*/, const uint8_t *s1/*align 8*/, const uint8_t *s2/*align 8*/, int stride);
  181. void (*put_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
  182. void (*put_signed_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
  183. void (*add_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
  184. void (*add_pixels8)(uint8_t *pixels, DCTELEM *block, int line_size);
  185. void (*add_pixels4)(uint8_t *pixels, DCTELEM *block, int line_size);
  186. int (*sum_abs_dctelem)(DCTELEM *block/*align 16*/);
  187. /**
  188. * translational global motion compensation.
  189. */
  190. void (*gmc1)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x16, int y16, int rounder);
  191. /**
  192. * global motion compensation.
  193. */
  194. void (*gmc )(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int ox, int oy,
  195. int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height);
  196. void (*clear_block)(DCTELEM *block/*align 16*/);
  197. void (*clear_blocks)(DCTELEM *blocks/*align 16*/);
  198. int (*pix_sum)(uint8_t * pix, int line_size);
  199. int (*pix_norm1)(uint8_t * pix, int line_size);
  200. // 16x16 8x8 4x4 2x2 16x8 8x4 4x2 8x16 4x8 2x4
  201. me_cmp_func sad[6]; /* identical to pix_absAxA except additional void * */
  202. me_cmp_func sse[6];
  203. me_cmp_func hadamard8_diff[6];
  204. me_cmp_func dct_sad[6];
  205. me_cmp_func quant_psnr[6];
  206. me_cmp_func bit[6];
  207. me_cmp_func rd[6];
  208. me_cmp_func vsad[6];
  209. me_cmp_func vsse[6];
  210. me_cmp_func nsse[6];
  211. me_cmp_func w53[6];
  212. me_cmp_func w97[6];
  213. me_cmp_func dct_max[6];
  214. me_cmp_func dct264_sad[6];
  215. me_cmp_func me_pre_cmp[6];
  216. me_cmp_func me_cmp[6];
  217. me_cmp_func me_sub_cmp[6];
  218. me_cmp_func mb_cmp[6];
  219. me_cmp_func ildct_cmp[6]; //only width 16 used
  220. me_cmp_func frame_skip_cmp[6]; //only width 8 used
  221. int (*ssd_int8_vs_int16)(const int8_t *pix1, const int16_t *pix2,
  222. int size);
  223. /**
  224. * Halfpel motion compensation with rounding (a+b+1)>>1.
  225. * this is an array[4][4] of motion compensation functions for 4
  226. * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
  227. * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
  228. * @param block destination where the result is stored
  229. * @param pixels source
  230. * @param line_size number of bytes in a horizontal line of block
  231. * @param h height
  232. */
  233. op_pixels_func put_pixels_tab[4][4];
  234. /**
  235. * Halfpel motion compensation with rounding (a+b+1)>>1.
  236. * This is an array[4][4] of motion compensation functions for 4
  237. * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
  238. * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
  239. * @param block destination into which the result is averaged (a+b+1)>>1
  240. * @param pixels source
  241. * @param line_size number of bytes in a horizontal line of block
  242. * @param h height
  243. */
  244. op_pixels_func avg_pixels_tab[4][4];
  245. /**
  246. * Halfpel motion compensation with no rounding (a+b)>>1.
  247. * this is an array[2][4] of motion compensation functions for 2
  248. * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
  249. * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
  250. * @param block destination where the result is stored
  251. * @param pixels source
  252. * @param line_size number of bytes in a horizontal line of block
  253. * @param h height
  254. */
  255. op_pixels_func put_no_rnd_pixels_tab[4][4];
  256. /**
  257. * Halfpel motion compensation with no rounding (a+b)>>1.
  258. * this is an array[2][4] of motion compensation functions for 2
  259. * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
  260. * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
  261. * @param block destination into which the result is averaged (a+b)>>1
  262. * @param pixels source
  263. * @param line_size number of bytes in a horizontal line of block
  264. * @param h height
  265. */
  266. op_pixels_func avg_no_rnd_pixels_tab[4][4];
  267. /**
  268. * Thirdpel motion compensation with rounding (a+b+1)>>1.
  269. * this is an array[12] of motion compensation functions for the 9 thirdpe
  270. * positions<br>
  271. * *pixels_tab[ xthirdpel + 4*ythirdpel ]
  272. * @param block destination where the result is stored
  273. * @param pixels source
  274. * @param line_size number of bytes in a horizontal line of block
  275. * @param h height
  276. */
  277. tpel_mc_func put_tpel_pixels_tab[11]; //FIXME individual func ptr per width?
  278. tpel_mc_func avg_tpel_pixels_tab[11]; //FIXME individual func ptr per width?
  279. qpel_mc_func put_qpel_pixels_tab[2][16];
  280. qpel_mc_func avg_qpel_pixels_tab[2][16];
  281. qpel_mc_func put_no_rnd_qpel_pixels_tab[2][16];
  282. qpel_mc_func avg_no_rnd_qpel_pixels_tab[2][16];
  283. qpel_mc_func put_mspel_pixels_tab[8];
  284. /**
  285. * h264 Chroma MC
  286. */
  287. h264_chroma_mc_func put_h264_chroma_pixels_tab[3];
  288. h264_chroma_mc_func avg_h264_chroma_pixels_tab[3];
  289. qpel_mc_func put_h264_qpel_pixels_tab[4][16];
  290. qpel_mc_func avg_h264_qpel_pixels_tab[4][16];
  291. me_cmp_func pix_abs[2][4];
  292. /* huffyuv specific */
  293. void (*add_bytes)(uint8_t *dst/*align 16*/, uint8_t *src/*align 16*/, int w);
  294. void (*diff_bytes)(uint8_t *dst/*align 16*/, const uint8_t *src1/*align 16*/, const uint8_t *src2/*align 1*/,int w);
  295. /**
  296. * subtract huffyuv's variant of median prediction
  297. * note, this might read from src1[-1], src2[-1]
  298. */
  299. void (*sub_hfyu_median_prediction)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w, int *left, int *left_top);
  300. void (*add_hfyu_median_prediction)(uint8_t *dst, const uint8_t *top, const uint8_t *diff, int w, int *left, int *left_top);
  301. int (*add_hfyu_left_prediction)(uint8_t *dst, const uint8_t *src, int w, int left);
  302. void (*add_hfyu_left_prediction_bgr32)(uint8_t *dst, const uint8_t *src, int w, int *red, int *green, int *blue, int *alpha);
  303. /* this might write to dst[w] */
  304. void (*bswap_buf)(uint32_t *dst, const uint32_t *src, int w);
  305. void (*bswap16_buf)(uint16_t *dst, const uint16_t *src, int len);
  306. void (*h263_v_loop_filter)(uint8_t *src, int stride, int qscale);
  307. void (*h263_h_loop_filter)(uint8_t *src, int stride, int qscale);
  308. void (*h261_loop_filter)(uint8_t *src, int stride);
  309. /* assume len is a multiple of 8, and arrays are 16-byte aligned */
  310. void (*vector_clipf)(float *dst /* align 16 */, const float *src /* align 16 */, float min, float max, int len /* align 16 */);
  311. /* (I)DCT */
  312. void (*fdct)(DCTELEM *block/* align 16*/);
  313. void (*fdct248)(DCTELEM *block/* align 16*/);
  314. /* IDCT really*/
  315. void (*idct)(DCTELEM *block/* align 16*/);
  316. /**
  317. * block -> idct -> clip to unsigned 8 bit -> dest.
  318. * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...)
  319. * @param line_size size in bytes of a horizontal line of dest
  320. */
  321. void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
  322. /**
  323. * block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
  324. * @param line_size size in bytes of a horizontal line of dest
  325. */
  326. void (*idct_add)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
  327. /**
  328. * idct input permutation.
  329. * several optimized IDCTs need a permutated input (relative to the normal order of the reference
  330. * IDCT)
  331. * this permutation must be performed before the idct_put/add, note, normally this can be merged
  332. * with the zigzag/alternate scan<br>
  333. * an example to avoid confusion:
  334. * - (->decode coeffs -> zigzag reorder -> dequant -> reference idct ->...)
  335. * - (x -> reference dct -> reference idct -> x)
  336. * - (x -> reference dct -> simple_mmx_perm = idct_permutation -> simple_idct_mmx -> x)
  337. * - (->decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant -> simple_idct_mmx ->...)
  338. */
  339. uint8_t idct_permutation[64];
  340. int idct_permutation_type;
  341. #define FF_NO_IDCT_PERM 1
  342. #define FF_LIBMPEG2_IDCT_PERM 2
  343. #define FF_SIMPLE_IDCT_PERM 3
  344. #define FF_TRANSPOSE_IDCT_PERM 4
  345. #define FF_PARTTRANS_IDCT_PERM 5
  346. #define FF_SSE2_IDCT_PERM 6
  347. int (*try_8x8basis)(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale);
  348. void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale);
  349. #define BASIS_SHIFT 16
  350. #define RECON_SHIFT 6
  351. void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w, int h, int sides);
  352. #define EDGE_WIDTH 16
  353. #define EDGE_TOP 1
  354. #define EDGE_BOTTOM 2
  355. void (*shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
  356. /**
  357. * Calculate scalar product of two vectors.
  358. * @param len length of vectors, should be multiple of 16
  359. */
  360. int32_t (*scalarproduct_int16)(const int16_t *v1, const int16_t *v2/*align 16*/, int len);
  361. /* ape functions */
  362. /**
  363. * Calculate scalar product of v1 and v2,
  364. * and v1[i] += v3[i] * mul
  365. * @param len length of vectors, should be multiple of 16
  366. */
  367. int32_t (*scalarproduct_and_madd_int16)(int16_t *v1/*align 16*/, const int16_t *v2, const int16_t *v3, int len, int mul);
  368. /**
  369. * Apply symmetric window in 16-bit fixed-point.
  370. * @param output destination array
  371. * constraints: 16-byte aligned
  372. * @param input source array
  373. * constraints: 16-byte aligned
  374. * @param window window array
  375. * constraints: 16-byte aligned, at least len/2 elements
  376. * @param len full window length
  377. * constraints: multiple of ? greater than zero
  378. */
  379. void (*apply_window_int16)(int16_t *output, const int16_t *input,
  380. const int16_t *window, unsigned int len);
  381. /**
  382. * Clip each element in an array of int32_t to a given minimum and maximum value.
  383. * @param dst destination array
  384. * constraints: 16-byte aligned
  385. * @param src source array
  386. * constraints: 16-byte aligned
  387. * @param min minimum value
  388. * constraints: must be in the range [-(1 << 24), 1 << 24]
  389. * @param max maximum value
  390. * constraints: must be in the range [-(1 << 24), 1 << 24]
  391. * @param len number of elements in the array
  392. * constraints: multiple of 32 greater than zero
  393. */
  394. void (*vector_clip_int32)(int32_t *dst, const int32_t *src, int32_t min,
  395. int32_t max, unsigned int len);
  396. op_fill_func fill_block_tab[2];
  397. } DSPContext;
  398. void ff_dsputil_static_init(void);
  399. void ff_dsputil_init(DSPContext* p, AVCodecContext *avctx);
  400. attribute_deprecated void dsputil_init(DSPContext* c, AVCodecContext *avctx);
  401. int ff_check_alignment(void);
  402. /**
  403. * permute block according to permuatation.
  404. * @param last last non zero element in scantable order
  405. */
  406. void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last);
  407. void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type);
  408. #define BYTE_VEC32(c) ((c)*0x01010101UL)
  409. #define BYTE_VEC64(c) ((c)*0x0001000100010001UL)
  410. static inline uint32_t rnd_avg32(uint32_t a, uint32_t b)
  411. {
  412. return (a | b) - (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
  413. }
  414. static inline uint32_t no_rnd_avg32(uint32_t a, uint32_t b)
  415. {
  416. return (a & b) + (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
  417. }
  418. static inline uint64_t rnd_avg64(uint64_t a, uint64_t b)
  419. {
  420. return (a | b) - (((a ^ b) & ~BYTE_VEC64(0x01)) >> 1);
  421. }
  422. static inline uint64_t no_rnd_avg64(uint64_t a, uint64_t b)
  423. {
  424. return (a & b) + (((a ^ b) & ~BYTE_VEC64(0x01)) >> 1);
  425. }
  426. static inline int get_penalty_factor(int lambda, int lambda2, int type){
  427. switch(type&0xFF){
  428. default:
  429. case FF_CMP_SAD:
  430. return lambda>>FF_LAMBDA_SHIFT;
  431. case FF_CMP_DCT:
  432. return (3*lambda)>>(FF_LAMBDA_SHIFT+1);
  433. case FF_CMP_W53:
  434. return (4*lambda)>>(FF_LAMBDA_SHIFT);
  435. case FF_CMP_W97:
  436. return (2*lambda)>>(FF_LAMBDA_SHIFT);
  437. case FF_CMP_SATD:
  438. case FF_CMP_DCT264:
  439. return (2*lambda)>>FF_LAMBDA_SHIFT;
  440. case FF_CMP_RD:
  441. case FF_CMP_PSNR:
  442. case FF_CMP_SSE:
  443. case FF_CMP_NSSE:
  444. return lambda2>>FF_LAMBDA_SHIFT;
  445. case FF_CMP_BIT:
  446. return 1;
  447. }
  448. }
  449. void ff_dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx);
  450. void ff_dsputil_init_arm(DSPContext* c, AVCodecContext *avctx);
  451. void ff_dsputil_init_bfin(DSPContext* c, AVCodecContext *avctx);
  452. void ff_dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx);
  453. void ff_dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx);
  454. void ff_dsputil_init_sh4(DSPContext* c, AVCodecContext *avctx);
  455. void ff_dsputil_init_vis(DSPContext* c, AVCodecContext *avctx);
  456. void ff_dsputil_init_dwt(DSPContext *c);
  457. #if (ARCH_ARM && HAVE_NEON) || ARCH_PPC || HAVE_MMX
  458. # define STRIDE_ALIGN 16
  459. #else
  460. # define STRIDE_ALIGN 8
  461. #endif
  462. // Some broken preprocessors need a second expansion
  463. // to be forced to tokenize __VA_ARGS__
  464. #define E(x) x
  465. #define LOCAL_ALIGNED_A(a, t, v, s, o, ...) \
  466. uint8_t la_##v[sizeof(t s o) + (a)]; \
  467. t (*v) o = (void *)FFALIGN((uintptr_t)la_##v, a)
  468. #define LOCAL_ALIGNED_D(a, t, v, s, o, ...) \
  469. DECLARE_ALIGNED(a, t, la_##v) s o; \
  470. t (*v) o = la_##v
  471. #define LOCAL_ALIGNED(a, t, v, ...) E(LOCAL_ALIGNED_A(a, t, v, __VA_ARGS__,,))
  472. #if HAVE_LOCAL_ALIGNED_8
  473. # define LOCAL_ALIGNED_8(t, v, ...) E(LOCAL_ALIGNED_D(8, t, v, __VA_ARGS__,,))
  474. #else
  475. # define LOCAL_ALIGNED_8(t, v, ...) LOCAL_ALIGNED(8, t, v, __VA_ARGS__)
  476. #endif
  477. #if HAVE_LOCAL_ALIGNED_16
  478. # define LOCAL_ALIGNED_16(t, v, ...) E(LOCAL_ALIGNED_D(16, t, v, __VA_ARGS__,,))
  479. #else
  480. # define LOCAL_ALIGNED_16(t, v, ...) LOCAL_ALIGNED(16, t, v, __VA_ARGS__)
  481. #endif
  482. #define WRAPPER8_16_SQ(name8, name16)\
  483. static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
  484. int score=0;\
  485. score +=name8(s, dst , src , stride, 8);\
  486. score +=name8(s, dst+8 , src+8 , stride, 8);\
  487. if(h==16){\
  488. dst += 8*stride;\
  489. src += 8*stride;\
  490. score +=name8(s, dst , src , stride, 8);\
  491. score +=name8(s, dst+8 , src+8 , stride, 8);\
  492. }\
  493. return score;\
  494. }
  495. static inline void copy_block2(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
  496. {
  497. int i;
  498. for(i=0; i<h; i++)
  499. {
  500. AV_COPY16U(dst, src);
  501. dst+=dstStride;
  502. src+=srcStride;
  503. }
  504. }
  505. static inline void copy_block4(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
  506. {
  507. int i;
  508. for(i=0; i<h; i++)
  509. {
  510. AV_COPY32U(dst, src);
  511. dst+=dstStride;
  512. src+=srcStride;
  513. }
  514. }
  515. static inline void copy_block8(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
  516. {
  517. int i;
  518. for(i=0; i<h; i++)
  519. {
  520. AV_COPY64U(dst, src);
  521. dst+=dstStride;
  522. src+=srcStride;
  523. }
  524. }
  525. static inline void copy_block9(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
  526. {
  527. int i;
  528. for(i=0; i<h; i++)
  529. {
  530. AV_COPY64U(dst, src);
  531. dst[8]= src[8];
  532. dst+=dstStride;
  533. src+=srcStride;
  534. }
  535. }
  536. static inline void copy_block16(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
  537. {
  538. int i;
  539. for(i=0; i<h; i++)
  540. {
  541. AV_COPY128U(dst, src);
  542. dst+=dstStride;
  543. src+=srcStride;
  544. }
  545. }
  546. static inline void copy_block17(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
  547. {
  548. int i;
  549. for(i=0; i<h; i++)
  550. {
  551. AV_COPY128U(dst, src);
  552. dst[16]= src[16];
  553. dst+=dstStride;
  554. src+=srcStride;
  555. }
  556. }
  557. #endif /* AVCODEC_DSPUTIL_H */