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.

2941 lines
99KB

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