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.

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