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.

3153 lines
132KB

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