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.

2853 lines
95KB

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