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.

773 lines
29KB

  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 dsputil.h
  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 FFMPEG_DSPUTIL_H
  29. #define FFMPEG_DSPUTIL_H
  30. #include "avcodec.h"
  31. //#define DEBUG
  32. /* dct code */
  33. typedef short DCTELEM;
  34. typedef int DWTELEM;
  35. typedef short IDWTELEM;
  36. void fdct_ifast (DCTELEM *data);
  37. void fdct_ifast248 (DCTELEM *data);
  38. void ff_jpeg_fdct_islow (DCTELEM *data);
  39. void ff_fdct248_islow (DCTELEM *data);
  40. void j_rev_dct (DCTELEM *data);
  41. void j_rev_dct4 (DCTELEM *data);
  42. void j_rev_dct2 (DCTELEM *data);
  43. void j_rev_dct1 (DCTELEM *data);
  44. void ff_wmv2_idct_c(DCTELEM *data);
  45. void ff_fdct_mmx(DCTELEM *block);
  46. void ff_fdct_mmx2(DCTELEM *block);
  47. void ff_fdct_sse2(DCTELEM *block);
  48. void ff_h264_idct8_add_c(uint8_t *dst, DCTELEM *block, int stride);
  49. void ff_h264_idct_add_c(uint8_t *dst, DCTELEM *block, int stride);
  50. void ff_h264_idct8_dc_add_c(uint8_t *dst, DCTELEM *block, int stride);
  51. void ff_h264_idct_dc_add_c(uint8_t *dst, DCTELEM *block, int stride);
  52. void ff_h264_lowres_idct_add_c(uint8_t *dst, int stride, DCTELEM *block);
  53. void ff_h264_lowres_idct_put_c(uint8_t *dst, int stride, DCTELEM *block);
  54. void ff_vector_fmul_add_add_c(float *dst, const float *src0, const float *src1,
  55. const float *src2, int src3, int blocksize, int step);
  56. void ff_float_to_int16_c(int16_t *dst, const float *src, int len);
  57. /* encoding scans */
  58. extern const uint8_t ff_alternate_horizontal_scan[64];
  59. extern const uint8_t ff_alternate_vertical_scan[64];
  60. extern const uint8_t ff_zigzag_direct[64];
  61. extern const uint8_t ff_zigzag248_direct[64];
  62. /* pixel operations */
  63. #define MAX_NEG_CROP 1024
  64. /* temporary */
  65. extern uint32_t ff_squareTbl[512];
  66. extern uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP];
  67. /* VP3 DSP functions */
  68. void ff_vp3_idct_c(DCTELEM *block/* align 16*/);
  69. void ff_vp3_idct_put_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
  70. void ff_vp3_idct_add_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
  71. /* 1/2^n downscaling functions from imgconvert.c */
  72. void ff_img_copy_plane(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
  73. void ff_shrink22(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
  74. void ff_shrink44(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
  75. void ff_shrink88(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
  76. void ff_gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
  77. int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height);
  78. /* minimum alignment rules ;)
  79. If you notice errors in the align stuff, need more alignment for some ASM code
  80. for some CPU or need to use a function with less aligned data then send a mail
  81. to the ffmpeg-devel mailing list, ...
  82. !warning These alignments might not match reality, (missing attribute((align))
  83. stuff somewhere possible).
  84. I (Michael) did not check them, these are just the alignments which I think
  85. could be reached easily ...
  86. !future video codecs might need functions with less strict alignment
  87. */
  88. /*
  89. void get_pixels_c(DCTELEM *block, const uint8_t *pixels, int line_size);
  90. void diff_pixels_c(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride);
  91. void put_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
  92. void add_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
  93. void clear_blocks_c(DCTELEM *blocks);
  94. */
  95. /* add and put pixel (decoding) */
  96. // blocksizes for op_pixels_func are 8x4,8x8 16x8 16x16
  97. //h for op_pixels_func is limited to {width/2, width} but never larger than 16 and never smaller then 4
  98. typedef void (*op_pixels_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int h);
  99. 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);
  100. typedef void (*qpel_mc_func)(uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);
  101. typedef void (*h264_chroma_mc_func)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x, int y);
  102. typedef void (*h264_weight_func)(uint8_t *block, int stride, int log2_denom, int weight, int offset);
  103. typedef void (*h264_biweight_func)(uint8_t *dst, uint8_t *src, int stride, int log2_denom, int weightd, int weights, int offset);
  104. #define DEF_OLD_QPEL(name)\
  105. void ff_put_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
  106. void ff_put_no_rnd_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
  107. void ff_avg_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);
  108. DEF_OLD_QPEL(qpel16_mc11_old_c)
  109. DEF_OLD_QPEL(qpel16_mc31_old_c)
  110. DEF_OLD_QPEL(qpel16_mc12_old_c)
  111. DEF_OLD_QPEL(qpel16_mc32_old_c)
  112. DEF_OLD_QPEL(qpel16_mc13_old_c)
  113. DEF_OLD_QPEL(qpel16_mc33_old_c)
  114. DEF_OLD_QPEL(qpel8_mc11_old_c)
  115. DEF_OLD_QPEL(qpel8_mc31_old_c)
  116. DEF_OLD_QPEL(qpel8_mc12_old_c)
  117. DEF_OLD_QPEL(qpel8_mc32_old_c)
  118. DEF_OLD_QPEL(qpel8_mc13_old_c)
  119. DEF_OLD_QPEL(qpel8_mc33_old_c)
  120. #define CALL_2X_PIXELS(a, b, n)\
  121. static void a(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  122. b(block , pixels , line_size, h);\
  123. b(block+n, pixels+n, line_size, h);\
  124. }
  125. /* motion estimation */
  126. // h is limited to {width/2, width, 2*width} but never larger than 16 and never smaller then 2
  127. // although currently h<4 is not used as functions with width <8 are neither used nor implemented
  128. 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))*/;
  129. // for snow slices
  130. typedef struct slice_buffer_s slice_buffer;
  131. /**
  132. * Scantable.
  133. */
  134. typedef struct ScanTable{
  135. const uint8_t *scantable;
  136. uint8_t permutated[64];
  137. uint8_t raster_end[64];
  138. #ifdef ARCH_POWERPC
  139. /** Used by dct_quantize_altivec to find last-non-zero */
  140. DECLARE_ALIGNED(16, uint8_t, inverse[64]);
  141. #endif
  142. } ScanTable;
  143. void ff_init_scantable(uint8_t *, ScanTable *st, const uint8_t *src_scantable);
  144. void ff_emulated_edge_mc(uint8_t *buf, uint8_t *src, int linesize,
  145. int block_w, int block_h,
  146. int src_x, int src_y, int w, int h);
  147. /**
  148. * DSPContext.
  149. */
  150. typedef struct DSPContext {
  151. /* pixel ops : interface with DCT */
  152. void (*get_pixels)(DCTELEM *block/*align 16*/, const uint8_t *pixels/*align 8*/, int line_size);
  153. void (*diff_pixels)(DCTELEM *block/*align 16*/, const uint8_t *s1/*align 8*/, const uint8_t *s2/*align 8*/, int stride);
  154. void (*put_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
  155. void (*put_signed_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
  156. void (*add_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
  157. void (*add_pixels8)(uint8_t *pixels, DCTELEM *block, int line_size);
  158. void (*add_pixels4)(uint8_t *pixels, DCTELEM *block, int line_size);
  159. int (*sum_abs_dctelem)(DCTELEM *block/*align 16*/);
  160. /**
  161. * translational global motion compensation.
  162. */
  163. void (*gmc1)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x16, int y16, int rounder);
  164. /**
  165. * global motion compensation.
  166. */
  167. void (*gmc )(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int ox, int oy,
  168. int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height);
  169. void (*clear_blocks)(DCTELEM *blocks/*align 16*/);
  170. int (*pix_sum)(uint8_t * pix, int line_size);
  171. int (*pix_norm1)(uint8_t * pix, int line_size);
  172. // 16x16 8x8 4x4 2x2 16x8 8x4 4x2 8x16 4x8 2x4
  173. me_cmp_func sad[5]; /* identical to pix_absAxA except additional void * */
  174. me_cmp_func sse[5];
  175. me_cmp_func hadamard8_diff[5];
  176. me_cmp_func dct_sad[5];
  177. me_cmp_func quant_psnr[5];
  178. me_cmp_func bit[5];
  179. me_cmp_func rd[5];
  180. me_cmp_func vsad[5];
  181. me_cmp_func vsse[5];
  182. me_cmp_func nsse[5];
  183. me_cmp_func w53[5];
  184. me_cmp_func w97[5];
  185. me_cmp_func dct_max[5];
  186. me_cmp_func dct264_sad[5];
  187. me_cmp_func me_pre_cmp[5];
  188. me_cmp_func me_cmp[5];
  189. me_cmp_func me_sub_cmp[5];
  190. me_cmp_func mb_cmp[5];
  191. me_cmp_func ildct_cmp[5]; //only width 16 used
  192. me_cmp_func frame_skip_cmp[5]; //only width 8 used
  193. int (*ssd_int8_vs_int16)(const int8_t *pix1, const int16_t *pix2,
  194. int size);
  195. /**
  196. * Halfpel motion compensation with rounding (a+b+1)>>1.
  197. * this is an array[4][4] of motion compensation functions for 4
  198. * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
  199. * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
  200. * @param block destination where the result is stored
  201. * @param pixels source
  202. * @param line_size number of bytes in a horizontal line of block
  203. * @param h height
  204. */
  205. op_pixels_func put_pixels_tab[4][4];
  206. /**
  207. * Halfpel motion compensation with rounding (a+b+1)>>1.
  208. * This is an array[4][4] of motion compensation functions for 4
  209. * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
  210. * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
  211. * @param block destination into which the result is averaged (a+b+1)>>1
  212. * @param pixels source
  213. * @param line_size number of bytes in a horizontal line of block
  214. * @param h height
  215. */
  216. op_pixels_func avg_pixels_tab[4][4];
  217. /**
  218. * Halfpel motion compensation with no rounding (a+b)>>1.
  219. * this is an array[2][4] of motion compensation functions for 2
  220. * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
  221. * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
  222. * @param block destination where the result is stored
  223. * @param pixels source
  224. * @param line_size number of bytes in a horizontal line of block
  225. * @param h height
  226. */
  227. op_pixels_func put_no_rnd_pixels_tab[4][4];
  228. /**
  229. * Halfpel motion compensation with no rounding (a+b)>>1.
  230. * this is an array[2][4] of motion compensation functions for 2
  231. * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
  232. * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
  233. * @param block destination into which the result is averaged (a+b)>>1
  234. * @param pixels source
  235. * @param line_size number of bytes in a horizontal line of block
  236. * @param h height
  237. */
  238. op_pixels_func avg_no_rnd_pixels_tab[4][4];
  239. void (*put_no_rnd_pixels_l2[2])(uint8_t *block/*align width (8 or 16)*/, const uint8_t *a/*align 1*/, const uint8_t *b/*align 1*/, int line_size, int h);
  240. /**
  241. * Thirdpel motion compensation with rounding (a+b+1)>>1.
  242. * this is an array[12] of motion compensation functions for the 9 thirdpe
  243. * positions<br>
  244. * *pixels_tab[ xthirdpel + 4*ythirdpel ]
  245. * @param block destination where the result is stored
  246. * @param pixels source
  247. * @param line_size number of bytes in a horizontal line of block
  248. * @param h height
  249. */
  250. tpel_mc_func put_tpel_pixels_tab[11]; //FIXME individual func ptr per width?
  251. tpel_mc_func avg_tpel_pixels_tab[11]; //FIXME individual func ptr per width?
  252. qpel_mc_func put_qpel_pixels_tab[2][16];
  253. qpel_mc_func avg_qpel_pixels_tab[2][16];
  254. qpel_mc_func put_no_rnd_qpel_pixels_tab[2][16];
  255. qpel_mc_func avg_no_rnd_qpel_pixels_tab[2][16];
  256. qpel_mc_func put_mspel_pixels_tab[8];
  257. /**
  258. * h264 Chroma MC
  259. */
  260. h264_chroma_mc_func put_h264_chroma_pixels_tab[3];
  261. /* This is really one func used in VC-1 decoding */
  262. h264_chroma_mc_func put_no_rnd_h264_chroma_pixels_tab[3];
  263. h264_chroma_mc_func avg_h264_chroma_pixels_tab[3];
  264. qpel_mc_func put_h264_qpel_pixels_tab[4][16];
  265. qpel_mc_func avg_h264_qpel_pixels_tab[4][16];
  266. qpel_mc_func put_2tap_qpel_pixels_tab[4][16];
  267. qpel_mc_func avg_2tap_qpel_pixels_tab[4][16];
  268. h264_weight_func weight_h264_pixels_tab[10];
  269. h264_biweight_func biweight_h264_pixels_tab[10];
  270. /* AVS specific */
  271. qpel_mc_func put_cavs_qpel_pixels_tab[2][16];
  272. qpel_mc_func avg_cavs_qpel_pixels_tab[2][16];
  273. void (*cavs_filter_lv)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
  274. void (*cavs_filter_lh)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
  275. void (*cavs_filter_cv)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
  276. void (*cavs_filter_ch)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
  277. void (*cavs_idct8_add)(uint8_t *dst, DCTELEM *block, int stride);
  278. me_cmp_func pix_abs[2][4];
  279. /* huffyuv specific */
  280. void (*add_bytes)(uint8_t *dst/*align 16*/, uint8_t *src/*align 16*/, int w);
  281. void (*add_bytes_l2)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 16*/, int w);
  282. void (*diff_bytes)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 1*/,int w);
  283. /**
  284. * subtract huffyuv's variant of median prediction
  285. * note, this might read from src1[-1], src2[-1]
  286. */
  287. void (*sub_hfyu_median_prediction)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w, int *left, int *left_top);
  288. /* this might write to dst[w] */
  289. void (*add_png_paeth_prediction)(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp);
  290. void (*bswap_buf)(uint32_t *dst, const uint32_t *src, int w);
  291. void (*h264_v_loop_filter_luma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0);
  292. void (*h264_h_loop_filter_luma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0);
  293. void (*h264_v_loop_filter_chroma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0);
  294. void (*h264_h_loop_filter_chroma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0);
  295. void (*h264_v_loop_filter_chroma_intra)(uint8_t *pix, int stride, int alpha, int beta);
  296. void (*h264_h_loop_filter_chroma_intra)(uint8_t *pix, int stride, int alpha, int beta);
  297. // h264_loop_filter_strength: simd only. the C version is inlined in h264.c
  298. void (*h264_loop_filter_strength)(int16_t bS[2][4][4], uint8_t nnz[40], int8_t ref[2][40], int16_t mv[2][40][2],
  299. int bidir, int edges, int step, int mask_mv0, int mask_mv1);
  300. void (*h263_v_loop_filter)(uint8_t *src, int stride, int qscale);
  301. void (*h263_h_loop_filter)(uint8_t *src, int stride, int qscale);
  302. void (*h261_loop_filter)(uint8_t *src, int stride);
  303. void (*x8_v_loop_filter)(uint8_t *src, int stride, int qscale);
  304. void (*x8_h_loop_filter)(uint8_t *src, int stride, int qscale);
  305. /* assume len is a multiple of 4, and arrays are 16-byte aligned */
  306. void (*vorbis_inverse_coupling)(float *mag, float *ang, int blocksize);
  307. /* no alignment needed */
  308. void (*flac_compute_autocorr)(const int32_t *data, int len, int lag, double *autoc);
  309. /* assume len is a multiple of 8, and arrays are 16-byte aligned */
  310. void (*vector_fmul)(float *dst, const float *src, int len);
  311. void (*vector_fmul_reverse)(float *dst, const float *src0, const float *src1, int len);
  312. /* assume len is a multiple of 8, and src arrays are 16-byte aligned */
  313. void (*vector_fmul_add_add)(float *dst, const float *src0, const float *src1, const float *src2, int src3, int len, int step);
  314. /* C version: convert floats from the range [384.0,386.0] to ints in [-32768,32767]
  315. * simd versions: convert floats from [-32768.0,32767.0] without rescaling and arrays are 16byte aligned */
  316. void (*float_to_int16)(int16_t *dst, const float *src, int len);
  317. /* (I)DCT */
  318. void (*fdct)(DCTELEM *block/* align 16*/);
  319. void (*fdct248)(DCTELEM *block/* align 16*/);
  320. /* IDCT really*/
  321. void (*idct)(DCTELEM *block/* align 16*/);
  322. /**
  323. * block -> idct -> clip to unsigned 8 bit -> dest.
  324. * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...)
  325. * @param line_size size in bytes of a horizontal line of dest
  326. */
  327. void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
  328. /**
  329. * block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
  330. * @param line_size size in bytes of a horizontal line of dest
  331. */
  332. void (*idct_add)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
  333. /**
  334. * idct input permutation.
  335. * several optimized IDCTs need a permutated input (relative to the normal order of the reference
  336. * IDCT)
  337. * this permutation must be performed before the idct_put/add, note, normally this can be merged
  338. * with the zigzag/alternate scan<br>
  339. * an example to avoid confusion:
  340. * - (->decode coeffs -> zigzag reorder -> dequant -> reference idct ->...)
  341. * - (x -> referece dct -> reference idct -> x)
  342. * - (x -> referece dct -> simple_mmx_perm = idct_permutation -> simple_idct_mmx -> x)
  343. * - (->decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant -> simple_idct_mmx ->...)
  344. */
  345. uint8_t idct_permutation[64];
  346. int idct_permutation_type;
  347. #define FF_NO_IDCT_PERM 1
  348. #define FF_LIBMPEG2_IDCT_PERM 2
  349. #define FF_SIMPLE_IDCT_PERM 3
  350. #define FF_TRANSPOSE_IDCT_PERM 4
  351. #define FF_PARTTRANS_IDCT_PERM 5
  352. #define FF_SSE2_IDCT_PERM 6
  353. int (*try_8x8basis)(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale);
  354. void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale);
  355. #define BASIS_SHIFT 16
  356. #define RECON_SHIFT 6
  357. void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w);
  358. #define EDGE_WIDTH 16
  359. /* h264 functions */
  360. void (*h264_idct_add)(uint8_t *dst, DCTELEM *block, int stride);
  361. void (*h264_idct8_add)(uint8_t *dst, DCTELEM *block, int stride);
  362. void (*h264_idct_dc_add)(uint8_t *dst, DCTELEM *block, int stride);
  363. void (*h264_idct8_dc_add)(uint8_t *dst, DCTELEM *block, int stride);
  364. void (*h264_dct)(DCTELEM block[4][4]);
  365. /* snow wavelet */
  366. void (*vertical_compose97i)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width);
  367. void (*horizontal_compose97i)(IDWTELEM *b, int width);
  368. void (*inner_add_yblock)(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h, int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8);
  369. void (*prefetch)(void *mem, int stride, int h);
  370. void (*shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
  371. /* vc1 functions */
  372. void (*vc1_inv_trans_8x8)(DCTELEM *b);
  373. void (*vc1_inv_trans_8x4)(uint8_t *dest, int line_size, DCTELEM *block);
  374. void (*vc1_inv_trans_4x8)(uint8_t *dest, int line_size, DCTELEM *block);
  375. void (*vc1_inv_trans_4x4)(uint8_t *dest, int line_size, DCTELEM *block);
  376. void (*vc1_v_overlap)(uint8_t* src, int stride);
  377. void (*vc1_h_overlap)(uint8_t* src, int stride);
  378. /* put 8x8 block with bicubic interpolation and quarterpel precision
  379. * last argument is actually round value instead of height
  380. */
  381. op_pixels_func put_vc1_mspel_pixels_tab[16];
  382. /* intrax8 functions */
  383. void (*x8_spatial_compensation[12])(uint8_t *src , uint8_t *dst, int linesize);
  384. void (*x8_setup_spatial_compensation)(uint8_t *src, uint8_t *dst, int linesize,
  385. int * range, int * sum, int edges);
  386. } DSPContext;
  387. void dsputil_static_init(void);
  388. void dsputil_init(DSPContext* p, AVCodecContext *avctx);
  389. int ff_check_alignment(void);
  390. /**
  391. * permute block according to permuatation.
  392. * @param last last non zero element in scantable order
  393. */
  394. void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last);
  395. void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type);
  396. #define BYTE_VEC32(c) ((c)*0x01010101UL)
  397. static inline uint32_t rnd_avg32(uint32_t a, uint32_t b)
  398. {
  399. return (a | b) - (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
  400. }
  401. static inline uint32_t no_rnd_avg32(uint32_t a, uint32_t b)
  402. {
  403. return (a & b) + (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
  404. }
  405. static inline int get_penalty_factor(int lambda, int lambda2, int type){
  406. switch(type&0xFF){
  407. default:
  408. case FF_CMP_SAD:
  409. return lambda>>FF_LAMBDA_SHIFT;
  410. case FF_CMP_DCT:
  411. return (3*lambda)>>(FF_LAMBDA_SHIFT+1);
  412. case FF_CMP_W53:
  413. return (4*lambda)>>(FF_LAMBDA_SHIFT);
  414. case FF_CMP_W97:
  415. return (2*lambda)>>(FF_LAMBDA_SHIFT);
  416. case FF_CMP_SATD:
  417. case FF_CMP_DCT264:
  418. return (2*lambda)>>FF_LAMBDA_SHIFT;
  419. case FF_CMP_RD:
  420. case FF_CMP_PSNR:
  421. case FF_CMP_SSE:
  422. case FF_CMP_NSSE:
  423. return lambda2>>FF_LAMBDA_SHIFT;
  424. case FF_CMP_BIT:
  425. return 1;
  426. }
  427. }
  428. /**
  429. * Empty mmx state.
  430. * this must be called between any dsp function and float/double code.
  431. * for example sin(); dsp->idct_put(); emms_c(); cos()
  432. */
  433. #define emms_c()
  434. /* should be defined by architectures supporting
  435. one or more MultiMedia extension */
  436. int mm_support(void);
  437. void dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx);
  438. void dsputil_init_armv4l(DSPContext* c, AVCodecContext *avctx);
  439. void dsputil_init_bfin(DSPContext* c, AVCodecContext *avctx);
  440. void dsputil_init_mlib(DSPContext* c, AVCodecContext *avctx);
  441. void dsputil_init_mmi(DSPContext* c, AVCodecContext *avctx);
  442. void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx);
  443. void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx);
  444. void dsputil_init_sh4(DSPContext* c, AVCodecContext *avctx);
  445. void dsputil_init_vis(DSPContext* c, AVCodecContext *avctx);
  446. #define DECLARE_ALIGNED_16(t, v) DECLARE_ALIGNED(16, t, v)
  447. #if defined(HAVE_MMX)
  448. #undef emms_c
  449. #define MM_MMX 0x0001 /* standard MMX */
  450. #define MM_3DNOW 0x0004 /* AMD 3DNOW */
  451. #define MM_MMXEXT 0x0002 /* SSE integer functions or AMD MMX ext */
  452. #define MM_SSE 0x0008 /* SSE functions */
  453. #define MM_SSE2 0x0010 /* PIV SSE2 functions */
  454. #define MM_3DNOWEXT 0x0020 /* AMD 3DNowExt */
  455. #define MM_SSE3 0x0040 /* Prescott SSE3 functions */
  456. #define MM_SSSE3 0x0080 /* Conroe SSSE3 functions */
  457. extern int mm_flags;
  458. void add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
  459. void put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
  460. void put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
  461. static inline void emms(void)
  462. {
  463. asm volatile ("emms;":::"memory");
  464. }
  465. #define emms_c() \
  466. {\
  467. if (mm_flags & MM_MMX)\
  468. emms();\
  469. }
  470. void dsputil_init_pix_mmx(DSPContext* c, AVCodecContext *avctx);
  471. #elif defined(ARCH_ARMV4L)
  472. #define MM_IWMMXT 0x0100 /* XScale IWMMXT */
  473. extern int mm_flags;
  474. #elif defined(ARCH_POWERPC)
  475. #define MM_ALTIVEC 0x0001 /* standard AltiVec */
  476. extern int mm_flags;
  477. #define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(16, t, v)
  478. #define STRIDE_ALIGN 16
  479. #elif defined(HAVE_MMI)
  480. #define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(16, t, v)
  481. #define STRIDE_ALIGN 16
  482. #else
  483. #define mm_flags 0
  484. #define mm_support() 0
  485. #endif
  486. #ifndef DECLARE_ALIGNED_8
  487. # define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(8, t, v)
  488. #endif
  489. #ifndef STRIDE_ALIGN
  490. # define STRIDE_ALIGN 8
  491. #endif
  492. /* PSNR */
  493. void get_psnr(uint8_t *orig_image[3], uint8_t *coded_image[3],
  494. int orig_linesize[3], int coded_linesize,
  495. AVCodecContext *avctx);
  496. /* FFT computation */
  497. /* NOTE: soon integer code will be added, so you must use the
  498. FFTSample type */
  499. typedef float FFTSample;
  500. struct MDCTContext;
  501. typedef struct FFTComplex {
  502. FFTSample re, im;
  503. } FFTComplex;
  504. typedef struct FFTContext {
  505. int nbits;
  506. int inverse;
  507. uint16_t *revtab;
  508. FFTComplex *exptab;
  509. FFTComplex *exptab1; /* only used by SSE code */
  510. void (*fft_calc)(struct FFTContext *s, FFTComplex *z);
  511. void (*imdct_calc)(struct MDCTContext *s, FFTSample *output,
  512. const FFTSample *input, FFTSample *tmp);
  513. } FFTContext;
  514. int ff_fft_init(FFTContext *s, int nbits, int inverse);
  515. void ff_fft_permute(FFTContext *s, FFTComplex *z);
  516. void ff_fft_calc_c(FFTContext *s, FFTComplex *z);
  517. void ff_fft_calc_sse(FFTContext *s, FFTComplex *z);
  518. void ff_fft_calc_3dn(FFTContext *s, FFTComplex *z);
  519. void ff_fft_calc_3dn2(FFTContext *s, FFTComplex *z);
  520. void ff_fft_calc_altivec(FFTContext *s, FFTComplex *z);
  521. static inline void ff_fft_calc(FFTContext *s, FFTComplex *z)
  522. {
  523. s->fft_calc(s, z);
  524. }
  525. void ff_fft_end(FFTContext *s);
  526. /* MDCT computation */
  527. typedef struct MDCTContext {
  528. int n; /* size of MDCT (i.e. number of input data * 2) */
  529. int nbits; /* n = 2^nbits */
  530. /* pre/post rotation tables */
  531. FFTSample *tcos;
  532. FFTSample *tsin;
  533. FFTContext fft;
  534. } MDCTContext;
  535. /**
  536. * Generate a Kaiser-Bessel Derived Window.
  537. * @param window pointer to half window
  538. * @param alpha determines window shape
  539. * @param n size of half window
  540. */
  541. void ff_kbd_window_init(float *window, float alpha, int n);
  542. /**
  543. * Generate a sine window.
  544. * @param window pointer to half window
  545. * @param n size of half window
  546. */
  547. void ff_sine_window_init(float *window, int n);
  548. int ff_mdct_init(MDCTContext *s, int nbits, int inverse);
  549. void ff_imdct_calc(MDCTContext *s, FFTSample *output,
  550. const FFTSample *input, FFTSample *tmp);
  551. void ff_imdct_calc_3dn2(MDCTContext *s, FFTSample *output,
  552. const FFTSample *input, FFTSample *tmp);
  553. void ff_imdct_calc_sse(MDCTContext *s, FFTSample *output,
  554. const FFTSample *input, FFTSample *tmp);
  555. void ff_mdct_calc(MDCTContext *s, FFTSample *out,
  556. const FFTSample *input, FFTSample *tmp);
  557. void ff_mdct_end(MDCTContext *s);
  558. #define WRAPPER8_16(name8, name16)\
  559. static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
  560. return name8(s, dst , src , stride, h)\
  561. +name8(s, dst+8 , src+8 , stride, h);\
  562. }
  563. #define WRAPPER8_16_SQ(name8, name16)\
  564. static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
  565. int score=0;\
  566. score +=name8(s, dst , src , stride, 8);\
  567. score +=name8(s, dst+8 , src+8 , stride, 8);\
  568. if(h==16){\
  569. dst += 8*stride;\
  570. src += 8*stride;\
  571. score +=name8(s, dst , src , stride, 8);\
  572. score +=name8(s, dst+8 , src+8 , stride, 8);\
  573. }\
  574. return score;\
  575. }
  576. static inline void copy_block2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
  577. {
  578. int i;
  579. for(i=0; i<h; i++)
  580. {
  581. AV_WN16(dst , AV_RN16(src ));
  582. dst+=dstStride;
  583. src+=srcStride;
  584. }
  585. }
  586. static inline void copy_block4(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
  587. {
  588. int i;
  589. for(i=0; i<h; i++)
  590. {
  591. AV_WN32(dst , AV_RN32(src ));
  592. dst+=dstStride;
  593. src+=srcStride;
  594. }
  595. }
  596. static inline void copy_block8(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
  597. {
  598. int i;
  599. for(i=0; i<h; i++)
  600. {
  601. AV_WN32(dst , AV_RN32(src ));
  602. AV_WN32(dst+4 , AV_RN32(src+4 ));
  603. dst+=dstStride;
  604. src+=srcStride;
  605. }
  606. }
  607. static inline void copy_block9(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
  608. {
  609. int i;
  610. for(i=0; i<h; i++)
  611. {
  612. AV_WN32(dst , AV_RN32(src ));
  613. AV_WN32(dst+4 , AV_RN32(src+4 ));
  614. dst[8]= src[8];
  615. dst+=dstStride;
  616. src+=srcStride;
  617. }
  618. }
  619. static inline void copy_block16(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
  620. {
  621. int i;
  622. for(i=0; i<h; i++)
  623. {
  624. AV_WN32(dst , AV_RN32(src ));
  625. AV_WN32(dst+4 , AV_RN32(src+4 ));
  626. AV_WN32(dst+8 , AV_RN32(src+8 ));
  627. AV_WN32(dst+12, AV_RN32(src+12));
  628. dst+=dstStride;
  629. src+=srcStride;
  630. }
  631. }
  632. static inline void copy_block17(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
  633. {
  634. int i;
  635. for(i=0; i<h; i++)
  636. {
  637. AV_WN32(dst , AV_RN32(src ));
  638. AV_WN32(dst+4 , AV_RN32(src+4 ));
  639. AV_WN32(dst+8 , AV_RN32(src+8 ));
  640. AV_WN32(dst+12, AV_RN32(src+12));
  641. dst[16]= src[16];
  642. dst+=dstStride;
  643. src+=srcStride;
  644. }
  645. }
  646. #endif /* FFMPEG_DSPUTIL_H */