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.

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