dsputil.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  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. int (*try_8x8basis)(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale);
  353. void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale);
  354. #define BASIS_SHIFT 16
  355. #define RECON_SHIFT 6
  356. void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w);
  357. #define EDGE_WIDTH 16
  358. /* h264 functions */
  359. void (*h264_idct_add)(uint8_t *dst, DCTELEM *block, int stride);
  360. void (*h264_idct8_add)(uint8_t *dst, DCTELEM *block, int stride);
  361. void (*h264_idct_dc_add)(uint8_t *dst, DCTELEM *block, int stride);
  362. void (*h264_idct8_dc_add)(uint8_t *dst, DCTELEM *block, int stride);
  363. void (*h264_dct)(DCTELEM block[4][4]);
  364. /* snow wavelet */
  365. void (*vertical_compose97i)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width);
  366. void (*horizontal_compose97i)(IDWTELEM *b, int width);
  367. 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);
  368. void (*prefetch)(void *mem, int stride, int h);
  369. void (*shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
  370. /* vc1 functions */
  371. void (*vc1_inv_trans_8x8)(DCTELEM *b);
  372. void (*vc1_inv_trans_8x4)(uint8_t *dest, int line_size, DCTELEM *block);
  373. void (*vc1_inv_trans_4x8)(uint8_t *dest, int line_size, DCTELEM *block);
  374. void (*vc1_inv_trans_4x4)(uint8_t *dest, int line_size, DCTELEM *block);
  375. void (*vc1_v_overlap)(uint8_t* src, int stride);
  376. void (*vc1_h_overlap)(uint8_t* src, int stride);
  377. /* put 8x8 block with bicubic interpolation and quarterpel precision
  378. * last argument is actually round value instead of height
  379. */
  380. op_pixels_func put_vc1_mspel_pixels_tab[16];
  381. /* intrax8 functions */
  382. void (*x8_spatial_compensation[12])(uint8_t *src , uint8_t *dst, int linesize);
  383. void (*x8_setup_spatial_compensation)(uint8_t *src, uint8_t *dst, int linesize,
  384. int * range, int * sum, int edges);
  385. } DSPContext;
  386. void dsputil_static_init(void);
  387. void dsputil_init(DSPContext* p, AVCodecContext *avctx);
  388. int ff_check_alignment(void);
  389. /**
  390. * permute block according to permuatation.
  391. * @param last last non zero element in scantable order
  392. */
  393. void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last);
  394. void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type);
  395. #define BYTE_VEC32(c) ((c)*0x01010101UL)
  396. static inline uint32_t rnd_avg32(uint32_t a, uint32_t b)
  397. {
  398. return (a | b) - (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
  399. }
  400. static inline uint32_t no_rnd_avg32(uint32_t a, uint32_t b)
  401. {
  402. return (a & b) + (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
  403. }
  404. static inline int get_penalty_factor(int lambda, int lambda2, int type){
  405. switch(type&0xFF){
  406. default:
  407. case FF_CMP_SAD:
  408. return lambda>>FF_LAMBDA_SHIFT;
  409. case FF_CMP_DCT:
  410. return (3*lambda)>>(FF_LAMBDA_SHIFT+1);
  411. case FF_CMP_W53:
  412. return (4*lambda)>>(FF_LAMBDA_SHIFT);
  413. case FF_CMP_W97:
  414. return (2*lambda)>>(FF_LAMBDA_SHIFT);
  415. case FF_CMP_SATD:
  416. case FF_CMP_DCT264:
  417. return (2*lambda)>>FF_LAMBDA_SHIFT;
  418. case FF_CMP_RD:
  419. case FF_CMP_PSNR:
  420. case FF_CMP_SSE:
  421. case FF_CMP_NSSE:
  422. return lambda2>>FF_LAMBDA_SHIFT;
  423. case FF_CMP_BIT:
  424. return 1;
  425. }
  426. }
  427. /**
  428. * Empty mmx state.
  429. * this must be called between any dsp function and float/double code.
  430. * for example sin(); dsp->idct_put(); emms_c(); cos()
  431. */
  432. #define emms_c()
  433. /* should be defined by architectures supporting
  434. one or more MultiMedia extension */
  435. int mm_support(void);
  436. void dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx);
  437. void dsputil_init_armv4l(DSPContext* c, AVCodecContext *avctx);
  438. void dsputil_init_bfin(DSPContext* c, AVCodecContext *avctx);
  439. void dsputil_init_mlib(DSPContext* c, AVCodecContext *avctx);
  440. void dsputil_init_mmi(DSPContext* c, AVCodecContext *avctx);
  441. void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx);
  442. void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx);
  443. void dsputil_init_sh4(DSPContext* c, AVCodecContext *avctx);
  444. void dsputil_init_vis(DSPContext* c, AVCodecContext *avctx);
  445. #define DECLARE_ALIGNED_16(t, v) DECLARE_ALIGNED(16, t, v)
  446. #if defined(HAVE_MMX)
  447. #undef emms_c
  448. #define MM_MMX 0x0001 /* standard MMX */
  449. #define MM_3DNOW 0x0004 /* AMD 3DNOW */
  450. #define MM_MMXEXT 0x0002 /* SSE integer functions or AMD MMX ext */
  451. #define MM_SSE 0x0008 /* SSE functions */
  452. #define MM_SSE2 0x0010 /* PIV SSE2 functions */
  453. #define MM_3DNOWEXT 0x0020 /* AMD 3DNowExt */
  454. #define MM_SSE3 0x0040 /* Prescott SSE3 functions */
  455. #define MM_SSSE3 0x0080 /* Conroe SSSE3 functions */
  456. extern int mm_flags;
  457. void add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
  458. void put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
  459. void put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
  460. static inline void emms(void)
  461. {
  462. asm volatile ("emms;":::"memory");
  463. }
  464. #define emms_c() \
  465. {\
  466. if (mm_flags & MM_MMX)\
  467. emms();\
  468. }
  469. void dsputil_init_pix_mmx(DSPContext* c, AVCodecContext *avctx);
  470. #elif defined(ARCH_ARMV4L)
  471. #define MM_IWMMXT 0x0100 /* XScale IWMMXT */
  472. extern int mm_flags;
  473. #elif defined(ARCH_POWERPC)
  474. #define MM_ALTIVEC 0x0001 /* standard AltiVec */
  475. extern int mm_flags;
  476. #define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(16, t, v)
  477. #define STRIDE_ALIGN 16
  478. #elif defined(HAVE_MMI)
  479. #define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(16, t, v)
  480. #define STRIDE_ALIGN 16
  481. #endif
  482. #ifndef DECLARE_ALIGNED_8
  483. # define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(8, t, v)
  484. #endif
  485. #ifndef STRIDE_ALIGN
  486. # define STRIDE_ALIGN 8
  487. #endif
  488. /* PSNR */
  489. void get_psnr(uint8_t *orig_image[3], uint8_t *coded_image[3],
  490. int orig_linesize[3], int coded_linesize,
  491. AVCodecContext *avctx);
  492. /* FFT computation */
  493. /* NOTE: soon integer code will be added, so you must use the
  494. FFTSample type */
  495. typedef float FFTSample;
  496. struct MDCTContext;
  497. typedef struct FFTComplex {
  498. FFTSample re, im;
  499. } FFTComplex;
  500. typedef struct FFTContext {
  501. int nbits;
  502. int inverse;
  503. uint16_t *revtab;
  504. FFTComplex *exptab;
  505. FFTComplex *exptab1; /* only used by SSE code */
  506. void (*fft_calc)(struct FFTContext *s, FFTComplex *z);
  507. void (*imdct_calc)(struct MDCTContext *s, FFTSample *output,
  508. const FFTSample *input, FFTSample *tmp);
  509. } FFTContext;
  510. int ff_fft_init(FFTContext *s, int nbits, int inverse);
  511. void ff_fft_permute(FFTContext *s, FFTComplex *z);
  512. void ff_fft_calc_c(FFTContext *s, FFTComplex *z);
  513. void ff_fft_calc_sse(FFTContext *s, FFTComplex *z);
  514. void ff_fft_calc_3dn(FFTContext *s, FFTComplex *z);
  515. void ff_fft_calc_3dn2(FFTContext *s, FFTComplex *z);
  516. void ff_fft_calc_altivec(FFTContext *s, FFTComplex *z);
  517. static inline void ff_fft_calc(FFTContext *s, FFTComplex *z)
  518. {
  519. s->fft_calc(s, z);
  520. }
  521. void ff_fft_end(FFTContext *s);
  522. /* MDCT computation */
  523. typedef struct MDCTContext {
  524. int n; /* size of MDCT (i.e. number of input data * 2) */
  525. int nbits; /* n = 2^nbits */
  526. /* pre/post rotation tables */
  527. FFTSample *tcos;
  528. FFTSample *tsin;
  529. FFTContext fft;
  530. } MDCTContext;
  531. /**
  532. * Generate a Kaiser-Bessel Derived Window.
  533. * @param window pointer to half window
  534. * @param alpha determines window shape
  535. * @param n size of half window
  536. */
  537. void ff_kbd_window_init(float *window, float alpha, int n);
  538. int ff_mdct_init(MDCTContext *s, int nbits, int inverse);
  539. void ff_imdct_calc(MDCTContext *s, FFTSample *output,
  540. const FFTSample *input, FFTSample *tmp);
  541. void ff_imdct_calc_3dn2(MDCTContext *s, FFTSample *output,
  542. const FFTSample *input, FFTSample *tmp);
  543. void ff_imdct_calc_sse(MDCTContext *s, FFTSample *output,
  544. const FFTSample *input, FFTSample *tmp);
  545. void ff_mdct_calc(MDCTContext *s, FFTSample *out,
  546. const FFTSample *input, FFTSample *tmp);
  547. void ff_mdct_end(MDCTContext *s);
  548. #define WRAPPER8_16(name8, name16)\
  549. static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
  550. return name8(s, dst , src , stride, h)\
  551. +name8(s, dst+8 , src+8 , stride, h);\
  552. }
  553. #define WRAPPER8_16_SQ(name8, name16)\
  554. static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
  555. int score=0;\
  556. score +=name8(s, dst , src , stride, 8);\
  557. score +=name8(s, dst+8 , src+8 , stride, 8);\
  558. if(h==16){\
  559. dst += 8*stride;\
  560. src += 8*stride;\
  561. score +=name8(s, dst , src , stride, 8);\
  562. score +=name8(s, dst+8 , src+8 , stride, 8);\
  563. }\
  564. return score;\
  565. }
  566. static inline void copy_block2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
  567. {
  568. int i;
  569. for(i=0; i<h; i++)
  570. {
  571. AV_WN16(dst , AV_RN16(src ));
  572. dst+=dstStride;
  573. src+=srcStride;
  574. }
  575. }
  576. static inline void copy_block4(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_WN32(dst , AV_RN32(src ));
  582. dst+=dstStride;
  583. src+=srcStride;
  584. }
  585. }
  586. static inline void copy_block8(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. AV_WN32(dst+4 , AV_RN32(src+4 ));
  593. dst+=dstStride;
  594. src+=srcStride;
  595. }
  596. }
  597. static inline void copy_block9(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
  598. {
  599. int i;
  600. for(i=0; i<h; i++)
  601. {
  602. AV_WN32(dst , AV_RN32(src ));
  603. AV_WN32(dst+4 , AV_RN32(src+4 ));
  604. dst[8]= src[8];
  605. dst+=dstStride;
  606. src+=srcStride;
  607. }
  608. }
  609. static inline void copy_block16(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
  610. {
  611. int i;
  612. for(i=0; i<h; i++)
  613. {
  614. AV_WN32(dst , AV_RN32(src ));
  615. AV_WN32(dst+4 , AV_RN32(src+4 ));
  616. AV_WN32(dst+8 , AV_RN32(src+8 ));
  617. AV_WN32(dst+12, AV_RN32(src+12));
  618. dst+=dstStride;
  619. src+=srcStride;
  620. }
  621. }
  622. static inline void copy_block17(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
  623. {
  624. int i;
  625. for(i=0; i<h; i++)
  626. {
  627. AV_WN32(dst , AV_RN32(src ));
  628. AV_WN32(dst+4 , AV_RN32(src+4 ));
  629. AV_WN32(dst+8 , AV_RN32(src+8 ));
  630. AV_WN32(dst+12, AV_RN32(src+12));
  631. dst[16]= src[16];
  632. dst+=dstStride;
  633. src+=srcStride;
  634. }
  635. }
  636. #endif /* FFMPEG_DSPUTIL_H */