../../../ffmpeg/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
336 / 1726
19.5%
Branches:
175 / 1285
13.6%
Functions:
24 / 58
41.4%

libavcodec/sanm.c
Line Branch Exec Source
1 /*
2 * LucasArts Smush video decoder
3 * Copyright (c) 2006 Cyril Zorin
4 * Copyright (c) 2011 Konstantin Shishkov
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 #include "libavutil/avassert.h"
24 #include "libavutil/mem.h"
25
26 #include "avcodec.h"
27 #include "bytestream.h"
28 #include "copy_block.h"
29 #include "codec_internal.h"
30 #include "decode.h"
31
32 #define NGLYPHS 256
33 #define GLYPH_COORD_VECT_SIZE 16
34 #define PALETTE_SIZE 256
35 #define PALETTE_DELTA 768
36
37 static const int8_t glyph4_x[GLYPH_COORD_VECT_SIZE] = {
38 0, 1, 2, 3, 3, 3, 3, 2, 1, 0, 0, 0, 1, 2, 2, 1
39 };
40
41 static const int8_t glyph4_y[GLYPH_COORD_VECT_SIZE] = {
42 0, 0, 0, 0, 1, 2, 3, 3, 3, 3, 2, 1, 1, 1, 2, 2
43 };
44
45 static const int8_t glyph8_x[GLYPH_COORD_VECT_SIZE] = {
46 0, 2, 5, 7, 7, 7, 7, 7, 7, 5, 2, 0, 0, 0, 0, 0
47 };
48
49 static const int8_t glyph8_y[GLYPH_COORD_VECT_SIZE] = {
50 0, 0, 0, 0, 1, 3, 4, 6, 7, 7, 7, 7, 6, 4, 3, 1
51 };
52
53 /* codec47/bl16 motion vectors */
54 static const int8_t c47_mv[256][2] = {
55 { 0, 0 }, { -1, -43 }, { 6, -43 }, { -9, -42 }, { 13, -41 },
56 { -16, -40 }, { 19, -39 }, { -23, -36 }, { 26, -34 }, { -2, -33 },
57 { 4, -33 }, { -29, -32 }, { -9, -32 }, { 11, -31 }, { -16, -29 },
58 { 32, -29 }, { 18, -28 }, { -34, -26 }, { -22, -25 }, { -1, -25 },
59 { 3, -25 }, { -7, -24 }, { 8, -24 }, { 24, -23 }, { 36, -23 },
60 { -12, -22 }, { 13, -21 }, { -38, -20 }, { 0, -20 }, { -27, -19 },
61 { -4, -19 }, { 4, -19 }, { -17, -18 }, { -8, -17 }, { 8, -17 },
62 { 18, -17 }, { 28, -17 }, { 39, -17 }, { -12, -15 }, { 12, -15 },
63 { -21, -14 }, { -1, -14 }, { 1, -14 }, { -41, -13 }, { -5, -13 },
64 { 5, -13 }, { 21, -13 }, { -31, -12 }, { -15, -11 }, { -8, -11 },
65 { 8, -11 }, { 15, -11 }, { -2, -10 }, { 1, -10 }, { 31, -10 },
66 { -23, -9 }, { -11, -9 }, { -5, -9 }, { 4, -9 }, { 11, -9 },
67 { 42, -9 }, { 6, -8 }, { 24, -8 }, { -18, -7 }, { -7, -7 },
68 { -3, -7 }, { -1, -7 }, { 2, -7 }, { 18, -7 }, { -43, -6 },
69 { -13, -6 }, { -4, -6 }, { 4, -6 }, { 8, -6 }, { -33, -5 },
70 { -9, -5 }, { -2, -5 }, { 0, -5 }, { 2, -5 }, { 5, -5 },
71 { 13, -5 }, { -25, -4 }, { -6, -4 }, { -3, -4 }, { 3, -4 },
72 { 9, -4 }, { -19, -3 }, { -7, -3 }, { -4, -3 }, { -2, -3 },
73 { -1, -3 }, { 0, -3 }, { 1, -3 }, { 2, -3 }, { 4, -3 },
74 { 6, -3 }, { 33, -3 }, { -14, -2 }, { -10, -2 }, { -5, -2 },
75 { -3, -2 }, { -2, -2 }, { -1, -2 }, { 0, -2 }, { 1, -2 },
76 { 2, -2 }, { 3, -2 }, { 5, -2 }, { 7, -2 }, { 14, -2 },
77 { 19, -2 }, { 25, -2 }, { 43, -2 }, { -7, -1 }, { -3, -1 },
78 { -2, -1 }, { -1, -1 }, { 0, -1 }, { 1, -1 }, { 2, -1 },
79 { 3, -1 }, { 10, -1 }, { -5, 0 }, { -3, 0 }, { -2, 0 },
80 { -1, 0 }, { 1, 0 }, { 2, 0 }, { 3, 0 }, { 5, 0 },
81 { 7, 0 }, { -10, 1 }, { -7, 1 }, { -3, 1 }, { -2, 1 },
82 { -1, 1 }, { 0, 1 }, { 1, 1 }, { 2, 1 }, { 3, 1 },
83 { -43, 2 }, { -25, 2 }, { -19, 2 }, { -14, 2 }, { -5, 2 },
84 { -3, 2 }, { -2, 2 }, { -1, 2 }, { 0, 2 }, { 1, 2 },
85 { 2, 2 }, { 3, 2 }, { 5, 2 }, { 7, 2 }, { 10, 2 },
86 { 14, 2 }, { -33, 3 }, { -6, 3 }, { -4, 3 }, { -2, 3 },
87 { -1, 3 }, { 0, 3 }, { 1, 3 }, { 2, 3 }, { 4, 3 },
88 { 19, 3 }, { -9, 4 }, { -3, 4 }, { 3, 4 }, { 7, 4 },
89 { 25, 4 }, { -13, 5 }, { -5, 5 }, { -2, 5 }, { 0, 5 },
90 { 2, 5 }, { 5, 5 }, { 9, 5 }, { 33, 5 }, { -8, 6 },
91 { -4, 6 }, { 4, 6 }, { 13, 6 }, { 43, 6 }, { -18, 7 },
92 { -2, 7 }, { 0, 7 }, { 2, 7 }, { 7, 7 }, { 18, 7 },
93 { -24, 8 }, { -6, 8 }, { -42, 9 }, { -11, 9 }, { -4, 9 },
94 { 5, 9 }, { 11, 9 }, { 23, 9 }, { -31, 10 }, { -1, 10 },
95 { 2, 10 }, { -15, 11 }, { -8, 11 }, { 8, 11 }, { 15, 11 },
96 { 31, 12 }, { -21, 13 }, { -5, 13 }, { 5, 13 }, { 41, 13 },
97 { -1, 14 }, { 1, 14 }, { 21, 14 }, { -12, 15 }, { 12, 15 },
98 { -39, 17 }, { -28, 17 }, { -18, 17 }, { -8, 17 }, { 8, 17 },
99 { 17, 18 }, { -4, 19 }, { 0, 19 }, { 4, 19 }, { 27, 19 },
100 { 38, 20 }, { -13, 21 }, { 12, 22 }, { -36, 23 }, { -24, 23 },
101 { -8, 24 }, { 7, 24 }, { -3, 25 }, { 1, 25 }, { 22, 25 },
102 { 34, 26 }, { -18, 28 }, { -32, 29 }, { 16, 29 }, { -11, 31 },
103 { 9, 32 }, { 29, 32 }, { -4, 33 }, { 2, 33 }, { -26, 34 },
104 { 23, 36 }, { -19, 39 }, { 16, 40 }, { -13, 41 }, { 9, 42 },
105 { -6, 43 }, { 1, 43 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
106 };
107
108 /* codec37/48 motion vector tables: 3x 512 bytes/256 x-y pairs */
109 static const int8_t c37_mv[] = {
110 0, 0, 1, 0, 2, 0, 3, 0, 5, 0,
111 8, 0, 13, 0, 21, 0, -1, 0, -2, 0,
112 -3, 0, -5, 0, -8, 0, -13, 0, -17, 0,
113 -21, 0, 0, 1, 1, 1, 2, 1, 3, 1,
114 5, 1, 8, 1, 13, 1, 21, 1, -1, 1,
115 -2, 1, -3, 1, -5, 1, -8, 1, -13, 1,
116 -17, 1, -21, 1, 0, 2, 1, 2, 2, 2,
117 3, 2, 5, 2, 8, 2, 13, 2, 21, 2,
118 -1, 2, -2, 2, -3, 2, -5, 2, -8, 2,
119 -13, 2, -17, 2, -21, 2, 0, 3, 1, 3,
120 2, 3, 3, 3, 5, 3, 8, 3, 13, 3,
121 21, 3, -1, 3, -2, 3, -3, 3, -5, 3,
122 -8, 3, -13, 3, -17, 3, -21, 3, 0, 5,
123 1, 5, 2, 5, 3, 5, 5, 5, 8, 5,
124 13, 5, 21, 5, -1, 5, -2, 5, -3, 5,
125 -5, 5, -8, 5, -13, 5, -17, 5, -21, 5,
126 0, 8, 1, 8, 2, 8, 3, 8, 5, 8,
127 8, 8, 13, 8, 21, 8, -1, 8, -2, 8,
128 -3, 8, -5, 8, -8, 8, -13, 8, -17, 8,
129 -21, 8, 0, 13, 1, 13, 2, 13, 3, 13,
130 5, 13, 8, 13, 13, 13, 21, 13, -1, 13,
131 -2, 13, -3, 13, -5, 13, -8, 13, -13, 13,
132 -17, 13, -21, 13, 0, 21, 1, 21, 2, 21,
133 3, 21, 5, 21, 8, 21, 13, 21, 21, 21,
134 -1, 21, -2, 21, -3, 21, -5, 21, -8, 21,
135 -13, 21, -17, 21, -21, 21, 0, -1, 1, -1,
136 2, -1, 3, -1, 5, -1, 8, -1, 13, -1,
137 21, -1, -1, -1, -2, -1, -3, -1, -5, -1,
138 -8, -1, -13, -1, -17, -1, -21, -1, 0, -2,
139 1, -2, 2, -2, 3, -2, 5, -2, 8, -2,
140 13, -2, 21, -2, -1, -2, -2, -2, -3, -2,
141 -5, -2, -8, -2, -13, -2, -17, -2, -21, -2,
142 0, -3, 1, -3, 2, -3, 3, -3, 5, -3,
143 8, -3, 13, -3, 21, -3, -1, -3, -2, -3,
144 -3, -3, -5, -3, -8, -3, -13, -3, -17, -3,
145 -21, -3, 0, -5, 1, -5, 2, -5, 3, -5,
146 5, -5, 8, -5, 13, -5, 21, -5, -1, -5,
147 -2, -5, -3, -5, -5, -5, -8, -5, -13, -5,
148 -17, -5, -21, -5, 0, -8, 1, -8, 2, -8,
149 3, -8, 5, -8, 8, -8, 13, -8, 21, -8,
150 -1, -8, -2, -8, -3, -8, -5, -8, -8, -8,
151 -13, -8, -17, -8, -21, -8, 0, -13, 1, -13,
152 2, -13, 3, -13, 5, -13, 8, -13, 13, -13,
153 21, -13, -1, -13, -2, -13, -3, -13, -5, -13,
154 -8, -13, -13, -13, -17, -13, -21, -13, 0, -17,
155 1, -17, 2, -17, 3, -17, 5, -17, 8, -17,
156 13, -17, 21, -17, -1, -17, -2, -17, -3, -17,
157 -5, -17, -8, -17, -13, -17, -17, -17, -21, -17,
158 0, -21, 1, -21, 2, -21, 3, -21, 5, -21,
159 8, -21, 13, -21, 21, -21, -1, -21, -2, -21,
160 -3, -21, -5, -21, -8, -21, -13, -21, -17, -21,
161 0, 0,
162 0, 0, -8, -29, 8, -29, -18, -25, 17, -25,
163 0, -23, -6, -22, 6, -22, -13, -19, 12, -19,
164 0, -18, 25, -18, -25, -17, -5, -17, 5, -17,
165 -10, -15, 10, -15, 0, -14, -4, -13, 4, -13,
166 19, -13, -19, -12, -8, -11, -2, -11, 0, -11,
167 2, -11, 8, -11, -15, -10, -4, -10, 4, -10,
168 15, -10, -6, -9, -1, -9, 1, -9, 6, -9,
169 -29, -8, -11, -8, -8, -8, -3, -8, 3, -8,
170 8, -8, 11, -8, 29, -8, -5, -7, -2, -7,
171 0, -7, 2, -7, 5, -7, -22, -6, -9, -6,
172 -6, -6, -3, -6, -1, -6, 1, -6, 3, -6,
173 6, -6, 9, -6, 22, -6, -17, -5, -7, -5,
174 -4, -5, -2, -5, 0, -5, 2, -5, 4, -5,
175 7, -5, 17, -5, -13, -4, -10, -4, -5, -4,
176 -3, -4, -1, -4, 0, -4, 1, -4, 3, -4,
177 5, -4, 10, -4, 13, -4, -8, -3, -6, -3,
178 -4, -3, -3, -3, -2, -3, -1, -3, 0, -3,
179 1, -3, 2, -3, 4, -3, 6, -3, 8, -3,
180 -11, -2, -7, -2, -5, -2, -3, -2, -2, -2,
181 -1, -2, 0, -2, 1, -2, 2, -2, 3, -2,
182 5, -2, 7, -2, 11, -2, -9, -1, -6, -1,
183 -4, -1, -3, -1, -2, -1, -1, -1, 0, -1,
184 1, -1, 2, -1, 3, -1, 4, -1, 6, -1,
185 9, -1, -31, 0, -23, 0, -18, 0, -14, 0,
186 -11, 0, -7, 0, -5, 0, -4, 0, -3, 0,
187 -2, 0, -1, 0, 0, -31, 1, 0, 2, 0,
188 3, 0, 4, 0, 5, 0, 7, 0, 11, 0,
189 14, 0, 18, 0, 23, 0, 31, 0, -9, 1,
190 -6, 1, -4, 1, -3, 1, -2, 1, -1, 1,
191 0, 1, 1, 1, 2, 1, 3, 1, 4, 1,
192 6, 1, 9, 1, -11, 2, -7, 2, -5, 2,
193 -3, 2, -2, 2, -1, 2, 0, 2, 1, 2,
194 2, 2, 3, 2, 5, 2, 7, 2, 11, 2,
195 -8, 3, -6, 3, -4, 3, -2, 3, -1, 3,
196 0, 3, 1, 3, 2, 3, 3, 3, 4, 3,
197 6, 3, 8, 3, -13, 4, -10, 4, -5, 4,
198 -3, 4, -1, 4, 0, 4, 1, 4, 3, 4,
199 5, 4, 10, 4, 13, 4, -17, 5, -7, 5,
200 -4, 5, -2, 5, 0, 5, 2, 5, 4, 5,
201 7, 5, 17, 5, -22, 6, -9, 6, -6, 6,
202 -3, 6, -1, 6, 1, 6, 3, 6, 6, 6,
203 9, 6, 22, 6, -5, 7, -2, 7, 0, 7,
204 2, 7, 5, 7, -29, 8, -11, 8, -8, 8,
205 -3, 8, 3, 8, 8, 8, 11, 8, 29, 8,
206 -6, 9, -1, 9, 1, 9, 6, 9, -15, 10,
207 -4, 10, 4, 10, 15, 10, -8, 11, -2, 11,
208 0, 11, 2, 11, 8, 11, 19, 12, -19, 13,
209 -4, 13, 4, 13, 0, 14, -10, 15, 10, 15,
210 -5, 17, 5, 17, 25, 17, -25, 18, 0, 18,
211 -12, 19, 13, 19, -6, 22, 6, 22, 0, 23,
212 -17, 25, 18, 25, -8, 29, 8, 29, 0, 31,
213 0, 0,
214 0, 0, -6, -22, 6, -22, -13, -19, 12, -19,
215 0, -18, -5, -17, 5, -17, -10, -15, 10, -15,
216 0, -14, -4, -13, 4, -13, 19, -13, -19, -12,
217 -8, -11, -2, -11, 0, -11, 2, -11, 8, -11,
218 -15, -10, -4, -10, 4, -10, 15, -10, -6, -9,
219 -1, -9, 1, -9, 6, -9, -11, -8, -8, -8,
220 -3, -8, 0, -8, 3, -8, 8, -8, 11, -8,
221 -5, -7, -2, -7, 0, -7, 2, -7, 5, -7,
222 -22, -6, -9, -6, -6, -6, -3, -6, -1, -6,
223 1, -6, 3, -6, 6, -6, 9, -6, 22, -6,
224 -17, -5, -7, -5, -4, -5, -2, -5, -1, -5,
225 0, -5, 1, -5, 2, -5, 4, -5, 7, -5,
226 17, -5, -13, -4, -10, -4, -5, -4, -3, -4,
227 -2, -4, -1, -4, 0, -4, 1, -4, 2, -4,
228 3, -4, 5, -4, 10, -4, 13, -4, -8, -3,
229 -6, -3, -4, -3, -3, -3, -2, -3, -1, -3,
230 0, -3, 1, -3, 2, -3, 3, -3, 4, -3,
231 6, -3, 8, -3, -11, -2, -7, -2, -5, -2,
232 -4, -2, -3, -2, -2, -2, -1, -2, 0, -2,
233 1, -2, 2, -2, 3, -2, 4, -2, 5, -2,
234 7, -2, 11, -2, -9, -1, -6, -1, -5, -1,
235 -4, -1, -3, -1, -2, -1, -1, -1, 0, -1,
236 1, -1, 2, -1, 3, -1, 4, -1, 5, -1,
237 6, -1, 9, -1, -23, 0, -18, 0, -14, 0,
238 -11, 0, -7, 0, -5, 0, -4, 0, -3, 0,
239 -2, 0, -1, 0, 0, -23, 1, 0, 2, 0,
240 3, 0, 4, 0, 5, 0, 7, 0, 11, 0,
241 14, 0, 18, 0, 23, 0, -9, 1, -6, 1,
242 -5, 1, -4, 1, -3, 1, -2, 1, -1, 1,
243 0, 1, 1, 1, 2, 1, 3, 1, 4, 1,
244 5, 1, 6, 1, 9, 1, -11, 2, -7, 2,
245 -5, 2, -4, 2, -3, 2, -2, 2, -1, 2,
246 0, 2, 1, 2, 2, 2, 3, 2, 4, 2,
247 5, 2, 7, 2, 11, 2, -8, 3, -6, 3,
248 -4, 3, -3, 3, -2, 3, -1, 3, 0, 3,
249 1, 3, 2, 3, 3, 3, 4, 3, 6, 3,
250 8, 3, -13, 4, -10, 4, -5, 4, -3, 4,
251 -2, 4, -1, 4, 0, 4, 1, 4, 2, 4,
252 3, 4, 5, 4, 10, 4, 13, 4, -17, 5,
253 -7, 5, -4, 5, -2, 5, -1, 5, 0, 5,
254 1, 5, 2, 5, 4, 5, 7, 5, 17, 5,
255 -22, 6, -9, 6, -6, 6, -3, 6, -1, 6,
256 1, 6, 3, 6, 6, 6, 9, 6, 22, 6,
257 -5, 7, -2, 7, 0, 7, 2, 7, 5, 7,
258 -11, 8, -8, 8, -3, 8, 0, 8, 3, 8,
259 8, 8, 11, 8, -6, 9, -1, 9, 1, 9,
260 6, 9, -15, 10, -4, 10, 4, 10, 15, 10,
261 -8, 11, -2, 11, 0, 11, 2, 11, 8, 11,
262 19, 12, -19, 13, -4, 13, 4, 13, 0, 14,
263 -10, 15, 10, 15, -5, 17, 5, 17, 0, 18,
264 -12, 19, 13, 19, -6, 22, 6, 22, 0, 23,
265 0, 0
266 };
267
268 typedef struct SANMVideoContext {
269 AVCodecContext *avctx;
270 GetByteContext gb;
271
272 int version, subversion, have_dimensions, first_fob;
273 uint32_t pal[PALETTE_SIZE];
274 int16_t delta_pal[PALETTE_DELTA], shift_pal[PALETTE_DELTA];
275
276 ptrdiff_t pitch;
277 int width, height;
278 int aligned_width, aligned_height;
279 int prev_seq;
280
281 AVFrame *frame;
282 uint16_t *fbuf, *frm0, *frm1, *frm2;
283 uint8_t *stored_frame;
284 uint32_t fbuf_size, frm0_size, frm1_size, frm2_size;
285 uint32_t stor_size;
286 uint32_t stored_frame_size;
287
288 uint8_t *rle_buf;
289 unsigned int rle_buf_size;
290
291 long npixels, buf_size;
292
293 uint16_t codebook[256];
294 uint16_t small_codebook[4];
295
296 int8_t p4x4glyphs[NGLYPHS][16];
297 int8_t p8x8glyphs[NGLYPHS][64];
298 uint8_t c47itbl[0x10000];
299 uint8_t c23lut[256];
300 uint8_t c4tbl[2][256][16];
301 uint16_t c4param;
302 uint8_t c47cb[4];
303 uint8_t c45tbl1[0x300];
304 uint8_t c45tbl2[0x8000];
305 } SANMVideoContext;
306
307 enum GlyphEdge {
308 LEFT_EDGE,
309 TOP_EDGE,
310 RIGHT_EDGE,
311 BOTTOM_EDGE,
312 NO_EDGE
313 };
314
315 enum GlyphDir {
316 DIR_LEFT,
317 DIR_UP,
318 DIR_RIGHT,
319 DIR_DOWN,
320 NO_DIR
321 };
322
323 /**
324 * Return enum GlyphEdge of box where point (x, y) lies.
325 *
326 * @param x x point coordinate
327 * @param y y point coordinate
328 * @param edge_size box width/height.
329 */
330 1632 static enum GlyphEdge which_edge(int x, int y, int edge_size)
331 {
332 1632 const int edge_max = edge_size - 1;
333
334
2/2
✓ Branch 2 → 3 taken 408 times.
✓ Branch 2 → 4 taken 1224 times.
1632 if (!y)
335 408 return BOTTOM_EDGE;
336
2/2
✓ Branch 4 → 5 taken 408 times.
✓ Branch 4 → 6 taken 816 times.
1224 else if (y == edge_max)
337 408 return TOP_EDGE;
338
2/2
✓ Branch 6 → 7 taken 306 times.
✓ Branch 6 → 8 taken 510 times.
816 else if (!x)
339 306 return LEFT_EDGE;
340
2/2
✓ Branch 8 → 9 taken 306 times.
✓ Branch 8 → 10 taken 204 times.
510 else if (x == edge_max)
341 306 return RIGHT_EDGE;
342 else
343 204 return NO_EDGE;
344 }
345
346 1536 static enum GlyphDir which_direction(enum GlyphEdge edge0, enum GlyphEdge edge1)
347 {
348
6/6
✓ Branch 2 → 3 taken 288 times.
✓ Branch 2 → 4 taken 1248 times.
✓ Branch 3 → 4 taken 228 times.
✓ Branch 3 → 10 taken 60 times.
✓ Branch 4 → 5 taken 288 times.
✓ Branch 4 → 6 taken 1188 times.
1536 if ((edge0 == LEFT_EDGE && edge1 == RIGHT_EDGE) ||
349
4/4
✓ Branch 5 → 6 taken 228 times.
✓ Branch 5 → 10 taken 60 times.
✓ Branch 6 → 7 taken 384 times.
✓ Branch 6 → 8 taken 1032 times.
1476 (edge1 == LEFT_EDGE && edge0 == RIGHT_EDGE) ||
350
4/4
✓ Branch 7 → 8 taken 96 times.
✓ Branch 7 → 10 taken 288 times.
✓ Branch 8 → 9 taken 288 times.
✓ Branch 8 → 11 taken 840 times.
1416 (edge0 == BOTTOM_EDGE && edge1 != TOP_EDGE) ||
351
2/2
✓ Branch 9 → 10 taken 192 times.
✓ Branch 9 → 11 taken 96 times.
288 (edge1 == BOTTOM_EDGE && edge0 != TOP_EDGE))
352 600 return DIR_UP;
353
6/6
✓ Branch 11 → 12 taken 384 times.
✓ Branch 11 → 13 taken 552 times.
✓ Branch 12 → 13 taken 96 times.
✓ Branch 12 → 15 taken 288 times.
✓ Branch 13 → 14 taken 288 times.
✓ Branch 13 → 16 taken 360 times.
936 else if ((edge0 == TOP_EDGE && edge1 != BOTTOM_EDGE) ||
354
2/2
✓ Branch 14 → 15 taken 192 times.
✓ Branch 14 → 16 taken 96 times.
288 (edge1 == TOP_EDGE && edge0 != BOTTOM_EDGE))
355 480 return DIR_DOWN;
356
5/6
✓ Branch 16 → 17 taken 84 times.
✓ Branch 16 → 18 taken 372 times.
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 20 taken 84 times.
✓ Branch 18 → 19 taken 24 times.
✓ Branch 18 → 21 taken 348 times.
456 else if ((edge0 == LEFT_EDGE && edge1 != RIGHT_EDGE) ||
357
1/2
✓ Branch 19 → 20 taken 24 times.
✗ Branch 19 → 21 not taken.
24 (edge1 == LEFT_EDGE && edge0 != RIGHT_EDGE))
358 108 return DIR_LEFT;
359
5/6
✓ Branch 21 → 22 taken 96 times.
✓ Branch 21 → 23 taken 252 times.
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 29 taken 96 times.
✓ Branch 23 → 24 taken 96 times.
✓ Branch 23 → 25 taken 156 times.
348 else if ((edge0 == TOP_EDGE && edge1 == BOTTOM_EDGE) ||
360
3/4
✗ Branch 24 → 25 not taken.
✓ Branch 24 → 29 taken 96 times.
✓ Branch 25 → 26 taken 84 times.
✓ Branch 25 → 27 taken 72 times.
252 (edge1 == TOP_EDGE && edge0 == BOTTOM_EDGE) ||
361
3/4
✗ Branch 26 → 27 not taken.
✓ Branch 26 → 29 taken 84 times.
✓ Branch 27 → 28 taken 24 times.
✓ Branch 27 → 30 taken 48 times.
156 (edge0 == RIGHT_EDGE && edge1 != LEFT_EDGE) ||
362
1/2
✓ Branch 28 → 29 taken 24 times.
✗ Branch 28 → 30 not taken.
24 (edge1 == RIGHT_EDGE && edge0 != LEFT_EDGE))
363 300 return DIR_RIGHT;
364
365 48 return NO_DIR;
366 }
367
368 /* Interpolate two points. */
369 6600 static void interp_point(int8_t *points, int x0, int y0, int x1, int y1,
370 int pos, int npoints)
371 {
372
2/2
✓ Branch 2 → 3 taken 6504 times.
✓ Branch 2 → 4 taken 96 times.
6600 if (npoints) {
373 6504 points[0] = (x0 * pos + x1 * (npoints - pos) + (npoints >> 1)) / npoints;
374 6504 points[1] = (y0 * pos + y1 * (npoints - pos) + (npoints >> 1)) / npoints;
375 } else {
376 96 points[0] = x0;
377 96 points[1] = y0;
378 }
379 6600 }
380
381 /**
382 * Construct glyphs by iterating through vector coordinates.
383 *
384 * @param pglyphs pointer to table where glyphs are stored
385 * @param xvec pointer to x component of vector coordinates
386 * @param yvec pointer to y component of vector coordinates
387 * @param side_length glyph width/height.
388 */
389 6 static void make_glyphs(int8_t *pglyphs, const int8_t *xvec, const int8_t *yvec,
390 const int side_length)
391 {
392 6 const int glyph_size = side_length * side_length;
393 6 int8_t *pglyph = pglyphs;
394
395 int i, j;
396
2/2
✓ Branch 31 → 3 taken 96 times.
✓ Branch 31 → 32 taken 6 times.
102 for (i = 0; i < GLYPH_COORD_VECT_SIZE; i++) {
397 96 int x0 = xvec[i];
398 96 int y0 = yvec[i];
399 96 enum GlyphEdge edge0 = which_edge(x0, y0, side_length);
400
401
2/2
✓ Branch 29 → 5 taken 1536 times.
✓ Branch 29 → 30 taken 96 times.
1632 for (j = 0; j < GLYPH_COORD_VECT_SIZE; j++, pglyph += glyph_size) {
402 1536 int x1 = xvec[j];
403 1536 int y1 = yvec[j];
404 1536 enum GlyphEdge edge1 = which_edge(x1, y1, side_length);
405 1536 enum GlyphDir dir = which_direction(edge0, edge1);
406 1536 int npoints = FFMAX(FFABS(x1 - x0), FFABS(y1 - y0));
407 int ipoint;
408
409
2/2
✓ Branch 27 → 8 taken 6600 times.
✓ Branch 27 → 28 taken 1536 times.
8136 for (ipoint = 0; ipoint <= npoints; ipoint++) {
410 int8_t point[2];
411 int irow, icol;
412
413 6600 interp_point(point, x0, y0, x1, y1, ipoint, npoints);
414
415
5/5
✓ Branch 9 → 10 taken 2832 times.
✓ Branch 9 → 14 taken 1968 times.
✓ Branch 9 → 18 taken 282 times.
✓ Branch 9 → 22 taken 1434 times.
✓ Branch 9 → 26 taken 84 times.
6600 switch (dir) {
416 2832 case DIR_UP:
417
2/2
✓ Branch 12 → 11 taken 8232 times.
✓ Branch 12 → 13 taken 2832 times.
11064 for (irow = point[1]; irow >= 0; irow--)
418 8232 pglyph[point[0] + irow * side_length] = 1;
419 2832 break;
420
421 1968 case DIR_DOWN:
422
2/2
✓ Branch 16 → 15 taken 4500 times.
✓ Branch 16 → 17 taken 1968 times.
6468 for (irow = point[1]; irow < side_length; irow++)
423 4500 pglyph[point[0] + irow * side_length] = 1;
424 1968 break;
425
426 282 case DIR_LEFT:
427
2/2
✓ Branch 20 → 19 taken 378 times.
✓ Branch 20 → 21 taken 282 times.
660 for (icol = point[0]; icol >= 0; icol--)
428 378 pglyph[icol + point[1] * side_length] = 1;
429 282 break;
430
431 1434 case DIR_RIGHT:
432
2/2
✓ Branch 24 → 23 taken 4794 times.
✓ Branch 24 → 25 taken 1434 times.
6228 for (icol = point[0]; icol < side_length; icol++)
433 4794 pglyph[icol + point[1] * side_length] = 1;
434 1434 break;
435 }
436 }
437 }
438 }
439 6 }
440
441 6 static void init_sizes(SANMVideoContext *ctx, int width, int height)
442 {
443 6 ctx->width = width;
444 6 ctx->height = height;
445 6 ctx->npixels = width * height;
446
447 6 ctx->aligned_width = FFALIGN(width, 8);
448 6 ctx->aligned_height = FFALIGN(height, 8);
449
450 6 ctx->buf_size = ctx->aligned_width * ctx->aligned_height * sizeof(ctx->frm0[0]);
451 6 ctx->pitch = width;
452 6 }
453
454 3 static void destroy_buffers(SANMVideoContext *ctx)
455 {
456 3 av_freep(&ctx->fbuf);
457 3 av_freep(&ctx->frm0);
458 3 av_freep(&ctx->frm1);
459 3 av_freep(&ctx->frm2);
460 3 av_freep(&ctx->stored_frame);
461 3 av_freep(&ctx->rle_buf);
462 3 ctx->frm0_size =
463 3 ctx->frm1_size =
464 3 ctx->frm2_size = 0;
465 3 init_sizes(ctx, 0, 0);
466 3 }
467
468 3 static av_cold int init_buffers(SANMVideoContext *ctx)
469 {
470 3 av_fast_padded_mallocz(&ctx->fbuf, &ctx->fbuf_size, ctx->buf_size);
471 3 av_fast_padded_mallocz(&ctx->frm0, &ctx->frm0_size, ctx->buf_size);
472 3 av_fast_padded_mallocz(&ctx->frm1, &ctx->frm1_size, ctx->buf_size);
473 3 av_fast_padded_mallocz(&ctx->frm2, &ctx->frm2_size, ctx->buf_size);
474
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 9 taken 3 times.
3 if (!ctx->version) {
475 ✗ av_fast_padded_mallocz(&ctx->stored_frame,
476 ✗ &ctx->stored_frame_size, ctx->buf_size);
477 ✗ ctx->stor_size = 0;
478 }
479
480
3/6
✓ Branch 9 → 10 taken 3 times.
✗ Branch 9 → 14 not taken.
✓ Branch 10 → 11 taken 3 times.
✗ Branch 10 → 14 not taken.
✓ Branch 11 → 12 taken 3 times.
✗ Branch 11 → 14 not taken.
3 if (!ctx->frm0 || !ctx->frm1 || !ctx->frm2 ||
481
2/4
✓ Branch 12 → 13 taken 3 times.
✗ Branch 12 → 16 not taken.
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 16 taken 3 times.
3 (!ctx->stored_frame && !ctx->version)) {
482 ✗ destroy_buffers(ctx);
483 ✗ return AVERROR(ENOMEM);
484 }
485
486 3 return 0;
487 }
488
489 ✗ static void codec33_gen_tiles(SANMVideoContext *ctx, int8_t param1)
490 {
491 ✗ uint8_t *dst = &(ctx->c4tbl[0][0][0]);
492 int i, j, k, l, m, n, o, p;
493
494
0/2
✗ Branch 7 → 3 not taken.
✗ Branch 7 → 8 not taken.
✗ for (i = 0; i < 8; i++) {
495
0/2
✗ Branch 5 → 4 not taken.
✗ Branch 5 → 6 not taken.
✗ for (k = 0; k < 8; k++) {
496 ✗ j = i + param1;
497 ✗ l = k + param1;
498 ✗ p = (j + l) >> 1;
499 ✗ n = (j + p) >> 1;
500 ✗ m = (p + l) >> 1;
501
502 ✗ *dst++ = p; *dst++ = p; *dst++ = n; *dst++ = j;
503 ✗ *dst++ = p; *dst++ = p; *dst++ = n; *dst++ = j;
504 ✗ *dst++ = m; *dst++ = m; *dst++ = p; *dst++ = j;
505 ✗ *dst++ = l; *dst++ = l; *dst++ = m; *dst++ = p;
506 }
507 }
508
509
0/2
✗ Branch 13 → 9 not taken.
✗ Branch 13 → 14 not taken.
✗ for (i = 0; i < 8; i++) {
510
0/2
✗ Branch 11 → 10 not taken.
✗ Branch 11 → 12 not taken.
✗ for (k = 0; k < 8; k++) {
511 ✗ j = i + param1;
512 ✗ l = k + param1;
513 ✗ n = (j + l) >> 1;
514 ✗ m = (l + n) >> 1;
515
516 ✗ *dst++ = j; *dst++ = j; *dst++ = j; *dst++ = j;
517 ✗ *dst++ = n; *dst++ = n; *dst++ = n; *dst++ = n;
518 ✗ *dst++ = m; *dst++ = m; *dst++ = m; *dst++ = m;
519 ✗ *dst++ = l; *dst++ = l; *dst++ = l; *dst++ = l;
520 }
521 }
522
523
0/2
✗ Branch 19 → 15 not taken.
✗ Branch 19 → 20 not taken.
✗ for (i = 0; i < 8; i++) {
524
0/2
✗ Branch 17 → 16 not taken.
✗ Branch 17 → 18 not taken.
✗ for (k = 0; k < 8; k++) {
525 ✗ j = i + param1;
526 ✗ l = k + param1;
527 ✗ m = (j + l) >> 1;
528 ✗ n = (j + m) >> 1;
529 ✗ o = (l + m) >> 1;
530
531 ✗ *dst++ = j; *dst++ = j; *dst++ = n; *dst++ = m;
532 ✗ *dst++ = j; *dst++ = j; *dst++ = n; *dst++ = m;
533 ✗ *dst++ = n; *dst++ = n; *dst++ = m; *dst++ = o;
534 ✗ *dst++ = m; *dst++ = m; *dst++ = o; *dst++ = l;
535 }
536 }
537
538
0/2
✗ Branch 25 → 21 not taken.
✗ Branch 25 → 26 not taken.
✗ for (i = 0; i < 8; i++) {
539
0/2
✗ Branch 23 → 22 not taken.
✗ Branch 23 → 24 not taken.
✗ for (k = 0; k < 8; k++) {
540 ✗ j = i + param1;
541 ✗ l = k + param1;
542 ✗ m = (j + l) >> 1;
543 ✗ n = (l + m) >> 1;
544
545 ✗ *dst++ = j; *dst++ = m; *dst++ = n; *dst++ = l;
546 ✗ *dst++ = j; *dst++ = m; *dst++ = n; *dst++ = l;
547 ✗ *dst++ = j; *dst++ = m; *dst++ = n; *dst++ = l;
548 ✗ *dst++ = j; *dst++ = m; *dst++ = n; *dst++ = l;
549 }
550 }
551 ✗ }
552
553 ✗ static void codec4_gen_tiles(SANMVideoContext *ctx, uint16_t param1)
554 {
555 ✗ uint8_t *dst = &(ctx->c4tbl[0][0][0]);
556 int i, j, k, l, m, n, o;
557
558
0/2
✗ Branch 11 → 3 not taken.
✗ Branch 11 → 12 not taken.
✗ for (i = 1; i < 16; i += 2) {
559
0/2
✗ Branch 9 → 4 not taken.
✗ Branch 9 → 10 not taken.
✗ for (k = 0; k < 16; k++) {
560 ✗ j = i + param1;
561 ✗ l = k + param1;
562 ✗ m = (j + l) / 2;
563 ✗ n = (j + m) / 2;
564 ✗ o = (l + m) / 2;
565
0/4
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 6 not taken.
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 7 not taken.
✗ if (j == m || l == m) {
566 ✗ *dst++ = l; *dst++ = j; *dst++ = l; *dst++ = j;
567 ✗ *dst++ = j; *dst++ = l; *dst++ = j; *dst++ = j;
568 ✗ *dst++ = l; *dst++ = j; *dst++ = l; *dst++ = j;
569 ✗ *dst++ = l; *dst++ = l; *dst++ = j; *dst++ = l;
570 } else {
571 ✗ *dst++ = m; *dst++ = m; *dst++ = n; *dst++ = j;
572 ✗ *dst++ = m; *dst++ = m; *dst++ = n; *dst++ = j;
573 ✗ *dst++ = o; *dst++ = o; *dst++ = m; *dst++ = n;
574 ✗ *dst++ = l; *dst++ = l; *dst++ = o; *dst++ = m;
575 }
576 }
577 }
578
579
0/2
✗ Branch 21 → 13 not taken.
✗ Branch 21 → 22 not taken.
✗ for (i = 0; i < 16; i += 2) {
580
0/2
✗ Branch 19 → 14 not taken.
✗ Branch 19 → 20 not taken.
✗ for (k = 0; k < 16; k++) {
581 ✗ j = i + param1;
582 ✗ l = k + param1;
583 ✗ m = (j + l) / 2;
584 ✗ n = (j + m) / 2;
585 ✗ o = (l + m) / 2;
586
0/4
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 16 not taken.
✗ Branch 15 → 16 not taken.
✗ Branch 15 → 17 not taken.
✗ if (m == j || m == l) {
587 ✗ *dst++ = j; *dst++ = j; *dst++ = l; *dst++ = j;
588 ✗ *dst++ = j; *dst++ = j; *dst++ = j; *dst++ = l;
589 ✗ *dst++ = l; *dst++ = j; *dst++ = l; *dst++ = l;
590 ✗ *dst++ = j; *dst++ = l; *dst++ = j; *dst++ = l;
591 } else {
592 ✗ *dst++ = j; *dst++ = j; *dst++ = n; *dst++ = m;
593 ✗ *dst++ = j; *dst++ = j; *dst++ = n; *dst++ = m;
594 ✗ *dst++ = n; *dst++ = n; *dst++ = m; *dst++ = o;
595 ✗ *dst++ = m; *dst++ = m; *dst++ = o; *dst++ = l;
596 }
597 }
598 }
599 ✗ }
600
601
602 ✗ static int codec4_load_tiles(SANMVideoContext *ctx, GetByteContext *gb,
603 uint16_t param2, uint8_t clr)
604 {
605 ✗ uint8_t c, *dst = (uint8_t *)&(ctx->c4tbl[1][0][0]);
606 ✗ uint32_t loop = param2 * 8;
607
608
0/4
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 5 not taken.
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 6 not taken.
✗ if ((param2 > 256) || (bytestream2_get_bytes_left(gb) < loop))
609 ✗ return AVERROR_INVALIDDATA;
610
611
0/2
✗ Branch 9 → 7 not taken.
✗ Branch 9 → 10 not taken.
✗ while (loop--) {
612 ✗ c = bytestream2_get_byteu(gb);
613 ✗ *dst++ = (c >> 4) + clr;
614 ✗ *dst++ = (c & 0xf) + clr;
615 }
616
617 ✗ return 0;
618 }
619
620 9 static void rotate_bufs(SANMVideoContext *ctx, int rotate_code)
621 {
622
2/2
✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 4 taken 8 times.
9 if (rotate_code == 2)
623 1 FFSWAP(uint16_t*, ctx->frm1, ctx->frm2);
624 9 FFSWAP(uint16_t*, ctx->frm2, ctx->frm0);
625 9 }
626
627 3 static av_cold int decode_init(AVCodecContext *avctx)
628 {
629 3 SANMVideoContext *ctx = avctx->priv_data;
630
631 3 ctx->avctx = avctx;
632 3 ctx->version = !avctx->extradata_size;
633 // early sanity check before allocations to avoid need for deallocation code.
634
1/4
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 6 taken 3 times.
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 6 not taken.
3 if (!ctx->version && avctx->extradata_size < 1026) {
635 ✗ av_log(avctx, AV_LOG_ERROR, "Not enough extradata.\n");
636 ✗ return AVERROR_INVALIDDATA;
637 }
638
639
1/2
✓ Branch 6 → 7 taken 3 times.
✗ Branch 6 → 8 not taken.
3 avctx->pix_fmt = ctx->version ? AV_PIX_FMT_RGB565 : AV_PIX_FMT_PAL8;
640
641
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 20 taken 3 times.
3 if (!ctx->version) {
642 // ANIM valid range is 2x2 up to 640x480. If the given
643 // width/height are within that range, lock the dimensions
644 // and forego future changes in process_frame_obj().
645 // NOTE: the smush demuxer passes 0/0 since ANM/SAN files
646 // have no dimension information in their header.
647
0/4
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 12 not taken.
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 19 not taken.
✗ if (avctx->width != 0 || avctx->height != 0) {
648
0/4
✗ Branch 12 → 13 not taken.
✗ Branch 12 → 14 not taken.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 15 not taken.
✗ if ((avctx->width < 2) || (avctx->height < 2))
649 ✗ return AVERROR_INVALIDDATA;
650
0/4
✗ Branch 15 → 16 not taken.
✗ Branch 15 → 18 not taken.
✗ Branch 16 → 17 not taken.
✗ Branch 16 → 18 not taken.
✗ if ((avctx->width <= 640) && (avctx->height <= 480))
651 ✗ ctx->have_dimensions = 1;
652 else
653 ✗ return AVERROR_INVALIDDATA;
654 }
655
2/4
✓ Branch 20 → 21 taken 3 times.
✗ Branch 20 → 24 not taken.
✓ Branch 21 → 22 taken 3 times.
✗ Branch 21 → 24 not taken.
3 } else if (avctx->width > 800 || avctx->height > 600 ||
656
2/4
✓ Branch 22 → 23 taken 3 times.
✗ Branch 22 → 24 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 3 times.
3 avctx->width < 8 || avctx->height < 8) {
657 // BL16 valid range is 8x8 - 800x600
658 ✗ return AVERROR_INVALIDDATA;
659 }
660 3 init_sizes(ctx, avctx->width, avctx->height);
661
1/2
✗ Branch 27 → 28 not taken.
✓ Branch 27 → 30 taken 3 times.
3 if (init_buffers(ctx)) {
662 ✗ av_log(avctx, AV_LOG_ERROR, "Error allocating buffers.\n");
663 ✗ return AVERROR(ENOMEM);
664 }
665
666 3 make_glyphs(ctx->p4x4glyphs[0], glyph4_x, glyph4_y, 4);
667 3 make_glyphs(ctx->p8x8glyphs[0], glyph8_x, glyph8_y, 8);
668
669
1/2
✗ Branch 32 → 33 not taken.
✓ Branch 32 → 38 taken 3 times.
3 if (!ctx->version) {
670 int i;
671
672 ✗ ctx->subversion = AV_RL16(avctx->extradata);
673
0/2
✗ Branch 35 → 34 not taken.
✗ Branch 35 → 36 not taken.
✗ for (i = 0; i < PALETTE_SIZE; i++)
674 ✗ ctx->pal[i] = 0xFFU << 24 | AV_RL32(avctx->extradata + 2 + i * 4);
675
0/2
✗ Branch 36 → 37 not taken.
✗ Branch 36 → 38 not taken.
✗ if (ctx->subversion < 2)
676 ✗ ctx->pal[0] = 0xFFU << 24;
677 }
678 3 ctx->c4param = 0xffff;
679
680 3 return 0;
681 }
682
683 3 static av_cold int decode_end(AVCodecContext *avctx)
684 {
685 3 SANMVideoContext *ctx = avctx->priv_data;
686
687 3 destroy_buffers(ctx);
688
689 3 return 0;
690 }
691
692 ✗ static int old_codec4(SANMVideoContext *ctx, GetByteContext *gb, int top, int left,
693 int w, int h, uint8_t param, uint16_t param2, int codec)
694 {
695 ✗ const uint16_t mx = ctx->width, my = ctx->height, p = ctx->pitch;
696 ✗ uint8_t mask, bits, idx, *gs, *dst = (uint8_t *)ctx->fbuf;
697 int i, j, k, l, bit, ret, x, y;
698
699
0/2
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 7 not taken.
✗ if (ctx->c4param != param) {
700
0/2
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✗ if (codec > 32)
701 ✗ codec33_gen_tiles(ctx, param);
702 else
703 ✗ codec4_gen_tiles(ctx, param);
704 ✗ ctx->c4param = param;
705 }
706
0/2
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 11 not taken.
✗ if (param2 > 0) {
707 ✗ ret = codec4_load_tiles(ctx, gb, param2, param);
708
0/2
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 11 not taken.
✗ if (ret)
709 ✗ return ret;
710 }
711
712
0/2
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 13 not taken.
✗ if (codec > 32)
713 ✗ codec -= 29;
714
715
0/2
✗ Branch 59 → 14 not taken.
✗ Branch 59 → 60 not taken.
✗ for (j = 0; j < w; j += 4) {
716 ✗ mask = bits = 0;
717 ✗ x = left + j;
718
0/2
✗ Branch 57 → 15 not taken.
✗ Branch 57 → 58 not taken.
✗ for (i = 0; i < h; i += 4) {
719 ✗ y = top + i;
720
0/2
✗ Branch 15 → 16 not taken.
✗ Branch 15 → 23 not taken.
✗ if (param2 > 0) {
721
0/2
✗ Branch 16 → 17 not taken.
✗ Branch 16 → 22 not taken.
✗ if (bits == 0) {
722
0/2
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 20 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 1)
723 ✗ return AVERROR_INVALIDDATA;
724 ✗ mask = bytestream2_get_byteu(gb);
725 ✗ bits = 8;
726 }
727 ✗ bit = !!(mask & 0x80);
728 ✗ mask <<= 1;
729 ✗ bits--;
730 } else {
731 ✗ bit = 0;
732 }
733
734
0/2
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 27 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 1)
735 ✗ return AVERROR_INVALIDDATA;
736 ✗ idx = bytestream2_get_byteu(gb);
737
0/6
✗ Branch 28 → 29 not taken.
✗ Branch 28 → 32 not taken.
✗ Branch 29 → 30 not taken.
✗ Branch 29 → 32 not taken.
✗ Branch 30 → 31 not taken.
✗ Branch 30 → 32 not taken.
✗ if ((bit == 0) && (idx == 0x80) && (codec != 5))
738 ✗ continue;
739
0/8
✗ Branch 32 → 33 not taken.
✗ Branch 32 → 36 not taken.
✗ Branch 33 → 34 not taken.
✗ Branch 33 → 36 not taken.
✗ Branch 34 → 35 not taken.
✗ Branch 34 → 36 not taken.
✗ Branch 35 → 36 not taken.
✗ Branch 35 → 37 not taken.
✗ if ((y >= my) || ((y + 4) < 0) || ((x + 4) < 0) || (x >= mx))
740 ✗ continue;
741 ✗ gs = &(ctx->c4tbl[bit][idx][0]);
742
0/8
✗ Branch 37 → 38 not taken.
✗ Branch 37 → 45 not taken.
✗ Branch 38 → 39 not taken.
✗ Branch 38 → 45 not taken.
✗ Branch 39 → 40 not taken.
✗ Branch 39 → 45 not taken.
✗ Branch 40 → 41 not taken.
✗ Branch 40 → 45 not taken.
✗ if ((y >= 0) && (x >= 0) && ((y + 4) < my) && ((x + 4) < mx)) {
743
0/2
✗ Branch 43 → 42 not taken.
✗ Branch 43 → 44 not taken.
✗ for (k = 0; k < 4; k++, gs += 4)
744 ✗ memcpy(dst + x + (y + k) * p, gs, 4);
745 } else {
746
0/2
✗ Branch 55 → 46 not taken.
✗ Branch 55 → 56 not taken.
✗ for (k = 0; k < 4; k++) {
747
0/2
✗ Branch 53 → 47 not taken.
✗ Branch 53 → 54 not taken.
✗ for (l = 0; l < 4; l++, gs++) {
748 ✗ const int yo = y + k, xo = x + l;
749
0/8
✗ Branch 47 → 48 not taken.
✗ Branch 47 → 52 not taken.
✗ Branch 48 → 49 not taken.
✗ Branch 48 → 52 not taken.
✗ Branch 49 → 50 not taken.
✗ Branch 49 → 52 not taken.
✗ Branch 50 → 51 not taken.
✗ Branch 50 → 52 not taken.
✗ if ((yo >= 0) && (yo < my) && (xo >= 0) && (xo < mx))
750 ✗ *(dst + yo * p + xo) = *gs;
751 }
752 }
753 }
754 }
755 }
756 ✗ return 0;
757 }
758
759 1 static int rle_decode(SANMVideoContext *ctx, GetByteContext *gb, uint8_t *dst, const int out_size)
760 {
761 1 int opcode, color, run_len, left = out_size;
762
763
2/2
✓ Branch 16 → 3 taken 4800 times.
✓ Branch 16 → 17 taken 1 time.
4801 while (left > 0) {
764 4800 opcode = bytestream2_get_byte(gb);
765 4800 run_len = (opcode >> 1) + 1;
766
2/4
✓ Branch 4 → 5 taken 4800 times.
✗ Branch 4 → 7 not taken.
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 4800 times.
4800 if (run_len > left || bytestream2_get_bytes_left(gb) <= 0)
767 ✗ return AVERROR_INVALIDDATA;
768
769
1/2
✓ Branch 8 → 9 taken 4800 times.
✗ Branch 8 → 11 not taken.
4800 if (opcode & 1) {
770 4800 color = bytestream2_get_byte(gb);
771 4800 memset(dst, color, run_len);
772 } else {
773
0/2
✗ Branch 12 → 13 not taken.
✗ Branch 12 → 14 not taken.
✗ if (bytestream2_get_bytes_left(gb) < run_len)
774 ✗ return AVERROR_INVALIDDATA;
775 ✗ bytestream2_get_bufferu(gb, dst, run_len);
776 }
777
778 4800 dst += run_len;
779 4800 left -= run_len;
780 }
781
782 1 return 0;
783 }
784
785 ✗ static int old_codec23(SANMVideoContext *ctx, GetByteContext *gb, int top, int left,
786 int width, int height, uint8_t param, uint16_t param2)
787 {
788 ✗ const uint16_t mx = ctx->width, my = ctx->height, p = ctx->pitch;
789 ✗ uint8_t c, lut[256], *dst = (uint8_t *)ctx->fbuf;
790 int sk, i, j, ls, pc, y;
791
792
0/2
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 6 not taken.
✗ if (ctx->subversion < 2) {
793 /* Rebel Assault 1: constant offset + 0xd0 */
794
0/2
✗ Branch 5 → 4 not taken.
✗ Branch 5 → 17 not taken.
✗ for (i = 0; i < sizeof(lut); i++)
795 ✗ lut[i] = (i + param + 0xd0) & 0xff;
796
0/2
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 12 not taken.
✗ } else if (param2 == 256) {
797
0/2
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 10 not taken.
✗ if (bytestream2_get_bytes_left(gb) < sizeof(ctx->c23lut))
798 ✗ return AVERROR_INVALIDDATA;
799 ✗ bytestream2_get_bufferu(gb, ctx->c23lut, sizeof(ctx->c23lut));
800 ✗ memcpy(lut, ctx->c23lut, sizeof(lut));
801
0/2
✗ Branch 12 → 13 not taken.
✗ Branch 12 → 16 not taken.
✗ } else if (param2 < 256) {
802
0/2
✗ Branch 15 → 14 not taken.
✗ Branch 15 → 17 not taken.
✗ for (i = 0; i < sizeof(lut); i++)
803 ✗ lut[i] = (i + param2) & 0xff;
804 } else {
805 ✗ memcpy(lut, ctx->c23lut, sizeof(lut));
806 }
807
0/2
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 20 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 1)
808 ✗ return 0; /* some c23 frames just set up the LUT */
809
810
0/8
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 24 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 24 not taken.
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 24 not taken.
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 25 not taken.
✗ if (((top + height) < 0) || (top >= my) || (left + width < 0) || (left >= mx))
811 ✗ return 0;
812
813
0/2
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 36 not taken.
✗ if (top < 0) {
814 ✗ y = -top;
815
0/4
✗ Branch 32 → 33 not taken.
✗ Branch 32 → 35 not taken.
✗ Branch 34 → 27 not taken.
✗ Branch 34 → 35 not taken.
✗ while (y-- && bytestream2_get_bytes_left(gb) > 1) {
816 ✗ ls = bytestream2_get_le16u(gb);
817
0/2
✗ Branch 29 → 30 not taken.
✗ Branch 29 → 31 not taken.
✗ if (bytestream2_get_bytes_left(gb) < ls)
818 ✗ return AVERROR_INVALIDDATA;
819 ✗ bytestream2_skip(gb, ls);
820 }
821 ✗ height += top;
822 ✗ top = 0;
823 }
824
825 ✗ y = top;
826
0/6
✗ Branch 58 → 59 not taken.
✗ Branch 58 → 61 not taken.
✗ Branch 59 → 60 not taken.
✗ Branch 59 → 61 not taken.
✗ Branch 60 → 37 not taken.
✗ Branch 60 → 61 not taken.
✗ for (; (bytestream2_get_bytes_left(gb) > 1) && (height > 0) && (y < my); height--, y++) {
827 ✗ ls = bytestream2_get_le16u(gb);
828 ✗ sk = 1;
829 ✗ pc = left;
830
0/6
✗ Branch 53 → 54 not taken.
✗ Branch 53 → 56 not taken.
✗ Branch 54 → 55 not taken.
✗ Branch 54 → 56 not taken.
✗ Branch 55 → 39 not taken.
✗ Branch 55 → 56 not taken.
✗ while ((bytestream2_get_bytes_left(gb) > 0) && (ls > 0) && (pc <= (width + left))) {
831 ✗ j = bytestream2_get_byteu(gb);
832 ✗ ls--;
833
0/2
✗ Branch 40 → 41 not taken.
✗ Branch 40 → 49 not taken.
✗ if (!sk) {
834
0/2
✗ Branch 48 → 42 not taken.
✗ Branch 48 → 51 not taken.
✗ while (j--) {
835
0/4
✗ Branch 42 → 43 not taken.
✗ Branch 42 → 45 not taken.
✗ Branch 43 → 44 not taken.
✗ Branch 43 → 45 not taken.
✗ if ((pc >= 0) && (pc < mx)) {
836 ✗ c = *(dst + (y * p) + pc);
837 ✗ *(dst + (y * p) + pc) = lut[c];
838 }
839
0/2
✗ Branch 45 → 46 not taken.
✗ Branch 45 → 47 not taken.
✗ if (pc < mx)
840 ✗ pc++;
841 }
842 } else {
843
0/2
✗ Branch 49 → 50 not taken.
✗ Branch 49 → 51 not taken.
✗ if (pc < mx)
844 ✗ pc += j;
845 }
846 ✗ sk ^= 1;
847 }
848 }
849 ✗ return 0;
850 }
851
852 ✗ static int old_codec21(SANMVideoContext *ctx, GetByteContext *gb, int top, int left,
853 int width, int height)
854 {
855 ✗ const uint16_t mx = ctx->width, my = ctx->height, p = ctx->pitch;
856 ✗ uint8_t *dst = (uint8_t *)ctx->fbuf, c;
857 int j, y, pc, sk, ls;
858
859
0/8
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 6 not taken.
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 6 not taken.
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 6 not taken.
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 7 not taken.
✗ if (((top + height) < 0) || (top >= my) || (left + width < 0) || (left >= mx))
860 ✗ return 0;
861
862 ✗ y = top;
863
0/6
✗ Branch 39 → 40 not taken.
✗ Branch 39 → 42 not taken.
✗ Branch 40 → 41 not taken.
✗ Branch 40 → 42 not taken.
✗ Branch 41 → 8 not taken.
✗ Branch 41 → 42 not taken.
✗ for (; (bytestream2_get_bytes_left(gb) > 2) && (height > 0) && (y < my); height--, y++) {
864 ✗ ls = bytestream2_get_le16u(gb);
865
0/2
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 15 not taken.
✗ if (y < 0) {
866
0/2
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 13 not taken.
✗ if (ls >= bytestream2_get_bytes_left(gb))
867 ✗ return 0;
868 ✗ bytestream2_skip(gb, ls);
869 ✗ continue;
870 }
871 ✗ sk = 1;
872 ✗ pc = left;
873
0/6
✗ Branch 34 → 35 not taken.
✗ Branch 34 → 37 not taken.
✗ Branch 35 → 36 not taken.
✗ Branch 35 → 37 not taken.
✗ Branch 36 → 16 not taken.
✗ Branch 36 → 37 not taken.
✗ while ((bytestream2_get_bytes_left(gb) > 1) && (ls > 1) && (pc <= (width + left))) {
874 ✗ j = bytestream2_get_le16u(gb);
875 ✗ ls -= 2;
876
0/2
✗ Branch 17 → 18 not taken.
✗ Branch 17 → 20 not taken.
✗ if (sk) {
877
0/2
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 32 not taken.
✗ if (pc < mx)
878 ✗ pc += j;
879 } else {
880
0/6
✗ Branch 29 → 30 not taken.
✗ Branch 29 → 32 not taken.
✗ Branch 30 → 31 not taken.
✗ Branch 30 → 32 not taken.
✗ Branch 31 → 21 not taken.
✗ Branch 31 → 32 not taken.
✗ while ((bytestream2_get_bytes_left(gb) > 0) && (ls > 0) && (j >= 0)) {
881 ✗ c = bytestream2_get_byteu(gb);
882
0/4
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 25 not taken.
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 25 not taken.
✗ if ((pc >= 0) && (pc < mx)) {
883 ✗ *(dst + (y * p) + pc) = c;
884 }
885 ✗ ls--;
886 ✗ j--;
887
0/2
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 27 not taken.
✗ if (pc < mx)
888 ✗ pc++;
889 }
890 }
891 ✗ sk ^= 1;
892 }
893 }
894 ✗ return 0;
895 }
896
897 ✗ static int old_codec1(SANMVideoContext *ctx, GetByteContext *gb, int top,
898 int left, int width, int height, int opaque)
899 {
900 ✗ const uint16_t mx = ctx->width, my = ctx->height, p = ctx->pitch;
901 ✗ uint8_t *dst = (uint8_t *)ctx->fbuf, code, c;
902 int j, x, y, flag, dlen;
903
904
0/8
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 6 not taken.
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 6 not taken.
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 6 not taken.
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 7 not taken.
✗ if (((top + height) < 0) || (top >= my) || (left + width < 0) || (left >= mx))
905 ✗ return 0;
906
907
0/2
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 18 not taken.
✗ if (top < 0) {
908 ✗ y = -top;
909
0/4
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 17 not taken.
✗ Branch 16 → 9 not taken.
✗ Branch 16 → 17 not taken.
✗ while (y-- && bytestream2_get_bytes_left(gb) > 1) {
910 ✗ dlen = bytestream2_get_le16u(gb);
911
0/2
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 13 not taken.
✗ if (bytestream2_get_bytes_left(gb) <= dlen)
912 ✗ return AVERROR_INVALIDDATA;
913 ✗ bytestream2_skip(gb, dlen);
914 }
915 ✗ height += top;
916 ✗ top = 0;
917 }
918
919 ✗ y = top;
920
0/6
✗ Branch 59 → 60 not taken.
✗ Branch 59 → 62 not taken.
✗ Branch 60 → 61 not taken.
✗ Branch 60 → 62 not taken.
✗ Branch 61 → 19 not taken.
✗ Branch 61 → 62 not taken.
✗ for (; (bytestream2_get_bytes_left(gb) > 1) && (height > 0) && (y < my); height--, y++) {
921 ✗ dlen = bytestream2_get_le16u(gb);
922 ✗ x = left;
923
0/4
✗ Branch 55 → 56 not taken.
✗ Branch 55 → 57 not taken.
✗ Branch 56 → 21 not taken.
✗ Branch 56 → 57 not taken.
✗ while (bytestream2_get_bytes_left(gb) > 1 && dlen) {
924 ✗ code = bytestream2_get_byteu(gb);
925 ✗ dlen--;
926 ✗ flag = code & 1;
927 ✗ code = (code >> 1) + 1;
928
0/2
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 38 not taken.
✗ if (flag) {
929 ✗ c = bytestream2_get_byteu(gb);
930 ✗ dlen--;
931
0/2
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 26 not taken.
✗ if (x >= mx)
932 ✗ continue;
933
0/2
✗ Branch 26 → 27 not taken.
✗ Branch 26 → 28 not taken.
✗ if (x < 0) {
934 ✗ int dff = FFMIN(-x, code);
935 ✗ code -= dff;
936 ✗ x += dff;
937 }
938
0/2
✗ Branch 28 → 29 not taken.
✗ Branch 28 → 30 not taken.
✗ if (x + code >= mx)
939 ✗ code = mx - x;
940
0/2
✗ Branch 30 → 31 not taken.
✗ Branch 30 → 32 not taken.
✗ if (code < 1)
941 ✗ continue;
942
0/6
✗ Branch 34 → 35 not taken.
✗ Branch 34 → 37 not taken.
✗ Branch 35 → 33 not taken.
✗ Branch 35 → 36 not taken.
✗ Branch 36 → 33 not taken.
✗ Branch 36 → 37 not taken.
✗ for (j = 0; (j < code) && (c || opaque); j++) {
943 ✗ *(dst + (y * p) + x + j) = c;
944 }
945 ✗ x += code;
946 } else {
947
0/2
✗ Branch 39 → 40 not taken.
✗ Branch 39 → 41 not taken.
✗ if (bytestream2_get_bytes_left(gb) < code)
948 ✗ return AVERROR_INVALIDDATA;
949
0/2
✗ Branch 51 → 42 not taken.
✗ Branch 51 → 52 not taken.
✗ for (j = 0; j < code; j++) {
950 ✗ c = bytestream2_get_byteu(gb);
951
0/8
✗ Branch 43 → 44 not taken.
✗ Branch 43 → 48 not taken.
✗ Branch 44 → 45 not taken.
✗ Branch 44 → 48 not taken.
✗ Branch 45 → 46 not taken.
✗ Branch 45 → 47 not taken.
✗ Branch 46 → 47 not taken.
✗ Branch 46 → 48 not taken.
✗ if ((x >= 0) && (x < mx) && (c || opaque))
952 ✗ *(dst + (y * p) + x) = c;
953
0/2
✗ Branch 48 → 49 not taken.
✗ Branch 48 → 50 not taken.
✗ if (x < mx)
954 ✗ x++;
955 }
956 ✗ dlen -= code;
957 }
958 }
959 }
960
961 ✗ return 0;
962 }
963
964 ✗ static int old_codec31(SANMVideoContext *ctx, GetByteContext *gb, int top,
965 int left, int width, int height, int p1, int opaque)
966 {
967 ✗ const uint16_t mx = ctx->width, my = ctx->height, p = ctx->pitch;
968 ✗ uint8_t *dst = (uint8_t *)ctx->fbuf, c;
969 int j, x, y, flag, dlen, code;
970
971
0/8
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 6 not taken.
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 6 not taken.
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 6 not taken.
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 7 not taken.
✗ if (((top + height) < 0) || (top >= my) || (left + width < 0) || (left >= mx))
972 ✗ return 0;
973
974
0/2
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 18 not taken.
✗ if (top < 0) {
975 ✗ y = -top;
976
0/4
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 17 not taken.
✗ Branch 16 → 9 not taken.
✗ Branch 16 → 17 not taken.
✗ while (y-- && bytestream2_get_bytes_left(gb) > 1) {
977 ✗ dlen = bytestream2_get_le16u(gb);
978
0/2
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 13 not taken.
✗ if (bytestream2_get_bytes_left(gb) <= dlen)
979 ✗ return AVERROR_INVALIDDATA;
980 ✗ bytestream2_skip(gb, dlen);
981 }
982 ✗ height += top;
983 ✗ top = 0;
984 }
985
986 ✗ y = top;
987
0/6
✗ Branch 69 → 70 not taken.
✗ Branch 69 → 72 not taken.
✗ Branch 70 → 71 not taken.
✗ Branch 70 → 72 not taken.
✗ Branch 71 → 19 not taken.
✗ Branch 71 → 72 not taken.
✗ for (; (bytestream2_get_bytes_left(gb) > 1) && (height > 0) && (y < my); height--, y++) {
988 ✗ dlen = bytestream2_get_le16u(gb);
989 ✗ x = left;
990
0/4
✗ Branch 65 → 66 not taken.
✗ Branch 65 → 67 not taken.
✗ Branch 66 → 21 not taken.
✗ Branch 66 → 67 not taken.
✗ while (bytestream2_get_bytes_left(gb) > 1 && dlen) {
991 ✗ code = bytestream2_get_byteu(gb);
992 ✗ dlen--;
993 ✗ flag = code & 1;
994 ✗ code = (code >> 1) + 1;
995
0/2
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 41 not taken.
✗ if (flag) {
996 ✗ c = bytestream2_get_byteu(gb);
997 ✗ dlen--;
998
0/2
✗ Branch 40 → 25 not taken.
✗ Branch 40 → 63 not taken.
✗ for (j = 0; (j < code); j++) {
999
0/8
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 27 not taken.
✗ Branch 26 → 27 not taken.
✗ Branch 26 → 30 not taken.
✗ Branch 27 → 28 not taken.
✗ Branch 27 → 30 not taken.
✗ Branch 28 → 29 not taken.
✗ Branch 28 → 30 not taken.
✗ if ((opaque || (c & 0xf)) && (x >= 0) && (x < mx))
1000 ✗ *(dst + (y * p) + x) = p1 + (c & 0xf);
1001
0/2
✗ Branch 30 → 31 not taken.
✗ Branch 30 → 32 not taken.
✗ if (x < mx)
1002 ✗ x++;
1003
0/8
✗ Branch 32 → 33 not taken.
✗ Branch 32 → 34 not taken.
✗ Branch 33 → 34 not taken.
✗ Branch 33 → 37 not taken.
✗ Branch 34 → 35 not taken.
✗ Branch 34 → 37 not taken.
✗ Branch 35 → 36 not taken.
✗ Branch 35 → 37 not taken.
✗ if ((opaque || (c >> 4)) && (x >= 0) && (x < mx))
1004 ✗ *(dst + (y * p) + x) = p1 + (c >> 4);
1005
0/2
✗ Branch 37 → 38 not taken.
✗ Branch 37 → 39 not taken.
✗ if (x < mx)
1006 ✗ x++;
1007 }
1008 } else {
1009
0/2
✗ Branch 42 → 43 not taken.
✗ Branch 42 → 44 not taken.
✗ if (bytestream2_get_bytes_left(gb) < code)
1010 ✗ return AVERROR_INVALIDDATA;
1011
0/2
✗ Branch 61 → 45 not taken.
✗ Branch 61 → 62 not taken.
✗ for (j = 0; j < code; j++) {
1012 ✗ c = bytestream2_get_byteu(gb);
1013
0/8
✗ Branch 46 → 47 not taken.
✗ Branch 46 → 48 not taken.
✗ Branch 47 → 48 not taken.
✗ Branch 47 → 51 not taken.
✗ Branch 48 → 49 not taken.
✗ Branch 48 → 51 not taken.
✗ Branch 49 → 50 not taken.
✗ Branch 49 → 51 not taken.
✗ if ((opaque || (c & 0xf)) && (x >= 0) && (x < mx))
1014 ✗ *(dst + (y * p) + x) = p1 + (c & 0xf);
1015
0/2
✗ Branch 51 → 52 not taken.
✗ Branch 51 → 53 not taken.
✗ if (x < mx)
1016 ✗ x++;
1017
0/8
✗ Branch 53 → 54 not taken.
✗ Branch 53 → 55 not taken.
✗ Branch 54 → 55 not taken.
✗ Branch 54 → 58 not taken.
✗ Branch 55 → 56 not taken.
✗ Branch 55 → 58 not taken.
✗ Branch 56 → 57 not taken.
✗ Branch 56 → 58 not taken.
✗ if ((opaque || (c >> 4)) && (x >= 0) && (x < mx))
1018 ✗ *(dst + (y * p) + x) = p1 + (c >> 4);
1019
0/2
✗ Branch 58 → 59 not taken.
✗ Branch 58 → 60 not taken.
✗ if (x < mx)
1020 ✗ x++;
1021 }
1022 ✗ dlen -= code;
1023 }
1024 }
1025 }
1026
1027 ✗ return 0;
1028 }
1029
1030 ✗ static int old_codec2(SANMVideoContext *ctx, GetByteContext *gb, int top,
1031 int left, int width, int height)
1032 {
1033 ✗ uint8_t *dst = (uint8_t *)ctx->fbuf, col;
1034 ✗ int16_t xpos = left, ypos = top;
1035
1036
0/2
✗ Branch 13 → 3 not taken.
✗ Branch 13 → 14 not taken.
✗ while (bytestream2_get_bytes_left(gb) > 3) {
1037 ✗ xpos += bytestream2_get_le16u(gb);
1038 ✗ ypos += bytestream2_get_byteu(gb);
1039 ✗ col = bytestream2_get_byteu(gb);
1040
0/4
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 11 not taken.
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 11 not taken.
✗ if (xpos >= 0 && ypos >= 0 &&
1041
0/4
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 11 not taken.
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 11 not taken.
✗ xpos < ctx->width && ypos < ctx->height) {
1042 ✗ *(dst + xpos + ypos * ctx->pitch) = col;
1043 }
1044 }
1045 ✗ return 0;
1046 }
1047
1048 ✗ static void blt_solid(uint8_t *dst, const uint8_t *src, int16_t left, int16_t top,
1049 uint16_t srcxoff, uint16_t srcyoff, uint16_t srcwidth,
1050 uint16_t srcheight, const uint16_t srcpitch, const uint16_t dstpitch,
1051 const uint16_t dstheight, int32_t size)
1052 {
1053
0/6
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 5 not taken.
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 6 not taken.
✗ if ((srcwidth < 1) || (srcheight < 1) || (size < 1))
1054 ✗ return;
1055
1056
0/2
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 10 not taken.
✗ if (top < 0) {
1057
0/2
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 9 not taken.
✗ if (-top >= srcheight)
1058 ✗ return;
1059 ✗ srcyoff -= top;
1060 ✗ srcheight += top;
1061 ✗ size += (srcpitch * top);
1062 ✗ top = 0;
1063 }
1064
1065
0/2
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 14 not taken.
✗ if ((top + srcheight) > dstheight) {
1066 ✗ int clip = (top + srcheight) - dstheight;
1067
0/2
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 13 not taken.
✗ if (clip >= srcheight)
1068 ✗ return;
1069 ✗ srcheight -= clip;
1070 }
1071
1072
0/2
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 18 not taken.
✗ if (left < 0) {
1073
0/2
✗ Branch 15 → 16 not taken.
✗ Branch 15 → 17 not taken.
✗ if (-left >= srcwidth)
1074 ✗ return;
1075 ✗ srcxoff -= left;
1076 ✗ srcwidth += left;
1077 ✗ size += left;
1078 ✗ left = 0;
1079 }
1080
1081
0/2
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 22 not taken.
✗ if (left + srcwidth > dstpitch) {
1082 ✗ int clip = (left + srcwidth) - dstpitch;
1083
0/2
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 21 not taken.
✗ if (clip >= srcwidth)
1084 ✗ return;
1085 ✗ srcwidth -= clip;
1086 }
1087
1088 ✗ src += ((uintptr_t)srcyoff * srcpitch) + srcxoff;
1089 ✗ dst += ((uintptr_t)top * dstpitch) + left;
1090
0/4
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 26 not taken.
✗ Branch 25 → 23 not taken.
✗ Branch 25 → 26 not taken.
✗ while ((srcheight--) && (size >= srcwidth)) {
1091 ✗ memcpy(dst, src, srcwidth);
1092 ✗ src += srcpitch;
1093 ✗ dst += dstpitch;
1094 ✗ size -= srcpitch;
1095 }
1096
0/6
✗ Branch 26 → 27 not taken.
✗ Branch 26 → 30 not taken.
✗ Branch 27 → 28 not taken.
✗ Branch 27 → 30 not taken.
✗ Branch 28 → 29 not taken.
✗ Branch 28 → 30 not taken.
✗ if ((size > 0) && (size < srcwidth) && (srcheight > 0))
1097 ✗ memcpy(dst, src, size);
1098 }
1099
1100 ✗ static void blt_mask(uint8_t *dst, const uint8_t *src, int16_t left, int16_t top,
1101 uint16_t srcxoff, uint16_t srcyoff, uint16_t srcwidth,
1102 uint16_t srcheight, const uint16_t srcpitch, const uint16_t dstpitch,
1103 const uint16_t dstheight, int32_t size, const uint8_t skipcolor)
1104 {
1105
0/6
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 5 not taken.
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 6 not taken.
✗ if ((srcwidth < 1) || (srcheight < 1) || (size < 1))
1106 ✗ return;
1107
1108
0/2
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 10 not taken.
✗ if (top < 0) {
1109
0/2
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 9 not taken.
✗ if (-top >= srcheight)
1110 ✗ return;
1111 ✗ srcyoff -= top;
1112 ✗ srcheight += top;
1113 ✗ size += (srcpitch * top);
1114 ✗ top = 0;
1115 }
1116
1117
0/2
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 14 not taken.
✗ if ((top + srcheight) > dstheight) {
1118 ✗ int clip = (top + srcheight) - dstheight;
1119
0/2
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 13 not taken.
✗ if (clip >= srcheight)
1120 ✗ return;
1121 ✗ srcheight -= clip;
1122 }
1123
1124
0/2
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 18 not taken.
✗ if (left < 0) {
1125
0/2
✗ Branch 15 → 16 not taken.
✗ Branch 15 → 17 not taken.
✗ if (-left >= srcwidth)
1126 ✗ return;
1127 ✗ srcxoff -= left;
1128 ✗ srcwidth += left;
1129 ✗ size += left;
1130 ✗ left = 0;
1131 }
1132
1133
0/2
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 22 not taken.
✗ if (left + srcwidth > dstpitch) {
1134 ✗ int clip = (left + srcwidth) - dstpitch;
1135
0/2
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 21 not taken.
✗ if (clip >= srcwidth)
1136 ✗ return;
1137 ✗ srcwidth -= clip;
1138 }
1139
1140 ✗ src += ((uintptr_t)srcyoff * srcpitch) + srcxoff;
1141 ✗ dst += ((uintptr_t)top * dstpitch) + left;
1142
0/4
✗ Branch 30 → 31 not taken.
✗ Branch 30 → 32 not taken.
✗ Branch 31 → 23 not taken.
✗ Branch 31 → 32 not taken.
✗ for (int i = 0; (size > 0) && (i < srcheight); i++) {
1143
0/4
✗ Branch 27 → 28 not taken.
✗ Branch 27 → 29 not taken.
✗ Branch 28 → 24 not taken.
✗ Branch 28 → 29 not taken.
✗ for (int j = 0; (size > 0) && (j < srcwidth); j++, size--) {
1144
0/2
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 26 not taken.
✗ if (src[j] != skipcolor)
1145 ✗ dst[j] = src[j];
1146 }
1147 ✗ src += srcpitch;
1148 ✗ dst += dstpitch;
1149 }
1150 }
1151
1152 ✗ static void blt_ipol(uint8_t *dst, const uint8_t *src1, const uint8_t *src2,
1153 int16_t left, int16_t top, uint16_t srcxoff, uint16_t srcyoff,
1154 uint16_t srcwidth, uint16_t srcheight, const uint16_t srcpitch,
1155 const uint16_t dstpitch, const uint16_t dstheight, int32_t size,
1156 const uint8_t *itbl)
1157 {
1158
0/6
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 5 not taken.
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 6 not taken.
✗ if ((srcwidth < 1) || (srcheight < 1) || (size < 1))
1159 ✗ return;
1160
1161
0/2
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 10 not taken.
✗ if (top < 0) {
1162
0/2
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 9 not taken.
✗ if (-top >= srcheight)
1163 ✗ return;
1164 ✗ srcyoff -= top;
1165 ✗ srcheight += top;
1166 ✗ size += (srcpitch * top);
1167 ✗ top = 0;
1168 }
1169
1170
0/2
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 14 not taken.
✗ if ((top + srcheight) > dstheight) {
1171 ✗ int clip = (top + srcheight) - dstheight;
1172
0/2
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 13 not taken.
✗ if (clip >= srcheight)
1173 ✗ return;
1174 ✗ srcheight -= clip;
1175 }
1176
1177
0/2
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 18 not taken.
✗ if (left < 0) {
1178
0/2
✗ Branch 15 → 16 not taken.
✗ Branch 15 → 17 not taken.
✗ if (-left >= srcwidth)
1179 ✗ return;
1180 ✗ srcxoff -= left;
1181 ✗ srcwidth += left;
1182 ✗ size += left;
1183 ✗ left = 0;
1184 }
1185
1186
0/2
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 22 not taken.
✗ if (left + srcwidth > dstpitch) {
1187 ✗ int clip = (left + srcwidth) - dstpitch;
1188
0/2
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 21 not taken.
✗ if (clip >= srcwidth)
1189 ✗ return;
1190 ✗ srcwidth -= clip;
1191 }
1192
1193 ✗ src1 += ((uintptr_t)srcyoff * srcpitch) + srcxoff;
1194 ✗ src2 += ((uintptr_t)srcyoff * srcpitch) + srcxoff;
1195 ✗ dst += ((uintptr_t)top * dstpitch) + left;
1196
0/4
✗ Branch 28 → 29 not taken.
✗ Branch 28 → 30 not taken.
✗ Branch 29 → 23 not taken.
✗ Branch 29 → 30 not taken.
✗ for (int i = 0; (size > 0) && (i < srcheight); i++) {
1197
0/4
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 27 not taken.
✗ Branch 26 → 24 not taken.
✗ Branch 26 → 27 not taken.
✗ for (int j = 0; (size > 0) && (j < srcwidth); j++, size--) {
1198 ✗ dst[j] = itbl[(src1[j] << 8) | src2[j]];
1199 }
1200 ✗ src1 += srcpitch;
1201 ✗ src2 += srcpitch;
1202 ✗ dst += dstpitch;
1203 }
1204 }
1205
1206 ✗ static int old_codec20(SANMVideoContext *ctx, GetByteContext *gb, int top, int left,
1207 const int w, const int h)
1208 {
1209 ✗ blt_solid((uint8_t*)ctx->fbuf, gb->buffer, left, top, 0, 0, w, h, w, ctx->pitch,
1210
0/2
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✗ ctx->height, FFMIN(bytestream2_get_bytes_left(gb), w * h));
1211
1212 ✗ return 0;
1213 }
1214
1215 ✗ static inline void codec37_mv(uint8_t *dst, const uint8_t *src,
1216 int height, int stride, int x, int y)
1217 {
1218 int pos, i, j;
1219
1220 ✗ pos = x + y * stride;
1221
0/2
✗ Branch 11 → 3 not taken.
✗ Branch 11 → 12 not taken.
✗ for (j = 0; j < 4; j++) {
1222
0/2
✗ Branch 9 → 4 not taken.
✗ Branch 9 → 10 not taken.
✗ for (i = 0; i < 4; i++) {
1223
0/4
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 6 not taken.
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 7 not taken.
✗ if ((pos + i) < 0 || (pos + i) >= height * stride)
1224 ✗ dst[i] = 0;
1225 else
1226 ✗ dst[i] = src[i];
1227 }
1228 ✗ dst += stride;
1229 ✗ src += stride;
1230 ✗ pos += stride;
1231 }
1232 ✗ }
1233
1234 ✗ static int old_codec37(SANMVideoContext *ctx, GetByteContext *gb, int top, int left,
1235 int width, int height)
1236 {
1237 int i, j, k, l, t, run, len, code, skip, mx, my;
1238 uint8_t *dst, *prev;
1239 ✗ int skip_run = 0;
1240
1241 ✗ width = FFALIGN(width, 4);
1242
0/2
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 4 not taken.
✗ if (width > ctx->aligned_width)
1243 ✗ return AVERROR_INVALIDDATA;
1244
1245
0/2
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 6 not taken.
✗ if (FFALIGN(height, 4) > ctx->aligned_height)
1246 ✗ return AVERROR_INVALIDDATA;
1247
1248
0/2
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 9 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 16)
1249 ✗ return AVERROR_INVALIDDATA;
1250
1251 ✗ int compr = bytestream2_get_byteu(gb);
1252 ✗ int mvoff = bytestream2_get_byteu(gb);
1253 ✗ int seq = bytestream2_get_le16u(gb);
1254 ✗ uint32_t decoded_size = bytestream2_get_le32u(gb);
1255 int flags;
1256
1257 ✗ bytestream2_skip(gb, 4);
1258 ✗ flags = bytestream2_get_byteu(gb);
1259 ✗ bytestream2_skip(gb, 3);
1260
1261
0/2
✗ Branch 16 → 17 not taken.
✗ Branch 16 → 18 not taken.
✗ if (decoded_size > height * width) {
1262 ✗ decoded_size = height * width;
1263 ✗ av_log(ctx->avctx, AV_LOG_WARNING, "Decoded size is too large.\n");
1264 }
1265
1266
0/8
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 20 not taken.
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 23 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 23 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 23 not taken.
✗ if (((seq & 1) || !(flags & 1)) && (compr && compr != 2)) {
1267 ✗ FFSWAP(uint16_t*, ctx->frm0, ctx->frm2);
1268 }
1269
1270 ✗ dst = ((uint8_t*)ctx->frm0);
1271 ✗ prev = ((uint8_t*)ctx->frm2);
1272
1273
0/2
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 26 not taken.
✗ if (mvoff > 2) {
1274 ✗ av_log(ctx->avctx, AV_LOG_ERROR, "Invalid motion base value %d.\n", mvoff);
1275 ✗ return AVERROR_INVALIDDATA;
1276 }
1277
1278
0/5
✗ Branch 26 → 27 not taken.
✗ Branch 26 → 32 not taken.
✗ Branch 26 → 78 not taken.
✗ Branch 26 → 82 not taken.
✗ Branch 26 → 136 not taken.
✗ switch (compr) {
1279 ✗ case 0:
1280
0/2
✗ Branch 28 → 29 not taken.
✗ Branch 28 → 30 not taken.
✗ if (bytestream2_get_bytes_left(gb) < width * height)
1281 ✗ return AVERROR_INVALIDDATA;
1282 ✗ bytestream2_get_bufferu(gb, dst, width * height);
1283 ✗ memset(ctx->frm2, 0, ctx->frm2_size);
1284 ✗ break;
1285 ✗ case 1:
1286 ✗ run = 0;
1287 ✗ len = -1;
1288 ✗ code = 0;
1289
1290
0/2
✗ Branch 76 → 33 not taken.
✗ Branch 76 → 77 not taken.
✗ for (j = 0; j < height; j += 4) {
1291
0/2
✗ Branch 74 → 34 not taken.
✗ Branch 74 → 75 not taken.
✗ for (i = 0; i < width; i += 4) {
1292
0/2
✗ Branch 34 → 35 not taken.
✗ Branch 34 → 40 not taken.
✗ if (len < 0) {
1293
0/2
✗ Branch 36 → 37 not taken.
✗ Branch 36 → 38 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 1)
1294 ✗ return AVERROR_INVALIDDATA;
1295 ✗ code = bytestream2_get_byte(gb);
1296 ✗ len = code >> 1;
1297 ✗ run = code & 1;
1298 ✗ skip = 0;
1299 } else {
1300 ✗ skip = run;
1301 }
1302
1303
0/2
✗ Branch 41 → 42 not taken.
✗ Branch 41 → 71 not taken.
✗ if (!skip) {
1304
0/2
✗ Branch 43 → 44 not taken.
✗ Branch 43 → 45 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 1)
1305 ✗ return AVERROR_INVALIDDATA;
1306 ✗ code = bytestream2_get_byte(gb);
1307
0/2
✗ Branch 46 → 47 not taken.
✗ Branch 46 → 71 not taken.
✗ if (code == 0xff) {
1308 ✗ len--;
1309
0/2
✗ Branch 69 → 48 not taken.
✗ Branch 69 → 70 not taken.
✗ for (k = 0; k < 4; k++) {
1310
0/2
✗ Branch 67 → 49 not taken.
✗ Branch 67 → 68 not taken.
✗ for (l = 0; l < 4; l++) {
1311
0/2
✗ Branch 49 → 50 not taken.
✗ Branch 49 → 60 not taken.
✗ if (len < 0) {
1312
0/2
✗ Branch 51 → 52 not taken.
✗ Branch 51 → 53 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 1)
1313 ✗ return AVERROR_INVALIDDATA;
1314 ✗ code = bytestream2_get_byte(gb);
1315 ✗ len = code >> 1;
1316 ✗ run = code & 1;
1317
0/2
✗ Branch 54 → 55 not taken.
✗ Branch 54 → 60 not taken.
✗ if (run) {
1318
0/2
✗ Branch 56 → 57 not taken.
✗ Branch 56 → 58 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 1)
1319 ✗ return AVERROR_INVALIDDATA;
1320 ✗ code = bytestream2_get_byte(gb);
1321 }
1322 }
1323
0/2
✗ Branch 60 → 61 not taken.
✗ Branch 60 → 66 not taken.
✗ if (!run) {
1324
0/2
✗ Branch 62 → 63 not taken.
✗ Branch 62 → 64 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 1)
1325 ✗ return AVERROR_INVALIDDATA;
1326 ✗ code = bytestream2_get_byte(gb);
1327 }
1328 ✗ *(dst + i + (k * width) + l) = code;
1329 ✗ len--;
1330 }
1331 }
1332 ✗ continue;
1333 }
1334 }
1335 /* 4x4 block copy from prev with MV */
1336 ✗ mx = c37_mv[(mvoff * 256 + code) * 2];
1337 ✗ my = c37_mv[(mvoff * 256 + code) * 2 + 1];
1338 ✗ codec37_mv(dst + i, prev + i + mx + my * width,
1339 height, width, i + mx, j + my);
1340 ✗ len--;
1341 }
1342 ✗ dst += width * 4;
1343 ✗ prev += width * 4;
1344 }
1345 ✗ break;
1346 ✗ case 2:
1347
0/2
✗ Branch 79 → 80 not taken.
✗ Branch 79 → 81 not taken.
✗ if (rle_decode(ctx, gb, dst, decoded_size))
1348 ✗ return AVERROR_INVALIDDATA;
1349 ✗ memset(ctx->frm2, 0, ctx->frm2_size);
1350 ✗ break;
1351 ✗ case 3:
1352 case 4:
1353
0/2
✗ Branch 134 → 83 not taken.
✗ Branch 134 → 135 not taken.
✗ for (j = 0; j < height; j += 4) {
1354
0/2
✗ Branch 132 → 84 not taken.
✗ Branch 132 → 133 not taken.
✗ for (i = 0; i < width; i += 4) {
1355 int code;
1356
0/2
✗ Branch 84 → 85 not taken.
✗ Branch 84 → 87 not taken.
✗ if (skip_run) {
1357 ✗ skip_run--;
1358 ✗ copy_block4(dst + i, prev + i, width, width, 4);
1359 ✗ continue;
1360 }
1361
0/2
✗ Branch 88 → 89 not taken.
✗ Branch 88 → 90 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 1)
1362 ✗ return AVERROR_INVALIDDATA;
1363 ✗ code = bytestream2_get_byteu(gb);
1364
0/2
✗ Branch 91 → 92 not taken.
✗ Branch 91 → 99 not taken.
✗ if (code == 0xFF) {
1365
0/2
✗ Branch 93 → 94 not taken.
✗ Branch 93 → 95 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 16)
1366 ✗ return AVERROR_INVALIDDATA;
1367
0/2
✗ Branch 98 → 96 not taken.
✗ Branch 98 → 131 not taken.
✗ for (k = 0; k < 4; k++)
1368 ✗ bytestream2_get_bufferu(gb, dst + i + k * width, 4);
1369
0/4
✗ Branch 99 → 100 not taken.
✗ Branch 99 → 113 not taken.
✗ Branch 100 → 101 not taken.
✗ Branch 100 → 113 not taken.
✗ } else if ((flags & 4) && (code == 0xFE)) {
1370
0/2
✗ Branch 102 → 103 not taken.
✗ Branch 102 → 104 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 4)
1371 ✗ return AVERROR_INVALIDDATA;
1372
0/2
✗ Branch 111 → 105 not taken.
✗ Branch 111 → 112 not taken.
✗ for (k = 0; k < 4; k += 2) {
1373 ✗ uint8_t c1 = bytestream2_get_byteu(gb);
1374 ✗ uint8_t c2 = bytestream2_get_byteu(gb);
1375
0/2
✗ Branch 109 → 108 not taken.
✗ Branch 109 → 110 not taken.
✗ for (l = 0; l < 2; l++) {
1376 ✗ *(dst + i + ((k + l) * width) + 0) = c1;
1377 ✗ *(dst + i + ((k + l) * width) + 1) = c1;
1378 ✗ *(dst + i + ((k + l) * width) + 2) = c2;
1379 ✗ *(dst + i + ((k + l) * width) + 3) = c2;
1380 }
1381 }
1382
0/4
✗ Branch 113 → 114 not taken.
✗ Branch 113 → 123 not taken.
✗ Branch 114 → 115 not taken.
✗ Branch 114 → 123 not taken.
✗ } else if ((flags & 4) && (code == 0xFD)) {
1383
0/2
✗ Branch 116 → 117 not taken.
✗ Branch 116 → 118 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 1)
1384 ✗ return AVERROR_INVALIDDATA;
1385 ✗ t = bytestream2_get_byteu(gb);
1386
0/2
✗ Branch 121 → 120 not taken.
✗ Branch 121 → 122 not taken.
✗ for (k = 0; k < 4; k++)
1387 ✗ memset(dst + i + k * width, t, 4);
1388 } else {
1389 ✗ mx = c37_mv[(mvoff * 256 + code) * 2];
1390 ✗ my = c37_mv[(mvoff * 256 + code) * 2 + 1];
1391 ✗ codec37_mv(dst + i, prev + i + mx + my * width,
1392 height, width, i + mx, j + my);
1393
1394
0/4
✗ Branch 124 → 125 not taken.
✗ Branch 124 → 131 not taken.
✗ Branch 125 → 126 not taken.
✗ Branch 125 → 131 not taken.
✗ if ((compr == 4) && (code == 0)) {
1395
0/2
✗ Branch 127 → 128 not taken.
✗ Branch 127 → 129 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 1)
1396 ✗ return AVERROR_INVALIDDATA;
1397 ✗ skip_run = bytestream2_get_byteu(gb);
1398 }
1399 }
1400 }
1401 ✗ dst += width * 4;
1402 ✗ prev += width * 4;
1403 }
1404 ✗ break;
1405 ✗ default:
1406 ✗ avpriv_report_missing_feature(ctx->avctx,
1407 "Subcodec 37 compression %d", compr);
1408 ✗ return AVERROR_PATCHWELCOME;
1409 }
1410
1411
0/2
✗ Branch 138 → 139 not taken.
✗ Branch 138 → 140 not taken.
✗ if ((flags & 2) == 0) {
1412 ✗ blt_solid((uint8_t*)ctx->fbuf, (uint8_t*)ctx->frm0, left, top, 0, 0, width,
1413 ✗ height, width, ctx->pitch, ctx->height, width * height);
1414 } else {
1415 ✗ blt_mask((uint8_t*)ctx->fbuf, (uint8_t*)ctx->frm0, left, top, 0, 0, width,
1416 ✗ height, width, ctx->pitch, ctx->height, width * height, 0);
1417 }
1418 ✗ return 0;
1419 }
1420
1421 ✗ static int codec47_block(SANMVideoContext *ctx, GetByteContext *gb,uint8_t *dst,
1422 uint8_t *prev1, uint8_t *prev2, int stride, int size)
1423 {
1424 int code, k, t;
1425 uint8_t colors[2];
1426 int8_t *pglyph;
1427
1428
0/2
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 1)
1429 ✗ return AVERROR_INVALIDDATA;
1430
1431 ✗ code = bytestream2_get_byteu(gb);
1432
0/2
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 61 not taken.
✗ if (code >= 0xF8) {
1433
0/5
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 30 not taken.
✗ Branch 7 → 38 not taken.
✗ Branch 7 → 53 not taken.
✗ Branch 7 → 57 not taken.
✗ switch (code) {
1434 ✗ case 0xFF:
1435
0/2
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 17 not taken.
✗ if (size == 2) {
1436
0/2
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 12 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 4)
1437 ✗ return AVERROR_INVALIDDATA;
1438 ✗ dst[0] = bytestream2_get_byteu(gb);
1439 ✗ dst[1] = bytestream2_get_byteu(gb);
1440 ✗ dst[0 + stride] = bytestream2_get_byteu(gb);
1441 ✗ dst[1 + stride] = bytestream2_get_byteu(gb);
1442 } else {
1443 ✗ size >>= 1;
1444
0/2
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 20 not taken.
✗ if (codec47_block(ctx, gb, dst, prev1, prev2, stride, size))
1445 ✗ return AVERROR_INVALIDDATA;
1446
0/2
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 23 not taken.
✗ if (codec47_block(ctx, gb, dst + size, prev1 + size, prev2 + size,
1447 stride, size))
1448 ✗ return AVERROR_INVALIDDATA;
1449 ✗ dst += size * stride;
1450 ✗ prev1 += size * stride;
1451 ✗ prev2 += size * stride;
1452
0/2
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 26 not taken.
✗ if (codec47_block(ctx, gb, dst, prev1, prev2, stride, size))
1453 ✗ return AVERROR_INVALIDDATA;
1454
0/2
✗ Branch 27 → 28 not taken.
✗ Branch 27 → 29 not taken.
✗ if (codec47_block(ctx, gb, dst + size, prev1 + size, prev2 + size,
1455 stride, size))
1456 ✗ return AVERROR_INVALIDDATA;
1457 }
1458 ✗ break;
1459 ✗ case 0xFE:
1460
0/2
✗ Branch 31 → 32 not taken.
✗ Branch 31 → 33 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 1)
1461 ✗ return AVERROR_INVALIDDATA;
1462
1463 ✗ t = bytestream2_get_byteu(gb);
1464
0/2
✗ Branch 36 → 35 not taken.
✗ Branch 36 → 37 not taken.
✗ for (k = 0; k < size; k++)
1465 ✗ memset(dst + k * stride, t, size);
1466 ✗ break;
1467 ✗ case 0xFD:
1468
0/2
✗ Branch 39 → 40 not taken.
✗ Branch 39 → 41 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 3)
1469 ✗ return AVERROR_INVALIDDATA;
1470
1471 ✗ code = bytestream2_get_byteu(gb);
1472
0/2
✗ Branch 42 → 43 not taken.
✗ Branch 42 → 44 not taken.
✗ pglyph = (size == 8) ? ctx->p8x8glyphs[code] : ctx->p4x4glyphs[code];
1473 ✗ bytestream2_get_bufferu(gb, colors, 2);
1474
1475
0/2
✗ Branch 51 → 47 not taken.
✗ Branch 51 → 52 not taken.
✗ for (k = 0; k < size; k++)
1476
0/2
✗ Branch 49 → 48 not taken.
✗ Branch 49 → 50 not taken.
✗ for (t = 0; t < size; t++)
1477 ✗ dst[t + k * stride] = colors[!*pglyph++];
1478 ✗ break;
1479 ✗ case 0xFC:
1480
0/2
✗ Branch 55 → 54 not taken.
✗ Branch 55 → 56 not taken.
✗ for (k = 0; k < size; k++)
1481 ✗ memcpy(dst + k * stride, prev1 + k * stride, size);
1482 ✗ break;
1483 ✗ default:
1484
0/2
✗ Branch 59 → 58 not taken.
✗ Branch 59 → 60 not taken.
✗ for (k = 0; k < size; k++)
1485 ✗ memset(dst + k * stride, ctx->c47cb[code & 3], size);
1486 }
1487 } else {
1488 ✗ int mx = c47_mv[code][0];
1489 ✗ int my = c47_mv[code][1];
1490 ✗ int index = prev2 - (const uint8_t *)ctx->frm2;
1491
1492 av_assert2(index >= 0 && index < (ctx->buf_size >> 1));
1493
1494
0/2
✗ Branch 61 → 62 not taken.
✗ Branch 61 → 63 not taken.
✗ if (index < -mx - my * stride ||
1495
0/2
✗ Branch 62 → 63 not taken.
✗ Branch 62 → 65 not taken.
✗ (ctx->buf_size >> 1) - index < mx + size + (my + size - 1) * stride) {
1496 ✗ av_log(ctx->avctx, AV_LOG_ERROR, "MV is invalid.\n");
1497 ✗ return AVERROR_INVALIDDATA;
1498 }
1499
1500
0/2
✗ Branch 67 → 66 not taken.
✗ Branch 67 → 68 not taken.
✗ for (k = 0; k < size; k++)
1501 ✗ memcpy(dst + k * stride, prev2 + mx + (my + k) * stride, size);
1502 }
1503
1504 ✗ return 0;
1505 }
1506
1507 ✗ static void codec47_read_interptable(GetByteContext *gb, uint8_t *itbl)
1508 {
1509 uint8_t *p1, *p2;
1510 int i, j;
1511
1512
0/2
✗ Branch 8 → 3 not taken.
✗ Branch 8 → 9 not taken.
✗ for (i = 0; i < 256; i++) {
1513 ✗ p1 = p2 = itbl + i;
1514
0/2
✗ Branch 6 → 4 not taken.
✗ Branch 6 → 7 not taken.
✗ for (j = 256 - i; j; j--) {
1515 ✗ *p1 = *p2 = bytestream2_get_byte(gb);
1516 ✗ p1 += 1;
1517 ✗ p2 += 256;
1518 }
1519 ✗ itbl += 256;
1520 }
1521 ✗ }
1522
1523 ✗ static void codec47_comp1(GetByteContext *gb, uint8_t *dst_in, int width,
1524 const int height, const ptrdiff_t stride, const uint8_t *itbl)
1525 {
1526 uint8_t p1, *dst;
1527 uint16_t px;
1528 int i, j;
1529
1530 ✗ dst = dst_in + stride;
1531
0/2
✗ Branch 9 → 3 not taken.
✗ Branch 9 → 10 not taken.
✗ for (i = 0; i < height; i += 2) {
1532 ✗ p1 = bytestream2_get_byte(gb);
1533 ✗ *dst++ = p1;
1534 ✗ *dst++ = p1;
1535 ✗ px = p1;
1536
0/2
✗ Branch 7 → 5 not taken.
✗ Branch 7 → 8 not taken.
✗ for (j = 2; j < width; j += 2) {
1537 ✗ p1 = bytestream2_get_byte(gb);
1538 ✗ px = (px << 8) | p1;
1539 ✗ *dst++ = itbl[px];
1540 ✗ *dst++ = p1;
1541 }
1542 ✗ dst += stride;
1543 }
1544
1545 ✗ memcpy(dst_in, dst_in + stride, width);
1546 ✗ dst = dst_in + stride + stride;
1547
0/2
✗ Branch 15 → 11 not taken.
✗ Branch 15 → 16 not taken.
✗ for (i = 2; i < height - 1; i += 2) {
1548
0/2
✗ Branch 13 → 12 not taken.
✗ Branch 13 → 14 not taken.
✗ for (j = 0; j < width; j++) {
1549 ✗ px = (*(dst - stride) << 8) | *(dst + stride);
1550 ✗ *dst++ = itbl[px];
1551 }
1552 ✗ dst += stride;
1553 }
1554 ✗ }
1555
1556 ✗ static int old_codec47(SANMVideoContext *ctx, GetByteContext *gb, int top, int left,
1557 int width, int height)
1558 {
1559 uint32_t decoded_size;
1560 int i, j;
1561 ✗ uint8_t *dst = (uint8_t *)ctx->frm0;
1562 ✗ uint8_t *prev1 = (uint8_t *)ctx->frm1;
1563 ✗ uint8_t *prev2 = (uint8_t *)ctx->frm2;
1564 uint8_t auxcol[2];
1565
1566 ✗ width = FFALIGN(width, 8);
1567
0/2
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 4 not taken.
✗ if (width > ctx->aligned_width)
1568 ✗ return AVERROR_INVALIDDATA;
1569
1570
0/2
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 6 not taken.
✗ if (FFALIGN(height, 8) > ctx->aligned_height)
1571 ✗ return AVERROR_INVALIDDATA;
1572
1573
0/2
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 9 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 26)
1574 ✗ return AVERROR_INVALIDDATA;
1575
1576 ✗ int seq = bytestream2_get_le16u(gb);
1577 ✗ int compr = bytestream2_get_byteu(gb);
1578 ✗ int new_rot = bytestream2_get_byteu(gb);
1579 ✗ int skip = bytestream2_get_byteu(gb);
1580
1581 ✗ bytestream2_skip(gb, 3);
1582 ✗ bytestream2_get_bufferu(gb, ctx->c47cb, 4);
1583 ✗ auxcol[0] = bytestream2_get_byteu(gb);
1584 ✗ auxcol[1] = bytestream2_get_byteu(gb);
1585 ✗ decoded_size = bytestream2_get_le32u(gb);
1586 ✗ bytestream2_skip(gb, 8);
1587
1588
0/2
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 21 not taken.
✗ if (decoded_size > ctx->aligned_height * width) {
1589 ✗ decoded_size = height * width;
1590 ✗ av_log(ctx->avctx, AV_LOG_WARNING, "Decoded size is too large.\n");
1591 }
1592
1593
0/2
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 26 not taken.
✗ if (skip & 1) {
1594
0/2
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 25 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 0x8080)
1595 ✗ return AVERROR_INVALIDDATA;
1596 ✗ codec47_read_interptable(gb, ctx->c47itbl);
1597 }
1598
0/2
✗ Branch 26 → 27 not taken.
✗ Branch 26 → 28 not taken.
✗ if (!seq) {
1599 ✗ ctx->prev_seq = -1;
1600 ✗ memset(prev1, auxcol[0], ctx->frm0_size);
1601 ✗ memset(prev2, auxcol[1], ctx->frm0_size);
1602 }
1603
1604
0/7
✗ Branch 28 → 29 not taken.
✗ Branch 28 → 33 not taken.
✗ Branch 28 → 38 not taken.
✗ Branch 28 → 49 not taken.
✗ Branch 28 → 50 not taken.
✗ Branch 28 → 51 not taken.
✗ Branch 28 → 55 not taken.
✗ switch (compr) {
1605 ✗ case 0:
1606
0/2
✗ Branch 30 → 31 not taken.
✗ Branch 30 → 32 not taken.
✗ if (bytestream2_get_bytes_left(gb) < width * height)
1607 ✗ return AVERROR_INVALIDDATA;
1608 ✗ bytestream2_get_bufferu(gb, dst, width * height);
1609 ✗ break;
1610 ✗ case 1:
1611
0/2
✗ Branch 34 → 35 not taken.
✗ Branch 34 → 36 not taken.
✗ if (bytestream2_get_bytes_left(gb) < ((width + 1) >> 1) * ((height + 1) >> 1))
1612 ✗ return AVERROR_INVALIDDATA;
1613 ✗ codec47_comp1(gb, dst, width, height, width, ctx->c47itbl);
1614 ✗ break;
1615 ✗ case 2:
1616
0/2
✗ Branch 38 → 39 not taken.
✗ Branch 38 → 48 not taken.
✗ if (seq == ctx->prev_seq + 1) {
1617
0/2
✗ Branch 47 → 40 not taken.
✗ Branch 47 → 48 not taken.
✗ for (j = 0; j < height; j += 8) {
1618
0/2
✗ Branch 45 → 41 not taken.
✗ Branch 45 → 46 not taken.
✗ for (i = 0; i < width; i += 8)
1619
0/2
✗ Branch 42 → 43 not taken.
✗ Branch 42 → 44 not taken.
✗ if (codec47_block(ctx, gb, dst + i, prev1 + i, prev2 + i, width, 8))
1620 ✗ return AVERROR_INVALIDDATA;
1621 ✗ dst += width * 8;
1622 ✗ prev1 += width * 8;
1623 ✗ prev2 += width * 8;
1624 }
1625 }
1626 ✗ break;
1627 ✗ case 3:
1628 ✗ memcpy(ctx->frm0, ctx->frm2, ctx->frm0_size);
1629 ✗ break;
1630 ✗ case 4:
1631 ✗ memcpy(ctx->frm0, ctx->frm1, ctx->frm0_size);
1632 ✗ break;
1633 ✗ case 5:
1634
0/2
✗ Branch 52 → 53 not taken.
✗ Branch 52 → 54 not taken.
✗ if (rle_decode(ctx, gb, dst, decoded_size))
1635 ✗ return AVERROR_INVALIDDATA;
1636 ✗ break;
1637 ✗ default:
1638 ✗ avpriv_report_missing_feature(ctx->avctx,
1639 "Subcodec 47 compression %d", compr);
1640 ✗ return AVERROR_PATCHWELCOME;
1641 }
1642
1643 ✗ blt_solid((uint8_t*)ctx->fbuf, (uint8_t*)ctx->frm0, left, top, 0, 0, width,
1644 ✗ height, width, ctx->pitch, ctx->height, width * height);
1645
1646
0/4
✗ Branch 59 → 60 not taken.
✗ Branch 59 → 62 not taken.
✗ Branch 60 → 61 not taken.
✗ Branch 60 → 62 not taken.
✗ if ((seq == ctx->prev_seq + 1) && new_rot)
1647 ✗ rotate_bufs(ctx, new_rot);
1648
1649 ✗ ctx->prev_seq = seq;
1650
1651 ✗ return 0;
1652 }
1653
1654 // scale 4x4 input block to an 8x8 output block
1655 ✗ static void c48_4to8(uint8_t *dst, const uint8_t *src, const uint16_t w)
1656 {
1657 uint16_t p;
1658 // dst is always at least 16bit aligned
1659
0/2
✗ Branch 7 → 3 not taken.
✗ Branch 7 → 8 not taken.
✗ for (int i = 0; i < 4; i++) {
1660
0/2
✗ Branch 5 → 4 not taken.
✗ Branch 5 → 6 not taken.
✗ for (int j = 0; j < 8; j += 2) {
1661 ✗ p = *src++;
1662 ✗ p = (p << 8) | p;
1663 ✗ *((uint16_t *)(dst + w * 0 + j)) = p;
1664 ✗ *((uint16_t *)(dst + w * 1 + j)) = p;
1665 }
1666 ✗ dst += w * 2;
1667 }
1668 ✗ }
1669
1670 ✗ static int c48_invalid_mv(int x, int y, const uint16_t w, int h, int blocksize, int mvofs) {
1671
0/2
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 4 not taken.
✗ if (mvofs < -x + -y*w)
1672 ✗ return AVERROR_INVALIDDATA;
1673
1674
0/2
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 6 not taken.
✗ if (mvofs > w-x-blocksize + w*(h-y-blocksize))
1675 ✗ return AVERROR_INVALIDDATA;
1676
1677 ✗ return 0;
1678 }
1679
1680 ✗ static int codec48_block(GetByteContext *gb, uint8_t *dst, uint8_t *db, int x, int y,
1681 const uint16_t w, const int aligned_height, const uint8_t *itbl)
1682 {
1683 uint8_t opc, sb[16];
1684 int i, j, k, l;
1685 int16_t mvofs;
1686 uint32_t ofs;
1687
1688
0/2
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 1)
1689 ✗ return 1;
1690
1691 ✗ opc = bytestream2_get_byteu(gb);
1692
0/10
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 20 not taken.
✗ Branch 6 → 34 not taken.
✗ Branch 6 → 47 not taken.
✗ Branch 6 → 67 not taken.
✗ Branch 6 → 87 not taken.
✗ Branch 6 → 93 not taken.
✗ Branch 6 → 110 not taken.
✗ Branch 6 → 127 not taken.
✗ Branch 6 → 138 not taken.
✗ switch (opc) {
1693 ✗ case 0xFF: // 1x1 -> 8x8 block scale
1694
0/2
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 10 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 1)
1695 ✗ return 1;
1696
1697
0/4
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 14 not taken.
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 14 not taken.
✗ if (y > 0 && x > 0) {
1698 ✗ sb[15] = bytestream2_get_byteu(gb);
1699 ✗ sb[ 7] = itbl[(*(dst - 1*w + 7) << 8) | sb[15]];
1700 ✗ sb[ 3] = itbl[(*(dst - 1*w + 7) << 8) | sb[ 7]];
1701 ✗ sb[11] = itbl[(sb[15] << 8) | sb[ 7]];
1702 ✗ sb[ 1] = itbl[(*(dst + 0*w - 1) << 8) | sb[ 3]];
1703 ✗ sb[ 0] = itbl[(*(dst + 0*w - 1) << 8) | sb[ 1]];
1704 ✗ sb[ 2] = itbl[(sb[ 3] << 8) | sb[ 1]];
1705 ✗ sb[ 5] = itbl[(*(dst + 2*w - 1) << 8) | sb[ 7]];
1706 ✗ sb[ 4] = itbl[(*(dst + 2*w - 1) << 8) | sb[ 5]];
1707 ✗ sb[ 6] = itbl[(sb[ 7] << 8) | sb[ 5]];
1708 ✗ sb[ 9] = itbl[(*(dst + 3*w - 1) << 8) | sb[11]];
1709 ✗ sb[ 8] = itbl[(*(dst + 3*w - 1) << 8) | sb[ 9]];
1710 ✗ sb[10] = itbl[(sb[11] << 8) | sb[ 9]];
1711 ✗ sb[13] = itbl[(*(dst + 4*w - 1) << 8) | sb[15]];
1712 ✗ sb[12] = itbl[(*(dst + 4*w - 1) << 8) | sb[13]];
1713 ✗ sb[14] = itbl[(sb[15] << 8) | sb[13]];
1714 } else {
1715 ✗ opc = bytestream2_get_byteu(gb);
1716
0/2
✗ Branch 17 → 16 not taken.
✗ Branch 17 → 18 not taken.
✗ for (i = 0; i < 16; i++)
1717 ✗ sb[i] = opc;
1718 }
1719 ✗ c48_4to8(dst, sb, w);
1720 ✗ break;
1721 ✗ case 0xFE: // 1x 8x8 copy from deltabuf, 16bit mv from source
1722
0/2
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 23 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 2)
1723 ✗ return 1;
1724 ✗ mvofs = bytestream2_get_le16(gb);
1725
0/2
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 27 not taken.
✗ if (c48_invalid_mv(x, y, w, aligned_height, 8, mvofs))
1726 ✗ break;
1727
0/2
✗ Branch 32 → 28 not taken.
✗ Branch 32 → 33 not taken.
✗ for (i = 0; i < 8; i++) {
1728 ✗ ofs = w * i;
1729
0/2
✗ Branch 30 → 29 not taken.
✗ Branch 30 → 31 not taken.
✗ for (k = 0; k < 8; k++)
1730 ✗ *(dst + ofs + k) = *(db + ofs + k + mvofs);
1731 }
1732 ✗ break;
1733 ✗ case 0xFD: // 2x2 -> 8x8 block scale
1734
0/2
✗ Branch 35 → 36 not taken.
✗ Branch 35 → 37 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 4)
1735 ✗ return 1;
1736 ✗ sb[ 5] = bytestream2_get_byteu(gb);
1737 ✗ sb[ 7] = bytestream2_get_byteu(gb);
1738 ✗ sb[13] = bytestream2_get_byteu(gb);
1739 ✗ sb[15] = bytestream2_get_byteu(gb);
1740
1741
0/4
✗ Branch 41 → 42 not taken.
✗ Branch 41 → 44 not taken.
✗ Branch 42 → 43 not taken.
✗ Branch 42 → 44 not taken.
✗ if (y > 0 && x >0) {
1742 ✗ sb[ 1] = itbl[(*(dst - 1*w + 3) << 8) | sb[ 5]];
1743 ✗ sb[ 3] = itbl[(*(dst - 1*w + 7) << 8) | sb[ 7]];
1744 ✗ sb[ 9] = itbl[(sb[13] << 8) | sb[ 5]];
1745 ✗ sb[11] = itbl[(sb[15] << 8) | sb[ 7]];
1746 ✗ sb[ 0] = itbl[(*(dst + 0*w - 1) << 8) | sb[ 1]];
1747 ✗ sb[ 2] = itbl[(sb[ 3] << 8) | sb[ 1]];
1748 ✗ sb[ 4] = itbl[(*(dst + 2*w - 1) << 8) | sb[ 5]];
1749 ✗ sb[ 6] = itbl[(sb[ 7] << 8) | sb[ 5]];
1750 ✗ sb[ 8] = itbl[(*(dst + 3*w - 1) << 8) | sb[ 9]];
1751 ✗ sb[10] = itbl[(sb[11] << 8) | sb[ 9]];
1752 ✗ sb[12] = itbl[(*(dst + 4*w - 1) << 8) | sb[13]];
1753 ✗ sb[14] = itbl[(sb[15] << 8) | sb[13]];
1754 } else {
1755 ✗ sb[ 0] = sb[ 1] = sb[ 4] = sb[ 5];
1756 ✗ sb[ 2] = sb[ 3] = sb[ 6] = sb[ 7];
1757 ✗ sb[ 8] = sb[ 9] = sb[12] = sb[13];
1758 ✗ sb[10] = sb[11] = sb[14] = sb[15];
1759 }
1760 ✗ c48_4to8(dst, sb, w);
1761 ✗ break;
1762 ✗ case 0xFC: // 4x copy 4x4 block, per-block c37_mv from source
1763
0/2
✗ Branch 48 → 49 not taken.
✗ Branch 48 → 50 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 4)
1764 ✗ return 1;
1765
0/2
✗ Branch 65 → 51 not taken.
✗ Branch 65 → 66 not taken.
✗ for (i = 0; i < 8; i += 4) {
1766
0/2
✗ Branch 63 → 52 not taken.
✗ Branch 63 → 64 not taken.
✗ for (k = 0; k < 8; k += 4) {
1767 ✗ opc = bytestream2_get_byteu(gb);
1768 ✗ mvofs = c37_mv[opc * 2] + (c37_mv[opc * 2 + 1] * w);
1769
0/2
✗ Branch 54 → 55 not taken.
✗ Branch 54 → 56 not taken.
✗ if (c48_invalid_mv(x+k, y+i, w, aligned_height, 4, mvofs))
1770 ✗ continue;
1771
0/2
✗ Branch 61 → 57 not taken.
✗ Branch 61 → 62 not taken.
✗ for (j = 0; j < 4; j++) {
1772 ✗ ofs = (w * (j + i)) + k;
1773
0/2
✗ Branch 59 → 58 not taken.
✗ Branch 59 → 60 not taken.
✗ for (l = 0; l < 4; l++)
1774 ✗ *(dst + ofs + l) = *(db + ofs + l + mvofs);
1775 }
1776 }
1777 }
1778 ✗ break;
1779 ✗ case 0xFB: // Copy 4x 4x4 blocks, per-block mv from source
1780
0/2
✗ Branch 68 → 69 not taken.
✗ Branch 68 → 70 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 8)
1781 ✗ return 1;
1782
0/2
✗ Branch 85 → 71 not taken.
✗ Branch 85 → 86 not taken.
✗ for (i = 0; i < 8; i += 4) {
1783
0/2
✗ Branch 83 → 72 not taken.
✗ Branch 83 → 84 not taken.
✗ for (k = 0; k < 8; k += 4) {
1784 ✗ mvofs = bytestream2_get_le16(gb);
1785
0/2
✗ Branch 74 → 75 not taken.
✗ Branch 74 → 76 not taken.
✗ if (c48_invalid_mv(x+k, y+i, w, aligned_height, 4, mvofs))
1786 ✗ continue;
1787
0/2
✗ Branch 81 → 77 not taken.
✗ Branch 81 → 82 not taken.
✗ for (j = 0; j < 4; j++) {
1788 ✗ ofs = (w * (j + i)) + k;
1789
0/2
✗ Branch 79 → 78 not taken.
✗ Branch 79 → 80 not taken.
✗ for (l = 0; l < 4; l++)
1790 ✗ *(dst + ofs + l) = *(db + ofs + l + mvofs);
1791 }
1792 }
1793 }
1794 ✗ break;
1795 ✗ case 0xFA: // scale 4x4 input block to 8x8 dest block
1796
0/2
✗ Branch 88 → 89 not taken.
✗ Branch 88 → 90 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 16)
1797 ✗ return 1;
1798 ✗ bytestream2_get_bufferu(gb, sb, 16);
1799 ✗ c48_4to8(dst, sb, w);
1800 ✗ break;
1801 ✗ case 0xF9: // 16x 2x2 copy from delta, per-block c37_mv from source
1802
0/2
✗ Branch 94 → 95 not taken.
✗ Branch 94 → 96 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 16)
1803 ✗ return 1;
1804
0/2
✗ Branch 108 → 97 not taken.
✗ Branch 108 → 109 not taken.
✗ for (i = 0; i < 8; i += 2) {
1805
0/2
✗ Branch 106 → 98 not taken.
✗ Branch 106 → 107 not taken.
✗ for (j = 0; j < 8; j += 2) {
1806 ✗ ofs = (w * i) + j;
1807 ✗ opc = bytestream2_get_byteu(gb);
1808 ✗ mvofs = c37_mv[opc * 2] + (c37_mv[opc * 2 + 1] * w);
1809
0/2
✗ Branch 100 → 101 not taken.
✗ Branch 100 → 102 not taken.
✗ if (c48_invalid_mv(x+j, y+i, w, aligned_height, 2, mvofs))
1810 ✗ continue;
1811
0/2
✗ Branch 104 → 103 not taken.
✗ Branch 104 → 105 not taken.
✗ for (l = 0; l < 2; l++) {
1812 ✗ *(dst + ofs + l + 0) = *(db + ofs + l + 0 + mvofs);
1813 ✗ *(dst + ofs + l + w) = *(db + ofs + l + w + mvofs);
1814 }
1815 }
1816 }
1817 ✗ break;
1818 ✗ case 0xF8: // 16x 2x2 blocks copy, 16bit mv from source
1819
0/2
✗ Branch 111 → 112 not taken.
✗ Branch 111 → 113 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 32)
1820 ✗ return 1;
1821
0/2
✗ Branch 125 → 114 not taken.
✗ Branch 125 → 126 not taken.
✗ for (i = 0; i < 8; i += 2) {
1822
0/2
✗ Branch 123 → 115 not taken.
✗ Branch 123 → 124 not taken.
✗ for (j = 0; j < 8; j += 2) {
1823 ✗ ofs = w * i + j;
1824 ✗ mvofs = bytestream2_get_le16(gb);
1825
0/2
✗ Branch 117 → 118 not taken.
✗ Branch 117 → 119 not taken.
✗ if (c48_invalid_mv(x+j, y+i, w, aligned_height, 2, mvofs))
1826 ✗ continue;
1827
0/2
✗ Branch 121 → 120 not taken.
✗ Branch 121 → 122 not taken.
✗ for (l = 0; l < 2; l++) {
1828 ✗ *(dst + ofs + l + 0) = *(db + ofs + l + 0 + mvofs);
1829 ✗ *(dst + ofs + l + w) = *(db + ofs + l + w + mvofs);
1830 }
1831 }
1832 }
1833 ✗ break;
1834 ✗ case 0xF7: // copy 8x8 block from src to dest
1835
0/2
✗ Branch 128 → 129 not taken.
✗ Branch 128 → 130 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 64)
1836 ✗ return 1;
1837
0/2
✗ Branch 136 → 131 not taken.
✗ Branch 136 → 137 not taken.
✗ for (i = 0; i < 8; i++) {
1838 ✗ ofs = i * w;
1839
0/2
✗ Branch 134 → 132 not taken.
✗ Branch 134 → 135 not taken.
✗ for (l = 0; l < 8; l++)
1840 ✗ *(dst + ofs + l) = bytestream2_get_byteu(gb);
1841 }
1842 ✗ break;
1843 ✗ default: // copy 8x8 block from prev, c37_mv from source
1844 ✗ mvofs = c37_mv[opc * 2] + (c37_mv[opc * 2 + 1] * w);
1845
0/2
✗ Branch 139 → 140 not taken.
✗ Branch 139 → 141 not taken.
✗ if (c48_invalid_mv(x, y, w, aligned_height, 8, mvofs))
1846 ✗ break;
1847
0/2
✗ Branch 146 → 142 not taken.
✗ Branch 146 → 147 not taken.
✗ for (i = 0; i < 8; i++) {
1848 ✗ ofs = i * w;
1849
0/2
✗ Branch 144 → 143 not taken.
✗ Branch 144 → 145 not taken.
✗ for (l = 0; l < 8; l++)
1850 ✗ *(dst + ofs + l) = *(db + ofs + l + mvofs);
1851 }
1852 ✗ break;
1853 }
1854 ✗ return 0;
1855 }
1856
1857 ✗ static int old_codec48(SANMVideoContext *ctx, GetByteContext *gb, int top, int left,
1858 int width, int height)
1859 {
1860 uint8_t *dst, *prev;
1861 int i, j, flags, ah;
1862
1863 ✗ width = FFALIGN(width, 8);
1864
0/2
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 4 not taken.
✗ if (width > ctx->aligned_width)
1865 ✗ return AVERROR_INVALIDDATA;
1866
1867 ✗ ah = FFALIGN(height, 8);
1868
0/2
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 6 not taken.
✗ if (ah > ctx->aligned_height)
1869 ✗ return AVERROR_INVALIDDATA;
1870
1871
0/2
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 9 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 16)
1872 ✗ return AVERROR_INVALIDDATA;
1873
1874 ✗ int compr = bytestream2_get_byteu(gb);
1875 ✗ int mvidx = bytestream2_get_byteu(gb);
1876 ✗ int seq = bytestream2_get_le16u(gb);
1877 ✗ uint32_t decoded_size = bytestream2_get_le32u(gb);
1878
1879 // all codec48 videos use 1, but just to be safe...
1880
0/2
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 16 not taken.
✗ if (mvidx != 1) {
1881 ✗ av_log(ctx->avctx, AV_LOG_ERROR, "Invalid motion base value %d.\n", mvidx);
1882 ✗ return AVERROR_INVALIDDATA;
1883 }
1884
1885 ✗ bytestream2_skip(gb, 4);
1886 ✗ flags = bytestream2_get_byteu(gb);
1887 ✗ bytestream2_skip(gb, 3);
1888
1889
0/2
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 24 not taken.
✗ if (flags & 8) {
1890
0/2
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 23 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 0x8080)
1891 ✗ return AVERROR_INVALIDDATA;
1892 ✗ codec47_read_interptable(gb, ctx->c47itbl);
1893 }
1894
1895 ✗ dst = (uint8_t*)ctx->frm0;
1896 ✗ prev = (uint8_t*)ctx->frm2;
1897
1898
0/2
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 26 not taken.
✗ if (seq == 0)
1899 ✗ memset(ctx->frm2, 0, ctx->frm2_size);
1900
1901
0/6
✗ Branch 26 → 27 not taken.
✗ Branch 26 → 31 not taken.
✗ Branch 26 → 38 not taken.
✗ Branch 26 → 54 not taken.
✗ Branch 26 → 59 not taken.
✗ Branch 26 → 60 not taken.
✗ switch (compr) {
1902 ✗ case 0:
1903
0/2
✗ Branch 28 → 29 not taken.
✗ Branch 28 → 30 not taken.
✗ if (bytestream2_get_bytes_left(gb) < width * height)
1904 ✗ return AVERROR_INVALIDDATA;
1905 ✗ bytestream2_get_bufferu(gb, dst, width * height);
1906 ✗ break;
1907 ✗ case 2:
1908
0/2
✗ Branch 31 → 32 not taken.
✗ Branch 31 → 34 not taken.
✗ if (decoded_size > width * height) {
1909 ✗ av_log(ctx->avctx, AV_LOG_ERROR, "Decoded size %u is too large.\n", decoded_size);
1910 ✗ decoded_size = width * height;
1911 }
1912
1913
0/2
✗ Branch 35 → 36 not taken.
✗ Branch 35 → 37 not taken.
✗ if (rle_decode(ctx, gb, dst, decoded_size))
1914 ✗ return AVERROR_INVALIDDATA;
1915 ✗ break;
1916 ✗ case 3:
1917
0/4
✗ Branch 38 → 39 not taken.
✗ Branch 38 → 40 not taken.
✗ Branch 39 → 40 not taken.
✗ Branch 39 → 53 not taken.
✗ if ((seq == 0) || (seq == ctx->prev_seq + 1)) {
1918
0/6
✗ Branch 40 → 41 not taken.
✗ Branch 40 → 43 not taken.
✗ Branch 41 → 42 not taken.
✗ Branch 41 → 43 not taken.
✗ Branch 42 → 43 not taken.
✗ Branch 42 → 44 not taken.
✗ if ((seq & 1) || ((flags & 1) == 0) || (flags & 0x10)) {
1919 ✗ FFSWAP(uint16_t*, ctx->frm0, ctx->frm2);
1920 ✗ dst = (uint8_t*)ctx->frm0;
1921 ✗ prev = (uint8_t*)ctx->frm2;
1922 }
1923
0/2
✗ Branch 52 → 45 not taken.
✗ Branch 52 → 53 not taken.
✗ for (j = 0; j < height; j += 8) {
1924
0/2
✗ Branch 50 → 46 not taken.
✗ Branch 50 → 51 not taken.
✗ for (i = 0; i < width; i += 8) {
1925
0/2
✗ Branch 47 → 48 not taken.
✗ Branch 47 → 49 not taken.
✗ if (codec48_block(gb, dst + i, prev + i, i, j, width,
1926 ✗ ah, ctx->c47itbl))
1927 ✗ return AVERROR_INVALIDDATA;
1928 }
1929 ✗ dst += width * 8;
1930 ✗ prev += width * 8;
1931 }
1932 }
1933 ✗ break;
1934 ✗ case 5:
1935
0/2
✗ Branch 55 → 56 not taken.
✗ Branch 55 → 57 not taken.
✗ if (bytestream2_get_bytes_left(gb) < ((width + 1) >> 1) * ((height + 1) >> 1))
1936 ✗ return AVERROR_INVALIDDATA;
1937 ✗ codec47_comp1(gb, dst, width, height, width, ctx->c47itbl);
1938 ✗ break;
1939 ✗ case 6: /* this is a "stub" frame that follows a frame with flag 0x10 set. */
1940 ✗ break;
1941 ✗ default:
1942 ✗ avpriv_report_missing_feature(ctx->avctx,
1943 "Subcodec 48 compression %d", compr);
1944 ✗ return AVERROR_PATCHWELCOME;
1945 }
1946
1947 ✗ ctx->prev_seq = seq;
1948
0/2
✗ Branch 63 → 64 not taken.
✗ Branch 63 → 68 not taken.
✗ if ((flags & 2) == 0) {
1949
0/2
✗ Branch 64 → 65 not taken.
✗ Branch 64 → 67 not taken.
✗ if (flags & 0x10) {
1950 /* generate an artificial frame from the 2 buffers. This will be
1951 * followed up immediately with a codec48 compression 6 frame, which
1952 * will then blit the actual decoding result (frm0) to the main buffer.
1953 */
1954 ✗ blt_ipol((uint8_t*)ctx->fbuf, (uint8_t*)ctx->frm0, (uint8_t*)ctx->frm2,
1955 ✗ left, top, 0, 0, width, height, width, ctx->pitch, ctx->height,
1956 ✗ width * height, ctx->c47itbl);
1957 ✗ return 0;
1958 }
1959 ✗ blt_solid((uint8_t*)ctx->fbuf, (uint8_t*)ctx->frm0, left, top, 0, 0, width,
1960 ✗ height, width, ctx->pitch, ctx->height, width * height);
1961 } else {
1962 ✗ blt_mask((uint8_t*)ctx->fbuf, (uint8_t*)ctx->frm0, left, top, 0, 0, width,
1963 ✗ height, width, ctx->pitch, ctx->height, width * height, 0);
1964 }
1965 ✗ return 0;
1966 }
1967
1968 ✗ static void old_codec45(SANMVideoContext *ctx, GetByteContext *gb, int top, int left, int flag)
1969 {
1970 int t1, t2, i;
1971
1972
0/2
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 6)
1973 ✗ return;
1974
1975 ✗ bytestream2_skip(gb, 2);
1976 ✗ t1 = bytestream2_get_le16u(gb);
1977 ✗ t2 = bytestream2_get_byteu(gb);
1978 ✗ bytestream2_skip(gb, 1);
1979
0/2
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 11 not taken.
✗ if (t2 != 1)
1980 ✗ return;
1981
0/2
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 25 not taken.
✗ if (t1 == 0) {
1982
0/2
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 15 not taken.
✗ if (bytestream2_get_bytes_left(gb) < 0x300)
1983 ✗ return;
1984 ✗ bytestream2_get_bufferu(gb, ctx->c45tbl1, 0x300);
1985 ✗ i = 0;
1986
0/4
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 25 not taken.
✗ Branch 24 → 17 not taken.
✗ Branch 24 → 25 not taken.
✗ while ((bytestream2_get_bytes_left(gb) > 1) && (i < 0x8000)) {
1987 ✗ uint8_t len = bytestream2_get_byteu(gb);
1988 ✗ uint8_t val = bytestream2_get_byteu(gb);
1989
0/2
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 21 not taken.
✗ if ((i + len) > 0x8000)
1990 ✗ len = 0x8000 - i;
1991 ✗ memset(ctx->c45tbl2 + i, val, len);
1992 ✗ i += len;
1993 }
1994 }
1995
1996
0/2
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 27 not taken.
✗ if (flag)
1997 ✗ return;
1998
1999
0/2
✗ Branch 42 → 28 not taken.
✗ Branch 42 → 43 not taken.
✗ while (bytestream2_get_bytes_left(gb) > 3) {
2000 ✗ left += (int16_t)bytestream2_get_le16u(gb);
2001 ✗ top += bytestream2_get_byteu(gb);
2002 ✗ int len = bytestream2_get_byteu(gb);
2003
0/2
✗ Branch 39 → 32 not taken.
✗ Branch 39 → 40 not taken.
✗ while (len >= 0) {
2004
0/6
✗ Branch 32 → 33 not taken.
✗ Branch 32 → 38 not taken.
✗ Branch 33 → 34 not taken.
✗ Branch 33 → 38 not taken.
✗ Branch 34 → 35 not taken.
✗ Branch 34 → 38 not taken.
✗ if ((left > 0) && (top > 0) && (left < (ctx->width - 1))) {
2005
0/2
✗ Branch 35 → 36 not taken.
✗ Branch 35 → 37 not taken.
✗ if (top >= (ctx->height - 1))
2006 ✗ return;
2007
2008 ✗ uint8_t *dst = (uint8_t *)ctx->fbuf + left + top * ctx->pitch;
2009 ✗ unsigned int c1 = *(dst - 1) * 3;
2010 ✗ unsigned int c2 = *(dst + 1) * 3;
2011 ✗ unsigned int r = ctx->c45tbl1[c1 + 0] + ctx->c45tbl1[c2 + 0];
2012 ✗ unsigned int g = ctx->c45tbl1[c1 + 1] + ctx->c45tbl1[c2 + 1];
2013 ✗ unsigned int b = ctx->c45tbl1[c1 + 2] + ctx->c45tbl1[c2 + 2];
2014 ✗ c1 = *(dst - ctx->pitch) * 3;
2015 ✗ c2 = *(dst + ctx->pitch) * 3;
2016 ✗ r += ctx->c45tbl1[c1 + 0] + ctx->c45tbl1[c2 + 0];
2017 ✗ g += ctx->c45tbl1[c1 + 1] + ctx->c45tbl1[c2 + 1];
2018 ✗ b += ctx->c45tbl1[c1 + 2] + ctx->c45tbl1[c2 + 2];
2019 ✗ *dst = ctx->c45tbl2[((r << 5) & 0x7c00) | (g & 0x3e0) | (b >> 5)];
2020 }
2021 ✗ left++;
2022 ✗ len--;
2023 }
2024 ✗ left--;
2025 }
2026 }
2027
2028 ✗ static int process_frame_obj(SANMVideoContext *ctx, GetByteContext *gb,
2029 int xoff, int yoff)
2030 {
2031 uint16_t w, h, parm2;
2032 uint8_t codec, param;
2033 int16_t left, top;
2034 int fsc;
2035
2036 ✗ codec = bytestream2_get_byteu(gb);
2037 ✗ param = bytestream2_get_byteu(gb);
2038 ✗ left = bytestream2_get_le16u(gb);
2039 ✗ top = bytestream2_get_le16u(gb);
2040 ✗ w = bytestream2_get_le16u(gb);
2041 ✗ h = bytestream2_get_le16u(gb);
2042 ✗ bytestream2_skip(gb, 2);
2043 ✗ parm2 = bytestream2_get_le16u(gb);
2044
2045
0/16
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 18 not taken.
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 18 not taken.
✗ Branch 12 → 13 not taken.
✗ Branch 12 → 18 not taken.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 18 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 18 not taken.
✗ Branch 15 → 16 not taken.
✗ Branch 15 → 18 not taken.
✗ Branch 16 → 17 not taken.
✗ Branch 16 → 18 not taken.
✗ Branch 17 → 18 not taken.
✗ Branch 17 → 23 not taken.
✗ if (w < 1 || h < 1 || w > 640 || h > 480 || left > 640 || top > 480 || left + w <= 0 || top + h <= 0) {
2046 /* codec45 frames with data for the 2 tables have nonsensical dimensions */
2047
0/2
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 21 not taken.
✗ if (codec == 45) {
2048 ✗ old_codec45(ctx, gb, 0, 0, 1);
2049 ✗ return 0;
2050 }
2051
2052 ✗ av_log(ctx->avctx, AV_LOG_WARNING,
2053 "ignoring invalid fobj dimensions: c%d %d %d @ %d %d\n",
2054 codec, w, h, left, top);
2055 ✗ return 0;
2056 }
2057
2058 /* codecs with their own buffers */
2059
0/6
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 26 not taken.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 26 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 27 not taken.
✗ fsc = (codec == 37 || codec == 47 || codec == 48);
2060
2061 /* special case for "Shadows of the Empire" videos: they have top=60
2062 * at all frames to vertically center the video in the 640x480 game
2063 * window, but we don't need that.
2064 */
2065
0/8
✗ Branch 28 → 29 not taken.
✗ Branch 28 → 33 not taken.
✗ Branch 29 → 30 not taken.
✗ Branch 29 → 33 not taken.
✗ Branch 30 → 31 not taken.
✗ Branch 30 → 33 not taken.
✗ Branch 31 → 32 not taken.
✗ Branch 31 → 33 not taken.
✗ if ((w == 640) && (h == 272) && (top == 60) && (codec == 47))
2066 ✗ left = top = 0;
2067
2068
0/4
✗ Branch 33 → 34 not taken.
✗ Branch 33 → 74 not taken.
✗ Branch 34 → 35 not taken.
✗ Branch 34 → 74 not taken.
✗ if (!ctx->have_dimensions && (codec != 45)) {
2069 int xres, yres;
2070
0/2
✗ Branch 35 → 36 not taken.
✗ Branch 35 → 40 not taken.
✗ if (ctx->subversion < 2) {
2071 /* Rebel Assault 1: 384x242 internal size */
2072 ✗ xres = 384;
2073 ✗ yres = 242;
2074
0/4
✗ Branch 36 → 37 not taken.
✗ Branch 36 → 38 not taken.
✗ Branch 37 → 38 not taken.
✗ Branch 37 → 39 not taken.
✗ if (w > xres || h > yres)
2075 ✗ return AVERROR_INVALIDDATA;
2076 ✗ ctx->have_dimensions = 1;
2077 } else {
2078 /* detect common sizes */
2079 ✗ xres = w + left;
2080 ✗ yres = h + top;
2081
0/6
✗ Branch 40 → 41 not taken.
✗ Branch 40 → 42 not taken.
✗ Branch 41 → 42 not taken.
✗ Branch 41 → 50 not taken.
✗ Branch 42 → 43 not taken.
✗ Branch 42 → 44 not taken.
✗ if (((xres == 424) && (yres == 260)) || /* RA2 */
2082
0/4
✗ Branch 43 → 44 not taken.
✗ Branch 43 → 50 not taken.
✗ Branch 44 → 45 not taken.
✗ Branch 44 → 46 not taken.
✗ ((xres == 320) && (yres == 200)) || /* FT/Dig */
2083
0/4
✗ Branch 45 → 46 not taken.
✗ Branch 45 → 50 not taken.
✗ Branch 46 → 47 not taken.
✗ Branch 46 → 48 not taken.
✗ ((xres == 640) && (yres == 272)) || /* SotE */
2084
0/4
✗ Branch 47 → 48 not taken.
✗ Branch 47 → 50 not taken.
✗ Branch 48 → 49 not taken.
✗ Branch 48 → 51 not taken.
✗ ((xres == 640) && (yres == 350)) || /* MotS */
2085
0/2
✗ Branch 49 → 50 not taken.
✗ Branch 49 → 51 not taken.
✗ ((xres == 640) && (yres == 480))) {
2086 ✗ ctx->have_dimensions = 1;
2087 }
2088
2089 ✗ xres = FFMAX(xres, ctx->width);
2090 ✗ yres = FFMAX(yres, ctx->height);
2091 }
2092
2093
0/12
✗ Branch 52 → 53 not taken.
✗ Branch 52 → 54 not taken.
✗ Branch 55 → 56 not taken.
✗ Branch 55 → 62 not taken.
✗ Branch 56 → 57 not taken.
✗ Branch 56 → 58 not taken.
✗ Branch 59 → 60 not taken.
✗ Branch 59 → 62 not taken.
✗ Branch 60 → 61 not taken.
✗ Branch 60 → 62 not taken.
✗ Branch 61 → 62 not taken.
✗ Branch 61 → 63 not taken.
✗ if ((xres < (fsc ? 8 : 1)) || (yres < (fsc ? 8 : 1)) || (xres > 640) || (yres > 480))
2094 ✗ return AVERROR_INVALIDDATA;
2095
2096
0/4
✗ Branch 63 → 64 not taken.
✗ Branch 63 → 65 not taken.
✗ Branch 64 → 65 not taken.
✗ Branch 64 → 73 not taken.
✗ if (ctx->width < xres || ctx->height < yres) {
2097 ✗ int ret = ff_set_dimensions(ctx->avctx, xres, yres);
2098
0/2
✗ Branch 66 → 67 not taken.
✗ Branch 66 → 68 not taken.
✗ if (ret < 0)
2099 ✗ return ret;
2100 ✗ init_sizes(ctx, xres, yres);
2101
0/2
✗ Branch 70 → 71 not taken.
✗ Branch 70 → 73 not taken.
✗ if (init_buffers(ctx)) {
2102 ✗ av_log(ctx->avctx, AV_LOG_ERROR, "Error resizing buffers.\n");
2103 ✗ return AVERROR(ENOMEM);
2104 }
2105 }
2106 } else {
2107 /* for codec37/47/48, return error for frames larger than the canvas, it's also
2108 * what the DOS engines do.
2109 */
2110
0/8
✗ Branch 74 → 75 not taken.
✗ Branch 74 → 77 not taken.
✗ Branch 75 → 76 not taken.
✗ Branch 75 → 77 not taken.
✗ Branch 76 → 77 not taken.
✗ Branch 76 → 79 not taken.
✗ Branch 77 → 78 not taken.
✗ Branch 77 → 79 not taken.
✗ if (((w > ctx->width) || (h > ctx->height) || (w * h > ctx->buf_size)) && fsc)
2111 ✗ return AVERROR_INVALIDDATA;
2112 }
2113
2114 /* users of codecs>=37 are subversion 2, enforce that for STOR/FTCH */
2115
0/4
✗ Branch 79 → 80 not taken.
✗ Branch 79 → 82 not taken.
✗ Branch 80 → 81 not taken.
✗ Branch 80 → 82 not taken.
✗ if (fsc && ctx->subversion < 2) {
2116 ✗ ctx->subversion = 2;
2117 ✗ ctx->stor_size = 0; /* invalidate existing data */
2118 }
2119
2120 /* clear the main buffer on the first fob */
2121
0/2
✗ Branch 82 → 83 not taken.
✗ Branch 82 → 85 not taken.
✗ if (ctx->first_fob) {
2122 ✗ ctx->first_fob = 0;
2123
0/2
✗ Branch 83 → 84 not taken.
✗ Branch 83 → 85 not taken.
✗ if (!fsc)
2124 ✗ memset(ctx->fbuf, 0, ctx->frm0_size);
2125 }
2126
2127 ✗ left += xoff;
2128 ✗ top += yoff;
2129
2130
0/12
✗ Branch 85 → 86 not taken.
✗ Branch 85 → 87 not taken.
✗ Branch 85 → 88 not taken.
✗ Branch 85 → 89 not taken.
✗ Branch 85 → 90 not taken.
✗ Branch 85 → 91 not taken.
✗ Branch 85 → 92 not taken.
✗ Branch 85 → 93 not taken.
✗ Branch 85 → 94 not taken.
✗ Branch 85 → 95 not taken.
✗ Branch 85 → 96 not taken.
✗ Branch 85 → 97 not taken.
✗ switch (codec) {
2131 ✗ case 1:
2132 case 3:
2133 ✗ return old_codec1(ctx, gb, top, left, w, h, codec == 3);
2134 ✗ case 2:
2135 ✗ return old_codec2(ctx, gb, top, left, w, h);
2136 ✗ case 4:
2137 case 5:
2138 case 33:
2139 case 34:
2140 ✗ return old_codec4(ctx, gb, top, left, w, h, param, parm2, codec);
2141 ✗ case 20:
2142 ✗ return old_codec20(ctx, gb, top, left, w, h);
2143 ✗ case 21:
2144 ✗ return old_codec21(ctx, gb, top, left, w, h);
2145 ✗ case 23:
2146 ✗ return old_codec23(ctx, gb, top, left, w, h, param, parm2);
2147 ✗ case 31:
2148 case 32:
2149 ✗ return old_codec31(ctx, gb, top, left, w, h, param, (codec == 32));
2150 ✗ case 37:
2151 ✗ return old_codec37(ctx, gb, top, left, w, h); break;
2152 ✗ case 45:
2153 ✗ old_codec45(ctx, gb, top, left, 0); break;
2154 ✗ case 47:
2155 ✗ return old_codec47(ctx, gb, top, left, w, h); break;
2156 ✗ case 48:
2157 ✗ return old_codec48(ctx, gb, top, left, w, h); break;
2158 ✗ default:
2159 ✗ avpriv_request_sample(ctx->avctx, "Subcodec %d", codec);
2160 ✗ ctx->frame->flags |= AV_FRAME_FLAG_CORRUPT;
2161 ✗ break;
2162 }
2163 ✗ return 0;
2164 }
2165
2166 ✗ static int process_ftch(SANMVideoContext *ctx, int size)
2167 {
2168 int xoff, yoff, ret;
2169 GetByteContext gb;
2170
2171 /* FTCH defines additional x/y offsets */
2172
0/2
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 7 not taken.
✗ if (size == 6) {
2173 ✗ bytestream2_skip(&ctx->gb, 2);
2174 ✗ xoff = bytestream2_get_le16u(&ctx->gb);
2175 ✗ yoff = bytestream2_get_le16u(&ctx->gb);
2176
0/2
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 16 not taken.
✗ } else if (size == 12) {
2177
0/2
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 12 not taken.
✗ av_assert0(bytestream2_get_bytes_left(&ctx->gb) >= 12);
2178 ✗ bytestream2_skip(&ctx->gb, 4);
2179 ✗ xoff = bytestream2_get_be32u(&ctx->gb);
2180 ✗ yoff = bytestream2_get_be32u(&ctx->gb);
2181 } else
2182 ✗ return 1;
2183
2184
0/2
✗ Branch 17 → 18 not taken.
✗ Branch 17 → 24 not taken.
✗ if (ctx->stor_size > 0) {
2185 /* decode the stored FOBJ */
2186 ✗ uint8_t *bitstream = av_malloc(ctx->stor_size + AV_INPUT_BUFFER_PADDING_SIZE);
2187
0/2
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 21 not taken.
✗ if (!bitstream)
2188 ✗ return AVERROR(ENOMEM);
2189 ✗ memcpy(bitstream, ctx->stored_frame, ctx->stor_size);
2190 ✗ bytestream2_init(&gb, bitstream, ctx->stor_size);
2191 ✗ ret = process_frame_obj(ctx, &gb, xoff, yoff);
2192 ✗ av_free(bitstream);
2193 } else {
2194 /* this happens a lot in RA1: The individual files are meant to
2195 * be played in sequence, with some referencing objects STORed
2196 * by previous files, e.g. the cockpit codec21 object in RA1 LVL8.
2197 * But spamming the log with errors is also not helpful, so
2198 * here we simply ignore this case. Return 1 to indicate that
2199 * there was no valid image fetched.
2200 */
2201 ✗ ret = 1;
2202 }
2203 ✗ return ret;
2204 }
2205
2206 ✗ static int process_xpal(SANMVideoContext *ctx, int size)
2207 {
2208 ✗ int16_t *dp = ctx->delta_pal;
2209 ✗ uint32_t *pal = ctx->pal;
2210 uint16_t cmd;
2211 uint8_t c[3];
2212 int i, j;
2213
2214
0/2
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 4 not taken.
✗ if (size < 4)
2215 ✗ return AVERROR_INVALIDDATA;
2216 ✗ bytestream2_skip(&ctx->gb, 2);
2217 ✗ cmd = bytestream2_get_be16(&ctx->gb);
2218 ✗ size -= 4;
2219
2220
0/2
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 13 not taken.
✗ if (cmd == 1) {
2221
0/2
✗ Branch 12 → 8 not taken.
✗ Branch 12 → 32 not taken.
✗ for (i = 0; i < PALETTE_DELTA; i += 3) {
2222
0/2
✗ Branch 10 → 9 not taken.
✗ Branch 10 → 11 not taken.
✗ for (j = 0; j < 3; j++) {
2223 ✗ ctx->shift_pal[i + j] += dp[i + j];
2224 ✗ c[j] = av_clip_uint8(ctx->shift_pal[i + j] >> 7) & 0xFFU;
2225 }
2226 ✗ *pal++ = 0xFFU << 24 | c[0] << 16 | c[1] << 8 | c[2];
2227 }
2228
0/4
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 15 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 32 not taken.
✗ } else if (cmd == 0 || cmd == 2) {
2229
0/2
✗ Branch 15 → 16 not taken.
✗ Branch 15 → 18 not taken.
✗ if (size < PALETTE_DELTA * 2) {
2230 ✗ av_log(ctx->avctx, AV_LOG_ERROR,
2231 "Incorrect palette change block size %"PRIu32".\n", size);
2232 ✗ return AVERROR_INVALIDDATA;
2233 }
2234
0/2
✗ Branch 21 → 19 not taken.
✗ Branch 21 → 22 not taken.
✗ for (i = 0; i < PALETTE_DELTA; i++)
2235 ✗ dp[i] = bytestream2_get_le16u(&ctx->gb);
2236 ✗ size -= PALETTE_DELTA * 2;
2237
2238
0/2
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 29 not taken.
✗ if (size >= PALETTE_SIZE * 3) {
2239
0/2
✗ Branch 26 → 24 not taken.
✗ Branch 26 → 27 not taken.
✗ for (i = 0; i < PALETTE_SIZE; i++)
2240 ✗ ctx->pal[i] = 0xFFU << 24 | bytestream2_get_be24u(&ctx->gb);
2241
0/2
✗ Branch 27 → 28 not taken.
✗ Branch 27 → 29 not taken.
✗ if (ctx->subversion < 2)
2242 ✗ ctx->pal[0] = 0xFFU << 24;
2243 }
2244
0/2
✗ Branch 31 → 30 not taken.
✗ Branch 31 → 32 not taken.
✗ for (i = 0, j = 0; i < PALETTE_DELTA; i += 3, j++) {
2245 ✗ ctx->shift_pal[i + 0] = (((ctx->pal[j]) >> 16) & 0xFFU) << 7;
2246 ✗ ctx->shift_pal[i + 1] = (((ctx->pal[j]) >> 8) & 0xFFU) << 7;
2247 ✗ ctx->shift_pal[i + 2] = (((ctx->pal[j]) >> 0) & 0xFFU) << 7;
2248 }
2249 }
2250 ✗ return 0;
2251 }
2252
2253 ✗ static int bl16_decode_0(SANMVideoContext *ctx)
2254 {
2255 ✗ uint16_t *frm = ctx->frm0;
2256 int x, y;
2257
2258
0/2
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 6 not taken.
✗ if (bytestream2_get_bytes_left(&ctx->gb) < ctx->width * ctx->height * 2) {
2259 ✗ av_log(ctx->avctx, AV_LOG_ERROR, "Insufficient data for raw frame.\n");
2260 ✗ return AVERROR_INVALIDDATA;
2261 }
2262
0/2
✗ Branch 12 → 7 not taken.
✗ Branch 12 → 13 not taken.
✗ for (y = 0; y < ctx->height; y++) {
2263
0/2
✗ Branch 10 → 8 not taken.
✗ Branch 10 → 11 not taken.
✗ for (x = 0; x < ctx->width; x++)
2264 ✗ frm[x] = bytestream2_get_le16u(&ctx->gb);
2265 ✗ frm += ctx->pitch;
2266 }
2267 ✗ return 0;
2268 }
2269
2270 /* BL16 pixel interpolation function, see tgsmush.dll c690 */
2271 ✗ static inline uint16_t bl16_c1_avg_col(uint16_t c1, uint16_t c2)
2272 {
2273 ✗ return (((c2 & 0x07e0) + (c1 & 0x07e0)) & 0x00fc0) |
2274 ✗ (((c2 & 0xf800) + (c1 & 0xf800)) & 0x1f000) |
2275 ✗ (((c2 & 0x001f) + (c1 & 0x001f))) >> 1;
2276 }
2277
2278 /* Quarter-sized keyframe encoded as stream of 16bit pixel values. Interpolate
2279 * missing pixels by averaging the colors of immediate neighbours.
2280 * Identical to codec47_comp1() but with 16bit-pixels. tgsmush.dll c6f0
2281 */
2282 ✗ static int bl16_decode_1(SANMVideoContext *ctx)
2283 {
2284 uint16_t hh, hw, hw1, c1, c2, *dst1, *dst2;
2285
2286 ✗ hh = (ctx->height + 1) >> 1;
2287 ✗ hw1 = (ctx->width - 1) >> 1;
2288
0/4
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 5 not taken.
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 6 not taken.
✗ if (!hw1 || (bytestream2_get_bytes_left(&ctx->gb) < (hh * hw1 * 2)))
2289 ✗ return AVERROR_INVALIDDATA;
2290 ✗ dst1 = (uint16_t *)ctx->frm0 + ctx->pitch; /* start with line 1 */
2291
0/2
✗ Branch 14 → 7 not taken.
✗ Branch 14 → 15 not taken.
✗ while (hh--) {
2292 ✗ hw = hw1;
2293 ✗ c1 = bytestream2_get_le16u(&ctx->gb);
2294 ✗ dst1[0] = c1;
2295 ✗ dst1[1] = c1;
2296 ✗ dst2 = dst1 + 2;
2297
0/2
✗ Branch 12 → 9 not taken.
✗ Branch 12 → 13 not taken.
✗ while (--hw) {
2298 ✗ c2 = bytestream2_get_le16u(&ctx->gb);
2299 ✗ *dst2++ = bl16_c1_avg_col(c1, c2);
2300 ✗ *dst2++ = c2;
2301 ✗ c1 = c2;
2302 }
2303 ✗ dst1 += ctx->pitch * 2; /* skip to overnext line */
2304 }
2305 /* line 0 is a copy of line 1 */
2306 ✗ memcpy(ctx->frm0, ctx->frm0 + ctx->pitch, ctx->pitch);
2307
2308 /* complete the skipped lines by averaging from the pixels in the lines
2309 * above and below
2310 */
2311 ✗ dst1 = ctx->frm0 + (ctx->pitch * 2);
2312 ✗ hh = (ctx->height - 1) >> 1;
2313
0/2
✗ Branch 21 → 16 not taken.
✗ Branch 21 → 22 not taken.
✗ while (hh--) {
2314 ✗ hw = ctx->width;
2315 ✗ dst2 = dst1;
2316
0/2
✗ Branch 19 → 17 not taken.
✗ Branch 19 → 20 not taken.
✗ while (hw--) {
2317 ✗ c1 = *(dst2 - ctx->pitch); /* pixel from line above */
2318 ✗ c2 = *(dst2 + ctx->pitch); /* pixel from line below */
2319 ✗ *dst2++ = bl16_c1_avg_col(c1, c2);
2320 }
2321 ✗ dst1 += ctx->pitch * 2;
2322 }
2323 ✗ return 0;
2324 }
2325
2326 42964 static void copy_block(uint16_t *pdest, uint16_t *psrc, int block_size, ptrdiff_t pitch)
2327 {
2328 42964 uint8_t *dst = (uint8_t *)pdest;
2329 42964 uint8_t *src = (uint8_t *)psrc;
2330 42964 ptrdiff_t stride = pitch * 2;
2331
2332
3/4
✓ Branch 2 → 3 taken 14526 times.
✓ Branch 2 → 5 taken 12400 times.
✓ Branch 2 → 7 taken 16038 times.
✗ Branch 2 → 9 not taken.
42964 switch (block_size) {
2333 14526 case 2:
2334 14526 copy_block4(dst, src, stride, stride, 2);
2335 14526 break;
2336 12400 case 4:
2337 12400 copy_block8(dst, src, stride, stride, 4);
2338 12400 break;
2339 16038 case 8:
2340 16038 copy_block16(dst, src, stride, stride, 8);
2341 16038 break;
2342 }
2343 42964 }
2344
2345 7913 static void fill_block(uint16_t *pdest, uint16_t color, int block_size, ptrdiff_t pitch)
2346 {
2347 int x, y;
2348
2349 7913 pitch -= block_size;
2350
2/2
✓ Branch 7 → 3 taken 30438 times.
✓ Branch 7 → 8 taken 7913 times.
38351 for (y = 0; y < block_size; y++, pdest += pitch)
2351
2/2
✓ Branch 5 → 4 taken 149540 times.
✓ Branch 5 → 6 taken 30438 times.
179978 for (x = 0; x < block_size; x++)
2352 149540 *pdest++ = color;
2353 7913 }
2354
2355 8368 static int draw_glyph(SANMVideoContext *ctx, uint16_t *dst, int index,
2356 uint16_t fg_color, uint16_t bg_color, int block_size,
2357 ptrdiff_t pitch)
2358 {
2359 int8_t *pglyph;
2360 8368 uint16_t colors[2] = { fg_color, bg_color };
2361 int x, y;
2362
2363
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 8368 times.
8368 if (index >= NGLYPHS) {
2364 ✗ av_log(ctx->avctx, AV_LOG_ERROR, "Ignoring nonexistent glyph #%u.\n", index);
2365 ✗ return AVERROR_INVALIDDATA;
2366 }
2367
2368
2/2
✓ Branch 5 → 6 taken 1158 times.
✓ Branch 5 → 7 taken 7210 times.
8368 pglyph = block_size == 8 ? ctx->p8x8glyphs[index] : ctx->p4x4glyphs[index];
2369 8368 pitch -= block_size;
2370
2371
2/2
✓ Branch 13 → 9 taken 38104 times.
✓ Branch 13 → 14 taken 8368 times.
46472 for (y = 0; y < block_size; y++, dst += pitch)
2372
2/2
✓ Branch 11 → 10 taken 189472 times.
✓ Branch 11 → 12 taken 38104 times.
227576 for (x = 0; x < block_size; x++)
2373 189472 *dst++ = colors[*pglyph++];
2374 8368 return 0;
2375 }
2376
2377 8029 static int opcode_0xf7(SANMVideoContext *ctx, int cx, int cy, int block_size, ptrdiff_t pitch)
2378 {
2379 8029 uint16_t *dst = ctx->frm0 + cx + cy * ctx->pitch;
2380
2381
2/2
✓ Branch 2 → 3 taken 825 times.
✓ Branch 2 → 8 taken 7204 times.
8029 if (block_size == 2) {
2382 uint32_t indices;
2383
2384
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 825 times.
825 if (bytestream2_get_bytes_left(&ctx->gb) < 4)
2385 ✗ return AVERROR_INVALIDDATA;
2386
2387 825 indices = bytestream2_get_le32u(&ctx->gb);
2388 825 dst[0] = ctx->codebook[indices & 0xFF];
2389 825 indices >>= 8;
2390 825 dst[1] = ctx->codebook[indices & 0xFF];
2391 825 indices >>= 8;
2392 825 dst[pitch] = ctx->codebook[indices & 0xFF];
2393 825 indices >>= 8;
2394 825 dst[pitch + 1] = ctx->codebook[indices & 0xFF];
2395 } else {
2396 uint16_t fgcolor, bgcolor;
2397 int glyph;
2398
2399
2/2
✓ Branch 9 → 10 taken 1 time.
✓ Branch 9 → 11 taken 7203 times.
7204 if (bytestream2_get_bytes_left(&ctx->gb) < 3)
2400 1 return AVERROR_INVALIDDATA;
2401
2402 7203 glyph = bytestream2_get_byteu(&ctx->gb);
2403 7203 bgcolor = ctx->codebook[bytestream2_get_byteu(&ctx->gb)];
2404 7203 fgcolor = ctx->codebook[bytestream2_get_byteu(&ctx->gb)];
2405
2406 7203 draw_glyph(ctx, dst, glyph, fgcolor, bgcolor, block_size, pitch);
2407 }
2408 8028 return 0;
2409 }
2410
2411 1169 static int opcode_0xf8(SANMVideoContext *ctx, int cx, int cy, int block_size, ptrdiff_t pitch)
2412 {
2413 1169 uint16_t *dst = ctx->frm0 + cx + cy * ctx->pitch;
2414
2415
2/2
✓ Branch 2 → 3 taken 4 times.
✓ Branch 2 → 11 taken 1165 times.
1169 if (block_size == 2) {
2416
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 4 times.
4 if (bytestream2_get_bytes_left(&ctx->gb) < 8)
2417 ✗ return AVERROR_INVALIDDATA;
2418
2419 4 dst[0] = bytestream2_get_le16u(&ctx->gb);
2420 4 dst[1] = bytestream2_get_le16u(&ctx->gb);
2421 4 dst[pitch] = bytestream2_get_le16u(&ctx->gb);
2422 4 dst[pitch + 1] = bytestream2_get_le16u(&ctx->gb);
2423 } else {
2424 uint16_t fgcolor, bgcolor;
2425 int glyph;
2426
2427
1/2
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 1165 times.
1165 if (bytestream2_get_bytes_left(&ctx->gb) < 5)
2428 ✗ return AVERROR_INVALIDDATA;
2429
2430 1165 glyph = bytestream2_get_byteu(&ctx->gb);
2431 1165 bgcolor = bytestream2_get_le16u(&ctx->gb);
2432 1165 fgcolor = bytestream2_get_le16u(&ctx->gb);
2433
2434 1165 draw_glyph(ctx, dst, glyph, fgcolor, bgcolor, block_size, pitch);
2435 }
2436 1169 return 0;
2437 }
2438
2439 30376 static int good_mvec(SANMVideoContext *ctx, int cx, int cy, int mx, int my,
2440 int block_size)
2441 {
2442 30376 int start_pos = cx + mx + (cy + my) * ctx->pitch;
2443 30376 int end_pos = start_pos + (block_size - 1) * (ctx->pitch + 1);
2444
2445
2/4
✓ Branch 2 → 3 taken 30376 times.
✗ Branch 2 → 5 not taken.
✓ Branch 3 → 4 taken 30376 times.
✗ Branch 3 → 5 not taken.
30376 int good = start_pos >= 0 && end_pos < (ctx->buf_size >> 1);
2446
2447
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 30376 times.
30376 if (!good)
2448 ✗ av_log(ctx->avctx, AV_LOG_ERROR,
2449 "Ignoring invalid motion vector (%i, %i)->(%u, %u), block size = %u\n",
2450 cx + mx, cy + my, cx, cy, block_size);
2451
2452 30376 return good;
2453 }
2454
2455 71636 static int bl16_block(SANMVideoContext *ctx, int cx, int cy, int blk_size)
2456 {
2457 int16_t mx, my, index;
2458 int opcode;
2459
2460
2/2
✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 5 taken 71635 times.
71636 if (bytestream2_get_bytes_left(&ctx->gb) < 1)
2461 1 return AVERROR_INVALIDDATA;
2462
2463 71635 opcode = bytestream2_get_byteu(&ctx->gb);
2464
2465
9/9
✓ Branch 6 → 7 taken 28212 times.
✓ Branch 6 → 13 taken 2164 times.
✓ Branch 6 → 21 taken 12588 times.
✓ Branch 6 → 23 taken 8029 times.
✓ Branch 6 → 25 taken 1169 times.
✓ Branch 6 → 27 taken 315 times.
✓ Branch 6 → 29 taken 5496 times.
✓ Branch 6 → 35 taken 2102 times.
✓ Branch 6 → 41 taken 11560 times.
71635 switch (opcode) {
2466 28212 default:
2467 28212 mx = c47_mv[opcode][0];
2468 28212 my = c47_mv[opcode][1];
2469
2470 /* The original implementation of this codec precomputes a table
2471 * of int16_t of all motion vectors a for given image width.
2472 * For widths starting at 762 pixels, the calculation of
2473 * mv table indices 1+ and 255- overflow the int16_t, inverting the
2474 * sign of the offset. This is actively exploited in e.g. the
2475 * "jonesopn_8.snm" video of "Indiana Jones and the Infernal Machine".
2476 * Therefore let the overflow happen and extract x/y components from
2477 * the new value.
2478 */
2479
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 28212 times.
28212 if (ctx->width > 761) {
2480 ✗ index = (int16_t)(my * ctx->width + mx);
2481 ✗ mx = index % ctx->width;
2482 ✗ my = index / ctx->width;
2483 }
2484
1/2
✓ Branch 10 → 11 taken 28212 times.
✗ Branch 10 → 12 not taken.
28212 if (good_mvec(ctx, cx, cy, mx, my, blk_size)) {
2485 28212 copy_block(ctx->frm0 + cx + ctx->pitch * cy,
2486 28212 ctx->frm2 + cx + mx + ctx->pitch * (cy + my),
2487 blk_size, ctx->pitch);
2488 }
2489 28212 break;
2490 2164 case 0xF5:
2491
1/2
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 2164 times.
2164 if (bytestream2_get_bytes_left(&ctx->gb) < 2)
2492 ✗ return AVERROR_INVALIDDATA;
2493 2164 index = bytestream2_get_le16u(&ctx->gb);
2494
2495 2164 mx = index % ctx->width;
2496 2164 my = index / ctx->width;
2497
2498
1/2
✓ Branch 18 → 19 taken 2164 times.
✗ Branch 18 → 20 not taken.
2164 if (good_mvec(ctx, cx, cy, mx, my, blk_size)) {
2499 2164 copy_block(ctx->frm0 + cx + ctx->pitch * cy,
2500 2164 ctx->frm2 + cx + mx + ctx->pitch * (cy + my),
2501 blk_size, ctx->pitch);
2502 }
2503 2164 break;
2504 12588 case 0xF6:
2505 12588 copy_block(ctx->frm0 + cx + ctx->pitch * cy,
2506 12588 ctx->frm1 + cx + ctx->pitch * cy,
2507 blk_size, ctx->pitch);
2508 12588 break;
2509 8029 case 0xF7:
2510 8029 opcode_0xf7(ctx, cx, cy, blk_size, ctx->pitch);
2511 8029 break;
2512
2513 1169 case 0xF8:
2514 1169 opcode_0xf8(ctx, cx, cy, blk_size, ctx->pitch);
2515 1169 break;
2516 315 case 0xF9:
2517 case 0xFA:
2518 case 0xFB:
2519 case 0xFC:
2520 315 fill_block(ctx->frm0 + cx + cy * ctx->pitch,
2521 315 ctx->small_codebook[opcode - 0xf9], blk_size, ctx->pitch);
2522 315 break;
2523 5496 case 0xFD:
2524
1/2
✗ Branch 30 → 31 not taken.
✓ Branch 30 → 32 taken 5496 times.
5496 if (bytestream2_get_bytes_left(&ctx->gb) < 1)
2525 ✗ return AVERROR_INVALIDDATA;
2526 5496 fill_block(ctx->frm0 + cx + cy * ctx->pitch,
2527 5496 ctx->codebook[bytestream2_get_byteu(&ctx->gb)], blk_size, ctx->pitch);
2528 5496 break;
2529 2102 case 0xFE:
2530
1/2
✗ Branch 36 → 37 not taken.
✓ Branch 36 → 38 taken 2102 times.
2102 if (bytestream2_get_bytes_left(&ctx->gb) < 2)
2531 ✗ return AVERROR_INVALIDDATA;
2532 2102 fill_block(ctx->frm0 + cx + cy * ctx->pitch,
2533 2102 bytestream2_get_le16u(&ctx->gb), blk_size, ctx->pitch);
2534 2102 break;
2535 11560 case 0xFF:
2536
1/2
✗ Branch 41 → 42 not taken.
✓ Branch 41 → 43 taken 11560 times.
11560 if (blk_size == 2) {
2537 ✗ opcode_0xf8(ctx, cx, cy, blk_size, ctx->pitch);
2538 } else {
2539 11560 blk_size >>= 1;
2540
1/2
✗ Branch 44 → 45 not taken.
✓ Branch 44 → 46 taken 11560 times.
11560 if (bl16_block(ctx, cx, cy, blk_size))
2541 ✗ return AVERROR_INVALIDDATA;
2542
1/2
✗ Branch 47 → 48 not taken.
✓ Branch 47 → 49 taken 11560 times.
11560 if (bl16_block(ctx, cx + blk_size, cy, blk_size))
2543 ✗ return AVERROR_INVALIDDATA;
2544
1/2
✗ Branch 50 → 51 not taken.
✓ Branch 50 → 52 taken 11560 times.
11560 if (bl16_block(ctx, cx, cy + blk_size, blk_size))
2545 ✗ return AVERROR_INVALIDDATA;
2546
1/2
✗ Branch 53 → 54 not taken.
✓ Branch 53 → 55 taken 11560 times.
11560 if (bl16_block(ctx, cx + blk_size, cy + blk_size, blk_size))
2547 ✗ return AVERROR_INVALIDDATA;
2548 }
2549 11560 break;
2550 }
2551 71635 return 0;
2552 }
2553
2554 6 static int bl16_decode_2(SANMVideoContext *ctx)
2555 {
2556 int cx, cy, ret;
2557
2558
2/2
✓ Branch 10 → 3 taken 318 times.
✓ Branch 10 → 11 taken 5 times.
323 for (cy = 0; cy < ctx->aligned_height; cy += 8)
2559
2/2
✓ Branch 8 → 4 taken 25396 times.
✓ Branch 8 → 9 taken 317 times.
25713 for (cx = 0; cx < ctx->aligned_width; cx += 8)
2560
2/2
✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 7 taken 25395 times.
25396 if (ret = bl16_block(ctx, cx, cy, 8))
2561 1 return ret;
2562
2563 5 return 0;
2564 }
2565
2566 1 static int bl16_decode_5(SANMVideoContext *ctx, int rle_size)
2567 {
2568 #if HAVE_BIGENDIAN
2569 uint16_t *frm;
2570 int npixels;
2571 #endif
2572 1 uint8_t *dst = (uint8_t*)ctx->frm0;
2573
2574
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 1 time.
1 if (rle_decode(ctx, &ctx->gb, dst, rle_size))
2575 ✗ return AVERROR_INVALIDDATA;
2576
2577 #if HAVE_BIGENDIAN
2578 npixels = ctx->npixels;
2579 frm = ctx->frm0;
2580 while (npixels--) {
2581 *frm = av_bswap16(*frm);
2582 frm++;
2583 }
2584 #endif
2585
2586 1 return 0;
2587 }
2588
2589 ✗ static int bl16_decode_6(SANMVideoContext *ctx)
2590 {
2591 ✗ int npixels = ctx->npixels;
2592 ✗ uint16_t *frm = ctx->frm0;
2593
2594
0/2
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 6 not taken.
✗ if (bytestream2_get_bytes_left(&ctx->gb) < npixels) {
2595 ✗ av_log(ctx->avctx, AV_LOG_ERROR, "Insufficient data for frame.\n");
2596 ✗ return AVERROR_INVALIDDATA;
2597 }
2598
0/2
✗ Branch 9 → 7 not taken.
✗ Branch 9 → 10 not taken.
✗ while (npixels--)
2599 ✗ *frm++ = ctx->codebook[bytestream2_get_byteu(&ctx->gb)];
2600
2601 ✗ return 0;
2602 }
2603
2604 /* Quarter-sized keyframe encoded as stream of codebook indices. Interpolate
2605 * missing pixels by averaging the colors of immediate neighbours.
2606 * Identical to codec47_comp1(), but without the interpolation table.
2607 * tgsmush.dll c6f0
2608 */
2609 ✗ static int bl16_decode_7(SANMVideoContext *ctx)
2610 {
2611 uint16_t hh, hw, hw1, c1, c2, *dst1, *dst2;
2612
2613 ✗ hh = (ctx->height + 1) >> 1;
2614 ✗ hw1 = (ctx->width - 1) >> 1;
2615
0/4
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 5 not taken.
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 6 not taken.
✗ if (!hw1 || (bytestream2_get_bytes_left(&ctx->gb) < (hh * hw1)))
2616 ✗ return AVERROR_INVALIDDATA;
2617 ✗ dst1 = (uint16_t *)ctx->frm0 + ctx->pitch; /* start with line 1 */
2618
0/2
✗ Branch 14 → 7 not taken.
✗ Branch 14 → 15 not taken.
✗ while (hh--) {
2619 ✗ hw = hw1;
2620 ✗ c1 = ctx->codebook[bytestream2_get_byteu(&ctx->gb)];
2621 ✗ dst1[0] = c1; /* leftmost 2 pixels of a row are identical */
2622 ✗ dst1[1] = c1;
2623 ✗ dst2 = dst1 + 2;
2624
0/2
✗ Branch 12 → 9 not taken.
✗ Branch 12 → 13 not taken.
✗ while (--hw) {
2625 ✗ c2 = ctx->codebook[bytestream2_get_byteu(&ctx->gb)];
2626 ✗ *dst2++ = bl16_c1_avg_col(c1, c2);
2627 ✗ *dst2++ = c2;
2628 ✗ c1 = c2;
2629 }
2630 ✗ dst1 += ctx->pitch * 2; /* skip to overnext line */
2631 }
2632 /* line 0 is a copy of line 1 */
2633 ✗ memcpy(ctx->frm0, ctx->frm0 + ctx->pitch, ctx->pitch);
2634
2635 /* complete the skipped lines by averaging from the pixels in the lines
2636 * above and below.
2637 */
2638 ✗ dst1 = ctx->frm0 + (ctx->pitch * 2);
2639 ✗ hh = (ctx->height - 1) >> 1;
2640
0/2
✗ Branch 21 → 16 not taken.
✗ Branch 21 → 22 not taken.
✗ while (hh--) {
2641 ✗ hw = ctx->width;
2642 ✗ dst2 = dst1;
2643
0/2
✗ Branch 19 → 17 not taken.
✗ Branch 19 → 20 not taken.
✗ while (hw--) {
2644 ✗ c1 = *(dst2 - ctx->pitch); /* pixel from line above */
2645 ✗ c2 = *(dst2 + ctx->pitch); /* pixel from line below */
2646 ✗ *dst2++ = bl16_c1_avg_col(c1, c2);
2647 }
2648 ✗ dst1 += ctx->pitch * 2;
2649 }
2650 ✗ return 0;
2651 }
2652
2653 ✗ static int bl16_decode_8(SANMVideoContext *ctx)
2654 {
2655 ✗ uint16_t *pdest = ctx->frm0;
2656 uint8_t *rsrc;
2657 ✗ long npixels = ctx->npixels;
2658
2659 ✗ av_fast_malloc(&ctx->rle_buf, &ctx->rle_buf_size, npixels);
2660
0/2
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 6 not taken.
✗ if (!ctx->rle_buf) {
2661 ✗ av_log(ctx->avctx, AV_LOG_ERROR, "RLE buffer allocation failed.\n");
2662 ✗ return AVERROR(ENOMEM);
2663 }
2664 ✗ rsrc = ctx->rle_buf;
2665
2666
0/2
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 9 not taken.
✗ if (rle_decode(ctx, &ctx->gb, rsrc, npixels))
2667 ✗ return AVERROR_INVALIDDATA;
2668
2669
0/2
✗ Branch 11 → 10 not taken.
✗ Branch 11 → 12 not taken.
✗ while (npixels--)
2670 ✗ *pdest++ = ctx->codebook[*rsrc++];
2671
2672 ✗ return 0;
2673 }
2674
2675 2 static void fill_frame(uint16_t *pbuf, int buf_size, uint16_t color)
2676 {
2677
1/2
✓ Branch 2 → 3 taken 2 times.
✗ Branch 2 → 4 not taken.
2 if (buf_size--) {
2678 2 *pbuf++ = color;
2679 2 av_memcpy_backptr((uint8_t*)pbuf, 2, 2*buf_size);
2680 }
2681 2 }
2682
2683 15 static int copy_output(SANMVideoContext *ctx, int sanm)
2684 {
2685 uint8_t *dst;
2686
1/2
✓ Branch 2 → 3 taken 15 times.
✗ Branch 2 → 4 not taken.
15 const uint8_t *src = sanm ? (uint8_t *)ctx->frm0 : (uint8_t *)ctx->fbuf;
2687 15 int ret, height = ctx->height;
2688
1/2
✓ Branch 5 → 6 taken 15 times.
✗ Branch 5 → 7 not taken.
15 ptrdiff_t dstpitch, srcpitch = ctx->pitch * (sanm ? sizeof(ctx->frm0[0]) : 1);
2689
2690
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 15 times.
15 if ((ret = ff_get_buffer(ctx->avctx, ctx->frame, 0)) < 0)
2691 ✗ return ret;
2692
2693 15 dst = ctx->frame->data[0];
2694 15 dstpitch = ctx->frame->linesize[0];
2695
2696
2/2
✓ Branch 13 → 12 taken 7200 times.
✓ Branch 13 → 14 taken 15 times.
7215 while (height--) {
2697 7200 memcpy(dst, src, srcpitch);
2698 7200 src += srcpitch;
2699 7200 dst += dstpitch;
2700 }
2701
2702 15 return 0;
2703 }
2704
2705 16 static int decode_bl16(AVCodecContext *avctx,int *got_frame_ptr)
2706 {
2707 16 SANMVideoContext *ctx = avctx->priv_data;
2708 int i, ret, w, h, seq_num, codec, bg_color, rle_output_size, rcode;
2709
2710
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 6 taken 16 times.
16 if ((ret = bytestream2_get_bytes_left(&ctx->gb)) < 560) {
2711 ✗ av_log(ctx->avctx, AV_LOG_ERROR, "Input frame too short (%d bytes).\n",
2712 ret);
2713 ✗ return AVERROR_INVALIDDATA;
2714 }
2715 16 bytestream2_skip(&ctx->gb, 8); // skip pad
2716
2717 16 w = bytestream2_get_le32u(&ctx->gb);
2718 16 h = bytestream2_get_le32u(&ctx->gb);
2719
2720
2/4
✓ Branch 9 → 10 taken 16 times.
✗ Branch 9 → 11 not taken.
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 13 taken 16 times.
16 if (w != ctx->width || h != ctx->height) {
2721 ✗ avpriv_report_missing_feature(ctx->avctx, "Variable size frames");
2722 ✗ return AVERROR_PATCHWELCOME;
2723 }
2724
2725 16 seq_num = bytestream2_get_le16u(&ctx->gb);
2726 16 codec = bytestream2_get_byteu(&ctx->gb);
2727 16 rcode = bytestream2_get_byteu(&ctx->gb);
2728
2729 16 bytestream2_skip(&ctx->gb, 4); // skip pad
2730
2731
2/2
✓ Branch 20 → 18 taken 64 times.
✓ Branch 20 → 21 taken 16 times.
80 for (i = 0; i < 4; i++)
2732 64 ctx->small_codebook[i] = bytestream2_get_le16u(&ctx->gb);
2733 16 bg_color = bytestream2_get_le16u(&ctx->gb);
2734
2735 16 bytestream2_skip(&ctx->gb, 2); // skip pad
2736
2737 16 rle_output_size = bytestream2_get_le32u(&ctx->gb);
2738
1/2
✗ Branch 24 → 25 not taken.
✓ Branch 24 → 27 taken 16 times.
16 if (rle_output_size > w * ctx->aligned_height * 2) {
2739 ✗ av_log(avctx, AV_LOG_WARNING, "bl16 rle size too large, truncated: %d\n",
2740 rle_output_size);
2741 ✗ rle_output_size = w * ctx->aligned_height * 2;
2742 }
2743
2744
2/2
✓ Branch 30 → 28 taken 4096 times.
✓ Branch 30 → 31 taken 16 times.
4112 for (i = 0; i < 256; i++)
2745 4096 ctx->codebook[i] = bytestream2_get_le16u(&ctx->gb);
2746
2747 16 bytestream2_skip(&ctx->gb, 8); // skip pad
2748
2749
2/2
✓ Branch 32 → 33 taken 1 time.
✓ Branch 32 → 35 taken 15 times.
16 if (seq_num == 0) {
2750 1 ctx->frame->flags |= AV_FRAME_FLAG_KEY;
2751 1 ctx->frame->pict_type = AV_PICTURE_TYPE_I;
2752 1 fill_frame(ctx->frm1, ctx->npixels, bg_color);
2753 1 fill_frame(ctx->frm2, ctx->npixels, bg_color);
2754 } else {
2755 15 ctx->frame->flags &= ~AV_FRAME_FLAG_KEY;
2756 15 ctx->frame->pict_type = AV_PICTURE_TYPE_P;
2757 }
2758
2759 16 ret = 0;
2760
3/10
✗ Branch 36 → 37 not taken.
✗ Branch 36 → 38 not taken.
✓ Branch 36 → 39 taken 6 times.
✗ Branch 36 → 40 not taken.
✓ Branch 36 → 41 taken 9 times.
✓ Branch 36 → 42 taken 1 time.
✗ Branch 36 → 43 not taken.
✗ Branch 36 → 44 not taken.
✗ Branch 36 → 45 not taken.
✗ Branch 36 → 46 not taken.
16 switch (codec) {
2761 ✗ case 0: ret = bl16_decode_0(ctx); break;
2762 ✗ case 1: ret = bl16_decode_1(ctx); break;
2763 6 case 2: ret = bl16_decode_2(ctx); break;
2764 ✗ case 3: memcpy(ctx->frm0, ctx->frm2, ctx->frm2_size); break;
2765 9 case 4: memcpy(ctx->frm0, ctx->frm1, ctx->frm1_size); break;
2766 1 case 5: ret = bl16_decode_5(ctx, rle_output_size); break;
2767 ✗ case 6: ret = bl16_decode_6(ctx); break;
2768 ✗ case 7: ret = bl16_decode_7(ctx); break;
2769 ✗ case 8: ret = bl16_decode_8(ctx); break;
2770 ✗ default:
2771 ✗ avpriv_request_sample(ctx->avctx, "Unknown/unsupported compression type %d", codec);
2772 ✗ return AVERROR_PATCHWELCOME;
2773 }
2774
2775
2/2
✓ Branch 48 → 49 taken 1 time.
✓ Branch 48 → 51 taken 15 times.
16 if (ret) {
2776 1 av_log(avctx, AV_LOG_ERROR,
2777 "Subcodec %d: error decoding frame.\n", codec);
2778 1 return ret;
2779 }
2780
2781 15 ret = copy_output(ctx, 1);
2782
2/2
✓ Branch 52 → 53 taken 9 times.
✓ Branch 52 → 54 taken 6 times.
15 if (rcode)
2783 9 rotate_bufs(ctx, rcode);
2784
1/2
✗ Branch 54 → 55 not taken.
✓ Branch 54 → 56 taken 15 times.
15 if (ret)
2785 ✗ return ret;
2786
2787 15 *got_frame_ptr = 1;
2788 15 return 0;
2789 }
2790
2791 ✗ static int decode_anim(AVCodecContext *avctx, int *got_frame_ptr)
2792 {
2793 ✗ SANMVideoContext *ctx = avctx->priv_data;
2794 ✗ int i, ret, to_store = 0, have_img = 0;
2795
2796 ✗ ctx->first_fob = 1;
2797
0/2
✗ Branch 62 → 3 not taken.
✗ Branch 62 → 63 not taken.
✗ while (bytestream2_get_bytes_left(&ctx->gb) >= 8) {
2798 uint32_t sig, size;
2799 int pos;
2800
2801 ✗ sig = bytestream2_get_be32u(&ctx->gb);
2802 ✗ size = bytestream2_get_be32u(&ctx->gb);
2803 ✗ pos = bytestream2_tell(&ctx->gb);
2804
2805
0/2
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 10 not taken.
✗ if (bytestream2_get_bytes_left(&ctx->gb) < size) {
2806 ✗ av_log(avctx, AV_LOG_ERROR, "Incorrect chunk size %"PRIu32".\n", size);
2807 ✗ break;
2808 }
2809
0/6
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 21 not taken.
✗ Branch 10 → 37 not taken.
✗ Branch 10 → 41 not taken.
✗ Branch 10 → 42 not taken.
✗ Branch 10 → 50 not taken.
✗ switch (sig) {
2810 ✗ case MKBETAG('N', 'P', 'A', 'L'):
2811
0/2
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 14 not taken.
✗ if (size != PALETTE_SIZE * 3) {
2812 ✗ av_log(avctx, AV_LOG_ERROR,
2813 "Incorrect palette block size %"PRIu32".\n", size);
2814 ✗ return AVERROR_INVALIDDATA;
2815 }
2816
0/2
✗ Branch 17 → 15 not taken.
✗ Branch 17 → 18 not taken.
✗ for (i = 0; i < PALETTE_SIZE; i++)
2817 ✗ ctx->pal[i] = 0xFFU << 24 | bytestream2_get_be24u(&ctx->gb);
2818
0/2
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 20 not taken.
✗ if (ctx->subversion < 2)
2819 ✗ ctx->pal[0] = 0xFFU << 24;
2820 ✗ break;
2821 ✗ case MKBETAG('F', 'O', 'B', 'J'):
2822
0/2
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 23 not taken.
✗ if (size < 16)
2823 ✗ return AVERROR_INVALIDDATA;
2824 GetByteContext fc;
2825 ✗ bytestream2_init(&fc, ctx->gb.buffer, size);
2826
0/2
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 27 not taken.
✗ if (ret = process_frame_obj(ctx, &fc, 0, 0)) {
2827 ✗ return ret;
2828 }
2829 ✗ have_img = 1;
2830
2831 /* STOR: for ANIMv0/1 store the whole FOBJ datablock, as it
2832 * needs to be replayed on FTCH, since none of the codecs
2833 * it uses work on the full buffer.
2834 * For ANIMv2, it's enough to store the current framebuffer.
2835 */
2836
0/2
✗ Branch 27 → 28 not taken.
✗ Branch 27 → 36 not taken.
✗ if (to_store) {
2837 ✗ to_store = 0;
2838
0/2
✗ Branch 28 → 29 not taken.
✗ Branch 28 → 35 not taken.
✗ if (ctx->subversion < 2) {
2839
0/2
✗ Branch 29 → 30 not taken.
✗ Branch 29 → 33 not taken.
✗ if (size <= ctx->stored_frame_size) {
2840 ✗ bytestream2_seek(&fc, 0, SEEK_SET);
2841 ✗ bytestream2_get_bufferu(&fc, ctx->stored_frame, size);
2842 ✗ ctx->stor_size = size;
2843 } else {
2844 ✗ av_log(avctx, AV_LOG_ERROR, "FOBJ too large for STOR\n");
2845 ✗ ret = AVERROR(ENOMEM);
2846 }
2847 } else {
2848 ✗ memcpy(ctx->stored_frame, ctx->fbuf, ctx->buf_size);
2849 ✗ ctx->stor_size = ctx->buf_size;
2850 }
2851 }
2852 ✗ bytestream2_skip(&ctx->gb, size);
2853 ✗ break;
2854 ✗ case MKBETAG('X', 'P', 'A', 'L'):
2855
0/2
✗ Branch 38 → 39 not taken.
✗ Branch 38 → 40 not taken.
✗ if (ret = process_xpal(ctx, size))
2856 ✗ return ret;
2857 ✗ break;
2858 ✗ case MKBETAG('S', 'T', 'O', 'R'):
2859 ✗ to_store = 1;
2860 ✗ break;
2861 ✗ case MKBETAG('F', 'T', 'C', 'H'):
2862
0/2
✗ Branch 42 → 43 not taken.
✗ Branch 42 → 47 not taken.
✗ if (ctx->subversion < 2) {
2863
0/2
✗ Branch 44 → 45 not taken.
✗ Branch 44 → 46 not taken.
✗ if ((ret = process_ftch(ctx, size)) < 0)
2864 ✗ return ret;
2865 ✗ have_img = (ret == 0) ? 1 : 0;
2866 } else {
2867
0/2
✗ Branch 47 → 48 not taken.
✗ Branch 47 → 49 not taken.
✗ if (ctx->stor_size > 0) {
2868 ✗ memcpy(ctx->fbuf, ctx->stored_frame, ctx->buf_size);
2869 ✗ have_img = 1;
2870 }
2871 }
2872 ✗ break;
2873 ✗ default:
2874 ✗ bytestream2_skip(&ctx->gb, size);
2875 ✗ av_log(avctx, AV_LOG_DEBUG,
2876 "Unknown/unsupported chunk %"PRIx32".\n", sig);
2877 ✗ break;
2878 }
2879
2880 /* the sizes of chunks are usually a multiple of 2. However
2881 * there are a few unaligned FOBJs in RA1 L2PLAY.ANM only (looks
2882 * like a game bug) and IACT audio chunks which have odd sizes
2883 * but are padded with a zero byte.
2884 */
2885 ✗ bytestream2_seek(&ctx->gb, pos + size, SEEK_SET);
2886
0/2
✗ Branch 56 → 57 not taken.
✗ Branch 56 → 60 not taken.
✗ if ((pos + size) & 1) {
2887
0/2
✗ Branch 58 → 59 not taken.
✗ Branch 58 → 60 not taken.
✗ if (bytestream2_peek_byte(&ctx->gb) == 0)
2888 ✗ bytestream2_skip(&ctx->gb, 1);
2889 }
2890 }
2891
2892
0/2
✗ Branch 63 → 64 not taken.
✗ Branch 63 → 68 not taken.
✗ if (have_img) {
2893
0/2
✗ Branch 65 → 66 not taken.
✗ Branch 65 → 67 not taken.
✗ if ((ret = copy_output(ctx, 0)))
2894 ✗ return ret;
2895 ✗ memcpy(ctx->frame->data[1], ctx->pal, 1024);
2896 ✗ *got_frame_ptr = 1;
2897 }
2898 ✗ return 0;
2899 }
2900
2901 16 static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
2902 int *got_frame_ptr, AVPacket *pkt)
2903 {
2904 16 SANMVideoContext *ctx = avctx->priv_data;
2905 int ret;
2906
2907 16 ctx->frame = frame;
2908 16 bytestream2_init(&ctx->gb, pkt->data, pkt->size);
2909
2910
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 16 times.
16 if (!ctx->version) {
2911
0/2
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 10 not taken.
✗ if ((ret = decode_anim(avctx, got_frame_ptr)))
2912 ✗ return ret;
2913 } else {
2914
2/2
✓ Branch 8 → 9 taken 1 time.
✓ Branch 8 → 10 taken 15 times.
16 if ((ret = decode_bl16(avctx, got_frame_ptr)))
2915 1 return ret;
2916 }
2917 15 return pkt->size;
2918 }
2919
2920 const FFCodec ff_sanm_decoder = {
2921 .p.name = "sanm",
2922 CODEC_LONG_NAME("LucasArts SANM/Smush video"),
2923 .p.type = AVMEDIA_TYPE_VIDEO,
2924 .p.id = AV_CODEC_ID_SANM,
2925 .priv_data_size = sizeof(SANMVideoContext),
2926 .init = decode_init,
2927 .close = decode_end,
2928 FF_CODEC_DECODE_CB(decode_frame),
2929 .p.capabilities = AV_CODEC_CAP_DR1,
2930 };
2931