FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/mjpegdec.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 1221 1865 65.5%
Functions: 32 33 97.0%
Branches: 898 1699 52.9%

Line Branch Exec Source
1 /*
2 * MJPEG decoder
3 * Copyright (c) 2000, 2001 Fabrice Bellard
4 * Copyright (c) 2003 Alex Beregszaszi
5 * Copyright (c) 2003-2004 Michael Niedermayer
6 *
7 * Support for external huffman table, various fixes (AVID workaround),
8 * aspecting, new decode_frame mechanism and apple mjpeg-b support
9 * by Alex Beregszaszi
10 *
11 * This file is part of FFmpeg.
12 *
13 * FFmpeg is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
17 *
18 * FFmpeg is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
22 *
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with FFmpeg; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 */
27
28 /**
29 * @file
30 * MJPEG decoder.
31 */
32
33 #include "config_components.h"
34
35 #include "libavutil/display.h"
36 #include "libavutil/emms.h"
37 #include "libavutil/imgutils.h"
38 #include "libavutil/avassert.h"
39 #include "libavutil/mem.h"
40 #include "libavutil/opt.h"
41 #include "avcodec.h"
42 #include "blockdsp.h"
43 #include "codec_internal.h"
44 #include "copy_block.h"
45 #include "decode.h"
46 #include "hwaccel_internal.h"
47 #include "hwconfig.h"
48 #include "idctdsp.h"
49 #include "internal.h"
50 #include "jpegtables.h"
51 #include "mjpeg.h"
52 #include "mjpegdec.h"
53 #include "jpeglsdec.h"
54 #include "profiles.h"
55 #include "put_bits.h"
56 #include "exif.h"
57 #include "bytestream.h"
58 #include "tiff_common.h"
59
60
61 211 static int init_default_huffman_tables(MJpegDecodeContext *s)
62 {
63 static const struct {
64 int class;
65 int index;
66 const uint8_t *bits;
67 const uint8_t *values;
68 int length;
69 } ht[] = {
70 { 0, 0, ff_mjpeg_bits_dc_luminance,
71 ff_mjpeg_val_dc, 12 },
72 { 0, 1, ff_mjpeg_bits_dc_chrominance,
73 ff_mjpeg_val_dc, 12 },
74 { 1, 0, ff_mjpeg_bits_ac_luminance,
75 ff_mjpeg_val_ac_luminance, 162 },
76 { 1, 1, ff_mjpeg_bits_ac_chrominance,
77 ff_mjpeg_val_ac_chrominance, 162 },
78 { 2, 0, ff_mjpeg_bits_ac_luminance,
79 ff_mjpeg_val_ac_luminance, 162 },
80 { 2, 1, ff_mjpeg_bits_ac_chrominance,
81 ff_mjpeg_val_ac_chrominance, 162 },
82 };
83 int i, ret;
84
85
2/2
✓ Branch 0 taken 1266 times.
✓ Branch 1 taken 211 times.
1477 for (i = 0; i < FF_ARRAY_ELEMS(ht); i++) {
86 1266 ff_vlc_free(&s->vlcs[ht[i].class][ht[i].index]);
87 1266 ret = ff_mjpeg_build_vlc(&s->vlcs[ht[i].class][ht[i].index],
88 1266 ht[i].bits, ht[i].values,
89 1266 ht[i].class == 1, s->avctx);
90
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1266 times.
1266 if (ret < 0)
91 return ret;
92
93
2/2
✓ Branch 0 taken 844 times.
✓ Branch 1 taken 422 times.
1266 if (ht[i].class < 2) {
94 844 memcpy(s->raw_huffman_lengths[ht[i].class][ht[i].index],
95 844 ht[i].bits + 1, 16);
96 844 memcpy(s->raw_huffman_values[ht[i].class][ht[i].index],
97 844 ht[i].values, ht[i].length);
98 }
99 }
100
101 211 return 0;
102 }
103
104 11 static void parse_avid(MJpegDecodeContext *s, uint8_t *buf, int len)
105 {
106 11 s->buggy_avid = 1;
107
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 if (len > 14 && buf[12] == 1) /* 1 - NTSC */
108 11 s->interlace_polarity = 1;
109
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
11 if (len > 14 && buf[12] == 2) /* 2 - PAL */
110 s->interlace_polarity = 0;
111
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
112 av_log(s->avctx, AV_LOG_INFO, "AVID: len:%d %d\n", len, len > 14 ? buf[12] : -1);
113 11 }
114
115 319 static void init_idct(AVCodecContext *avctx)
116 {
117 319 MJpegDecodeContext *s = avctx->priv_data;
118
119 319 ff_idctdsp_init(&s->idsp, avctx);
120 319 ff_permute_scantable(s->permutated_scantable, ff_zigzag_direct,
121 319 s->idsp.idct_permutation);
122 319 }
123
124 211 av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx)
125 {
126 211 MJpegDecodeContext *s = avctx->priv_data;
127 int ret;
128
129
2/2
✓ Branch 0 taken 209 times.
✓ Branch 1 taken 2 times.
211 if (!s->picture_ptr) {
130 209 s->picture = av_frame_alloc();
131
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 209 times.
209 if (!s->picture)
132 return AVERROR(ENOMEM);
133 209 s->picture_ptr = s->picture;
134 }
135
136 211 s->avctx = avctx;
137 211 ff_blockdsp_init(&s->bdsp);
138 211 ff_hpeldsp_init(&s->hdsp, avctx->flags);
139 211 init_idct(avctx);
140 211 s->buffer_size = 0;
141 211 s->buffer = NULL;
142 211 s->start_code = -1;
143 211 s->first_picture = 1;
144 211 s->got_picture = 0;
145 211 s->orig_height = avctx->coded_height;
146 211 avctx->chroma_sample_location = AVCHROMA_LOC_CENTER;
147 211 avctx->colorspace = AVCOL_SPC_BT470BG;
148 211 s->hwaccel_pix_fmt = s->hwaccel_sw_pix_fmt = AV_PIX_FMT_NONE;
149
150
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 211 times.
211 if ((ret = init_default_huffman_tables(s)) < 0)
151 return ret;
152
153
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 211 times.
211 if (s->extern_huff) {
154 av_log(avctx, AV_LOG_INFO, "using external huffman table\n");
155 if ((ret = init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size * 8)) < 0)
156 return ret;
157 if (ff_mjpeg_decode_dht(s)) {
158 av_log(avctx, AV_LOG_ERROR,
159 "error using external huffman table, switching back to internal\n");
160 if ((ret = init_default_huffman_tables(s)) < 0)
161 return ret;
162 }
163 }
164
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 211 times.
211 if (avctx->field_order == AV_FIELD_BB) { /* quicktime icefloe 019 */
165 s->interlace_polarity = 1; /* bottom field first */
166 av_log(avctx, AV_LOG_DEBUG, "bottom field first\n");
167
2/2
✓ Branch 0 taken 209 times.
✓ Branch 1 taken 2 times.
211 } else if (avctx->field_order == AV_FIELD_UNKNOWN) {
168
2/2
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 158 times.
209 if (avctx->codec_tag == AV_RL32("MJPG"))
169 51 s->interlace_polarity = 1;
170 }
171
172
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 209 times.
211 if (avctx->codec_id == AV_CODEC_ID_SMVJPEG) {
173
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (avctx->extradata_size >= 4)
174 2 s->smv_frames_per_jpeg = AV_RL32(avctx->extradata);
175
176
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (s->smv_frames_per_jpeg <= 0) {
177 av_log(avctx, AV_LOG_ERROR, "Invalid number of frames per jpeg.\n");
178 return AVERROR_INVALIDDATA;
179 }
180
181 2 s->smv_frame = av_frame_alloc();
182
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!s->smv_frame)
183 return AVERROR(ENOMEM);
184
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 207 times.
209 } else if (avctx->extradata_size > 8
185
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 && AV_RL32(avctx->extradata) == 0x2C
186 && AV_RL32(avctx->extradata+4) == 0x18) {
187 parse_avid(s, avctx->extradata, avctx->extradata_size);
188 }
189
190
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 200 times.
211 if (avctx->codec->id == AV_CODEC_ID_AMV)
191 11 s->flipped = 1;
192
193 211 return 0;
194 }
195
196
197 /* quantize tables */
198 2606 int ff_mjpeg_decode_dqt(MJpegDecodeContext *s)
199 {
200 int len, index, i;
201
202 2606 len = get_bits(&s->gb, 16) - 2;
203
204
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2606 times.
2606 if (8*len > get_bits_left(&s->gb)) {
205 av_log(s->avctx, AV_LOG_ERROR, "dqt: len %d is too large\n", len);
206 return AVERROR_INVALIDDATA;
207 }
208
209
2/2
✓ Branch 0 taken 3126 times.
✓ Branch 1 taken 2606 times.
5732 while (len >= 65) {
210 3126 int pr = get_bits(&s->gb, 4);
211
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3126 times.
3126 if (pr > 1) {
212 av_log(s->avctx, AV_LOG_ERROR, "dqt: invalid precision\n");
213 return AVERROR_INVALIDDATA;
214 }
215 3126 index = get_bits(&s->gb, 4);
216
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3126 times.
3126 if (index >= 4)
217 return -1;
218 3126 av_log(s->avctx, AV_LOG_DEBUG, "index=%d\n", index);
219 /* read quant table */
220
2/2
✓ Branch 0 taken 200064 times.
✓ Branch 1 taken 3126 times.
203190 for (i = 0; i < 64; i++) {
221
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 200064 times.
200064 s->quant_matrixes[index][i] = get_bits(&s->gb, pr ? 16 : 8);
222
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 200064 times.
200064 if (s->quant_matrixes[index][i] == 0) {
223 int log_level = s->avctx->err_recognition & AV_EF_EXPLODE ? AV_LOG_ERROR : AV_LOG_WARNING;
224 av_log(s->avctx, log_level, "dqt: 0 quant value\n");
225 if (s->avctx->err_recognition & AV_EF_EXPLODE)
226 return AVERROR_INVALIDDATA;
227 }
228 }
229
230 // XXX FIXME fine-tune, and perhaps add dc too
231 3126 s->qscale[index] = FFMAX(s->quant_matrixes[index][1],
232 3126 s->quant_matrixes[index][8]) >> 1;
233 3126 av_log(s->avctx, AV_LOG_DEBUG, "qscale[%d]: %d\n",
234 index, s->qscale[index]);
235 3126 len -= 1 + 64 * (1+pr);
236 }
237 2606 return 0;
238 }
239
240 /* decode huffman tables and build VLC decoders */
241 2652 int ff_mjpeg_decode_dht(MJpegDecodeContext *s)
242 {
243 int len, index, i, class, n, v;
244 uint8_t bits_table[17];
245 uint8_t val_table[256];
246 2652 int ret = 0;
247
248 2652 len = get_bits(&s->gb, 16) - 2;
249
250
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
2652 if (8*len > get_bits_left(&s->gb)) {
251 av_log(s->avctx, AV_LOG_ERROR, "dht: len %d is too large\n", len);
252 return AVERROR_INVALIDDATA;
253 }
254
255
2/2
✓ Branch 0 taken 9259 times.
✓ Branch 1 taken 2652 times.
11911 while (len > 0) {
256
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9259 times.
9259 if (len < 17)
257 return AVERROR_INVALIDDATA;
258 9259 class = get_bits(&s->gb, 4);
259
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9259 times.
9259 if (class >= 2)
260 return AVERROR_INVALIDDATA;
261 9259 index = get_bits(&s->gb, 4);
262
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9259 times.
9259 if (index >= 4)
263 return AVERROR_INVALIDDATA;
264 9259 n = 0;
265
2/2
✓ Branch 0 taken 148144 times.
✓ Branch 1 taken 9259 times.
157403 for (i = 1; i <= 16; i++) {
266 148144 bits_table[i] = get_bits(&s->gb, 8);
267 148144 n += bits_table[i];
268 }
269 9259 len -= 17;
270
2/4
✓ Branch 0 taken 9259 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9259 times.
9259 if (len < n || n > 256)
271 return AVERROR_INVALIDDATA;
272
273
2/2
✓ Branch 0 taken 453071 times.
✓ Branch 1 taken 9259 times.
462330 for (i = 0; i < n; i++) {
274 453071 v = get_bits(&s->gb, 8);
275 453071 val_table[i] = v;
276 }
277 9259 len -= n;
278
279 /* build VLC and flush previous vlc if present */
280 9259 ff_vlc_free(&s->vlcs[class][index]);
281 9259 av_log(s->avctx, AV_LOG_DEBUG, "class=%d index=%d nb_codes=%d\n",
282 class, index, n);
283
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9259 times.
9259 if ((ret = ff_mjpeg_build_vlc(&s->vlcs[class][index], bits_table,
284 9259 val_table, class > 0, s->avctx)) < 0)
285 return ret;
286
287
2/2
✓ Branch 0 taken 4649 times.
✓ Branch 1 taken 4610 times.
9259 if (class > 0) {
288 4649 ff_vlc_free(&s->vlcs[2][index]);
289
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4649 times.
4649 if ((ret = ff_mjpeg_build_vlc(&s->vlcs[2][index], bits_table,
290 4649 val_table, 0, s->avctx)) < 0)
291 return ret;
292 }
293
294
2/2
✓ Branch 0 taken 148144 times.
✓ Branch 1 taken 9259 times.
157403 for (i = 0; i < 16; i++)
295 148144 s->raw_huffman_lengths[class][index][i] = bits_table[i + 1];
296
2/2
✓ Branch 0 taken 2370304 times.
✓ Branch 1 taken 9259 times.
2379563 for (i = 0; i < 256; i++)
297 2370304 s->raw_huffman_values[class][index][i] = val_table[i];
298 }
299 2652 return 0;
300 }
301
302 2622 int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
303 {
304 int len, nb_components, i, width, height, bits, ret, size_change;
305 unsigned pix_fmt_id;
306 2622 int h_count[MAX_COMPONENTS] = { 0 };
307 2622 int v_count[MAX_COMPONENTS] = { 0 };
308
309 2622 s->cur_scan = 0;
310 2622 memset(s->upscale_h, 0, sizeof(s->upscale_h));
311 2622 memset(s->upscale_v, 0, sizeof(s->upscale_v));
312
313 2622 len = get_bits(&s->gb, 16);
314 2622 bits = get_bits(&s->gb, 8);
315
316
2/4
✓ Branch 0 taken 2622 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2622 times.
2622 if (bits > 16 || bits < 1) {
317 av_log(s->avctx, AV_LOG_ERROR, "bits %d is invalid\n", bits);
318 return AVERROR_INVALIDDATA;
319 }
320
321
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 2514 times.
2622 if (s->avctx->bits_per_raw_sample != bits) {
322
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 av_log(s->avctx, s->avctx->bits_per_raw_sample > 0 ? AV_LOG_INFO : AV_LOG_DEBUG, "Changing bps from %d to %d\n", s->avctx->bits_per_raw_sample, bits);
323 108 s->avctx->bits_per_raw_sample = bits;
324 108 init_idct(s->avctx);
325 }
326
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2622 times.
2622 if (s->pegasus_rct)
327 bits = 9;
328
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2622 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2622 if (bits == 9 && !s->pegasus_rct)
329 s->rct = 1; // FIXME ugly
330
331
3/4
✓ Branch 0 taken 426 times.
✓ Branch 1 taken 2196 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 426 times.
2622 if(s->lossless && s->avctx->lowres){
332 av_log(s->avctx, AV_LOG_ERROR, "lowres is not possible with lossless jpeg\n");
333 return -1;
334 }
335
336 2622 height = get_bits(&s->gb, 16);
337 2622 width = get_bits(&s->gb, 16);
338
339 // HACK for odd_height.mov
340
4/6
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 2596 times.
✓ Branch 2 taken 26 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 26 times.
2622 if (s->interlaced && s->width == width && s->height == height + 1)
341 height= s->height;
342
343 2622 av_log(s->avctx, AV_LOG_DEBUG, "sof0: picture: %dx%d\n", width, height);
344
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2622 times.
2622 if (av_image_check_size(width, height, 0, s->avctx) < 0)
345 return AVERROR_INVALIDDATA;
346
3/4
✓ Branch 0 taken 2620 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2620 times.
2622 if (s->buf_size && (width + 7) / 8 * ((height + 7) / 8) > s->buf_size * 4LL)
347 return AVERROR_INVALIDDATA;
348
349 2622 nb_components = get_bits(&s->gb, 8);
350
2/4
✓ Branch 0 taken 2622 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2622 times.
2622 if (nb_components <= 0 ||
351 nb_components > MAX_COMPONENTS)
352 return -1;
353
4/4
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 2596 times.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 11 times.
2622 if (s->interlaced && (s->bottom_field == !s->interlace_polarity)) {
354
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 if (nb_components != s->nb_components) {
355 av_log(s->avctx, AV_LOG_ERROR,
356 "nb_components changing in interlaced picture\n");
357 return AVERROR_INVALIDDATA;
358 }
359 }
360
3/6
✓ Branch 0 taken 221 times.
✓ Branch 1 taken 2401 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 221 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
2622 if (s->ls && !(bits <= 8 || nb_components == 1)) {
361 avpriv_report_missing_feature(s->avctx,
362 "JPEG-LS that is not <= 8 "
363 "bits/component or 16-bit gray");
364 return AVERROR_PATCHWELCOME;
365 }
366
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2622 times.
2622 if (len != 8 + 3 * nb_components) {
367 av_log(s->avctx, AV_LOG_ERROR, "decode_sof0: error, len(%d) mismatch %d components\n", len, nb_components);
368 return AVERROR_INVALIDDATA;
369 }
370
371 2622 s->nb_components = nb_components;
372 2622 s->h_max = 1;
373 2622 s->v_max = 1;
374
2/2
✓ Branch 0 taken 7830 times.
✓ Branch 1 taken 2622 times.
10452 for (i = 0; i < nb_components; i++) {
375 /* component id */
376 7830 s->component_id[i] = get_bits(&s->gb, 8);
377 7830 h_count[i] = get_bits(&s->gb, 4);
378 7830 v_count[i] = get_bits(&s->gb, 4);
379 /* compute hmax and vmax (only used in interleaved case) */
380
2/2
✓ Branch 0 taken 2179 times.
✓ Branch 1 taken 5651 times.
7830 if (h_count[i] > s->h_max)
381 2179 s->h_max = h_count[i];
382
2/2
✓ Branch 0 taken 2334 times.
✓ Branch 1 taken 5496 times.
7830 if (v_count[i] > s->v_max)
383 2334 s->v_max = v_count[i];
384 7830 s->quant_index[i] = get_bits(&s->gb, 8);
385
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7830 times.
7830 if (s->quant_index[i] >= 4) {
386 av_log(s->avctx, AV_LOG_ERROR, "quant_index is invalid\n");
387 return AVERROR_INVALIDDATA;
388 }
389
2/4
✓ Branch 0 taken 7830 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7830 times.
7830 if (!h_count[i] || !v_count[i]) {
390 av_log(s->avctx, AV_LOG_ERROR,
391 "Invalid sampling factor in component %d %d:%d\n",
392 i, h_count[i], v_count[i]);
393 return AVERROR_INVALIDDATA;
394 }
395
396 7830 av_log(s->avctx, AV_LOG_DEBUG, "component %d %d:%d id: %d quant:%d\n",
397 i, h_count[i], v_count[i],
398 s->component_id[i], s->quant_index[i]);
399 }
400
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2622 times.
2622 if ( nb_components == 4
401 && s->component_id[0] == 'C'
402 && s->component_id[1] == 'M'
403 && s->component_id[2] == 'Y'
404 && s->component_id[3] == 'K')
405 s->adobe_transform = 0;
406
407
4/6
✓ Branch 0 taken 221 times.
✓ Branch 1 taken 2401 times.
✓ Branch 2 taken 221 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 221 times.
2622 if (s->ls && (s->h_max > 1 || s->v_max > 1)) {
408 avpriv_report_missing_feature(s->avctx, "Subsampling in JPEG-LS");
409 return AVERROR_PATCHWELCOME;
410 }
411
412
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2622 times.
2622 if (s->bayer) {
413 if (nb_components == 2) {
414 /* Bayer images embedded in DNGs can contain 2 interleaved components and the
415 width stored in their SOF3 markers is the width of each one. We only output
416 a single component, therefore we need to adjust the output image width. We
417 handle the deinterleaving (but not the debayering) in this file. */
418 width *= 2;
419 }
420 /* They can also contain 1 component, which is double the width and half the height
421 of the final image (rows are interleaved). We don't handle the decoding in this
422 file, but leave that to the TIFF/DNG decoder. */
423 }
424
425 /* if different size, realloc/alloc picture */
426
5/6
✓ Branch 0 taken 2247 times.
✓ Branch 1 taken 375 times.
✓ Branch 2 taken 2241 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 2241 times.
✗ Branch 5 not taken.
2622 if (width != s->width || height != s->height || bits != s->bits ||
427
1/2
✓ Branch 0 taken 2241 times.
✗ Branch 1 not taken.
2241 memcmp(s->h_count, h_count, sizeof(h_count)) ||
428
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2241 times.
2241 memcmp(s->v_count, v_count, sizeof(v_count))) {
429 381 size_change = 1;
430
431 381 s->width = width;
432 381 s->height = height;
433 381 s->bits = bits;
434 381 memcpy(s->h_count, h_count, sizeof(h_count));
435 381 memcpy(s->v_count, v_count, sizeof(v_count));
436 381 s->interlaced = 0;
437 381 s->got_picture = 0;
438
439 /* test interlaced mode */
440
2/2
✓ Branch 0 taken 178 times.
✓ Branch 1 taken 203 times.
381 if (s->first_picture &&
441
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 178 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
178 (s->multiscope != 2 || s->avctx->pkt_timebase.den >= 25 * s->avctx->pkt_timebase.num) &&
442
2/2
✓ Branch 0 taken 131 times.
✓ Branch 1 taken 47 times.
178 s->orig_height != 0 &&
443
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 127 times.
131 s->height < ((s->orig_height * 3) / 4)) {
444 4 s->interlaced = 1;
445 4 s->bottom_field = s->interlace_polarity;
446 4 s->picture_ptr->flags |= AV_FRAME_FLAG_INTERLACED;
447
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 s->picture_ptr->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST * !s->interlace_polarity;
448 4 height *= 2;
449 }
450
451 381 ret = ff_set_dimensions(s->avctx, width, height);
452
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 381 times.
381 if (ret < 0)
453 return ret;
454
455
2/2
✓ Branch 0 taken 379 times.
✓ Branch 1 taken 2 times.
381 if (s->avctx->codec_id != AV_CODEC_ID_SMVJPEG &&
456
1/2
✓ Branch 0 taken 379 times.
✗ Branch 1 not taken.
379 (s->avctx->codec_tag == MKTAG('A', 'V', 'R', 'n') ||
457
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 377 times.
379 s->avctx->codec_tag == MKTAG('A', 'V', 'D', 'J')) &&
458
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 s->orig_height < height)
459 2 s->avctx->height = AV_CEIL_RSHIFT(s->orig_height, s->avctx->lowres);
460
461 381 s->first_picture = 0;
462 } else {
463 2241 size_change = 0;
464 }
465
466
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2619 times.
2622 if (s->avctx->codec_id == AV_CODEC_ID_SMVJPEG) {
467 3 s->avctx->height = s->avctx->coded_height / s->smv_frames_per_jpeg;
468
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (s->avctx->height <= 0)
469 return AVERROR_INVALIDDATA;
470 }
471
472
5/6
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 2599 times.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 15 times.
✗ Branch 5 not taken.
2622 if (s->got_picture && s->interlaced && (s->bottom_field == !s->interlace_polarity)) {
473
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 if (s->progressive) {
474 avpriv_request_sample(s->avctx, "progressively coded interlaced picture");
475 return AVERROR_INVALIDDATA;
476 }
477 } else {
478
9/10
✓ Branch 0 taken 273 times.
✓ Branch 1 taken 2334 times.
✓ Branch 2 taken 235 times.
✓ Branch 3 taken 38 times.
✓ Branch 4 taken 221 times.
✓ Branch 5 taken 14 times.
✓ Branch 6 taken 16 times.
✓ Branch 7 taken 205 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 16 times.
2607 if (s->v_max == 1 && s->h_max == 1 && s->lossless==1 && (nb_components==3 || nb_components==4))
479 205 s->rgb = 1;
480
2/2
✓ Branch 0 taken 2181 times.
✓ Branch 1 taken 221 times.
2402 else if (!s->lossless)
481 2181 s->rgb = 0;
482 /* XXX: not complete test ! */
483 2607 pix_fmt_id = ((unsigned)s->h_count[0] << 28) | (s->v_count[0] << 24) |
484 2607 (s->h_count[1] << 20) | (s->v_count[1] << 16) |
485 2607 (s->h_count[2] << 12) | (s->v_count[2] << 8) |
486 2607 (s->h_count[3] << 4) | s->v_count[3];
487 2607 av_log(s->avctx, AV_LOG_DEBUG, "pix fmt id %x\n", pix_fmt_id);
488 /* NOTE we do not allocate pictures large enough for the possible
489 * padding of h/v_count being 4 */
490
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2607 times.
2607 if (!(pix_fmt_id & 0xD0D0D0D0))
491 pix_fmt_id -= (pix_fmt_id & 0xF0F0F0F0) >> 1;
492
2/2
✓ Branch 0 taken 412 times.
✓ Branch 1 taken 2195 times.
2607 if (!(pix_fmt_id & 0x0D0D0D0D))
493 412 pix_fmt_id -= (pix_fmt_id & 0x0F0F0F0F) >> 1;
494
495
2/2
✓ Branch 0 taken 20856 times.
✓ Branch 1 taken 2607 times.
23463 for (i = 0; i < 8; i++) {
496 20856 int j = 6 + (i&1) - (i&6);
497 20856 int is = (pix_fmt_id >> (4*i)) & 0xF;
498 20856 int js = (pix_fmt_id >> (4*j)) & 0xF;
499
500
7/8
✓ Branch 0 taken 11474 times.
✓ Branch 1 taken 9382 times.
✓ Branch 2 taken 11466 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 11466 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1132 times.
✓ Branch 7 taken 10334 times.
20856 if (is == 1 && js != 2 && (i < 2 || i > 5))
501 1132 js = (pix_fmt_id >> ( 8 + 4*(i&1))) & 0xF;
502
7/8
✓ Branch 0 taken 11474 times.
✓ Branch 1 taken 9382 times.
✓ Branch 2 taken 11464 times.
✓ Branch 3 taken 10 times.
✓ Branch 4 taken 11464 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1130 times.
✓ Branch 7 taken 10334 times.
20856 if (is == 1 && js != 2 && (i < 2 || i > 5))
503 1130 js = (pix_fmt_id >> (16 + 4*(i&1))) & 0xF;
504
505
4/4
✓ Branch 0 taken 11474 times.
✓ Branch 1 taken 9382 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 11464 times.
20856 if (is == 1 && js == 2) {
506
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 2 times.
10 if (i & 1) s->upscale_h[j/2] = 1;
507 2 else s->upscale_v[j/2] = 1;
508 }
509 }
510
511
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2607 times.
2607 if (s->bayer) {
512 if (pix_fmt_id != 0x11110000 && pix_fmt_id != 0x11000000)
513 goto unk_pixfmt;
514 }
515
516
9/15
✗ Branch 0 not taken.
✓ Branch 1 taken 425 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 18 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 232 times.
✓ Branch 9 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 2 times.
✓ Branch 12 taken 1920 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
2607 switch (pix_fmt_id) {
517 case 0x11110000: /* for bayer-encoded huffman lossless JPEGs embedded in DNGs */
518 if (!s->bayer)
519 goto unk_pixfmt;
520 s->avctx->pix_fmt = AV_PIX_FMT_GRAY16LE;
521 break;
522 425 case 0x11111100:
523
2/2
✓ Branch 0 taken 205 times.
✓ Branch 1 taken 220 times.
425 if (s->rgb)
524
1/2
✓ Branch 0 taken 205 times.
✗ Branch 1 not taken.
205 s->avctx->pix_fmt = s->bits <= 9 ? AV_PIX_FMT_BGR24 : AV_PIX_FMT_BGR48;
525 else {
526
2/2
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 4 times.
220 if ( s->adobe_transform == 0
527
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 216 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
216 || s->component_id[0] == 'R' && s->component_id[1] == 'G' && s->component_id[2] == 'B') {
528
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 s->avctx->pix_fmt = s->bits <= 8 ? AV_PIX_FMT_GBRP : AV_PIX_FMT_GBRP16;
529 } else {
530
2/4
✓ Branch 0 taken 216 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 216 times.
216 if (s->bits <= 8) s->avctx->pix_fmt = s->cs_itu601 ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_YUVJ444P;
531 else s->avctx->pix_fmt = AV_PIX_FMT_YUV444P16;
532
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 216 times.
216 s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG;
533 }
534 }
535
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 425 times.
425 av_assert0(s->nb_components == 3);
536 425 break;
537 case 0x11111111:
538 if (s->rgb)
539 s->avctx->pix_fmt = s->bits <= 9 ? AV_PIX_FMT_ABGR : AV_PIX_FMT_RGBA64;
540 else {
541 if (s->adobe_transform == 0 && s->bits <= 8) {
542 s->avctx->pix_fmt = AV_PIX_FMT_GBRAP;
543 } else {
544 s->avctx->pix_fmt = s->bits <= 8 ? AV_PIX_FMT_YUVA444P : AV_PIX_FMT_YUVA444P16;
545 s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG;
546 }
547 }
548 av_assert0(s->nb_components == 4);
549 break;
550 2 case 0x11412100:
551
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (s->bits > 8)
552 goto unk_pixfmt;
553
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 if (s->component_id[0] == 'R' && s->component_id[1] == 'G' && s->component_id[2] == 'B') {
554 2 s->avctx->pix_fmt = AV_PIX_FMT_GBRP;
555 2 s->upscale_h[0] = 4;
556 2 s->upscale_h[1] = 0;
557 2 s->upscale_h[2] = 1;
558 } else {
559 goto unk_pixfmt;
560 }
561 2 break;
562 case 0x22111122:
563 case 0x22111111:
564 if (s->adobe_transform == 0 && s->bits <= 8) {
565 s->avctx->pix_fmt = AV_PIX_FMT_GBRAP;
566 s->upscale_v[1] = s->upscale_v[2] = 1;
567 s->upscale_h[1] = s->upscale_h[2] = 1;
568 } else if (s->adobe_transform == 2 && s->bits <= 8) {
569 s->avctx->pix_fmt = AV_PIX_FMT_YUVA444P;
570 s->upscale_v[1] = s->upscale_v[2] = 1;
571 s->upscale_h[1] = s->upscale_h[2] = 1;
572 s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG;
573 } else {
574 if (s->bits <= 8) s->avctx->pix_fmt = AV_PIX_FMT_YUVA420P;
575 else s->avctx->pix_fmt = AV_PIX_FMT_YUVA420P16;
576 s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG;
577 }
578 av_assert0(s->nb_components == 4);
579 break;
580 4 case 0x12121100:
581 case 0x22122100:
582 case 0x21211100:
583 case 0x21112100:
584 case 0x22211200:
585 case 0x22221100:
586 case 0x22112200:
587 case 0x11222200:
588
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (s->bits > 8)
589 goto unk_pixfmt;
590
3/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2 times.
4 if (s->adobe_transform == 0 || s->component_id[0] == 'R' &&
591
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 s->component_id[1] == 'G' && s->component_id[2] == 'B') {
592 2 s->avctx->pix_fmt = AV_PIX_FMT_GBRP;
593 } else {
594
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 s->avctx->pix_fmt = s->cs_itu601 ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_YUVJ444P;
595
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG;
596 }
597 4 break;
598 18 case 0x11000000:
599 case 0x13000000:
600 case 0x14000000:
601 case 0x31000000:
602 case 0x33000000:
603 case 0x34000000:
604 case 0x41000000:
605 case 0x43000000:
606 case 0x44000000:
607
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 2 times.
18 if(s->bits <= 8)
608
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
16 s->avctx->pix_fmt = s->force_pal8 ? AV_PIX_FMT_PAL8 : AV_PIX_FMT_GRAY8;
609 else
610 2 s->avctx->pix_fmt = AV_PIX_FMT_GRAY16;
611 18 break;
612 case 0x12111100:
613 case 0x14121200:
614 case 0x14111100:
615 case 0x22211100:
616 case 0x22112100:
617 if (s->component_id[0] == 'R' && s->component_id[1] == 'G' && s->component_id[2] == 'B') {
618 if (s->bits <= 8) s->avctx->pix_fmt = AV_PIX_FMT_GBRP;
619 else
620 goto unk_pixfmt;
621 s->upscale_v[1] = s->upscale_v[2] = 1;
622 } else {
623 if (pix_fmt_id == 0x14111100)
624 s->upscale_v[1] = s->upscale_v[2] = 1;
625 if (s->bits <= 8) s->avctx->pix_fmt = s->cs_itu601 ? AV_PIX_FMT_YUV440P : AV_PIX_FMT_YUVJ440P;
626 else
627 goto unk_pixfmt;
628 s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG;
629 }
630 break;
631 232 case 0x21111100:
632
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 232 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
232 if (s->component_id[0] == 'R' && s->component_id[1] == 'G' && s->component_id[2] == 'B') {
633 if (s->bits <= 8) s->avctx->pix_fmt = AV_PIX_FMT_GBRP;
634 else
635 goto unk_pixfmt;
636 s->upscale_h[1] = s->upscale_h[2] = 1;
637 } else {
638
2/4
✓ Branch 0 taken 232 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 232 times.
232 if (s->bits <= 8) s->avctx->pix_fmt = s->cs_itu601 ? AV_PIX_FMT_YUV422P : AV_PIX_FMT_YUVJ422P;
639 else s->avctx->pix_fmt = AV_PIX_FMT_YUV422P16;
640
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 232 times.
232 s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG;
641 }
642 232 break;
643 2 case 0x11311100:
644
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (s->bits > 8)
645 goto unk_pixfmt;
646
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 if (s->component_id[0] == 'R' && s->component_id[1] == 'G' && s->component_id[2] == 'B')
647 2 s->avctx->pix_fmt = AV_PIX_FMT_GBRP;
648 else
649 goto unk_pixfmt;
650 2 s->upscale_h[0] = s->upscale_h[2] = 2;
651 2 break;
652 2 case 0x31111100:
653
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (s->bits > 8)
654 goto unk_pixfmt;
655
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 s->avctx->pix_fmt = s->cs_itu601 ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_YUVJ444P;
656
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG;
657 2 s->upscale_h[1] = s->upscale_h[2] = 2;
658 2 break;
659 2 case 0x22121100:
660 case 0x22111200:
661 case 0x41211100:
662
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if (s->bits <= 8) s->avctx->pix_fmt = s->cs_itu601 ? AV_PIX_FMT_YUV422P : AV_PIX_FMT_YUVJ422P;
663 else
664 goto unk_pixfmt;
665
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG;
666 2 break;
667 1920 case 0x22111100:
668 case 0x23111100:
669 case 0x42111100:
670 case 0x24111100:
671
3/4
✓ Branch 0 taken 1920 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 205 times.
✓ Branch 3 taken 1715 times.
1920 if (s->bits <= 8) s->avctx->pix_fmt = s->cs_itu601 ? AV_PIX_FMT_YUV420P : AV_PIX_FMT_YUVJ420P;
672 else s->avctx->pix_fmt = AV_PIX_FMT_YUV420P16;
673
2/2
✓ Branch 0 taken 205 times.
✓ Branch 1 taken 1715 times.
1920 s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG;
674
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1920 times.
1920 if (pix_fmt_id == 0x42111100) {
675 if (s->bits > 8)
676 goto unk_pixfmt;
677 s->upscale_h[1] = s->upscale_h[2] = 1;
678
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1920 times.
1920 } else if (pix_fmt_id == 0x24111100) {
679 if (s->bits > 8)
680 goto unk_pixfmt;
681 s->upscale_v[1] = s->upscale_v[2] = 1;
682
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1920 times.
1920 } else if (pix_fmt_id == 0x23111100) {
683 if (s->bits > 8)
684 goto unk_pixfmt;
685 s->upscale_v[1] = s->upscale_v[2] = 2;
686 }
687 1920 break;
688 case 0x41111100:
689 if (s->bits <= 8) s->avctx->pix_fmt = s->cs_itu601 ? AV_PIX_FMT_YUV411P : AV_PIX_FMT_YUVJ411P;
690 else
691 goto unk_pixfmt;
692 s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG;
693 break;
694 default:
695 unk_pixfmt:
696 avpriv_report_missing_feature(s->avctx, "Pixel format 0x%x bits:%d", pix_fmt_id, s->bits);
697 memset(s->upscale_h, 0, sizeof(s->upscale_h));
698 memset(s->upscale_v, 0, sizeof(s->upscale_v));
699 return AVERROR_PATCHWELCOME;
700 }
701
4/6
✓ Branch 0 taken 2595 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2595 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 12 times.
2607 if ((AV_RB32(s->upscale_h) || AV_RB32(s->upscale_v)) && s->avctx->lowres) {
702 avpriv_report_missing_feature(s->avctx, "Lowres for weird subsampling");
703 return AVERROR_PATCHWELCOME;
704 }
705
2/2
✓ Branch 0 taken 221 times.
✓ Branch 1 taken 2386 times.
2607 if (s->ls) {
706 221 memset(s->upscale_h, 0, sizeof(s->upscale_h));
707 221 memset(s->upscale_v, 0, sizeof(s->upscale_v));
708
2/2
✓ Branch 0 taken 205 times.
✓ Branch 1 taken 16 times.
221 if (s->nb_components == 3) {
709 205 s->avctx->pix_fmt = AV_PIX_FMT_RGB24;
710
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 } else if (s->nb_components != 1) {
711 av_log(s->avctx, AV_LOG_ERROR, "Unsupported number of components %d\n", s->nb_components);
712 return AVERROR_PATCHWELCOME;
713
4/6
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
16 } else if ((s->palette_index || s->force_pal8) && s->bits <= 8)
714 8 s->avctx->pix_fmt = AV_PIX_FMT_PAL8;
715
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 else if (s->bits <= 8)
716 8 s->avctx->pix_fmt = AV_PIX_FMT_GRAY8;
717 else
718 s->avctx->pix_fmt = AV_PIX_FMT_GRAY16;
719 }
720
721 2607 s->pix_desc = av_pix_fmt_desc_get(s->avctx->pix_fmt);
722
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2607 times.
2607 if (!s->pix_desc) {
723 av_log(s->avctx, AV_LOG_ERROR, "Could not get a pixel format descriptor.\n");
724 return AVERROR_BUG;
725 }
726
727
4/4
✓ Branch 0 taken 2421 times.
✓ Branch 1 taken 186 times.
✓ Branch 2 taken 2218 times.
✓ Branch 3 taken 203 times.
2607 if (s->avctx->pix_fmt == s->hwaccel_sw_pix_fmt && !size_change) {
728 2218 s->avctx->pix_fmt = s->hwaccel_pix_fmt;
729 } else {
730 389 enum AVPixelFormat pix_fmts[] = {
731 #if CONFIG_MJPEG_NVDEC_HWACCEL
732 AV_PIX_FMT_CUDA,
733 #endif
734 #if CONFIG_MJPEG_VAAPI_HWACCEL
735 AV_PIX_FMT_VAAPI,
736 #endif
737 389 s->avctx->pix_fmt,
738 AV_PIX_FMT_NONE,
739 };
740 389 s->hwaccel_pix_fmt = ff_get_format(s->avctx, pix_fmts);
741
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 389 times.
389 if (s->hwaccel_pix_fmt < 0)
742 return AVERROR(EINVAL);
743
744 389 s->hwaccel_sw_pix_fmt = s->avctx->pix_fmt;
745 389 s->avctx->pix_fmt = s->hwaccel_pix_fmt;
746 }
747
748
2/2
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 2521 times.
2607 if (s->avctx->skip_frame == AVDISCARD_ALL) {
749 86 s->picture_ptr->pict_type = AV_PICTURE_TYPE_I;
750 86 s->picture_ptr->flags |= AV_FRAME_FLAG_KEY;
751 86 s->got_picture = 1;
752 86 return 0;
753 }
754
755 2521 av_frame_unref(s->picture_ptr);
756
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2521 times.
2521 if (ff_get_buffer(s->avctx, s->picture_ptr, AV_GET_BUFFER_FLAG_REF) < 0)
757 return -1;
758 2521 s->picture_ptr->pict_type = AV_PICTURE_TYPE_I;
759 2521 s->picture_ptr->flags |= AV_FRAME_FLAG_KEY;
760 2521 s->got_picture = 1;
761
762 // Lets clear the palette to avoid leaving uninitialized values in it
763
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 2513 times.
2521 if (s->avctx->pix_fmt == AV_PIX_FMT_PAL8)
764 8 memset(s->picture_ptr->data[1], 0, 1024);
765
766
2/2
✓ Branch 0 taken 10084 times.
✓ Branch 1 taken 2521 times.
12605 for (i = 0; i < 4; i++)
767 10084 s->linesize[i] = s->picture_ptr->linesize[i] << s->interlaced;
768
769 ff_dlog(s->avctx, "%d %d %d %d %d %d\n",
770 s->width, s->height, s->linesize[0], s->linesize[1],
771 s->interlaced, s->avctx->height);
772
773 }
774
775
3/6
✓ Branch 0 taken 205 times.
✓ Branch 1 taken 2331 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 205 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
2536 if ((s->rgb && !s->lossless && !s->ls) ||
776
5/6
✓ Branch 0 taken 2331 times.
✓ Branch 1 taken 205 times.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 2315 times.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
2536 (!s->rgb && s->ls && s->nb_components > 1) ||
777
3/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 2528 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
2536 (s->avctx->pix_fmt == AV_PIX_FMT_PAL8 && !s->ls)
778 ) {
779 av_log(s->avctx, AV_LOG_ERROR, "Unsupported coding and pixel format combination\n");
780 return AVERROR_PATCHWELCOME;
781 }
782
783 /* totally blank picture as progressive JPEG will only add details to it */
784
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 2529 times.
2536 if (s->progressive) {
785 7 int bw = (width + s->h_max * 8 - 1) / (s->h_max * 8);
786 7 int bh = (height + s->v_max * 8 - 1) / (s->v_max * 8);
787
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 7 times.
28 for (i = 0; i < s->nb_components; i++) {
788 21 int size = bw * bh * s->h_count[i] * s->v_count[i];
789 21 av_freep(&s->blocks[i]);
790 21 av_freep(&s->last_nnz[i]);
791 21 s->blocks[i] = av_calloc(size, sizeof(**s->blocks));
792 21 s->last_nnz[i] = av_calloc(size, sizeof(**s->last_nnz));
793
2/4
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
21 if (!s->blocks[i] || !s->last_nnz[i])
794 return AVERROR(ENOMEM);
795 21 s->block_stride[i] = bw * s->h_count[i];
796 }
797 7 memset(s->coefs_finished, 0, sizeof(s->coefs_finished));
798 }
799
800
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2536 times.
2536 if (s->avctx->hwaccel) {
801 const FFHWAccel *hwaccel = ffhwaccel(s->avctx->hwaccel);
802 s->hwaccel_picture_private =
803 av_mallocz(hwaccel->frame_priv_data_size);
804 if (!s->hwaccel_picture_private)
805 return AVERROR(ENOMEM);
806
807 ret = hwaccel->start_frame(s->avctx, s->raw_image_buffer,
808 s->raw_image_buffer_size);
809 if (ret < 0)
810 return ret;
811 }
812
813 2536 return 0;
814 }
815
816 26815832 static inline int mjpeg_decode_dc(MJpegDecodeContext *s, int dc_index)
817 {
818 int code;
819 26815832 code = get_vlc2(&s->gb, s->vlcs[0][dc_index].table, 9, 2);
820
2/4
✓ Branch 0 taken 26815832 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 26815832 times.
26815832 if (code < 0 || code > 16) {
821 av_log(s->avctx, AV_LOG_WARNING,
822 "mjpeg_decode_dc: bad vlc: %d:%d (%p)\n",
823 0, dc_index, &s->vlcs[0][dc_index]);
824 return 0xfffff;
825 }
826
827
2/2
✓ Branch 0 taken 23773974 times.
✓ Branch 1 taken 3041858 times.
26815832 if (code)
828 23773974 return get_xbits(&s->gb, code);
829 else
830 3041858 return 0;
831 }
832
833 /* decode block and dequantize */
834 3918656 static int decode_block(MJpegDecodeContext *s, int16_t *block, int component,
835 int dc_index, int ac_index, uint16_t *quant_matrix)
836 {
837 int code, i, j, level, val;
838
839 /* DC coef */
840 3918656 val = mjpeg_decode_dc(s, dc_index);
841
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3918656 times.
3918656 if (val == 0xfffff) {
842 av_log(s->avctx, AV_LOG_ERROR, "error dc\n");
843 return AVERROR_INVALIDDATA;
844 }
845 3918656 val = val * (unsigned)quant_matrix[0] + s->last_dc[component];
846 3918656 s->last_dc[component] = val;
847 3918656 block[0] = av_clip_int16(val);
848 /* AC coefs */
849 3918656 i = 0;
850 3918656 {OPEN_READER(re, &s->gb);
851 do {
852 36246588 UPDATE_CACHE(re, &s->gb);
853
2/2
✓ Branch 1 taken 364883 times.
✓ Branch 2 taken 35881705 times.
36246588 GET_VLC(code, re, &s->gb, s->vlcs[1][ac_index].table, 9, 2);
854
855 36246588 i += ((unsigned)code) >> 4;
856 36246588 code &= 0xf;
857
2/2
✓ Branch 0 taken 32378666 times.
✓ Branch 1 taken 3867922 times.
36246588 if (code) {
858
2/2
✓ Branch 0 taken 485 times.
✓ Branch 1 taken 32378181 times.
32378666 if (code > MIN_CACHE_BITS - 16)
859 485 UPDATE_CACHE(re, &s->gb);
860
861 {
862 32378666 int cache = GET_CACHE(re, &s->gb);
863 32378666 int sign = (~cache) >> 31;
864 32378666 level = (NEG_USR32(sign ^ cache,code) ^ sign) - sign;
865 }
866
867 32378666 LAST_SKIP_BITS(re, &s->gb, code);
868
869
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32378666 times.
32378666 if (i > 63) {
870 av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i);
871 return AVERROR_INVALIDDATA;
872 }
873 32378666 j = s->permutated_scantable[i];
874 32378666 block[j] = level * quant_matrix[i];
875 }
876
2/2
✓ Branch 0 taken 32327932 times.
✓ Branch 1 taken 3918656 times.
36246588 } while (i < 63);
877 3918656 CLOSE_READER(re, &s->gb);}
878
879 3918656 return 0;
880 }
881
882 876 static int decode_dc_progressive(MJpegDecodeContext *s, int16_t *block,
883 int component, int dc_index,
884 uint16_t *quant_matrix, int Al)
885 {
886 unsigned val;
887 876 s->bdsp.clear_block(block);
888 876 val = mjpeg_decode_dc(s, dc_index);
889
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 876 times.
876 if (val == 0xfffff) {
890 av_log(s->avctx, AV_LOG_ERROR, "error dc\n");
891 return AVERROR_INVALIDDATA;
892 }
893 876 val = (val * (quant_matrix[0] << Al)) + s->last_dc[component];
894 876 s->last_dc[component] = val;
895 876 block[0] = val;
896 876 return 0;
897 }
898
899 /* decode block and dequantize - progressive JPEG version */
900 1336 static int decode_block_progressive(MJpegDecodeContext *s, int16_t *block,
901 uint8_t *last_nnz, int ac_index,
902 uint16_t *quant_matrix,
903 int ss, int se, int Al, int *EOBRUN)
904 {
905 int code, i, j, val, run;
906 unsigned level;
907
908
2/2
✓ Branch 0 taken 340 times.
✓ Branch 1 taken 996 times.
1336 if (*EOBRUN) {
909 340 (*EOBRUN)--;
910 340 return 0;
911 }
912
913 {
914 996 OPEN_READER(re, &s->gb);
915 996 for (i = ss; ; i++) {
916 5910 UPDATE_CACHE(re, &s->gb);
917
2/2
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 6891 times.
6906 GET_VLC(code, re, &s->gb, s->vlcs[2][ac_index].table, 9, 2);
918
919 6906 run = ((unsigned) code) >> 4;
920 6906 code &= 0xF;
921
2/2
✓ Branch 0 taken 6037 times.
✓ Branch 1 taken 869 times.
6906 if (code) {
922 6037 i += run;
923
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6037 times.
6037 if (code > MIN_CACHE_BITS - 16)
924 UPDATE_CACHE(re, &s->gb);
925
926 {
927 6037 int cache = GET_CACHE(re, &s->gb);
928 6037 int sign = (~cache) >> 31;
929 6037 level = (NEG_USR32(sign ^ cache,code) ^ sign) - sign;
930 }
931
932 6037 LAST_SKIP_BITS(re, &s->gb, code);
933
934
2/2
✓ Branch 0 taken 139 times.
✓ Branch 1 taken 5898 times.
6037 if (i >= se) {
935
1/2
✓ Branch 0 taken 139 times.
✗ Branch 1 not taken.
139 if (i == se) {
936 139 j = s->permutated_scantable[se];
937 139 block[j] = level * (quant_matrix[se] << Al);
938 139 break;
939 }
940 av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i);
941 return AVERROR_INVALIDDATA;
942 }
943 5898 j = s->permutated_scantable[i];
944 5898 block[j] = level * (quant_matrix[i] << Al);
945 } else {
946
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 857 times.
869 if (run == 0xF) {// ZRL - skip 15 coefficients
947 12 i += 15;
948
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (i >= se) {
949 av_log(s->avctx, AV_LOG_ERROR, "ZRL overflow: %d\n", i);
950 return AVERROR_INVALIDDATA;
951 }
952 } else {
953 857 val = (1 << run);
954
2/2
✓ Branch 0 taken 149 times.
✓ Branch 1 taken 708 times.
857 if (run) {
955 149 UPDATE_CACHE(re, &s->gb);
956 149 val += NEG_USR32(GET_CACHE(re, &s->gb), run);
957 149 LAST_SKIP_BITS(re, &s->gb, run);
958 }
959 857 *EOBRUN = val - 1;
960 857 break;
961 }
962 }
963 }
964 996 CLOSE_READER(re, &s->gb);
965 }
966
967
1/2
✓ Branch 0 taken 996 times.
✗ Branch 1 not taken.
996 if (i > *last_nnz)
968 996 *last_nnz = i;
969
970 996 return 0;
971 }
972
973 #define REFINE_BIT(j) { \
974 UPDATE_CACHE(re, &s->gb); \
975 sign = block[j] >> 15; \
976 block[j] += SHOW_UBITS(re, &s->gb, 1) * \
977 ((quant_matrix[i] ^ sign) - sign) << Al; \
978 LAST_SKIP_BITS(re, &s->gb, 1); \
979 }
980
981 #define ZERO_RUN \
982 for (; ; i++) { \
983 if (i > last) { \
984 i += run; \
985 if (i > se) { \
986 av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i); \
987 return -1; \
988 } \
989 break; \
990 } \
991 j = s->permutated_scantable[i]; \
992 if (block[j]) \
993 REFINE_BIT(j) \
994 else if (run-- == 0) \
995 break; \
996 }
997
998 /* decode block and dequantize - progressive JPEG refinement pass */
999 1080 static int decode_block_refinement(MJpegDecodeContext *s, int16_t *block,
1000 uint8_t *last_nnz,
1001 int ac_index, uint16_t *quant_matrix,
1002 int ss, int se, int Al, int *EOBRUN)
1003 {
1004 1080 int code, i = ss, j, sign, val, run;
1005 1080 int last = FFMIN(se, *last_nnz);
1006
1007 1080 OPEN_READER(re, &s->gb);
1008
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 960 times.
1080 if (*EOBRUN) {
1009 120 (*EOBRUN)--;
1010 } else {
1011 9339 for (; ; i++) {
1012 9339 UPDATE_CACHE(re, &s->gb);
1013
2/2
✓ Branch 1 taken 13 times.
✓ Branch 2 taken 10286 times.
10299 GET_VLC(code, re, &s->gb, s->vlcs[2][ac_index].table, 9, 2);
1014
1015
2/2
✓ Branch 0 taken 9342 times.
✓ Branch 1 taken 957 times.
10299 if (code & 0xF) {
1016 9342 run = ((unsigned) code) >> 4;
1017 9342 UPDATE_CACHE(re, &s->gb);
1018 9342 val = SHOW_UBITS(re, &s->gb, 1);
1019 9342 LAST_SKIP_BITS(re, &s->gb, 1);
1020
7/8
✓ Branch 0 taken 3889 times.
✓ Branch 1 taken 21930 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3889 times.
✓ Branch 5 taken 9094 times.
✓ Branch 6 taken 12836 times.
✓ Branch 8 taken 5453 times.
✓ Branch 9 taken 7383 times.
25819 ZERO_RUN;
1021 9342 j = s->permutated_scantable[i];
1022 9342 val--;
1023 9342 block[j] = ((quant_matrix[i] << Al) ^ val) - val;
1024
2/2
✓ Branch 0 taken 63 times.
✓ Branch 1 taken 9279 times.
9342 if (i == se) {
1025
1/2
✓ Branch 0 taken 63 times.
✗ Branch 1 not taken.
63 if (i > *last_nnz)
1026 63 *last_nnz = i;
1027 63 CLOSE_READER(re, &s->gb);
1028 63 return 0;
1029 }
1030 } else {
1031 957 run = ((unsigned) code) >> 4;
1032
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 897 times.
957 if (run == 0xF) {
1033
7/8
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 621 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 42 times.
✓ Branch 5 taken 177 times.
✓ Branch 6 taken 444 times.
✓ Branch 8 taken 18 times.
✓ Branch 9 taken 426 times.
663 ZERO_RUN;
1034 } else {
1035 897 val = run;
1036 897 run = (1 << run);
1037
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 874 times.
897 if (val) {
1038 23 UPDATE_CACHE(re, &s->gb);
1039 23 run += SHOW_UBITS(re, &s->gb, val);
1040 23 LAST_SKIP_BITS(re, &s->gb, val);
1041 }
1042 897 *EOBRUN = run - 1;
1043 897 break;
1044 }
1045 }
1046 }
1047
1048
2/2
✓ Branch 0 taken 804 times.
✓ Branch 1 taken 93 times.
897 if (i > *last_nnz)
1049 804 *last_nnz = i;
1050 }
1051
1052
2/2
✓ Branch 0 taken 879 times.
✓ Branch 1 taken 1017 times.
1896 for (; i <= last; i++) {
1053 879 j = s->permutated_scantable[i];
1054
2/2
✓ Branch 0 taken 188 times.
✓ Branch 1 taken 691 times.
879 if (block[j])
1055 188 REFINE_BIT(j)
1056 }
1057 1017 CLOSE_READER(re, &s->gb);
1058
1059 1017 return 0;
1060 }
1061 #undef REFINE_BIT
1062 #undef ZERO_RUN
1063
1064 780868 static int handle_rstn(MJpegDecodeContext *s, int nb_components)
1065 {
1066 int i;
1067 780868 int reset = 0;
1068
1069
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 780868 times.
780868 if (s->restart_interval) {
1070 s->restart_count--;
1071 if(s->restart_count == 0 && s->avctx->codec_id == AV_CODEC_ID_THP){
1072 align_get_bits(&s->gb);
1073 for (i = 0; i < nb_components; i++) /* reset dc */
1074 s->last_dc[i] = (4 << s->bits);
1075 }
1076
1077 i = 8 + ((-get_bits_count(&s->gb)) & 7);
1078 /* skip RSTn */
1079 if (s->restart_count == 0) {
1080 if( show_bits(&s->gb, i) == (1 << i) - 1
1081 || show_bits(&s->gb, i) == 0xFF) {
1082 int pos = get_bits_count(&s->gb);
1083 align_get_bits(&s->gb);
1084 while (get_bits_left(&s->gb) >= 8 && show_bits(&s->gb, 8) == 0xFF)
1085 skip_bits(&s->gb, 8);
1086 if (get_bits_left(&s->gb) >= 8 && (get_bits(&s->gb, 8) & 0xF8) == 0xD0) {
1087 for (i = 0; i < nb_components; i++) /* reset dc */
1088 s->last_dc[i] = (4 << s->bits);
1089 reset = 1;
1090 } else
1091 skip_bits_long(&s->gb, pos - get_bits_count(&s->gb));
1092 }
1093 }
1094 }
1095 780868 return reset;
1096 }
1097
1098 /* Handles 1 to 4 components */
1099 static int ljpeg_decode_rgb_scan(MJpegDecodeContext *s, int nb_components, int predictor, int point_transform)
1100 {
1101 int i, mb_x, mb_y;
1102 unsigned width;
1103 uint16_t (*buffer)[4];
1104 int left[4], top[4], topleft[4];
1105 const int linesize = s->linesize[0];
1106 const int mask = ((1 << s->bits) - 1) << point_transform;
1107 int resync_mb_y = 0;
1108 int resync_mb_x = 0;
1109 int vpred[6];
1110
1111 if (!s->bayer && s->nb_components < 3)
1112 return AVERROR_INVALIDDATA;
1113 if (s->bayer && s->nb_components > 2)
1114 return AVERROR_INVALIDDATA;
1115 if (s->nb_components <= 0 || s->nb_components > 4)
1116 return AVERROR_INVALIDDATA;
1117 if (s->v_max != 1 || s->h_max != 1 || !s->lossless)
1118 return AVERROR_INVALIDDATA;
1119 if (s->bayer) {
1120 if (s->rct || s->pegasus_rct)
1121 return AVERROR_INVALIDDATA;
1122 }
1123
1124
1125 s->restart_count = s->restart_interval;
1126
1127 if (s->restart_interval == 0)
1128 s->restart_interval = INT_MAX;
1129
1130 if (s->bayer)
1131 width = s->mb_width / nb_components; /* Interleaved, width stored is the total so need to divide */
1132 else
1133 width = s->mb_width;
1134
1135 av_fast_malloc(&s->ljpeg_buffer, &s->ljpeg_buffer_size, width * 4 * sizeof(s->ljpeg_buffer[0][0]));
1136 if (!s->ljpeg_buffer)
1137 return AVERROR(ENOMEM);
1138
1139 buffer = s->ljpeg_buffer;
1140
1141 for (i = 0; i < 4; i++)
1142 buffer[0][i] = 1 << (s->bits - 1);
1143
1144 for (mb_y = 0; mb_y < s->mb_height; mb_y++) {
1145 uint8_t *ptr = s->picture_ptr->data[0] + (linesize * mb_y);
1146
1147 if (s->interlaced && s->bottom_field)
1148 ptr += linesize >> 1;
1149
1150 for (i = 0; i < 4; i++)
1151 top[i] = left[i] = topleft[i] = buffer[0][i];
1152
1153 if ((mb_y * s->width) % s->restart_interval == 0) {
1154 for (i = 0; i < 6; i++)
1155 vpred[i] = 1 << (s->bits-1);
1156 }
1157
1158 for (mb_x = 0; mb_x < width; mb_x++) {
1159 int modified_predictor = predictor;
1160
1161 if (get_bits_left(&s->gb) < 1) {
1162 av_log(s->avctx, AV_LOG_ERROR, "bitstream end in rgb_scan\n");
1163 return AVERROR_INVALIDDATA;
1164 }
1165
1166 if (s->restart_interval && !s->restart_count){
1167 s->restart_count = s->restart_interval;
1168 resync_mb_x = mb_x;
1169 resync_mb_y = mb_y;
1170 for(i=0; i<4; i++)
1171 top[i] = left[i]= topleft[i]= 1 << (s->bits - 1);
1172 }
1173 if (mb_y == resync_mb_y || mb_y == resync_mb_y+1 && mb_x < resync_mb_x || !mb_x)
1174 modified_predictor = 1;
1175
1176 for (i=0;i<nb_components;i++) {
1177 int pred, dc;
1178
1179 topleft[i] = top[i];
1180 top[i] = buffer[mb_x][i];
1181
1182 dc = mjpeg_decode_dc(s, s->dc_index[i]);
1183 if(dc == 0xFFFFF)
1184 return -1;
1185
1186 if (!s->bayer || mb_x) {
1187 pred = left[i];
1188 } else { /* This path runs only for the first line in bayer images */
1189 vpred[i] += dc;
1190 pred = vpred[i] - dc;
1191 }
1192
1193 PREDICT(pred, topleft[i], top[i], pred, modified_predictor);
1194
1195 left[i] = buffer[mb_x][i] =
1196 mask & (pred + (unsigned)(dc * (1 << point_transform)));
1197 }
1198
1199 if (s->restart_interval && !--s->restart_count) {
1200 align_get_bits(&s->gb);
1201 skip_bits(&s->gb, 16); /* skip RSTn */
1202 }
1203 }
1204 if (s->rct && s->nb_components == 4) {
1205 for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
1206 ptr[4*mb_x + 2] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2] - 0x200) >> 2);
1207 ptr[4*mb_x + 1] = buffer[mb_x][1] + ptr[4*mb_x + 2];
1208 ptr[4*mb_x + 3] = buffer[mb_x][2] + ptr[4*mb_x + 2];
1209 ptr[4*mb_x + 0] = buffer[mb_x][3];
1210 }
1211 } else if (s->nb_components == 4) {
1212 for(i=0; i<nb_components; i++) {
1213 int c= s->comp_index[i];
1214 if (s->bits <= 8) {
1215 for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
1216 ptr[4*mb_x+3-c] = buffer[mb_x][i];
1217 }
1218 } else if(s->bits == 9) {
1219 return AVERROR_PATCHWELCOME;
1220 } else {
1221 for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
1222 ((uint16_t*)ptr)[4*mb_x+c] = buffer[mb_x][i];
1223 }
1224 }
1225 }
1226 } else if (s->rct) {
1227 for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
1228 ptr[3*mb_x + 1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2] - 0x200) >> 2);
1229 ptr[3*mb_x + 0] = buffer[mb_x][1] + ptr[3*mb_x + 1];
1230 ptr[3*mb_x + 2] = buffer[mb_x][2] + ptr[3*mb_x + 1];
1231 }
1232 } else if (s->pegasus_rct) {
1233 for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
1234 ptr[3*mb_x + 1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2]) >> 2);
1235 ptr[3*mb_x + 0] = buffer[mb_x][1] + ptr[3*mb_x + 1];
1236 ptr[3*mb_x + 2] = buffer[mb_x][2] + ptr[3*mb_x + 1];
1237 }
1238 } else if (s->bayer) {
1239 if (s->bits <= 8)
1240 return AVERROR_PATCHWELCOME;
1241 if (nb_components == 1) {
1242 /* Leave decoding to the TIFF/DNG decoder (see comment in ff_mjpeg_decode_sof) */
1243 for (mb_x = 0; mb_x < width; mb_x++)
1244 ((uint16_t*)ptr)[mb_x] = buffer[mb_x][0];
1245 } else if (nb_components == 2) {
1246 for (mb_x = 0; mb_x < width; mb_x++) {
1247 ((uint16_t*)ptr)[2*mb_x + 0] = buffer[mb_x][0];
1248 ((uint16_t*)ptr)[2*mb_x + 1] = buffer[mb_x][1];
1249 }
1250 }
1251 } else {
1252 for(i=0; i<nb_components; i++) {
1253 int c= s->comp_index[i];
1254 if (s->bits <= 8) {
1255 for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
1256 ptr[3*mb_x+2-c] = buffer[mb_x][i];
1257 }
1258 } else if(s->bits == 9) {
1259 return AVERROR_PATCHWELCOME;
1260 } else {
1261 for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
1262 ((uint16_t*)ptr)[3*mb_x+2-c] = buffer[mb_x][i];
1263 }
1264 }
1265 }
1266 }
1267 }
1268 return 0;
1269 }
1270
1271 200 static int ljpeg_decode_yuv_scan(MJpegDecodeContext *s, int predictor,
1272 int point_transform, int nb_components)
1273 {
1274 int i, mb_x, mb_y, mask;
1275 200 int bits= (s->bits+7)&~7;
1276 200 int resync_mb_y = 0;
1277 200 int resync_mb_x = 0;
1278
1279 200 point_transform += bits - s->bits;
1280 200 mask = ((1 << s->bits) - 1) << point_transform;
1281
1282
2/4
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 200 times.
200 av_assert0(nb_components>=1 && nb_components<=4);
1283
1284
2/2
✓ Branch 0 taken 22450 times.
✓ Branch 1 taken 200 times.
22650 for (mb_y = 0; mb_y < s->mb_height; mb_y++) {
1285
2/2
✓ Branch 0 taken 3816050 times.
✓ Branch 1 taken 22450 times.
3838500 for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
1286
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3816050 times.
3816050 if (get_bits_left(&s->gb) < 1) {
1287 av_log(s->avctx, AV_LOG_ERROR, "bitstream end in yuv_scan\n");
1288 return AVERROR_INVALIDDATA;
1289 }
1290
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3816050 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3816050 if (s->restart_interval && !s->restart_count){
1291 s->restart_count = s->restart_interval;
1292 resync_mb_x = mb_x;
1293 resync_mb_y = mb_y;
1294 }
1295
1296
8/10
✓ Branch 0 taken 3793600 times.
✓ Branch 1 taken 22450 times.
✓ Branch 2 taken 3766550 times.
✓ Branch 3 taken 27050 times.
✓ Branch 4 taken 27050 times.
✓ Branch 5 taken 3739500 times.
✓ Branch 6 taken 27050 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 3766550 times.
3865550 if(!mb_x || mb_y == resync_mb_y || mb_y == resync_mb_y+1 && mb_x < resync_mb_x || s->interlaced){
1297
5/6
✓ Branch 0 taken 22250 times.
✓ Branch 1 taken 27250 times.
✓ Branch 2 taken 200 times.
✓ Branch 3 taken 22050 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 200 times.
49500 int toprow = mb_y == resync_mb_y || mb_y == resync_mb_y+1 && mb_x < resync_mb_x;
1298
4/6
✓ Branch 0 taken 27050 times.
✓ Branch 1 taken 22450 times.
✓ Branch 2 taken 27050 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 27050 times.
49500 int leftcol = !mb_x || mb_y == resync_mb_y && mb_x == resync_mb_x;
1299
2/2
✓ Branch 0 taken 148500 times.
✓ Branch 1 taken 49500 times.
198000 for (i = 0; i < nb_components; i++) {
1300 uint8_t *ptr;
1301 uint16_t *ptr16;
1302 int n, h, v, x, y, c, j, linesize;
1303 148500 n = s->nb_blocks[i];
1304 148500 c = s->comp_index[i];
1305 148500 h = s->h_scount[i];
1306 148500 v = s->v_scount[i];
1307 148500 x = 0;
1308 148500 y = 0;
1309 148500 linesize= s->linesize[c];
1310
1311
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 148500 times.
148500 if(bits>8) linesize /= 2;
1312
1313
2/2
✓ Branch 0 taken 297000 times.
✓ Branch 1 taken 148500 times.
445500 for(j=0; j<n; j++) {
1314 int pred, dc;
1315
1316 297000 dc = mjpeg_decode_dc(s, s->dc_index[i]);
1317
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 297000 times.
297000 if(dc == 0xFFFFF)
1318 return -1;
1319
1/2
✓ Branch 0 taken 297000 times.
✗ Branch 1 not taken.
297000 if ( h * mb_x + x >= s->width
1320
1/2
✓ Branch 0 taken 297000 times.
✗ Branch 1 not taken.
297000 || v * mb_y + y >= s->height) {
1321 // Nothing to do
1322
1/2
✓ Branch 0 taken 297000 times.
✗ Branch 1 not taken.
297000 } else if (bits<=8) {
1323 297000 ptr = s->picture_ptr->data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
1324
4/4
✓ Branch 0 taken 198000 times.
✓ Branch 1 taken 99000 times.
✓ Branch 2 taken 109000 times.
✓ Branch 3 taken 89000 times.
297000 if(y==0 && toprow){
1325
4/4
✓ Branch 0 taken 81750 times.
✓ Branch 1 taken 27250 times.
✓ Branch 2 taken 600 times.
✓ Branch 3 taken 81150 times.
109000 if(x==0 && leftcol){
1326 600 pred= 1 << (bits - 1);
1327 }else{
1328 108400 pred= ptr[-1];
1329 }
1330 }else{
1331
4/4
✓ Branch 0 taken 116250 times.
✓ Branch 1 taken 71750 times.
✓ Branch 2 taken 89200 times.
✓ Branch 3 taken 27050 times.
188000 if(x==0 && leftcol){
1332 89200 pred= ptr[-linesize];
1333 }else{
1334
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 98800 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
98800 PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);
1335 }
1336 }
1337
1338
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 297000 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
297000 if (s->interlaced && s->bottom_field)
1339 ptr += linesize >> 1;
1340 297000 pred &= mask;
1341 297000 *ptr= pred + ((unsigned)dc << point_transform);
1342 }else{
1343 ptr16 = (uint16_t*)(s->picture_ptr->data[c] + 2*(linesize * (v * mb_y + y)) + 2*(h * mb_x + x)); //FIXME optimize this crap
1344 if(y==0 && toprow){
1345 if(x==0 && leftcol){
1346 pred= 1 << (bits - 1);
1347 }else{
1348 pred= ptr16[-1];
1349 }
1350 }else{
1351 if(x==0 && leftcol){
1352 pred= ptr16[-linesize];
1353 }else{
1354 PREDICT(pred, ptr16[-linesize-1], ptr16[-linesize], ptr16[-1], predictor);
1355 }
1356 }
1357
1358 if (s->interlaced && s->bottom_field)
1359 ptr16 += linesize >> 1;
1360 pred &= mask;
1361 *ptr16= pred + ((unsigned)dc << point_transform);
1362 }
1363
2/2
✓ Branch 0 taken 198000 times.
✓ Branch 1 taken 99000 times.
297000 if (++x == h) {
1364 198000 x = 0;
1365 198000 y++;
1366 }
1367 }
1368 }
1369 } else {
1370
2/2
✓ Branch 0 taken 11299650 times.
✓ Branch 1 taken 3766550 times.
15066200 for (i = 0; i < nb_components; i++) {
1371 uint8_t *ptr;
1372 uint16_t *ptr16;
1373 int n, h, v, x, y, c, j, linesize, dc;
1374 11299650 n = s->nb_blocks[i];
1375 11299650 c = s->comp_index[i];
1376 11299650 h = s->h_scount[i];
1377 11299650 v = s->v_scount[i];
1378 11299650 x = 0;
1379 11299650 y = 0;
1380 11299650 linesize = s->linesize[c];
1381
1382
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11299650 times.
11299650 if(bits>8) linesize /= 2;
1383
1384
2/2
✓ Branch 0 taken 22599300 times.
✓ Branch 1 taken 11299650 times.
33898950 for (j = 0; j < n; j++) {
1385 int pred;
1386
1387 22599300 dc = mjpeg_decode_dc(s, s->dc_index[i]);
1388
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22599300 times.
22599300 if(dc == 0xFFFFF)
1389 return -1;
1390
1/2
✓ Branch 0 taken 22599300 times.
✗ Branch 1 not taken.
22599300 if ( h * mb_x + x >= s->width
1391
1/2
✓ Branch 0 taken 22599300 times.
✗ Branch 1 not taken.
22599300 || v * mb_y + y >= s->height) {
1392 // Nothing to do
1393
1/2
✓ Branch 0 taken 22599300 times.
✗ Branch 1 not taken.
22599300 } else if (bits<=8) {
1394 22599300 ptr = s->picture_ptr->data[c] +
1395 22599300 (linesize * (v * mb_y + y)) +
1396 22599300 (h * mb_x + x); //FIXME optimize this crap
1397
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 22599300 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
22599300 PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);
1398
1399 22599300 pred &= mask;
1400 22599300 *ptr = pred + ((unsigned)dc << point_transform);
1401 }else{
1402 ptr16 = (uint16_t*)(s->picture_ptr->data[c] + 2*(linesize * (v * mb_y + y)) + 2*(h * mb_x + x)); //FIXME optimize this crap
1403 PREDICT(pred, ptr16[-linesize-1], ptr16[-linesize], ptr16[-1], predictor);
1404
1405 pred &= mask;
1406 *ptr16= pred + ((unsigned)dc << point_transform);
1407 }
1408
1409
2/2
✓ Branch 0 taken 15066200 times.
✓ Branch 1 taken 7533100 times.
22599300 if (++x == h) {
1410 15066200 x = 0;
1411 15066200 y++;
1412 }
1413 }
1414 }
1415 }
1416
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3816050 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3816050 if (s->restart_interval && !--s->restart_count) {
1417 align_get_bits(&s->gb);
1418 skip_bits(&s->gb, 16); /* skip RSTn */
1419 }
1420 }
1421 }
1422 200 return 0;
1423 }
1424
1425 786684 static av_always_inline void mjpeg_copy_block(MJpegDecodeContext *s,
1426 uint8_t *dst, const uint8_t *src,
1427 int linesize, int lowres)
1428 {
1429
1/5
✓ Branch 0 taken 786684 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
786684 switch (lowres) {
1430 786684 case 0: s->hdsp.put_pixels_tab[1][0](dst, src, linesize, 8);
1431 786684 break;
1432 case 1: copy_block4(dst, src, linesize, linesize, 4);
1433 break;
1434 case 2: copy_block2(dst, src, linesize, linesize, 2);
1435 break;
1436 case 3: *dst = *src;
1437 break;
1438 }
1439 786684 }
1440
1441 11750 static void shift_output(MJpegDecodeContext *s, uint8_t *ptr, int linesize)
1442 {
1443 int block_x, block_y;
1444 11750 int size = 8 >> s->avctx->lowres;
1445
1/2
✓ Branch 0 taken 11750 times.
✗ Branch 1 not taken.
11750 if (s->bits > 8) {
1446
2/2
✓ Branch 0 taken 94000 times.
✓ Branch 1 taken 11750 times.
105750 for (block_y=0; block_y<size; block_y++)
1447
2/2
✓ Branch 0 taken 752000 times.
✓ Branch 1 taken 94000 times.
846000 for (block_x=0; block_x<size; block_x++)
1448 752000 *(uint16_t*)(ptr + 2*block_x + block_y*linesize) <<= 16 - s->bits;
1449 } else {
1450 for (block_y=0; block_y<size; block_y++)
1451 for (block_x=0; block_x<size; block_x++)
1452 *(ptr + block_x + block_y*linesize) <<= 8 - s->bits;
1453 }
1454 11750 }
1455
1456 2145 static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int Ah,
1457 int Al, const uint8_t *mb_bitmask,
1458 int mb_bitmask_size,
1459 const AVFrame *reference)
1460 {
1461 int i, mb_x, mb_y, chroma_h_shift, chroma_v_shift, chroma_width, chroma_height;
1462 uint8_t *data[MAX_COMPONENTS];
1463 const uint8_t *reference_data[MAX_COMPONENTS];
1464 int linesize[MAX_COMPONENTS];
1465 2145 GetBitContext mb_bitmask_gb = {0}; // initialize to silence gcc warning
1466
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2144 times.
2145 int bytes_per_pixel = 1 + (s->bits > 8);
1467
1468
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 2114 times.
2145 if (mb_bitmask) {
1469
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
31 if (mb_bitmask_size != (s->mb_width * s->mb_height + 7)>>3) {
1470 av_log(s->avctx, AV_LOG_ERROR, "mb_bitmask_size mismatches\n");
1471 return AVERROR_INVALIDDATA;
1472 }
1473 31 init_get_bits(&mb_bitmask_gb, mb_bitmask, s->mb_width * s->mb_height);
1474 }
1475
1476 2145 s->restart_count = 0;
1477
1478 2145 av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt, &chroma_h_shift,
1479 &chroma_v_shift);
1480 2145 chroma_width = AV_CEIL_RSHIFT(s->width, chroma_h_shift);
1481 2145 chroma_height = AV_CEIL_RSHIFT(s->height, chroma_v_shift);
1482
1483
2/2
✓ Branch 0 taken 6427 times.
✓ Branch 1 taken 2145 times.
8572 for (i = 0; i < nb_components; i++) {
1484 6427 int c = s->comp_index[i];
1485 6427 data[c] = s->picture_ptr->data[c];
1486
2/2
✓ Branch 0 taken 93 times.
✓ Branch 1 taken 6334 times.
6427 reference_data[c] = reference ? reference->data[c] : NULL;
1487 6427 linesize[c] = s->linesize[c];
1488 6427 s->coefs_finished[c] |= 1;
1489 }
1490
1491
2/2
✓ Branch 0 taken 28477 times.
✓ Branch 1 taken 2145 times.
30622 for (mb_y = 0; mb_y < s->mb_height; mb_y++) {
1492
2/2
✓ Branch 0 taken 778452 times.
✓ Branch 1 taken 28477 times.
806929 for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
1493
4/4
✓ Branch 0 taken 148800 times.
✓ Branch 1 taken 629652 times.
✓ Branch 3 taken 131114 times.
✓ Branch 4 taken 17686 times.
778452 const int copy_mb = mb_bitmask && !get_bits1(&mb_bitmask_gb);
1494
1495
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 778452 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
778452 if (s->restart_interval && !s->restart_count)
1496 s->restart_count = s->restart_interval;
1497
1498
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 778452 times.
778452 if (get_bits_left(&s->gb) < 0) {
1499 av_log(s->avctx, AV_LOG_ERROR, "overread %d\n",
1500 -get_bits_left(&s->gb));
1501 return AVERROR_INVALIDDATA;
1502 }
1503
2/2
✓ Branch 0 taken 2311640 times.
✓ Branch 1 taken 778452 times.
3090092 for (i = 0; i < nb_components; i++) {
1504 uint8_t *ptr;
1505 int n, h, v, x, y, c, j;
1506 int block_offset;
1507 2311640 n = s->nb_blocks[i];
1508 2311640 c = s->comp_index[i];
1509 2311640 h = s->h_scount[i];
1510 2311640 v = s->v_scount[i];
1511 2311640 x = 0;
1512 2311640 y = 0;
1513
2/2
✓ Branch 0 taken 4706216 times.
✓ Branch 1 taken 2311640 times.
7017856 for (j = 0; j < n; j++) {
1514 4706216 block_offset = (((linesize[c] * (v * mb_y + y) * 8) +
1515 4706216 (h * mb_x + x) * 8 * bytes_per_pixel) >> s->avctx->lowres);
1516
1517
4/4
✓ Branch 0 taken 21440 times.
✓ Branch 1 taken 4684776 times.
✓ Branch 2 taken 10720 times.
✓ Branch 3 taken 10720 times.
4706216 if (s->interlaced && s->bottom_field)
1518 10720 block_offset += linesize[c] >> 1;
1519
6/6
✓ Branch 0 taken 3759806 times.
✓ Branch 1 taken 946410 times.
✓ Branch 2 taken 2813496 times.
✓ Branch 3 taken 946310 times.
✓ Branch 4 taken 4704016 times.
✓ Branch 5 taken 2200 times.
4706216 if ( 8*(h * mb_x + x) < ((c == 1) || (c == 2) ? chroma_width : s->width)
1520
6/6
✓ Branch 0 taken 3757614 times.
✓ Branch 1 taken 946402 times.
✓ Branch 2 taken 2811304 times.
✓ Branch 3 taken 946310 times.
✓ Branch 4 taken 4697867 times.
✓ Branch 5 taken 6149 times.
4704016 && 8*(v * mb_y + y) < ((c == 1) || (c == 2) ? chroma_height : s->height)) {
1521 4697867 ptr = data[c] + block_offset;
1522 } else
1523 8349 ptr = NULL;
1524
2/2
✓ Branch 0 taken 4705340 times.
✓ Branch 1 taken 876 times.
4706216 if (!s->progressive) {
1525
2/2
✓ Branch 0 taken 786684 times.
✓ Branch 1 taken 3918656 times.
4705340 if (copy_mb) {
1526
1/2
✓ Branch 0 taken 786684 times.
✗ Branch 1 not taken.
786684 if (ptr)
1527 786684 mjpeg_copy_block(s, ptr, reference_data[c] + block_offset,
1528 786684 linesize[c], s->avctx->lowres);
1529
1530 } else {
1531 3918656 s->bdsp.clear_block(s->block);
1532
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3918656 times.
3918656 if (decode_block(s, s->block, i,
1533 s->dc_index[i], s->ac_index[i],
1534 3918656 s->quant_matrixes[s->quant_sindex[i]]) < 0) {
1535 av_log(s->avctx, AV_LOG_ERROR,
1536 "error y=%d x=%d\n", mb_y, mb_x);
1537 return AVERROR_INVALIDDATA;
1538 }
1539
3/4
✓ Branch 0 taken 3910323 times.
✓ Branch 1 taken 8333 times.
✓ Branch 2 taken 3910323 times.
✗ Branch 3 not taken.
3918656 if (ptr && linesize[c]) {
1540 3910323 s->idsp.idct_put(ptr, linesize[c], s->block);
1541
2/2
✓ Branch 0 taken 11750 times.
✓ Branch 1 taken 3898573 times.
3910323 if (s->bits & 7)
1542 11750 shift_output(s, ptr, linesize[c]);
1543 }
1544 }
1545 } else {
1546 876 int block_idx = s->block_stride[c] * (v * mb_y + y) +
1547 876 (h * mb_x + x);
1548 876 int16_t *block = s->blocks[c][block_idx];
1549
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 876 times.
876 if (Ah)
1550 block[0] += get_bits1(&s->gb) *
1551 s->quant_matrixes[s->quant_sindex[i]][0] << Al;
1552
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 876 times.
876 else if (decode_dc_progressive(s, block, i, s->dc_index[i],
1553 876 s->quant_matrixes[s->quant_sindex[i]],
1554 Al) < 0) {
1555 av_log(s->avctx, AV_LOG_ERROR,
1556 "error y=%d x=%d\n", mb_y, mb_x);
1557 return AVERROR_INVALIDDATA;
1558 }
1559 }
1560 ff_dlog(s->avctx, "mb: %d %d processed\n", mb_y, mb_x);
1561 ff_dlog(s->avctx, "%d %d %d %d %d %d %d %d \n",
1562 mb_x, mb_y, x, y, c, s->bottom_field,
1563 (v * mb_y + y) * 8, (h * mb_x + x) * 8);
1564
2/2
✓ Branch 0 taken 3425053 times.
✓ Branch 1 taken 1281163 times.
4706216 if (++x == h) {
1565 3425053 x = 0;
1566 3425053 y++;
1567 }
1568 }
1569 }
1570
1571 778452 handle_rstn(s, nb_components);
1572 }
1573 }
1574 2145 return 0;
1575 }
1576
1577 59 static int mjpeg_decode_scan_progressive_ac(MJpegDecodeContext *s, int ss,
1578 int se, int Ah, int Al)
1579 {
1580 int mb_x, mb_y;
1581 59 int EOBRUN = 0;
1582 59 int c = s->comp_index[0];
1583 59 uint16_t *quant_matrix = s->quant_matrixes[s->quant_sindex[0]];
1584
1585
3/6
✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 59 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 59 times.
59 av_assert0(ss>=0 && Ah>=0 && Al>=0);
1586
2/4
✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 59 times.
59 if (se < ss || se > 63) {
1587 av_log(s->avctx, AV_LOG_ERROR, "SS/SE %d/%d is invalid\n", ss, se);
1588 return AVERROR_INVALIDDATA;
1589 }
1590
1591 // s->coefs_finished is a bitmask for coefficients coded
1592 // ss and se are parameters telling start and end coefficients
1593 59 s->coefs_finished[c] |= (2ULL << se) - (1ULL << ss);
1594
1595 59 s->restart_count = 0;
1596
1597
2/2
✓ Branch 0 taken 412 times.
✓ Branch 1 taken 59 times.
471 for (mb_y = 0; mb_y < s->mb_height; mb_y++) {
1598 412 int block_idx = mb_y * s->block_stride[c];
1599 412 int16_t (*block)[64] = &s->blocks[c][block_idx];
1600 412 uint8_t *last_nnz = &s->last_nnz[c][block_idx];
1601
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 412 times.
412 if (get_bits_left(&s->gb) <= 0) {
1602 av_log(s->avctx, AV_LOG_ERROR, "bitstream truncated in mjpeg_decode_scan_progressive_ac\n");
1603 return AVERROR_INVALIDDATA;
1604 }
1605
2/2
✓ Branch 0 taken 2416 times.
✓ Branch 1 taken 412 times.
2828 for (mb_x = 0; mb_x < s->mb_width; mb_x++, block++, last_nnz++) {
1606 int ret;
1607
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2416 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2416 if (s->restart_interval && !s->restart_count)
1608 s->restart_count = s->restart_interval;
1609
1610
2/2
✓ Branch 0 taken 1080 times.
✓ Branch 1 taken 1336 times.
2416 if (Ah)
1611 1080 ret = decode_block_refinement(s, *block, last_nnz, s->ac_index[0],
1612 quant_matrix, ss, se, Al, &EOBRUN);
1613 else
1614 1336 ret = decode_block_progressive(s, *block, last_nnz, s->ac_index[0],
1615 quant_matrix, ss, se, Al, &EOBRUN);
1616
1617
2/4
✓ Branch 0 taken 2416 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 2416 times.
2416 if (ret >= 0 && get_bits_left(&s->gb) < 0)
1618 ret = AVERROR_INVALIDDATA;
1619
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2416 times.
2416 if (ret < 0) {
1620 av_log(s->avctx, AV_LOG_ERROR,
1621 "error y=%d x=%d\n", mb_y, mb_x);
1622 return AVERROR_INVALIDDATA;
1623 }
1624
1625
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2416 times.
2416 if (handle_rstn(s, 0))
1626 EOBRUN = 0;
1627 }
1628 }
1629 59 return 0;
1630 }
1631
1632 7 static void mjpeg_idct_scan_progressive_ac(MJpegDecodeContext *s)
1633 {
1634 int mb_x, mb_y;
1635 int c;
1636
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 const int bytes_per_pixel = 1 + (s->bits > 8);
1637
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 const int block_size = s->lossless ? 1 : 8;
1638
1639
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 7 times.
28 for (c = 0; c < s->nb_components; c++) {
1640 21 uint8_t *data = s->picture_ptr->data[c];
1641 21 int linesize = s->linesize[c];
1642 21 int h = s->h_max / s->h_count[c];
1643 21 int v = s->v_max / s->v_count[c];
1644 21 int mb_width = (s->width + h * block_size - 1) / (h * block_size);
1645 21 int mb_height = (s->height + v * block_size - 1) / (v * block_size);
1646
1647
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 if (~s->coefs_finished[c])
1648 av_log(s->avctx, AV_LOG_WARNING, "component %d is incomplete\n", c);
1649
1650
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
21 if (s->interlaced && s->bottom_field)
1651 data += linesize >> 1;
1652
1653
2/2
✓ Branch 0 taken 153 times.
✓ Branch 1 taken 21 times.
174 for (mb_y = 0; mb_y < mb_height; mb_y++) {
1654 153 uint8_t *ptr = data + (mb_y * linesize * 8 >> s->avctx->lowres);
1655 153 int block_idx = mb_y * s->block_stride[c];
1656 153 int16_t (*block)[64] = &s->blocks[c][block_idx];
1657
2/2
✓ Branch 0 taken 860 times.
✓ Branch 1 taken 153 times.
1013 for (mb_x = 0; mb_x < mb_width; mb_x++, block++) {
1658 860 s->idsp.idct_put(ptr, linesize, *block);
1659
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 860 times.
860 if (s->bits & 7)
1660 shift_output(s, ptr, linesize);
1661 860 ptr += bytes_per_pixel*8 >> s->avctx->lowres;
1662 }
1663 }
1664 }
1665 7 }
1666
1667 2617 int ff_mjpeg_decode_sos(MJpegDecodeContext *s, const uint8_t *mb_bitmask,
1668 int mb_bitmask_size, const AVFrame *reference)
1669 {
1670 int len, nb_components, i, h, v, predictor, point_transform;
1671 int index, id, ret;
1672
2/2
✓ Branch 0 taken 413 times.
✓ Branch 1 taken 2204 times.
2617 const int block_size = s->lossless ? 1 : 8;
1673 int ilv, prev_shift;
1674
1675
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2617 times.
2617 if (!s->got_picture) {
1676 av_log(s->avctx, AV_LOG_WARNING,
1677 "Can not process SOS before SOF, skipping\n");
1678 return -1;
1679 }
1680
1681
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 2586 times.
2617 if (reference) {
1682
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 if (reference->width != s->picture_ptr->width ||
1683
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 reference->height != s->picture_ptr->height ||
1684
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
31 reference->format != s->picture_ptr->format) {
1685 av_log(s->avctx, AV_LOG_ERROR, "Reference mismatching\n");
1686 return AVERROR_INVALIDDATA;
1687 }
1688 }
1689
1690 /* XXX: verify len field validity */
1691 2617 len = get_bits(&s->gb, 16);
1692 2617 nb_components = get_bits(&s->gb, 8);
1693
2/4
✓ Branch 0 taken 2617 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2617 times.
2617 if (nb_components == 0 || nb_components > MAX_COMPONENTS) {
1694 avpriv_report_missing_feature(s->avctx,
1695 "decode_sos: nb_components (%d)",
1696 nb_components);
1697 return AVERROR_PATCHWELCOME;
1698 }
1699
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2617 times.
2617 if (len != 6 + 2 * nb_components) {
1700 av_log(s->avctx, AV_LOG_ERROR, "decode_sos: invalid len (%d)\n", len);
1701 return AVERROR_INVALIDDATA;
1702 }
1703
2/2
✓ Branch 0 taken 7709 times.
✓ Branch 1 taken 2617 times.
10326 for (i = 0; i < nb_components; i++) {
1704 7709 id = get_bits(&s->gb, 8);
1705 7709 av_log(s->avctx, AV_LOG_DEBUG, "component: %d\n", id);
1706 /* find component index */
1707
1/2
✓ Branch 0 taken 15407 times.
✗ Branch 1 not taken.
15407 for (index = 0; index < s->nb_components; index++)
1708
2/2
✓ Branch 0 taken 7709 times.
✓ Branch 1 taken 7698 times.
15407 if (id == s->component_id[index])
1709 7709 break;
1710
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7709 times.
7709 if (index == s->nb_components) {
1711 av_log(s->avctx, AV_LOG_ERROR,
1712 "decode_sos: index(%d) out of components\n", index);
1713 return AVERROR_INVALIDDATA;
1714 }
1715 /* Metasoft MJPEG codec has Cb and Cr swapped */
1716
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7709 times.
7709 if (s->avctx->codec_tag == MKTAG('M', 'T', 'S', 'J')
1717 && nb_components == 3 && s->nb_components == 3 && i)
1718 index = 3 - i;
1719
1720 7709 s->quant_sindex[i] = s->quant_index[index];
1721 7709 s->nb_blocks[i] = s->h_count[index] * s->v_count[index];
1722 7709 s->h_scount[i] = s->h_count[index];
1723 7709 s->v_scount[i] = s->v_count[index];
1724
1725 7709 s->comp_index[i] = index;
1726
1727 7709 s->dc_index[i] = get_bits(&s->gb, 4);
1728 7709 s->ac_index[i] = get_bits(&s->gb, 4);
1729
1730
2/4
✓ Branch 0 taken 7709 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7709 times.
✗ Branch 3 not taken.
7709 if (s->dc_index[i] < 0 || s->ac_index[i] < 0 ||
1731
2/4
✓ Branch 0 taken 7709 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7709 times.
7709 s->dc_index[i] >= 4 || s->ac_index[i] >= 4)
1732 goto out_of_range;
1733
5/8
✓ Branch 0 taken 7709 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80 times.
✓ Branch 3 taken 7629 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 80 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 7629 times.
7709 if (!s->vlcs[0][s->dc_index[i]].table || !(s->progressive ? s->vlcs[2][s->ac_index[0]].table : s->vlcs[1][s->ac_index[i]].table))
1734 goto out_of_range;
1735 }
1736
1737 2617 predictor = get_bits(&s->gb, 8); /* JPEG Ss / lossless JPEG predictor /JPEG-LS NEAR */
1738 2617 ilv = get_bits(&s->gb, 8); /* JPEG Se / JPEG-LS ILV */
1739
1/2
✓ Branch 0 taken 2617 times.
✗ Branch 1 not taken.
2617 if(s->avctx->codec_tag != AV_RL32("CJPG")){
1740 2617 prev_shift = get_bits(&s->gb, 4); /* Ah */
1741 2617 point_transform = get_bits(&s->gb, 4); /* Al */
1742 }else
1743 prev_shift = point_transform = 0;
1744
1745
2/2
✓ Branch 0 taken 2546 times.
✓ Branch 1 taken 71 times.
2617 if (nb_components > 1) {
1746 /* interleaved stream */
1747 2546 s->mb_width = (s->width + s->h_max * block_size - 1) / (s->h_max * block_size);
1748 2546 s->mb_height = (s->height + s->v_max * block_size - 1) / (s->v_max * block_size);
1749
2/2
✓ Branch 0 taken 63 times.
✓ Branch 1 taken 8 times.
71 } else if (!s->ls) { /* skip this for JPEG-LS */
1750 63 h = s->h_max / s->h_scount[0];
1751 63 v = s->v_max / s->v_scount[0];
1752 63 s->mb_width = (s->width + h * block_size - 1) / (h * block_size);
1753 63 s->mb_height = (s->height + v * block_size - 1) / (v * block_size);
1754 63 s->nb_blocks[0] = 1;
1755 63 s->h_scount[0] = 1;
1756 63 s->v_scount[0] = 1;
1757 }
1758
1759
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2617 times.
2617 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
1760 av_log(s->avctx, AV_LOG_DEBUG, "%s %s p:%d >>:%d ilv:%d bits:%d skip:%d %s comp:%d\n",
1761 s->lossless ? "lossless" : "sequential DCT", s->rgb ? "RGB" : "",
1762 predictor, point_transform, ilv, s->bits, s->mjpb_skiptosod,
1763 s->pegasus_rct ? "PRCT" : (s->rct ? "RCT" : ""), nb_components);
1764
1765
1766 /* mjpeg-b can have padding bytes between sos and image data, skip them */
1767
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2617 times.
2639 for (i = s->mjpb_skiptosod; i > 0; i--)
1768 22 skip_bits(&s->gb, 8);
1769
1770 2617 next_field:
1771
2/2
✓ Branch 0 taken 7709 times.
✓ Branch 1 taken 2617 times.
10326 for (i = 0; i < nb_components; i++)
1772 7709 s->last_dc[i] = (4 << s->bits);
1773
1774
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2617 times.
2617 if (s->avctx->hwaccel) {
1775 int bytes_to_start = get_bits_count(&s->gb) / 8;
1776 av_assert0(bytes_to_start >= 0 &&
1777 s->raw_scan_buffer_size >= bytes_to_start);
1778
1779 ret = FF_HW_CALL(s->avctx, decode_slice,
1780 s->raw_scan_buffer + bytes_to_start,
1781 s->raw_scan_buffer_size - bytes_to_start);
1782 if (ret < 0)
1783 return ret;
1784
1785
2/2
✓ Branch 0 taken 413 times.
✓ Branch 1 taken 2204 times.
2617 } else if (s->lossless) {
1786
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 413 times.
413 av_assert0(s->picture_ptr == s->picture);
1787
2/2
✓ Branch 0 taken 213 times.
✓ Branch 1 taken 200 times.
413 if (CONFIG_JPEGLS_DECODER && s->ls) {
1788 // for () {
1789 // reset_ls_coding_parameters(s, 0);
1790
1791
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 213 times.
213 if ((ret = ff_jpegls_decode_picture(s, predictor,
1792 point_transform, ilv)) < 0)
1793 return ret;
1794 } else {
1795
2/4
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 200 times.
200 if (s->rgb || s->bayer) {
1796 if ((ret = ljpeg_decode_rgb_scan(s, nb_components, predictor, point_transform)) < 0)
1797 return ret;
1798 } else {
1799
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 200 times.
200 if ((ret = ljpeg_decode_yuv_scan(s, predictor,
1800 point_transform,
1801 nb_components)) < 0)
1802 return ret;
1803 }
1804 }
1805 } else {
1806
4/4
✓ Branch 0 taken 68 times.
✓ Branch 1 taken 2136 times.
✓ Branch 2 taken 59 times.
✓ Branch 3 taken 9 times.
2204 if (s->progressive && predictor) {
1807
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
59 av_assert0(s->picture_ptr == s->picture);
1808
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 59 times.
59 if ((ret = mjpeg_decode_scan_progressive_ac(s, predictor,
1809 ilv, prev_shift,
1810 point_transform)) < 0)
1811 return ret;
1812 } else {
1813
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2145 times.
2145 if ((ret = mjpeg_decode_scan(s, nb_components,
1814 prev_shift, point_transform,
1815 mb_bitmask, mb_bitmask_size, reference)) < 0)
1816 return ret;
1817 }
1818 }
1819
1820
4/4
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 2589 times.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 13 times.
2645 if (s->interlaced &&
1821
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 15 times.
43 get_bits_left(&s->gb) > 32 &&
1822 15 show_bits(&s->gb, 8) == 0xFF) {
1823 GetBitContext bak = s->gb;
1824 align_get_bits(&bak);
1825 if (show_bits(&bak, 16) == 0xFFD1) {
1826 av_log(s->avctx, AV_LOG_DEBUG, "AVRn interlaced picture marker found\n");
1827 s->gb = bak;
1828 skip_bits(&s->gb, 16);
1829 s->bottom_field ^= 1;
1830
1831 goto next_field;
1832 }
1833 }
1834
1835 2617 emms_c();
1836 2617 return 0;
1837 out_of_range:
1838 av_log(s->avctx, AV_LOG_ERROR, "decode_sos: ac/dc index out of range\n");
1839 return AVERROR_INVALIDDATA;
1840 }
1841
1842 16 static int mjpeg_decode_dri(MJpegDecodeContext *s)
1843 {
1844
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
16 if (get_bits(&s->gb, 16) != 4)
1845 return AVERROR_INVALIDDATA;
1846 16 s->restart_interval = get_bits(&s->gb, 16);
1847 16 s->restart_count = 0;
1848 16 av_log(s->avctx, AV_LOG_DEBUG, "restart interval: %d\n",
1849 s->restart_interval);
1850
1851 16 return 0;
1852 }
1853
1854 223 static int mjpeg_decode_app(MJpegDecodeContext *s)
1855 {
1856 int len, id, i;
1857
1858 223 len = get_bits(&s->gb, 16);
1859
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 223 times.
223 if (len < 6) {
1860 if (s->bayer) {
1861 // Pentax K-1 (digital camera) JPEG images embedded in DNG images contain unknown APP0 markers
1862 av_log(s->avctx, AV_LOG_WARNING, "skipping APPx (len=%"PRId32") for bayer-encoded image\n", len);
1863 skip_bits(&s->gb, len);
1864 return 0;
1865 } else
1866 return AVERROR_INVALIDDATA;
1867 }
1868
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 223 times.
223 if (8 * len > get_bits_left(&s->gb))
1869 return AVERROR_INVALIDDATA;
1870
1871 223 id = get_bits_long(&s->gb, 32);
1872 223 len -= 6;
1873
1874
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 223 times.
223 if (s->avctx->debug & FF_DEBUG_STARTCODE)
1875 av_log(s->avctx, AV_LOG_DEBUG, "APPx (%s / %8X) len=%d\n",
1876 av_fourcc2str(av_bswap32(id)), id, len);
1877
1878 /* Buggy AVID, it puts EOI only at every 10th frame. */
1879 /* Also, this fourcc is used by non-avid files too, it holds some
1880 information, but it's always present in AVID-created files. */
1881
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 204 times.
223 if (id == AV_RB32("AVI1")) {
1882 /* structure:
1883 4bytes AVI1
1884 1bytes polarity
1885 1bytes always zero
1886 4bytes field_size
1887 4bytes field_size_less_padding
1888 */
1889 19 s->buggy_avid = 1;
1890 19 i = get_bits(&s->gb, 8); len--;
1891 19 av_log(s->avctx, AV_LOG_DEBUG, "polarity %d\n", i);
1892 19 goto out;
1893 }
1894
1895
2/2
✓ Branch 0 taken 149 times.
✓ Branch 1 taken 55 times.
204 if (id == AV_RB32("JFIF")) {
1896 int t_w, t_h, v1, v2;
1897
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 149 times.
149 if (len < 8)
1898 goto out;
1899 149 skip_bits(&s->gb, 8); /* the trailing zero-byte */
1900 149 v1 = get_bits(&s->gb, 8);
1901 149 v2 = get_bits(&s->gb, 8);
1902 149 skip_bits(&s->gb, 8);
1903
1904 149 s->avctx->sample_aspect_ratio.num = get_bits(&s->gb, 16);
1905 149 s->avctx->sample_aspect_ratio.den = get_bits(&s->gb, 16);
1906
1/2
✓ Branch 0 taken 149 times.
✗ Branch 1 not taken.
149 if ( s->avctx->sample_aspect_ratio.num <= 0
1907
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 149 times.
149 || s->avctx->sample_aspect_ratio.den <= 0) {
1908 s->avctx->sample_aspect_ratio.num = 0;
1909 s->avctx->sample_aspect_ratio.den = 1;
1910 }
1911
1912
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 149 times.
149 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
1913 av_log(s->avctx, AV_LOG_INFO,
1914 "mjpeg: JFIF header found (version: %x.%x) SAR=%d/%d\n",
1915 v1, v2,
1916 s->avctx->sample_aspect_ratio.num,
1917 s->avctx->sample_aspect_ratio.den);
1918
1919 149 len -= 8;
1920
2/2
✓ Branch 0 taken 147 times.
✓ Branch 1 taken 2 times.
149 if (len >= 2) {
1921 147 t_w = get_bits(&s->gb, 8);
1922 147 t_h = get_bits(&s->gb, 8);
1923
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 147 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
147 if (t_w && t_h) {
1924 /* skip thumbnail */
1925 if (len -10 - (t_w * t_h * 3) > 0)
1926 len -= t_w * t_h * 3;
1927 }
1928 147 len -= 2;
1929 }
1930 149 goto out;
1931 }
1932
1933
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 42 times.
55 if ( id == AV_RB32("Adob")
1934
1/2
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
13 && len >= 7
1935
1/2
✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
13 && show_bits(&s->gb, 8) == 'e'
1936
1/2
✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
13 && show_bits_long(&s->gb, 32) != AV_RB32("e_CM")) {
1937 13 skip_bits(&s->gb, 8); /* 'e' */
1938 13 skip_bits(&s->gb, 16); /* version */
1939 13 skip_bits(&s->gb, 16); /* flags0 */
1940 13 skip_bits(&s->gb, 16); /* flags1 */
1941 13 s->adobe_transform = get_bits(&s->gb, 8);
1942
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
13 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
1943 av_log(s->avctx, AV_LOG_INFO, "mjpeg: Adobe header found, transform=%d\n", s->adobe_transform);
1944 13 len -= 7;
1945 13 goto out;
1946 }
1947
1948
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
42 if (id == AV_RB32("LJIF")) {
1949 int rgb = s->rgb;
1950 int pegasus_rct = s->pegasus_rct;
1951 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
1952 av_log(s->avctx, AV_LOG_INFO,
1953 "Pegasus lossless jpeg header found\n");
1954 skip_bits(&s->gb, 16); /* version ? */
1955 skip_bits(&s->gb, 16); /* unknown always 0? */
1956 skip_bits(&s->gb, 16); /* unknown always 0? */
1957 skip_bits(&s->gb, 16); /* unknown always 0? */
1958 switch (i=get_bits(&s->gb, 8)) {
1959 case 1:
1960 rgb = 1;
1961 pegasus_rct = 0;
1962 break;
1963 case 2:
1964 rgb = 1;
1965 pegasus_rct = 1;
1966 break;
1967 default:
1968 av_log(s->avctx, AV_LOG_ERROR, "unknown colorspace %d\n", i);
1969 }
1970
1971 len -= 9;
1972 if (s->bayer)
1973 goto out;
1974 if (s->got_picture)
1975 if (rgb != s->rgb || pegasus_rct != s->pegasus_rct) {
1976 av_log(s->avctx, AV_LOG_WARNING, "Mismatching LJIF tag\n");
1977 goto out;
1978 }
1979
1980 s->rgb = rgb;
1981 s->pegasus_rct = pegasus_rct;
1982
1983 goto out;
1984 }
1985
3/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 34 times.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
42 if (id == AV_RL32("colr") && len > 0) {
1986 8 s->colr = get_bits(&s->gb, 8);
1987
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
1988 av_log(s->avctx, AV_LOG_INFO, "COLR %d\n", s->colr);
1989 8 len --;
1990 8 goto out;
1991 }
1992
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 34 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
34 if (id == AV_RL32("xfrm") && len > 0) {
1993 s->xfrm = get_bits(&s->gb, 8);
1994 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
1995 av_log(s->avctx, AV_LOG_INFO, "XFRM %d\n", s->xfrm);
1996 len --;
1997 goto out;
1998 }
1999
2000 /* JPS extension by VRex */
2001
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 34 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
34 if (s->start_code == APP3 && id == AV_RB32("_JPS") && len >= 10) {
2002 int flags, layout, type;
2003 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
2004 av_log(s->avctx, AV_LOG_INFO, "_JPSJPS_\n");
2005
2006 skip_bits(&s->gb, 32); len -= 4; /* JPS_ */
2007 skip_bits(&s->gb, 16); len -= 2; /* block length */
2008 skip_bits(&s->gb, 8); /* reserved */
2009 flags = get_bits(&s->gb, 8);
2010 layout = get_bits(&s->gb, 8);
2011 type = get_bits(&s->gb, 8);
2012 len -= 4;
2013
2014 av_freep(&s->stereo3d);
2015 s->stereo3d = av_stereo3d_alloc();
2016 if (!s->stereo3d) {
2017 goto out;
2018 }
2019 if (type == 0) {
2020 s->stereo3d->type = AV_STEREO3D_2D;
2021 } else if (type == 1) {
2022 switch (layout) {
2023 case 0x01:
2024 s->stereo3d->type = AV_STEREO3D_LINES;
2025 break;
2026 case 0x02:
2027 s->stereo3d->type = AV_STEREO3D_SIDEBYSIDE;
2028 break;
2029 case 0x03:
2030 s->stereo3d->type = AV_STEREO3D_TOPBOTTOM;
2031 break;
2032 }
2033 if (!(flags & 0x04)) {
2034 s->stereo3d->flags = AV_STEREO3D_FLAG_INVERT;
2035 }
2036 }
2037 goto out;
2038 }
2039
2040 /* EXIF metadata */
2041
5/6
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
34 if (s->start_code == APP1 && id == AV_RB32("Exif") && len >= 2) {
2042 GetByteContext gbytes;
2043 int ret, le, ifd_offset, bytes_read;
2044 const uint8_t *aligned;
2045
2046 18 skip_bits(&s->gb, 16); // skip padding
2047 18 len -= 2;
2048
2049 // init byte wise reading
2050 18 aligned = align_get_bits(&s->gb);
2051 18 bytestream2_init(&gbytes, aligned, len);
2052
2053 // read TIFF header
2054 18 ret = ff_tdecode_header(&gbytes, &le, &ifd_offset);
2055
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (ret) {
2056 av_log(s->avctx, AV_LOG_ERROR, "mjpeg: invalid TIFF header in EXIF data\n");
2057 } else {
2058 18 bytestream2_seek(&gbytes, ifd_offset, SEEK_SET);
2059
2060 // read 0th IFD and store the metadata
2061 // (return values > 0 indicate the presence of subimage metadata)
2062 18 ret = ff_exif_decode_ifd(s->avctx, &gbytes, le, 0, &s->exif_metadata);
2063
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (ret < 0) {
2064 av_log(s->avctx, AV_LOG_ERROR, "mjpeg: error decoding EXIF data\n");
2065 }
2066 }
2067
2068 18 bytes_read = bytestream2_tell(&gbytes);
2069 18 skip_bits(&s->gb, bytes_read << 3);
2070 18 len -= bytes_read;
2071
2072 18 goto out;
2073 }
2074
2075 /* Apple MJPEG-A */
2076
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
16 if ((s->start_code == APP1) && (len > (0x28 - 8))) {
2077 2 id = get_bits_long(&s->gb, 32);
2078 2 len -= 4;
2079 /* Apple MJPEG-A */
2080
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (id == AV_RB32("mjpg")) {
2081 /* structure:
2082 4bytes field size
2083 4bytes pad field size
2084 4bytes next off
2085 4bytes quant off
2086 4bytes huff off
2087 4bytes image off
2088 4bytes scan off
2089 4bytes data off
2090 */
2091 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
2092 av_log(s->avctx, AV_LOG_INFO, "mjpeg: Apple MJPEG-A header found\n");
2093 }
2094 }
2095
2096
4/6
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 10 times.
16 if (s->start_code == APP2 && id == AV_RB32("ICC_") && len >= 10) {
2097 int id2;
2098 unsigned seqno;
2099 unsigned nummarkers;
2100
2101 10 id = get_bits_long(&s->gb, 32);
2102 10 id2 = get_bits(&s->gb, 24);
2103 10 len -= 7;
2104
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
10 if (id != AV_RB32("PROF") || id2 != AV_RB24("ILE")) {
2105 av_log(s->avctx, AV_LOG_WARNING, "Invalid ICC_PROFILE header in APP2\n");
2106 goto out;
2107 }
2108
2109 10 skip_bits(&s->gb, 8);
2110 10 seqno = get_bits(&s->gb, 8);
2111 10 len -= 2;
2112
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (seqno == 0) {
2113 av_log(s->avctx, AV_LOG_WARNING, "Invalid sequence number in APP2\n");
2114 goto out;
2115 }
2116
2117 10 nummarkers = get_bits(&s->gb, 8);
2118 10 len -= 1;
2119
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (nummarkers == 0) {
2120 av_log(s->avctx, AV_LOG_WARNING, "Invalid number of markers coded in APP2\n");
2121 goto out;
2122
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
10 } else if (s->iccnum != 0 && nummarkers != s->iccnum) {
2123 av_log(s->avctx, AV_LOG_WARNING, "Mistmatch in coded number of ICC markers between markers\n");
2124 goto out;
2125
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 } else if (seqno > nummarkers) {
2126 av_log(s->avctx, AV_LOG_WARNING, "Mismatching sequence number and coded number of ICC markers\n");
2127 goto out;
2128 }
2129
2130 /* Allocate if this is the first APP2 we've seen. */
2131
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if (s->iccnum == 0) {
2132
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
10 if (!FF_ALLOCZ_TYPED_ARRAY(s->iccentries, nummarkers)) {
2133 av_log(s->avctx, AV_LOG_ERROR, "Could not allocate ICC data arrays\n");
2134 return AVERROR(ENOMEM);
2135 }
2136 10 s->iccnum = nummarkers;
2137 }
2138
2139
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (s->iccentries[seqno - 1].data) {
2140 av_log(s->avctx, AV_LOG_WARNING, "Duplicate ICC sequence number\n");
2141 goto out;
2142 }
2143
2144 10 s->iccentries[seqno - 1].length = len;
2145 10 s->iccentries[seqno - 1].data = av_malloc(len);
2146
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (!s->iccentries[seqno - 1].data) {
2147 av_log(s->avctx, AV_LOG_ERROR, "Could not allocate ICC data buffer\n");
2148 return AVERROR(ENOMEM);
2149 }
2150
2151 10 memcpy(s->iccentries[seqno - 1].data, align_get_bits(&s->gb), len);
2152 10 skip_bits(&s->gb, len << 3);
2153 10 len = 0;
2154 10 s->iccread++;
2155
2156
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if (s->iccread > s->iccnum)
2157 av_log(s->avctx, AV_LOG_WARNING, "Read more ICC markers than are supposed to be coded\n");
2158 }
2159
2160 16 out:
2161 /* slow but needed for extreme adobe jpegs */
2162
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 223 times.
223 if (len < 0)
2163 av_log(s->avctx, AV_LOG_ERROR,
2164 "mjpeg: error, decode_app parser read over the end\n");
2165
2/2
✓ Branch 0 taken 107450 times.
✓ Branch 1 taken 223 times.
107673 while (--len > 0)
2166 107450 skip_bits(&s->gb, 8);
2167
2168 223 return 0;
2169 }
2170
2171 234 static int mjpeg_decode_com(MJpegDecodeContext *s)
2172 {
2173 234 int len = get_bits(&s->gb, 16);
2174
2/4
✓ Branch 0 taken 234 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 234 times.
✗ Branch 4 not taken.
234 if (len >= 2 && 8 * len - 16 <= get_bits_left(&s->gb)) {
2175 int i;
2176 234 char *cbuf = av_malloc(len - 1);
2177
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 234 times.
234 if (!cbuf)
2178 return AVERROR(ENOMEM);
2179
2180
2/2
✓ Branch 0 taken 3571 times.
✓ Branch 1 taken 234 times.
3805 for (i = 0; i < len - 2; i++)
2181 3571 cbuf[i] = get_bits(&s->gb, 8);
2182
3/4
✓ Branch 0 taken 234 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 224 times.
234 if (i > 0 && cbuf[i - 1] == '\n')
2183 10 cbuf[i - 1] = 0;
2184 else
2185 224 cbuf[i] = 0;
2186
2187
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 234 times.
234 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
2188 av_log(s->avctx, AV_LOG_INFO, "comment: '%s'\n", cbuf);
2189
2190 /* buggy avid, it puts EOI only at every 10th frame */
2191
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 223 times.
234 if (!strncmp(cbuf, "AVID", 4)) {
2192 11 parse_avid(s, cbuf, len);
2193
2/2
✓ Branch 0 taken 205 times.
✓ Branch 1 taken 18 times.
223 } else if (!strcmp(cbuf, "CS=ITU601"))
2194 205 s->cs_itu601 = 1;
2195
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18 else if ((!strncmp(cbuf, "Intel(R) JPEG Library, version 1", 32) && s->avctx->codec_tag) ||
2196
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 (!strncmp(cbuf, "Metasoft MJPEG Codec", 20)))
2197 s->flipped = 1;
2198
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 else if (!strcmp(cbuf, "MULTISCOPE II")) {
2199 s->avctx->sample_aspect_ratio = (AVRational) { 1, 2 };
2200 s->multiscope = 2;
2201 }
2202
2203 234 av_free(cbuf);
2204 }
2205
2206 234 return 0;
2207 }
2208
2209 /* return the 8 bit start code value and update the search
2210 state. Return -1 if no start code found */
2211 16601 static int find_marker(const uint8_t **pbuf_ptr, const uint8_t *buf_end)
2212 {
2213 const uint8_t *buf_ptr;
2214 unsigned int v, v2;
2215 int val;
2216 16601 int skipped = 0;
2217
2218 16601 buf_ptr = *pbuf_ptr;
2219
2/2
✓ Branch 0 taken 284940 times.
✓ Branch 1 taken 12 times.
284952 while (buf_end - buf_ptr > 1) {
2220 284940 v = *buf_ptr++;
2221 284940 v2 = *buf_ptr;
2222
7/8
✓ Branch 0 taken 19108 times.
✓ Branch 1 taken 265832 times.
✓ Branch 2 taken 16610 times.
✓ Branch 3 taken 2498 times.
✓ Branch 4 taken 16589 times.
✓ Branch 5 taken 21 times.
✓ Branch 6 taken 16589 times.
✗ Branch 7 not taken.
284940 if ((v == 0xff) && (v2 >= SOF0) && (v2 <= COM) && buf_ptr < buf_end) {
2223 16589 val = *buf_ptr++;
2224 16589 goto found;
2225 }
2226 268351 skipped++;
2227 }
2228 12 buf_ptr = buf_end;
2229 12 val = -1;
2230 16601 found:
2231 ff_dlog(NULL, "find_marker skipped %d bytes\n", skipped);
2232 16601 *pbuf_ptr = buf_ptr;
2233 16601 return val;
2234 }
2235
2236 16601 int ff_mjpeg_find_marker(MJpegDecodeContext *s,
2237 const uint8_t **buf_ptr, const uint8_t *buf_end,
2238 const uint8_t **unescaped_buf_ptr,
2239 int *unescaped_buf_size)
2240 {
2241 int start_code;
2242 16601 start_code = find_marker(buf_ptr, buf_end);
2243
2244 16601 av_fast_padded_malloc(&s->buffer, &s->buffer_size, buf_end - *buf_ptr);
2245
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16601 times.
16601 if (!s->buffer)
2246 return AVERROR(ENOMEM);
2247
2248 /* unescape buffer of SOS, use special treatment for JPEG-LS */
2249
4/4
✓ Branch 0 taken 2736 times.
✓ Branch 1 taken 13865 times.
✓ Branch 2 taken 2523 times.
✓ Branch 3 taken 213 times.
19124 if (start_code == SOS && !s->ls) {
2250 2523 const uint8_t *src = *buf_ptr;
2251 2523 const uint8_t *ptr = src;
2252 2523 uint8_t *dst = s->buffer;
2253
2254 #define copy_data_segment(skip) do { \
2255 ptrdiff_t length = (ptr - src) - (skip); \
2256 if (length > 0) { \
2257 memcpy(dst, src, length); \
2258 dst += length; \
2259 src = ptr; \
2260 } \
2261 } while (0)
2262
2263
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 2449 times.
2523 if (s->avctx->codec_id == AV_CODEC_ID_THP) {
2264 74 ptr = buf_end;
2265
1/2
✓ Branch 0 taken 74 times.
✗ Branch 1 not taken.
74 copy_data_segment(0);
2266 } else {
2267
1/2
✓ Branch 0 taken 43286497 times.
✗ Branch 1 not taken.
43288946 while (ptr < buf_end) {
2268 43286497 uint8_t x = *(ptr++);
2269
2270
2/2
✓ Branch 0 taken 43100576 times.
✓ Branch 1 taken 185921 times.
43286497 if (x == 0xff) {
2271 185921 ptrdiff_t skip = 0;
2272
4/4
✓ Branch 0 taken 369532 times.
✓ Branch 1 taken 2324 times.
✓ Branch 2 taken 185935 times.
✓ Branch 3 taken 183597 times.
371856 while (ptr < buf_end && x == 0xff) {
2273 185935 x = *(ptr++);
2274 185935 skip++;
2275 }
2276
2277 /* 0xFF, 0xFF, ... */
2278
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 185914 times.
185921 if (skip > 1) {
2279
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 copy_data_segment(skip);
2280
2281 /* decrement src as it is equal to ptr after the
2282 * copy_data_segment macro and we might want to
2283 * copy the current value of x later on */
2284 7 src--;
2285 }
2286
2287
4/4
✓ Branch 0 taken 2431 times.
✓ Branch 1 taken 183490 times.
✓ Branch 2 taken 2355 times.
✓ Branch 3 taken 76 times.
185921 if (x < RST0 || x > RST7) {
2288
2/2
✓ Branch 0 taken 185838 times.
✓ Branch 1 taken 7 times.
185845 copy_data_segment(1);
2289
2/2
✓ Branch 0 taken 2449 times.
✓ Branch 1 taken 183396 times.
185845 if (x)
2290 2449 break;
2291 }
2292 }
2293 }
2294
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 2442 times.
2449 if (src < ptr)
2295
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 copy_data_segment(0);
2296 }
2297 #undef copy_data_segment
2298
2299 2523 *unescaped_buf_ptr = s->buffer;
2300 2523 *unescaped_buf_size = dst - s->buffer;
2301 2523 memset(s->buffer + *unescaped_buf_size, 0,
2302 AV_INPUT_BUFFER_PADDING_SIZE);
2303
2304 2523 av_log(s->avctx, AV_LOG_DEBUG, "escaping removed %"PTRDIFF_SPECIFIER" bytes\n",
2305 2523 (buf_end - *buf_ptr) - (dst - s->buffer));
2306
3/4
✓ Branch 0 taken 213 times.
✓ Branch 1 taken 13865 times.
✓ Branch 2 taken 213 times.
✗ Branch 3 not taken.
14078 } else if (start_code == SOS && s->ls) {
2307 213 const uint8_t *src = *buf_ptr;
2308 213 uint8_t *dst = s->buffer;
2309 213 int bit_count = 0;
2310 213 int t = 0, b = 0;
2311 PutBitContext pb;
2312
2313 /* find marker */
2314
1/2
✓ Branch 0 taken 27487079 times.
✗ Branch 1 not taken.
27487292 while (src + t < buf_end) {
2315 27487079 uint8_t x = src[t++];
2316
2/2
✓ Branch 0 taken 27333028 times.
✓ Branch 1 taken 154051 times.
27487079 if (x == 0xff) {
2317
4/4
✓ Branch 0 taken 307889 times.
✓ Branch 1 taken 213 times.
✓ Branch 2 taken 154051 times.
✓ Branch 3 taken 153838 times.
308102 while ((src + t < buf_end) && x == 0xff)
2318 154051 x = src[t++];
2319
2/2
✓ Branch 0 taken 213 times.
✓ Branch 1 taken 153838 times.
154051 if (x & 0x80) {
2320 213 t -= FFMIN(2, t);
2321 213 break;
2322 }
2323 }
2324 }
2325 213 bit_count = t * 8;
2326 213 init_put_bits(&pb, dst, t);
2327
2328 /* unescape bitstream */
2329
2/2
✓ Branch 0 taken 27486866 times.
✓ Branch 1 taken 213 times.
27487079 while (b < t) {
2330 27486866 uint8_t x = src[b++];
2331 27486866 put_bits(&pb, 8, x);
2332
3/4
✓ Branch 0 taken 153838 times.
✓ Branch 1 taken 27333028 times.
✓ Branch 2 taken 153838 times.
✗ Branch 3 not taken.
27486866 if (x == 0xFF && b < t) {
2333 153838 x = src[b++];
2334
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 153838 times.
153838 if (x & 0x80) {
2335 av_log(s->avctx, AV_LOG_WARNING, "Invalid escape sequence\n");
2336 x &= 0x7f;
2337 }
2338 153838 put_bits(&pb, 7, x);
2339 153838 bit_count--;
2340 }
2341 }
2342 213 flush_put_bits(&pb);
2343
2344 213 *unescaped_buf_ptr = dst;
2345 213 *unescaped_buf_size = (bit_count + 7) >> 3;
2346 213 memset(s->buffer + *unescaped_buf_size, 0,
2347 AV_INPUT_BUFFER_PADDING_SIZE);
2348 } else {
2349 13865 *unescaped_buf_ptr = *buf_ptr;
2350 13865 *unescaped_buf_size = buf_end - *buf_ptr;
2351 }
2352
2353 16601 return start_code;
2354 }
2355
2356 211 static void reset_icc_profile(MJpegDecodeContext *s)
2357 {
2358 int i;
2359
2360
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 201 times.
211 if (s->iccentries) {
2361
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 for (i = 0; i < s->iccnum; i++)
2362 10 av_freep(&s->iccentries[i].data);
2363 10 av_freep(&s->iccentries);
2364 }
2365
2366 211 s->iccread = 0;
2367 211 s->iccnum = 0;
2368 211 }
2369
2370 2587 int ff_mjpeg_decode_frame_from_buf(AVCodecContext *avctx, AVFrame *frame,
2371 int *got_frame, const AVPacket *avpkt,
2372 const uint8_t *buf, const int buf_size)
2373 {
2374 2587 MJpegDecodeContext *s = avctx->priv_data;
2375 const uint8_t *buf_end, *buf_ptr;
2376 const uint8_t *unescaped_buf_ptr;
2377 int hshift, vshift;
2378 int unescaped_buf_size;
2379 int start_code;
2380 int index;
2381 2587 int ret = 0;
2382 int is16bit;
2383 2587 AVDictionaryEntry *e = NULL;
2384
2385 2587 s->force_pal8 = 0;
2386
2387 2587 s->buf_size = buf_size;
2388
2389 2587 av_dict_free(&s->exif_metadata);
2390 2587 av_freep(&s->stereo3d);
2391 2587 s->adobe_transform = -1;
2392
2393
1/2
✓ Branch 0 taken 2587 times.
✗ Branch 1 not taken.
2587 if (s->iccnum != 0)
2394 reset_icc_profile(s);
2395
2396 2587 redo_for_pal8:
2397 2595 buf_ptr = buf;
2398 2595 buf_end = buf + buf_size;
2399
1/2
✓ Branch 0 taken 16399 times.
✗ Branch 1 not taken.
16399 while (buf_ptr < buf_end) {
2400 /* find start next marker */
2401 16399 start_code = ff_mjpeg_find_marker(s, &buf_ptr, buf_end,
2402 &unescaped_buf_ptr,
2403 &unescaped_buf_size);
2404 /* EOF */
2405
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 16387 times.
16399 if (start_code < 0) {
2406 12 break;
2407
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16387 times.
16387 } else if (unescaped_buf_size > INT_MAX / 8) {
2408 av_log(avctx, AV_LOG_ERROR,
2409 "MJPEG packet 0x%x too big (%d/%d), corrupt data?\n",
2410 start_code, unescaped_buf_size, buf_size);
2411 return AVERROR_INVALIDDATA;
2412 }
2413 16387 av_log(avctx, AV_LOG_DEBUG, "marker=%x avail_size_in_buf=%"PTRDIFF_SPECIFIER"\n",
2414 start_code, buf_end - buf_ptr);
2415
2416 16387 ret = init_get_bits8(&s->gb, unescaped_buf_ptr, unescaped_buf_size);
2417
2418
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16387 times.
16387 if (ret < 0) {
2419 av_log(avctx, AV_LOG_ERROR, "invalid buffer\n");
2420 goto fail;
2421 }
2422
2423 16387 s->start_code = start_code;
2424
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16387 times.
16387 if (avctx->debug & FF_DEBUG_STARTCODE)
2425 av_log(avctx, AV_LOG_DEBUG, "startcode: %X\n", start_code);
2426
2427 /* process markers */
2428
4/4
✓ Branch 0 taken 11179 times.
✓ Branch 1 taken 5208 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 11177 times.
16387 if (start_code >= RST0 && start_code <= RST7) {
2429 2 av_log(avctx, AV_LOG_DEBUG,
2430 "restart marker: %d\n", start_code & 0x0f);
2431 /* APP fields */
2432
4/4
✓ Branch 0 taken 694 times.
✓ Branch 1 taken 15691 times.
✓ Branch 2 taken 223 times.
✓ Branch 3 taken 471 times.
16385 } else if (start_code >= APP0 && start_code <= APP15) {
2433
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 223 times.
223 if ((ret = mjpeg_decode_app(s)) < 0)
2434 av_log(avctx, AV_LOG_ERROR, "unable to decode APP fields: %s\n",
2435 av_err2str(ret));
2436 /* Comment */
2437
2/2
✓ Branch 0 taken 234 times.
✓ Branch 1 taken 15928 times.
16162 } else if (start_code == COM) {
2438 234 ret = mjpeg_decode_com(s);
2439
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 234 times.
234 if (ret < 0)
2440 return ret;
2441
2/2
✓ Branch 0 taken 2580 times.
✓ Branch 1 taken 13348 times.
15928 } else if (start_code == DQT) {
2442 2580 ret = ff_mjpeg_decode_dqt(s);
2443
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2580 times.
2580 if (ret < 0)
2444 return ret;
2445 }
2446
2447 16387 ret = -1;
2448
2449 if (!CONFIG_JPEGLS_DECODER &&
2450 (start_code == SOF48 || start_code == LSE)) {
2451 av_log(avctx, AV_LOG_ERROR, "JPEG-LS support not enabled.\n");
2452 return AVERROR(ENOSYS);
2453 }
2454
2455
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 15559 times.
16387 if (avctx->skip_frame == AVDISCARD_ALL) {
2456
2/2
✓ Branch 0 taken 391 times.
✓ Branch 1 taken 437 times.
828 switch(start_code) {
2457 391 case SOF0:
2458 case SOF1:
2459 case SOF2:
2460 case SOF3:
2461 case SOF48:
2462 case SOI:
2463 case SOS:
2464 case EOI:
2465 391 break;
2466 437 default:
2467 437 goto skip;
2468 }
2469 }
2470
2471
11/12
✓ Branch 0 taken 2598 times.
✓ Branch 1 taken 2622 times.
✓ Branch 2 taken 2158 times.
✓ Branch 3 taken 14 times.
✓ Branch 4 taken 205 times.
✓ Branch 5 taken 221 times.
✓ Branch 6 taken 16 times.
✓ Branch 7 taken 2579 times.
✓ Branch 8 taken 2705 times.
✓ Branch 9 taken 16 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2816 times.
15950 switch (start_code) {
2472 2598 case SOI:
2473 2598 s->restart_interval = 0;
2474 2598 s->restart_count = 0;
2475 2598 s->raw_image_buffer = buf_ptr;
2476 2598 s->raw_image_buffer_size = buf_end - buf_ptr;
2477 /* nothing to do on SOI */
2478 2598 break;
2479 2622 case DHT:
2480
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2622 times.
2622 if ((ret = ff_mjpeg_decode_dht(s)) < 0) {
2481 av_log(avctx, AV_LOG_ERROR, "huffman table decode error\n");
2482 goto fail;
2483 }
2484 2622 break;
2485 2158 case SOF0:
2486 case SOF1:
2487
2/2
✓ Branch 0 taken 2156 times.
✓ Branch 1 taken 2 times.
2158 if (start_code == SOF0)
2488 2156 avctx->profile = AV_PROFILE_MJPEG_HUFFMAN_BASELINE_DCT;
2489 else
2490 2 avctx->profile = AV_PROFILE_MJPEG_HUFFMAN_EXTENDED_SEQUENTIAL_DCT;
2491 2158 s->lossless = 0;
2492 2158 s->ls = 0;
2493 2158 s->progressive = 0;
2494
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2158 times.
2158 if ((ret = ff_mjpeg_decode_sof(s)) < 0)
2495 goto fail;
2496 2158 break;
2497 14 case SOF2:
2498 14 avctx->profile = AV_PROFILE_MJPEG_HUFFMAN_PROGRESSIVE_DCT;
2499 14 s->lossless = 0;
2500 14 s->ls = 0;
2501 14 s->progressive = 1;
2502
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
14 if ((ret = ff_mjpeg_decode_sof(s)) < 0)
2503 goto fail;
2504 14 break;
2505 205 case SOF3:
2506 205 avctx->profile = AV_PROFILE_MJPEG_HUFFMAN_LOSSLESS;
2507 205 avctx->properties |= FF_CODEC_PROPERTY_LOSSLESS;
2508 205 s->lossless = 1;
2509 205 s->ls = 0;
2510 205 s->progressive = 0;
2511
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 205 times.
205 if ((ret = ff_mjpeg_decode_sof(s)) < 0)
2512 goto fail;
2513 205 break;
2514 221 case SOF48:
2515 221 avctx->profile = AV_PROFILE_MJPEG_JPEG_LS;
2516 221 avctx->properties |= FF_CODEC_PROPERTY_LOSSLESS;
2517 221 s->lossless = 1;
2518 221 s->ls = 1;
2519 221 s->progressive = 0;
2520
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 221 times.
221 if ((ret = ff_mjpeg_decode_sof(s)) < 0)
2521 goto fail;
2522 221 break;
2523 16 case LSE:
2524
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if (!CONFIG_JPEGLS_DECODER ||
2525 16 (ret = ff_jpegls_decode_lse(s)) < 0)
2526 goto fail;
2527
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
16 if (ret == 1)
2528 8 goto redo_for_pal8;
2529 8 break;
2530 case EOI:
2531 2590 eoi_parser:
2532
3/4
✓ Branch 0 taken 2590 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2503 times.
✓ Branch 3 taken 87 times.
2590 if (!avctx->hwaccel && avctx->skip_frame != AVDISCARD_ALL &&
2533
4/6
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 2496 times.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
2503 s->progressive && s->cur_scan && s->got_picture)
2534 7 mjpeg_idct_scan_progressive_ac(s);
2535 2590 s->cur_scan = 0;
2536
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2590 times.
2590 if (!s->got_picture) {
2537 av_log(avctx, AV_LOG_WARNING,
2538 "Found EOI before any SOF, ignoring\n");
2539 break;
2540 }
2541
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 2582 times.
2590 if (s->interlaced) {
2542 8 s->bottom_field ^= 1;
2543 /* if not bottom field, do not output image yet */
2544
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 if (s->bottom_field == !s->interlace_polarity)
2545 4 break;
2546 }
2547
2/2
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 2500 times.
2586 if (avctx->skip_frame == AVDISCARD_ALL) {
2548 86 s->got_picture = 0;
2549 86 goto the_end_no_picture;
2550 }
2551
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2500 times.
2500 if (avctx->hwaccel) {
2552 ret = FF_HW_SIMPLE_CALL(avctx, end_frame);
2553 if (ret < 0)
2554 return ret;
2555
2556 av_freep(&s->hwaccel_picture_private);
2557 }
2558
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2500 times.
2500 if ((ret = av_frame_ref(frame, s->picture_ptr)) < 0)
2559 return ret;
2560 2500 *got_frame = 1;
2561 2500 s->got_picture = 0;
2562
2563
3/4
✓ Branch 0 taken 2087 times.
✓ Branch 1 taken 413 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2087 times.
2500 if (!s->lossless && avctx->debug & FF_DEBUG_QP) {
2564 int qp = FFMAX3(s->qscale[0],
2565 s->qscale[1],
2566 s->qscale[2]);
2567
2568 av_log(avctx, AV_LOG_DEBUG, "QP: %d\n", qp);
2569 }
2570
2571 2500 goto the_end;
2572 2705 case SOS:
2573 2705 s->raw_scan_buffer = buf_ptr;
2574 2705 s->raw_scan_buffer_size = buf_end - buf_ptr;
2575
2576 2705 s->cur_scan++;
2577
2/2
✓ Branch 0 taken 141 times.
✓ Branch 1 taken 2564 times.
2705 if (avctx->skip_frame == AVDISCARD_ALL) {
2578 141 skip_bits(&s->gb, get_bits_left(&s->gb));
2579 141 break;
2580 }
2581
2582
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2564 times.
2564 if ((ret = ff_mjpeg_decode_sos(s, NULL, 0, NULL)) < 0 &&
2583 (avctx->err_recognition & AV_EF_EXPLODE))
2584 goto fail;
2585 2564 break;
2586 16 case DRI:
2587
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
16 if ((ret = mjpeg_decode_dri(s)) < 0)
2588 return ret;
2589 16 break;
2590 case SOF5:
2591 case SOF6:
2592 case SOF7:
2593 case SOF9:
2594 case SOF10:
2595 case SOF11:
2596 case SOF13:
2597 case SOF14:
2598 case SOF15:
2599 case JPG:
2600 av_log(avctx, AV_LOG_ERROR,
2601 "mjpeg: unsupported coding type (%x)\n", start_code);
2602 break;
2603 }
2604
2605 13804 skip:
2606 /* eof process start code */
2607 13804 buf_ptr += (get_bits_count(&s->gb) + 7) / 8;
2608 27608 av_log(avctx, AV_LOG_DEBUG,
2609 "marker parser used %d bytes (%d bits)\n",
2610 13804 (get_bits_count(&s->gb) + 7) / 8, get_bits_count(&s->gb));
2611 }
2612
3/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
12 if (s->got_picture && s->cur_scan) {
2613 11 av_log(avctx, AV_LOG_WARNING, "EOI missing, emulating\n");
2614 11 goto eoi_parser;
2615 }
2616 1 av_log(avctx, AV_LOG_FATAL, "No JPEG data found in image\n");
2617 1 return AVERROR_INVALIDDATA;
2618 fail:
2619 s->got_picture = 0;
2620 return ret;
2621 2500 the_end:
2622
2623 2500 is16bit = av_pix_fmt_desc_get(avctx->pix_fmt)->comp[0].step > 1;
2624
2625
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2494 times.
2500 if (AV_RB32(s->upscale_h)) {
2626 int p;
2627
15/28
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✓ Branch 11 taken 1 times.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 3 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 3 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 3 times.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✓ Branch 25 taken 3 times.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
6 av_assert0(avctx->pix_fmt == AV_PIX_FMT_YUVJ444P ||
2628 avctx->pix_fmt == AV_PIX_FMT_YUV444P ||
2629 avctx->pix_fmt == AV_PIX_FMT_YUVJ440P ||
2630 avctx->pix_fmt == AV_PIX_FMT_YUV440P ||
2631 avctx->pix_fmt == AV_PIX_FMT_YUVA444P ||
2632 avctx->pix_fmt == AV_PIX_FMT_YUVJ422P ||
2633 avctx->pix_fmt == AV_PIX_FMT_YUV422P ||
2634 avctx->pix_fmt == AV_PIX_FMT_YUVJ420P ||
2635 avctx->pix_fmt == AV_PIX_FMT_YUV420P ||
2636 avctx->pix_fmt == AV_PIX_FMT_YUV420P16||
2637 avctx->pix_fmt == AV_PIX_FMT_YUVA420P ||
2638 avctx->pix_fmt == AV_PIX_FMT_YUVA420P16||
2639 avctx->pix_fmt == AV_PIX_FMT_GBRP ||
2640 avctx->pix_fmt == AV_PIX_FMT_GBRAP
2641 );
2642 6 ret = av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &hshift, &vshift);
2643
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (ret)
2644 return ret;
2645
2646
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
6 av_assert0(s->nb_components == av_pix_fmt_count_planes(s->picture_ptr->format));
2647
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 6 times.
24 for (p = 0; p<s->nb_components; p++) {
2648 18 uint8_t *line = s->picture_ptr->data[p];
2649 18 int w = s->width;
2650 18 int h = s->height;
2651
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if (!s->upscale_h[p])
2652 9 continue;
2653
4/4
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 2 times.
9 if (p==1 || p==2) {
2654 7 w = AV_CEIL_RSHIFT(w, hshift);
2655 7 h = AV_CEIL_RSHIFT(h, vshift);
2656 }
2657
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8 times.
9 if (s->upscale_v[p] == 1)
2658 1 h = (h+1)>>1;
2659
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 av_assert0(w > 0);
2660
2/2
✓ Branch 0 taken 534 times.
✓ Branch 1 taken 9 times.
543 for (int i = 0; i < h; i++) {
2661
2/2
✓ Branch 0 taken 214 times.
✓ Branch 1 taken 320 times.
534 if (s->upscale_h[p] == 1) {
2662
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 214 times.
214 if (is16bit) ((uint16_t*)line)[w - 1] = ((uint16_t*)line)[(w - 1) / 2];
2663 214 else line[w - 1] = line[(w - 1) / 2];
2664
2/2
✓ Branch 0 taken 11220 times.
✓ Branch 1 taken 214 times.
11434 for (index = w - 2; index > 0; index--) {
2665
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11220 times.
11220 if (is16bit)
2666 ((uint16_t*)line)[index] = (((uint16_t*)line)[index / 2] + ((uint16_t*)line)[(index + 1) / 2]) >> 1;
2667 else
2668 11220 line[index] = (line[index / 2] + line[(index + 1) / 2]) >> 1;
2669 }
2670
2/2
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 64 times.
320 } else if (s->upscale_h[p] == 2) {
2671
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 256 times.
256 if (is16bit) {
2672 ((uint16_t*)line)[w - 1] = ((uint16_t*)line)[(w - 1) / 3];
2673 if (w > 1)
2674 ((uint16_t*)line)[w - 2] = ((uint16_t*)line)[w - 1];
2675 } else {
2676 256 line[w - 1] = line[(w - 1) / 3];
2677
1/2
✓ Branch 0 taken 256 times.
✗ Branch 1 not taken.
256 if (w > 1)
2678 256 line[w - 2] = line[w - 1];
2679 }
2680
2/2
✓ Branch 0 taken 15616 times.
✓ Branch 1 taken 256 times.
15872 for (index = w - 3; index > 0; index--) {
2681 15616 line[index] = (line[index / 3] + line[(index + 1) / 3] + line[(index + 2) / 3] + 1) / 3;
2682 }
2683
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 } else if (s->upscale_h[p] == 4){
2684
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 64 times.
64 if (is16bit) {
2685 uint16_t *line16 = (uint16_t *) line;
2686 line16[w - 1] = line16[(w - 1) >> 2];
2687 if (w > 1)
2688 line16[w - 2] = (line16[(w - 1) >> 2] * 3 + line16[(w - 2) >> 2]) >> 2;
2689 if (w > 2)
2690 line16[w - 3] = (line16[(w - 1) >> 2] + line16[(w - 2) >> 2]) >> 1;
2691 } else {
2692 64 line[w - 1] = line[(w - 1) >> 2];
2693
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 if (w > 1)
2694 64 line[w - 2] = (line[(w - 1) >> 2] * 3 + line[(w - 2) >> 2]) >> 2;
2695
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 if (w > 2)
2696 64 line[w - 3] = (line[(w - 1) >> 2] + line[(w - 2) >> 2]) >> 1;
2697 }
2698
2/2
✓ Branch 0 taken 3840 times.
✓ Branch 1 taken 64 times.
3904 for (index = w - 4; index > 0; index--)
2699 3840 line[index] = (line[(index + 3) >> 2] + line[(index + 2) >> 2]
2700 3840 + line[(index + 1) >> 2] + line[index >> 2]) >> 2;
2701 }
2702 534 line += s->linesize[p];
2703 }
2704 }
2705 }
2706
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2499 times.
2500 if (AV_RB32(s->upscale_v)) {
2707 int p;
2708
12/26
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 1 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 1 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
1 av_assert0(avctx->pix_fmt == AV_PIX_FMT_YUVJ444P ||
2709 avctx->pix_fmt == AV_PIX_FMT_YUV444P ||
2710 avctx->pix_fmt == AV_PIX_FMT_YUVJ422P ||
2711 avctx->pix_fmt == AV_PIX_FMT_YUV422P ||
2712 avctx->pix_fmt == AV_PIX_FMT_YUVJ420P ||
2713 avctx->pix_fmt == AV_PIX_FMT_YUV420P ||
2714 avctx->pix_fmt == AV_PIX_FMT_YUV440P ||
2715 avctx->pix_fmt == AV_PIX_FMT_YUVJ440P ||
2716 avctx->pix_fmt == AV_PIX_FMT_YUVA444P ||
2717 avctx->pix_fmt == AV_PIX_FMT_YUVA420P ||
2718 avctx->pix_fmt == AV_PIX_FMT_YUVA420P16||
2719 avctx->pix_fmt == AV_PIX_FMT_GBRP ||
2720 avctx->pix_fmt == AV_PIX_FMT_GBRAP
2721 );
2722 1 ret = av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &hshift, &vshift);
2723
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret)
2724 return ret;
2725
2726
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 av_assert0(s->nb_components == av_pix_fmt_count_planes(s->picture_ptr->format));
2727
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 for (p = 0; p < s->nb_components; p++) {
2728 uint8_t *dst;
2729 3 int w = s->width;
2730 3 int h = s->height;
2731
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if (!s->upscale_v[p])
2732 2 continue;
2733
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (p==1 || p==2) {
2734 1 w = AV_CEIL_RSHIFT(w, hshift);
2735 1 h = AV_CEIL_RSHIFT(h, vshift);
2736 }
2737 1 dst = &((uint8_t *)s->picture_ptr->data[p])[(h - 1) * s->linesize[p]];
2738
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 1 times.
43 for (int i = h - 1; i; i--) {
2739 42 uint8_t *src1 = &((uint8_t *)s->picture_ptr->data[p])[i * s->upscale_v[p] / (s->upscale_v[p] + 1) * s->linesize[p]];
2740 42 uint8_t *src2 = &((uint8_t *)s->picture_ptr->data[p])[(i + 1) * s->upscale_v[p] / (s->upscale_v[p] + 1) * s->linesize[p]];
2741
4/6
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
✓ Branch 3 taken 21 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 21 times.
42 if (s->upscale_v[p] != 2 && (src1 == src2 || i == h - 1)) {
2742 21 memcpy(dst, src1, w);
2743 } else {
2744
2/2
✓ Branch 0 taken 1344 times.
✓ Branch 1 taken 21 times.
1365 for (index = 0; index < w; index++)
2745 1344 dst[index] = (src1[index] + src2[index]) >> 1;
2746 }
2747 42 dst -= s->linesize[p];
2748 }
2749 }
2750 }
2751
3/4
✓ Branch 0 taken 370 times.
✓ Branch 1 taken 2130 times.
✓ Branch 2 taken 370 times.
✗ Branch 3 not taken.
2500 if (s->flipped && !s->rgb) {
2752 370 ret = av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &hshift, &vshift);
2753
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 370 times.
370 if (ret)
2754 return ret;
2755
2756
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 370 times.
370 av_assert0(s->nb_components == av_pix_fmt_count_planes(frame->format));
2757
2/2
✓ Branch 0 taken 1110 times.
✓ Branch 1 taken 370 times.
1480 for (index=0; index<s->nb_components; index++) {
2758 1110 int h = frame->height;
2759
3/4
✓ Branch 0 taken 740 times.
✓ Branch 1 taken 370 times.
✓ Branch 2 taken 740 times.
✗ Branch 3 not taken.
1110 if (index && index < 3)
2760 740 h = AV_CEIL_RSHIFT(h, vshift);
2761
1/2
✓ Branch 0 taken 1110 times.
✗ Branch 1 not taken.
1110 if (frame->data[index]) {
2762 1110 frame->data[index] += (h - 1) * frame->linesize[index];
2763 1110 frame->linesize[index] *= -1;
2764 }
2765 }
2766 }
2767
2768
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2495 times.
2500 if (avctx->pix_fmt == AV_PIX_FMT_GBRP) {
2769
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 av_assert0(s->nb_components == 3);
2770 5 FFSWAP(uint8_t *, frame->data[0], frame->data[2]);
2771 5 FFSWAP(uint8_t *, frame->data[0], frame->data[1]);
2772 5 FFSWAP(int, frame->linesize[0], frame->linesize[2]);
2773 5 FFSWAP(int, frame->linesize[0], frame->linesize[1]);
2774 }
2775
2776
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2496 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
2500 if (s->adobe_transform == 0 && avctx->pix_fmt == AV_PIX_FMT_GBRAP) {
2777 int w = s->picture_ptr->width;
2778 int h = s->picture_ptr->height;
2779 av_assert0(s->nb_components == 4);
2780 for (int i = 0; i < h; i++) {
2781 int j;
2782 uint8_t *dst[4];
2783 for (index=0; index<4; index++) {
2784 dst[index] = s->picture_ptr->data[index]
2785 + s->picture_ptr->linesize[index]*i;
2786 }
2787 for (j=0; j<w; j++) {
2788 int k = dst[3][j];
2789 int r = dst[0][j] * k;
2790 int g = dst[1][j] * k;
2791 int b = dst[2][j] * k;
2792 dst[0][j] = g*257 >> 16;
2793 dst[1][j] = b*257 >> 16;
2794 dst[2][j] = r*257 >> 16;
2795 }
2796 memset(dst[3], 255, w);
2797 }
2798 }
2799
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2500 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2500 if (s->adobe_transform == 2 && avctx->pix_fmt == AV_PIX_FMT_YUVA444P) {
2800 int w = s->picture_ptr->width;
2801 int h = s->picture_ptr->height;
2802 av_assert0(s->nb_components == 4);
2803 for (int i = 0; i < h; i++) {
2804 int j;
2805 uint8_t *dst[4];
2806 for (index=0; index<4; index++) {
2807 dst[index] = s->picture_ptr->data[index]
2808 + s->picture_ptr->linesize[index]*i;
2809 }
2810 for (j=0; j<w; j++) {
2811 int k = dst[3][j];
2812 int r = (255 - dst[0][j]) * k;
2813 int g = (128 - dst[1][j]) * k;
2814 int b = (128 - dst[2][j]) * k;
2815 dst[0][j] = r*257 >> 16;
2816 dst[1][j] = (g*257 >> 16) + 128;
2817 dst[2][j] = (b*257 >> 16) + 128;
2818 }
2819 memset(dst[3], 255, w);
2820 }
2821 }
2822
2823
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2500 times.
2500 if (s->stereo3d) {
2824 AVStereo3D *stereo = av_stereo3d_create_side_data(frame);
2825 if (stereo) {
2826 stereo->type = s->stereo3d->type;
2827 stereo->flags = s->stereo3d->flags;
2828 }
2829 av_freep(&s->stereo3d);
2830 }
2831
2832
3/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2495 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
2500 if (s->iccnum != 0 && s->iccnum == s->iccread) {
2833 AVFrameSideData *sd;
2834 5 size_t offset = 0;
2835 5 int total_size = 0;
2836
2837 /* Sum size of all parts. */
2838
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 for (int i = 0; i < s->iccnum; i++)
2839 5 total_size += s->iccentries[i].length;
2840
2841 5 ret = ff_frame_new_side_data(avctx, frame, AV_FRAME_DATA_ICC_PROFILE, total_size, &sd);
2842
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (ret < 0) {
2843 av_log(avctx, AV_LOG_ERROR, "Could not allocate frame side data\n");
2844 return ret;
2845 }
2846
2847
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (sd) {
2848 /* Reassemble the parts, which are now in-order. */
2849
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 for (int i = 0; i < s->iccnum; i++) {
2850 5 memcpy(sd->data + offset, s->iccentries[i].data, s->iccentries[i].length);
2851 5 offset += s->iccentries[i].length;
2852 }
2853 }
2854 }
2855
2856
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2499 times.
2500 if (e = av_dict_get(s->exif_metadata, "Orientation", e, AV_DICT_IGNORE_SUFFIX)) {
2857 1 char *value = e->value + strspn(e->value, " \n\t\r"), *endptr;
2858 1 int orientation = strtol(value, &endptr, 0);
2859
2860
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (!*endptr) {
2861 1 AVFrameSideData *sd = NULL;
2862
2863
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1 if (orientation >= 2 && orientation <= 8) {
2864 int32_t *matrix;
2865
2866 sd = av_frame_new_side_data(frame, AV_FRAME_DATA_DISPLAYMATRIX, sizeof(int32_t) * 9);
2867 if (!sd) {
2868 av_log(avctx, AV_LOG_ERROR, "Could not allocate frame side data\n");
2869 return AVERROR(ENOMEM);
2870 }
2871
2872 matrix = (int32_t *)sd->data;
2873
2874 switch (orientation) {
2875 case 2:
2876 av_display_rotation_set(matrix, 0.0);
2877 av_display_matrix_flip(matrix, 1, 0);
2878 break;
2879 case 3:
2880 av_display_rotation_set(matrix, 180.0);
2881 break;
2882 case 4:
2883 av_display_rotation_set(matrix, 180.0);
2884 av_display_matrix_flip(matrix, 1, 0);
2885 break;
2886 case 5:
2887 av_display_rotation_set(matrix, 90.0);
2888 av_display_matrix_flip(matrix, 1, 0);
2889 break;
2890 case 6:
2891 av_display_rotation_set(matrix, 90.0);
2892 break;
2893 case 7:
2894 av_display_rotation_set(matrix, -90.0);
2895 av_display_matrix_flip(matrix, 1, 0);
2896 break;
2897 case 8:
2898 av_display_rotation_set(matrix, -90.0);
2899 break;
2900 default:
2901 av_assert0(0);
2902 }
2903 }
2904 }
2905 }
2906
2907 2500 av_dict_copy(&frame->metadata, s->exif_metadata, 0);
2908 2500 av_dict_free(&s->exif_metadata);
2909
2910
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2497 times.
2500 if (avctx->codec_id != AV_CODEC_ID_SMVJPEG &&
2911
1/2
✓ Branch 0 taken 2497 times.
✗ Branch 1 not taken.
2497 (avctx->codec_tag == MKTAG('A', 'V', 'R', 'n') ||
2912
2/2
✓ Branch 0 taken 2487 times.
✓ Branch 1 taken 10 times.
2497 avctx->codec_tag == MKTAG('A', 'V', 'D', 'J')) &&
2913
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 avctx->coded_height > s->orig_height) {
2914 10 frame->height = AV_CEIL_RSHIFT(avctx->coded_height, avctx->lowres);
2915 10 frame->crop_top = frame->height - avctx->height;
2916 }
2917
2918 2490 the_end_no_picture:
2919 2586 av_log(avctx, AV_LOG_DEBUG, "decode frame unused %"PTRDIFF_SPECIFIER" bytes\n",
2920 buf_end - buf_ptr);
2921 2586 return buf_ptr - buf;
2922 }
2923
2924 2206 int ff_mjpeg_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame,
2925 AVPacket *avpkt)
2926 {
2927 4412 return ff_mjpeg_decode_frame_from_buf(avctx, frame, got_frame,
2928 2206 avpkt, avpkt->data, avpkt->size);
2929 }
2930
2931
2932 /* mxpeg may call the following function (with a blank MJpegDecodeContext)
2933 * even without having called ff_mjpeg_decode_init(). */
2934 211 av_cold int ff_mjpeg_decode_end(AVCodecContext *avctx)
2935 {
2936 211 MJpegDecodeContext *s = avctx->priv_data;
2937 int i, j;
2938
2939
3/8
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 207 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
211 if (s->interlaced && s->bottom_field == !s->interlace_polarity && s->got_picture && !avctx->frame_num) {
2940 av_log(avctx, AV_LOG_INFO, "Single field\n");
2941 }
2942
2943
2/2
✓ Branch 0 taken 209 times.
✓ Branch 1 taken 2 times.
211 if (s->picture) {
2944 209 av_frame_free(&s->picture);
2945 209 s->picture_ptr = NULL;
2946
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 } else if (s->picture_ptr)
2947 av_frame_unref(s->picture_ptr);
2948
2949 211 av_frame_free(&s->smv_frame);
2950
2951 211 av_freep(&s->buffer);
2952 211 av_freep(&s->stereo3d);
2953 211 av_freep(&s->ljpeg_buffer);
2954 211 s->ljpeg_buffer_size = 0;
2955
2956
2/2
✓ Branch 0 taken 633 times.
✓ Branch 1 taken 211 times.
844 for (i = 0; i < 3; i++) {
2957
2/2
✓ Branch 0 taken 2532 times.
✓ Branch 1 taken 633 times.
3165 for (j = 0; j < 4; j++)
2958 2532 ff_vlc_free(&s->vlcs[i][j]);
2959 }
2960
2/2
✓ Branch 0 taken 844 times.
✓ Branch 1 taken 211 times.
1055 for (i = 0; i < MAX_COMPONENTS; i++) {
2961 844 av_freep(&s->blocks[i]);
2962 844 av_freep(&s->last_nnz[i]);
2963 }
2964 211 av_dict_free(&s->exif_metadata);
2965
2966 211 reset_icc_profile(s);
2967
2968 211 av_freep(&s->hwaccel_picture_private);
2969 211 av_freep(&s->jls_state);
2970
2971 211 return 0;
2972 }
2973
2974 4 static void decode_flush(AVCodecContext *avctx)
2975 {
2976 4 MJpegDecodeContext *s = avctx->priv_data;
2977 4 s->got_picture = 0;
2978
2979 4 s->smv_next_frame = 0;
2980 4 av_frame_unref(s->smv_frame);
2981 4 }
2982
2983 #if CONFIG_MJPEG_DECODER
2984 #define OFFSET(x) offsetof(MJpegDecodeContext, x)
2985 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
2986 static const AVOption options[] = {
2987 { "extern_huff", "Use external huffman table.",
2988 OFFSET(extern_huff), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
2989 { NULL },
2990 };
2991
2992 static const AVClass mjpegdec_class = {
2993 .class_name = "MJPEG decoder",
2994 .item_name = av_default_item_name,
2995 .option = options,
2996 .version = LIBAVUTIL_VERSION_INT,
2997 };
2998
2999 const FFCodec ff_mjpeg_decoder = {
3000 .p.name = "mjpeg",
3001 CODEC_LONG_NAME("MJPEG (Motion JPEG)"),
3002 .p.type = AVMEDIA_TYPE_VIDEO,
3003 .p.id = AV_CODEC_ID_MJPEG,
3004 .priv_data_size = sizeof(MJpegDecodeContext),
3005 .init = ff_mjpeg_decode_init,
3006 .close = ff_mjpeg_decode_end,
3007 FF_CODEC_DECODE_CB(ff_mjpeg_decode_frame),
3008 .flush = decode_flush,
3009 .p.capabilities = AV_CODEC_CAP_DR1,
3010 .p.max_lowres = 3,
3011 .p.priv_class = &mjpegdec_class,
3012 .p.profiles = NULL_IF_CONFIG_SMALL(ff_mjpeg_profiles),
3013 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
3014 FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM |
3015 FF_CODEC_CAP_ICC_PROFILES,
3016 .hw_configs = (const AVCodecHWConfigInternal *const []) {
3017 #if CONFIG_MJPEG_NVDEC_HWACCEL
3018 HWACCEL_NVDEC(mjpeg),
3019 #endif
3020 #if CONFIG_MJPEG_VAAPI_HWACCEL
3021 HWACCEL_VAAPI(mjpeg),
3022 #endif
3023 NULL
3024 },
3025 };
3026 #endif
3027 #if CONFIG_THP_DECODER
3028 const FFCodec ff_thp_decoder = {
3029 .p.name = "thp",
3030 CODEC_LONG_NAME("Nintendo Gamecube THP video"),
3031 .p.type = AVMEDIA_TYPE_VIDEO,
3032 .p.id = AV_CODEC_ID_THP,
3033 .priv_data_size = sizeof(MJpegDecodeContext),
3034 .init = ff_mjpeg_decode_init,
3035 .close = ff_mjpeg_decode_end,
3036 FF_CODEC_DECODE_CB(ff_mjpeg_decode_frame),
3037 .flush = decode_flush,
3038 .p.capabilities = AV_CODEC_CAP_DR1,
3039 .p.max_lowres = 3,
3040 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
3041 };
3042 #endif
3043
3044 #if CONFIG_SMVJPEG_DECODER
3045 // SMV JPEG just stacks several output frames into one JPEG picture
3046 // we handle that by setting up the cropping parameters appropriately
3047 13 static void smv_process_frame(AVCodecContext *avctx, AVFrame *frame)
3048 {
3049 13 MJpegDecodeContext *s = avctx->priv_data;
3050
3051
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
13 av_assert0((s->smv_next_frame + 1) * avctx->height <= avctx->coded_height);
3052
3053 13 frame->width = avctx->coded_width;
3054 13 frame->height = avctx->coded_height;
3055 13 frame->crop_top = FFMIN(s->smv_next_frame * avctx->height, frame->height);
3056 13 frame->crop_bottom = frame->height - (s->smv_next_frame + 1) * avctx->height;
3057
3058
1/2
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
13 if (s->smv_frame->pts != AV_NOPTS_VALUE)
3059 13 s->smv_frame->pts += s->smv_frame->duration;
3060 13 s->smv_next_frame = (s->smv_next_frame + 1) % s->smv_frames_per_jpeg;
3061
3062
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 11 times.
13 if (s->smv_next_frame == 0)
3063 2 av_frame_unref(s->smv_frame);
3064 13 }
3065
3066 16 static int smvjpeg_receive_frame(AVCodecContext *avctx, AVFrame *frame)
3067 {
3068 16 MJpegDecodeContext *s = avctx->priv_data;
3069 16 AVPacket *const pkt = avctx->internal->in_pkt;
3070 16 int got_frame = 0;
3071 int ret;
3072
3073
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 6 times.
16 if (s->smv_next_frame > 0)
3074 10 goto return_frame;
3075
3076 6 ret = ff_decode_get_packet(avctx, pkt);
3077
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if (ret < 0)
3078 3 return ret;
3079
3080 3 av_frame_unref(s->smv_frame);
3081
3082 3 ret = ff_mjpeg_decode_frame(avctx, s->smv_frame, &got_frame, pkt);
3083 3 s->smv_frame->pkt_dts = pkt->dts;
3084 3 av_packet_unref(pkt);
3085
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (ret < 0)
3086 return ret;
3087
3088
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!got_frame)
3089 return AVERROR(EAGAIN);
3090
3091 // packet duration covers all the frames in the packet
3092 3 s->smv_frame->duration /= s->smv_frames_per_jpeg;
3093
3094 13 return_frame:
3095
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
13 av_assert0(s->smv_frame->buf[0]);
3096 13 ret = av_frame_ref(frame, s->smv_frame);
3097
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
13 if (ret < 0)
3098 return ret;
3099
3100 13 smv_process_frame(avctx, frame);
3101 13 return 0;
3102 }
3103
3104 const FFCodec ff_smvjpeg_decoder = {
3105 .p.name = "smvjpeg",
3106 CODEC_LONG_NAME("SMV JPEG"),
3107 .p.type = AVMEDIA_TYPE_VIDEO,
3108 .p.id = AV_CODEC_ID_SMVJPEG,
3109 .priv_data_size = sizeof(MJpegDecodeContext),
3110 .init = ff_mjpeg_decode_init,
3111 .close = ff_mjpeg_decode_end,
3112 FF_CODEC_RECEIVE_FRAME_CB(smvjpeg_receive_frame),
3113 .flush = decode_flush,
3114 .p.capabilities = AV_CODEC_CAP_DR1,
3115 .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING |
3116 FF_CODEC_CAP_INIT_CLEANUP,
3117 };
3118 #endif
3119