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.

2922 lines
98KB

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