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.

2764 lines
93KB

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