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.

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