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.

2756 lines
92KB

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