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.

3086 lines
105KB

  1. /*
  2. * DSP utils
  3. * Copyright (c) 2000, 2001 Fabrice Bellard
  4. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  5. *
  6. * gmc & q-pel & 32/64 bit based MC by Michael Niedermayer <michaelni@gmx.at>
  7. *
  8. * This file is part of FFmpeg.
  9. *
  10. * FFmpeg is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * FFmpeg is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with FFmpeg; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. /**
  25. * @file
  26. * DSP utils
  27. */
  28. #include "libavutil/imgutils.h"
  29. #include "avcodec.h"
  30. #include "dsputil.h"
  31. #include "simple_idct.h"
  32. #include "faandct.h"
  33. #include "faanidct.h"
  34. #include "mathops.h"
  35. #include "mpegvideo.h"
  36. #include "config.h"
  37. #include "ac3dec.h"
  38. #include "vorbis.h"
  39. #include "diracdsp.h"
  40. uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP] = {0, };
  41. uint32_t ff_squareTbl[512] = {0, };
  42. #define BIT_DEPTH 9
  43. #include "dsputil_template.c"
  44. #undef BIT_DEPTH
  45. #define BIT_DEPTH 10
  46. #include "dsputil_template.c"
  47. #undef BIT_DEPTH
  48. #define BIT_DEPTH 8
  49. #include "dsputil_template.c"
  50. // 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size
  51. #define pb_7f (~0UL/255 * 0x7f)
  52. #define pb_80 (~0UL/255 * 0x80)
  53. const uint8_t ff_zigzag_direct[64] = {
  54. 0, 1, 8, 16, 9, 2, 3, 10,
  55. 17, 24, 32, 25, 18, 11, 4, 5,
  56. 12, 19, 26, 33, 40, 48, 41, 34,
  57. 27, 20, 13, 6, 7, 14, 21, 28,
  58. 35, 42, 49, 56, 57, 50, 43, 36,
  59. 29, 22, 15, 23, 30, 37, 44, 51,
  60. 58, 59, 52, 45, 38, 31, 39, 46,
  61. 53, 60, 61, 54, 47, 55, 62, 63
  62. };
  63. /* Specific zigzag scan for 248 idct. NOTE that unlike the
  64. specification, we interleave the fields */
  65. const uint8_t ff_zigzag248_direct[64] = {
  66. 0, 8, 1, 9, 16, 24, 2, 10,
  67. 17, 25, 32, 40, 48, 56, 33, 41,
  68. 18, 26, 3, 11, 4, 12, 19, 27,
  69. 34, 42, 49, 57, 50, 58, 35, 43,
  70. 20, 28, 5, 13, 6, 14, 21, 29,
  71. 36, 44, 51, 59, 52, 60, 37, 45,
  72. 22, 30, 7, 15, 23, 31, 38, 46,
  73. 53, 61, 54, 62, 39, 47, 55, 63,
  74. };
  75. /* not permutated inverse zigzag_direct + 1 for MMX quantizer */
  76. DECLARE_ALIGNED(16, uint16_t, ff_inv_zigzag_direct16)[64];
  77. const uint8_t ff_alternate_horizontal_scan[64] = {
  78. 0, 1, 2, 3, 8, 9, 16, 17,
  79. 10, 11, 4, 5, 6, 7, 15, 14,
  80. 13, 12, 19, 18, 24, 25, 32, 33,
  81. 26, 27, 20, 21, 22, 23, 28, 29,
  82. 30, 31, 34, 35, 40, 41, 48, 49,
  83. 42, 43, 36, 37, 38, 39, 44, 45,
  84. 46, 47, 50, 51, 56, 57, 58, 59,
  85. 52, 53, 54, 55, 60, 61, 62, 63,
  86. };
  87. const uint8_t ff_alternate_vertical_scan[64] = {
  88. 0, 8, 16, 24, 1, 9, 2, 10,
  89. 17, 25, 32, 40, 48, 56, 57, 49,
  90. 41, 33, 26, 18, 3, 11, 4, 12,
  91. 19, 27, 34, 42, 50, 58, 35, 43,
  92. 51, 59, 20, 28, 5, 13, 6, 14,
  93. 21, 29, 36, 44, 52, 60, 37, 45,
  94. 53, 61, 22, 30, 7, 15, 23, 31,
  95. 38, 46, 54, 62, 39, 47, 55, 63,
  96. };
  97. /* Input permutation for the simple_idct_mmx */
  98. static const uint8_t simple_mmx_permutation[64]={
  99. 0x00, 0x08, 0x04, 0x09, 0x01, 0x0C, 0x05, 0x0D,
  100. 0x10, 0x18, 0x14, 0x19, 0x11, 0x1C, 0x15, 0x1D,
  101. 0x20, 0x28, 0x24, 0x29, 0x21, 0x2C, 0x25, 0x2D,
  102. 0x12, 0x1A, 0x16, 0x1B, 0x13, 0x1E, 0x17, 0x1F,
  103. 0x02, 0x0A, 0x06, 0x0B, 0x03, 0x0E, 0x07, 0x0F,
  104. 0x30, 0x38, 0x34, 0x39, 0x31, 0x3C, 0x35, 0x3D,
  105. 0x22, 0x2A, 0x26, 0x2B, 0x23, 0x2E, 0x27, 0x2F,
  106. 0x32, 0x3A, 0x36, 0x3B, 0x33, 0x3E, 0x37, 0x3F,
  107. };
  108. static const uint8_t idct_sse2_row_perm[8] = {0, 4, 1, 5, 2, 6, 3, 7};
  109. void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable){
  110. int i;
  111. int end;
  112. st->scantable= src_scantable;
  113. for(i=0; i<64; i++){
  114. int j;
  115. j = src_scantable[i];
  116. st->permutated[i] = permutation[j];
  117. }
  118. end=-1;
  119. for(i=0; i<64; i++){
  120. int j;
  121. j = st->permutated[i];
  122. if(j>end) end=j;
  123. st->raster_end[i]= end;
  124. }
  125. }
  126. void ff_init_scantable_permutation(uint8_t *idct_permutation,
  127. int idct_permutation_type)
  128. {
  129. int i;
  130. switch(idct_permutation_type){
  131. case FF_NO_IDCT_PERM:
  132. for(i=0; i<64; i++)
  133. idct_permutation[i]= i;
  134. break;
  135. case FF_LIBMPEG2_IDCT_PERM:
  136. for(i=0; i<64; i++)
  137. idct_permutation[i]= (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
  138. break;
  139. case FF_SIMPLE_IDCT_PERM:
  140. for(i=0; i<64; i++)
  141. idct_permutation[i]= simple_mmx_permutation[i];
  142. break;
  143. case FF_TRANSPOSE_IDCT_PERM:
  144. for(i=0; i<64; i++)
  145. idct_permutation[i]= ((i&7)<<3) | (i>>3);
  146. break;
  147. case FF_PARTTRANS_IDCT_PERM:
  148. for(i=0; i<64; i++)
  149. idct_permutation[i]= (i&0x24) | ((i&3)<<3) | ((i>>3)&3);
  150. break;
  151. case FF_SSE2_IDCT_PERM:
  152. for(i=0; i<64; i++)
  153. idct_permutation[i]= (i&0x38) | idct_sse2_row_perm[i&7];
  154. break;
  155. default:
  156. av_log(NULL, AV_LOG_ERROR, "Internal error, IDCT permutation not set\n");
  157. }
  158. }
  159. static int pix_sum_c(uint8_t * pix, int line_size)
  160. {
  161. int s, i, j;
  162. s = 0;
  163. for (i = 0; i < 16; i++) {
  164. for (j = 0; j < 16; j += 8) {
  165. s += pix[0];
  166. s += pix[1];
  167. s += pix[2];
  168. s += pix[3];
  169. s += pix[4];
  170. s += pix[5];
  171. s += pix[6];
  172. s += pix[7];
  173. pix += 8;
  174. }
  175. pix += line_size - 16;
  176. }
  177. return s;
  178. }
  179. static int pix_norm1_c(uint8_t * pix, int line_size)
  180. {
  181. int s, i, j;
  182. uint32_t *sq = ff_squareTbl + 256;
  183. s = 0;
  184. for (i = 0; i < 16; i++) {
  185. for (j = 0; j < 16; j += 8) {
  186. #if 0
  187. s += sq[pix[0]];
  188. s += sq[pix[1]];
  189. s += sq[pix[2]];
  190. s += sq[pix[3]];
  191. s += sq[pix[4]];
  192. s += sq[pix[5]];
  193. s += sq[pix[6]];
  194. s += sq[pix[7]];
  195. #else
  196. #if HAVE_FAST_64BIT
  197. register uint64_t x=*(uint64_t*)pix;
  198. s += sq[x&0xff];
  199. s += sq[(x>>8)&0xff];
  200. s += sq[(x>>16)&0xff];
  201. s += sq[(x>>24)&0xff];
  202. s += sq[(x>>32)&0xff];
  203. s += sq[(x>>40)&0xff];
  204. s += sq[(x>>48)&0xff];
  205. s += sq[(x>>56)&0xff];
  206. #else
  207. register uint32_t x=*(uint32_t*)pix;
  208. s += sq[x&0xff];
  209. s += sq[(x>>8)&0xff];
  210. s += sq[(x>>16)&0xff];
  211. s += sq[(x>>24)&0xff];
  212. x=*(uint32_t*)(pix+4);
  213. s += sq[x&0xff];
  214. s += sq[(x>>8)&0xff];
  215. s += sq[(x>>16)&0xff];
  216. s += sq[(x>>24)&0xff];
  217. #endif
  218. #endif
  219. pix += 8;
  220. }
  221. pix += line_size - 16;
  222. }
  223. return s;
  224. }
  225. static void bswap_buf(uint32_t *dst, const uint32_t *src, int w){
  226. int i;
  227. for(i=0; i+8<=w; i+=8){
  228. dst[i+0]= av_bswap32(src[i+0]);
  229. dst[i+1]= av_bswap32(src[i+1]);
  230. dst[i+2]= av_bswap32(src[i+2]);
  231. dst[i+3]= av_bswap32(src[i+3]);
  232. dst[i+4]= av_bswap32(src[i+4]);
  233. dst[i+5]= av_bswap32(src[i+5]);
  234. dst[i+6]= av_bswap32(src[i+6]);
  235. dst[i+7]= av_bswap32(src[i+7]);
  236. }
  237. for(;i<w; i++){
  238. dst[i+0]= av_bswap32(src[i+0]);
  239. }
  240. }
  241. static void bswap16_buf(uint16_t *dst, const uint16_t *src, int len)
  242. {
  243. while (len--)
  244. *dst++ = av_bswap16(*src++);
  245. }
  246. static int sse4_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h)
  247. {
  248. int s, i;
  249. uint32_t *sq = ff_squareTbl + 256;
  250. s = 0;
  251. for (i = 0; i < h; i++) {
  252. s += sq[pix1[0] - pix2[0]];
  253. s += sq[pix1[1] - pix2[1]];
  254. s += sq[pix1[2] - pix2[2]];
  255. s += sq[pix1[3] - pix2[3]];
  256. pix1 += line_size;
  257. pix2 += line_size;
  258. }
  259. return s;
  260. }
  261. static int sse8_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h)
  262. {
  263. int s, i;
  264. uint32_t *sq = ff_squareTbl + 256;
  265. s = 0;
  266. for (i = 0; i < h; i++) {
  267. s += sq[pix1[0] - pix2[0]];
  268. s += sq[pix1[1] - pix2[1]];
  269. s += sq[pix1[2] - pix2[2]];
  270. s += sq[pix1[3] - pix2[3]];
  271. s += sq[pix1[4] - pix2[4]];
  272. s += sq[pix1[5] - pix2[5]];
  273. s += sq[pix1[6] - pix2[6]];
  274. s += sq[pix1[7] - pix2[7]];
  275. pix1 += line_size;
  276. pix2 += line_size;
  277. }
  278. return s;
  279. }
  280. static int sse16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  281. {
  282. int s, i;
  283. uint32_t *sq = ff_squareTbl + 256;
  284. s = 0;
  285. for (i = 0; i < h; i++) {
  286. s += sq[pix1[ 0] - pix2[ 0]];
  287. s += sq[pix1[ 1] - pix2[ 1]];
  288. s += sq[pix1[ 2] - pix2[ 2]];
  289. s += sq[pix1[ 3] - pix2[ 3]];
  290. s += sq[pix1[ 4] - pix2[ 4]];
  291. s += sq[pix1[ 5] - pix2[ 5]];
  292. s += sq[pix1[ 6] - pix2[ 6]];
  293. s += sq[pix1[ 7] - pix2[ 7]];
  294. s += sq[pix1[ 8] - pix2[ 8]];
  295. s += sq[pix1[ 9] - pix2[ 9]];
  296. s += sq[pix1[10] - pix2[10]];
  297. s += sq[pix1[11] - pix2[11]];
  298. s += sq[pix1[12] - pix2[12]];
  299. s += sq[pix1[13] - pix2[13]];
  300. s += sq[pix1[14] - pix2[14]];
  301. s += sq[pix1[15] - pix2[15]];
  302. pix1 += line_size;
  303. pix2 += line_size;
  304. }
  305. return s;
  306. }
  307. static void diff_pixels_c(DCTELEM *restrict block, const uint8_t *s1,
  308. const uint8_t *s2, int stride){
  309. int i;
  310. /* read the pixels */
  311. for(i=0;i<8;i++) {
  312. block[0] = s1[0] - s2[0];
  313. block[1] = s1[1] - s2[1];
  314. block[2] = s1[2] - s2[2];
  315. block[3] = s1[3] - s2[3];
  316. block[4] = s1[4] - s2[4];
  317. block[5] = s1[5] - s2[5];
  318. block[6] = s1[6] - s2[6];
  319. block[7] = s1[7] - s2[7];
  320. s1 += stride;
  321. s2 += stride;
  322. block += 8;
  323. }
  324. }
  325. void ff_put_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels,
  326. int line_size)
  327. {
  328. int i;
  329. /* read the pixels */
  330. for(i=0;i<8;i++) {
  331. pixels[0] = av_clip_uint8(block[0]);
  332. pixels[1] = av_clip_uint8(block[1]);
  333. pixels[2] = av_clip_uint8(block[2]);
  334. pixels[3] = av_clip_uint8(block[3]);
  335. pixels[4] = av_clip_uint8(block[4]);
  336. pixels[5] = av_clip_uint8(block[5]);
  337. pixels[6] = av_clip_uint8(block[6]);
  338. pixels[7] = av_clip_uint8(block[7]);
  339. pixels += line_size;
  340. block += 8;
  341. }
  342. }
  343. void ff_put_signed_pixels_clamped_c(const DCTELEM *block,
  344. uint8_t *restrict pixels,
  345. int line_size)
  346. {
  347. int i, j;
  348. for (i = 0; i < 8; i++) {
  349. for (j = 0; j < 8; j++) {
  350. if (*block < -128)
  351. *pixels = 0;
  352. else if (*block > 127)
  353. *pixels = 255;
  354. else
  355. *pixels = (uint8_t)(*block + 128);
  356. block++;
  357. pixels++;
  358. }
  359. pixels += (line_size - 8);
  360. }
  361. }
  362. void ff_add_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels,
  363. int line_size)
  364. {
  365. int i;
  366. /* read the pixels */
  367. for(i=0;i<8;i++) {
  368. pixels[0] = av_clip_uint8(pixels[0] + block[0]);
  369. pixels[1] = av_clip_uint8(pixels[1] + block[1]);
  370. pixels[2] = av_clip_uint8(pixels[2] + block[2]);
  371. pixels[3] = av_clip_uint8(pixels[3] + block[3]);
  372. pixels[4] = av_clip_uint8(pixels[4] + block[4]);
  373. pixels[5] = av_clip_uint8(pixels[5] + block[5]);
  374. pixels[6] = av_clip_uint8(pixels[6] + block[6]);
  375. pixels[7] = av_clip_uint8(pixels[7] + block[7]);
  376. pixels += line_size;
  377. block += 8;
  378. }
  379. }
  380. static int sum_abs_dctelem_c(DCTELEM *block)
  381. {
  382. int sum=0, i;
  383. for(i=0; i<64; i++)
  384. sum+= FFABS(block[i]);
  385. return sum;
  386. }
  387. static void fill_block16_c(uint8_t *block, uint8_t value, int line_size, int h)
  388. {
  389. int i;
  390. for (i = 0; i < h; i++) {
  391. memset(block, value, 16);
  392. block += line_size;
  393. }
  394. }
  395. static void fill_block8_c(uint8_t *block, uint8_t value, int line_size, int h)
  396. {
  397. int i;
  398. for (i = 0; i < h; i++) {
  399. memset(block, value, 8);
  400. block += line_size;
  401. }
  402. }
  403. #define avg2(a,b) ((a+b+1)>>1)
  404. #define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
  405. static void gmc1_c(uint8_t *dst, uint8_t *src, int stride, int h, int x16, int y16, int rounder)
  406. {
  407. const int A=(16-x16)*(16-y16);
  408. const int B=( x16)*(16-y16);
  409. const int C=(16-x16)*( y16);
  410. const int D=( x16)*( y16);
  411. int i;
  412. for(i=0; i<h; i++)
  413. {
  414. dst[0]= (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + rounder)>>8;
  415. dst[1]= (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + rounder)>>8;
  416. dst[2]= (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + rounder)>>8;
  417. dst[3]= (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + rounder)>>8;
  418. dst[4]= (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + rounder)>>8;
  419. dst[5]= (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + rounder)>>8;
  420. dst[6]= (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + rounder)>>8;
  421. dst[7]= (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + rounder)>>8;
  422. dst+= stride;
  423. src+= stride;
  424. }
  425. }
  426. void ff_gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
  427. int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height)
  428. {
  429. int y, vx, vy;
  430. const int s= 1<<shift;
  431. width--;
  432. height--;
  433. for(y=0; y<h; y++){
  434. int x;
  435. vx= ox;
  436. vy= oy;
  437. for(x=0; x<8; x++){ //XXX FIXME optimize
  438. int src_x, src_y, frac_x, frac_y, index;
  439. src_x= vx>>16;
  440. src_y= vy>>16;
  441. frac_x= src_x&(s-1);
  442. frac_y= src_y&(s-1);
  443. src_x>>=shift;
  444. src_y>>=shift;
  445. if((unsigned)src_x < width){
  446. if((unsigned)src_y < height){
  447. index= src_x + src_y*stride;
  448. dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
  449. + src[index +1]* frac_x )*(s-frac_y)
  450. + ( src[index+stride ]*(s-frac_x)
  451. + src[index+stride+1]* frac_x )* frac_y
  452. + r)>>(shift*2);
  453. }else{
  454. index= src_x + av_clip(src_y, 0, height)*stride;
  455. dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
  456. + src[index +1]* frac_x )*s
  457. + r)>>(shift*2);
  458. }
  459. }else{
  460. if((unsigned)src_y < height){
  461. index= av_clip(src_x, 0, width) + src_y*stride;
  462. dst[y*stride + x]= ( ( src[index ]*(s-frac_y)
  463. + src[index+stride ]* frac_y )*s
  464. + r)>>(shift*2);
  465. }else{
  466. index= av_clip(src_x, 0, width) + av_clip(src_y, 0, height)*stride;
  467. dst[y*stride + x]= src[index ];
  468. }
  469. }
  470. vx+= dxx;
  471. vy+= dyx;
  472. }
  473. ox += dxy;
  474. oy += dyy;
  475. }
  476. }
  477. static inline void put_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  478. switch(width){
  479. case 2: put_pixels2_8_c (dst, src, stride, height); break;
  480. case 4: put_pixels4_8_c (dst, src, stride, height); break;
  481. case 8: put_pixels8_8_c (dst, src, stride, height); break;
  482. case 16:put_pixels16_8_c(dst, src, stride, height); break;
  483. }
  484. }
  485. static inline void put_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  486. int i,j;
  487. for (i=0; i < height; i++) {
  488. for (j=0; j < width; j++) {
  489. dst[j] = (683*(2*src[j] + src[j+1] + 1)) >> 11;
  490. }
  491. src += stride;
  492. dst += stride;
  493. }
  494. }
  495. static inline void put_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  496. int i,j;
  497. for (i=0; i < height; i++) {
  498. for (j=0; j < width; j++) {
  499. dst[j] = (683*(src[j] + 2*src[j+1] + 1)) >> 11;
  500. }
  501. src += stride;
  502. dst += stride;
  503. }
  504. }
  505. static inline void put_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  506. int i,j;
  507. for (i=0; i < height; i++) {
  508. for (j=0; j < width; j++) {
  509. dst[j] = (683*(2*src[j] + src[j+stride] + 1)) >> 11;
  510. }
  511. src += stride;
  512. dst += stride;
  513. }
  514. }
  515. static inline void put_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  516. int i,j;
  517. for (i=0; i < height; i++) {
  518. for (j=0; j < width; j++) {
  519. dst[j] = (2731*(4*src[j] + 3*src[j+1] + 3*src[j+stride] + 2*src[j+stride+1] + 6)) >> 15;
  520. }
  521. src += stride;
  522. dst += stride;
  523. }
  524. }
  525. static inline void put_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  526. int i,j;
  527. for (i=0; i < height; i++) {
  528. for (j=0; j < width; j++) {
  529. dst[j] = (2731*(3*src[j] + 2*src[j+1] + 4*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15;
  530. }
  531. src += stride;
  532. dst += stride;
  533. }
  534. }
  535. static inline void put_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  536. int i,j;
  537. for (i=0; i < height; i++) {
  538. for (j=0; j < width; j++) {
  539. dst[j] = (683*(src[j] + 2*src[j+stride] + 1)) >> 11;
  540. }
  541. src += stride;
  542. dst += stride;
  543. }
  544. }
  545. static inline void put_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  546. int i,j;
  547. for (i=0; i < height; i++) {
  548. for (j=0; j < width; j++) {
  549. dst[j] = (2731*(3*src[j] + 4*src[j+1] + 2*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15;
  550. }
  551. src += stride;
  552. dst += stride;
  553. }
  554. }
  555. static inline void put_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  556. int i,j;
  557. for (i=0; i < height; i++) {
  558. for (j=0; j < width; j++) {
  559. dst[j] = (2731*(2*src[j] + 3*src[j+1] + 3*src[j+stride] + 4*src[j+stride+1] + 6)) >> 15;
  560. }
  561. src += stride;
  562. dst += stride;
  563. }
  564. }
  565. static inline void avg_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  566. switch(width){
  567. case 2: avg_pixels2_8_c (dst, src, stride, height); break;
  568. case 4: avg_pixels4_8_c (dst, src, stride, height); break;
  569. case 8: avg_pixels8_8_c (dst, src, stride, height); break;
  570. case 16:avg_pixels16_8_c(dst, src, stride, height); break;
  571. }
  572. }
  573. static inline void avg_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  574. int i,j;
  575. for (i=0; i < height; i++) {
  576. for (j=0; j < width; j++) {
  577. dst[j] = (dst[j] + ((683*(2*src[j] + src[j+1] + 1)) >> 11) + 1) >> 1;
  578. }
  579. src += stride;
  580. dst += stride;
  581. }
  582. }
  583. static inline void avg_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  584. int i,j;
  585. for (i=0; i < height; i++) {
  586. for (j=0; j < width; j++) {
  587. dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+1] + 1)) >> 11) + 1) >> 1;
  588. }
  589. src += stride;
  590. dst += stride;
  591. }
  592. }
  593. static inline void avg_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  594. int i,j;
  595. for (i=0; i < height; i++) {
  596. for (j=0; j < width; j++) {
  597. dst[j] = (dst[j] + ((683*(2*src[j] + src[j+stride] + 1)) >> 11) + 1) >> 1;
  598. }
  599. src += stride;
  600. dst += stride;
  601. }
  602. }
  603. static inline void avg_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  604. int i,j;
  605. for (i=0; i < height; i++) {
  606. for (j=0; j < width; j++) {
  607. dst[j] = (dst[j] + ((2731*(4*src[j] + 3*src[j+1] + 3*src[j+stride] + 2*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
  608. }
  609. src += stride;
  610. dst += stride;
  611. }
  612. }
  613. static inline void avg_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  614. int i,j;
  615. for (i=0; i < height; i++) {
  616. for (j=0; j < width; j++) {
  617. dst[j] = (dst[j] + ((2731*(3*src[j] + 2*src[j+1] + 4*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
  618. }
  619. src += stride;
  620. dst += stride;
  621. }
  622. }
  623. static inline void avg_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  624. int i,j;
  625. for (i=0; i < height; i++) {
  626. for (j=0; j < width; j++) {
  627. dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+stride] + 1)) >> 11) + 1) >> 1;
  628. }
  629. src += stride;
  630. dst += stride;
  631. }
  632. }
  633. static inline void avg_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  634. int i,j;
  635. for (i=0; i < height; i++) {
  636. for (j=0; j < width; j++) {
  637. dst[j] = (dst[j] + ((2731*(3*src[j] + 4*src[j+1] + 2*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
  638. }
  639. src += stride;
  640. dst += stride;
  641. }
  642. }
  643. static inline void avg_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  644. int i,j;
  645. for (i=0; i < height; i++) {
  646. for (j=0; j < width; j++) {
  647. dst[j] = (dst[j] + ((2731*(2*src[j] + 3*src[j+1] + 3*src[j+stride] + 4*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
  648. }
  649. src += stride;
  650. dst += stride;
  651. }
  652. }
  653. #define QPEL_MC(r, OPNAME, RND, OP) \
  654. static void OPNAME ## mpeg4_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
  655. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  656. int i;\
  657. for(i=0; i<h; i++)\
  658. {\
  659. OP(dst[0], (src[0]+src[1])*20 - (src[0]+src[2])*6 + (src[1]+src[3])*3 - (src[2]+src[4]));\
  660. OP(dst[1], (src[1]+src[2])*20 - (src[0]+src[3])*6 + (src[0]+src[4])*3 - (src[1]+src[5]));\
  661. OP(dst[2], (src[2]+src[3])*20 - (src[1]+src[4])*6 + (src[0]+src[5])*3 - (src[0]+src[6]));\
  662. OP(dst[3], (src[3]+src[4])*20 - (src[2]+src[5])*6 + (src[1]+src[6])*3 - (src[0]+src[7]));\
  663. OP(dst[4], (src[4]+src[5])*20 - (src[3]+src[6])*6 + (src[2]+src[7])*3 - (src[1]+src[8]));\
  664. OP(dst[5], (src[5]+src[6])*20 - (src[4]+src[7])*6 + (src[3]+src[8])*3 - (src[2]+src[8]));\
  665. OP(dst[6], (src[6]+src[7])*20 - (src[5]+src[8])*6 + (src[4]+src[8])*3 - (src[3]+src[7]));\
  666. OP(dst[7], (src[7]+src[8])*20 - (src[6]+src[8])*6 + (src[5]+src[7])*3 - (src[4]+src[6]));\
  667. dst+=dstStride;\
  668. src+=srcStride;\
  669. }\
  670. }\
  671. \
  672. static void OPNAME ## mpeg4_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  673. const int w=8;\
  674. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  675. int i;\
  676. for(i=0; i<w; i++)\
  677. {\
  678. const int src0= src[0*srcStride];\
  679. const int src1= src[1*srcStride];\
  680. const int src2= src[2*srcStride];\
  681. const int src3= src[3*srcStride];\
  682. const int src4= src[4*srcStride];\
  683. const int src5= src[5*srcStride];\
  684. const int src6= src[6*srcStride];\
  685. const int src7= src[7*srcStride];\
  686. const int src8= src[8*srcStride];\
  687. OP(dst[0*dstStride], (src0+src1)*20 - (src0+src2)*6 + (src1+src3)*3 - (src2+src4));\
  688. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*6 + (src0+src4)*3 - (src1+src5));\
  689. OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*6 + (src0+src5)*3 - (src0+src6));\
  690. OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*6 + (src1+src6)*3 - (src0+src7));\
  691. OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*6 + (src2+src7)*3 - (src1+src8));\
  692. OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*6 + (src3+src8)*3 - (src2+src8));\
  693. OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*6 + (src4+src8)*3 - (src3+src7));\
  694. OP(dst[7*dstStride], (src7+src8)*20 - (src6+src8)*6 + (src5+src7)*3 - (src4+src6));\
  695. dst++;\
  696. src++;\
  697. }\
  698. }\
  699. \
  700. static void OPNAME ## mpeg4_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
  701. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  702. int i;\
  703. \
  704. for(i=0; i<h; i++)\
  705. {\
  706. OP(dst[ 0], (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]));\
  707. OP(dst[ 1], (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]));\
  708. OP(dst[ 2], (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]));\
  709. OP(dst[ 3], (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]));\
  710. OP(dst[ 4], (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]));\
  711. OP(dst[ 5], (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]));\
  712. OP(dst[ 6], (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]));\
  713. OP(dst[ 7], (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]));\
  714. OP(dst[ 8], (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]));\
  715. OP(dst[ 9], (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]));\
  716. OP(dst[10], (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]));\
  717. OP(dst[11], (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]));\
  718. OP(dst[12], (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]));\
  719. OP(dst[13], (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]));\
  720. OP(dst[14], (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]));\
  721. OP(dst[15], (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]));\
  722. dst+=dstStride;\
  723. src+=srcStride;\
  724. }\
  725. }\
  726. \
  727. static void OPNAME ## mpeg4_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  728. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  729. int i;\
  730. const int w=16;\
  731. for(i=0; i<w; i++)\
  732. {\
  733. const int src0= src[0*srcStride];\
  734. const int src1= src[1*srcStride];\
  735. const int src2= src[2*srcStride];\
  736. const int src3= src[3*srcStride];\
  737. const int src4= src[4*srcStride];\
  738. const int src5= src[5*srcStride];\
  739. const int src6= src[6*srcStride];\
  740. const int src7= src[7*srcStride];\
  741. const int src8= src[8*srcStride];\
  742. const int src9= src[9*srcStride];\
  743. const int src10= src[10*srcStride];\
  744. const int src11= src[11*srcStride];\
  745. const int src12= src[12*srcStride];\
  746. const int src13= src[13*srcStride];\
  747. const int src14= src[14*srcStride];\
  748. const int src15= src[15*srcStride];\
  749. const int src16= src[16*srcStride];\
  750. OP(dst[ 0*dstStride], (src0 +src1 )*20 - (src0 +src2 )*6 + (src1 +src3 )*3 - (src2 +src4 ));\
  751. OP(dst[ 1*dstStride], (src1 +src2 )*20 - (src0 +src3 )*6 + (src0 +src4 )*3 - (src1 +src5 ));\
  752. OP(dst[ 2*dstStride], (src2 +src3 )*20 - (src1 +src4 )*6 + (src0 +src5 )*3 - (src0 +src6 ));\
  753. OP(dst[ 3*dstStride], (src3 +src4 )*20 - (src2 +src5 )*6 + (src1 +src6 )*3 - (src0 +src7 ));\
  754. OP(dst[ 4*dstStride], (src4 +src5 )*20 - (src3 +src6 )*6 + (src2 +src7 )*3 - (src1 +src8 ));\
  755. OP(dst[ 5*dstStride], (src5 +src6 )*20 - (src4 +src7 )*6 + (src3 +src8 )*3 - (src2 +src9 ));\
  756. OP(dst[ 6*dstStride], (src6 +src7 )*20 - (src5 +src8 )*6 + (src4 +src9 )*3 - (src3 +src10));\
  757. OP(dst[ 7*dstStride], (src7 +src8 )*20 - (src6 +src9 )*6 + (src5 +src10)*3 - (src4 +src11));\
  758. OP(dst[ 8*dstStride], (src8 +src9 )*20 - (src7 +src10)*6 + (src6 +src11)*3 - (src5 +src12));\
  759. OP(dst[ 9*dstStride], (src9 +src10)*20 - (src8 +src11)*6 + (src7 +src12)*3 - (src6 +src13));\
  760. OP(dst[10*dstStride], (src10+src11)*20 - (src9 +src12)*6 + (src8 +src13)*3 - (src7 +src14));\
  761. OP(dst[11*dstStride], (src11+src12)*20 - (src10+src13)*6 + (src9 +src14)*3 - (src8 +src15));\
  762. OP(dst[12*dstStride], (src12+src13)*20 - (src11+src14)*6 + (src10+src15)*3 - (src9 +src16));\
  763. OP(dst[13*dstStride], (src13+src14)*20 - (src12+src15)*6 + (src11+src16)*3 - (src10+src16));\
  764. OP(dst[14*dstStride], (src14+src15)*20 - (src13+src16)*6 + (src12+src16)*3 - (src11+src15));\
  765. OP(dst[15*dstStride], (src15+src16)*20 - (src14+src16)*6 + (src13+src15)*3 - (src12+src14));\
  766. dst++;\
  767. src++;\
  768. }\
  769. }\
  770. \
  771. static void OPNAME ## qpel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
  772. uint8_t half[64];\
  773. put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
  774. OPNAME ## pixels8_l2_8(dst, src, half, stride, stride, 8, 8);\
  775. }\
  776. \
  777. static void OPNAME ## qpel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
  778. OPNAME ## mpeg4_qpel8_h_lowpass(dst, src, stride, stride, 8);\
  779. }\
  780. \
  781. static void OPNAME ## qpel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
  782. uint8_t half[64];\
  783. put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
  784. OPNAME ## pixels8_l2_8(dst, src+1, half, stride, stride, 8, 8);\
  785. }\
  786. \
  787. static void OPNAME ## qpel8_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
  788. uint8_t full[16*9];\
  789. uint8_t half[64];\
  790. copy_block9(full, src, 16, stride, 9);\
  791. put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
  792. OPNAME ## pixels8_l2_8(dst, full, half, stride, 16, 8, 8);\
  793. }\
  794. \
  795. static void OPNAME ## qpel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
  796. uint8_t full[16*9];\
  797. copy_block9(full, src, 16, stride, 9);\
  798. OPNAME ## mpeg4_qpel8_v_lowpass(dst, full, stride, 16);\
  799. }\
  800. \
  801. static void OPNAME ## qpel8_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
  802. uint8_t full[16*9];\
  803. uint8_t half[64];\
  804. copy_block9(full, src, 16, stride, 9);\
  805. put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
  806. OPNAME ## pixels8_l2_8(dst, full+16, half, stride, 16, 8, 8);\
  807. }\
  808. void ff_ ## OPNAME ## qpel8_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
  809. uint8_t full[16*9];\
  810. uint8_t halfH[72];\
  811. uint8_t halfV[64];\
  812. uint8_t halfHV[64];\
  813. copy_block9(full, src, 16, stride, 9);\
  814. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  815. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
  816. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  817. OPNAME ## pixels8_l4_8(dst, full, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  818. }\
  819. static void OPNAME ## qpel8_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
  820. uint8_t full[16*9];\
  821. uint8_t halfH[72];\
  822. uint8_t halfHV[64];\
  823. copy_block9(full, src, 16, stride, 9);\
  824. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  825. put ## RND ## pixels8_l2_8(halfH, halfH, full, 8, 8, 16, 9);\
  826. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  827. OPNAME ## pixels8_l2_8(dst, halfH, halfHV, stride, 8, 8, 8);\
  828. }\
  829. void ff_ ## OPNAME ## qpel8_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
  830. uint8_t full[16*9];\
  831. uint8_t halfH[72];\
  832. uint8_t halfV[64];\
  833. uint8_t halfHV[64];\
  834. copy_block9(full, src, 16, stride, 9);\
  835. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  836. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
  837. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  838. OPNAME ## pixels8_l4_8(dst, full+1, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  839. }\
  840. static void OPNAME ## qpel8_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
  841. uint8_t full[16*9];\
  842. uint8_t halfH[72];\
  843. uint8_t halfHV[64];\
  844. copy_block9(full, src, 16, stride, 9);\
  845. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  846. put ## RND ## pixels8_l2_8(halfH, halfH, full+1, 8, 8, 16, 9);\
  847. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  848. OPNAME ## pixels8_l2_8(dst, halfH, halfHV, stride, 8, 8, 8);\
  849. }\
  850. void ff_ ## OPNAME ## qpel8_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
  851. uint8_t full[16*9];\
  852. uint8_t halfH[72];\
  853. uint8_t halfV[64];\
  854. uint8_t halfHV[64];\
  855. copy_block9(full, src, 16, stride, 9);\
  856. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  857. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
  858. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  859. OPNAME ## pixels8_l4_8(dst, full+16, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  860. }\
  861. static void OPNAME ## qpel8_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
  862. uint8_t full[16*9];\
  863. uint8_t halfH[72];\
  864. uint8_t halfHV[64];\
  865. copy_block9(full, src, 16, stride, 9);\
  866. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  867. put ## RND ## pixels8_l2_8(halfH, halfH, full, 8, 8, 16, 9);\
  868. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  869. OPNAME ## pixels8_l2_8(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  870. }\
  871. void ff_ ## OPNAME ## qpel8_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
  872. uint8_t full[16*9];\
  873. uint8_t halfH[72];\
  874. uint8_t halfV[64];\
  875. uint8_t halfHV[64];\
  876. copy_block9(full, src, 16, stride, 9);\
  877. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full , 8, 16, 9);\
  878. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
  879. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  880. OPNAME ## pixels8_l4_8(dst, full+17, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  881. }\
  882. static void OPNAME ## qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
  883. uint8_t full[16*9];\
  884. uint8_t halfH[72];\
  885. uint8_t halfHV[64];\
  886. copy_block9(full, src, 16, stride, 9);\
  887. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  888. put ## RND ## pixels8_l2_8(halfH, halfH, full+1, 8, 8, 16, 9);\
  889. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  890. OPNAME ## pixels8_l2_8(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  891. }\
  892. static void OPNAME ## qpel8_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
  893. uint8_t halfH[72];\
  894. uint8_t halfHV[64];\
  895. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  896. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  897. OPNAME ## pixels8_l2_8(dst, halfH, halfHV, stride, 8, 8, 8);\
  898. }\
  899. static void OPNAME ## qpel8_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
  900. uint8_t halfH[72];\
  901. uint8_t halfHV[64];\
  902. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  903. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  904. OPNAME ## pixels8_l2_8(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  905. }\
  906. void ff_ ## OPNAME ## qpel8_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
  907. uint8_t full[16*9];\
  908. uint8_t halfH[72];\
  909. uint8_t halfV[64];\
  910. uint8_t halfHV[64];\
  911. copy_block9(full, src, 16, stride, 9);\
  912. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  913. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
  914. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  915. OPNAME ## pixels8_l2_8(dst, halfV, halfHV, stride, 8, 8, 8);\
  916. }\
  917. static void OPNAME ## qpel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
  918. uint8_t full[16*9];\
  919. uint8_t halfH[72];\
  920. copy_block9(full, src, 16, stride, 9);\
  921. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  922. put ## RND ## pixels8_l2_8(halfH, halfH, full, 8, 8, 16, 9);\
  923. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  924. }\
  925. void ff_ ## OPNAME ## qpel8_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
  926. uint8_t full[16*9];\
  927. uint8_t halfH[72];\
  928. uint8_t halfV[64];\
  929. uint8_t halfHV[64];\
  930. copy_block9(full, src, 16, stride, 9);\
  931. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  932. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
  933. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  934. OPNAME ## pixels8_l2_8(dst, halfV, halfHV, stride, 8, 8, 8);\
  935. }\
  936. static void OPNAME ## qpel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
  937. uint8_t full[16*9];\
  938. uint8_t halfH[72];\
  939. copy_block9(full, src, 16, stride, 9);\
  940. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  941. put ## RND ## pixels8_l2_8(halfH, halfH, full+1, 8, 8, 16, 9);\
  942. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  943. }\
  944. static void OPNAME ## qpel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
  945. uint8_t halfH[72];\
  946. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  947. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  948. }\
  949. \
  950. static void OPNAME ## qpel16_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
  951. uint8_t half[256];\
  952. put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
  953. OPNAME ## pixels16_l2_8(dst, src, half, stride, stride, 16, 16);\
  954. }\
  955. \
  956. static void OPNAME ## qpel16_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
  957. OPNAME ## mpeg4_qpel16_h_lowpass(dst, src, stride, stride, 16);\
  958. }\
  959. \
  960. static void OPNAME ## qpel16_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
  961. uint8_t half[256];\
  962. put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
  963. OPNAME ## pixels16_l2_8(dst, src+1, half, stride, stride, 16, 16);\
  964. }\
  965. \
  966. static void OPNAME ## qpel16_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
  967. uint8_t full[24*17];\
  968. uint8_t half[256];\
  969. copy_block17(full, src, 24, stride, 17);\
  970. put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
  971. OPNAME ## pixels16_l2_8(dst, full, half, stride, 24, 16, 16);\
  972. }\
  973. \
  974. static void OPNAME ## qpel16_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
  975. uint8_t full[24*17];\
  976. copy_block17(full, src, 24, stride, 17);\
  977. OPNAME ## mpeg4_qpel16_v_lowpass(dst, full, stride, 24);\
  978. }\
  979. \
  980. static void OPNAME ## qpel16_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
  981. uint8_t full[24*17];\
  982. uint8_t half[256];\
  983. copy_block17(full, src, 24, stride, 17);\
  984. put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
  985. OPNAME ## pixels16_l2_8(dst, full+24, half, stride, 24, 16, 16);\
  986. }\
  987. void ff_ ## OPNAME ## qpel16_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
  988. uint8_t full[24*17];\
  989. uint8_t halfH[272];\
  990. uint8_t halfV[256];\
  991. uint8_t halfHV[256];\
  992. copy_block17(full, src, 24, stride, 17);\
  993. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  994. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
  995. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  996. OPNAME ## pixels16_l4_8(dst, full, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  997. }\
  998. static void OPNAME ## qpel16_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
  999. uint8_t full[24*17];\
  1000. uint8_t halfH[272];\
  1001. uint8_t halfHV[256];\
  1002. copy_block17(full, src, 24, stride, 17);\
  1003. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1004. put ## RND ## pixels16_l2_8(halfH, halfH, full, 16, 16, 24, 17);\
  1005. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1006. OPNAME ## pixels16_l2_8(dst, halfH, halfHV, stride, 16, 16, 16);\
  1007. }\
  1008. void ff_ ## OPNAME ## qpel16_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1009. uint8_t full[24*17];\
  1010. uint8_t halfH[272];\
  1011. uint8_t halfV[256];\
  1012. uint8_t halfHV[256];\
  1013. copy_block17(full, src, 24, stride, 17);\
  1014. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1015. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
  1016. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1017. OPNAME ## pixels16_l4_8(dst, full+1, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1018. }\
  1019. static void OPNAME ## qpel16_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
  1020. uint8_t full[24*17];\
  1021. uint8_t halfH[272];\
  1022. uint8_t halfHV[256];\
  1023. copy_block17(full, src, 24, stride, 17);\
  1024. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1025. put ## RND ## pixels16_l2_8(halfH, halfH, full+1, 16, 16, 24, 17);\
  1026. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1027. OPNAME ## pixels16_l2_8(dst, halfH, halfHV, stride, 16, 16, 16);\
  1028. }\
  1029. void ff_ ## OPNAME ## qpel16_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1030. uint8_t full[24*17];\
  1031. uint8_t halfH[272];\
  1032. uint8_t halfV[256];\
  1033. uint8_t halfHV[256];\
  1034. copy_block17(full, src, 24, stride, 17);\
  1035. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1036. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
  1037. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1038. OPNAME ## pixels16_l4_8(dst, full+24, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1039. }\
  1040. static void OPNAME ## qpel16_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
  1041. uint8_t full[24*17];\
  1042. uint8_t halfH[272];\
  1043. uint8_t halfHV[256];\
  1044. copy_block17(full, src, 24, stride, 17);\
  1045. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1046. put ## RND ## pixels16_l2_8(halfH, halfH, full, 16, 16, 24, 17);\
  1047. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1048. OPNAME ## pixels16_l2_8(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  1049. }\
  1050. void ff_ ## OPNAME ## qpel16_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1051. uint8_t full[24*17];\
  1052. uint8_t halfH[272];\
  1053. uint8_t halfV[256];\
  1054. uint8_t halfHV[256];\
  1055. copy_block17(full, src, 24, stride, 17);\
  1056. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full , 16, 24, 17);\
  1057. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
  1058. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1059. OPNAME ## pixels16_l4_8(dst, full+25, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1060. }\
  1061. static void OPNAME ## qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
  1062. uint8_t full[24*17];\
  1063. uint8_t halfH[272];\
  1064. uint8_t halfHV[256];\
  1065. copy_block17(full, src, 24, stride, 17);\
  1066. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1067. put ## RND ## pixels16_l2_8(halfH, halfH, full+1, 16, 16, 24, 17);\
  1068. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1069. OPNAME ## pixels16_l2_8(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  1070. }\
  1071. static void OPNAME ## qpel16_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
  1072. uint8_t halfH[272];\
  1073. uint8_t halfHV[256];\
  1074. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1075. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1076. OPNAME ## pixels16_l2_8(dst, halfH, halfHV, stride, 16, 16, 16);\
  1077. }\
  1078. static void OPNAME ## qpel16_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
  1079. uint8_t halfH[272];\
  1080. uint8_t halfHV[256];\
  1081. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1082. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1083. OPNAME ## pixels16_l2_8(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  1084. }\
  1085. void ff_ ## OPNAME ## qpel16_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1086. uint8_t full[24*17];\
  1087. uint8_t halfH[272];\
  1088. uint8_t halfV[256];\
  1089. uint8_t halfHV[256];\
  1090. copy_block17(full, src, 24, stride, 17);\
  1091. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1092. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
  1093. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1094. OPNAME ## pixels16_l2_8(dst, halfV, halfHV, stride, 16, 16, 16);\
  1095. }\
  1096. static void OPNAME ## qpel16_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
  1097. uint8_t full[24*17];\
  1098. uint8_t halfH[272];\
  1099. copy_block17(full, src, 24, stride, 17);\
  1100. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1101. put ## RND ## pixels16_l2_8(halfH, halfH, full, 16, 16, 24, 17);\
  1102. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  1103. }\
  1104. void ff_ ## OPNAME ## qpel16_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1105. uint8_t full[24*17];\
  1106. uint8_t halfH[272];\
  1107. uint8_t halfV[256];\
  1108. uint8_t halfHV[256];\
  1109. copy_block17(full, src, 24, stride, 17);\
  1110. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1111. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
  1112. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1113. OPNAME ## pixels16_l2_8(dst, halfV, halfHV, stride, 16, 16, 16);\
  1114. }\
  1115. static void OPNAME ## qpel16_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
  1116. uint8_t full[24*17];\
  1117. uint8_t halfH[272];\
  1118. copy_block17(full, src, 24, stride, 17);\
  1119. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1120. put ## RND ## pixels16_l2_8(halfH, halfH, full+1, 16, 16, 24, 17);\
  1121. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  1122. }\
  1123. static void OPNAME ## qpel16_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
  1124. uint8_t halfH[272];\
  1125. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1126. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  1127. }
  1128. #define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
  1129. #define op_avg_no_rnd(a, b) a = (((a)+cm[((b) + 15)>>5])>>1)
  1130. #define op_put(a, b) a = cm[((b) + 16)>>5]
  1131. #define op_put_no_rnd(a, b) a = cm[((b) + 15)>>5]
  1132. QPEL_MC(0, put_ , _ , op_put)
  1133. QPEL_MC(1, put_no_rnd_, _no_rnd_, op_put_no_rnd)
  1134. QPEL_MC(0, avg_ , _ , op_avg)
  1135. //QPEL_MC(1, avg_no_rnd , _ , op_avg)
  1136. #undef op_avg
  1137. #undef op_avg_no_rnd
  1138. #undef op_put
  1139. #undef op_put_no_rnd
  1140. #define put_qpel8_mc00_c ff_put_pixels8x8_c
  1141. #define avg_qpel8_mc00_c ff_avg_pixels8x8_c
  1142. #define put_qpel16_mc00_c ff_put_pixels16x16_c
  1143. #define avg_qpel16_mc00_c ff_avg_pixels16x16_c
  1144. #define put_no_rnd_qpel8_mc00_c ff_put_pixels8x8_c
  1145. #define put_no_rnd_qpel16_mc00_c ff_put_pixels16x16_8_c
  1146. static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){
  1147. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  1148. int i;
  1149. for(i=0; i<h; i++){
  1150. dst[0]= cm[(9*(src[0] + src[1]) - (src[-1] + src[2]) + 8)>>4];
  1151. dst[1]= cm[(9*(src[1] + src[2]) - (src[ 0] + src[3]) + 8)>>4];
  1152. dst[2]= cm[(9*(src[2] + src[3]) - (src[ 1] + src[4]) + 8)>>4];
  1153. dst[3]= cm[(9*(src[3] + src[4]) - (src[ 2] + src[5]) + 8)>>4];
  1154. dst[4]= cm[(9*(src[4] + src[5]) - (src[ 3] + src[6]) + 8)>>4];
  1155. dst[5]= cm[(9*(src[5] + src[6]) - (src[ 4] + src[7]) + 8)>>4];
  1156. dst[6]= cm[(9*(src[6] + src[7]) - (src[ 5] + src[8]) + 8)>>4];
  1157. dst[7]= cm[(9*(src[7] + src[8]) - (src[ 6] + src[9]) + 8)>>4];
  1158. dst+=dstStride;
  1159. src+=srcStride;
  1160. }
  1161. }
  1162. #if CONFIG_RV40_DECODER
  1163. void ff_put_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){
  1164. put_pixels16_xy2_8_c(dst, src, stride, 16);
  1165. }
  1166. void ff_avg_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){
  1167. avg_pixels16_xy2_8_c(dst, src, stride, 16);
  1168. }
  1169. void ff_put_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){
  1170. put_pixels8_xy2_8_c(dst, src, stride, 8);
  1171. }
  1172. void ff_avg_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){
  1173. avg_pixels8_xy2_8_c(dst, src, stride, 8);
  1174. }
  1175. #endif /* CONFIG_RV40_DECODER */
  1176. #if CONFIG_DIRAC_DECODER
  1177. #define DIRAC_MC(OPNAME)\
  1178. void ff_ ## OPNAME ## _dirac_pixels8_c(uint8_t *dst, const uint8_t *src[5], int stride, int h)\
  1179. {\
  1180. OPNAME ## _pixels8_8_c(dst, src[0], stride, h);\
  1181. }\
  1182. void ff_ ## OPNAME ## _dirac_pixels16_c(uint8_t *dst, const uint8_t *src[5], int stride, int h)\
  1183. {\
  1184. OPNAME ## _pixels16_8_c(dst, src[0], stride, h);\
  1185. }\
  1186. void ff_ ## OPNAME ## _dirac_pixels32_c(uint8_t *dst, const uint8_t *src[5], int stride, int h)\
  1187. {\
  1188. OPNAME ## _pixels16_8_c(dst , src[0] , stride, h);\
  1189. OPNAME ## _pixels16_8_c(dst+16, src[0]+16, stride, h);\
  1190. }\
  1191. void ff_ ## OPNAME ## _dirac_pixels8_l2_c(uint8_t *dst, const uint8_t *src[5], int stride, int h)\
  1192. {\
  1193. OPNAME ## _pixels8_l2_8(dst, src[0], src[1], stride, stride, stride, h);\
  1194. }\
  1195. void ff_ ## OPNAME ## _dirac_pixels16_l2_c(uint8_t *dst, const uint8_t *src[5], int stride, int h)\
  1196. {\
  1197. OPNAME ## _pixels16_l2_8(dst, src[0], src[1], stride, stride, stride, h);\
  1198. }\
  1199. void ff_ ## OPNAME ## _dirac_pixels32_l2_c(uint8_t *dst, const uint8_t *src[5], int stride, int h)\
  1200. {\
  1201. OPNAME ## _pixels16_l2_8(dst , src[0] , src[1] , stride, stride, stride, h);\
  1202. OPNAME ## _pixels16_l2_8(dst+16, src[0]+16, src[1]+16, stride, stride, stride, h);\
  1203. }\
  1204. void ff_ ## OPNAME ## _dirac_pixels8_l4_c(uint8_t *dst, const uint8_t *src[5], int stride, int h)\
  1205. {\
  1206. OPNAME ## _pixels8_l4_8(dst, src[0], src[1], src[2], src[3], stride, stride, stride, stride, stride, h);\
  1207. }\
  1208. void ff_ ## OPNAME ## _dirac_pixels16_l4_c(uint8_t *dst, const uint8_t *src[5], int stride, int h)\
  1209. {\
  1210. OPNAME ## _pixels16_l4_8(dst, src[0], src[1], src[2], src[3], stride, stride, stride, stride, stride, h);\
  1211. }\
  1212. void ff_ ## OPNAME ## _dirac_pixels32_l4_c(uint8_t *dst, const uint8_t *src[5], int stride, int h)\
  1213. {\
  1214. OPNAME ## _pixels16_l4_8(dst , src[0] , src[1] , src[2] , src[3] , stride, stride, stride, stride, stride, h);\
  1215. OPNAME ## _pixels16_l4_8(dst+16, src[0]+16, src[1]+16, src[2]+16, src[3]+16, stride, stride, stride, stride, stride, h);\
  1216. }
  1217. DIRAC_MC(put)
  1218. DIRAC_MC(avg)
  1219. #endif
  1220. static void wmv2_mspel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int w){
  1221. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  1222. int i;
  1223. for(i=0; i<w; i++){
  1224. const int src_1= src[ -srcStride];
  1225. const int src0 = src[0 ];
  1226. const int src1 = src[ srcStride];
  1227. const int src2 = src[2*srcStride];
  1228. const int src3 = src[3*srcStride];
  1229. const int src4 = src[4*srcStride];
  1230. const int src5 = src[5*srcStride];
  1231. const int src6 = src[6*srcStride];
  1232. const int src7 = src[7*srcStride];
  1233. const int src8 = src[8*srcStride];
  1234. const int src9 = src[9*srcStride];
  1235. dst[0*dstStride]= cm[(9*(src0 + src1) - (src_1 + src2) + 8)>>4];
  1236. dst[1*dstStride]= cm[(9*(src1 + src2) - (src0 + src3) + 8)>>4];
  1237. dst[2*dstStride]= cm[(9*(src2 + src3) - (src1 + src4) + 8)>>4];
  1238. dst[3*dstStride]= cm[(9*(src3 + src4) - (src2 + src5) + 8)>>4];
  1239. dst[4*dstStride]= cm[(9*(src4 + src5) - (src3 + src6) + 8)>>4];
  1240. dst[5*dstStride]= cm[(9*(src5 + src6) - (src4 + src7) + 8)>>4];
  1241. dst[6*dstStride]= cm[(9*(src6 + src7) - (src5 + src8) + 8)>>4];
  1242. dst[7*dstStride]= cm[(9*(src7 + src8) - (src6 + src9) + 8)>>4];
  1243. src++;
  1244. dst++;
  1245. }
  1246. }
  1247. static void put_mspel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){
  1248. uint8_t half[64];
  1249. wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
  1250. put_pixels8_l2_8(dst, src, half, stride, stride, 8, 8);
  1251. }
  1252. static void put_mspel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){
  1253. wmv2_mspel8_h_lowpass(dst, src, stride, stride, 8);
  1254. }
  1255. static void put_mspel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){
  1256. uint8_t half[64];
  1257. wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
  1258. put_pixels8_l2_8(dst, src+1, half, stride, stride, 8, 8);
  1259. }
  1260. static void put_mspel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){
  1261. wmv2_mspel8_v_lowpass(dst, src, stride, stride, 8);
  1262. }
  1263. static void put_mspel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){
  1264. uint8_t halfH[88];
  1265. uint8_t halfV[64];
  1266. uint8_t halfHV[64];
  1267. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  1268. wmv2_mspel8_v_lowpass(halfV, src, 8, stride, 8);
  1269. wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
  1270. put_pixels8_l2_8(dst, halfV, halfHV, stride, 8, 8, 8);
  1271. }
  1272. static void put_mspel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){
  1273. uint8_t halfH[88];
  1274. uint8_t halfV[64];
  1275. uint8_t halfHV[64];
  1276. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  1277. wmv2_mspel8_v_lowpass(halfV, src+1, 8, stride, 8);
  1278. wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
  1279. put_pixels8_l2_8(dst, halfV, halfHV, stride, 8, 8, 8);
  1280. }
  1281. static void put_mspel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){
  1282. uint8_t halfH[88];
  1283. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  1284. wmv2_mspel8_v_lowpass(dst, halfH+8, stride, 8, 8);
  1285. }
  1286. static void h263_v_loop_filter_c(uint8_t *src, int stride, int qscale){
  1287. if(CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
  1288. int x;
  1289. const int strength= ff_h263_loop_filter_strength[qscale];
  1290. for(x=0; x<8; x++){
  1291. int d1, d2, ad1;
  1292. int p0= src[x-2*stride];
  1293. int p1= src[x-1*stride];
  1294. int p2= src[x+0*stride];
  1295. int p3= src[x+1*stride];
  1296. int d = (p0 - p3 + 4*(p2 - p1)) / 8;
  1297. if (d<-2*strength) d1= 0;
  1298. else if(d<- strength) d1=-2*strength - d;
  1299. else if(d< strength) d1= d;
  1300. else if(d< 2*strength) d1= 2*strength - d;
  1301. else d1= 0;
  1302. p1 += d1;
  1303. p2 -= d1;
  1304. if(p1&256) p1= ~(p1>>31);
  1305. if(p2&256) p2= ~(p2>>31);
  1306. src[x-1*stride] = p1;
  1307. src[x+0*stride] = p2;
  1308. ad1= FFABS(d1)>>1;
  1309. d2= av_clip((p0-p3)/4, -ad1, ad1);
  1310. src[x-2*stride] = p0 - d2;
  1311. src[x+ stride] = p3 + d2;
  1312. }
  1313. }
  1314. }
  1315. static void h263_h_loop_filter_c(uint8_t *src, int stride, int qscale){
  1316. if(CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
  1317. int y;
  1318. const int strength= ff_h263_loop_filter_strength[qscale];
  1319. for(y=0; y<8; y++){
  1320. int d1, d2, ad1;
  1321. int p0= src[y*stride-2];
  1322. int p1= src[y*stride-1];
  1323. int p2= src[y*stride+0];
  1324. int p3= src[y*stride+1];
  1325. int d = (p0 - p3 + 4*(p2 - p1)) / 8;
  1326. if (d<-2*strength) d1= 0;
  1327. else if(d<- strength) d1=-2*strength - d;
  1328. else if(d< strength) d1= d;
  1329. else if(d< 2*strength) d1= 2*strength - d;
  1330. else d1= 0;
  1331. p1 += d1;
  1332. p2 -= d1;
  1333. if(p1&256) p1= ~(p1>>31);
  1334. if(p2&256) p2= ~(p2>>31);
  1335. src[y*stride-1] = p1;
  1336. src[y*stride+0] = p2;
  1337. ad1= FFABS(d1)>>1;
  1338. d2= av_clip((p0-p3)/4, -ad1, ad1);
  1339. src[y*stride-2] = p0 - d2;
  1340. src[y*stride+1] = p3 + d2;
  1341. }
  1342. }
  1343. }
  1344. static void h261_loop_filter_c(uint8_t *src, int stride){
  1345. int x,y,xy,yz;
  1346. int temp[64];
  1347. for(x=0; x<8; x++){
  1348. temp[x ] = 4*src[x ];
  1349. temp[x + 7*8] = 4*src[x + 7*stride];
  1350. }
  1351. for(y=1; y<7; y++){
  1352. for(x=0; x<8; x++){
  1353. xy = y * stride + x;
  1354. yz = y * 8 + x;
  1355. temp[yz] = src[xy - stride] + 2*src[xy] + src[xy + stride];
  1356. }
  1357. }
  1358. for(y=0; y<8; y++){
  1359. src[ y*stride] = (temp[ y*8] + 2)>>2;
  1360. src[7+y*stride] = (temp[7+y*8] + 2)>>2;
  1361. for(x=1; x<7; x++){
  1362. xy = y * stride + x;
  1363. yz = y * 8 + x;
  1364. src[xy] = (temp[yz-1] + 2*temp[yz] + temp[yz+1] + 8)>>4;
  1365. }
  1366. }
  1367. }
  1368. static inline int pix_abs16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  1369. {
  1370. int s, i;
  1371. s = 0;
  1372. for(i=0;i<h;i++) {
  1373. s += abs(pix1[0] - pix2[0]);
  1374. s += abs(pix1[1] - pix2[1]);
  1375. s += abs(pix1[2] - pix2[2]);
  1376. s += abs(pix1[3] - pix2[3]);
  1377. s += abs(pix1[4] - pix2[4]);
  1378. s += abs(pix1[5] - pix2[5]);
  1379. s += abs(pix1[6] - pix2[6]);
  1380. s += abs(pix1[7] - pix2[7]);
  1381. s += abs(pix1[8] - pix2[8]);
  1382. s += abs(pix1[9] - pix2[9]);
  1383. s += abs(pix1[10] - pix2[10]);
  1384. s += abs(pix1[11] - pix2[11]);
  1385. s += abs(pix1[12] - pix2[12]);
  1386. s += abs(pix1[13] - pix2[13]);
  1387. s += abs(pix1[14] - pix2[14]);
  1388. s += abs(pix1[15] - pix2[15]);
  1389. pix1 += line_size;
  1390. pix2 += line_size;
  1391. }
  1392. return s;
  1393. }
  1394. static int pix_abs16_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  1395. {
  1396. int s, i;
  1397. s = 0;
  1398. for(i=0;i<h;i++) {
  1399. s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
  1400. s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
  1401. s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
  1402. s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
  1403. s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
  1404. s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
  1405. s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
  1406. s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
  1407. s += abs(pix1[8] - avg2(pix2[8], pix2[9]));
  1408. s += abs(pix1[9] - avg2(pix2[9], pix2[10]));
  1409. s += abs(pix1[10] - avg2(pix2[10], pix2[11]));
  1410. s += abs(pix1[11] - avg2(pix2[11], pix2[12]));
  1411. s += abs(pix1[12] - avg2(pix2[12], pix2[13]));
  1412. s += abs(pix1[13] - avg2(pix2[13], pix2[14]));
  1413. s += abs(pix1[14] - avg2(pix2[14], pix2[15]));
  1414. s += abs(pix1[15] - avg2(pix2[15], pix2[16]));
  1415. pix1 += line_size;
  1416. pix2 += line_size;
  1417. }
  1418. return s;
  1419. }
  1420. static int pix_abs16_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  1421. {
  1422. int s, i;
  1423. uint8_t *pix3 = pix2 + line_size;
  1424. s = 0;
  1425. for(i=0;i<h;i++) {
  1426. s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
  1427. s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
  1428. s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
  1429. s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
  1430. s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
  1431. s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
  1432. s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
  1433. s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
  1434. s += abs(pix1[8] - avg2(pix2[8], pix3[8]));
  1435. s += abs(pix1[9] - avg2(pix2[9], pix3[9]));
  1436. s += abs(pix1[10] - avg2(pix2[10], pix3[10]));
  1437. s += abs(pix1[11] - avg2(pix2[11], pix3[11]));
  1438. s += abs(pix1[12] - avg2(pix2[12], pix3[12]));
  1439. s += abs(pix1[13] - avg2(pix2[13], pix3[13]));
  1440. s += abs(pix1[14] - avg2(pix2[14], pix3[14]));
  1441. s += abs(pix1[15] - avg2(pix2[15], pix3[15]));
  1442. pix1 += line_size;
  1443. pix2 += line_size;
  1444. pix3 += line_size;
  1445. }
  1446. return s;
  1447. }
  1448. static int pix_abs16_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  1449. {
  1450. int s, i;
  1451. uint8_t *pix3 = pix2 + line_size;
  1452. s = 0;
  1453. for(i=0;i<h;i++) {
  1454. s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
  1455. s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
  1456. s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
  1457. s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
  1458. s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
  1459. s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
  1460. s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
  1461. s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
  1462. s += abs(pix1[8] - avg4(pix2[8], pix2[9], pix3[8], pix3[9]));
  1463. s += abs(pix1[9] - avg4(pix2[9], pix2[10], pix3[9], pix3[10]));
  1464. s += abs(pix1[10] - avg4(pix2[10], pix2[11], pix3[10], pix3[11]));
  1465. s += abs(pix1[11] - avg4(pix2[11], pix2[12], pix3[11], pix3[12]));
  1466. s += abs(pix1[12] - avg4(pix2[12], pix2[13], pix3[12], pix3[13]));
  1467. s += abs(pix1[13] - avg4(pix2[13], pix2[14], pix3[13], pix3[14]));
  1468. s += abs(pix1[14] - avg4(pix2[14], pix2[15], pix3[14], pix3[15]));
  1469. s += abs(pix1[15] - avg4(pix2[15], pix2[16], pix3[15], pix3[16]));
  1470. pix1 += line_size;
  1471. pix2 += line_size;
  1472. pix3 += line_size;
  1473. }
  1474. return s;
  1475. }
  1476. static inline int pix_abs8_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  1477. {
  1478. int s, i;
  1479. s = 0;
  1480. for(i=0;i<h;i++) {
  1481. s += abs(pix1[0] - pix2[0]);
  1482. s += abs(pix1[1] - pix2[1]);
  1483. s += abs(pix1[2] - pix2[2]);
  1484. s += abs(pix1[3] - pix2[3]);
  1485. s += abs(pix1[4] - pix2[4]);
  1486. s += abs(pix1[5] - pix2[5]);
  1487. s += abs(pix1[6] - pix2[6]);
  1488. s += abs(pix1[7] - pix2[7]);
  1489. pix1 += line_size;
  1490. pix2 += line_size;
  1491. }
  1492. return s;
  1493. }
  1494. static int pix_abs8_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  1495. {
  1496. int s, i;
  1497. s = 0;
  1498. for(i=0;i<h;i++) {
  1499. s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
  1500. s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
  1501. s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
  1502. s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
  1503. s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
  1504. s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
  1505. s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
  1506. s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
  1507. pix1 += line_size;
  1508. pix2 += line_size;
  1509. }
  1510. return s;
  1511. }
  1512. static int pix_abs8_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  1513. {
  1514. int s, i;
  1515. uint8_t *pix3 = pix2 + line_size;
  1516. s = 0;
  1517. for(i=0;i<h;i++) {
  1518. s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
  1519. s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
  1520. s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
  1521. s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
  1522. s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
  1523. s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
  1524. s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
  1525. s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
  1526. pix1 += line_size;
  1527. pix2 += line_size;
  1528. pix3 += line_size;
  1529. }
  1530. return s;
  1531. }
  1532. static int pix_abs8_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  1533. {
  1534. int s, i;
  1535. uint8_t *pix3 = pix2 + line_size;
  1536. s = 0;
  1537. for(i=0;i<h;i++) {
  1538. s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
  1539. s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
  1540. s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
  1541. s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
  1542. s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
  1543. s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
  1544. s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
  1545. s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
  1546. pix1 += line_size;
  1547. pix2 += line_size;
  1548. pix3 += line_size;
  1549. }
  1550. return s;
  1551. }
  1552. static int nsse16_c(void *v, uint8_t *s1, uint8_t *s2, int stride, int h){
  1553. MpegEncContext *c = v;
  1554. int score1=0;
  1555. int score2=0;
  1556. int x,y;
  1557. for(y=0; y<h; y++){
  1558. for(x=0; x<16; x++){
  1559. score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]);
  1560. }
  1561. if(y+1<h){
  1562. for(x=0; x<15; x++){
  1563. score2+= FFABS( s1[x ] - s1[x +stride]
  1564. - s1[x+1] + s1[x+1+stride])
  1565. -FFABS( s2[x ] - s2[x +stride]
  1566. - s2[x+1] + s2[x+1+stride]);
  1567. }
  1568. }
  1569. s1+= stride;
  1570. s2+= stride;
  1571. }
  1572. if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
  1573. else return score1 + FFABS(score2)*8;
  1574. }
  1575. static int nsse8_c(void *v, uint8_t *s1, uint8_t *s2, int stride, int h){
  1576. MpegEncContext *c = v;
  1577. int score1=0;
  1578. int score2=0;
  1579. int x,y;
  1580. for(y=0; y<h; y++){
  1581. for(x=0; x<8; x++){
  1582. score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]);
  1583. }
  1584. if(y+1<h){
  1585. for(x=0; x<7; x++){
  1586. score2+= FFABS( s1[x ] - s1[x +stride]
  1587. - s1[x+1] + s1[x+1+stride])
  1588. -FFABS( s2[x ] - s2[x +stride]
  1589. - s2[x+1] + s2[x+1+stride]);
  1590. }
  1591. }
  1592. s1+= stride;
  1593. s2+= stride;
  1594. }
  1595. if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
  1596. else return score1 + FFABS(score2)*8;
  1597. }
  1598. static int try_8x8basis_c(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale){
  1599. int i;
  1600. unsigned int sum=0;
  1601. for(i=0; i<8*8; i++){
  1602. int b= rem[i] + ((basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT));
  1603. int w= weight[i];
  1604. b>>= RECON_SHIFT;
  1605. assert(-512<b && b<512);
  1606. sum += (w*b)*(w*b)>>4;
  1607. }
  1608. return sum>>2;
  1609. }
  1610. static void add_8x8basis_c(int16_t rem[64], int16_t basis[64], int scale){
  1611. int i;
  1612. for(i=0; i<8*8; i++){
  1613. rem[i] += (basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT);
  1614. }
  1615. }
  1616. /**
  1617. * Permute an 8x8 block.
  1618. * @param block the block which will be permuted according to the given permutation vector
  1619. * @param permutation the permutation vector
  1620. * @param last the last non zero coefficient in scantable order, used to speed the permutation up
  1621. * @param scantable the used scantable, this is only used to speed the permutation up, the block is not
  1622. * (inverse) permutated to scantable order!
  1623. */
  1624. void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last)
  1625. {
  1626. int i;
  1627. DCTELEM temp[64];
  1628. if(last<=0) return;
  1629. //if(permutation[1]==1) return; //FIXME it is ok but not clean and might fail for some permutations
  1630. for(i=0; i<=last; i++){
  1631. const int j= scantable[i];
  1632. temp[j]= block[j];
  1633. block[j]=0;
  1634. }
  1635. for(i=0; i<=last; i++){
  1636. const int j= scantable[i];
  1637. const int perm_j= permutation[j];
  1638. block[perm_j]= temp[j];
  1639. }
  1640. }
  1641. static int zero_cmp(void *s, uint8_t *a, uint8_t *b, int stride, int h){
  1642. return 0;
  1643. }
  1644. void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type){
  1645. int i;
  1646. memset(cmp, 0, sizeof(void*)*6);
  1647. for(i=0; i<6; i++){
  1648. switch(type&0xFF){
  1649. case FF_CMP_SAD:
  1650. cmp[i]= c->sad[i];
  1651. break;
  1652. case FF_CMP_SATD:
  1653. cmp[i]= c->hadamard8_diff[i];
  1654. break;
  1655. case FF_CMP_SSE:
  1656. cmp[i]= c->sse[i];
  1657. break;
  1658. case FF_CMP_DCT:
  1659. cmp[i]= c->dct_sad[i];
  1660. break;
  1661. case FF_CMP_DCT264:
  1662. cmp[i]= c->dct264_sad[i];
  1663. break;
  1664. case FF_CMP_DCTMAX:
  1665. cmp[i]= c->dct_max[i];
  1666. break;
  1667. case FF_CMP_PSNR:
  1668. cmp[i]= c->quant_psnr[i];
  1669. break;
  1670. case FF_CMP_BIT:
  1671. cmp[i]= c->bit[i];
  1672. break;
  1673. case FF_CMP_RD:
  1674. cmp[i]= c->rd[i];
  1675. break;
  1676. case FF_CMP_VSAD:
  1677. cmp[i]= c->vsad[i];
  1678. break;
  1679. case FF_CMP_VSSE:
  1680. cmp[i]= c->vsse[i];
  1681. break;
  1682. case FF_CMP_ZERO:
  1683. cmp[i]= zero_cmp;
  1684. break;
  1685. case FF_CMP_NSSE:
  1686. cmp[i]= c->nsse[i];
  1687. break;
  1688. #if CONFIG_DWT
  1689. case FF_CMP_W53:
  1690. cmp[i]= c->w53[i];
  1691. break;
  1692. case FF_CMP_W97:
  1693. cmp[i]= c->w97[i];
  1694. break;
  1695. #endif
  1696. default:
  1697. av_log(NULL, AV_LOG_ERROR,"internal error in cmp function selection\n");
  1698. }
  1699. }
  1700. }
  1701. static void add_bytes_c(uint8_t *dst, uint8_t *src, int w){
  1702. long i;
  1703. for(i=0; i<=w-sizeof(long); i+=sizeof(long)){
  1704. long a = *(long*)(src+i);
  1705. long b = *(long*)(dst+i);
  1706. *(long*)(dst+i) = ((a&pb_7f) + (b&pb_7f)) ^ ((a^b)&pb_80);
  1707. }
  1708. for(; i<w; i++)
  1709. dst[i+0] += src[i+0];
  1710. }
  1711. static void diff_bytes_c(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w){
  1712. long i;
  1713. #if !HAVE_FAST_UNALIGNED
  1714. if((long)src2 & (sizeof(long)-1)){
  1715. for(i=0; i+7<w; i+=8){
  1716. dst[i+0] = src1[i+0]-src2[i+0];
  1717. dst[i+1] = src1[i+1]-src2[i+1];
  1718. dst[i+2] = src1[i+2]-src2[i+2];
  1719. dst[i+3] = src1[i+3]-src2[i+3];
  1720. dst[i+4] = src1[i+4]-src2[i+4];
  1721. dst[i+5] = src1[i+5]-src2[i+5];
  1722. dst[i+6] = src1[i+6]-src2[i+6];
  1723. dst[i+7] = src1[i+7]-src2[i+7];
  1724. }
  1725. }else
  1726. #endif
  1727. for(i=0; i<=w-sizeof(long); i+=sizeof(long)){
  1728. long a = *(long*)(src1+i);
  1729. long b = *(long*)(src2+i);
  1730. *(long*)(dst+i) = ((a|pb_80) - (b&pb_7f)) ^ ((a^b^pb_80)&pb_80);
  1731. }
  1732. for(; i<w; i++)
  1733. dst[i+0] = src1[i+0]-src2[i+0];
  1734. }
  1735. static void add_hfyu_median_prediction_c(uint8_t *dst, const uint8_t *src1, const uint8_t *diff, int w, int *left, int *left_top){
  1736. int i;
  1737. uint8_t l, lt;
  1738. l= *left;
  1739. lt= *left_top;
  1740. for(i=0; i<w; i++){
  1741. l= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF) + diff[i];
  1742. lt= src1[i];
  1743. dst[i]= l;
  1744. }
  1745. *left= l;
  1746. *left_top= lt;
  1747. }
  1748. static void sub_hfyu_median_prediction_c(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w, int *left, int *left_top){
  1749. int i;
  1750. uint8_t l, lt;
  1751. l= *left;
  1752. lt= *left_top;
  1753. for(i=0; i<w; i++){
  1754. const int pred= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF);
  1755. lt= src1[i];
  1756. l= src2[i];
  1757. dst[i]= l - pred;
  1758. }
  1759. *left= l;
  1760. *left_top= lt;
  1761. }
  1762. static int add_hfyu_left_prediction_c(uint8_t *dst, const uint8_t *src, int w, int acc){
  1763. int i;
  1764. for(i=0; i<w-1; i++){
  1765. acc+= src[i];
  1766. dst[i]= acc;
  1767. i++;
  1768. acc+= src[i];
  1769. dst[i]= acc;
  1770. }
  1771. for(; i<w; i++){
  1772. acc+= src[i];
  1773. dst[i]= acc;
  1774. }
  1775. return acc;
  1776. }
  1777. #if HAVE_BIGENDIAN
  1778. #define B 3
  1779. #define G 2
  1780. #define R 1
  1781. #define A 0
  1782. #else
  1783. #define B 0
  1784. #define G 1
  1785. #define R 2
  1786. #define A 3
  1787. #endif
  1788. static void add_hfyu_left_prediction_bgr32_c(uint8_t *dst, const uint8_t *src, int w, int *red, int *green, int *blue, int *alpha){
  1789. int i;
  1790. int r,g,b,a;
  1791. r= *red;
  1792. g= *green;
  1793. b= *blue;
  1794. a= *alpha;
  1795. for(i=0; i<w; i++){
  1796. b+= src[4*i+B];
  1797. g+= src[4*i+G];
  1798. r+= src[4*i+R];
  1799. a+= src[4*i+A];
  1800. dst[4*i+B]= b;
  1801. dst[4*i+G]= g;
  1802. dst[4*i+R]= r;
  1803. dst[4*i+A]= a;
  1804. }
  1805. *red= r;
  1806. *green= g;
  1807. *blue= b;
  1808. *alpha= a;
  1809. }
  1810. #undef B
  1811. #undef G
  1812. #undef R
  1813. #undef A
  1814. #define BUTTERFLY2(o1,o2,i1,i2) \
  1815. o1= (i1)+(i2);\
  1816. o2= (i1)-(i2);
  1817. #define BUTTERFLY1(x,y) \
  1818. {\
  1819. int a,b;\
  1820. a= x;\
  1821. b= y;\
  1822. x= a+b;\
  1823. y= a-b;\
  1824. }
  1825. #define BUTTERFLYA(x,y) (FFABS((x)+(y)) + FFABS((x)-(y)))
  1826. static int hadamard8_diff8x8_c(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h){
  1827. int i;
  1828. int temp[64];
  1829. int sum=0;
  1830. assert(h==8);
  1831. for(i=0; i<8; i++){
  1832. //FIXME try pointer walks
  1833. BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0]-dst[stride*i+0],src[stride*i+1]-dst[stride*i+1]);
  1834. BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2]-dst[stride*i+2],src[stride*i+3]-dst[stride*i+3]);
  1835. BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4]-dst[stride*i+4],src[stride*i+5]-dst[stride*i+5]);
  1836. BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6]-dst[stride*i+6],src[stride*i+7]-dst[stride*i+7]);
  1837. BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
  1838. BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
  1839. BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
  1840. BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
  1841. BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
  1842. BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
  1843. BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
  1844. BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
  1845. }
  1846. for(i=0; i<8; i++){
  1847. BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
  1848. BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
  1849. BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
  1850. BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
  1851. BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
  1852. BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
  1853. BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
  1854. BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
  1855. sum +=
  1856. BUTTERFLYA(temp[8*0+i], temp[8*4+i])
  1857. +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
  1858. +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
  1859. +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
  1860. }
  1861. return sum;
  1862. }
  1863. static int hadamard8_intra8x8_c(/*MpegEncContext*/ void *s, uint8_t *src, uint8_t *dummy, int stride, int h){
  1864. int i;
  1865. int temp[64];
  1866. int sum=0;
  1867. assert(h==8);
  1868. for(i=0; i<8; i++){
  1869. //FIXME try pointer walks
  1870. BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0],src[stride*i+1]);
  1871. BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2],src[stride*i+3]);
  1872. BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4],src[stride*i+5]);
  1873. BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6],src[stride*i+7]);
  1874. BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
  1875. BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
  1876. BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
  1877. BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
  1878. BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
  1879. BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
  1880. BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
  1881. BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
  1882. }
  1883. for(i=0; i<8; i++){
  1884. BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
  1885. BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
  1886. BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
  1887. BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
  1888. BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
  1889. BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
  1890. BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
  1891. BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
  1892. sum +=
  1893. BUTTERFLYA(temp[8*0+i], temp[8*4+i])
  1894. +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
  1895. +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
  1896. +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
  1897. }
  1898. sum -= FFABS(temp[8*0] + temp[8*4]); // -mean
  1899. return sum;
  1900. }
  1901. static int dct_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  1902. MpegEncContext * const s= (MpegEncContext *)c;
  1903. LOCAL_ALIGNED_16(DCTELEM, temp, [64]);
  1904. assert(h==8);
  1905. s->dsp.diff_pixels(temp, src1, src2, stride);
  1906. s->dsp.fdct(temp);
  1907. return s->dsp.sum_abs_dctelem(temp);
  1908. }
  1909. #if CONFIG_GPL
  1910. #define DCT8_1D {\
  1911. const int s07 = SRC(0) + SRC(7);\
  1912. const int s16 = SRC(1) + SRC(6);\
  1913. const int s25 = SRC(2) + SRC(5);\
  1914. const int s34 = SRC(3) + SRC(4);\
  1915. const int a0 = s07 + s34;\
  1916. const int a1 = s16 + s25;\
  1917. const int a2 = s07 - s34;\
  1918. const int a3 = s16 - s25;\
  1919. const int d07 = SRC(0) - SRC(7);\
  1920. const int d16 = SRC(1) - SRC(6);\
  1921. const int d25 = SRC(2) - SRC(5);\
  1922. const int d34 = SRC(3) - SRC(4);\
  1923. const int a4 = d16 + d25 + (d07 + (d07>>1));\
  1924. const int a5 = d07 - d34 - (d25 + (d25>>1));\
  1925. const int a6 = d07 + d34 - (d16 + (d16>>1));\
  1926. const int a7 = d16 - d25 + (d34 + (d34>>1));\
  1927. DST(0, a0 + a1 ) ;\
  1928. DST(1, a4 + (a7>>2)) ;\
  1929. DST(2, a2 + (a3>>1)) ;\
  1930. DST(3, a5 + (a6>>2)) ;\
  1931. DST(4, a0 - a1 ) ;\
  1932. DST(5, a6 - (a5>>2)) ;\
  1933. DST(6, (a2>>1) - a3 ) ;\
  1934. DST(7, (a4>>2) - a7 ) ;\
  1935. }
  1936. static int dct264_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  1937. MpegEncContext * const s= (MpegEncContext *)c;
  1938. DCTELEM dct[8][8];
  1939. int i;
  1940. int sum=0;
  1941. s->dsp.diff_pixels(dct[0], src1, src2, stride);
  1942. #define SRC(x) dct[i][x]
  1943. #define DST(x,v) dct[i][x]= v
  1944. for( i = 0; i < 8; i++ )
  1945. DCT8_1D
  1946. #undef SRC
  1947. #undef DST
  1948. #define SRC(x) dct[x][i]
  1949. #define DST(x,v) sum += FFABS(v)
  1950. for( i = 0; i < 8; i++ )
  1951. DCT8_1D
  1952. #undef SRC
  1953. #undef DST
  1954. return sum;
  1955. }
  1956. #endif
  1957. static int dct_max8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  1958. MpegEncContext * const s= (MpegEncContext *)c;
  1959. LOCAL_ALIGNED_16(DCTELEM, temp, [64]);
  1960. int sum=0, i;
  1961. assert(h==8);
  1962. s->dsp.diff_pixels(temp, src1, src2, stride);
  1963. s->dsp.fdct(temp);
  1964. for(i=0; i<64; i++)
  1965. sum= FFMAX(sum, FFABS(temp[i]));
  1966. return sum;
  1967. }
  1968. static int quant_psnr8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  1969. MpegEncContext * const s= (MpegEncContext *)c;
  1970. LOCAL_ALIGNED_16(DCTELEM, temp, [64*2]);
  1971. DCTELEM * const bak = temp+64;
  1972. int sum=0, i;
  1973. assert(h==8);
  1974. s->mb_intra=0;
  1975. s->dsp.diff_pixels(temp, src1, src2, stride);
  1976. memcpy(bak, temp, 64*sizeof(DCTELEM));
  1977. s->block_last_index[0/*FIXME*/]= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  1978. s->dct_unquantize_inter(s, temp, 0, s->qscale);
  1979. ff_simple_idct_8(temp); //FIXME
  1980. for(i=0; i<64; i++)
  1981. sum+= (temp[i]-bak[i])*(temp[i]-bak[i]);
  1982. return sum;
  1983. }
  1984. static int rd8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  1985. MpegEncContext * const s= (MpegEncContext *)c;
  1986. const uint8_t *scantable= s->intra_scantable.permutated;
  1987. LOCAL_ALIGNED_16(DCTELEM, temp, [64]);
  1988. LOCAL_ALIGNED_16(uint8_t, lsrc1, [64]);
  1989. LOCAL_ALIGNED_16(uint8_t, lsrc2, [64]);
  1990. int i, last, run, bits, level, distortion, start_i;
  1991. const int esc_length= s->ac_esc_length;
  1992. uint8_t * length;
  1993. uint8_t * last_length;
  1994. assert(h==8);
  1995. copy_block8(lsrc1, src1, 8, stride, 8);
  1996. copy_block8(lsrc2, src2, 8, stride, 8);
  1997. s->dsp.diff_pixels(temp, lsrc1, lsrc2, 8);
  1998. s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  1999. bits=0;
  2000. if (s->mb_intra) {
  2001. start_i = 1;
  2002. length = s->intra_ac_vlc_length;
  2003. last_length= s->intra_ac_vlc_last_length;
  2004. bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
  2005. } else {
  2006. start_i = 0;
  2007. length = s->inter_ac_vlc_length;
  2008. last_length= s->inter_ac_vlc_last_length;
  2009. }
  2010. if(last>=start_i){
  2011. run=0;
  2012. for(i=start_i; i<last; i++){
  2013. int j= scantable[i];
  2014. level= temp[j];
  2015. if(level){
  2016. level+=64;
  2017. if((level&(~127)) == 0){
  2018. bits+= length[UNI_AC_ENC_INDEX(run, level)];
  2019. }else
  2020. bits+= esc_length;
  2021. run=0;
  2022. }else
  2023. run++;
  2024. }
  2025. i= scantable[last];
  2026. level= temp[i] + 64;
  2027. assert(level - 64);
  2028. if((level&(~127)) == 0){
  2029. bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
  2030. }else
  2031. bits+= esc_length;
  2032. }
  2033. if(last>=0){
  2034. if(s->mb_intra)
  2035. s->dct_unquantize_intra(s, temp, 0, s->qscale);
  2036. else
  2037. s->dct_unquantize_inter(s, temp, 0, s->qscale);
  2038. }
  2039. s->dsp.idct_add(lsrc2, 8, temp);
  2040. distortion= s->dsp.sse[1](NULL, lsrc2, lsrc1, 8, 8);
  2041. return distortion + ((bits*s->qscale*s->qscale*109 + 64)>>7);
  2042. }
  2043. static int bit8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  2044. MpegEncContext * const s= (MpegEncContext *)c;
  2045. const uint8_t *scantable= s->intra_scantable.permutated;
  2046. LOCAL_ALIGNED_16(DCTELEM, temp, [64]);
  2047. int i, last, run, bits, level, start_i;
  2048. const int esc_length= s->ac_esc_length;
  2049. uint8_t * length;
  2050. uint8_t * last_length;
  2051. assert(h==8);
  2052. s->dsp.diff_pixels(temp, src1, src2, stride);
  2053. s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  2054. bits=0;
  2055. if (s->mb_intra) {
  2056. start_i = 1;
  2057. length = s->intra_ac_vlc_length;
  2058. last_length= s->intra_ac_vlc_last_length;
  2059. bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
  2060. } else {
  2061. start_i = 0;
  2062. length = s->inter_ac_vlc_length;
  2063. last_length= s->inter_ac_vlc_last_length;
  2064. }
  2065. if(last>=start_i){
  2066. run=0;
  2067. for(i=start_i; i<last; i++){
  2068. int j= scantable[i];
  2069. level= temp[j];
  2070. if(level){
  2071. level+=64;
  2072. if((level&(~127)) == 0){
  2073. bits+= length[UNI_AC_ENC_INDEX(run, level)];
  2074. }else
  2075. bits+= esc_length;
  2076. run=0;
  2077. }else
  2078. run++;
  2079. }
  2080. i= scantable[last];
  2081. level= temp[i] + 64;
  2082. assert(level - 64);
  2083. if((level&(~127)) == 0){
  2084. bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
  2085. }else
  2086. bits+= esc_length;
  2087. }
  2088. return bits;
  2089. }
  2090. #define VSAD_INTRA(size) \
  2091. static int vsad_intra##size##_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){ \
  2092. int score=0; \
  2093. int x,y; \
  2094. \
  2095. for(y=1; y<h; y++){ \
  2096. for(x=0; x<size; x+=4){ \
  2097. score+= FFABS(s[x ] - s[x +stride]) + FFABS(s[x+1] - s[x+1+stride]) \
  2098. +FFABS(s[x+2] - s[x+2+stride]) + FFABS(s[x+3] - s[x+3+stride]); \
  2099. } \
  2100. s+= stride; \
  2101. } \
  2102. \
  2103. return score; \
  2104. }
  2105. VSAD_INTRA(8)
  2106. VSAD_INTRA(16)
  2107. static int vsad16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
  2108. int score=0;
  2109. int x,y;
  2110. for(y=1; y<h; y++){
  2111. for(x=0; x<16; x++){
  2112. score+= FFABS(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]);
  2113. }
  2114. s1+= stride;
  2115. s2+= stride;
  2116. }
  2117. return score;
  2118. }
  2119. #define SQ(a) ((a)*(a))
  2120. #define VSSE_INTRA(size) \
  2121. static int vsse_intra##size##_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){ \
  2122. int score=0; \
  2123. int x,y; \
  2124. \
  2125. for(y=1; y<h; y++){ \
  2126. for(x=0; x<size; x+=4){ \
  2127. score+= SQ(s[x ] - s[x +stride]) + SQ(s[x+1] - s[x+1+stride]) \
  2128. +SQ(s[x+2] - s[x+2+stride]) + SQ(s[x+3] - s[x+3+stride]); \
  2129. } \
  2130. s+= stride; \
  2131. } \
  2132. \
  2133. return score; \
  2134. }
  2135. VSSE_INTRA(8)
  2136. VSSE_INTRA(16)
  2137. static int vsse16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
  2138. int score=0;
  2139. int x,y;
  2140. for(y=1; y<h; y++){
  2141. for(x=0; x<16; x++){
  2142. score+= SQ(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]);
  2143. }
  2144. s1+= stride;
  2145. s2+= stride;
  2146. }
  2147. return score;
  2148. }
  2149. static int ssd_int8_vs_int16_c(const int8_t *pix1, const int16_t *pix2,
  2150. int size){
  2151. int score=0;
  2152. int i;
  2153. for(i=0; i<size; i++)
  2154. score += (pix1[i]-pix2[i])*(pix1[i]-pix2[i]);
  2155. return score;
  2156. }
  2157. WRAPPER8_16_SQ(hadamard8_diff8x8_c, hadamard8_diff16_c)
  2158. WRAPPER8_16_SQ(hadamard8_intra8x8_c, hadamard8_intra16_c)
  2159. WRAPPER8_16_SQ(dct_sad8x8_c, dct_sad16_c)
  2160. #if CONFIG_GPL
  2161. WRAPPER8_16_SQ(dct264_sad8x8_c, dct264_sad16_c)
  2162. #endif
  2163. WRAPPER8_16_SQ(dct_max8x8_c, dct_max16_c)
  2164. WRAPPER8_16_SQ(quant_psnr8x8_c, quant_psnr16_c)
  2165. WRAPPER8_16_SQ(rd8x8_c, rd16_c)
  2166. WRAPPER8_16_SQ(bit8x8_c, bit16_c)
  2167. static void vector_fmul_c(float *dst, const float *src0, const float *src1, int len){
  2168. int i;
  2169. for(i=0; i<len; i++)
  2170. dst[i] = src0[i] * src1[i];
  2171. }
  2172. static void vector_fmul_reverse_c(float *dst, const float *src0, const float *src1, int len){
  2173. int i;
  2174. src1 += len-1;
  2175. for(i=0; i<len; i++)
  2176. dst[i] = src0[i] * src1[-i];
  2177. }
  2178. static void vector_fmul_add_c(float *dst, const float *src0, const float *src1, const float *src2, int len){
  2179. int i;
  2180. for(i=0; i<len; i++)
  2181. dst[i] = src0[i] * src1[i] + src2[i];
  2182. }
  2183. static void vector_fmul_window_c(float *dst, const float *src0,
  2184. const float *src1, const float *win, int len)
  2185. {
  2186. int i,j;
  2187. dst += len;
  2188. win += len;
  2189. src0+= len;
  2190. for(i=-len, j=len-1; i<0; i++, j--) {
  2191. float s0 = src0[i];
  2192. float s1 = src1[j];
  2193. float wi = win[i];
  2194. float wj = win[j];
  2195. dst[i] = s0*wj - s1*wi;
  2196. dst[j] = s0*wi + s1*wj;
  2197. }
  2198. }
  2199. static void vector_fmul_scalar_c(float *dst, const float *src, float mul,
  2200. int len)
  2201. {
  2202. int i;
  2203. for (i = 0; i < len; i++)
  2204. dst[i] = src[i] * mul;
  2205. }
  2206. static void vector_fmac_scalar_c(float *dst, const float *src, float mul,
  2207. int len)
  2208. {
  2209. int i;
  2210. for (i = 0; i < len; i++)
  2211. dst[i] += src[i] * mul;
  2212. }
  2213. static void butterflies_float_c(float *restrict v1, float *restrict v2,
  2214. int len)
  2215. {
  2216. int i;
  2217. for (i = 0; i < len; i++) {
  2218. float t = v1[i] - v2[i];
  2219. v1[i] += v2[i];
  2220. v2[i] = t;
  2221. }
  2222. }
  2223. static void butterflies_float_interleave_c(float *dst, const float *src0,
  2224. const float *src1, int len)
  2225. {
  2226. int i;
  2227. for (i = 0; i < len; i++) {
  2228. float f1 = src0[i];
  2229. float f2 = src1[i];
  2230. dst[2*i ] = f1 + f2;
  2231. dst[2*i + 1] = f1 - f2;
  2232. }
  2233. }
  2234. static float scalarproduct_float_c(const float *v1, const float *v2, int len)
  2235. {
  2236. float p = 0.0;
  2237. int i;
  2238. for (i = 0; i < len; i++)
  2239. p += v1[i] * v2[i];
  2240. return p;
  2241. }
  2242. static inline uint32_t clipf_c_one(uint32_t a, uint32_t mini,
  2243. uint32_t maxi, uint32_t maxisign)
  2244. {
  2245. if(a > mini) return mini;
  2246. else if((a^(1U<<31)) > maxisign) return maxi;
  2247. else return a;
  2248. }
  2249. static void vector_clipf_c_opposite_sign(float *dst, const float *src, float *min, float *max, int len){
  2250. int i;
  2251. uint32_t mini = *(uint32_t*)min;
  2252. uint32_t maxi = *(uint32_t*)max;
  2253. uint32_t maxisign = maxi ^ (1U<<31);
  2254. uint32_t *dsti = (uint32_t*)dst;
  2255. const uint32_t *srci = (const uint32_t*)src;
  2256. for(i=0; i<len; i+=8) {
  2257. dsti[i + 0] = clipf_c_one(srci[i + 0], mini, maxi, maxisign);
  2258. dsti[i + 1] = clipf_c_one(srci[i + 1], mini, maxi, maxisign);
  2259. dsti[i + 2] = clipf_c_one(srci[i + 2], mini, maxi, maxisign);
  2260. dsti[i + 3] = clipf_c_one(srci[i + 3], mini, maxi, maxisign);
  2261. dsti[i + 4] = clipf_c_one(srci[i + 4], mini, maxi, maxisign);
  2262. dsti[i + 5] = clipf_c_one(srci[i + 5], mini, maxi, maxisign);
  2263. dsti[i + 6] = clipf_c_one(srci[i + 6], mini, maxi, maxisign);
  2264. dsti[i + 7] = clipf_c_one(srci[i + 7], mini, maxi, maxisign);
  2265. }
  2266. }
  2267. static void vector_clipf_c(float *dst, const float *src, float min, float max, int len){
  2268. int i;
  2269. if(min < 0 && max > 0) {
  2270. vector_clipf_c_opposite_sign(dst, src, &min, &max, len);
  2271. } else {
  2272. for(i=0; i < len; i+=8) {
  2273. dst[i ] = av_clipf(src[i ], min, max);
  2274. dst[i + 1] = av_clipf(src[i + 1], min, max);
  2275. dst[i + 2] = av_clipf(src[i + 2], min, max);
  2276. dst[i + 3] = av_clipf(src[i + 3], min, max);
  2277. dst[i + 4] = av_clipf(src[i + 4], min, max);
  2278. dst[i + 5] = av_clipf(src[i + 5], min, max);
  2279. dst[i + 6] = av_clipf(src[i + 6], min, max);
  2280. dst[i + 7] = av_clipf(src[i + 7], min, max);
  2281. }
  2282. }
  2283. }
  2284. static int32_t scalarproduct_int16_c(const int16_t * v1, const int16_t * v2, int order)
  2285. {
  2286. int res = 0;
  2287. while (order--)
  2288. res += *v1++ * *v2++;
  2289. return res;
  2290. }
  2291. static int32_t scalarproduct_and_madd_int16_c(int16_t *v1, const int16_t *v2, const int16_t *v3, int order, int mul)
  2292. {
  2293. int res = 0;
  2294. while (order--) {
  2295. res += *v1 * *v2++;
  2296. *v1++ += mul * *v3++;
  2297. }
  2298. return res;
  2299. }
  2300. static void apply_window_int16_c(int16_t *output, const int16_t *input,
  2301. const int16_t *window, unsigned int len)
  2302. {
  2303. int i;
  2304. int len2 = len >> 1;
  2305. for (i = 0; i < len2; i++) {
  2306. int16_t w = window[i];
  2307. output[i] = (MUL16(input[i], w) + (1 << 14)) >> 15;
  2308. output[len-i-1] = (MUL16(input[len-i-1], w) + (1 << 14)) >> 15;
  2309. }
  2310. }
  2311. static void vector_clip_int32_c(int32_t *dst, const int32_t *src, int32_t min,
  2312. int32_t max, unsigned int len)
  2313. {
  2314. do {
  2315. *dst++ = av_clip(*src++, min, max);
  2316. *dst++ = av_clip(*src++, min, max);
  2317. *dst++ = av_clip(*src++, min, max);
  2318. *dst++ = av_clip(*src++, min, max);
  2319. *dst++ = av_clip(*src++, min, max);
  2320. *dst++ = av_clip(*src++, min, max);
  2321. *dst++ = av_clip(*src++, min, max);
  2322. *dst++ = av_clip(*src++, min, max);
  2323. len -= 8;
  2324. } while (len > 0);
  2325. }
  2326. #define W0 2048
  2327. #define W1 2841 /* 2048*sqrt (2)*cos (1*pi/16) */
  2328. #define W2 2676 /* 2048*sqrt (2)*cos (2*pi/16) */
  2329. #define W3 2408 /* 2048*sqrt (2)*cos (3*pi/16) */
  2330. #define W4 2048 /* 2048*sqrt (2)*cos (4*pi/16) */
  2331. #define W5 1609 /* 2048*sqrt (2)*cos (5*pi/16) */
  2332. #define W6 1108 /* 2048*sqrt (2)*cos (6*pi/16) */
  2333. #define W7 565 /* 2048*sqrt (2)*cos (7*pi/16) */
  2334. static void wmv2_idct_row(short * b)
  2335. {
  2336. int s1,s2;
  2337. int a0,a1,a2,a3,a4,a5,a6,a7;
  2338. /*step 1*/
  2339. a1 = W1*b[1]+W7*b[7];
  2340. a7 = W7*b[1]-W1*b[7];
  2341. a5 = W5*b[5]+W3*b[3];
  2342. a3 = W3*b[5]-W5*b[3];
  2343. a2 = W2*b[2]+W6*b[6];
  2344. a6 = W6*b[2]-W2*b[6];
  2345. a0 = W0*b[0]+W0*b[4];
  2346. a4 = W0*b[0]-W0*b[4];
  2347. /*step 2*/
  2348. s1 = (181*(a1-a5+a7-a3)+128)>>8;//1,3,5,7,
  2349. s2 = (181*(a1-a5-a7+a3)+128)>>8;
  2350. /*step 3*/
  2351. b[0] = (a0+a2+a1+a5 + (1<<7))>>8;
  2352. b[1] = (a4+a6 +s1 + (1<<7))>>8;
  2353. b[2] = (a4-a6 +s2 + (1<<7))>>8;
  2354. b[3] = (a0-a2+a7+a3 + (1<<7))>>8;
  2355. b[4] = (a0-a2-a7-a3 + (1<<7))>>8;
  2356. b[5] = (a4-a6 -s2 + (1<<7))>>8;
  2357. b[6] = (a4+a6 -s1 + (1<<7))>>8;
  2358. b[7] = (a0+a2-a1-a5 + (1<<7))>>8;
  2359. }
  2360. static void wmv2_idct_col(short * b)
  2361. {
  2362. int s1,s2;
  2363. int a0,a1,a2,a3,a4,a5,a6,a7;
  2364. /*step 1, with extended precision*/
  2365. a1 = (W1*b[8*1]+W7*b[8*7] + 4)>>3;
  2366. a7 = (W7*b[8*1]-W1*b[8*7] + 4)>>3;
  2367. a5 = (W5*b[8*5]+W3*b[8*3] + 4)>>3;
  2368. a3 = (W3*b[8*5]-W5*b[8*3] + 4)>>3;
  2369. a2 = (W2*b[8*2]+W6*b[8*6] + 4)>>3;
  2370. a6 = (W6*b[8*2]-W2*b[8*6] + 4)>>3;
  2371. a0 = (W0*b[8*0]+W0*b[8*4] )>>3;
  2372. a4 = (W0*b[8*0]-W0*b[8*4] )>>3;
  2373. /*step 2*/
  2374. s1 = (181*(a1-a5+a7-a3)+128)>>8;
  2375. s2 = (181*(a1-a5-a7+a3)+128)>>8;
  2376. /*step 3*/
  2377. b[8*0] = (a0+a2+a1+a5 + (1<<13))>>14;
  2378. b[8*1] = (a4+a6 +s1 + (1<<13))>>14;
  2379. b[8*2] = (a4-a6 +s2 + (1<<13))>>14;
  2380. b[8*3] = (a0-a2+a7+a3 + (1<<13))>>14;
  2381. b[8*4] = (a0-a2-a7-a3 + (1<<13))>>14;
  2382. b[8*5] = (a4-a6 -s2 + (1<<13))>>14;
  2383. b[8*6] = (a4+a6 -s1 + (1<<13))>>14;
  2384. b[8*7] = (a0+a2-a1-a5 + (1<<13))>>14;
  2385. }
  2386. void ff_wmv2_idct_c(short * block){
  2387. int i;
  2388. for(i=0;i<64;i+=8){
  2389. wmv2_idct_row(block+i);
  2390. }
  2391. for(i=0;i<8;i++){
  2392. wmv2_idct_col(block+i);
  2393. }
  2394. }
  2395. /* XXX: those functions should be suppressed ASAP when all IDCTs are
  2396. converted */
  2397. static void ff_wmv2_idct_put_c(uint8_t *dest, int line_size, DCTELEM *block)
  2398. {
  2399. ff_wmv2_idct_c(block);
  2400. ff_put_pixels_clamped_c(block, dest, line_size);
  2401. }
  2402. static void ff_wmv2_idct_add_c(uint8_t *dest, int line_size, DCTELEM *block)
  2403. {
  2404. ff_wmv2_idct_c(block);
  2405. ff_add_pixels_clamped_c(block, dest, line_size);
  2406. }
  2407. static void ff_jref_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
  2408. {
  2409. ff_j_rev_dct (block);
  2410. ff_put_pixels_clamped_c(block, dest, line_size);
  2411. }
  2412. static void ff_jref_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
  2413. {
  2414. ff_j_rev_dct (block);
  2415. ff_add_pixels_clamped_c(block, dest, line_size);
  2416. }
  2417. static void just_return(void *mem av_unused, int stride av_unused, int h av_unused) { return; }
  2418. /* init static data */
  2419. av_cold void ff_dsputil_static_init(void)
  2420. {
  2421. int i;
  2422. for(i=0;i<256;i++) ff_cropTbl[i + MAX_NEG_CROP] = i;
  2423. for(i=0;i<MAX_NEG_CROP;i++) {
  2424. ff_cropTbl[i] = 0;
  2425. ff_cropTbl[i + MAX_NEG_CROP + 256] = 255;
  2426. }
  2427. for(i=0;i<512;i++) {
  2428. ff_squareTbl[i] = (i - 256) * (i - 256);
  2429. }
  2430. for(i=0; i<64; i++) ff_inv_zigzag_direct16[ff_zigzag_direct[i]]= i+1;
  2431. }
  2432. int ff_check_alignment(void){
  2433. static int did_fail=0;
  2434. LOCAL_ALIGNED_16(int, aligned, [4]);
  2435. if((intptr_t)aligned & 15){
  2436. if(!did_fail){
  2437. #if HAVE_MMX || HAVE_ALTIVEC
  2438. av_log(NULL, AV_LOG_ERROR,
  2439. "Compiler did not align stack variables. Libavcodec has been miscompiled\n"
  2440. "and may be very slow or crash. This is not a bug in libavcodec,\n"
  2441. "but in the compiler. You may try recompiling using gcc >= 4.2.\n"
  2442. "Do not report crashes to FFmpeg developers.\n");
  2443. #endif
  2444. did_fail=1;
  2445. }
  2446. return -1;
  2447. }
  2448. return 0;
  2449. }
  2450. av_cold void ff_dsputil_init(DSPContext* c, AVCodecContext *avctx)
  2451. {
  2452. int i;
  2453. ff_check_alignment();
  2454. #if CONFIG_ENCODERS
  2455. if (avctx->bits_per_raw_sample == 10) {
  2456. c->fdct = ff_jpeg_fdct_islow_10;
  2457. c->fdct248 = ff_fdct248_islow_10;
  2458. } else {
  2459. if(avctx->dct_algo==FF_DCT_FASTINT) {
  2460. c->fdct = ff_fdct_ifast;
  2461. c->fdct248 = ff_fdct_ifast248;
  2462. }
  2463. else if(avctx->dct_algo==FF_DCT_FAAN) {
  2464. c->fdct = ff_faandct;
  2465. c->fdct248 = ff_faandct248;
  2466. }
  2467. else {
  2468. c->fdct = ff_jpeg_fdct_islow_8; //slow/accurate/default
  2469. c->fdct248 = ff_fdct248_islow_8;
  2470. }
  2471. }
  2472. #endif //CONFIG_ENCODERS
  2473. if (avctx->bits_per_raw_sample == 10) {
  2474. c->idct_put = ff_simple_idct_put_10;
  2475. c->idct_add = ff_simple_idct_add_10;
  2476. c->idct = ff_simple_idct_10;
  2477. c->idct_permutation_type = FF_NO_IDCT_PERM;
  2478. } else {
  2479. if(avctx->idct_algo==FF_IDCT_INT){
  2480. c->idct_put= ff_jref_idct_put;
  2481. c->idct_add= ff_jref_idct_add;
  2482. c->idct = ff_j_rev_dct;
  2483. c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
  2484. }else if((CONFIG_VP3_DECODER || CONFIG_VP5_DECODER || CONFIG_VP6_DECODER ) &&
  2485. avctx->idct_algo==FF_IDCT_VP3){
  2486. c->idct_put= ff_vp3_idct_put_c;
  2487. c->idct_add= ff_vp3_idct_add_c;
  2488. c->idct = ff_vp3_idct_c;
  2489. c->idct_permutation_type= FF_NO_IDCT_PERM;
  2490. }else if(avctx->idct_algo==FF_IDCT_WMV2){
  2491. c->idct_put= ff_wmv2_idct_put_c;
  2492. c->idct_add= ff_wmv2_idct_add_c;
  2493. c->idct = ff_wmv2_idct_c;
  2494. c->idct_permutation_type= FF_NO_IDCT_PERM;
  2495. }else if(avctx->idct_algo==FF_IDCT_FAAN){
  2496. c->idct_put= ff_faanidct_put;
  2497. c->idct_add= ff_faanidct_add;
  2498. c->idct = ff_faanidct;
  2499. c->idct_permutation_type= FF_NO_IDCT_PERM;
  2500. }else if(CONFIG_EATGQ_DECODER && avctx->idct_algo==FF_IDCT_EA) {
  2501. c->idct_put= ff_ea_idct_put_c;
  2502. c->idct_permutation_type= FF_NO_IDCT_PERM;
  2503. }else{ //accurate/default
  2504. c->idct_put = ff_simple_idct_put_8;
  2505. c->idct_add = ff_simple_idct_add_8;
  2506. c->idct = ff_simple_idct_8;
  2507. c->idct_permutation_type= FF_NO_IDCT_PERM;
  2508. }
  2509. }
  2510. c->diff_pixels = diff_pixels_c;
  2511. c->put_pixels_clamped = ff_put_pixels_clamped_c;
  2512. c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_c;
  2513. c->add_pixels_clamped = ff_add_pixels_clamped_c;
  2514. c->sum_abs_dctelem = sum_abs_dctelem_c;
  2515. c->gmc1 = gmc1_c;
  2516. c->gmc = ff_gmc_c;
  2517. c->pix_sum = pix_sum_c;
  2518. c->pix_norm1 = pix_norm1_c;
  2519. c->fill_block_tab[0] = fill_block16_c;
  2520. c->fill_block_tab[1] = fill_block8_c;
  2521. /* TODO [0] 16 [1] 8 */
  2522. c->pix_abs[0][0] = pix_abs16_c;
  2523. c->pix_abs[0][1] = pix_abs16_x2_c;
  2524. c->pix_abs[0][2] = pix_abs16_y2_c;
  2525. c->pix_abs[0][3] = pix_abs16_xy2_c;
  2526. c->pix_abs[1][0] = pix_abs8_c;
  2527. c->pix_abs[1][1] = pix_abs8_x2_c;
  2528. c->pix_abs[1][2] = pix_abs8_y2_c;
  2529. c->pix_abs[1][3] = pix_abs8_xy2_c;
  2530. c->put_tpel_pixels_tab[ 0] = put_tpel_pixels_mc00_c;
  2531. c->put_tpel_pixels_tab[ 1] = put_tpel_pixels_mc10_c;
  2532. c->put_tpel_pixels_tab[ 2] = put_tpel_pixels_mc20_c;
  2533. c->put_tpel_pixels_tab[ 4] = put_tpel_pixels_mc01_c;
  2534. c->put_tpel_pixels_tab[ 5] = put_tpel_pixels_mc11_c;
  2535. c->put_tpel_pixels_tab[ 6] = put_tpel_pixels_mc21_c;
  2536. c->put_tpel_pixels_tab[ 8] = put_tpel_pixels_mc02_c;
  2537. c->put_tpel_pixels_tab[ 9] = put_tpel_pixels_mc12_c;
  2538. c->put_tpel_pixels_tab[10] = put_tpel_pixels_mc22_c;
  2539. c->avg_tpel_pixels_tab[ 0] = avg_tpel_pixels_mc00_c;
  2540. c->avg_tpel_pixels_tab[ 1] = avg_tpel_pixels_mc10_c;
  2541. c->avg_tpel_pixels_tab[ 2] = avg_tpel_pixels_mc20_c;
  2542. c->avg_tpel_pixels_tab[ 4] = avg_tpel_pixels_mc01_c;
  2543. c->avg_tpel_pixels_tab[ 5] = avg_tpel_pixels_mc11_c;
  2544. c->avg_tpel_pixels_tab[ 6] = avg_tpel_pixels_mc21_c;
  2545. c->avg_tpel_pixels_tab[ 8] = avg_tpel_pixels_mc02_c;
  2546. c->avg_tpel_pixels_tab[ 9] = avg_tpel_pixels_mc12_c;
  2547. c->avg_tpel_pixels_tab[10] = avg_tpel_pixels_mc22_c;
  2548. #define dspfunc(PFX, IDX, NUM) \
  2549. c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_c; \
  2550. c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_c; \
  2551. c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_c; \
  2552. c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_c; \
  2553. c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_c; \
  2554. c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_c; \
  2555. c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_c; \
  2556. c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_c; \
  2557. c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_c; \
  2558. c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_c; \
  2559. c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_c; \
  2560. c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_c; \
  2561. c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_c; \
  2562. c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_c; \
  2563. c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_c; \
  2564. c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_c
  2565. dspfunc(put_qpel, 0, 16);
  2566. dspfunc(put_no_rnd_qpel, 0, 16);
  2567. dspfunc(avg_qpel, 0, 16);
  2568. /* dspfunc(avg_no_rnd_qpel, 0, 16); */
  2569. dspfunc(put_qpel, 1, 8);
  2570. dspfunc(put_no_rnd_qpel, 1, 8);
  2571. dspfunc(avg_qpel, 1, 8);
  2572. /* dspfunc(avg_no_rnd_qpel, 1, 8); */
  2573. #undef dspfunc
  2574. #if CONFIG_MLP_DECODER || CONFIG_TRUEHD_DECODER
  2575. ff_mlp_init(c, avctx);
  2576. #endif
  2577. #if CONFIG_WMV2_DECODER || CONFIG_VC1_DECODER
  2578. ff_intrax8dsp_init(c,avctx);
  2579. #endif
  2580. c->put_mspel_pixels_tab[0]= ff_put_pixels8x8_c;
  2581. c->put_mspel_pixels_tab[1]= put_mspel8_mc10_c;
  2582. c->put_mspel_pixels_tab[2]= put_mspel8_mc20_c;
  2583. c->put_mspel_pixels_tab[3]= put_mspel8_mc30_c;
  2584. c->put_mspel_pixels_tab[4]= put_mspel8_mc02_c;
  2585. c->put_mspel_pixels_tab[5]= put_mspel8_mc12_c;
  2586. c->put_mspel_pixels_tab[6]= put_mspel8_mc22_c;
  2587. c->put_mspel_pixels_tab[7]= put_mspel8_mc32_c;
  2588. #define SET_CMP_FUNC(name) \
  2589. c->name[0]= name ## 16_c;\
  2590. c->name[1]= name ## 8x8_c;
  2591. SET_CMP_FUNC(hadamard8_diff)
  2592. c->hadamard8_diff[4]= hadamard8_intra16_c;
  2593. c->hadamard8_diff[5]= hadamard8_intra8x8_c;
  2594. SET_CMP_FUNC(dct_sad)
  2595. SET_CMP_FUNC(dct_max)
  2596. #if CONFIG_GPL
  2597. SET_CMP_FUNC(dct264_sad)
  2598. #endif
  2599. c->sad[0]= pix_abs16_c;
  2600. c->sad[1]= pix_abs8_c;
  2601. c->sse[0]= sse16_c;
  2602. c->sse[1]= sse8_c;
  2603. c->sse[2]= sse4_c;
  2604. SET_CMP_FUNC(quant_psnr)
  2605. SET_CMP_FUNC(rd)
  2606. SET_CMP_FUNC(bit)
  2607. c->vsad[0]= vsad16_c;
  2608. c->vsad[4]= vsad_intra16_c;
  2609. c->vsad[5]= vsad_intra8_c;
  2610. c->vsse[0]= vsse16_c;
  2611. c->vsse[4]= vsse_intra16_c;
  2612. c->vsse[5]= vsse_intra8_c;
  2613. c->nsse[0]= nsse16_c;
  2614. c->nsse[1]= nsse8_c;
  2615. #if CONFIG_DWT
  2616. ff_dsputil_init_dwt(c);
  2617. #endif
  2618. c->ssd_int8_vs_int16 = ssd_int8_vs_int16_c;
  2619. c->add_bytes= add_bytes_c;
  2620. c->diff_bytes= diff_bytes_c;
  2621. c->add_hfyu_median_prediction= add_hfyu_median_prediction_c;
  2622. c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_c;
  2623. c->add_hfyu_left_prediction = add_hfyu_left_prediction_c;
  2624. c->add_hfyu_left_prediction_bgr32 = add_hfyu_left_prediction_bgr32_c;
  2625. c->bswap_buf= bswap_buf;
  2626. c->bswap16_buf = bswap16_buf;
  2627. if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
  2628. c->h263_h_loop_filter= h263_h_loop_filter_c;
  2629. c->h263_v_loop_filter= h263_v_loop_filter_c;
  2630. }
  2631. if (CONFIG_VP3_DECODER) {
  2632. c->vp3_h_loop_filter= ff_vp3_h_loop_filter_c;
  2633. c->vp3_v_loop_filter= ff_vp3_v_loop_filter_c;
  2634. c->vp3_idct_dc_add= ff_vp3_idct_dc_add_c;
  2635. }
  2636. c->h261_loop_filter= h261_loop_filter_c;
  2637. c->try_8x8basis= try_8x8basis_c;
  2638. c->add_8x8basis= add_8x8basis_c;
  2639. #if CONFIG_VORBIS_DECODER
  2640. c->vorbis_inverse_coupling = ff_vorbis_inverse_coupling;
  2641. #endif
  2642. #if CONFIG_AC3_DECODER
  2643. c->ac3_downmix = ff_ac3_downmix_c;
  2644. #endif
  2645. c->vector_fmul = vector_fmul_c;
  2646. c->vector_fmul_reverse = vector_fmul_reverse_c;
  2647. c->vector_fmul_add = vector_fmul_add_c;
  2648. c->vector_fmul_window = vector_fmul_window_c;
  2649. c->vector_clipf = vector_clipf_c;
  2650. c->scalarproduct_int16 = scalarproduct_int16_c;
  2651. c->scalarproduct_and_madd_int16 = scalarproduct_and_madd_int16_c;
  2652. c->apply_window_int16 = apply_window_int16_c;
  2653. c->vector_clip_int32 = vector_clip_int32_c;
  2654. c->scalarproduct_float = scalarproduct_float_c;
  2655. c->butterflies_float = butterflies_float_c;
  2656. c->butterflies_float_interleave = butterflies_float_interleave_c;
  2657. c->vector_fmul_scalar = vector_fmul_scalar_c;
  2658. c->vector_fmac_scalar = vector_fmac_scalar_c;
  2659. c->shrink[0]= av_image_copy_plane;
  2660. c->shrink[1]= ff_shrink22;
  2661. c->shrink[2]= ff_shrink44;
  2662. c->shrink[3]= ff_shrink88;
  2663. c->prefetch= just_return;
  2664. memset(c->put_2tap_qpel_pixels_tab, 0, sizeof(c->put_2tap_qpel_pixels_tab));
  2665. memset(c->avg_2tap_qpel_pixels_tab, 0, sizeof(c->avg_2tap_qpel_pixels_tab));
  2666. #undef FUNC
  2667. #undef FUNCC
  2668. #define FUNC(f, depth) f ## _ ## depth
  2669. #define FUNCC(f, depth) f ## _ ## depth ## _c
  2670. #define dspfunc1(PFX, IDX, NUM, depth)\
  2671. c->PFX ## _pixels_tab[IDX][0] = FUNCC(PFX ## _pixels ## NUM , depth);\
  2672. c->PFX ## _pixels_tab[IDX][1] = FUNCC(PFX ## _pixels ## NUM ## _x2 , depth);\
  2673. c->PFX ## _pixels_tab[IDX][2] = FUNCC(PFX ## _pixels ## NUM ## _y2 , depth);\
  2674. c->PFX ## _pixels_tab[IDX][3] = FUNCC(PFX ## _pixels ## NUM ## _xy2, depth)
  2675. #define dspfunc2(PFX, IDX, NUM, depth)\
  2676. c->PFX ## _pixels_tab[IDX][ 0] = FUNCC(PFX ## NUM ## _mc00, depth);\
  2677. c->PFX ## _pixels_tab[IDX][ 1] = FUNCC(PFX ## NUM ## _mc10, depth);\
  2678. c->PFX ## _pixels_tab[IDX][ 2] = FUNCC(PFX ## NUM ## _mc20, depth);\
  2679. c->PFX ## _pixels_tab[IDX][ 3] = FUNCC(PFX ## NUM ## _mc30, depth);\
  2680. c->PFX ## _pixels_tab[IDX][ 4] = FUNCC(PFX ## NUM ## _mc01, depth);\
  2681. c->PFX ## _pixels_tab[IDX][ 5] = FUNCC(PFX ## NUM ## _mc11, depth);\
  2682. c->PFX ## _pixels_tab[IDX][ 6] = FUNCC(PFX ## NUM ## _mc21, depth);\
  2683. c->PFX ## _pixels_tab[IDX][ 7] = FUNCC(PFX ## NUM ## _mc31, depth);\
  2684. c->PFX ## _pixels_tab[IDX][ 8] = FUNCC(PFX ## NUM ## _mc02, depth);\
  2685. c->PFX ## _pixels_tab[IDX][ 9] = FUNCC(PFX ## NUM ## _mc12, depth);\
  2686. c->PFX ## _pixels_tab[IDX][10] = FUNCC(PFX ## NUM ## _mc22, depth);\
  2687. c->PFX ## _pixels_tab[IDX][11] = FUNCC(PFX ## NUM ## _mc32, depth);\
  2688. c->PFX ## _pixels_tab[IDX][12] = FUNCC(PFX ## NUM ## _mc03, depth);\
  2689. c->PFX ## _pixels_tab[IDX][13] = FUNCC(PFX ## NUM ## _mc13, depth);\
  2690. c->PFX ## _pixels_tab[IDX][14] = FUNCC(PFX ## NUM ## _mc23, depth);\
  2691. c->PFX ## _pixels_tab[IDX][15] = FUNCC(PFX ## NUM ## _mc33, depth)
  2692. #define BIT_DEPTH_FUNCS(depth, dct)\
  2693. c->get_pixels = FUNCC(get_pixels ## dct , depth);\
  2694. c->draw_edges = FUNCC(draw_edges , depth);\
  2695. c->emulated_edge_mc = FUNC (ff_emulated_edge_mc , depth);\
  2696. c->clear_block = FUNCC(clear_block ## dct , depth);\
  2697. c->clear_blocks = FUNCC(clear_blocks ## dct , depth);\
  2698. c->add_pixels8 = FUNCC(add_pixels8 ## dct , depth);\
  2699. c->add_pixels4 = FUNCC(add_pixels4 ## dct , depth);\
  2700. c->put_no_rnd_pixels_l2[0] = FUNCC(put_no_rnd_pixels16_l2, depth);\
  2701. c->put_no_rnd_pixels_l2[1] = FUNCC(put_no_rnd_pixels8_l2 , depth);\
  2702. \
  2703. c->put_h264_chroma_pixels_tab[0] = FUNCC(put_h264_chroma_mc8 , depth);\
  2704. c->put_h264_chroma_pixels_tab[1] = FUNCC(put_h264_chroma_mc4 , depth);\
  2705. c->put_h264_chroma_pixels_tab[2] = FUNCC(put_h264_chroma_mc2 , depth);\
  2706. c->avg_h264_chroma_pixels_tab[0] = FUNCC(avg_h264_chroma_mc8 , depth);\
  2707. c->avg_h264_chroma_pixels_tab[1] = FUNCC(avg_h264_chroma_mc4 , depth);\
  2708. c->avg_h264_chroma_pixels_tab[2] = FUNCC(avg_h264_chroma_mc2 , depth);\
  2709. \
  2710. dspfunc1(put , 0, 16, depth);\
  2711. dspfunc1(put , 1, 8, depth);\
  2712. dspfunc1(put , 2, 4, depth);\
  2713. dspfunc1(put , 3, 2, depth);\
  2714. dspfunc1(put_no_rnd, 0, 16, depth);\
  2715. dspfunc1(put_no_rnd, 1, 8, depth);\
  2716. dspfunc1(avg , 0, 16, depth);\
  2717. dspfunc1(avg , 1, 8, depth);\
  2718. dspfunc1(avg , 2, 4, depth);\
  2719. dspfunc1(avg , 3, 2, depth);\
  2720. dspfunc1(avg_no_rnd, 0, 16, depth);\
  2721. dspfunc1(avg_no_rnd, 1, 8, depth);\
  2722. \
  2723. dspfunc2(put_h264_qpel, 0, 16, depth);\
  2724. dspfunc2(put_h264_qpel, 1, 8, depth);\
  2725. dspfunc2(put_h264_qpel, 2, 4, depth);\
  2726. dspfunc2(put_h264_qpel, 3, 2, depth);\
  2727. dspfunc2(avg_h264_qpel, 0, 16, depth);\
  2728. dspfunc2(avg_h264_qpel, 1, 8, depth);\
  2729. dspfunc2(avg_h264_qpel, 2, 4, depth);
  2730. switch (avctx->bits_per_raw_sample) {
  2731. case 9:
  2732. if (c->dct_bits == 32) {
  2733. BIT_DEPTH_FUNCS(9, _32);
  2734. } else {
  2735. BIT_DEPTH_FUNCS(9, _16);
  2736. }
  2737. break;
  2738. case 10:
  2739. if (c->dct_bits == 32) {
  2740. BIT_DEPTH_FUNCS(10, _32);
  2741. } else {
  2742. BIT_DEPTH_FUNCS(10, _16);
  2743. }
  2744. break;
  2745. default:
  2746. BIT_DEPTH_FUNCS(8, _16);
  2747. break;
  2748. }
  2749. if (HAVE_MMX) ff_dsputil_init_mmx (c, avctx);
  2750. if (ARCH_ARM) ff_dsputil_init_arm (c, avctx);
  2751. if (HAVE_VIS) ff_dsputil_init_vis (c, avctx);
  2752. if (ARCH_ALPHA) ff_dsputil_init_alpha (c, avctx);
  2753. if (ARCH_PPC) ff_dsputil_init_ppc (c, avctx);
  2754. if (HAVE_MMI) ff_dsputil_init_mmi (c, avctx);
  2755. if (ARCH_SH4) ff_dsputil_init_sh4 (c, avctx);
  2756. if (ARCH_BFIN) ff_dsputil_init_bfin (c, avctx);
  2757. for(i=0; i<64; i++){
  2758. if(!c->put_2tap_qpel_pixels_tab[0][i])
  2759. c->put_2tap_qpel_pixels_tab[0][i]= c->put_h264_qpel_pixels_tab[0][i];
  2760. if(!c->avg_2tap_qpel_pixels_tab[0][i])
  2761. c->avg_2tap_qpel_pixels_tab[0][i]= c->avg_h264_qpel_pixels_tab[0][i];
  2762. }
  2763. ff_init_scantable_permutation(c->idct_permutation,
  2764. c->idct_permutation_type);
  2765. }
  2766. av_cold void dsputil_init(DSPContext* c, AVCodecContext *avctx)
  2767. {
  2768. ff_dsputil_init(c, avctx);
  2769. }