../../../ffmpeg/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
162 / 307
52.8%
Branches:
126 / 326
38.7%
Functions:
4 / 4
100.0%

libavcodec/ffv1_parse.c
Line Branch Exec Source
1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "libavutil/crc.h"
20 #include "libavutil/mem.h"
21 #include "libavutil/pixdesc.h"
22 #include "rangecoder.h"
23 #include "ffv1.h"
24
25 1600 static int read_quant_table(RangeCoder *c, int16_t *quant_table, int scale)
26 {
27 int v;
28 1600 int i = 0;
29 uint8_t state[CONTEXT_SIZE];
30
31 1600 memset(state, 128, sizeof(state));
32
33
2/2
✓ Branch 11 → 3 taken 6253 times.
✓ Branch 11 → 12 taken 1600 times.
7853 for (v = 0; i < 128; v++) {
34 6253 unsigned len = ff_ffv1_get_symbol(c, state, 0) + 1U;
35
36
2/4
✓ Branch 4 → 5 taken 6253 times.
✗ Branch 4 → 6 not taken.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 6253 times.
6253 if (len > 128 - i || !len)
37 ✗ return AVERROR_INVALIDDATA;
38
39
2/2
✓ Branch 9 → 8 taken 204800 times.
✓ Branch 9 → 10 taken 6253 times.
211053 while (len--) {
40 204800 quant_table[i] = scale * v;
41 204800 i++;
42 }
43 }
44
45
2/2
✓ Branch 14 → 13 taken 203200 times.
✓ Branch 14 → 15 taken 1600 times.
204800 for (i = 1; i < 128; i++)
46 203200 quant_table[256 - i] = -quant_table[i];
47 1600 quant_table[128] = -quant_table[127];
48
49 1600 return 2 * v - 1;
50 }
51
52 320 int ff_ffv1_read_quant_tables(RangeCoder *c,
53 int16_t quant_table[MAX_CONTEXT_INPUTS][256])
54 {
55 int i;
56 320 int context_count = 1;
57
58
2/2
✓ Branch 9 → 3 taken 1600 times.
✓ Branch 9 → 10 taken 320 times.
1920 for (i = 0; i < 5; i++) {
59 1600 int ret = read_quant_table(c, quant_table[i], context_count);
60
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 1600 times.
1600 if (ret < 0)
61 ✗ return ret;
62 1600 context_count *= ret;
63
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 1600 times.
1600 if (context_count > 32768U) {
64 ✗ return AVERROR_INVALIDDATA;
65 }
66 }
67 320 return (context_count + 1) / 2;
68 }
69
70 148 int ff_ffv1_read_extra_header(FFV1Context *f)
71 {
72 RangeCoder c;
73 uint8_t state[CONTEXT_SIZE];
74 int ret;
75 uint8_t state2[32][CONTEXT_SIZE];
76 148 unsigned crc = 0;
77
78 148 memset(state2, 128, sizeof(state2));
79 148 memset(state, 128, sizeof(state));
80
81 148 ff_init_range_decoder(&c, f->avctx->extradata, f->avctx->extradata_size);
82 148 ff_build_rac_states(&c, 0.05 * (1LL << 32), 256 - 8);
83
84 148 f->version = ff_ffv1_get_symbol(&c, state, 0);
85
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 8 taken 148 times.
148 if (f->version < 2) {
86 ✗ av_log(f->avctx, AV_LOG_ERROR, "Invalid version in global header\n");
87 ✗ return AVERROR_INVALIDDATA;
88 }
89
1/2
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 11 taken 148 times.
148 if (f->version > 4) {
90 ✗ av_log(f->avctx, AV_LOG_ERROR, "unsupported version %d\n",
91 f->version);
92 ✗ return AVERROR_PATCHWELCOME;
93 }
94 148 f->combined_version = f->version << 16;
95
2/2
✓ Branch 11 → 12 taken 136 times.
✓ Branch 11 → 17 taken 12 times.
148 if (f->version > 2) {
96 136 c.bytestream_end -= 4;
97 136 f->micro_version = ff_ffv1_get_symbol(&c, state, 0);
98
2/4
✓ Branch 13 → 14 taken 136 times.
✗ Branch 13 → 15 not taken.
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 136 times.
136 if (f->micro_version < 0 || f->micro_version > 65535)
99 ✗ return AVERROR_INVALIDDATA;
100 136 f->combined_version += f->micro_version;
101 }
102 148 f->ac = ff_ffv1_get_symbol(&c, state, 0);
103
104
2/2
✓ Branch 18 → 19 taken 65 times.
✓ Branch 18 → 23 taken 83 times.
148 if (f->ac == AC_RANGE_CUSTOM_TAB) {
105
2/2
✓ Branch 22 → 20 taken 16575 times.
✓ Branch 22 → 28 taken 65 times.
16640 for (int i = 1; i < 256; i++)
106 16575 f->state_transition[i] = ff_ffv1_get_symbol(&c, state, 1) + c.one_state[i];
107 } else {
108 RangeCoder rc;
109 83 ff_build_rac_states(&rc, 0.05 * (1LL << 32), 256 - 8);
110
2/2
✓ Branch 26 → 25 taken 21165 times.
✓ Branch 26 → 27 taken 83 times.
21248 for (int i = 1; i < 256; i++)
111 21165 f->state_transition[i] = rc.one_state[i];
112 }
113
114 148 f->colorspace = ff_ffv1_get_symbol(&c, state, 0); //YUV cs type
115 148 f->avctx->bits_per_raw_sample = ff_ffv1_get_symbol(&c, state, 0);
116 148 f->chroma_planes = get_rac(&c, state);
117 148 f->chroma_h_shift = ff_ffv1_get_symbol(&c, state, 0);
118 148 f->chroma_v_shift = ff_ffv1_get_symbol(&c, state, 0);
119 148 f->transparency = get_rac(&c, state);
120 148 f->bayer = (f->colorspace == 2);
121
1/2
✗ Branch 34 → 35 not taken.
✓ Branch 34 → 39 taken 148 times.
148 if (f->bayer) {
122 ✗ f->bayer_order = ff_ffv1_get_symbol(&c, state, 0);
123
0/2
✗ Branch 36 → 37 not taken.
✗ Branch 36 → 39 not taken.
✗ if (f->bayer_order != 0) {
124 ✗ av_log(f->avctx, AV_LOG_ERROR, "Unsupported bayer order %d\n", f->bayer_order);
125 ✗ return AVERROR_PATCHWELCOME;
126 }
127 }
128
1/4
✗ Branch 39 → 40 not taken.
✓ Branch 39 → 41 taken 148 times.
✗ Branch 40 → 41 not taken.
✗ Branch 40 → 42 not taken.
148 f->plane_count = 1 + (f->chroma_planes || f->version<4) + f->transparency + f->bayer;
129 148 f->num_h_slices = 1 + ff_ffv1_get_symbol(&c, state, 0);
130 148 f->num_v_slices = 1 + ff_ffv1_get_symbol(&c, state, 0);
131
132
2/4
✓ Branch 45 → 46 taken 148 times.
✗ Branch 45 → 47 not taken.
✗ Branch 46 → 47 not taken.
✓ Branch 46 → 49 taken 148 times.
148 if (f->chroma_h_shift > 4U || f->chroma_v_shift > 4U) {
133 ✗ av_log(f->avctx, AV_LOG_ERROR, "chroma shift parameters %d %d are invalid\n",
134 f->chroma_h_shift, f->chroma_v_shift);
135 ✗ return AVERROR_INVALIDDATA;
136 }
137
138
2/4
✓ Branch 49 → 50 taken 148 times.
✗ Branch 49 → 53 not taken.
✓ Branch 50 → 51 taken 148 times.
✗ Branch 50 → 53 not taken.
148 if (f->num_h_slices > (unsigned)f->width || !f->num_h_slices ||
139
2/4
✓ Branch 51 → 52 taken 148 times.
✗ Branch 51 → 53 not taken.
✗ Branch 52 → 53 not taken.
✓ Branch 52 → 55 taken 148 times.
148 f->num_v_slices > (unsigned)f->height || !f->num_v_slices
140 ) {
141 ✗ av_log(f->avctx, AV_LOG_ERROR, "slice count invalid\n");
142 ✗ return AVERROR_INVALIDDATA;
143 }
144
145
1/2
✗ Branch 55 → 56 not taken.
✓ Branch 55 → 58 taken 148 times.
148 if (f->num_h_slices > MAX_SLICES / f->num_v_slices) {
146 ✗ av_log(f->avctx, AV_LOG_ERROR, "slice count unsupported\n");
147 ✗ return AVERROR_PATCHWELCOME;
148 }
149
150 148 f->quant_table_count = ff_ffv1_get_symbol(&c, state, 0);
151
2/4
✓ Branch 59 → 60 taken 148 times.
✗ Branch 59 → 61 not taken.
✗ Branch 60 → 61 not taken.
✓ Branch 60 → 63 taken 148 times.
148 if (f->quant_table_count > (unsigned)MAX_QUANT_TABLES || !f->quant_table_count) {
152 ✗ av_log(f->avctx, AV_LOG_ERROR, "quant table count %d is invalid\n", f->quant_table_count);
153 ✗ f->quant_table_count = 0;
154 ✗ return AVERROR_INVALIDDATA;
155 }
156
157
2/2
✓ Branch 69 → 64 taken 296 times.
✓ Branch 69 → 70 taken 148 times.
444 for (int i = 0; i < f->quant_table_count; i++) {
158 296 f->context_count[i] = ff_ffv1_read_quant_tables(&c, f->quant_tables[i]);
159
1/2
✗ Branch 65 → 66 not taken.
✓ Branch 65 → 68 taken 296 times.
296 if (f->context_count[i] < 0) {
160 ✗ av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\n");
161 ✗ return AVERROR_INVALIDDATA;
162 }
163 }
164
1/2
✗ Branch 71 → 72 not taken.
✓ Branch 71 → 73 taken 148 times.
148 if ((ret = ff_ffv1_allocate_initial_states(f)) < 0)
165 ✗ return ret;
166
167
2/2
✓ Branch 87 → 74 taken 296 times.
✓ Branch 87 → 88 taken 148 times.
444 for (int i = 0; i < f->quant_table_count; i++)
168
2/2
✓ Branch 75 → 76 taken 24 times.
✓ Branch 75 → 86 taken 272 times.
296 if (get_rac(&c, state)) {
169
2/2
✓ Branch 85 → 77 taken 151512 times.
✓ Branch 85 → 86 taken 24 times.
151536 for (int j = 0; j < f->context_count[i]; j++)
170
2/2
✓ Branch 83 → 78 taken 4848384 times.
✓ Branch 83 → 84 taken 151512 times.
4999896 for (int k = 0; k < CONTEXT_SIZE; k++) {
171
2/2
✓ Branch 78 → 79 taken 4847616 times.
✓ Branch 78 → 80 taken 768 times.
4848384 int pred = j ? f->initial_states[i][j - 1][k] : 128;
172 4848384 f->initial_states[i][j][k] =
173 4848384 (pred + ff_ffv1_get_symbol(&c, state2[k], 1)) & 0xFF;
174 }
175 }
176
177
2/2
✓ Branch 88 → 89 taken 136 times.
✓ Branch 88 → 98 taken 12 times.
148 if (f->version > 2) {
178 136 f->ec = ff_ffv1_get_symbol(&c, state, 0);
179
2/2
✓ Branch 90 → 91 taken 6 times.
✓ Branch 90 → 92 taken 130 times.
136 if (f->ec >= 2)
180 6 f->crcref = 0x7a8c4079;
181
1/2
✓ Branch 92 → 93 taken 136 times.
✗ Branch 92 → 95 not taken.
136 if (f->combined_version >= 0x30003)
182 136 f->intra = ff_ffv1_get_symbol(&c, state, 0);
183
2/2
✓ Branch 95 → 96 taken 6 times.
✓ Branch 95 → 98 taken 130 times.
136 if (f->combined_version >= 0x40004)
184 6 f->flt = ff_ffv1_get_symbol(&c, state, 0);
185 }
186
187
2/2
✓ Branch 98 → 99 taken 136 times.
✓ Branch 98 → 105 taken 12 times.
148 if (f->version > 2) {
188 unsigned v;
189 272 v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), f->crcref,
190 136 f->avctx->extradata, f->avctx->extradata_size);
191
2/4
✓ Branch 100 → 101 taken 136 times.
✗ Branch 100 → 102 not taken.
✗ Branch 101 → 102 not taken.
✓ Branch 101 → 104 taken 136 times.
136 if (v != f->crcref || f->avctx->extradata_size < 4) {
192 ✗ av_log(f->avctx, AV_LOG_ERROR, "CRC mismatch %X!\n", v);
193 ✗ return AVERROR_INVALIDDATA;
194 }
195 136 crc = AV_RB32(f->avctx->extradata + f->avctx->extradata_size - 4);
196 }
197
198
1/2
✗ Branch 105 → 106 not taken.
✓ Branch 105 → 107 taken 148 times.
148 if (f->avctx->debug & FF_DEBUG_PICT_INFO)
199 ✗ av_log(f->avctx, AV_LOG_DEBUG,
200 "global: ver:%d.%d, coder:%d, colorspace: %d bpr:%d chroma:%d(%d:%d), alpha:%d slices:%dx%d qtabs:%d ec:%d intra:%d CRC:0x%08X\n",
201 f->version, f->micro_version,
202 f->ac,
203 f->colorspace,
204 ✗ f->avctx->bits_per_raw_sample,
205 f->chroma_planes, f->chroma_h_shift, f->chroma_v_shift,
206 f->transparency,
207 f->num_h_slices, f->num_v_slices,
208 f->quant_table_count,
209 f->ec,
210 f->intra,
211 crc
212 );
213 148 return 0;
214 }
215
216 491 int ff_ffv1_parse_header(FFV1Context *f, RangeCoder *c, uint8_t *state)
217 {
218
2/2
✓ Branch 2 → 3 taken 44 times.
✓ Branch 2 → 47 taken 447 times.
491 if (f->version < 2) {
219 int chroma_planes, chroma_h_shift, chroma_v_shift, transparency, colorspace, bits_per_raw_sample;
220 44 unsigned v= ff_ffv1_get_symbol(c, state, 0);
221
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 7 taken 44 times.
44 if (v >= 2) {
222 ✗ av_log(f->avctx, AV_LOG_ERROR, "invalid version %d in ver01 header\n", v);
223 ✗ return AVERROR_INVALIDDATA;
224 }
225 44 f->version = v;
226 44 f->ac = ff_ffv1_get_symbol(c, state, 0);
227
228
1/2
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 17 taken 44 times.
44 if (f->ac == AC_RANGE_CUSTOM_TAB) {
229
0/2
✗ Branch 16 → 10 not taken.
✗ Branch 16 → 22 not taken.
✗ for (int i = 1; i < 256; i++) {
230 ✗ int st = ff_ffv1_get_symbol(c, state, 1) + c->one_state[i];
231
0/4
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 13 not taken.
✗ Branch 12 → 13 not taken.
✗ Branch 12 → 15 not taken.
✗ if (st < 1 || st > 255) {
232 ✗ av_log(f->avctx, AV_LOG_ERROR, "invalid state transition %d\n", st);
233 ✗ return AVERROR_INVALIDDATA;
234 }
235 ✗ f->state_transition[i] = st;
236 }
237 } else {
238 RangeCoder rc;
239 44 ff_build_rac_states(&rc, 0.05 * (1LL << 32), 256 - 8);
240
2/2
✓ Branch 20 → 19 taken 11220 times.
✓ Branch 20 → 21 taken 44 times.
11264 for (int i = 1; i < 256; i++)
241 11220 f->state_transition[i] = rc.one_state[i];
242 }
243
244 44 colorspace = ff_ffv1_get_symbol(c, state, 0); //YUV cs type
245
1/2
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 44 times.
44 bits_per_raw_sample = f->version > 0 ? ff_ffv1_get_symbol(c, state, 0) : f->avctx->bits_per_raw_sample;
246 44 chroma_planes = get_rac(c, state);
247 44 chroma_h_shift = ff_ffv1_get_symbol(c, state, 0);
248 44 chroma_v_shift = ff_ffv1_get_symbol(c, state, 0);
249 44 transparency = get_rac(c, state);
250
2/4
✓ Branch 30 → 31 taken 44 times.
✗ Branch 30 → 33 not taken.
✗ Branch 31 → 32 not taken.
✓ Branch 31 → 33 taken 44 times.
44 if (colorspace == 0 && f->avctx->skip_alpha)
251 ✗ transparency = 0;
252
253
2/2
✓ Branch 33 → 34 taken 32 times.
✓ Branch 33 → 42 taken 12 times.
44 if (f->plane_count) {
254
1/2
✓ Branch 34 → 35 taken 32 times.
✗ Branch 34 → 40 not taken.
32 if (colorspace != f->colorspace ||
255
1/2
✓ Branch 35 → 36 taken 32 times.
✗ Branch 35 → 40 not taken.
32 bits_per_raw_sample != f->avctx->bits_per_raw_sample ||
256
1/2
✓ Branch 36 → 37 taken 32 times.
✗ Branch 36 → 40 not taken.
32 chroma_planes != f->chroma_planes ||
257
1/2
✓ Branch 37 → 38 taken 32 times.
✗ Branch 37 → 40 not taken.
32 chroma_h_shift != f->chroma_h_shift ||
258
1/2
✓ Branch 38 → 39 taken 32 times.
✗ Branch 38 → 40 not taken.
32 chroma_v_shift != f->chroma_v_shift ||
259
1/2
✗ Branch 39 → 40 not taken.
✓ Branch 39 → 42 taken 32 times.
32 transparency != f->transparency) {
260 ✗ av_log(f->avctx, AV_LOG_ERROR, "Invalid change of global parameters\n");
261 ✗ return AVERROR_INVALIDDATA;
262 }
263 }
264
265
2/4
✓ Branch 42 → 43 taken 44 times.
✗ Branch 42 → 44 not taken.
✗ Branch 43 → 44 not taken.
✓ Branch 43 → 46 taken 44 times.
44 if (chroma_h_shift > 4U || chroma_v_shift > 4U) {
266 ✗ av_log(f->avctx, AV_LOG_ERROR, "chroma shift parameters %d %d are invalid\n",
267 chroma_h_shift, chroma_v_shift);
268 ✗ return AVERROR_INVALIDDATA;
269 }
270
271 44 f->colorspace = colorspace;
272 44 f->avctx->bits_per_raw_sample = bits_per_raw_sample;
273 44 f->chroma_planes = chroma_planes;
274 44 f->chroma_h_shift = chroma_h_shift;
275 44 f->chroma_v_shift = chroma_v_shift;
276 44 f->transparency = transparency;
277
278 44 f->plane_count = 2 + f->transparency;
279 }
280
281
2/2
✓ Branch 47 → 48 taken 390 times.
✓ Branch 47 → 159 taken 101 times.
491 if (f->colorspace == 0) {
282
2/4
✓ Branch 48 → 49 taken 390 times.
✗ Branch 48 → 68 not taken.
✗ Branch 49 → 50 not taken.
✓ Branch 49 → 68 taken 390 times.
390 if (!f->transparency && !f->chroma_planes) {
283
0/2
✗ Branch 50 → 51 not taken.
✗ Branch 50 → 52 not taken.
✗ if (f->avctx->bits_per_raw_sample <= 8)
284 ✗ f->pix_fmt = AV_PIX_FMT_GRAY8;
285
0/2
✗ Branch 52 → 53 not taken.
✗ Branch 52 → 54 not taken.
✗ else if (f->avctx->bits_per_raw_sample == 9) {
286 ✗ f->packed_at_lsb = 1;
287 ✗ f->pix_fmt = AV_PIX_FMT_GRAY9;
288
0/2
✗ Branch 54 → 55 not taken.
✗ Branch 54 → 56 not taken.
✗ } else if (f->avctx->bits_per_raw_sample == 10) {
289 ✗ f->packed_at_lsb = 1;
290 ✗ f->pix_fmt = AV_PIX_FMT_GRAY10;
291
0/2
✗ Branch 56 → 57 not taken.
✗ Branch 56 → 58 not taken.
✗ } else if (f->avctx->bits_per_raw_sample == 12) {
292 ✗ f->packed_at_lsb = 1;
293 ✗ f->pix_fmt = AV_PIX_FMT_GRAY12;
294
0/2
✗ Branch 58 → 59 not taken.
✗ Branch 58 → 60 not taken.
✗ } else if (f->avctx->bits_per_raw_sample == 14) {
295 ✗ f->packed_at_lsb = 1;
296 ✗ f->pix_fmt = AV_PIX_FMT_GRAY14;
297
0/2
✗ Branch 60 → 61 not taken.
✗ Branch 60 → 64 not taken.
✗ } else if (f->avctx->bits_per_raw_sample == 16) {
298 ✗ f->packed_at_lsb = 1;
299
0/2
✗ Branch 61 → 62 not taken.
✗ Branch 61 → 63 not taken.
✗ if (f->flt) {
300 ✗ f->pix_fmt = AV_PIX_FMT_GRAYF16;
301 } else
302 ✗ f->pix_fmt = AV_PIX_FMT_GRAY16;
303
0/2
✗ Branch 64 → 65 not taken.
✗ Branch 64 → 66 not taken.
✗ } else if (f->avctx->bits_per_raw_sample < 16) {
304 ✗ f->pix_fmt = AV_PIX_FMT_GRAY16;
305 } else
306 ✗ return AVERROR(ENOSYS);
307
1/4
✗ Branch 68 → 69 not taken.
✓ Branch 68 → 78 taken 390 times.
✗ Branch 69 → 70 not taken.
✗ Branch 69 → 78 not taken.
390 } else if (f->transparency && !f->chroma_planes) {
308
0/4
✗ Branch 70 → 71 not taken.
✗ Branch 70 → 73 not taken.
✗ Branch 71 → 72 not taken.
✗ Branch 71 → 73 not taken.
✗ if (f->avctx->bits_per_raw_sample <= 8 && !f->flt) {
309 ✗ f->pix_fmt = AV_PIX_FMT_YA8;
310
0/4
✗ Branch 73 → 74 not taken.
✗ Branch 73 → 76 not taken.
✗ Branch 74 → 75 not taken.
✗ Branch 74 → 76 not taken.
✗ } else if (f->avctx->bits_per_raw_sample == 16 && f->flt) {
311 ✗ f->pix_fmt = AV_PIX_FMT_YAF16;
312 } else
313 ✗ return AVERROR(ENOSYS);
314
3/4
✓ Branch 78 → 79 taken 254 times.
✓ Branch 78 → 88 taken 136 times.
✓ Branch 79 → 80 taken 254 times.
✗ Branch 79 → 88 not taken.
390 } else if (f->avctx->bits_per_raw_sample<=8 && !f->transparency) {
315
1/7
✗ Branch 80 → 81 not taken.
✗ Branch 80 → 82 not taken.
✗ Branch 80 → 83 not taken.
✓ Branch 80 → 84 taken 254 times.
✗ Branch 80 → 85 not taken.
✗ Branch 80 → 86 not taken.
✗ Branch 80 → 87 not taken.
254 switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
316 ✗ case 0x00: f->pix_fmt = AV_PIX_FMT_YUV444P; break;
317 ✗ case 0x01: f->pix_fmt = AV_PIX_FMT_YUV440P; break;
318 ✗ case 0x10: f->pix_fmt = AV_PIX_FMT_YUV422P; break;
319 254 case 0x11: f->pix_fmt = AV_PIX_FMT_YUV420P; break;
320 ✗ case 0x20: f->pix_fmt = AV_PIX_FMT_YUV411P; break;
321 ✗ case 0x22: f->pix_fmt = AV_PIX_FMT_YUV410P; break;
322 }
323
1/4
✗ Branch 88 → 89 not taken.
✓ Branch 88 → 95 taken 136 times.
✗ Branch 89 → 90 not taken.
✗ Branch 89 → 95 not taken.
136 } else if (f->avctx->bits_per_raw_sample <= 8 && f->transparency) {
324
0/4
✗ Branch 90 → 91 not taken.
✗ Branch 90 → 92 not taken.
✗ Branch 90 → 93 not taken.
✗ Branch 90 → 94 not taken.
✗ switch(16*f->chroma_h_shift + f->chroma_v_shift) {
325 ✗ case 0x00: f->pix_fmt = AV_PIX_FMT_YUVA444P; break;
326 ✗ case 0x10: f->pix_fmt = AV_PIX_FMT_YUVA422P; break;
327 ✗ case 0x11: f->pix_fmt = AV_PIX_FMT_YUVA420P; break;
328 }
329
1/4
✗ Branch 95 → 96 not taken.
✓ Branch 95 → 102 taken 136 times.
✗ Branch 96 → 97 not taken.
✗ Branch 96 → 102 not taken.
136 } else if (f->avctx->bits_per_raw_sample == 9 && !f->transparency) {
330 ✗ f->packed_at_lsb = 1;
331
0/4
✗ Branch 97 → 98 not taken.
✗ Branch 97 → 99 not taken.
✗ Branch 97 → 100 not taken.
✗ Branch 97 → 101 not taken.
✗ switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
332 ✗ case 0x00: f->pix_fmt = AV_PIX_FMT_YUV444P9; break;
333 ✗ case 0x10: f->pix_fmt = AV_PIX_FMT_YUV422P9; break;
334 ✗ case 0x11: f->pix_fmt = AV_PIX_FMT_YUV420P9; break;
335 }
336
1/4
✗ Branch 102 → 103 not taken.
✓ Branch 102 → 109 taken 136 times.
✗ Branch 103 → 104 not taken.
✗ Branch 103 → 109 not taken.
136 } else if (f->avctx->bits_per_raw_sample == 9 && f->transparency) {
337 ✗ f->packed_at_lsb = 1;
338
0/4
✗ Branch 104 → 105 not taken.
✗ Branch 104 → 106 not taken.
✗ Branch 104 → 107 not taken.
✗ Branch 104 → 108 not taken.
✗ switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
339 ✗ case 0x00: f->pix_fmt = AV_PIX_FMT_YUVA444P9; break;
340 ✗ case 0x10: f->pix_fmt = AV_PIX_FMT_YUVA422P9; break;
341 ✗ case 0x11: f->pix_fmt = AV_PIX_FMT_YUVA420P9; break;
342 }
343
3/4
✓ Branch 109 → 110 taken 92 times.
✓ Branch 109 → 117 taken 44 times.
✓ Branch 110 → 111 taken 92 times.
✗ Branch 110 → 117 not taken.
136 } else if (f->avctx->bits_per_raw_sample == 10 && !f->transparency) {
344 92 f->packed_at_lsb = 1;
345
1/5
✗ Branch 111 → 112 not taken.
✗ Branch 111 → 113 not taken.
✓ Branch 111 → 114 taken 92 times.
✗ Branch 111 → 115 not taken.
✗ Branch 111 → 116 not taken.
92 switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
346 ✗ case 0x00: f->pix_fmt = AV_PIX_FMT_YUV444P10; break;
347 ✗ case 0x01: f->pix_fmt = AV_PIX_FMT_YUV440P10; break;
348 92 case 0x10: f->pix_fmt = AV_PIX_FMT_YUV422P10; break;
349 ✗ case 0x11: f->pix_fmt = AV_PIX_FMT_YUV420P10; break;
350 }
351
1/4
✗ Branch 117 → 118 not taken.
✓ Branch 117 → 124 taken 44 times.
✗ Branch 118 → 119 not taken.
✗ Branch 118 → 124 not taken.
44 } else if (f->avctx->bits_per_raw_sample == 10 && f->transparency) {
352 ✗ f->packed_at_lsb = 1;
353
0/4
✗ Branch 119 → 120 not taken.
✗ Branch 119 → 121 not taken.
✗ Branch 119 → 122 not taken.
✗ Branch 119 → 123 not taken.
✗ switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
354 ✗ case 0x00: f->pix_fmt = AV_PIX_FMT_YUVA444P10; break;
355 ✗ case 0x10: f->pix_fmt = AV_PIX_FMT_YUVA422P10; break;
356 ✗ case 0x11: f->pix_fmt = AV_PIX_FMT_YUVA420P10; break;
357 }
358
1/4
✗ Branch 124 → 125 not taken.
✓ Branch 124 → 132 taken 44 times.
✗ Branch 125 → 126 not taken.
✗ Branch 125 → 132 not taken.
44 } else if (f->avctx->bits_per_raw_sample == 12 && !f->transparency) {
359 ✗ f->packed_at_lsb = 1;
360
0/5
✗ Branch 126 → 127 not taken.
✗ Branch 126 → 128 not taken.
✗ Branch 126 → 129 not taken.
✗ Branch 126 → 130 not taken.
✗ Branch 126 → 131 not taken.
✗ switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
361 ✗ case 0x00: f->pix_fmt = AV_PIX_FMT_YUV444P12; break;
362 ✗ case 0x01: f->pix_fmt = AV_PIX_FMT_YUV440P12; break;
363 ✗ case 0x10: f->pix_fmt = AV_PIX_FMT_YUV422P12; break;
364 ✗ case 0x11: f->pix_fmt = AV_PIX_FMT_YUV420P12; break;
365 }
366
1/4
✗ Branch 132 → 133 not taken.
✓ Branch 132 → 138 taken 44 times.
✗ Branch 133 → 134 not taken.
✗ Branch 133 → 138 not taken.
44 } else if (f->avctx->bits_per_raw_sample == 12 && f->transparency) {
367 ✗ f->packed_at_lsb = 1;
368
0/3
✗ Branch 134 → 135 not taken.
✗ Branch 134 → 136 not taken.
✗ Branch 134 → 137 not taken.
✗ switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
369 ✗ case 0x00: f->pix_fmt = AV_PIX_FMT_YUVA444P12; break;
370 ✗ case 0x10: f->pix_fmt = AV_PIX_FMT_YUVA422P12; break;
371 }
372
1/4
✗ Branch 138 → 139 not taken.
✓ Branch 138 → 145 taken 44 times.
✗ Branch 139 → 140 not taken.
✗ Branch 139 → 145 not taken.
44 } else if (f->avctx->bits_per_raw_sample == 14 && !f->transparency) {
373 ✗ f->packed_at_lsb = 1;
374
0/4
✗ Branch 140 → 141 not taken.
✗ Branch 140 → 142 not taken.
✗ Branch 140 → 143 not taken.
✗ Branch 140 → 144 not taken.
✗ switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
375 ✗ case 0x00: f->pix_fmt = AV_PIX_FMT_YUV444P14; break;
376 ✗ case 0x10: f->pix_fmt = AV_PIX_FMT_YUV422P14; break;
377 ✗ case 0x11: f->pix_fmt = AV_PIX_FMT_YUV420P14; break;
378 }
379
2/4
✓ Branch 145 → 146 taken 44 times.
✗ Branch 145 → 152 not taken.
✓ Branch 146 → 147 taken 44 times.
✗ Branch 146 → 152 not taken.
44 } else if (f->avctx->bits_per_raw_sample == 16 && !f->transparency){
380 44 f->packed_at_lsb = 1;
381
1/4
✓ Branch 147 → 148 taken 44 times.
✗ Branch 147 → 149 not taken.
✗ Branch 147 → 150 not taken.
✗ Branch 147 → 151 not taken.
44 switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
382 44 case 0x00: f->pix_fmt = AV_PIX_FMT_YUV444P16; break;
383 ✗ case 0x10: f->pix_fmt = AV_PIX_FMT_YUV422P16; break;
384 ✗ case 0x11: f->pix_fmt = AV_PIX_FMT_YUV420P16; break;
385 }
386
0/4
✗ Branch 152 → 153 not taken.
✗ Branch 152 → 158 not taken.
✗ Branch 153 → 154 not taken.
✗ Branch 153 → 158 not taken.
✗ } else if (f->avctx->bits_per_raw_sample == 16 && f->transparency){
387 ✗ f->packed_at_lsb = 1;
388
0/4
✗ Branch 154 → 155 not taken.
✗ Branch 154 → 156 not taken.
✗ Branch 154 → 157 not taken.
✗ Branch 154 → 158 not taken.
✗ switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
389 ✗ case 0x00: f->pix_fmt = AV_PIX_FMT_YUVA444P16; break;
390 ✗ case 0x10: f->pix_fmt = AV_PIX_FMT_YUVA422P16; break;
391 ✗ case 0x11: f->pix_fmt = AV_PIX_FMT_YUVA420P16; break;
392 }
393 }
394
1/2
✓ Branch 159 → 160 taken 101 times.
✗ Branch 159 → 214 not taken.
101 } else if (f->colorspace == 1) {
395
2/4
✓ Branch 160 → 161 taken 101 times.
✗ Branch 160 → 162 not taken.
✗ Branch 161 → 162 not taken.
✓ Branch 161 → 164 taken 101 times.
101 if (f->chroma_h_shift || f->chroma_v_shift) {
396 ✗ av_log(f->avctx, AV_LOG_ERROR,
397 "chroma subsampling not supported in this colorspace\n");
398 ✗ return AVERROR(ENOSYS);
399 }
400
3/4
✓ Branch 164 → 165 taken 44 times.
✓ Branch 164 → 167 taken 57 times.
✓ Branch 165 → 166 taken 44 times.
✗ Branch 165 → 167 not taken.
101 if ( f->avctx->bits_per_raw_sample <= 8 && !f->transparency)
401 44 f->pix_fmt = AV_PIX_FMT_0RGB32;
402
1/4
✗ Branch 167 → 168 not taken.
✓ Branch 167 → 170 taken 57 times.
✗ Branch 168 → 169 not taken.
✗ Branch 168 → 170 not taken.
57 else if (f->avctx->bits_per_raw_sample <= 8 && f->transparency)
403 ✗ f->pix_fmt = AV_PIX_FMT_RGB32;
404
1/4
✗ Branch 170 → 171 not taken.
✓ Branch 170 → 173 taken 57 times.
✗ Branch 171 → 172 not taken.
✗ Branch 171 → 173 not taken.
57 else if (f->avctx->bits_per_raw_sample == 9 && !f->transparency)
405 ✗ f->pix_fmt = AV_PIX_FMT_GBRP9;
406
1/4
✗ Branch 173 → 174 not taken.
✓ Branch 173 → 176 taken 57 times.
✗ Branch 174 → 175 not taken.
✗ Branch 174 → 176 not taken.
57 else if (f->avctx->bits_per_raw_sample == 10 && !f->transparency)
407 ✗ f->pix_fmt = AV_PIX_FMT_GBRP10;
408
1/4
✗ Branch 176 → 177 not taken.
✓ Branch 176 → 179 taken 57 times.
✗ Branch 177 → 178 not taken.
✗ Branch 177 → 179 not taken.
57 else if (f->avctx->bits_per_raw_sample == 10 && f->transparency)
409 ✗ f->pix_fmt = AV_PIX_FMT_GBRAP10;
410
1/4
✗ Branch 179 → 180 not taken.
✓ Branch 179 → 182 taken 57 times.
✗ Branch 180 → 181 not taken.
✗ Branch 180 → 182 not taken.
57 else if (f->avctx->bits_per_raw_sample == 12 && !f->transparency)
411 ✗ f->pix_fmt = AV_PIX_FMT_GBRP12;
412
1/4
✗ Branch 182 → 183 not taken.
✓ Branch 182 → 185 taken 57 times.
✗ Branch 183 → 184 not taken.
✗ Branch 183 → 185 not taken.
57 else if (f->avctx->bits_per_raw_sample == 12 && f->transparency)
413 ✗ f->pix_fmt = AV_PIX_FMT_GBRAP12;
414
1/4
✗ Branch 185 → 186 not taken.
✓ Branch 185 → 188 taken 57 times.
✗ Branch 186 → 187 not taken.
✗ Branch 186 → 188 not taken.
57 else if (f->avctx->bits_per_raw_sample == 14 && !f->transparency)
415 ✗ f->pix_fmt = AV_PIX_FMT_GBRP14;
416
1/4
✗ Branch 188 → 189 not taken.
✓ Branch 188 → 191 taken 57 times.
✗ Branch 189 → 190 not taken.
✗ Branch 189 → 191 not taken.
57 else if (f->avctx->bits_per_raw_sample == 14 && f->transparency)
417 ✗ f->pix_fmt = AV_PIX_FMT_GBRAP14;
418
3/4
✓ Branch 191 → 192 taken 44 times.
✓ Branch 191 → 197 taken 13 times.
✓ Branch 192 → 193 taken 44 times.
✗ Branch 192 → 197 not taken.
57 else if (f->avctx->bits_per_raw_sample == 16 && !f->transparency) {
419
1/2
✗ Branch 193 → 194 not taken.
✓ Branch 193 → 195 taken 44 times.
44 if (f->flt) {
420 ✗ f->pix_fmt = AV_PIX_FMT_GBRPF16;
421 } else
422 44 f->pix_fmt = AV_PIX_FMT_GBRP16;
423 44 f->use32bit = 1;
424
1/4
✗ Branch 197 → 198 not taken.
✓ Branch 197 → 203 taken 13 times.
✗ Branch 198 → 199 not taken.
✗ Branch 198 → 203 not taken.
13 } else if (f->avctx->bits_per_raw_sample == 16 && f->transparency) {
425
0/2
✗ Branch 199 → 200 not taken.
✗ Branch 199 → 201 not taken.
✗ if (f->flt) {
426 ✗ f->pix_fmt = AV_PIX_FMT_GBRAPF16;
427 } else
428 ✗ f->pix_fmt = AV_PIX_FMT_GBRAP16;
429 ✗ f->use32bit = 1;
430
2/4
✓ Branch 203 → 204 taken 13 times.
✗ Branch 203 → 208 not taken.
✓ Branch 204 → 205 taken 13 times.
✗ Branch 204 → 208 not taken.
13 } else if (f->avctx->bits_per_raw_sample == 32 && !f->transparency) {
431
1/2
✓ Branch 205 → 206 taken 13 times.
✗ Branch 205 → 207 not taken.
13 if (f->flt) {
432 13 f->pix_fmt = AV_PIX_FMT_GBRPF32;
433 }
434 13 f->use32bit = 1;
435
0/4
✗ Branch 208 → 209 not taken.
✗ Branch 208 → 213 not taken.
✗ Branch 209 → 210 not taken.
✗ Branch 209 → 213 not taken.
✗ } else if (f->avctx->bits_per_raw_sample == 32 && f->transparency) {
436
0/2
✗ Branch 210 → 211 not taken.
✗ Branch 210 → 212 not taken.
✗ if (f->flt) {
437 ✗ f->pix_fmt = AV_PIX_FMT_GBRAPF32;
438 }
439 ✗ f->use32bit = 1;
440 }
441
0/2
✗ Branch 214 → 215 not taken.
✗ Branch 214 → 217 not taken.
✗ } else if (f->colorspace == 2) {
442
0/2
✗ Branch 215 → 216 not taken.
✗ Branch 215 → 219 not taken.
✗ if (f->avctx->bits_per_raw_sample == 16) {
443 ✗ f->pix_fmt = AV_PIX_FMT_BAYER_RGGB16;
444 ✗ f->use32bit = 1;
445 }
446 } else {
447 ✗ av_log(f->avctx, AV_LOG_ERROR, "colorspace not supported\n");
448 ✗ return AVERROR(ENOSYS);
449 }
450
1/2
✗ Branch 219 → 220 not taken.
✓ Branch 219 → 222 taken 491 times.
491 if (f->pix_fmt == AV_PIX_FMT_NONE) {
451 ✗ av_log(f->avctx, AV_LOG_ERROR, "format not supported\n");
452 ✗ return AVERROR(ENOSYS);
453 }
454
455 491 return 0;
456 }
457