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.

3148 lines
131KB

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