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.

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