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.

657 lines
21KB

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