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.

742 lines
34KB

  1. /*
  2. * Copyright (C) 2010 David Conrad
  3. * Copyright (C) 2010 Ronald S. Bultje
  4. * Copyright (C) 2014 Peter Ross
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. /**
  23. * @file
  24. * VP8 compatible video decoder
  25. */
  26. #include "libavutil/common.h"
  27. #include "libavutil/intreadwrite.h"
  28. #include "mathops.h"
  29. #include "vp8dsp.h"
  30. #define MK_IDCT_DC_ADD4_C(name) \
  31. static void name ## _idct_dc_add4uv_c(uint8_t *dst, int16_t block[4][16], \
  32. ptrdiff_t stride) \
  33. { \
  34. name ## _idct_dc_add_c(dst + stride * 0 + 0, block[0], stride); \
  35. name ## _idct_dc_add_c(dst + stride * 0 + 4, block[1], stride); \
  36. name ## _idct_dc_add_c(dst + stride * 4 + 0, block[2], stride); \
  37. name ## _idct_dc_add_c(dst + stride * 4 + 4, block[3], stride); \
  38. } \
  39. \
  40. static void name ## _idct_dc_add4y_c(uint8_t *dst, int16_t block[4][16], \
  41. ptrdiff_t stride) \
  42. { \
  43. name ## _idct_dc_add_c(dst + 0, block[0], stride); \
  44. name ## _idct_dc_add_c(dst + 4, block[1], stride); \
  45. name ## _idct_dc_add_c(dst + 8, block[2], stride); \
  46. name ## _idct_dc_add_c(dst + 12, block[3], stride); \
  47. }
  48. #if CONFIG_VP7_DECODER
  49. static void vp7_luma_dc_wht_c(int16_t block[4][4][16], int16_t dc[16])
  50. {
  51. int i, a1, b1, c1, d1;
  52. int16_t tmp[16];
  53. for (i = 0; i < 4; i++) {
  54. a1 = (dc[i * 4 + 0] + dc[i * 4 + 2]) * 23170;
  55. b1 = (dc[i * 4 + 0] - dc[i * 4 + 2]) * 23170;
  56. c1 = dc[i * 4 + 1] * 12540 - dc[i * 4 + 3] * 30274;
  57. d1 = dc[i * 4 + 1] * 30274 + dc[i * 4 + 3] * 12540;
  58. tmp[i * 4 + 0] = (a1 + d1) >> 14;
  59. tmp[i * 4 + 3] = (a1 - d1) >> 14;
  60. tmp[i * 4 + 1] = (b1 + c1) >> 14;
  61. tmp[i * 4 + 2] = (b1 - c1) >> 14;
  62. }
  63. for (i = 0; i < 4; i++) {
  64. a1 = (tmp[i + 0] + tmp[i + 8]) * 23170;
  65. b1 = (tmp[i + 0] - tmp[i + 8]) * 23170;
  66. c1 = tmp[i + 4] * 12540 - tmp[i + 12] * 30274;
  67. d1 = tmp[i + 4] * 30274 + tmp[i + 12] * 12540;
  68. AV_ZERO64(dc + i * 4);
  69. block[0][i][0] = (a1 + d1 + 0x20000) >> 18;
  70. block[3][i][0] = (a1 - d1 + 0x20000) >> 18;
  71. block[1][i][0] = (b1 + c1 + 0x20000) >> 18;
  72. block[2][i][0] = (b1 - c1 + 0x20000) >> 18;
  73. }
  74. }
  75. static void vp7_luma_dc_wht_dc_c(int16_t block[4][4][16], int16_t dc[16])
  76. {
  77. int i, val = (23170 * (23170 * dc[0] >> 14) + 0x20000) >> 18;
  78. dc[0] = 0;
  79. for (i = 0; i < 4; i++) {
  80. block[i][0][0] = val;
  81. block[i][1][0] = val;
  82. block[i][2][0] = val;
  83. block[i][3][0] = val;
  84. }
  85. }
  86. static void vp7_idct_add_c(uint8_t *dst, int16_t block[16], ptrdiff_t stride)
  87. {
  88. int i, a1, b1, c1, d1;
  89. int16_t tmp[16];
  90. for (i = 0; i < 4; i++) {
  91. a1 = (block[i * 4 + 0] + block[i * 4 + 2]) * 23170;
  92. b1 = (block[i * 4 + 0] - block[i * 4 + 2]) * 23170;
  93. c1 = block[i * 4 + 1] * 12540 - block[i * 4 + 3] * 30274;
  94. d1 = block[i * 4 + 1] * 30274 + block[i * 4 + 3] * 12540;
  95. AV_ZERO64(block + i * 4);
  96. tmp[i * 4 + 0] = (a1 + d1) >> 14;
  97. tmp[i * 4 + 3] = (a1 - d1) >> 14;
  98. tmp[i * 4 + 1] = (b1 + c1) >> 14;
  99. tmp[i * 4 + 2] = (b1 - c1) >> 14;
  100. }
  101. for (i = 0; i < 4; i++) {
  102. a1 = (tmp[i + 0] + tmp[i + 8]) * 23170;
  103. b1 = (tmp[i + 0] - tmp[i + 8]) * 23170;
  104. c1 = tmp[i + 4] * 12540 - tmp[i + 12] * 30274;
  105. d1 = tmp[i + 4] * 30274 + tmp[i + 12] * 12540;
  106. dst[0 * stride + i] = av_clip_uint8(dst[0 * stride + i] +
  107. ((a1 + d1 + 0x20000) >> 18));
  108. dst[3 * stride + i] = av_clip_uint8(dst[3 * stride + i] +
  109. ((a1 - d1 + 0x20000) >> 18));
  110. dst[1 * stride + i] = av_clip_uint8(dst[1 * stride + i] +
  111. ((b1 + c1 + 0x20000) >> 18));
  112. dst[2 * stride + i] = av_clip_uint8(dst[2 * stride + i] +
  113. ((b1 - c1 + 0x20000) >> 18));
  114. }
  115. }
  116. static void vp7_idct_dc_add_c(uint8_t *dst, int16_t block[16], ptrdiff_t stride)
  117. {
  118. int i, dc = (23170 * (23170 * block[0] >> 14) + 0x20000) >> 18;
  119. block[0] = 0;
  120. for (i = 0; i < 4; i++) {
  121. dst[0] = av_clip_uint8(dst[0] + dc);
  122. dst[1] = av_clip_uint8(dst[1] + dc);
  123. dst[2] = av_clip_uint8(dst[2] + dc);
  124. dst[3] = av_clip_uint8(dst[3] + dc);
  125. dst += stride;
  126. }
  127. }
  128. MK_IDCT_DC_ADD4_C(vp7)
  129. #endif /* CONFIG_VP7_DECODER */
  130. // TODO: Maybe add dequant
  131. #if CONFIG_VP8_DECODER
  132. static void vp8_luma_dc_wht_c(int16_t block[4][4][16], int16_t dc[16])
  133. {
  134. int i, t0, t1, t2, t3;
  135. for (i = 0; i < 4; i++) {
  136. t0 = dc[0 * 4 + i] + dc[3 * 4 + i];
  137. t1 = dc[1 * 4 + i] + dc[2 * 4 + i];
  138. t2 = dc[1 * 4 + i] - dc[2 * 4 + i];
  139. t3 = dc[0 * 4 + i] - dc[3 * 4 + i];
  140. dc[0 * 4 + i] = t0 + t1;
  141. dc[1 * 4 + i] = t3 + t2;
  142. dc[2 * 4 + i] = t0 - t1;
  143. dc[3 * 4 + i] = t3 - t2;
  144. }
  145. for (i = 0; i < 4; i++) {
  146. t0 = dc[i * 4 + 0] + dc[i * 4 + 3] + 3; // rounding
  147. t1 = dc[i * 4 + 1] + dc[i * 4 + 2];
  148. t2 = dc[i * 4 + 1] - dc[i * 4 + 2];
  149. t3 = dc[i * 4 + 0] - dc[i * 4 + 3] + 3; // rounding
  150. AV_ZERO64(dc + i * 4);
  151. block[i][0][0] = (t0 + t1) >> 3;
  152. block[i][1][0] = (t3 + t2) >> 3;
  153. block[i][2][0] = (t0 - t1) >> 3;
  154. block[i][3][0] = (t3 - t2) >> 3;
  155. }
  156. }
  157. static void vp8_luma_dc_wht_dc_c(int16_t block[4][4][16], int16_t dc[16])
  158. {
  159. int i, val = (dc[0] + 3) >> 3;
  160. dc[0] = 0;
  161. for (i = 0; i < 4; i++) {
  162. block[i][0][0] = val;
  163. block[i][1][0] = val;
  164. block[i][2][0] = val;
  165. block[i][3][0] = val;
  166. }
  167. }
  168. #define MUL_20091(a) ((((a) * 20091) >> 16) + (a))
  169. #define MUL_35468(a) (((a) * 35468) >> 16)
  170. static void vp8_idct_add_c(uint8_t *dst, int16_t block[16], ptrdiff_t stride)
  171. {
  172. int i, t0, t1, t2, t3;
  173. int16_t tmp[16];
  174. for (i = 0; i < 4; i++) {
  175. t0 = block[0 * 4 + i] + block[2 * 4 + i];
  176. t1 = block[0 * 4 + i] - block[2 * 4 + i];
  177. t2 = MUL_35468(block[1 * 4 + i]) - MUL_20091(block[3 * 4 + i]);
  178. t3 = MUL_20091(block[1 * 4 + i]) + MUL_35468(block[3 * 4 + i]);
  179. block[0 * 4 + i] = 0;
  180. block[1 * 4 + i] = 0;
  181. block[2 * 4 + i] = 0;
  182. block[3 * 4 + i] = 0;
  183. tmp[i * 4 + 0] = t0 + t3;
  184. tmp[i * 4 + 1] = t1 + t2;
  185. tmp[i * 4 + 2] = t1 - t2;
  186. tmp[i * 4 + 3] = t0 - t3;
  187. }
  188. for (i = 0; i < 4; i++) {
  189. t0 = tmp[0 * 4 + i] + tmp[2 * 4 + i];
  190. t1 = tmp[0 * 4 + i] - tmp[2 * 4 + i];
  191. t2 = MUL_35468(tmp[1 * 4 + i]) - MUL_20091(tmp[3 * 4 + i]);
  192. t3 = MUL_20091(tmp[1 * 4 + i]) + MUL_35468(tmp[3 * 4 + i]);
  193. dst[0] = av_clip_uint8(dst[0] + ((t0 + t3 + 4) >> 3));
  194. dst[1] = av_clip_uint8(dst[1] + ((t1 + t2 + 4) >> 3));
  195. dst[2] = av_clip_uint8(dst[2] + ((t1 - t2 + 4) >> 3));
  196. dst[3] = av_clip_uint8(dst[3] + ((t0 - t3 + 4) >> 3));
  197. dst += stride;
  198. }
  199. }
  200. static void vp8_idct_dc_add_c(uint8_t *dst, int16_t block[16], ptrdiff_t stride)
  201. {
  202. int i, dc = (block[0] + 4) >> 3;
  203. block[0] = 0;
  204. for (i = 0; i < 4; i++) {
  205. dst[0] = av_clip_uint8(dst[0] + dc);
  206. dst[1] = av_clip_uint8(dst[1] + dc);
  207. dst[2] = av_clip_uint8(dst[2] + dc);
  208. dst[3] = av_clip_uint8(dst[3] + dc);
  209. dst += stride;
  210. }
  211. }
  212. MK_IDCT_DC_ADD4_C(vp8)
  213. #endif /* CONFIG_VP8_DECODER */
  214. // because I like only having two parameters to pass functions...
  215. #define LOAD_PIXELS \
  216. int av_unused p3 = p[-4 * stride]; \
  217. int av_unused p2 = p[-3 * stride]; \
  218. int av_unused p1 = p[-2 * stride]; \
  219. int av_unused p0 = p[-1 * stride]; \
  220. int av_unused q0 = p[ 0 * stride]; \
  221. int av_unused q1 = p[ 1 * stride]; \
  222. int av_unused q2 = p[ 2 * stride]; \
  223. int av_unused q3 = p[ 3 * stride];
  224. #define clip_int8(n) (cm[(n) + 0x80] - 0x80)
  225. static av_always_inline void filter_common(uint8_t *p, ptrdiff_t stride,
  226. int is4tap, int is_vp7)
  227. {
  228. LOAD_PIXELS
  229. int a, f1, f2;
  230. const uint8_t *cm = ff_crop_tab + MAX_NEG_CROP;
  231. a = 3 * (q0 - p0);
  232. if (is4tap)
  233. a += clip_int8(p1 - q1);
  234. a = clip_int8(a);
  235. // We deviate from the spec here with c(a+3) >> 3
  236. // since that's what libvpx does.
  237. f1 = FFMIN(a + 4, 127) >> 3;
  238. if (is_vp7)
  239. f2 = f1 - ((a & 7) == 4);
  240. else
  241. f2 = FFMIN(a + 3, 127) >> 3;
  242. // Despite what the spec says, we do need to clamp here to
  243. // be bitexact with libvpx.
  244. p[-1 * stride] = cm[p0 + f2];
  245. p[ 0 * stride] = cm[q0 - f1];
  246. // only used for _inner on blocks without high edge variance
  247. if (!is4tap) {
  248. a = (f1 + 1) >> 1;
  249. p[-2 * stride] = cm[p1 + a];
  250. p[ 1 * stride] = cm[q1 - a];
  251. }
  252. }
  253. static av_always_inline void vp7_filter_common(uint8_t *p, ptrdiff_t stride,
  254. int is4tap)
  255. {
  256. filter_common(p, stride, is4tap, IS_VP7);
  257. }
  258. static av_always_inline void vp8_filter_common(uint8_t *p, ptrdiff_t stride,
  259. int is4tap)
  260. {
  261. filter_common(p, stride, is4tap, IS_VP8);
  262. }
  263. static av_always_inline int vp7_simple_limit(uint8_t *p, ptrdiff_t stride,
  264. int flim)
  265. {
  266. LOAD_PIXELS
  267. return FFABS(p0 - q0) <= flim;
  268. }
  269. static av_always_inline int vp8_simple_limit(uint8_t *p, ptrdiff_t stride,
  270. int flim)
  271. {
  272. LOAD_PIXELS
  273. return 2 * FFABS(p0 - q0) + (FFABS(p1 - q1) >> 1) <= flim;
  274. }
  275. /**
  276. * E - limit at the macroblock edge
  277. * I - limit for interior difference
  278. */
  279. #define NORMAL_LIMIT(vpn) \
  280. static av_always_inline int vp ## vpn ## _normal_limit(uint8_t *p, \
  281. ptrdiff_t stride, \
  282. int E, int I) \
  283. { \
  284. LOAD_PIXELS \
  285. return vp ## vpn ## _simple_limit(p, stride, E) && \
  286. FFABS(p3 - p2) <= I && FFABS(p2 - p1) <= I && \
  287. FFABS(p1 - p0) <= I && FFABS(q3 - q2) <= I && \
  288. FFABS(q2 - q1) <= I && FFABS(q1 - q0) <= I; \
  289. }
  290. NORMAL_LIMIT(7)
  291. NORMAL_LIMIT(8)
  292. // high edge variance
  293. static av_always_inline int hev(uint8_t *p, ptrdiff_t stride, int thresh)
  294. {
  295. LOAD_PIXELS
  296. return FFABS(p1 - p0) > thresh || FFABS(q1 - q0) > thresh;
  297. }
  298. static av_always_inline void filter_mbedge(uint8_t *p, ptrdiff_t stride)
  299. {
  300. int a0, a1, a2, w;
  301. const uint8_t *cm = ff_crop_tab + MAX_NEG_CROP;
  302. LOAD_PIXELS
  303. w = clip_int8(p1 - q1);
  304. w = clip_int8(w + 3 * (q0 - p0));
  305. a0 = (27 * w + 63) >> 7;
  306. a1 = (18 * w + 63) >> 7;
  307. a2 = (9 * w + 63) >> 7;
  308. p[-3 * stride] = cm[p2 + a2];
  309. p[-2 * stride] = cm[p1 + a1];
  310. p[-1 * stride] = cm[p0 + a0];
  311. p[ 0 * stride] = cm[q0 - a0];
  312. p[ 1 * stride] = cm[q1 - a1];
  313. p[ 2 * stride] = cm[q2 - a2];
  314. }
  315. #define LOOP_FILTER(vpn, dir, size, stridea, strideb, maybe_inline) \
  316. static maybe_inline \
  317. void vpn ## _ ## dir ## _loop_filter ## size ## _c(uint8_t *dst, \
  318. ptrdiff_t stride, \
  319. int flim_E, int flim_I, \
  320. int hev_thresh) \
  321. { \
  322. int i; \
  323. for (i = 0; i < size; i++) \
  324. if (vpn ## _normal_limit(dst + i * stridea, strideb, \
  325. flim_E, flim_I)) { \
  326. if (hev(dst + i * stridea, strideb, hev_thresh)) \
  327. vpn ## _filter_common(dst + i * stridea, strideb, 1); \
  328. else \
  329. filter_mbedge(dst + i * stridea, strideb); \
  330. } \
  331. } \
  332. \
  333. static maybe_inline \
  334. void vpn ## _ ## dir ## _loop_filter ## size ## _inner_c(uint8_t *dst, \
  335. ptrdiff_t stride, \
  336. int flim_E, \
  337. int flim_I, \
  338. int hev_thresh) \
  339. { \
  340. int i; \
  341. for (i = 0; i < size; i++) \
  342. if (vpn ## _normal_limit(dst + i * stridea, strideb, \
  343. flim_E, flim_I)) { \
  344. int hv = hev(dst + i * stridea, strideb, hev_thresh); \
  345. if (hv) \
  346. vpn ## _filter_common(dst + i * stridea, strideb, 1); \
  347. else \
  348. vpn ## _filter_common(dst + i * stridea, strideb, 0); \
  349. } \
  350. }
  351. #define UV_LOOP_FILTER(vpn, dir, stridea, strideb) \
  352. LOOP_FILTER(vpn, dir, 8, stridea, strideb, av_always_inline) \
  353. static void vpn ## _ ## dir ## _loop_filter8uv_c(uint8_t *dstU, \
  354. uint8_t *dstV, \
  355. ptrdiff_t stride, int fE, \
  356. int fI, int hev_thresh) \
  357. { \
  358. vpn ## _ ## dir ## _loop_filter8_c(dstU, stride, fE, fI, hev_thresh); \
  359. vpn ## _ ## dir ## _loop_filter8_c(dstV, stride, fE, fI, hev_thresh); \
  360. } \
  361. \
  362. static void vpn ## _ ## dir ## _loop_filter8uv_inner_c(uint8_t *dstU, \
  363. uint8_t *dstV, \
  364. ptrdiff_t stride, \
  365. int fE, int fI, \
  366. int hev_thresh) \
  367. { \
  368. vpn ## _ ## dir ## _loop_filter8_inner_c(dstU, stride, fE, fI, \
  369. hev_thresh); \
  370. vpn ## _ ## dir ## _loop_filter8_inner_c(dstV, stride, fE, fI, \
  371. hev_thresh); \
  372. }
  373. #define LOOP_FILTER_SIMPLE(vpn) \
  374. static void vpn ## _v_loop_filter_simple_c(uint8_t *dst, ptrdiff_t stride, \
  375. int flim) \
  376. { \
  377. int i; \
  378. for (i = 0; i < 16; i++) \
  379. if (vpn ## _simple_limit(dst + i, stride, flim)) \
  380. vpn ## _filter_common(dst + i, stride, 1); \
  381. } \
  382. \
  383. static void vpn ## _h_loop_filter_simple_c(uint8_t *dst, ptrdiff_t stride, \
  384. int flim) \
  385. { \
  386. int i; \
  387. for (i = 0; i < 16; i++) \
  388. if (vpn ## _simple_limit(dst + i * stride, 1, flim)) \
  389. vpn ## _filter_common(dst + i * stride, 1, 1); \
  390. }
  391. #define LOOP_FILTERS(vpn) \
  392. LOOP_FILTER(vpn, v, 16, 1, stride, ) \
  393. LOOP_FILTER(vpn, h, 16, stride, 1, ) \
  394. UV_LOOP_FILTER(vpn, v, 1, stride) \
  395. UV_LOOP_FILTER(vpn, h, stride, 1) \
  396. LOOP_FILTER_SIMPLE(vpn) \
  397. static const uint8_t subpel_filters[7][6] = {
  398. { 0, 6, 123, 12, 1, 0 },
  399. { 2, 11, 108, 36, 8, 1 },
  400. { 0, 9, 93, 50, 6, 0 },
  401. { 3, 16, 77, 77, 16, 3 },
  402. { 0, 6, 50, 93, 9, 0 },
  403. { 1, 8, 36, 108, 11, 2 },
  404. { 0, 1, 12, 123, 6, 0 },
  405. };
  406. #define PUT_PIXELS(WIDTH) \
  407. static void put_vp8_pixels ## WIDTH ## _c(uint8_t *dst, ptrdiff_t dststride, \
  408. uint8_t *src, ptrdiff_t srcstride, \
  409. int h, int x, int y) \
  410. { \
  411. int i; \
  412. for (i = 0; i < h; i++, dst += dststride, src += srcstride) \
  413. memcpy(dst, src, WIDTH); \
  414. }
  415. PUT_PIXELS(16)
  416. PUT_PIXELS(8)
  417. PUT_PIXELS(4)
  418. #define FILTER_6TAP(src, F, stride) \
  419. cm[(F[2] * src[x + 0 * stride] - F[1] * src[x - 1 * stride] + \
  420. F[0] * src[x - 2 * stride] + F[3] * src[x + 1 * stride] - \
  421. F[4] * src[x + 2 * stride] + F[5] * src[x + 3 * stride] + 64) >> 7]
  422. #define FILTER_4TAP(src, F, stride) \
  423. cm[(F[2] * src[x + 0 * stride] - F[1] * src[x - 1 * stride] + \
  424. F[3] * src[x + 1 * stride] - F[4] * src[x + 2 * stride] + 64) >> 7]
  425. #define VP8_EPEL_H(SIZE, TAPS) \
  426. static void put_vp8_epel ## SIZE ## _h ## TAPS ## _c(uint8_t *dst, \
  427. ptrdiff_t dststride, \
  428. uint8_t *src, \
  429. ptrdiff_t srcstride, \
  430. int h, int mx, int my) \
  431. { \
  432. const uint8_t *filter = subpel_filters[mx - 1]; \
  433. const uint8_t *cm = ff_crop_tab + MAX_NEG_CROP; \
  434. int x, y; \
  435. for (y = 0; y < h; y++) { \
  436. for (x = 0; x < SIZE; x++) \
  437. dst[x] = FILTER_ ## TAPS ## TAP(src, filter, 1); \
  438. dst += dststride; \
  439. src += srcstride; \
  440. } \
  441. }
  442. #define VP8_EPEL_V(SIZE, TAPS) \
  443. static void put_vp8_epel ## SIZE ## _v ## TAPS ## _c(uint8_t *dst, \
  444. ptrdiff_t dststride, \
  445. uint8_t *src, \
  446. ptrdiff_t srcstride, \
  447. int h, int mx, int my) \
  448. { \
  449. const uint8_t *filter = subpel_filters[my - 1]; \
  450. const uint8_t *cm = ff_crop_tab + MAX_NEG_CROP; \
  451. int x, y; \
  452. for (y = 0; y < h; y++) { \
  453. for (x = 0; x < SIZE; x++) \
  454. dst[x] = FILTER_ ## TAPS ## TAP(src, filter, srcstride); \
  455. dst += dststride; \
  456. src += srcstride; \
  457. } \
  458. }
  459. #define VP8_EPEL_HV(SIZE, HTAPS, VTAPS) \
  460. static void \
  461. put_vp8_epel ## SIZE ## _h ## HTAPS ## v ## VTAPS ## _c(uint8_t *dst, \
  462. ptrdiff_t dststride, \
  463. uint8_t *src, \
  464. ptrdiff_t srcstride, \
  465. int h, int mx, \
  466. int my) \
  467. { \
  468. const uint8_t *filter = subpel_filters[mx - 1]; \
  469. const uint8_t *cm = ff_crop_tab + MAX_NEG_CROP; \
  470. int x, y; \
  471. uint8_t tmp_array[(2 * SIZE + VTAPS - 1) * SIZE]; \
  472. uint8_t *tmp = tmp_array; \
  473. src -= (2 - (VTAPS == 4)) * srcstride; \
  474. \
  475. for (y = 0; y < h + VTAPS - 1; y++) { \
  476. for (x = 0; x < SIZE; x++) \
  477. tmp[x] = FILTER_ ## HTAPS ## TAP(src, filter, 1); \
  478. tmp += SIZE; \
  479. src += srcstride; \
  480. } \
  481. tmp = tmp_array + (2 - (VTAPS == 4)) * SIZE; \
  482. filter = subpel_filters[my - 1]; \
  483. \
  484. for (y = 0; y < h; y++) { \
  485. for (x = 0; x < SIZE; x++) \
  486. dst[x] = FILTER_ ## VTAPS ## TAP(tmp, filter, SIZE); \
  487. dst += dststride; \
  488. tmp += SIZE; \
  489. } \
  490. }
  491. VP8_EPEL_H(16, 4)
  492. VP8_EPEL_H(8, 4)
  493. VP8_EPEL_H(4, 4)
  494. VP8_EPEL_H(16, 6)
  495. VP8_EPEL_H(8, 6)
  496. VP8_EPEL_H(4, 6)
  497. VP8_EPEL_V(16, 4)
  498. VP8_EPEL_V(8, 4)
  499. VP8_EPEL_V(4, 4)
  500. VP8_EPEL_V(16, 6)
  501. VP8_EPEL_V(8, 6)
  502. VP8_EPEL_V(4, 6)
  503. VP8_EPEL_HV(16, 4, 4)
  504. VP8_EPEL_HV(8, 4, 4)
  505. VP8_EPEL_HV(4, 4, 4)
  506. VP8_EPEL_HV(16, 4, 6)
  507. VP8_EPEL_HV(8, 4, 6)
  508. VP8_EPEL_HV(4, 4, 6)
  509. VP8_EPEL_HV(16, 6, 4)
  510. VP8_EPEL_HV(8, 6, 4)
  511. VP8_EPEL_HV(4, 6, 4)
  512. VP8_EPEL_HV(16, 6, 6)
  513. VP8_EPEL_HV(8, 6, 6)
  514. VP8_EPEL_HV(4, 6, 6)
  515. #define VP8_BILINEAR(SIZE) \
  516. static void put_vp8_bilinear ## SIZE ## _h_c(uint8_t *dst, ptrdiff_t dstride, \
  517. uint8_t *src, ptrdiff_t sstride, \
  518. int h, int mx, int my) \
  519. { \
  520. int a = 8 - mx, b = mx; \
  521. int x, y; \
  522. for (y = 0; y < h; y++) { \
  523. for (x = 0; x < SIZE; x++) \
  524. dst[x] = (a * src[x] + b * src[x + 1] + 4) >> 3; \
  525. dst += dstride; \
  526. src += sstride; \
  527. } \
  528. } \
  529. \
  530. static void put_vp8_bilinear ## SIZE ## _v_c(uint8_t *dst, ptrdiff_t dstride, \
  531. uint8_t *src, ptrdiff_t sstride, \
  532. int h, int mx, int my) \
  533. { \
  534. int c = 8 - my, d = my; \
  535. int x, y; \
  536. for (y = 0; y < h; y++) { \
  537. for (x = 0; x < SIZE; x++) \
  538. dst[x] = (c * src[x] + d * src[x + sstride] + 4) >> 3; \
  539. dst += dstride; \
  540. src += sstride; \
  541. } \
  542. } \
  543. \
  544. static void put_vp8_bilinear ## SIZE ## _hv_c(uint8_t *dst, \
  545. ptrdiff_t dstride, \
  546. uint8_t *src, \
  547. ptrdiff_t sstride, \
  548. int h, int mx, int my) \
  549. { \
  550. int a = 8 - mx, b = mx; \
  551. int c = 8 - my, d = my; \
  552. int x, y; \
  553. uint8_t tmp_array[(2 * SIZE + 1) * SIZE]; \
  554. uint8_t *tmp = tmp_array; \
  555. for (y = 0; y < h + 1; y++) { \
  556. for (x = 0; x < SIZE; x++) \
  557. tmp[x] = (a * src[x] + b * src[x + 1] + 4) >> 3; \
  558. tmp += SIZE; \
  559. src += sstride; \
  560. } \
  561. tmp = tmp_array; \
  562. for (y = 0; y < h; y++) { \
  563. for (x = 0; x < SIZE; x++) \
  564. dst[x] = (c * tmp[x] + d * tmp[x + SIZE] + 4) >> 3; \
  565. dst += dstride; \
  566. tmp += SIZE; \
  567. } \
  568. }
  569. VP8_BILINEAR(16)
  570. VP8_BILINEAR(8)
  571. VP8_BILINEAR(4)
  572. #define VP78_MC_FUNC(IDX, SIZE) \
  573. dsp->put_vp8_epel_pixels_tab[IDX][0][0] = put_vp8_pixels ## SIZE ## _c; \
  574. dsp->put_vp8_epel_pixels_tab[IDX][0][1] = put_vp8_epel ## SIZE ## _h4_c; \
  575. dsp->put_vp8_epel_pixels_tab[IDX][0][2] = put_vp8_epel ## SIZE ## _h6_c; \
  576. dsp->put_vp8_epel_pixels_tab[IDX][1][0] = put_vp8_epel ## SIZE ## _v4_c; \
  577. dsp->put_vp8_epel_pixels_tab[IDX][1][1] = put_vp8_epel ## SIZE ## _h4v4_c; \
  578. dsp->put_vp8_epel_pixels_tab[IDX][1][2] = put_vp8_epel ## SIZE ## _h6v4_c; \
  579. dsp->put_vp8_epel_pixels_tab[IDX][2][0] = put_vp8_epel ## SIZE ## _v6_c; \
  580. dsp->put_vp8_epel_pixels_tab[IDX][2][1] = put_vp8_epel ## SIZE ## _h4v6_c; \
  581. dsp->put_vp8_epel_pixels_tab[IDX][2][2] = put_vp8_epel ## SIZE ## _h6v6_c
  582. #define VP78_BILINEAR_MC_FUNC(IDX, SIZE) \
  583. dsp->put_vp8_bilinear_pixels_tab[IDX][0][0] = put_vp8_pixels ## SIZE ## _c; \
  584. dsp->put_vp8_bilinear_pixels_tab[IDX][0][1] = put_vp8_bilinear ## SIZE ## _h_c; \
  585. dsp->put_vp8_bilinear_pixels_tab[IDX][0][2] = put_vp8_bilinear ## SIZE ## _h_c; \
  586. dsp->put_vp8_bilinear_pixels_tab[IDX][1][0] = put_vp8_bilinear ## SIZE ## _v_c; \
  587. dsp->put_vp8_bilinear_pixels_tab[IDX][1][1] = put_vp8_bilinear ## SIZE ## _hv_c; \
  588. dsp->put_vp8_bilinear_pixels_tab[IDX][1][2] = put_vp8_bilinear ## SIZE ## _hv_c; \
  589. dsp->put_vp8_bilinear_pixels_tab[IDX][2][0] = put_vp8_bilinear ## SIZE ## _v_c; \
  590. dsp->put_vp8_bilinear_pixels_tab[IDX][2][1] = put_vp8_bilinear ## SIZE ## _hv_c; \
  591. dsp->put_vp8_bilinear_pixels_tab[IDX][2][2] = put_vp8_bilinear ## SIZE ## _hv_c
  592. av_cold void ff_vp78dsp_init(VP8DSPContext *dsp)
  593. {
  594. VP78_MC_FUNC(0, 16);
  595. VP78_MC_FUNC(1, 8);
  596. VP78_MC_FUNC(2, 4);
  597. VP78_BILINEAR_MC_FUNC(0, 16);
  598. VP78_BILINEAR_MC_FUNC(1, 8);
  599. VP78_BILINEAR_MC_FUNC(2, 4);
  600. if (ARCH_ARM)
  601. ff_vp78dsp_init_arm(dsp);
  602. if (ARCH_PPC)
  603. ff_vp78dsp_init_ppc(dsp);
  604. if (ARCH_X86)
  605. ff_vp78dsp_init_x86(dsp);
  606. }
  607. #if CONFIG_VP7_DECODER
  608. LOOP_FILTERS(vp7)
  609. av_cold void ff_vp7dsp_init(VP8DSPContext *dsp)
  610. {
  611. dsp->vp8_luma_dc_wht = vp7_luma_dc_wht_c;
  612. dsp->vp8_luma_dc_wht_dc = vp7_luma_dc_wht_dc_c;
  613. dsp->vp8_idct_add = vp7_idct_add_c;
  614. dsp->vp8_idct_dc_add = vp7_idct_dc_add_c;
  615. dsp->vp8_idct_dc_add4y = vp7_idct_dc_add4y_c;
  616. dsp->vp8_idct_dc_add4uv = vp7_idct_dc_add4uv_c;
  617. dsp->vp8_v_loop_filter16y = vp7_v_loop_filter16_c;
  618. dsp->vp8_h_loop_filter16y = vp7_h_loop_filter16_c;
  619. dsp->vp8_v_loop_filter8uv = vp7_v_loop_filter8uv_c;
  620. dsp->vp8_h_loop_filter8uv = vp7_h_loop_filter8uv_c;
  621. dsp->vp8_v_loop_filter16y_inner = vp7_v_loop_filter16_inner_c;
  622. dsp->vp8_h_loop_filter16y_inner = vp7_h_loop_filter16_inner_c;
  623. dsp->vp8_v_loop_filter8uv_inner = vp7_v_loop_filter8uv_inner_c;
  624. dsp->vp8_h_loop_filter8uv_inner = vp7_h_loop_filter8uv_inner_c;
  625. dsp->vp8_v_loop_filter_simple = vp7_v_loop_filter_simple_c;
  626. dsp->vp8_h_loop_filter_simple = vp7_h_loop_filter_simple_c;
  627. }
  628. #endif /* CONFIG_VP7_DECODER */
  629. #if CONFIG_VP8_DECODER
  630. LOOP_FILTERS(vp8)
  631. av_cold void ff_vp8dsp_init(VP8DSPContext *dsp)
  632. {
  633. dsp->vp8_luma_dc_wht = vp8_luma_dc_wht_c;
  634. dsp->vp8_luma_dc_wht_dc = vp8_luma_dc_wht_dc_c;
  635. dsp->vp8_idct_add = vp8_idct_add_c;
  636. dsp->vp8_idct_dc_add = vp8_idct_dc_add_c;
  637. dsp->vp8_idct_dc_add4y = vp8_idct_dc_add4y_c;
  638. dsp->vp8_idct_dc_add4uv = vp8_idct_dc_add4uv_c;
  639. dsp->vp8_v_loop_filter16y = vp8_v_loop_filter16_c;
  640. dsp->vp8_h_loop_filter16y = vp8_h_loop_filter16_c;
  641. dsp->vp8_v_loop_filter8uv = vp8_v_loop_filter8uv_c;
  642. dsp->vp8_h_loop_filter8uv = vp8_h_loop_filter8uv_c;
  643. dsp->vp8_v_loop_filter16y_inner = vp8_v_loop_filter16_inner_c;
  644. dsp->vp8_h_loop_filter16y_inner = vp8_h_loop_filter16_inner_c;
  645. dsp->vp8_v_loop_filter8uv_inner = vp8_v_loop_filter8uv_inner_c;
  646. dsp->vp8_h_loop_filter8uv_inner = vp8_h_loop_filter8uv_inner_c;
  647. dsp->vp8_v_loop_filter_simple = vp8_v_loop_filter_simple_c;
  648. dsp->vp8_h_loop_filter_simple = vp8_h_loop_filter_simple_c;
  649. if (ARCH_ARM)
  650. ff_vp8dsp_init_arm(dsp);
  651. if (ARCH_X86)
  652. ff_vp8dsp_init_x86(dsp);
  653. if (ARCH_MIPS)
  654. ff_vp8dsp_init_mips(dsp);
  655. }
  656. #endif /* CONFIG_VP8_DECODER */