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.

2666 lines
89KB

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