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.

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