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.

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