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.

3145 lines
106KB

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