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