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.

3023 lines
102KB

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