../../../ffmpeg/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
476 / 1025
46.4%
Branches:
313 / 722
43.4%
Functions:
9 / 16
56.2%

libavcodec/cfhd.c
Line Branch Exec Source
1 /*
2 * Copyright (c) 2015-2016 Kieran Kunhya <kieran@kunhya.com>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 /**
22 * @file
23 * Cineform HD video decoder
24 */
25
26 #include "libavutil/attributes.h"
27 #include "libavutil/common.h"
28 #include "libavutil/imgutils.h"
29 #include "libavutil/intreadwrite.h"
30 #include "libavutil/mem.h"
31 #include "libavutil/pixdesc.h"
32
33 #include "avcodec.h"
34 #include "bytestream.h"
35 #include "codec_internal.h"
36 #include "decode.h"
37 #include "get_bits.h"
38 #include "internal.h"
39 #include "thread.h"
40 #include "cfhd.h"
41
42 #define ALPHA_COMPAND_DC_OFFSET 256
43 #define ALPHA_COMPAND_GAIN 9400
44
45 6 static av_cold int cfhd_init(AVCodecContext *avctx)
46 {
47 6 CFHDContext *s = avctx->priv_data;
48
49 6 s->avctx = avctx;
50
51
2/2
✓ Branch 8 → 3 taken 384 times.
✓ Branch 8 → 9 taken 6 times.
390 for (int i = 0; i < 64; i++) {
52 384 int val = i;
53
54
2/2
✓ Branch 3 → 4 taken 144 times.
✓ Branch 3 → 7 taken 240 times.
384 if (val >= 40) {
55
2/2
✓ Branch 4 → 5 taken 60 times.
✓ Branch 4 → 6 taken 84 times.
144 if (val >= 54) {
56 60 val -= 54;
57 60 val <<= 2;
58 60 val += 54;
59 }
60
61 144 val -= 40;
62 144 val <<= 2;
63 144 val += 40;
64 }
65
66 384 s->lut[0][i] = val;
67 }
68
69
2/2
✓ Branch 11 → 10 taken 1536 times.
✓ Branch 11 → 12 taken 6 times.
1542 for (int i = 0; i < 256; i++)
70 1536 s->lut[1][i] = i + ((768LL * i * i * i) / (256 * 256 * 256));
71
72 6 return ff_cfhd_init_vlcs(s);
73 }
74
75 99 static void init_plane_defaults(CFHDContext *s)
76 {
77 99 s->subband_num = 0;
78 99 s->level = 0;
79 99 s->subband_num_actual = 0;
80 99 }
81
82 33 static void init_peak_table_defaults(CFHDContext *s)
83 {
84 33 s->peak.level = 0;
85 33 s->peak.offset = 0;
86 33 memset(&s->peak.base, 0, sizeof(s->peak.base));
87 33 }
88
89 33 static void init_frame_defaults(CFHDContext *s)
90 {
91 33 s->coded_width = 0;
92 33 s->coded_height = 0;
93 33 s->coded_format = AV_PIX_FMT_YUV422P10;
94 33 s->cropped_height = 0;
95 33 s->bpc = 10;
96 33 s->channel_cnt = 3;
97 33 s->subband_cnt = SUBBAND_COUNT;
98 33 s->channel_num = 0;
99 33 s->lowpass_precision = 16;
100 33 s->quantisation = 1;
101 33 s->codebook = 0;
102 33 s->difference_coding = 0;
103 33 s->frame_type = 0;
104 33 s->sample_type = 0;
105
1/2
✓ Branch 2 → 3 taken 33 times.
✗ Branch 2 → 4 not taken.
33 if (s->transform_type != 2)
106 33 s->transform_type = -1;
107 33 init_plane_defaults(s);
108 33 init_peak_table_defaults(s);
109 33 }
110
111 3522977 static inline int dequant_and_decompand(CFHDContext *s, int level, int quantisation, int codebook)
112 {
113
2/4
✓ Branch 2 → 3 taken 3522977 times.
✗ Branch 2 → 4 not taken.
✓ Branch 3 → 4 taken 3522977 times.
✗ Branch 3 → 8 not taken.
3522977 if (codebook == 0 || codebook == 1) {
114
2/2
✓ Branch 4 → 5 taken 856386 times.
✓ Branch 4 → 6 taken 2666591 times.
3522977 return s->lut[codebook][abs(level)] * FFSIGN(level) * quantisation;
115 } else
116 ✗ return level * quantisation;
117 }
118
119 ✗ static inline void difference_coding(int16_t *band, int width, int height)
120 {
121
0/2
✗ Branch 7 → 3 not taken.
✗ Branch 7 → 8 not taken.
✗ for (int i = 0; i < height; i++) {
122
0/2
✗ Branch 5 → 4 not taken.
✗ Branch 5 → 6 not taken.
✗ for (int j = 1; j < width; j++) {
123 ✗ band[j] += band[j-1];
124 }
125 ✗ band += width;
126 }
127 ✗ }
128
129 ✗ static inline void peak_table(int16_t *band, Peak *peak, int length)
130 {
131
0/2
✗ Branch 7 → 3 not taken.
✗ Branch 7 → 8 not taken.
✗ for (int i = 0; i < length; i++)
132
0/2
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 6 not taken.
✗ if (abs(band[i]) > peak->level)
133 ✗ band[i] = bytestream2_get_le16(&peak->base);
134 ✗ }
135
136 ✗ static inline void process_alpha(int16_t *alpha, int width)
137 {
138
0/2
✗ Branch 4 → 3 not taken.
✗ Branch 4 → 5 not taken.
✗ for (int i = 0; i < width; i++) {
139 ✗ int channel = alpha[i];
140 ✗ channel -= ALPHA_COMPAND_DC_OFFSET;
141 ✗ channel <<= 3;
142 ✗ channel *= ALPHA_COMPAND_GAIN;
143 ✗ channel >>= 16;
144 ✗ channel = av_clip_uintp2(channel, 12);
145 ✗ alpha[i] = channel;
146 }
147 ✗ }
148
149 ✗ static inline void process_bayer(AVFrame *frame, int bpc)
150 {
151 ✗ const int linesize = frame->linesize[0];
152 ✗ uint16_t *r = (uint16_t *)frame->data[0];
153 ✗ uint16_t *g1 = (uint16_t *)(frame->data[0] + 2);
154 ✗ uint16_t *g2 = (uint16_t *)(frame->data[0] + frame->linesize[0]);
155 ✗ uint16_t *b = (uint16_t *)(frame->data[0] + frame->linesize[0] + 2);
156 ✗ const int mid = 1 << (bpc - 1);
157 ✗ const int factor = 1 << (16 - bpc);
158
159
0/2
✗ Branch 7 → 3 not taken.
✗ Branch 7 → 8 not taken.
✗ for (int y = 0; y < frame->height >> 1; y++) {
160
0/2
✗ Branch 5 → 4 not taken.
✗ Branch 5 → 6 not taken.
✗ for (int x = 0; x < frame->width; x += 2) {
161 int R, G1, G2, B;
162 int g, rg, bg, gd;
163
164 ✗ g = r[x];
165 ✗ rg = g1[x];
166 ✗ bg = g2[x];
167 ✗ gd = b[x];
168 ✗ gd -= mid;
169
170 ✗ R = (rg - mid) * 2 + g;
171 ✗ G1 = g + gd;
172 ✗ G2 = g - gd;
173 ✗ B = (bg - mid) * 2 + g;
174
175 ✗ R = av_clip_uintp2(R * factor, 16);
176 ✗ G1 = av_clip_uintp2(G1 * factor, 16);
177 ✗ G2 = av_clip_uintp2(G2 * factor, 16);
178 ✗ B = av_clip_uintp2(B * factor, 16);
179
180 ✗ r[x] = R;
181 ✗ g1[x] = G1;
182 ✗ g2[x] = G2;
183 ✗ b[x] = B;
184 }
185
186 ✗ r += linesize;
187 ✗ g1 += linesize;
188 ✗ g2 += linesize;
189 ✗ b += linesize;
190 }
191 ✗ }
192
193 ✗ static inline void interlaced_vertical_filter(int16_t *output, int16_t *low, int16_t *high,
194 int width, int linesize, int plane)
195 {
196
0/2
✗ Branch 4 → 3 not taken.
✗ Branch 4 → 5 not taken.
✗ for (int i = 0; i < width; i++) {
197 ✗ int16_t even = (low[i] - high[i])/2;
198 ✗ int16_t odd = (low[i] + high[i])/2;
199 ✗ output[i] = av_clip_uintp2(even, 10);
200 ✗ output[i + linesize] = av_clip_uintp2(odd, 10);
201 }
202 ✗ }
203
204 ✗ static inline void inverse_temporal_filter(int16_t *low, int16_t *high, int width)
205 {
206
0/2
✗ Branch 4 → 3 not taken.
✗ Branch 4 → 5 not taken.
✗ for (int i = 0; i < width; i++) {
207 ✗ int even = (low[i] - high[i]) / 2;
208 ✗ int odd = (low[i] + high[i]) / 2;
209
210 ✗ low[i] = even;
211 ✗ high[i] = odd;
212 }
213 ✗ }
214
215 12 static void free_buffers(CFHDContext *s)
216 {
217
2/2
✓ Branch 18 → 3 taken 48 times.
✓ Branch 18 → 19 taken 12 times.
60 for (size_t i = 0; i < FF_ARRAY_ELEMS(s->plane); i++) {
218 48 Plane *p = &s->plane[i];
219 48 av_freep(&s->plane[i].idwt_buf);
220 48 av_freep(&s->plane[i].idwt_tmp);
221 48 s->plane[i].idwt_size = 0;
222
223
2/2
✓ Branch 7 → 6 taken 816 times.
✓ Branch 7 → 8 taken 48 times.
864 for (int j = 0; j < SUBBAND_COUNT_3D; j++)
224 816 s->plane[i].subband[j] = NULL;
225
226
2/2
✓ Branch 10 → 9 taken 480 times.
✓ Branch 10 → 11 taken 48 times.
528 for (int j = 0; j < 10; j++)
227 480 s->plane[i].l_h[j] = NULL;
228
229
2/2
✓ Branch 16 → 12 taken 288 times.
✓ Branch 16 → 17 taken 48 times.
336 for (int j = 0; j < DWT_LEVELS_3D; j++)
230
2/2
✓ Branch 14 → 13 taken 1152 times.
✓ Branch 14 → 15 taken 288 times.
1440 for (unsigned k = 0; k < FF_ARRAY_ELEMS(p->band[j]); k++) {
231 1152 p->band[j][k].a_width = 0;
232 1152 p->band[j][k].a_height = 0;
233 1152 p->band[j][k].read_ok = 0;
234 }
235 }
236 12 s->a_height = 0;
237 12 s->a_width = 0;
238 12 s->a_transform_type = INT_MIN;
239 12 }
240
241 6 static int alloc_buffers(AVCodecContext *avctx)
242 {
243 6 CFHDContext *s = avctx->priv_data;
244 6 int ret, planes, bayer = 0;
245 int chroma_x_shift, chroma_y_shift;
246
247
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 6 times.
6 if ((ret = ff_set_dimensions(avctx, s->coded_width, s->coded_height)) < 0)
248 ✗ return ret;
249 6 avctx->pix_fmt = s->coded_format;
250
251 6 ff_cfhddsp_init(&s->dsp, s->bpc, avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16);
252
253
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 6 times.
6 if ((ret = av_pix_fmt_get_chroma_sub_sample(s->coded_format,
254 &chroma_x_shift,
255 &chroma_y_shift)) < 0)
256 ✗ return ret;
257 6 planes = av_pix_fmt_count_planes(s->coded_format);
258
1/2
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 6 times.
6 if (s->coded_format == AV_PIX_FMT_BAYER_RGGB16) {
259 ✗ planes = 4;
260 ✗ chroma_x_shift = 1;
261 ✗ chroma_y_shift = 1;
262 ✗ bayer = 1;
263 }
264
265
2/2
✓ Branch 61 → 13 taken 18 times.
✓ Branch 61 → 62 taken 6 times.
24 for (int i = 0; i < planes; i++) {
266 int w8, h8, w4, h4, w2, h2;
267
3/4
✓ Branch 13 → 14 taken 6 times.
✓ Branch 13 → 15 taken 12 times.
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 6 times.
18 int width = (i || bayer) ? s->coded_width >> chroma_x_shift : s->coded_width;
268
3/4
✓ Branch 17 → 18 taken 6 times.
✓ Branch 17 → 19 taken 12 times.
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 20 taken 6 times.
18 int height = (i || bayer) ? s->coded_height >> chroma_y_shift : s->coded_height;
269 18 ptrdiff_t stride = (FFALIGN(width / 8, 8) + 64) * 8;
270
271
1/2
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 24 taken 18 times.
18 if ((ret = av_image_check_size2(stride, height, avctx->max_pixels, s->coded_format, 0, avctx)) < 0)
272 ✗ return ret;
273
274
1/4
✗ Branch 24 → 25 not taken.
✓ Branch 24 → 27 taken 18 times.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 27 not taken.
18 if (chroma_y_shift && !bayer)
275 ✗ height = FFALIGN(height / 8, 2) * 8;
276 18 s->plane[i].width = width;
277 18 s->plane[i].height = height;
278 18 s->plane[i].stride = stride;
279
280 18 w8 = FFALIGN(s->plane[i].width / 8, 8) + 64;
281 18 h8 = FFALIGN(height, 8) / 8;
282 18 w4 = w8 * 2;
283 18 h4 = h8 * 2;
284 18 w2 = w4 * 2;
285 18 h2 = h4 * 2;
286
287
1/2
✓ Branch 27 → 28 taken 18 times.
✗ Branch 27 → 31 not taken.
18 if (s->transform_type == 0) {
288 18 s->plane[i].idwt_size = FFALIGN(height, 8) * stride;
289 18 s->plane[i].idwt_buf =
290 18 av_calloc(s->plane[i].idwt_size, sizeof(*s->plane[i].idwt_buf));
291 18 s->plane[i].idwt_tmp =
292 18 av_calloc(s->plane[i].idwt_size, sizeof(*s->plane[i].idwt_tmp));
293 } else {
294 ✗ s->plane[i].idwt_size = FFALIGN(height, 8) * stride * 2;
295 ✗ s->plane[i].idwt_buf =
296 ✗ av_calloc(s->plane[i].idwt_size, sizeof(*s->plane[i].idwt_buf));
297 ✗ s->plane[i].idwt_tmp =
298 ✗ av_calloc(s->plane[i].idwt_size, sizeof(*s->plane[i].idwt_tmp));
299 }
300
301
2/4
✓ Branch 34 → 35 taken 18 times.
✗ Branch 34 → 36 not taken.
✗ Branch 35 → 36 not taken.
✓ Branch 35 → 37 taken 18 times.
18 if (!s->plane[i].idwt_buf || !s->plane[i].idwt_tmp)
302 ✗ return AVERROR(ENOMEM);
303
304 18 s->plane[i].subband[0] = s->plane[i].idwt_buf;
305 18 s->plane[i].subband[1] = s->plane[i].idwt_buf + 2 * w8 * h8;
306 18 s->plane[i].subband[2] = s->plane[i].idwt_buf + 1 * w8 * h8;
307 18 s->plane[i].subband[3] = s->plane[i].idwt_buf + 3 * w8 * h8;
308 18 s->plane[i].subband[4] = s->plane[i].idwt_buf + 2 * w4 * h4;
309 18 s->plane[i].subband[5] = s->plane[i].idwt_buf + 1 * w4 * h4;
310 18 s->plane[i].subband[6] = s->plane[i].idwt_buf + 3 * w4 * h4;
311
1/2
✓ Branch 37 → 38 taken 18 times.
✗ Branch 37 → 39 not taken.
18 if (s->transform_type == 0) {
312 18 s->plane[i].subband[7] = s->plane[i].idwt_buf + 2 * w2 * h2;
313 18 s->plane[i].subband[8] = s->plane[i].idwt_buf + 1 * w2 * h2;
314 18 s->plane[i].subband[9] = s->plane[i].idwt_buf + 3 * w2 * h2;
315 } else {
316 ✗ int16_t *frame2 =
317 ✗ s->plane[i].subband[7] = s->plane[i].idwt_buf + 4 * w2 * h2;
318 ✗ s->plane[i].subband[8] = frame2 + 2 * w4 * h4;
319 ✗ s->plane[i].subband[9] = frame2 + 1 * w4 * h4;
320 ✗ s->plane[i].subband[10] = frame2 + 3 * w4 * h4;
321 ✗ s->plane[i].subband[11] = frame2 + 2 * w2 * h2;
322 ✗ s->plane[i].subband[12] = frame2 + 1 * w2 * h2;
323 ✗ s->plane[i].subband[13] = frame2 + 3 * w2 * h2;
324 ✗ s->plane[i].subband[14] = s->plane[i].idwt_buf + 2 * w2 * h2;
325 ✗ s->plane[i].subband[15] = s->plane[i].idwt_buf + 1 * w2 * h2;
326 ✗ s->plane[i].subband[16] = s->plane[i].idwt_buf + 3 * w2 * h2;
327 }
328
329
1/2
✓ Branch 40 → 41 taken 18 times.
✗ Branch 40 → 47 not taken.
18 if (s->transform_type == 0) {
330
2/2
✓ Branch 46 → 42 taken 54 times.
✓ Branch 46 → 58 taken 18 times.
72 for (int j = 0; j < DWT_LEVELS; j++) {
331
2/2
✓ Branch 44 → 43 taken 216 times.
✓ Branch 44 → 45 taken 54 times.
270 for (unsigned k = 0; k < FF_ARRAY_ELEMS(s->plane[i].band[j]); k++) {
332 216 s->plane[i].band[j][k].a_width = w8 << j;
333 216 s->plane[i].band[j][k].a_height = h8 << j;
334 }
335 }
336 } else {
337
0/2
✗ Branch 57 → 48 not taken.
✗ Branch 57 → 58 not taken.
✗ for (int j = 0; j < DWT_LEVELS_3D; j++) {
338
0/4
✗ Branch 48 → 49 not taken.
✗ Branch 48 → 52 not taken.
✗ Branch 49 → 50 not taken.
✗ Branch 49 → 51 not taken.
✗ int t = j < 1 ? 0 : (j < 3 ? 1 : 2);
339
340
0/2
✗ Branch 55 → 54 not taken.
✗ Branch 55 → 56 not taken.
✗ for (unsigned k = 0; k < FF_ARRAY_ELEMS(s->plane[i].band[j]); k++) {
341 ✗ s->plane[i].band[j][k].a_width = w8 << t;
342 ✗ s->plane[i].band[j][k].a_height = h8 << t;
343 }
344 }
345 }
346
347 /* ll2 and ll1 commented out because they are done in-place */
348 18 s->plane[i].l_h[0] = s->plane[i].idwt_tmp;
349 18 s->plane[i].l_h[1] = s->plane[i].idwt_tmp + 2 * w8 * h8;
350 // s->plane[i].l_h[2] = ll2;
351 18 s->plane[i].l_h[3] = s->plane[i].idwt_tmp;
352 18 s->plane[i].l_h[4] = s->plane[i].idwt_tmp + 2 * w4 * h4;
353 // s->plane[i].l_h[5] = ll1;
354 18 s->plane[i].l_h[6] = s->plane[i].idwt_tmp;
355 18 s->plane[i].l_h[7] = s->plane[i].idwt_tmp + 2 * w2 * h2;
356
1/2
✗ Branch 58 → 59 not taken.
✓ Branch 58 → 60 taken 18 times.
18 if (s->transform_type != 0) {
357 ✗ int16_t *frame2 = s->plane[i].idwt_tmp + 4 * w2 * h2;
358
359 ✗ s->plane[i].l_h[8] = frame2;
360 ✗ s->plane[i].l_h[9] = frame2 + 2 * w2 * h2;
361 }
362 }
363
364 6 s->a_transform_type = s->transform_type;
365 6 s->a_height = s->coded_height;
366 6 s->a_width = s->coded_width;
367 6 s->a_format = s->coded_format;
368
369 6 return 0;
370 }
371
372 33 static int cfhd_decode(AVCodecContext *avctx, AVFrame *pic,
373 int *got_frame, AVPacket *avpkt)
374 {
375 33 CFHDContext *s = avctx->priv_data;
376 33 CFHDDSPContext *dsp = &s->dsp;
377 GetByteContext gb;
378 33 int ret = 0, got_buffer = 0;
379
380 33 init_frame_defaults(s);
381 33 s->planes = av_pix_fmt_count_planes(s->coded_format);
382
383 33 bytestream2_init(&gb, avpkt->data, avpkt->size);
384
385
2/2
✓ Branch 407 → 6 taken 17193 times.
✓ Branch 407 → 408 taken 33 times.
17226 while (bytestream2_get_bytes_left(&gb) >= 4) {
386 /* Bit weird but implement the tag parsing as the spec says */
387 17193 uint16_t tagu = bytestream2_get_be16(&gb);
388 17193 int16_t tag = (int16_t)tagu;
389 17193 int8_t tag8 = (int8_t)(tagu >> 8);
390 17193 uint16_t abstag = abs(tag);
391 17193 int8_t abs_tag8 = abs(tag8);
392 17193 uint16_t data = bytestream2_get_be16(&gb);
393 int16_t *coeff_data;
394
395
1/4
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 11 taken 17193 times.
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 11 not taken.
17193 if (abs_tag8 >= 0x60 && abs_tag8 <= 0x6f) {
396 ✗ av_log(avctx, AV_LOG_DEBUG, "large len %x\n", ((tagu & 0xff) << 16) | data);
397
2/2
✓ Branch 11 → 12 taken 33 times.
✓ Branch 11 → 14 taken 17160 times.
17193 } else if (tag == SampleFlags) {
398 33 av_log(avctx, AV_LOG_DEBUG, "Progressive? %"PRIu16"\n", data);
399 33 s->progressive = data & 0x0001;
400
1/2
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 17160 times.
17160 } else if (tag == FrameType) {
401 ✗ s->frame_type = data;
402 ✗ av_log(avctx, AV_LOG_DEBUG, "Frame type %"PRIu16"\n", data);
403
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 17160 times.
17160 } else if (abstag == VersionMajor) {
404 ✗ av_log(avctx, AV_LOG_DEBUG, "Version major %"PRIu16"\n", data);
405
1/2
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 20 taken 17160 times.
17160 } else if (abstag == VersionMinor) {
406 ✗ av_log(avctx, AV_LOG_DEBUG, "Version minor %"PRIu16"\n", data);
407
1/2
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 17160 times.
17160 } else if (abstag == VersionRevision) {
408 ✗ av_log(avctx, AV_LOG_DEBUG, "Version revision %"PRIu16"\n", data);
409
1/2
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 24 taken 17160 times.
17160 } else if (abstag == VersionEdit) {
410 ✗ av_log(avctx, AV_LOG_DEBUG, "Version edit %"PRIu16"\n", data);
411
2/2
✓ Branch 24 → 25 taken 33 times.
✓ Branch 24 → 26 taken 17127 times.
17160 } else if (abstag == Version) {
412 33 av_log(avctx, AV_LOG_DEBUG, "Version %"PRIu16"\n", data);
413
2/2
✓ Branch 26 → 27 taken 33 times.
✓ Branch 26 → 29 taken 17094 times.
17127 } else if (tag == ImageWidth) {
414 33 av_log(avctx, AV_LOG_DEBUG, "Width %"PRIu16"\n", data);
415 33 s->coded_width = data;
416
2/2
✓ Branch 29 → 30 taken 33 times.
✓ Branch 29 → 32 taken 17061 times.
17094 } else if (tag == ImageHeight) {
417 33 av_log(avctx, AV_LOG_DEBUG, "Height %"PRIu16"\n", data);
418 33 s->coded_height = data;
419
2/2
✓ Branch 32 → 33 taken 33 times.
✓ Branch 32 → 37 taken 17028 times.
17061 } else if (tag == ChannelCount) {
420 33 av_log(avctx, AV_LOG_DEBUG, "Channel Count: %"PRIu16"\n", data);
421 33 s->channel_cnt = data;
422
1/2
✗ Branch 34 → 35 not taken.
✓ Branch 34 → 214 taken 33 times.
33 if (data > 4) {
423 ✗ av_log(avctx, AV_LOG_ERROR, "Channel Count of %"PRIu16" is unsupported\n", data);
424 ✗ ret = AVERROR_PATCHWELCOME;
425 ✗ goto end;
426 }
427
2/2
✓ Branch 37 → 38 taken 33 times.
✓ Branch 37 → 43 taken 16995 times.
17028 } else if (tag == SubbandCount) {
428 33 av_log(avctx, AV_LOG_DEBUG, "Subband Count: %"PRIu16"\n", data);
429
1/4
✗ Branch 39 → 40 not taken.
✓ Branch 39 → 214 taken 33 times.
✗ Branch 40 → 41 not taken.
✗ Branch 40 → 214 not taken.
33 if (data != SUBBAND_COUNT && data != SUBBAND_COUNT_3D) {
430 ✗ av_log(avctx, AV_LOG_ERROR, "Subband Count of %"PRIu16" is unsupported\n", data);
431 ✗ ret = AVERROR_PATCHWELCOME;
432 ✗ goto end;
433 }
434
2/2
✓ Branch 43 → 44 taken 66 times.
✓ Branch 43 → 46 taken 16929 times.
16995 } else if (tag == ChannelNumber) {
435 66 s->channel_num = data;
436 66 av_log(avctx, AV_LOG_DEBUG, "Channel number %"PRIu16"\n", data);
437 66 init_plane_defaults(s);
438
2/2
✓ Branch 46 → 47 taken 891 times.
✓ Branch 46 → 62 taken 16038 times.
16929 } else if (tag == SubbandNumber) {
439
5/8
✓ Branch 47 → 48 taken 792 times.
✓ Branch 47 → 52 taken 99 times.
✓ Branch 48 → 49 taken 198 times.
✓ Branch 48 → 52 taken 594 times.
✗ Branch 49 → 50 not taken.
✓ Branch 49 → 51 taken 198 times.
✗ Branch 50 → 51 not taken.
✗ Branch 50 → 52 not taken.
891 if (s->subband_num != 0 && data == 1 && (s->transform_type == 0 || s->transform_type == 2)) // hack
440 198 s->level++;
441 891 av_log(avctx, AV_LOG_DEBUG, "Subband number %"PRIu16"\n", data);
442 891 s->subband_num = data;
443
2/4
✓ Branch 53 → 54 taken 891 times.
✗ Branch 53 → 55 not taken.
✓ Branch 54 → 55 taken 891 times.
✗ Branch 54 → 57 not taken.
891 if ((s->transform_type == 0 && s->level >= DWT_LEVELS) ||
444
1/4
✗ Branch 55 → 56 not taken.
✓ Branch 55 → 59 taken 891 times.
✗ Branch 56 → 57 not taken.
✗ Branch 56 → 59 not taken.
891 (s->transform_type == 2 && s->level >= DWT_LEVELS_3D)) {
445 ✗ av_log(avctx, AV_LOG_ERROR, "Invalid level\n");
446 ✗ ret = AVERROR(EINVAL);
447 ✗ goto end;
448 }
449
1/2
✗ Branch 59 → 60 not taken.
✓ Branch 59 → 214 taken 891 times.
891 if (s->subband_num > 3) {
450 ✗ av_log(avctx, AV_LOG_ERROR, "Invalid subband number\n");
451 ✗ ret = AVERROR(EINVAL);
452 ✗ goto end;
453 }
454
2/2
✓ Branch 62 → 63 taken 891 times.
✓ Branch 62 → 76 taken 15147 times.
16038 } else if (tag == SubbandBand) {
455 891 av_log(avctx, AV_LOG_DEBUG, "Subband number actual %"PRIu16"\n", data);
456
2/4
✓ Branch 64 → 65 taken 891 times.
✗ Branch 64 → 66 not taken.
✓ Branch 65 → 66 taken 891 times.
✗ Branch 65 → 69 not taken.
891 if ((s->transform_type == 0 && data >= SUBBAND_COUNT) ||
457
1/6
✗ Branch 66 → 67 not taken.
✓ Branch 66 → 71 taken 891 times.
✗ Branch 67 → 68 not taken.
✗ Branch 67 → 71 not taken.
✗ Branch 68 → 69 not taken.
✗ Branch 68 → 71 not taken.
891 (s->transform_type == 2 && data >= SUBBAND_COUNT_3D && data != 255)) {
458 ✗ av_log(avctx, AV_LOG_ERROR, "Invalid subband number actual\n");
459 ✗ ret = AVERROR(EINVAL);
460 ✗ goto end;
461 }
462
1/4
✗ Branch 71 → 72 not taken.
✓ Branch 71 → 73 taken 891 times.
✗ Branch 72 → 73 not taken.
✗ Branch 72 → 74 not taken.
891 if (s->transform_type == 0 || s->transform_type == 2)
463 891 s->subband_num_actual = data;
464 else
465 ✗ av_log(avctx, AV_LOG_WARNING, "Ignoring subband num actual %"PRIu16"\n", data);
466
2/2
✓ Branch 76 → 77 taken 99 times.
✓ Branch 76 → 78 taken 15048 times.
15147 } else if (tag == LowpassPrecision)
467 99 av_log(avctx, AV_LOG_DEBUG, "Lowpass precision bits: %"PRIu16"\n", data);
468
2/2
✓ Branch 78 → 79 taken 891 times.
✓ Branch 78 → 80 taken 14157 times.
15048 else if (tag == Quantization) {
469 891 s->quantisation = data;
470 891 av_log(avctx, AV_LOG_DEBUG, "Quantisation: %"PRIu16"\n", data);
471
2/2
✓ Branch 80 → 81 taken 11 times.
✓ Branch 80 → 85 taken 14146 times.
14157 } else if (tag == PrescaleTable) {
472
2/2
✓ Branch 83 → 82 taken 88 times.
✓ Branch 83 → 84 taken 11 times.
99 for (int i = 0; i < 8; i++)
473 88 s->prescale_table[i] = (data >> (14 - i * 2)) & 0x3;
474 11 av_log(avctx, AV_LOG_DEBUG, "Prescale table: %x\n", data);
475
2/2
✓ Branch 85 → 86 taken 891 times.
✓ Branch 85 → 91 taken 13255 times.
14146 } else if (tag == BandEncoding) {
476
2/4
✓ Branch 86 → 87 taken 891 times.
✗ Branch 86 → 88 not taken.
✗ Branch 87 → 88 not taken.
✓ Branch 87 → 90 taken 891 times.
891 if (!data || data > 5) {
477 ✗ av_log(avctx, AV_LOG_ERROR, "Invalid band encoding\n");
478 ✗ ret = AVERROR(EINVAL);
479 ✗ goto end;
480 }
481 891 s->band_encoding = data;
482 891 av_log(avctx, AV_LOG_DEBUG, "Encode Method for Subband %d : %x\n", s->subband_num_actual, data);
483
2/2
✓ Branch 91 → 92 taken 99 times.
✓ Branch 91 → 94 taken 13156 times.
13255 } else if (tag == LowpassWidth) {
484 99 av_log(avctx, AV_LOG_DEBUG, "Lowpass width %"PRIu16"\n", data);
485 99 s->plane[s->channel_num].band[0][0].width = data;
486 99 s->plane[s->channel_num].band[0][0].stride = data;
487
2/2
✓ Branch 94 → 95 taken 99 times.
✓ Branch 94 → 97 taken 13057 times.
13156 } else if (tag == LowpassHeight) {
488 99 av_log(avctx, AV_LOG_DEBUG, "Lowpass height %"PRIu16"\n", data);
489 99 s->plane[s->channel_num].band[0][0].height = data;
490
2/2
✓ Branch 97 → 98 taken 99 times.
✓ Branch 97 → 99 taken 12958 times.
13057 } else if (tag == SampleType) {
491 99 s->sample_type = data;
492 99 av_log(avctx, AV_LOG_DEBUG, "Sample type? %"PRIu16"\n", data);
493
2/2
✓ Branch 99 → 100 taken 33 times.
✓ Branch 99 → 109 taken 12925 times.
12958 } else if (tag == TransformType) {
494
1/2
✗ Branch 100 → 101 not taken.
✓ Branch 100 → 103 taken 33 times.
33 if (data > 2) {
495 ✗ av_log(avctx, AV_LOG_ERROR, "Invalid transform type\n");
496 ✗ ret = AVERROR(EINVAL);
497 ✗ goto end;
498
1/2
✗ Branch 103 → 104 not taken.
✓ Branch 103 → 106 taken 33 times.
33 } else if (data == 1) {
499 ✗ av_log(avctx, AV_LOG_ERROR, "unsupported transform type\n");
500 ✗ ret = AVERROR_PATCHWELCOME;
501 ✗ goto end;
502 }
503
1/2
✓ Branch 106 → 107 taken 33 times.
✗ Branch 106 → 108 not taken.
33 if (s->transform_type == -1) {
504 33 s->transform_type = data;
505 33 av_log(avctx, AV_LOG_DEBUG, "Transform type %"PRIu16"\n", data);
506 } else {
507 ✗ av_log(avctx, AV_LOG_DEBUG, "Ignoring additional transform type %"PRIu16"\n", data);
508 }
509
3/4
✓ Branch 109 → 110 taken 66 times.
✓ Branch 109 → 118 taken 12859 times.
✓ Branch 110 → 111 taken 66 times.
✗ Branch 110 → 118 not taken.
12925 } else if (abstag >= 0x4000 && abstag <= 0x40ff) {
510
1/2
✗ Branch 111 → 112 not taken.
✓ Branch 111 → 113 taken 66 times.
66 if (abstag == 0x4001)
511 ✗ s->peak.level = 0;
512
1/2
✓ Branch 113 → 114 taken 66 times.
✗ Branch 113 → 115 not taken.
66 av_log(avctx, AV_LOG_DEBUG, "Small chunk length %d %s\n", data * 4, tag < 0 ? "optional" : "required");
513 66 bytestream2_skipu(&gb, data * 4);
514
1/2
✗ Branch 118 → 119 not taken.
✓ Branch 118 → 121 taken 12859 times.
12859 } else if (tag == FrameIndex) {
515 ✗ av_log(avctx, AV_LOG_DEBUG, "Frame index %"PRIu16"\n", data);
516 ✗ s->frame_index = data;
517
2/2
✓ Branch 121 → 122 taken 33 times.
✓ Branch 121 → 132 taken 12826 times.
12859 } else if (tag == SampleIndexTable) {
518 33 av_log(avctx, AV_LOG_DEBUG, "Sample index table - skipping %i values\n", data);
519
1/2
✗ Branch 124 → 125 not taken.
✓ Branch 124 → 127 taken 33 times.
33 if (data > bytestream2_get_bytes_left(&gb) / 4) {
520 ✗ av_log(avctx, AV_LOG_ERROR, "too many values (%d)\n", data);
521 ✗ ret = AVERROR_INVALIDDATA;
522 ✗ goto end;
523 }
524
2/2
✓ Branch 131 → 128 taken 99 times.
✓ Branch 131 → 214 taken 33 times.
132 for (int i = 0; i < data; i++) {
525 99 uint32_t offset = bytestream2_get_be32(&gb);
526 99 av_log(avctx, AV_LOG_DEBUG, "Offset = %"PRIu32"\n", offset);
527 }
528
2/2
✓ Branch 132 → 133 taken 297 times.
✓ Branch 132 → 138 taken 12529 times.
12826 } else if (tag == HighpassWidth) {
529 297 av_log(avctx, AV_LOG_DEBUG, "Highpass width %i channel %i level %i subband %i\n", data, s->channel_num, s->level, s->subband_num);
530
1/2
✗ Branch 134 → 135 not taken.
✓ Branch 134 → 137 taken 297 times.
297 if (data < 3) {
531 ✗ av_log(avctx, AV_LOG_ERROR, "Invalid highpass width\n");
532 ✗ ret = AVERROR(EINVAL);
533 ✗ goto end;
534 }
535 297 s->plane[s->channel_num].band[s->level][s->subband_num].width = data;
536 297 s->plane[s->channel_num].band[s->level][s->subband_num].stride = FFALIGN(data, 8);
537
2/2
✓ Branch 138 → 139 taken 297 times.
✓ Branch 138 → 144 taken 12232 times.
12529 } else if (tag == HighpassHeight) {
538 297 av_log(avctx, AV_LOG_DEBUG, "Highpass height %i\n", data);
539
1/2
✗ Branch 140 → 141 not taken.
✓ Branch 140 → 143 taken 297 times.
297 if (data < 3) {
540 ✗ av_log(avctx, AV_LOG_ERROR, "Invalid highpass height\n");
541 ✗ ret = AVERROR(EINVAL);
542 ✗ goto end;
543 }
544 297 s->plane[s->channel_num].band[s->level][s->subband_num].height = data;
545
2/2
✓ Branch 144 → 145 taken 891 times.
✓ Branch 144 → 150 taken 11341 times.
12232 } else if (tag == BandWidth) {
546 891 av_log(avctx, AV_LOG_DEBUG, "Highpass width2 %i\n", data);
547
1/2
✗ Branch 146 → 147 not taken.
✓ Branch 146 → 149 taken 891 times.
891 if (data < 3) {
548 ✗ av_log(avctx, AV_LOG_ERROR, "Invalid highpass width2\n");
549 ✗ ret = AVERROR(EINVAL);
550 ✗ goto end;
551 }
552 891 s->plane[s->channel_num].band[s->level][s->subband_num].width = data;
553 891 s->plane[s->channel_num].band[s->level][s->subband_num].stride = FFALIGN(data, 8);
554
2/2
✓ Branch 150 → 151 taken 891 times.
✓ Branch 150 → 156 taken 10450 times.
11341 } else if (tag == BandHeight) {
555 891 av_log(avctx, AV_LOG_DEBUG, "Highpass height2 %i\n", data);
556
1/2
✗ Branch 152 → 153 not taken.
✓ Branch 152 → 155 taken 891 times.
891 if (data < 3) {
557 ✗ av_log(avctx, AV_LOG_ERROR, "Invalid highpass height2\n");
558 ✗ ret = AVERROR(EINVAL);
559 ✗ goto end;
560 }
561 891 s->plane[s->channel_num].band[s->level][s->subband_num].height = data;
562
1/2
✗ Branch 156 → 157 not taken.
✓ Branch 156 → 173 taken 10450 times.
10450 } else if (tag == InputFormat) {
563 ✗ av_log(avctx, AV_LOG_DEBUG, "Input format %i\n", data);
564
0/2
✗ Branch 158 → 159 not taken.
✗ Branch 158 → 160 not taken.
✗ if (s->coded_format == AV_PIX_FMT_NONE ||
565
0/2
✗ Branch 159 → 160 not taken.
✗ Branch 159 → 214 not taken.
✗ s->coded_format == AV_PIX_FMT_YUV422P10) {
566
0/4
✗ Branch 160 → 161 not taken.
✗ Branch 160 → 163 not taken.
✗ Branch 161 → 162 not taken.
✗ Branch 161 → 163 not taken.
✗ if (data >= 100 && data <= 105) {
567 ✗ s->coded_format = AV_PIX_FMT_BAYER_RGGB16;
568
0/4
✗ Branch 163 → 164 not taken.
✗ Branch 163 → 166 not taken.
✗ Branch 164 → 165 not taken.
✗ Branch 164 → 166 not taken.
✗ } else if (data >= 122 && data <= 128) {
569 ✗ s->coded_format = AV_PIX_FMT_GBRP12;
570
0/2
✗ Branch 166 → 167 not taken.
✗ Branch 166 → 168 not taken.
✗ } else if (data == 30) {
571 ✗ s->coded_format = AV_PIX_FMT_GBRAP12;
572 } else {
573 ✗ s->coded_format = AV_PIX_FMT_YUV422P10;
574 }
575
0/2
✗ Branch 169 → 170 not taken.
✗ Branch 169 → 171 not taken.
✗ s->planes = s->coded_format == AV_PIX_FMT_BAYER_RGGB16 ? 4 : av_pix_fmt_count_planes(s->coded_format);
576 }
577
2/2
✓ Branch 173 → 174 taken 891 times.
✓ Branch 173 → 175 taken 9559 times.
10450 } else if (tag == BandCodingFlags) {
578 891 s->codebook = data & 0xf;
579 891 s->difference_coding = (data >> 4) & 1;
580 891 av_log(avctx, AV_LOG_DEBUG, "Other codebook? %i\n", s->codebook);
581
2/2
✓ Branch 175 → 176 taken 33 times.
✓ Branch 175 → 182 taken 9526 times.
9559 } else if (tag == Precision) {
582 33 av_log(avctx, AV_LOG_DEBUG, "Precision %i\n", data);
583
3/4
✓ Branch 177 → 178 taken 11 times.
✓ Branch 177 → 181 taken 22 times.
✗ Branch 178 → 179 not taken.
✓ Branch 178 → 181 taken 11 times.
33 if (!(data == 10 || data == 12)) {
584 ✗ av_log(avctx, AV_LOG_ERROR, "Invalid bits per channel\n");
585 ✗ ret = AVERROR(EINVAL);
586 ✗ goto end;
587 }
588 33 avctx->bits_per_raw_sample = s->bpc = data;
589
2/2
✓ Branch 182 → 183 taken 33 times.
✓ Branch 182 → 198 taken 9493 times.
9526 } else if (tag == EncodedFormat) {
590 33 av_log(avctx, AV_LOG_DEBUG, "Sample format? %i\n", data);
591
2/2
✓ Branch 184 → 185 taken 22 times.
✓ Branch 184 → 186 taken 11 times.
33 if (data == 1) {
592 22 s->coded_format = AV_PIX_FMT_YUV422P10;
593
1/2
✗ Branch 186 → 187 not taken.
✓ Branch 186 → 188 taken 11 times.
11 } else if (data == 2) {
594 ✗ s->coded_format = AV_PIX_FMT_BAYER_RGGB16;
595
1/2
✓ Branch 188 → 189 taken 11 times.
✗ Branch 188 → 190 not taken.
11 } else if (data == 3) {
596 11 s->coded_format = AV_PIX_FMT_GBRP12;
597
0/2
✗ Branch 190 → 191 not taken.
✗ Branch 190 → 192 not taken.
✗ } else if (data == 4) {
598 ✗ s->coded_format = AV_PIX_FMT_GBRAP12;
599 } else {
600 ✗ avpriv_report_missing_feature(avctx, "Sample format of %"PRIu16, data);
601 ✗ ret = AVERROR_PATCHWELCOME;
602 ✗ goto end;
603 }
604
1/2
✓ Branch 194 → 195 taken 33 times.
✗ Branch 194 → 196 not taken.
33 s->planes = data == 2 ? 4 : av_pix_fmt_count_planes(s->coded_format);
605
2/2
✓ Branch 198 → 199 taken 33 times.
✓ Branch 198 → 201 taken 9460 times.
9493 } else if (tag == -DisplayHeight) {
606 33 av_log(avctx, AV_LOG_DEBUG, "Cropped height %"PRIu16"\n", data);
607 33 s->cropped_height = data;
608
1/2
✗ Branch 201 → 202 not taken.
✓ Branch 201 → 203 taken 9460 times.
9460 } else if (tag == -PeakOffsetLow) {
609 ✗ s->peak.offset &= ~0xffff;
610 ✗ s->peak.offset |= (data & 0xffff);
611 ✗ s->peak.base = gb;
612 ✗ s->peak.level = 0;
613
1/2
✗ Branch 203 → 204 not taken.
✓ Branch 203 → 205 taken 9460 times.
9460 } else if (tag == -PeakOffsetHigh) {
614 ✗ s->peak.offset &= 0xffff;
615 ✗ s->peak.offset |= (data & 0xffffU)<<16;
616 ✗ s->peak.base = gb;
617 ✗ s->peak.level = 0;
618
1/4
✗ Branch 205 → 206 not taken.
✓ Branch 205 → 213 taken 9460 times.
✗ Branch 206 → 207 not taken.
✗ Branch 206 → 213 not taken.
9460 } else if (tag == -PeakLevel && s->peak.offset) {
619 ✗ s->peak.level = data;
620
0/2
✗ Branch 208 → 209 not taken.
✗ Branch 208 → 211 not taken.
✗ if (s->peak.offset < 4 - bytestream2_tell(&s->peak.base) ||
621
0/2
✗ Branch 210 → 211 not taken.
✗ Branch 210 → 212 not taken.
✗ s->peak.offset > 4 + bytestream2_get_bytes_left(&s->peak.base)
622 ) {
623 ✗ ret = AVERROR_INVALIDDATA;
624 ✗ goto end;
625 }
626 ✗ bytestream2_seek(&s->peak.base, s->peak.offset - 4, SEEK_CUR);
627 } else
628 9460 av_log(avctx, AV_LOG_DEBUG, "Unknown tag %i data %x\n", tag, data);
629
630
1/2
✗ Branch 214 → 215 not taken.
✓ Branch 214 → 217 taken 17193 times.
17193 if (s->channel_num >= s->planes) {
631 ✗ av_log(avctx, AV_LOG_ERROR, "Invalid channel number\n");
632 ✗ ret = AVERROR(EINVAL);
633 ✗ goto end;
634 }
635
636
5/8
✓ Branch 217 → 218 taken 15741 times.
✓ Branch 217 → 223 taken 1452 times.
✓ Branch 218 → 219 taken 15741 times.
✗ Branch 218 → 221 not taken.
✓ Branch 219 → 220 taken 15741 times.
✗ Branch 219 → 221 not taken.
✗ Branch 220 → 221 not taken.
✓ Branch 220 → 223 taken 15741 times.
17193 if (got_buffer && (s->coded_width || s->coded_height || s->coded_format != AV_PIX_FMT_NONE)) {
637 ✗ av_log(avctx, AV_LOG_ERROR, "Header tag after end of header\n");
638 ✗ ret = AVERROR(EINVAL);
639 ✗ goto end;
640 }
641
642
4/4
✓ Branch 223 → 224 taken 1782 times.
✓ Branch 223 → 265 taken 15411 times.
✓ Branch 224 → 225 taken 99 times.
✓ Branch 224 → 265 taken 1683 times.
17193 if (tag == BitstreamMarker && data == CoefficientSegment &&
643
2/2
✓ Branch 225 → 226 taken 33 times.
✓ Branch 225 → 265 taken 66 times.
99 s->coded_format != AV_PIX_FMT_NONE) {
644 33 int lowpass_height = s->plane[s->channel_num].band[0][0].height;
645 33 int lowpass_width = s->plane[s->channel_num].band[0][0].width;
646
1/2
✗ Branch 226 → 227 not taken.
✓ Branch 226 → 228 taken 33 times.
33 int factor = s->coded_format == AV_PIX_FMT_BAYER_RGGB16 ? 2 : 1;
647
648
1/2
✓ Branch 229 → 230 taken 33 times.
✗ Branch 229 → 231 not taken.
33 if (s->coded_width) {
649 33 s->coded_width *= factor;
650 }
651
652
1/2
✓ Branch 231 → 232 taken 33 times.
✗ Branch 231 → 233 not taken.
33 if (s->coded_height) {
653 33 s->coded_height *= factor;
654 }
655
656
3/4
✓ Branch 233 → 234 taken 6 times.
✓ Branch 233 → 236 taken 27 times.
✗ Branch 234 → 235 not taken.
✓ Branch 234 → 236 taken 6 times.
33 if (!s->a_width && !s->coded_width) {
657 ✗ s->coded_width = lowpass_width * factor * 8;
658 }
659
660
3/4
✓ Branch 236 → 237 taken 6 times.
✓ Branch 236 → 239 taken 27 times.
✗ Branch 237 → 238 not taken.
✓ Branch 237 → 239 taken 6 times.
33 if (!s->a_height && !s->coded_height) {
661 ✗ s->coded_height = lowpass_height * factor * 8;
662 }
663
664
3/4
✓ Branch 239 → 240 taken 27 times.
✓ Branch 239 → 242 taken 6 times.
✗ Branch 240 → 241 not taken.
✓ Branch 240 → 242 taken 27 times.
33 if (s->a_width && !s->coded_width)
665 ✗ s->coded_width = s->a_width;
666
3/4
✓ Branch 242 → 243 taken 27 times.
✓ Branch 242 → 245 taken 6 times.
✗ Branch 243 → 244 not taken.
✓ Branch 243 → 245 taken 27 times.
33 if (s->a_height && !s->coded_height)
667 ✗ s->coded_height = s->a_height;
668
669
3/4
✓ Branch 245 → 246 taken 27 times.
✓ Branch 245 → 249 taken 6 times.
✓ Branch 246 → 247 taken 27 times.
✗ Branch 246 → 249 not taken.
33 if (s->a_width != s->coded_width || s->a_height != s->coded_height ||
670
1/2
✓ Branch 247 → 248 taken 27 times.
✗ Branch 247 → 249 not taken.
27 s->a_format != s->coded_format ||
671
1/2
✗ Branch 248 → 249 not taken.
✓ Branch 248 → 254 taken 27 times.
27 s->transform_type != s->a_transform_type) {
672 6 free_buffers(s);
673
1/2
✗ Branch 251 → 252 not taken.
✓ Branch 251 → 254 taken 6 times.
6 if ((ret = alloc_buffers(avctx)) < 0) {
674 ✗ free_buffers(s);
675 ✗ return ret;
676 }
677 }
678 33 ret = ff_set_dimensions(avctx, s->coded_width, s->coded_height);
679
1/2
✗ Branch 255 → 256 not taken.
✓ Branch 255 → 257 taken 33 times.
33 if (ret < 0)
680 ✗ return ret;
681 33 avctx->pix_fmt = s->coded_format;
682
1/2
✓ Branch 257 → 258 taken 33 times.
✗ Branch 257 → 261 not taken.
33 if (s->cropped_height) {
683 33 unsigned height = s->cropped_height << (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16);
684
1/2
✗ Branch 258 → 259 not taken.
✓ Branch 258 → 260 taken 33 times.
33 if (avctx->height < height)
685 ✗ return AVERROR_INVALIDDATA;
686 33 avctx->height = height;
687 }
688 33 pic->width = pic->height = 0;
689
690
1/2
✗ Branch 262 → 263 not taken.
✓ Branch 262 → 264 taken 33 times.
33 if ((ret = ff_thread_get_buffer(avctx, pic, 0)) < 0)
691 ✗ return ret;
692
693 33 s->coded_width = 0;
694 33 s->coded_height = 0;
695 33 s->coded_format = AV_PIX_FMT_NONE;
696 33 got_buffer = 1;
697
1/8
✗ Branch 265 → 266 not taken.
✓ Branch 265 → 273 taken 17160 times.
✗ Branch 266 → 267 not taken.
✗ Branch 266 → 273 not taken.
✗ Branch 267 → 268 not taken.
✗ Branch 267 → 273 not taken.
✗ Branch 268 → 269 not taken.
✗ Branch 268 → 273 not taken.
17160 } else if (tag == FrameIndex && data == 1 && s->sample_type == 1 && s->frame_type == 2) {
698 ✗ pic->width = pic->height = 0;
699
700
0/2
✗ Branch 270 → 271 not taken.
✗ Branch 270 → 272 not taken.
✗ if ((ret = ff_thread_get_buffer(avctx, pic, 0)) < 0)
701 ✗ return ret;
702 ✗ s->coded_width = 0;
703 ✗ s->coded_height = 0;
704 ✗ s->coded_format = AV_PIX_FMT_NONE;
705 ✗ got_buffer = 1;
706 }
707
708
1/2
✗ Branch 273 → 274 not taken.
✓ Branch 273 → 275 taken 17193 times.
17193 if (s->subband_num_actual == 255)
709 ✗ goto finish;
710
711
8/10
✓ Branch 275 → 276 taken 1782 times.
✓ Branch 275 → 277 taken 15411 times.
✓ Branch 276 → 277 taken 1683 times.
✓ Branch 276 → 280 taken 99 times.
✓ Branch 277 → 278 taken 16203 times.
✓ Branch 277 → 280 taken 891 times.
✓ Branch 278 → 279 taken 16203 times.
✗ Branch 278 → 280 not taken.
✗ Branch 279 → 280 not taken.
✓ Branch 279 → 282 taken 16203 times.
17193 if (tag == BitstreamMarker && data == CoefficientSegment || tag == BandHeader || tag == BandSecondPass || s->peak.level)
712
1/2
✗ Branch 280 → 281 not taken.
✓ Branch 280 → 282 taken 990 times.
990 if (s->transform_type != s->a_transform_type)
713 ✗ return AVERROR_PATCHWELCOME;
714
715 17193 coeff_data = s->plane[s->channel_num].subband[s->subband_num_actual];
716
717 /* Lowpass coefficients */
718
4/4
✓ Branch 282 → 283 taken 1782 times.
✓ Branch 282 → 317 taken 15411 times.
✓ Branch 283 → 284 taken 99 times.
✓ Branch 283 → 317 taken 1683 times.
17193 if (tag == BitstreamMarker && data == CoefficientSegment) {
719 int lowpass_height, lowpass_width, lowpass_a_height, lowpass_a_width;
720
721
2/4
✓ Branch 284 → 285 taken 99 times.
✗ Branch 284 → 286 not taken.
✗ Branch 285 → 286 not taken.
✓ Branch 285 → 287 taken 99 times.
99 if (!s->a_width || !s->a_height) {
722 ✗ ret = AVERROR_INVALIDDATA;
723 ✗ goto end;
724 }
725
726 99 lowpass_height = s->plane[s->channel_num].band[0][0].height;
727 99 lowpass_width = s->plane[s->channel_num].band[0][0].width;
728 99 lowpass_a_height = s->plane[s->channel_num].band[0][0].a_height;
729 99 lowpass_a_width = s->plane[s->channel_num].band[0][0].a_width;
730
731
2/4
✓ Branch 287 → 288 taken 99 times.
✗ Branch 287 → 289 not taken.
✗ Branch 288 → 289 not taken.
✓ Branch 288 → 291 taken 99 times.
99 if (lowpass_width < 3 ||
732 lowpass_width > lowpass_a_width) {
733 ✗ av_log(avctx, AV_LOG_ERROR, "Invalid lowpass width\n");
734 ✗ ret = AVERROR(EINVAL);
735 ✗ goto end;
736 }
737
738
2/4
✓ Branch 291 → 292 taken 99 times.
✗ Branch 291 → 293 not taken.
✗ Branch 292 → 293 not taken.
✓ Branch 292 → 295 taken 99 times.
99 if (lowpass_height < 3 ||
739 lowpass_height > lowpass_a_height) {
740 ✗ av_log(avctx, AV_LOG_ERROR, "Invalid lowpass height\n");
741 ✗ ret = AVERROR(EINVAL);
742 ✗ goto end;
743 }
744
745
1/2
✗ Branch 295 → 296 not taken.
✓ Branch 295 → 298 taken 99 times.
99 if (!got_buffer) {
746 ✗ av_log(avctx, AV_LOG_ERROR, "No end of header tag found\n");
747 ✗ ret = AVERROR(EINVAL);
748 ✗ goto end;
749 }
750
751
2/4
✓ Branch 298 → 299 taken 99 times.
✗ Branch 298 → 302 not taken.
✓ Branch 299 → 300 taken 99 times.
✗ Branch 299 → 302 not taken.
99 if (lowpass_height > lowpass_a_height || lowpass_width > lowpass_a_width ||
752
1/2
✗ Branch 301 → 302 not taken.
✓ Branch 301 → 304 taken 99 times.
99 lowpass_width * lowpass_height * sizeof(int16_t) > bytestream2_get_bytes_left(&gb)) {
753 ✗ av_log(avctx, AV_LOG_ERROR, "Too many lowpass coefficients\n");
754 ✗ ret = AVERROR(EINVAL);
755 ✗ goto end;
756 }
757
758 99 av_log(avctx, AV_LOG_DEBUG, "Start of lowpass coeffs component %d height:%d, width:%d\n", s->channel_num, lowpass_height, lowpass_width);
759
2/2
✓ Branch 311 → 306 taken 4983 times.
✓ Branch 311 → 312 taken 99 times.
5082 for (int i = 0; i < lowpass_height; i++) {
760
2/2
✓ Branch 309 → 307 taken 339284 times.
✓ Branch 309 → 310 taken 4983 times.
344267 for (int j = 0; j < lowpass_width; j++)
761 339284 coeff_data[j] = bytestream2_get_be16u(&gb);
762
763 4983 coeff_data += lowpass_width;
764 }
765
766 /* Align to mod-4 position to continue reading tags */
767 99 bytestream2_seek(&gb, bytestream2_tell(&gb) & 3, SEEK_CUR);
768
769 /* Copy last line of coefficients if odd height */
770
2/2
✓ Branch 314 → 315 taken 33 times.
✓ Branch 314 → 316 taken 66 times.
99 if (lowpass_height & 1) {
771 33 memcpy(&coeff_data[lowpass_height * lowpass_width],
772 33 &coeff_data[(lowpass_height - 1) * lowpass_width],
773 33 lowpass_width * sizeof(*coeff_data));
774 }
775
776 99 s->plane[s->channel_num].band[0][0].read_ok = 1;
777
778 99 av_log(avctx, AV_LOG_DEBUG, "Lowpass coefficients %d\n", lowpass_width * lowpass_height);
779 }
780
781
1/2
✗ Branch 317 → 318 not taken.
✓ Branch 317 → 320 taken 17193 times.
17193 av_assert0(s->subband_num_actual != 255);
782
3/4
✓ Branch 320 → 321 taken 16302 times.
✓ Branch 320 → 322 taken 891 times.
✗ Branch 321 → 322 not taken.
✓ Branch 321 → 405 taken 16302 times.
17193 if (tag == BandHeader || tag == BandSecondPass) {
783 int highpass_height, highpass_width, highpass_a_width, highpass_a_height, highpass_stride, a_expected;
784 int expected;
785 GetBitContext gbit;
786 891 int count = 0, bytes;
787
788
2/4
✓ Branch 322 → 323 taken 891 times.
✗ Branch 322 → 324 not taken.
✗ Branch 323 → 324 not taken.
✓ Branch 323 → 325 taken 891 times.
891 if (!s->a_width || !s->a_height) {
789 ✗ ret = AVERROR_INVALIDDATA;
790 ✗ goto end;
791 }
792
793 891 highpass_height = s->plane[s->channel_num].band[s->level][s->subband_num].height;
794 891 highpass_width = s->plane[s->channel_num].band[s->level][s->subband_num].width;
795 891 highpass_a_width = s->plane[s->channel_num].band[s->level][s->subband_num].a_width;
796 891 highpass_a_height = s->plane[s->channel_num].band[s->level][s->subband_num].a_height;
797 891 highpass_stride = s->plane[s->channel_num].band[s->level][s->subband_num].stride;
798 891 a_expected = highpass_a_height * highpass_a_width;
799
800
1/2
✗ Branch 325 → 326 not taken.
✓ Branch 325 → 328 taken 891 times.
891 if (!got_buffer) {
801 ✗ av_log(avctx, AV_LOG_ERROR, "No end of header tag found\n");
802 ✗ ret = AVERROR(EINVAL);
803 ✗ goto end;
804 }
805
806
3/6
✓ Branch 328 → 329 taken 891 times.
✗ Branch 328 → 331 not taken.
✓ Branch 329 → 330 taken 891 times.
✗ Branch 329 → 331 not taken.
✗ Branch 330 → 331 not taken.
✓ Branch 330 → 333 taken 891 times.
891 if (highpass_height > highpass_a_height || highpass_width > highpass_a_width || a_expected < highpass_height * (uint64_t)highpass_stride) {
807 ✗ av_log(avctx, AV_LOG_ERROR, "Too many highpass coefficients\n");
808 ✗ ret = AVERROR(EINVAL);
809 ✗ goto end;
810 }
811 891 expected = highpass_height * highpass_stride;
812
813 891 av_log(avctx, AV_LOG_DEBUG, "Start subband coeffs plane %i level %i codebook %i expected %i\n", s->channel_num, s->level, s->codebook, expected);
814
815 891 ret = init_get_bits8(&gbit, gb.buffer, bytestream2_get_bytes_left(&gb));
816
1/2
✗ Branch 336 → 337 not taken.
✓ Branch 336 → 338 taken 891 times.
891 if (ret < 0)
817 ✗ goto end;
818 {
819 891 OPEN_READER(re, &gbit);
820
821 891 const int lossless = s->band_encoding == 5;
822
823
1/6
✗ Branch 338 → 339 not taken.
✓ Branch 338 → 342 taken 891 times.
✗ Branch 339 → 340 not taken.
✗ Branch 339 → 342 not taken.
✗ Branch 340 → 341 not taken.
✗ Branch 340 → 342 not taken.
891 if (s->codebook == 0 && s->transform_type == 2 && s->subband_num_actual == 7)
824 ✗ s->codebook = 1;
825
1/2
✗ Branch 342 → 343 not taken.
✓ Branch 342 → 365 taken 891 times.
891 if (!s->codebook) {
826 ✗ while (1) {
827 int level, run, coeff;
828
829 ✗ UPDATE_CACHE(re, &gbit);
830
0/4
✗ Branch 344 → 345 not taken.
✗ Branch 344 → 349 not taken.
✗ Branch 346 → 347 not taken.
✗ Branch 346 → 349 not taken.
✗ GET_RL_VLC(level, run, re, &gbit, s->table_9_rl_vlc,
831 VLC_BITS, 3, 1);
832
833 /* escape */
834
0/2
✗ Branch 349 → 350 not taken.
✗ Branch 349 → 351 not taken.
✗ if (!run)
835 ✗ break;
836
837 ✗ count += run;
838
839
0/2
✗ Branch 351 → 352 not taken.
✗ Branch 351 → 353 not taken.
✗ if (count > expected)
840 ✗ break;
841
842
0/2
✗ Branch 353 → 354 not taken.
✗ Branch 353 → 355 not taken.
✗ if (!lossless)
843 ✗ coeff = dequant_and_decompand(s, level, s->quantisation, 0);
844 else
845 ✗ coeff = level;
846
0/2
✗ Branch 356 → 357 not taken.
✗ Branch 356 → 360 not taken.
✗ if (tag == BandSecondPass) {
847 ✗ const uint16_t q = s->quantisation;
848
849
0/2
✗ Branch 359 → 358 not taken.
✗ Branch 359 → 363 not taken.
✗ for (int i = 0; i < run; i++) {
850 ✗ *coeff_data |= coeff * 256U;
851 ✗ *coeff_data++ *= q;
852 }
853 } else {
854
0/2
✗ Branch 362 → 361 not taken.
✗ Branch 362 → 363 not taken.
✗ for (int i = 0; i < run; i++)
855 ✗ *coeff_data++ = coeff;
856 }
857 }
858 } else {
859 3522977 while (1) {
860 int level, run, coeff;
861
862 3523868 UPDATE_CACHE(re, &gbit);
863
4/4
✓ Branch 366 → 367 taken 268732 times.
✓ Branch 366 → 371 taken 3255136 times.
✓ Branch 368 → 369 taken 17281 times.
✓ Branch 368 → 371 taken 251451 times.
3523868 GET_RL_VLC(level, run, re, &gbit, s->table_18_rl_vlc,
864 VLC_BITS, 3, 1);
865
866 /* escape */
867
2/2
✓ Branch 371 → 372 taken 891 times.
✓ Branch 371 → 373 taken 3522977 times.
3523868 if (!run)
868 891 break;
869
870 3522977 count += run;
871
872
1/2
✗ Branch 373 → 374 not taken.
✓ Branch 373 → 375 taken 3522977 times.
3522977 if (count > expected)
873 ✗ break;
874
875
1/2
✓ Branch 375 → 376 taken 3522977 times.
✗ Branch 375 → 377 not taken.
3522977 if (!lossless)
876 3522977 coeff = dequant_and_decompand(s, level, s->quantisation, s->codebook);
877 else
878 ✗ coeff = level;
879
1/2
✗ Branch 378 → 379 not taken.
✓ Branch 378 → 382 taken 3522977 times.
3522977 if (tag == BandSecondPass) {
880 ✗ const uint16_t q = s->quantisation;
881
882
0/2
✗ Branch 381 → 380 not taken.
✗ Branch 381 → 385 not taken.
✗ for (int i = 0; i < run; i++) {
883 ✗ *coeff_data |= coeff * 256U;
884 ✗ *coeff_data++ *= q;
885 }
886 } else {
887
2/2
✓ Branch 384 → 383 taken 21661728 times.
✓ Branch 384 → 385 taken 3522977 times.
25184705 for (int i = 0; i < run; i++)
888 21661728 *coeff_data++ = coeff;
889 }
890 }
891 }
892 891 CLOSE_READER(re, &gbit);
893 }
894
895
1/2
✗ Branch 386 → 387 not taken.
✓ Branch 386 → 389 taken 891 times.
891 if (count > expected) {
896 ✗ av_log(avctx, AV_LOG_ERROR, "Escape codeword not found, probably corrupt data\n");
897 ✗ ret = AVERROR(EINVAL);
898 ✗ goto end;
899 }
900
1/2
✗ Branch 389 → 390 not taken.
✓ Branch 389 → 391 taken 891 times.
891 if (s->peak.level)
901 ✗ peak_table(coeff_data - count, &s->peak, count);
902
1/2
✗ Branch 391 → 392 not taken.
✓ Branch 391 → 393 taken 891 times.
891 if (s->difference_coding)
903 ✗ difference_coding(s->plane[s->channel_num].subband[s->subband_num_actual], highpass_width, highpass_height);
904
905 891 bytes = FFALIGN(AV_CEIL_RSHIFT(get_bits_count(&gbit), 3), 4);
906
1/2
✗ Branch 395 → 396 not taken.
✓ Branch 395 → 398 taken 891 times.
891 if (bytes > bytestream2_get_bytes_left(&gb)) {
907 ✗ av_log(avctx, AV_LOG_ERROR, "Bitstream overread error\n");
908 ✗ ret = AVERROR(EINVAL);
909 ✗ goto end;
910 } else
911 891 bytestream2_seek(&gb, bytes, SEEK_CUR);
912
913 891 av_log(avctx, AV_LOG_DEBUG, "End subband coeffs %i extra %i\n", count, count - expected);
914 891 s->plane[s->channel_num].band[s->level][s->subband_num].read_ok = 1;
915 891 finish:
916
1/2
✓ Branch 401 → 402 taken 891 times.
✗ Branch 401 → 403 not taken.
891 if (s->subband_num_actual != 255)
917 891 s->codebook = 0;
918 }
919 }
920
921 33 s->planes = av_pix_fmt_count_planes(avctx->pix_fmt);
922
1/2
✗ Branch 409 → 410 not taken.
✓ Branch 409 → 411 taken 33 times.
33 if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16) {
923 ✗ s->progressive = 1;
924 ✗ s->planes = 4;
925 }
926
927 33 ff_thread_finish_setup(avctx);
928
929
3/6
✓ Branch 412 → 413 taken 33 times.
✗ Branch 412 → 416 not taken.
✓ Branch 413 → 414 taken 33 times.
✗ Branch 413 → 416 not taken.
✓ Branch 414 → 415 taken 33 times.
✗ Branch 414 → 416 not taken.
33 if (!s->a_width || !s->a_height || s->a_format == AV_PIX_FMT_NONE ||
930
1/2
✗ Branch 415 → 416 not taken.
✓ Branch 415 → 418 taken 33 times.
33 s->a_transform_type == INT_MIN) {
931 ✗ av_log(avctx, AV_LOG_ERROR, "Invalid dimensions\n");
932 ✗ ret = AVERROR(EINVAL);
933 ✗ goto end;
934 }
935
936
1/2
✗ Branch 418 → 419 not taken.
✓ Branch 418 → 421 taken 33 times.
33 if (!got_buffer) {
937 ✗ av_log(avctx, AV_LOG_ERROR, "No end of header tag found\n");
938 ✗ ret = AVERROR(EINVAL);
939 ✗ goto end;
940 }
941
942
2/2
✓ Branch 438 → 422 taken 99 times.
✓ Branch 438 → 439 taken 33 times.
132 for (int plane = 0; plane < s->planes; plane++) {
943
3/4
✓ Branch 433 → 434 taken 396 times.
✗ Branch 433 → 435 not taken.
✓ Branch 436 → 423 taken 297 times.
✓ Branch 436 → 437 taken 99 times.
396 for (int level = 0; level < (s->transform_type == 0 ? DWT_LEVELS : DWT_LEVELS_3D) ; level++) {
944
1/2
✗ Branch 423 → 424 not taken.
✓ Branch 423 → 427 taken 297 times.
297 if (s->transform_type == 2)
945
0/4
✗ Branch 424 → 425 not taken.
✗ Branch 424 → 426 not taken.
✗ Branch 425 → 426 not taken.
✗ Branch 425 → 427 not taken.
✗ if (level == 2 || level == 5)
946 ✗ continue;
947
2/2
✓ Branch 431 → 428 taken 990 times.
✓ Branch 431 → 432 taken 297 times.
1287 for (int o = !!level; o < 4 ; o++) {
948
1/2
✗ Branch 428 → 429 not taken.
✓ Branch 428 → 430 taken 990 times.
990 if (!s->plane[plane].band[level][o].read_ok) {
949 ✗ ret = AVERROR_INVALIDDATA;
950 ✗ goto end;
951 }
952 }
953 }
954 }
955
956
2/4
✓ Branch 439 → 440 taken 33 times.
✗ Branch 439 → 527 not taken.
✓ Branch 440 → 441 taken 33 times.
✗ Branch 440 → 527 not taken.
33 if (s->transform_type == 0 && s->sample_type != 1) {
957
3/4
✓ Branch 524 → 525 taken 99 times.
✓ Branch 524 → 526 taken 33 times.
✓ Branch 525 → 442 taken 99 times.
✗ Branch 525 → 526 not taken.
132 for (int plane = 0; plane < s->planes && !ret; plane++) {
958 /* level 1 */
959 99 int lowpass_height = s->plane[plane].band[0][0].height;
960 99 int output_stride = s->plane[plane].band[0][0].a_width;
961 99 int lowpass_width = s->plane[plane].band[0][0].width;
962 99 int highpass_stride = s->plane[plane].band[0][1].stride;
963
4/4
✓ Branch 442 → 443 taken 66 times.
✓ Branch 442 → 446 taken 33 times.
✓ Branch 443 → 444 taken 33 times.
✓ Branch 443 → 445 taken 33 times.
99 int act_plane = plane == 1 ? 2 : plane == 2 ? 1 : plane;
964 ptrdiff_t dst_linesize;
965 int16_t *low, *high, *output, *dst;
966
967
1/2
✗ Branch 447 → 448 not taken.
✓ Branch 447 → 449 taken 99 times.
99 if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16) {
968 ✗ act_plane = 0;
969 ✗ dst_linesize = pic->linesize[act_plane];
970 } else {
971 99 dst_linesize = pic->linesize[act_plane] / 2;
972 }
973
974
3/6
✓ Branch 450 → 451 taken 99 times.
✗ Branch 450 → 456 not taken.
✓ Branch 451 → 452 taken 99 times.
✗ Branch 451 → 456 not taken.
✓ Branch 452 → 453 taken 99 times.
✗ Branch 452 → 456 not taken.
99 if (lowpass_height > s->plane[plane].band[0][0].a_height || lowpass_width > s->plane[plane].band[0][0].a_width ||
975
2/4
✓ Branch 453 → 454 taken 99 times.
✗ Branch 453 → 456 not taken.
✓ Branch 454 → 455 taken 99 times.
✗ Branch 454 → 456 not taken.
99 !highpass_stride || s->plane[plane].band[0][1].width > s->plane[plane].band[0][1].a_width ||
976
1/2
✗ Branch 455 → 456 not taken.
✓ Branch 455 → 458 taken 99 times.
99 lowpass_width < 3 || lowpass_height < 3) {
977 ✗ av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
978 ✗ ret = AVERROR(EINVAL);
979 ✗ goto end;
980 }
981
982 99 av_log(avctx, AV_LOG_DEBUG, "Decoding level 1 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
983
984 99 low = s->plane[plane].subband[0];
985 99 high = s->plane[plane].subband[2];
986 99 output = s->plane[plane].l_h[0];
987 99 dsp->vert_filter(output, output_stride, low, lowpass_width, high, highpass_stride, lowpass_width, lowpass_height);
988
989 99 low = s->plane[plane].subband[1];
990 99 high = s->plane[plane].subband[3];
991 99 output = s->plane[plane].l_h[1];
992
993 99 dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
994
995 99 low = s->plane[plane].l_h[0];
996 99 high = s->plane[plane].l_h[1];
997 99 output = s->plane[plane].subband[0];
998 99 dsp->horiz_filter(output, output_stride, low, output_stride, high, output_stride, lowpass_width, lowpass_height * 2);
999
2/2
✓ Branch 462 → 463 taken 33 times.
✓ Branch 462 → 469 taken 66 times.
99 if (s->bpc == 12) {
1000 33 output = s->plane[plane].subband[0];
1001
2/2
✓ Branch 468 → 464 taken 3960 times.
✓ Branch 468 → 469 taken 33 times.
3993 for (int i = 0; i < lowpass_height * 2; i++) {
1002
2/2
✓ Branch 466 → 465 taken 712800 times.
✓ Branch 466 → 467 taken 3960 times.
716760 for (int j = 0; j < lowpass_width * 2; j++)
1003 712800 output[j] *= 4;
1004
1005 3960 output += output_stride * 2;
1006 }
1007 }
1008
1009 /* level 2 */
1010 99 lowpass_height = s->plane[plane].band[1][1].height;
1011 99 output_stride = s->plane[plane].band[1][1].a_width;
1012 99 lowpass_width = s->plane[plane].band[1][1].width;
1013 99 highpass_stride = s->plane[plane].band[1][1].stride;
1014
1015
3/6
✓ Branch 469 → 470 taken 99 times.
✗ Branch 469 → 475 not taken.
✓ Branch 470 → 471 taken 99 times.
✗ Branch 470 → 475 not taken.
✓ Branch 471 → 472 taken 99 times.
✗ Branch 471 → 475 not taken.
99 if (lowpass_height > s->plane[plane].band[1][1].a_height || lowpass_width > s->plane[plane].band[1][1].a_width ||
1016
2/4
✓ Branch 472 → 473 taken 99 times.
✗ Branch 472 → 475 not taken.
✓ Branch 473 → 474 taken 99 times.
✗ Branch 473 → 475 not taken.
99 !highpass_stride || s->plane[plane].band[1][1].width > s->plane[plane].band[1][1].a_width ||
1017
1/2
✗ Branch 474 → 475 not taken.
✓ Branch 474 → 477 taken 99 times.
99 lowpass_width < 3 || lowpass_height < 3) {
1018 ✗ av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
1019 ✗ ret = AVERROR(EINVAL);
1020 ✗ goto end;
1021 }
1022
1023 99 av_log(avctx, AV_LOG_DEBUG, "Level 2 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
1024
1025 99 low = s->plane[plane].subband[0];
1026 99 high = s->plane[plane].subband[5];
1027 99 output = s->plane[plane].l_h[3];
1028 99 dsp->vert_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1029
1030 99 low = s->plane[plane].subband[4];
1031 99 high = s->plane[plane].subband[6];
1032 99 output = s->plane[plane].l_h[4];
1033 99 dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1034
1035 99 low = s->plane[plane].l_h[3];
1036 99 high = s->plane[plane].l_h[4];
1037 99 output = s->plane[plane].subband[0];
1038 99 dsp->horiz_filter(output, output_stride, low, output_stride, high, output_stride, lowpass_width, lowpass_height * 2);
1039
1040 99 output = s->plane[plane].subband[0];
1041
2/2
✓ Branch 486 → 482 taken 19932 times.
✓ Branch 486 → 487 taken 99 times.
20031 for (int i = 0; i < lowpass_height * 2; i++) {
1042
2/2
✓ Branch 484 → 483 taken 5428544 times.
✓ Branch 484 → 485 taken 19932 times.
5448476 for (int j = 0; j < lowpass_width * 2; j++)
1043 5428544 output[j] *= 4;
1044
1045 19932 output += output_stride * 2;
1046 }
1047
1048 /* level 3 */
1049 99 lowpass_height = s->plane[plane].band[2][1].height;
1050 99 output_stride = s->plane[plane].band[2][1].a_width;
1051 99 lowpass_width = s->plane[plane].band[2][1].width;
1052 99 highpass_stride = s->plane[plane].band[2][1].stride;
1053
1054
3/6
✓ Branch 487 → 488 taken 99 times.
✗ Branch 487 → 494 not taken.
✓ Branch 488 → 489 taken 99 times.
✗ Branch 488 → 494 not taken.
✓ Branch 489 → 490 taken 99 times.
✗ Branch 489 → 494 not taken.
99 if (lowpass_height > s->plane[plane].band[2][1].a_height || lowpass_width > s->plane[plane].band[2][1].a_width ||
1055
2/4
✓ Branch 490 → 491 taken 99 times.
✗ Branch 490 → 494 not taken.
✓ Branch 491 → 492 taken 99 times.
✗ Branch 491 → 494 not taken.
99 !highpass_stride || s->plane[plane].band[2][1].width > s->plane[plane].band[2][1].a_width ||
1056
2/4
✓ Branch 492 → 493 taken 99 times.
✗ Branch 492 → 494 not taken.
✗ Branch 493 → 494 not taken.
✓ Branch 493 → 496 taken 99 times.
99 lowpass_height < 3 || lowpass_width < 3 || lowpass_width * 2 > s->plane[plane].width) {
1057 ✗ av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
1058 ✗ ret = AVERROR(EINVAL);
1059 ✗ goto end;
1060 }
1061
1062 99 av_log(avctx, AV_LOG_DEBUG, "Level 3 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
1063
1/2
✓ Branch 497 → 498 taken 99 times.
✗ Branch 497 → 516 not taken.
99 if (s->progressive) {
1064 99 low = s->plane[plane].subband[0];
1065 99 high = s->plane[plane].subband[8];
1066 99 output = s->plane[plane].l_h[6];
1067 99 dsp->vert_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1068
1069 99 low = s->plane[plane].subband[7];
1070 99 high = s->plane[plane].subband[9];
1071 99 output = s->plane[plane].l_h[7];
1072 99 dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1073
1074 99 dst = (int16_t *)pic->data[act_plane];
1075
1/2
✗ Branch 500 → 501 not taken.
✓ Branch 500 → 505 taken 99 times.
99 if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16) {
1076
0/2
✗ Branch 501 → 502 not taken.
✗ Branch 501 → 503 not taken.
✗ if (plane & 1)
1077 ✗ dst++;
1078
0/2
✗ Branch 503 → 504 not taken.
✗ Branch 503 → 505 not taken.
✗ if (plane > 1)
1079 ✗ dst += pic->linesize[act_plane] >> 1;
1080 }
1081 99 low = s->plane[plane].l_h[6];
1082 99 high = s->plane[plane].l_h[7];
1083
1084
1/2
✗ Branch 505 → 506 not taken.
✓ Branch 505 → 509 taken 99 times.
99 if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16 &&
1085
0/2
✗ Branch 506 → 507 not taken.
✗ Branch 506 → 508 not taken.
✗ (lowpass_height * 2 > avctx->coded_height / 2 ||
1086
0/2
✗ Branch 507 → 508 not taken.
✗ Branch 507 → 509 not taken.
✗ lowpass_width * 2 > avctx->coded_width / 2 )
1087 ) {
1088 ✗ ret = AVERROR_INVALIDDATA;
1089 ✗ goto end;
1090 }
1091
1092
2/2
✓ Branch 515 → 510 taken 39864 times.
✓ Branch 515 → 523 taken 99 times.
39963 for (int i = 0; i < s->plane[act_plane].height; i++) {
1093 39864 dsp->horiz_filter_clip(dst, low, high, lowpass_width, s->bpc);
1094
1/4
✗ Branch 511 → 512 not taken.
✓ Branch 511 → 514 taken 39864 times.
✗ Branch 512 → 513 not taken.
✗ Branch 512 → 514 not taken.
39864 if (avctx->pix_fmt == AV_PIX_FMT_GBRAP12 && act_plane == 3)
1095 ✗ process_alpha(dst, lowpass_width * 2);
1096 39864 low += output_stride;
1097 39864 high += output_stride;
1098 39864 dst += dst_linesize;
1099 }
1100 } else {
1101 ✗ av_log(avctx, AV_LOG_DEBUG, "interlaced frame ? %d", !!(pic->flags & AV_FRAME_FLAG_INTERLACED));
1102 ✗ pic->flags |= AV_FRAME_FLAG_INTERLACED;
1103 ✗ low = s->plane[plane].subband[0];
1104 ✗ high = s->plane[plane].subband[7];
1105 ✗ output = s->plane[plane].l_h[6];
1106 ✗ dsp->horiz_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1107
1108 ✗ low = s->plane[plane].subband[8];
1109 ✗ high = s->plane[plane].subband[9];
1110 ✗ output = s->plane[plane].l_h[7];
1111 ✗ dsp->horiz_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1112
1113 ✗ dst = (int16_t *)pic->data[act_plane];
1114 ✗ low = s->plane[plane].l_h[6];
1115 ✗ high = s->plane[plane].l_h[7];
1116
0/2
✗ Branch 522 → 520 not taken.
✗ Branch 522 → 523 not taken.
✗ for (int i = 0; i < s->plane[act_plane].height / 2; i++) {
1117 ✗ interlaced_vertical_filter(dst, low, high, lowpass_width * 2, pic->linesize[act_plane]/2, act_plane);
1118 ✗ low += output_stride * 2;
1119 ✗ high += output_stride * 2;
1120 ✗ dst += pic->linesize[act_plane];
1121 }
1122 }
1123 }
1124
0/8
✗ Branch 527 → 528 not taken.
✗ Branch 527 → 627 not taken.
✗ Branch 528 → 529 not taken.
✗ Branch 528 → 531 not taken.
✗ Branch 529 → 530 not taken.
✗ Branch 529 → 531 not taken.
✗ Branch 530 → 531 not taken.
✗ Branch 530 → 627 not taken.
✗ } else if (s->transform_type == 2 && (avctx->internal->is_copy || s->frame_index == 1 || s->sample_type != 1)) {
1125
0/4
✗ Branch 625 → 626 not taken.
✗ Branch 625 → 627 not taken.
✗ Branch 626 → 532 not taken.
✗ Branch 626 → 627 not taken.
✗ for (int plane = 0; plane < s->planes && !ret; plane++) {
1126 ✗ int lowpass_height = s->plane[plane].band[0][0].height;
1127 ✗ int output_stride = s->plane[plane].band[0][0].a_width;
1128 ✗ int lowpass_width = s->plane[plane].band[0][0].width;
1129 ✗ int highpass_stride = s->plane[plane].band[0][1].stride;
1130
0/4
✗ Branch 532 → 533 not taken.
✗ Branch 532 → 536 not taken.
✗ Branch 533 → 534 not taken.
✗ Branch 533 → 535 not taken.
✗ int act_plane = plane == 1 ? 2 : plane == 2 ? 1 : plane;
1131 int16_t *low, *high, *output, *dst;
1132 ptrdiff_t dst_linesize;
1133
1134
0/2
✗ Branch 537 → 538 not taken.
✗ Branch 537 → 539 not taken.
✗ if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16) {
1135 ✗ act_plane = 0;
1136 ✗ dst_linesize = pic->linesize[act_plane];
1137 } else {
1138 ✗ dst_linesize = pic->linesize[act_plane] / 2;
1139 }
1140
1141
0/6
✗ Branch 540 → 541 not taken.
✗ Branch 540 → 546 not taken.
✗ Branch 541 → 542 not taken.
✗ Branch 541 → 546 not taken.
✗ Branch 542 → 543 not taken.
✗ Branch 542 → 546 not taken.
✗ if (lowpass_height > s->plane[plane].band[0][0].a_height || lowpass_width > s->plane[plane].band[0][0].a_width ||
1142
0/4
✗ Branch 543 → 544 not taken.
✗ Branch 543 → 546 not taken.
✗ Branch 544 → 545 not taken.
✗ Branch 544 → 546 not taken.
✗ !highpass_stride || s->plane[plane].band[0][1].width > s->plane[plane].band[0][1].a_width ||
1143
0/2
✗ Branch 545 → 546 not taken.
✗ Branch 545 → 548 not taken.
✗ lowpass_width < 3 || lowpass_height < 3) {
1144 ✗ av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
1145 ✗ ret = AVERROR(EINVAL);
1146 ✗ goto end;
1147 }
1148
1149 ✗ av_log(avctx, AV_LOG_DEBUG, "Decoding level 1 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
1150
1151 ✗ low = s->plane[plane].subband[0];
1152 ✗ high = s->plane[plane].subband[2];
1153 ✗ output = s->plane[plane].l_h[0];
1154 ✗ dsp->vert_filter(output, output_stride, low, lowpass_width, high, highpass_stride, lowpass_width, lowpass_height);
1155
1156 ✗ low = s->plane[plane].subband[1];
1157 ✗ high = s->plane[plane].subband[3];
1158 ✗ output = s->plane[plane].l_h[1];
1159 ✗ dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1160
1161 ✗ low = s->plane[plane].l_h[0];
1162 ✗ high = s->plane[plane].l_h[1];
1163 ✗ output = s->plane[plane].l_h[7];
1164 ✗ dsp->horiz_filter(output, output_stride, low, output_stride, high, output_stride, lowpass_width, lowpass_height * 2);
1165
0/2
✗ Branch 552 → 553 not taken.
✗ Branch 552 → 559 not taken.
✗ if (s->bpc == 12) {
1166 ✗ output = s->plane[plane].l_h[7];
1167
0/2
✗ Branch 558 → 554 not taken.
✗ Branch 558 → 559 not taken.
✗ for (int i = 0; i < lowpass_height * 2; i++) {
1168
0/2
✗ Branch 556 → 555 not taken.
✗ Branch 556 → 557 not taken.
✗ for (int j = 0; j < lowpass_width * 2; j++)
1169 ✗ output[j] *= 4;
1170
1171 ✗ output += output_stride * 2;
1172 }
1173 }
1174
1175 ✗ lowpass_height = s->plane[plane].band[1][1].height;
1176 ✗ output_stride = s->plane[plane].band[1][1].a_width;
1177 ✗ lowpass_width = s->plane[plane].band[1][1].width;
1178 ✗ highpass_stride = s->plane[plane].band[1][1].stride;
1179
1180
0/6
✗ Branch 559 → 560 not taken.
✗ Branch 559 → 565 not taken.
✗ Branch 560 → 561 not taken.
✗ Branch 560 → 565 not taken.
✗ Branch 561 → 562 not taken.
✗ Branch 561 → 565 not taken.
✗ if (lowpass_height > s->plane[plane].band[1][1].a_height || lowpass_width > s->plane[plane].band[1][1].a_width ||
1181
0/4
✗ Branch 562 → 563 not taken.
✗ Branch 562 → 565 not taken.
✗ Branch 563 → 564 not taken.
✗ Branch 563 → 565 not taken.
✗ !highpass_stride || s->plane[plane].band[1][1].width > s->plane[plane].band[1][1].a_width ||
1182
0/2
✗ Branch 564 → 565 not taken.
✗ Branch 564 → 567 not taken.
✗ lowpass_width < 3 || lowpass_height < 3) {
1183 ✗ av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
1184 ✗ ret = AVERROR(EINVAL);
1185 ✗ goto end;
1186 }
1187
1188 ✗ av_log(avctx, AV_LOG_DEBUG, "Level 2 lowpass plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
1189
1190 ✗ low = s->plane[plane].l_h[7];
1191 ✗ high = s->plane[plane].subband[5];
1192 ✗ output = s->plane[plane].l_h[3];
1193 ✗ dsp->vert_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1194
1195 ✗ low = s->plane[plane].subband[4];
1196 ✗ high = s->plane[plane].subband[6];
1197 ✗ output = s->plane[plane].l_h[4];
1198 ✗ dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1199
1200 ✗ low = s->plane[plane].l_h[3];
1201 ✗ high = s->plane[plane].l_h[4];
1202 ✗ output = s->plane[plane].l_h[7];
1203 ✗ dsp->horiz_filter(output, output_stride, low, output_stride, high, output_stride, lowpass_width, lowpass_height * 2);
1204
1205 ✗ output = s->plane[plane].l_h[7];
1206
0/2
✗ Branch 576 → 572 not taken.
✗ Branch 576 → 577 not taken.
✗ for (int i = 0; i < lowpass_height * 2; i++) {
1207
0/2
✗ Branch 574 → 573 not taken.
✗ Branch 574 → 575 not taken.
✗ for (int j = 0; j < lowpass_width * 2; j++)
1208 ✗ output[j] *= 4;
1209 ✗ output += output_stride * 2;
1210 }
1211
1212 ✗ low = s->plane[plane].subband[7];
1213 ✗ high = s->plane[plane].subband[9];
1214 ✗ output = s->plane[plane].l_h[3];
1215 ✗ dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1216
1217 ✗ low = s->plane[plane].subband[8];
1218 ✗ high = s->plane[plane].subband[10];
1219 ✗ output = s->plane[plane].l_h[4];
1220 ✗ dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1221
1222 ✗ low = s->plane[plane].l_h[3];
1223 ✗ high = s->plane[plane].l_h[4];
1224 ✗ output = s->plane[plane].l_h[9];
1225 ✗ dsp->horiz_filter(output, output_stride, low, output_stride, high, output_stride, lowpass_width, lowpass_height * 2);
1226
1227 ✗ lowpass_height = s->plane[plane].band[4][1].height;
1228 ✗ output_stride = s->plane[plane].band[4][1].a_width;
1229 ✗ lowpass_width = s->plane[plane].band[4][1].width;
1230 ✗ highpass_stride = s->plane[plane].band[4][1].stride;
1231 ✗ av_log(avctx, AV_LOG_DEBUG, "temporal level %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
1232
1233
0/6
✗ Branch 581 → 582 not taken.
✗ Branch 581 → 588 not taken.
✗ Branch 582 → 583 not taken.
✗ Branch 582 → 588 not taken.
✗ Branch 583 → 584 not taken.
✗ Branch 583 → 588 not taken.
✗ if (lowpass_height > s->plane[plane].band[4][1].a_height || lowpass_width > s->plane[plane].band[4][1].a_width ||
1234
0/4
✗ Branch 584 → 585 not taken.
✗ Branch 584 → 588 not taken.
✗ Branch 585 → 586 not taken.
✗ Branch 585 → 588 not taken.
✗ !highpass_stride || s->plane[plane].band[4][1].width > s->plane[plane].band[4][1].a_width ||
1235
0/4
✗ Branch 586 → 587 not taken.
✗ Branch 586 → 588 not taken.
✗ Branch 587 → 588 not taken.
✗ Branch 587 → 590 not taken.
✗ lowpass_width < 3 || lowpass_height < 3 || lowpass_width * 2 > s->plane[plane].width) {
1236 ✗ av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
1237 ✗ ret = AVERROR(EINVAL);
1238 ✗ goto end;
1239 }
1240
1241 ✗ low = s->plane[plane].l_h[7];
1242 ✗ high = s->plane[plane].l_h[9];
1243 ✗ output = s->plane[plane].l_h[7];
1244
0/2
✗ Branch 593 → 591 not taken.
✗ Branch 593 → 594 not taken.
✗ for (int i = 0; i < lowpass_height; i++) {
1245 ✗ inverse_temporal_filter(low, high, lowpass_width);
1246 ✗ low += output_stride;
1247 ✗ high += output_stride;
1248 }
1249
0/2
✗ Branch 594 → 595 not taken.
✗ Branch 594 → 614 not taken.
✗ if (s->progressive) {
1250 ✗ low = s->plane[plane].l_h[7];
1251 ✗ high = s->plane[plane].subband[15];
1252 ✗ output = s->plane[plane].l_h[6];
1253 ✗ dsp->vert_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1254
1255 ✗ low = s->plane[plane].subband[14];
1256 ✗ high = s->plane[plane].subband[16];
1257 ✗ output = s->plane[plane].l_h[7];
1258 ✗ dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1259
1260 ✗ low = s->plane[plane].l_h[9];
1261 ✗ high = s->plane[plane].subband[12];
1262 ✗ output = s->plane[plane].l_h[8];
1263 ✗ dsp->vert_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1264
1265 ✗ low = s->plane[plane].subband[11];
1266 ✗ high = s->plane[plane].subband[13];
1267 ✗ output = s->plane[plane].l_h[9];
1268 ✗ dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1269
1270
0/2
✗ Branch 599 → 600 not taken.
✗ Branch 599 → 601 not taken.
✗ if (s->sample_type == 1)
1271 ✗ continue;
1272
1273 ✗ dst = (int16_t *)pic->data[act_plane];
1274
0/2
✗ Branch 601 → 602 not taken.
✗ Branch 601 → 606 not taken.
✗ if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16) {
1275
0/2
✗ Branch 602 → 603 not taken.
✗ Branch 602 → 604 not taken.
✗ if (plane & 1)
1276 ✗ dst++;
1277
0/2
✗ Branch 604 → 605 not taken.
✗ Branch 604 → 606 not taken.
✗ if (plane > 1)
1278 ✗ dst += pic->linesize[act_plane] >> 1;
1279 }
1280
1281
0/2
✗ Branch 606 → 607 not taken.
✗ Branch 606 → 610 not taken.
✗ if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16 &&
1282
0/2
✗ Branch 607 → 608 not taken.
✗ Branch 607 → 609 not taken.
✗ (lowpass_height * 2 > avctx->coded_height / 2 ||
1283
0/2
✗ Branch 608 → 609 not taken.
✗ Branch 608 → 610 not taken.
✗ lowpass_width * 2 > avctx->coded_width / 2 )
1284 ) {
1285 ✗ ret = AVERROR_INVALIDDATA;
1286 ✗ goto end;
1287 }
1288
1289 ✗ low = s->plane[plane].l_h[6];
1290 ✗ high = s->plane[plane].l_h[7];
1291
0/2
✗ Branch 613 → 611 not taken.
✗ Branch 613 → 624 not taken.
✗ for (int i = 0; i < s->plane[act_plane].height; i++) {
1292 ✗ dsp->horiz_filter_clip(dst, low, high, lowpass_width, s->bpc);
1293 ✗ low += output_stride;
1294 ✗ high += output_stride;
1295 ✗ dst += dst_linesize;
1296 }
1297 } else {
1298 ✗ pic->flags |= AV_FRAME_FLAG_INTERLACED;
1299 ✗ low = s->plane[plane].l_h[7];
1300 ✗ high = s->plane[plane].subband[14];
1301 ✗ output = s->plane[plane].l_h[6];
1302 ✗ dsp->horiz_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1303
1304 ✗ low = s->plane[plane].subband[15];
1305 ✗ high = s->plane[plane].subband[16];
1306 ✗ output = s->plane[plane].l_h[7];
1307 ✗ dsp->horiz_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1308
1309 ✗ low = s->plane[plane].l_h[9];
1310 ✗ high = s->plane[plane].subband[11];
1311 ✗ output = s->plane[plane].l_h[8];
1312 ✗ dsp->horiz_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1313
1314 ✗ low = s->plane[plane].subband[12];
1315 ✗ high = s->plane[plane].subband[13];
1316 ✗ output = s->plane[plane].l_h[9];
1317 ✗ dsp->horiz_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1318
1319
0/2
✗ Branch 618 → 619 not taken.
✗ Branch 618 → 620 not taken.
✗ if (s->sample_type == 1)
1320 ✗ continue;
1321
1322 ✗ dst = (int16_t *)pic->data[act_plane];
1323 ✗ low = s->plane[plane].l_h[6];
1324 ✗ high = s->plane[plane].l_h[7];
1325
0/2
✗ Branch 623 → 621 not taken.
✗ Branch 623 → 624 not taken.
✗ for (int i = 0; i < s->plane[act_plane].height / 2; i++) {
1326 ✗ interlaced_vertical_filter(dst, low, high, lowpass_width * 2, pic->linesize[act_plane]/2, act_plane);
1327 ✗ low += output_stride * 2;
1328 ✗ high += output_stride * 2;
1329 ✗ dst += pic->linesize[act_plane];
1330 }
1331 }
1332 }
1333 }
1334
1335
1/4
✗ Branch 627 → 628 not taken.
✓ Branch 627 → 666 taken 33 times.
✗ Branch 628 → 629 not taken.
✗ Branch 628 → 666 not taken.
33 if (s->transform_type == 2 && s->sample_type == 1) {
1336 int16_t *low, *high, *dst;
1337 int output_stride, lowpass_height, lowpass_width;
1338 ptrdiff_t dst_linesize;
1339
1340
0/2
✗ Branch 665 → 630 not taken.
✗ Branch 665 → 666 not taken.
✗ for (int plane = 0; plane < s->planes; plane++) {
1341
0/4
✗ Branch 630 → 631 not taken.
✗ Branch 630 → 634 not taken.
✗ Branch 631 → 632 not taken.
✗ Branch 631 → 633 not taken.
✗ int act_plane = plane == 1 ? 2 : plane == 2 ? 1 : plane;
1342
1343
0/2
✗ Branch 635 → 636 not taken.
✗ Branch 635 → 637 not taken.
✗ if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16) {
1344 ✗ act_plane = 0;
1345 ✗ dst_linesize = pic->linesize[act_plane];
1346 } else {
1347 ✗ dst_linesize = pic->linesize[act_plane] / 2;
1348 }
1349
1350 ✗ lowpass_height = s->plane[plane].band[4][1].height;
1351 ✗ output_stride = s->plane[plane].band[4][1].a_width;
1352 ✗ lowpass_width = s->plane[plane].band[4][1].width;
1353
1354
0/4
✗ Branch 638 → 639 not taken.
✗ Branch 638 → 644 not taken.
✗ Branch 639 → 640 not taken.
✗ Branch 639 → 644 not taken.
✗ if (lowpass_height > s->plane[plane].band[4][1].a_height || lowpass_width > s->plane[plane].band[4][1].a_width ||
1355
0/4
✗ Branch 640 → 641 not taken.
✗ Branch 640 → 644 not taken.
✗ Branch 641 → 642 not taken.
✗ Branch 641 → 644 not taken.
✗ s->plane[plane].band[4][1].width > s->plane[plane].band[4][1].a_width ||
1356
0/4
✗ Branch 642 → 643 not taken.
✗ Branch 642 → 644 not taken.
✗ Branch 643 → 644 not taken.
✗ Branch 643 → 646 not taken.
✗ lowpass_width < 3 || lowpass_height < 3 || lowpass_width * 2 > s->plane[plane].width) {
1357 ✗ av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
1358 ✗ ret = AVERROR(EINVAL);
1359 ✗ goto end;
1360 }
1361
1362
0/2
✗ Branch 646 → 647 not taken.
✗ Branch 646 → 660 not taken.
✗ if (s->progressive) {
1363 ✗ dst = (int16_t *)pic->data[act_plane];
1364 ✗ low = s->plane[plane].l_h[8];
1365 ✗ high = s->plane[plane].l_h[9];
1366
1367
0/2
✗ Branch 647 → 648 not taken.
✗ Branch 647 → 652 not taken.
✗ if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16) {
1368
0/2
✗ Branch 648 → 649 not taken.
✗ Branch 648 → 650 not taken.
✗ if (plane & 1)
1369 ✗ dst++;
1370
0/2
✗ Branch 650 → 651 not taken.
✗ Branch 650 → 652 not taken.
✗ if (plane > 1)
1371 ✗ dst += pic->linesize[act_plane] >> 1;
1372 }
1373
1374
0/2
✗ Branch 652 → 653 not taken.
✗ Branch 652 → 656 not taken.
✗ if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16 &&
1375
0/2
✗ Branch 653 → 654 not taken.
✗ Branch 653 → 655 not taken.
✗ (lowpass_height * 2 > avctx->coded_height / 2 ||
1376
0/2
✗ Branch 654 → 655 not taken.
✗ Branch 654 → 656 not taken.
✗ lowpass_width * 2 > avctx->coded_width / 2 )
1377 ) {
1378 ✗ ret = AVERROR_INVALIDDATA;
1379 ✗ goto end;
1380 }
1381
1382
0/2
✗ Branch 659 → 657 not taken.
✗ Branch 659 → 664 not taken.
✗ for (int i = 0; i < s->plane[act_plane].height; i++) {
1383 ✗ dsp->horiz_filter_clip(dst, low, high, lowpass_width, s->bpc);
1384 ✗ low += output_stride;
1385 ✗ high += output_stride;
1386 ✗ dst += dst_linesize;
1387 }
1388 } else {
1389 ✗ dst = (int16_t *)pic->data[act_plane];
1390 ✗ low = s->plane[plane].l_h[8];
1391 ✗ high = s->plane[plane].l_h[9];
1392
0/2
✗ Branch 663 → 661 not taken.
✗ Branch 663 → 664 not taken.
✗ for (int i = 0; i < s->plane[act_plane].height / 2; i++) {
1393 ✗ interlaced_vertical_filter(dst, low, high, lowpass_width * 2, pic->linesize[act_plane]/2, act_plane);
1394 ✗ low += output_stride * 2;
1395 ✗ high += output_stride * 2;
1396 ✗ dst += pic->linesize[act_plane];
1397 }
1398 }
1399 }
1400 }
1401
1402
1/2
✓ Branch 666 → 667 taken 33 times.
✗ Branch 666 → 668 not taken.
33 if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16)
1403 ✗ process_bayer(pic, s->bpc);
1404 33 end:
1405
1/2
✗ Branch 669 → 670 not taken.
✓ Branch 669 → 671 taken 33 times.
33 if (ret < 0)
1406 ✗ return ret;
1407
1408 33 *got_frame = 1;
1409 33 return avpkt->size;
1410 }
1411
1412 6 static av_cold int cfhd_close(AVCodecContext *avctx)
1413 {
1414 6 CFHDContext *s = avctx->priv_data;
1415
1416 6 free_buffers(s);
1417
1418 6 return 0;
1419 }
1420
1421 #if HAVE_THREADS
1422 ✗ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
1423 {
1424 ✗ CFHDContext *psrc = src->priv_data;
1425 ✗ CFHDContext *pdst = dst->priv_data;
1426 int ret;
1427
1428
0/4
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 4 not taken.
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✗ if (dst == src || psrc->transform_type == 0)
1429 ✗ return 0;
1430
1431
0/2
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 10 not taken.
✗ if (pdst->plane[0].idwt_size != psrc->plane[0].idwt_size ||
1432
0/2
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 10 not taken.
✗ pdst->a_format != psrc->a_format ||
1433
0/2
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 10 not taken.
✗ pdst->a_width != psrc->a_width ||
1434
0/2
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 10 not taken.
✗ pdst->a_height != psrc->a_height ||
1435
0/2
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 11 not taken.
✗ pdst->a_transform_type != psrc->a_transform_type)
1436 ✗ free_buffers(pdst);
1437
1438 ✗ pdst->a_format = psrc->a_format;
1439 ✗ pdst->a_width = psrc->a_width;
1440 ✗ pdst->a_height = psrc->a_height;
1441 ✗ pdst->a_transform_type = psrc->a_transform_type;
1442 ✗ pdst->transform_type = psrc->transform_type;
1443 ✗ pdst->progressive = psrc->progressive;
1444 ✗ pdst->planes = psrc->planes;
1445
1446
0/2
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 15 not taken.
✗ if (!pdst->plane[0].idwt_buf) {
1447 ✗ pdst->coded_width = pdst->a_width;
1448 ✗ pdst->coded_height = pdst->a_height;
1449 ✗ pdst->coded_format = pdst->a_format;
1450 ✗ pdst->transform_type = pdst->a_transform_type;
1451 ✗ ret = alloc_buffers(dst);
1452
0/2
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 15 not taken.
✗ if (ret < 0)
1453 ✗ return ret;
1454 }
1455
1456
0/2
✗ Branch 17 → 16 not taken.
✗ Branch 17 → 18 not taken.
✗ for (int plane = 0; plane < pdst->planes; plane++) {
1457 ✗ memcpy(pdst->plane[plane].band, psrc->plane[plane].band, sizeof(pdst->plane[plane].band));
1458 ✗ memcpy(pdst->plane[plane].idwt_buf, psrc->plane[plane].idwt_buf,
1459 ✗ pdst->plane[plane].idwt_size * sizeof(int16_t));
1460 }
1461
1462 ✗ return 0;
1463 }
1464 #endif
1465
1466 const FFCodec ff_cfhd_decoder = {
1467 .p.name = "cfhd",
1468 CODEC_LONG_NAME("GoPro CineForm HD"),
1469 .p.type = AVMEDIA_TYPE_VIDEO,
1470 .p.id = AV_CODEC_ID_CFHD,
1471 .priv_data_size = sizeof(CFHDContext),
1472 .init = cfhd_init,
1473 .close = cfhd_close,
1474 FF_CODEC_DECODE_CB(cfhd_decode),
1475 UPDATE_THREAD_CONTEXT(update_thread_context),
1476 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
1477 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
1478 };
1479