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.

2959 lines
99KB

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