2 * Microsoft Screen 2 (aka Windows Media Video V9 Screen) decoder
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 * Microsoft Screen 2 (aka Windows Media Video V9 Screen) decoder DSP routines
27 #include "libavutil/common.h"
29 static av_always_inline void mss2_blit_wmv9_template(uint8_t *dst,
35 ptrdiff_t mask_stride,
37 ptrdiff_t srcy_stride,
40 ptrdiff_t srcuv_stride,
45 for (i = 0, j = 0, k = 0; i < w; j += (i & 1), i++, k += 3) {
46 if (!use_mask || mask[i] == maskcolor) {
48 dst[k] = dst[k + 1] = dst[k + 2] = 0x80;
51 int u = srcu[j] - 128;
52 int v = srcv[j] - 128;
53 dst[k] = av_clip_uint8(y + ( 91881 * v + 32768 >> 16));
54 dst[k + 1] = av_clip_uint8(y + (-22554 * u - 46802 * v + 32768 >> 16));
55 dst[k + 2] = av_clip_uint8(y + (116130 * u + 32768 >> 16));
62 srcu += srcuv_stride * (r & 1);
63 srcv += srcuv_stride * (r & 1);
67 static void mss2_blit_wmv9_c(uint8_t *dst, ptrdiff_t dst_stride,
68 const uint8_t *srcy, ptrdiff_t srcy_stride,
69 const uint8_t *srcu, const uint8_t *srcv,
70 ptrdiff_t srcuv_stride, int w, int h)
72 mss2_blit_wmv9_template(dst, dst_stride, 0, 0,
75 srcu, srcv, srcuv_stride,
79 static void mss2_blit_wmv9_masked_c(uint8_t *dst, ptrdiff_t dst_stride,
80 int maskcolor, const uint8_t *mask,
81 ptrdiff_t mask_stride,
82 const uint8_t *srcy, ptrdiff_t srcy_stride,
83 const uint8_t *srcu, const uint8_t *srcv,
84 ptrdiff_t srcuv_stride, int w, int h)
86 mss2_blit_wmv9_template(dst, dst_stride, 0, 1,
87 maskcolor, mask, mask_stride,
89 srcu, srcv, srcuv_stride,
93 static void mss2_gray_fill_masked_c(uint8_t *dst, ptrdiff_t dst_stride,
94 int maskcolor, const uint8_t *mask,
95 ptrdiff_t mask_stride, int w, int h)
97 mss2_blit_wmv9_template(dst, dst_stride, 1, 1,
98 maskcolor, mask, mask_stride,
104 static void upsample_plane_c(uint8_t *plane, ptrdiff_t plane_stride, int w, int h)
106 uint8_t *src1, *src2, *dst1, *dst2, *p, a, b;
117 memcpy(plane + plane_stride * j,
118 plane + plane_stride * (j >> 1),
121 while ((j -= 2) > 0) {
122 dst1 = plane + plane_stride * (j + 1);
123 dst2 = plane + plane_stride * j;
124 src1 = plane + plane_stride * ((j + 1) >> 1);
125 src2 = plane + plane_stride * ( j >> 1);
127 for (i = (w - 1) >> 1; i >= 0; i--) {
130 dst1[i] = (3 * a + b + 2) >> 2;
131 dst2[i] = (a + 3 * b + 2) >> 2;
135 for (j = h - 1; j >= 0; j--) {
136 p = plane + plane_stride * j;
141 while ((i -= 2) > 0) {
144 p[i] = (3 * a + b + 1) >> 2;
145 p[i + 1] = (a + 3 * b + 1) >> 2;
150 av_cold void ff_mss2dsp_init(MSS2DSPContext* dsp)
152 dsp->mss2_blit_wmv9 = mss2_blit_wmv9_c;
153 dsp->mss2_blit_wmv9_masked = mss2_blit_wmv9_masked_c;
154 dsp->mss2_gray_fill_masked = mss2_gray_fill_masked_c;
155 dsp->upsample_plane = upsample_plane_c;