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.

2971 lines
101KB

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