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.

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