FFmpeg
mss2dsp.c
Go to the documentation of this file.
1 /*
2  * Microsoft Screen 2 (aka Windows Media Video V9 Screen) decoder
3  *
4  * This file is part of FFmpeg.
5  *
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.
10  *
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.
15  *
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
19  */
20 
21 /**
22  * @file
23  * Microsoft Screen 2 (aka Windows Media Video V9 Screen) decoder DSP routines
24  */
25 
26 #include "mss2dsp.h"
27 #include "libavutil/common.h"
28 
29 static av_always_inline void mss2_blit_wmv9_template(uint8_t *dst,
30  ptrdiff_t dst_stride,
31  int gray,
32  int use_mask,
33  int maskcolor,
34  const uint8_t *mask,
35  ptrdiff_t mask_stride,
36  const uint8_t *srcy,
37  ptrdiff_t srcy_stride,
38  const uint8_t *srcu,
39  const uint8_t *srcv,
40  ptrdiff_t srcuv_stride,
41  int w, int h)
42 {
43  int i, j, k, r = -1;
44  while (++r < h) {
45  for (i = 0, j = 0, k = 0; i < w; j += (i & 1), i++, k += 3) {
46  if (!use_mask || mask[i] == maskcolor) {
47  if (gray) {
48  dst[k] = dst[k + 1] = dst[k + 2] = 0x80;
49  } else {
50  int y = srcy[i];
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));
56  }
57  }
58  }
59  mask += mask_stride;
60  dst += dst_stride;
61  srcy += srcy_stride;
62  srcu += srcuv_stride * (r & 1);
63  srcv += srcuv_stride * (r & 1);
64  }
65 }
66 
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)
71 {
72  mss2_blit_wmv9_template(dst, dst_stride, 0, 0,
73  0, NULL, 0,
74  srcy, srcy_stride,
75  srcu, srcv, srcuv_stride,
76  w, h);
77 }
78 
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)
85 {
86  mss2_blit_wmv9_template(dst, dst_stride, 0, 1,
87  maskcolor, mask, mask_stride,
88  srcy, srcy_stride,
89  srcu, srcv, srcuv_stride,
90  w, h);
91 }
92 
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)
96 {
97  mss2_blit_wmv9_template(dst, dst_stride, 1, 1,
98  maskcolor, mask, mask_stride,
99  NULL, 0,
100  NULL, NULL, 0,
101  w, h);
102 }
103 
104 static void upsample_plane_c(uint8_t *plane, ptrdiff_t plane_stride, int w, int h)
105 {
106  uint8_t *src1, *src2, *dst1, *dst2, *p, a, b;
107  int i, j;
108 
109  if(!w || !h)
110  return;
111 
112  w += (w & 1);
113  h += (h & 1);
114 
115  j = h - 1;
116 
117  memcpy(plane + plane_stride * j,
118  plane + plane_stride * (j >> 1),
119  w);
120 
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);
126 
127  for (i = (w - 1) >> 1; i >= 0; i--) {
128  a = src1[i];
129  b = src2[i];
130  dst1[i] = (3 * a + b + 2) >> 2;
131  dst2[i] = (a + 3 * b + 2) >> 2;
132  }
133  }
134 
135  for (j = h - 1; j >= 0; j--) {
136  p = plane + plane_stride * j;
137  i = w - 1;
138 
139  p[i] = p[i >> 1];
140 
141  while ((i -= 2) > 0) {
142  a = p[ i >> 1];
143  b = p[(i + 1) >> 1];
144  p[i] = (3 * a + b + 1) >> 2;
145  p[i + 1] = (a + 3 * b + 1) >> 2;
146  }
147  }
148 }
149 
151 {
156 }
r
const char * r
Definition: vf_curves.c:116
mss2dsp.h
u
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:262
src1
const pixel * src1
Definition: h264pred_template.c:421
w
uint8_t w
Definition: llviddspenc.c:38
b
#define b
Definition: input.c:34
MSS2DSPContext::upsample_plane
void(* upsample_plane)(uint8_t *plane, ptrdiff_t plane_stride, int w, int h)
Definition: mss2dsp.h:46
ff_mss2dsp_init
av_cold void ff_mss2dsp_init(MSS2DSPContext *dsp)
Definition: mss2dsp.c:150
av_cold
#define av_cold
Definition: attributes.h:90
mask
static const uint16_t mask[17]
Definition: lzw.c:38
MSS2DSPContext::mss2_gray_fill_masked
void(* mss2_gray_fill_masked)(uint8_t *dst, ptrdiff_t dst_stride, int maskcolor, const uint8_t *mask, ptrdiff_t mask_stride, int w, int h)
Definition: mss2dsp.h:43
MSS2DSPContext::mss2_blit_wmv9_masked
void(* mss2_blit_wmv9_masked)(uint8_t *dst, ptrdiff_t dst_stride, int maskcolor, const uint8_t *mask, ptrdiff_t mask_stride, const uint8_t *srcy, ptrdiff_t srcy_stride, const uint8_t *srcu, const uint8_t *srcv, ptrdiff_t srcuv_stride, int w, int h)
Definition: mss2dsp.h:37
NULL
#define NULL
Definition: coverity.c:32
MSS2DSPContext::mss2_blit_wmv9
void(* mss2_blit_wmv9)(uint8_t *dst, ptrdiff_t dst_stride, const uint8_t *srcy, ptrdiff_t srcy_stride, const uint8_t *srcu, const uint8_t *srcv, ptrdiff_t srcuv_stride, int w, int h)
Definition: mss2dsp.h:33
upsample_plane_c
static void upsample_plane_c(uint8_t *plane, ptrdiff_t plane_stride, int w, int h)
Definition: mss2dsp.c:104
gray
The official guide to swscale for confused that consecutive non overlapping rectangles of slice_bottom special converter These generally are unscaled converters of common like for each output line the vertical scaler pulls lines from a ring buffer When the ring buffer does not contain the wanted then it is pulled from the input slice through the input converter and horizontal scaler The result is also stored in the ring buffer to serve future vertical scaler requests When no more output can be generated because lines from a future slice would be then all remaining lines in the current slice are horizontally scaled and put in the ring buffer[This is done for luma and chroma, each with possibly different numbers of lines per picture.] Input to YUV Converter When the input to the main path is not planar bits per component YUV or bit gray
Definition: swscale.txt:52
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
Rectangle::y
int y
Definition: mss2.c:468
mss2_blit_wmv9_c
static void mss2_blit_wmv9_c(uint8_t *dst, ptrdiff_t dst_stride, const uint8_t *srcy, ptrdiff_t srcy_stride, const uint8_t *srcu, const uint8_t *srcv, ptrdiff_t srcuv_stride, int w, int h)
Definition: mss2dsp.c:67
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
src2
const pixel * src2
Definition: h264pred_template.c:422
common.h
MSS2DSPContext
Definition: mss2dsp.h:32
av_always_inline
#define av_always_inline
Definition: attributes.h:49
mss2_blit_wmv9_template
static av_always_inline void mss2_blit_wmv9_template(uint8_t *dst, ptrdiff_t dst_stride, int gray, int use_mask, int maskcolor, const uint8_t *mask, ptrdiff_t mask_stride, const uint8_t *srcy, ptrdiff_t srcy_stride, const uint8_t *srcu, const uint8_t *srcv, ptrdiff_t srcuv_stride, int w, int h)
Definition: mss2dsp.c:29
mss2_gray_fill_masked_c
static void mss2_gray_fill_masked_c(uint8_t *dst, ptrdiff_t dst_stride, int maskcolor, const uint8_t *mask, ptrdiff_t mask_stride, int w, int h)
Definition: mss2dsp.c:93
av_clip_uint8
#define av_clip_uint8
Definition: common.h:101
h
h
Definition: vp9dsp_template.c:2038
mss2_blit_wmv9_masked_c
static void mss2_blit_wmv9_masked_c(uint8_t *dst, ptrdiff_t dst_stride, int maskcolor, const uint8_t *mask, ptrdiff_t mask_stride, const uint8_t *srcy, ptrdiff_t srcy_stride, const uint8_t *srcu, const uint8_t *srcv, ptrdiff_t srcuv_stride, int w, int h)
Definition: mss2dsp.c:79