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.

2817 lines
94KB

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