You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3188 lines
132KB

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