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.

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