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.

3188 lines
107KB

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