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.

2743 lines
93KB

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