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.

2744 lines
93KB

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