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.

2991 lines
102KB

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