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.

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