You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3199 lines
108KB

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