FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/mss2dsp.c
Date: 2021-09-26 18:22:30
Exec Total Coverage
Lines: 53 59 89.8%
Branches: 18 22 81.8%

Line Branch Exec Source
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 79 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 79 int i, j, k, r = -1;
44
2/2
✓ Branch 0 taken 18960 times.
✓ Branch 1 taken 79 times.
19039 while (++r < h) {
45
2/2
✓ Branch 0 taken 6062880 times.
✓ Branch 1 taken 18960 times.
6081840 for (i = 0, j = 0, k = 0; i < w; j += (i & 1), i++, k += 3) {
46
3/4
✓ Branch 0 taken 6062880 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5965570 times.
✓ Branch 3 taken 97310 times.
6062880 if (!use_mask || mask[i] == maskcolor) {
47
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5965570 times.
5965570 if (gray) {
48 dst[k] = dst[k + 1] = dst[k + 2] = 0x80;
49 } else {
50 5965570 int y = srcy[i];
51 5965570 int u = srcu[j] - 128;
52 5965570 int v = srcv[j] - 128;
53 5965570 dst[k] = av_clip_uint8(y + ( 91881 * v + 32768 >> 16));
54 5965570 dst[k + 1] = av_clip_uint8(y + (-22554 * u - 46802 * v + 32768 >> 16));
55 5965570 dst[k + 2] = av_clip_uint8(y + (116130 * u + 32768 >> 16));
56 }
57 }
58 }
59 18960 mask += mask_stride;
60 18960 dst += dst_stride;
61 18960 srcy += srcy_stride;
62 18960 srcu += srcuv_stride * (r & 1);
63 18960 srcv += srcuv_stride * (r & 1);
64 }
65 79 }
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 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 79 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 79 }
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 159 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
2/4
✓ Branch 0 taken 159 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 159 times.
159 if(!w || !h)
110 return;
111
112 159 w += (w & 1);
113 159 h += (h & 1);
114
115 159 j = h - 1;
116
117 159 memcpy(plane + plane_stride * j,
118 159 plane + plane_stride * (j >> 1),
119 w);
120
121
2/2
✓ Branch 0 taken 12561 times.
✓ Branch 1 taken 159 times.
12720 while ((j -= 2) > 0) {
122 12561 dst1 = plane + plane_stride * (j + 1);
123 12561 dst2 = plane + plane_stride * j;
124 12561 src1 = plane + plane_stride * ((j + 1) >> 1);
125 12561 src2 = plane + plane_stride * ( j >> 1);
126
127
2/2
✓ Branch 0 taken 1508134 times.
✓ Branch 1 taken 12561 times.
1520695 for (i = (w - 1) >> 1; i >= 0; i--) {
128 1508134 a = src1[i];
129 1508134 b = src2[i];
130 1508134 dst1[i] = (3 * a + b + 2) >> 2;
131 1508134 dst2[i] = (a + 3 * b + 2) >> 2;
132 }
133 }
134
135
2/2
✓ Branch 0 taken 25440 times.
✓ Branch 1 taken 159 times.
25599 for (j = h - 1; j >= 0; j--) {
136 25440 p = plane + plane_stride * j;
137 25440 i = w - 1;
138
139 25440 p[i] = p[i >> 1];
140
141
2/2
✓ Branch 0 taken 3024720 times.
✓ Branch 1 taken 25440 times.
3050160 while ((i -= 2) > 0) {
142 3024720 a = p[ i >> 1];
143 3024720 b = p[(i + 1) >> 1];
144 3024720 p[i] = (3 * a + b + 1) >> 2;
145 3024720 p[i + 1] = (a + 3 * b + 1) >> 2;
146 }
147 }
148 }
149
150 10 av_cold void ff_mss2dsp_init(MSS2DSPContext* dsp)
151 {
152 10 dsp->mss2_blit_wmv9 = mss2_blit_wmv9_c;
153 10 dsp->mss2_blit_wmv9_masked = mss2_blit_wmv9_masked_c;
154 10 dsp->mss2_gray_fill_masked = mss2_gray_fill_masked_c;
155 10 dsp->upsample_plane = upsample_plane_c;
156 10 }
157