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.

3207 lines
108KB

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