../../../ffmpeg/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
0 / 204
0.0%
Branches:
0 / 143
0.0%
Functions:
0 / 2
0.0%

libavcodec/scpr.h
Line Branch Exec Source
1 /*
2 * ScreenPressor decoder
3 *
4 * Copyright (c) 2017 Paul B Mahol
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 #ifndef AVCODEC_SCPR_H
24 #define AVCODEC_SCPR_H
25
26 #include "avcodec.h"
27 #include "bytestream.h"
28 #include "scpr3.h"
29
30 typedef struct RangeCoder {
31 uint32_t code;
32 uint32_t range;
33 uint32_t code1;
34 } RangeCoder;
35
36 typedef struct PixelModel {
37 uint32_t freq[256];
38 uint32_t lookup[16];
39 uint32_t total_freq;
40 } PixelModel;
41
42 typedef struct SCPRContext {
43 int version;
44 AVFrame *last_frame;
45 AVFrame *current_frame;
46 GetByteContext gb;
47 RangeCoder rc;
48 PixelModel pixel_model[3][4096];
49 uint32_t op_model[6][7];
50 uint32_t run_model[6][257];
51 uint32_t range_model[257];
52 uint32_t count_model[257];
53 uint32_t fill_model[6];
54 uint32_t sxy_model[4][17];
55 uint32_t mv_model[2][513];
56 uint32_t nbx, nby;
57 uint32_t nbcount;
58 uint32_t *blocks;
59 uint32_t cbits;
60 int cxshift;
61
62 PixelModel3 pixel_model3[3][4096];
63 RunModel3 run_model3[6];
64 RunModel3 range_model3;
65 RunModel3 count_model3;
66 FillModel3 fill_model3;
67 SxyModel3 sxy_model3[4];
68 MVModel3 mv_model3[2];
69 OpModel3 op_model3[6];
70
71 int (*get_freq)(RangeCoder *rc, uint32_t total_freq, uint32_t *freq);
72 int (*decode)(GetByteContext *gb, RangeCoder *rc, uint32_t cumFreq, uint32_t freq, uint32_t total_freq);
73 } SCPRContext;
74
75 ✗ av_unused static int decode_run_i(AVCodecContext *avctx, uint32_t ptype, int run,
76 int *px, int *py, uint32_t clr, uint32_t *dst,
77 int linesize, uint32_t *plx, uint32_t *ply,
78 uint32_t backstep, int off, int *cx, int *cx1)
79 {
80 uint32_t r, g, b;
81 int z;
82 ✗ int x = *px,
83 ✗ y = *py;
84 ✗ uint32_t lx = *plx,
85 ✗ ly = *ply;
86
87
0/2
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 4 not taken.
✗ if (y >= avctx->height)
88 ✗ return AVERROR_INVALIDDATA;
89
90
0/6
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 13 not taken.
✗ Branch 4 → 21 not taken.
✗ Branch 4 → 31 not taken.
✗ Branch 4 → 46 not taken.
✗ Branch 4 → 61 not taken.
✗ switch (ptype) {
91 ✗ case 0:
92
0/2
✗ Branch 11 → 6 not taken.
✗ Branch 11 → 12 not taken.
✗ while (run-- > 0) {
93 ✗ dst[y * linesize + x] = clr;
94 ✗ lx = x;
95 ✗ ly = y;
96 ✗ (x)++;
97
0/2
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 10 not taken.
✗ if (x >= avctx->width) {
98 ✗ x = 0;
99 ✗ (y)++;
100
0/4
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 10 not taken.
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 10 not taken.
✗ if (y >= avctx->height && run)
101 ✗ return AVERROR_INVALIDDATA;
102 }
103 }
104 ✗ break;
105 ✗ case 1:
106
0/2
✗ Branch 19 → 14 not taken.
✗ Branch 19 → 20 not taken.
✗ while (run-- > 0) {
107 ✗ dst[y * linesize + x] = dst[ly * linesize + lx];
108 ✗ lx = x;
109 ✗ ly = y;
110 ✗ (x)++;
111
0/2
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 18 not taken.
✗ if (x >= avctx->width) {
112 ✗ x = 0;
113 ✗ (y)++;
114
0/4
✗ Branch 15 → 16 not taken.
✗ Branch 15 → 18 not taken.
✗ Branch 16 → 17 not taken.
✗ Branch 16 → 18 not taken.
✗ if (y >= avctx->height && run)
115 ✗ return AVERROR_INVALIDDATA;
116 }
117 }
118 ✗ clr = dst[ly * linesize + lx];
119 ✗ break;
120 ✗ case 2:
121
0/2
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 23 not taken.
✗ if (y < 1)
122 ✗ return AVERROR_INVALIDDATA;
123
124
0/2
✗ Branch 29 → 24 not taken.
✗ Branch 29 → 30 not taken.
✗ while (run-- > 0) {
125 ✗ clr = dst[y * linesize + x + off + 1];
126 ✗ dst[y * linesize + x] = clr;
127 ✗ lx = x;
128 ✗ ly = y;
129 ✗ (x)++;
130
0/2
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 28 not taken.
✗ if (x >= avctx->width) {
131 ✗ x = 0;
132 ✗ (y)++;
133
0/4
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 28 not taken.
✗ Branch 26 → 27 not taken.
✗ Branch 26 → 28 not taken.
✗ if (y >= avctx->height && run)
134 ✗ return AVERROR_INVALIDDATA;
135 }
136 }
137 ✗ break;
138 ✗ case 4:
139
0/6
✗ Branch 31 → 32 not taken.
✗ Branch 31 → 34 not taken.
✗ Branch 32 → 33 not taken.
✗ Branch 32 → 35 not taken.
✗ Branch 33 → 34 not taken.
✗ Branch 33 → 35 not taken.
✗ if (y < 1 || (y == 1 && x == 0))
140 ✗ return AVERROR_INVALIDDATA;
141
142
0/2
✗ Branch 44 → 36 not taken.
✗ Branch 44 → 45 not taken.
✗ while (run-- > 0) {
143 ✗ uint8_t *odst = (uint8_t *)dst;
144 ✗ int off1 = (ly * linesize + lx) * 4;
145 ✗ int off2 = ((y * linesize + x) + off) * 4;
146
147
0/2
✗ Branch 36 → 37 not taken.
✗ Branch 36 → 38 not taken.
✗ if (x == 0) {
148 ✗ z = backstep * 4;
149 } else {
150 ✗ z = 0;
151 }
152
153 ✗ r = odst[off1] +
154 ✗ odst[off2 + 4] -
155 ✗ odst[off2 - z ];
156 ✗ g = odst[off1 + 1] +
157 ✗ odst[off2 + 5] -
158 ✗ odst[off2 - z + 1];
159 ✗ b = odst[off1 + 2] +
160 ✗ odst[off2 + 6] -
161 ✗ odst[off2 - z + 2];
162 ✗ clr = ((b & 0xFF) << 16) + ((g & 0xFF) << 8) + (r & 0xFF);
163 ✗ dst[y * linesize + x] = clr;
164 ✗ lx = x;
165 ✗ ly = y;
166 ✗ (x)++;
167
0/2
✗ Branch 39 → 40 not taken.
✗ Branch 39 → 43 not taken.
✗ if (x >= avctx->width) {
168 ✗ x = 0;
169 ✗ (y)++;
170
0/4
✗ Branch 40 → 41 not taken.
✗ Branch 40 → 43 not taken.
✗ Branch 41 → 42 not taken.
✗ Branch 41 → 43 not taken.
✗ if (y >= avctx->height && run)
171 ✗ return AVERROR_INVALIDDATA;
172 }
173 }
174 ✗ break;
175 ✗ case 5:
176
0/6
✗ Branch 46 → 47 not taken.
✗ Branch 46 → 49 not taken.
✗ Branch 47 → 48 not taken.
✗ Branch 47 → 50 not taken.
✗ Branch 48 → 49 not taken.
✗ Branch 48 → 50 not taken.
✗ if (y < 1 || (y == 1 && x == 0))
177 ✗ return AVERROR_INVALIDDATA;
178
179
0/2
✗ Branch 59 → 51 not taken.
✗ Branch 59 → 60 not taken.
✗ while (run-- > 0) {
180
0/2
✗ Branch 51 → 52 not taken.
✗ Branch 51 → 53 not taken.
✗ if (x == 0) {
181 ✗ z = backstep;
182 } else {
183 ✗ z = 0;
184 }
185
186 ✗ clr = dst[y * linesize + x + off - z];
187 ✗ dst[y * linesize + x] = clr;
188 ✗ lx = x;
189 ✗ ly = y;
190 ✗ (x)++;
191
0/2
✗ Branch 54 → 55 not taken.
✗ Branch 54 → 58 not taken.
✗ if (x >= avctx->width) {
192 ✗ x = 0;
193 ✗ (y)++;
194
0/4
✗ Branch 55 → 56 not taken.
✗ Branch 55 → 58 not taken.
✗ Branch 56 → 57 not taken.
✗ Branch 56 → 58 not taken.
✗ if (y >= avctx->height && run)
195 ✗ return AVERROR_INVALIDDATA;
196 }
197 }
198 ✗ break;
199 }
200
201 ✗ *px = x;
202 ✗ *py = y;
203 ✗ *plx= lx;
204 ✗ *ply= ly;
205
206
0/2
✗ Branch 61 → 62 not taken.
✗ Branch 61 → 63 not taken.
✗ if (avctx->bits_per_coded_sample == 16) {
207 ✗ *cx1 = (clr & 0x3F00) >> 2;
208 ✗ *cx = (clr & 0x3FFFFF) >> 16;
209 } else {
210 ✗ *cx1 = (clr & 0xFC00) >> 4;
211 ✗ *cx = (clr & 0xFFFFFF) >> 18;
212 }
213
214 ✗ return 0;
215 }
216
217 ✗ av_unused static int decode_run_p(AVCodecContext *avctx, uint32_t ptype, int run,
218 int x, int y, uint32_t clr,
219 uint32_t *dst, uint32_t *prev,
220 int linesize, int plinesize,
221 uint32_t *bx, uint32_t *by,
222 uint32_t backstep, int sx1, int sx2,
223 int *cx, int *cx1)
224 {
225 uint32_t r, g, b;
226 int z;
227
228
0/7
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 12 not taken.
✗ Branch 2 → 26 not taken.
✗ Branch 2 → 36 not taken.
✗ Branch 2 → 45 not taken.
✗ Branch 2 → 60 not taken.
✗ Branch 2 → 75 not taken.
✗ switch (ptype) {
229 ✗ case 0:
230
0/2
✗ Branch 10 → 4 not taken.
✗ Branch 10 → 11 not taken.
✗ while (run-- > 0) {
231
0/2
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 6 not taken.
✗ if (*by >= avctx->height)
232 ✗ return AVERROR_INVALIDDATA;
233
234 ✗ dst[*by * linesize + *bx] = clr;
235 ✗ (*bx)++;
236
0/4
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 8 not taken.
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 9 not taken.
✗ if (*bx >= x * 16 + sx2 || *bx >= avctx->width) {
237 ✗ *bx = x * 16 + sx1;
238 ✗ (*by)++;
239 }
240 }
241 ✗ break;
242 ✗ case 1:
243
0/2
✗ Branch 24 → 13 not taken.
✗ Branch 24 → 25 not taken.
✗ while (run-- > 0) {
244
0/2
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 17 not taken.
✗ if (*bx == 0) {
245
0/2
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 16 not taken.
✗ if (*by < 1)
246 ✗ return AVERROR_INVALIDDATA;
247 ✗ z = backstep;
248 } else {
249 ✗ z = 0;
250 }
251
252
0/2
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 20 not taken.
✗ if (*by >= avctx->height)
253 ✗ return AVERROR_INVALIDDATA;
254
255 ✗ clr = dst[*by * linesize + *bx - 1 - z];
256 ✗ dst[*by * linesize + *bx] = clr;
257 ✗ (*bx)++;
258
0/4
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 22 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 23 not taken.
✗ if (*bx >= x * 16 + sx2 || *bx >= avctx->width) {
259 ✗ *bx = x * 16 + sx1;
260 ✗ (*by)++;
261 }
262 }
263 ✗ break;
264 ✗ case 2:
265
0/2
✗ Branch 34 → 27 not taken.
✗ Branch 34 → 35 not taken.
✗ while (run-- > 0) {
266
0/4
✗ Branch 27 → 28 not taken.
✗ Branch 27 → 29 not taken.
✗ Branch 28 → 29 not taken.
✗ Branch 28 → 30 not taken.
✗ if (*by < 1 || *by >= avctx->height)
267 ✗ return AVERROR_INVALIDDATA;
268
269 ✗ clr = dst[(*by - 1) * linesize + *bx];
270 ✗ dst[*by * linesize + *bx] = clr;
271 ✗ (*bx)++;
272
0/4
✗ Branch 30 → 31 not taken.
✗ Branch 30 → 32 not taken.
✗ Branch 31 → 32 not taken.
✗ Branch 31 → 33 not taken.
✗ if (*bx >= x * 16 + sx2 || *bx >= avctx->width) {
273 ✗ *bx = x * 16 + sx1;
274 ✗ (*by)++;
275 }
276 }
277 ✗ break;
278 ✗ case 3:
279
0/2
✗ Branch 43 → 37 not taken.
✗ Branch 43 → 44 not taken.
✗ while (run-- > 0) {
280
0/2
✗ Branch 37 → 38 not taken.
✗ Branch 37 → 39 not taken.
✗ if (*by >= avctx->height)
281 ✗ return AVERROR_INVALIDDATA;
282
283 ✗ clr = prev[*by * plinesize + *bx];
284 ✗ dst[*by * linesize + *bx] = clr;
285 ✗ (*bx)++;
286
0/4
✗ Branch 39 → 40 not taken.
✗ Branch 39 → 41 not taken.
✗ Branch 40 → 41 not taken.
✗ Branch 40 → 42 not taken.
✗ if (*bx >= x * 16 + sx2 || *bx >= avctx->width) {
287 ✗ *bx = x * 16 + sx1;
288 ✗ (*by)++;
289 }
290 }
291 ✗ break;
292 ✗ case 4:
293
0/2
✗ Branch 58 → 46 not taken.
✗ Branch 58 → 59 not taken.
✗ while (run-- > 0) {
294 ✗ uint8_t *odst = (uint8_t *)dst;
295
296
0/4
✗ Branch 46 → 47 not taken.
✗ Branch 46 → 48 not taken.
✗ Branch 47 → 48 not taken.
✗ Branch 47 → 49 not taken.
✗ if (*by < 1 || *by >= avctx->height)
297 ✗ return AVERROR_INVALIDDATA;
298
299
0/2
✗ Branch 49 → 50 not taken.
✗ Branch 49 → 53 not taken.
✗ if (*bx == 0) {
300
0/2
✗ Branch 50 → 51 not taken.
✗ Branch 50 → 52 not taken.
✗ if (*by < 2)
301 ✗ return AVERROR_INVALIDDATA;
302 ✗ z = backstep;
303 } else {
304 ✗ z = 0;
305 }
306
307 ✗ r = odst[((*by - 1) * linesize + *bx) * 4] +
308 ✗ odst[(*by * linesize + *bx - 1 - z) * 4] -
309 ✗ odst[((*by - 1) * linesize + *bx - 1 - z) * 4];
310 ✗ g = odst[((*by - 1) * linesize + *bx) * 4 + 1] +
311 ✗ odst[(*by * linesize + *bx - 1 - z) * 4 + 1] -
312 ✗ odst[((*by - 1) * linesize + *bx - 1 - z) * 4 + 1];
313 ✗ b = odst[((*by - 1) * linesize + *bx) * 4 + 2] +
314 ✗ odst[(*by * linesize + *bx - 1 - z) * 4 + 2] -
315 ✗ odst[((*by - 1) * linesize + *bx - 1 - z) * 4 + 2];
316 ✗ clr = ((b & 0xFF) << 16) + ((g & 0xFF) << 8) + (r & 0xFF);
317 ✗ dst[*by * linesize + *bx] = clr;
318 ✗ (*bx)++;
319
0/4
✗ Branch 54 → 55 not taken.
✗ Branch 54 → 56 not taken.
✗ Branch 55 → 56 not taken.
✗ Branch 55 → 57 not taken.
✗ if (*bx >= x * 16 + sx2 || *bx >= avctx->width) {
320 ✗ *bx = x * 16 + sx1;
321 ✗ (*by)++;
322 }
323 }
324 ✗ break;
325 ✗ case 5:
326
0/2
✗ Branch 73 → 61 not taken.
✗ Branch 73 → 74 not taken.
✗ while (run-- > 0) {
327
0/4
✗ Branch 61 → 62 not taken.
✗ Branch 61 → 63 not taken.
✗ Branch 62 → 63 not taken.
✗ Branch 62 → 64 not taken.
✗ if (*by < 1 || *by >= avctx->height)
328 ✗ return AVERROR_INVALIDDATA;
329
330
0/2
✗ Branch 64 → 65 not taken.
✗ Branch 64 → 68 not taken.
✗ if (*bx == 0) {
331
0/2
✗ Branch 65 → 66 not taken.
✗ Branch 65 → 67 not taken.
✗ if (*by < 2)
332 ✗ return AVERROR_INVALIDDATA;
333 ✗ z = backstep;
334 } else {
335 ✗ z = 0;
336 }
337
338 ✗ clr = dst[(*by - 1) * linesize + *bx - 1 - z];
339 ✗ dst[*by * linesize + *bx] = clr;
340 ✗ (*bx)++;
341
0/4
✗ Branch 69 → 70 not taken.
✗ Branch 69 → 71 not taken.
✗ Branch 70 → 71 not taken.
✗ Branch 70 → 72 not taken.
✗ if (*bx >= x * 16 + sx2 || *bx >= avctx->width) {
342 ✗ *bx = x * 16 + sx1;
343 ✗ (*by)++;
344 }
345 }
346 ✗ break;
347 }
348
349
0/2
✗ Branch 75 → 76 not taken.
✗ Branch 75 → 77 not taken.
✗ if (avctx->bits_per_coded_sample == 16) {
350 ✗ *cx1 = (clr & 0x3F00) >> 2;
351 ✗ *cx = (clr & 0x3FFFFF) >> 16;
352 } else {
353 ✗ *cx1 = (clr & 0xFC00) >> 4;
354 ✗ *cx = (clr & 0xFFFFFF) >> 18;
355 }
356
357 ✗ return 0;
358 }
359
360 #endif /* AVCODEC_SCPR_H */
361