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.

2960 lines
98KB

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