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.

2993 lines
99KB

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