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.

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