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.

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