FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/mjpegdec.c
Date: 2024-04-19 17:50:32
Exec Total Coverage
Lines: 1222 1866 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 3124 times.
✓ Branch 1 taken 2606 times.
5730 while (len >= 65) {
210 3124 int pr = get_bits(&s->gb, 4);
211
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3124 times.
3124 if (pr > 1) {
212 av_log(s->avctx, AV_LOG_ERROR, "dqt: invalid precision\n");
213 return AVERROR_INVALIDDATA;
214 }
215 3124 index = get_bits(&s->gb, 4);
216
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3124 times.
3124 if (index >= 4)
217 return -1;
218 3124 av_log(s->avctx, AV_LOG_DEBUG, "index=%d\n", index);
219 /* read quant table */
220
2/2
✓ Branch 0 taken 199936 times.
✓ Branch 1 taken 3124 times.
203060 for (i = 0; i < 64; i++) {
221
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 199936 times.
199936 s->quant_matrixes[index][i] = get_bits(&s->gb, pr ? 16 : 8);
222
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 199936 times.
199936 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 3124 s->qscale[index] = FFMAX(s->quant_matrixes[index][1],
232 3124 s->quant_matrixes[index][8]) >> 1;
233 3124 av_log(s->avctx, AV_LOG_DEBUG, "qscale[%d]: %d\n",
234 index, s->qscale[index]);
235 3124 len -= 1 + 64 * (1+pr);
236 }
237 2606 return 0;
238 }
239
240 /* decode huffman tables and build VLC decoders */
241 2654 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 2654 int ret = 0;
247
248 2654 len = get_bits(&s->gb, 16) - 2;
249
250
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2654 times.
2654 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 9255 times.
✓ Branch 1 taken 2654 times.
11909 while (len > 0) {
256
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9255 times.
9255 if (len < 17)
257 return AVERROR_INVALIDDATA;
258 9255 class = get_bits(&s->gb, 4);
259
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9255 times.
9255 if (class >= 2)
260 return AVERROR_INVALIDDATA;
261 9255 index = get_bits(&s->gb, 4);
262
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9255 times.
9255 if (index >= 4)
263 return AVERROR_INVALIDDATA;
264 9255 n = 0;
265
2/2
✓ Branch 0 taken 148080 times.
✓ Branch 1 taken 9255 times.
157335 for (i = 1; i <= 16; i++) {
266 148080 bits_table[i] = get_bits(&s->gb, 8);
267 148080 n += bits_table[i];
268 }
269 9255 len -= 17;
270
2/4
✓ Branch 0 taken 9255 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9255 times.
9255 if (len < n || n > 256)
271 return AVERROR_INVALIDDATA;
272
273
2/2
✓ Branch 0 taken 452436 times.
✓ Branch 1 taken 9255 times.
461691 for (i = 0; i < n; i++) {
274 452436 v = get_bits(&s->gb, 8);
275 452436 val_table[i] = v;
276 }
277 9255 len -= n;
278
279 /* build VLC and flush previous vlc if present */
280 9255 ff_vlc_free(&s->vlcs[class][index]);
281 9255 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 9255 times.
9255 if ((ret = ff_mjpeg_build_vlc(&s->vlcs[class][index], bits_table,
284 9255 val_table, class > 0, s->avctx)) < 0)
285 return ret;
286
287
2/2
✓ Branch 0 taken 4647 times.
✓ Branch 1 taken 4608 times.
9255 if (class > 0) {
288 4647 ff_vlc_free(&s->vlcs[2][index]);
289
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4647 times.
4647 if ((ret = ff_mjpeg_build_vlc(&s->vlcs[2][index], bits_table,
290 4647 val_table, 0, s->avctx)) < 0)
291 return ret;
292 }
293
294
2/2
✓ Branch 0 taken 148080 times.
✓ Branch 1 taken 9255 times.
157335 for (i = 0; i < 16; i++)
295 148080 s->raw_huffman_lengths[class][index][i] = bits_table[i + 1];
296
2/2
✓ Branch 0 taken 2369280 times.
✓ Branch 1 taken 9255 times.
2378535 for (i = 0; i < 256; i++)
297 2369280 s->raw_huffman_values[class][index][i] = val_table[i];
298 }
299 2654 return 0;
300 }
301
302 2621 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 2621 int h_count[MAX_COMPONENTS] = { 0 };
307 2621 int v_count[MAX_COMPONENTS] = { 0 };
308
309 2621 s->cur_scan = 0;
310 2621 memset(s->upscale_h, 0, sizeof(s->upscale_h));
311 2621 memset(s->upscale_v, 0, sizeof(s->upscale_v));
312
313 2621 len = get_bits(&s->gb, 16);
314 2621 bits = get_bits(&s->gb, 8);
315
316
2/4
✓ Branch 0 taken 2621 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2621 times.
2621 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 2513 times.
2621 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 2621 times.
2621 if (s->pegasus_rct)
327 bits = 9;
328
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2621 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2621 if (bits == 9 && !s->pegasus_rct)
329 s->rct = 1; // FIXME ugly
330
331
3/4
✓ Branch 0 taken 426 times.
✓ Branch 1 taken 2195 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 426 times.
2621 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 2621 height = get_bits(&s->gb, 16);
337 2621 width = get_bits(&s->gb, 16);
338
339 // HACK for odd_height.mov
340
4/6
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 2595 times.
✓ Branch 2 taken 26 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 26 times.
2621 if (s->interlaced && s->width == width && s->height == height + 1)
341 height= s->height;
342
343 2621 av_log(s->avctx, AV_LOG_DEBUG, "sof0: picture: %dx%d\n", width, height);
344
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2621 times.
2621 if (av_image_check_size(width, height, 0, s->avctx) < 0)
345 return AVERROR_INVALIDDATA;
346
3/4
✓ Branch 0 taken 2619 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2619 times.
2621 if (s->buf_size && (width + 7) / 8 * ((height + 7) / 8) > s->buf_size * 4LL)
347 return AVERROR_INVALIDDATA;
348
349 2621 nb_components = get_bits(&s->gb, 8);
350
2/4
✓ Branch 0 taken 2621 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2621 times.
2621 if (nb_components <= 0 ||
351 nb_components > MAX_COMPONENTS)
352 return -1;
353
4/4
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 2595 times.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 11 times.
2621 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 2400 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 221 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
2621 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 2621 times.
2621 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 2621 s->nb_components = nb_components;
372 2621 s->h_max = 1;
373 2621 s->v_max = 1;
374
2/2
✓ Branch 0 taken 7827 times.
✓ Branch 1 taken 2621 times.
10448 for (i = 0; i < nb_components; i++) {
375 /* component id */
376 7827 s->component_id[i] = get_bits(&s->gb, 8);
377 7827 h_count[i] = get_bits(&s->gb, 4);
378 7827 v_count[i] = get_bits(&s->gb, 4);
379 /* compute hmax and vmax (only used in interleaved case) */
380
2/2
✓ Branch 0 taken 2178 times.
✓ Branch 1 taken 5649 times.
7827 if (h_count[i] > s->h_max)
381 2178 s->h_max = h_count[i];
382
2/2
✓ Branch 0 taken 2333 times.
✓ Branch 1 taken 5494 times.
7827 if (v_count[i] > s->v_max)
383 2333 s->v_max = v_count[i];
384 7827 s->quant_index[i] = get_bits(&s->gb, 8);
385
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7827 times.
7827 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 7827 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7827 times.
7827 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 7827 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 2621 times.
2621 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 2400 times.
✓ Branch 2 taken 221 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 221 times.
2621 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 2621 times.
2621 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 2246 times.
✓ Branch 1 taken 375 times.
✓ Branch 2 taken 2240 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 2240 times.
✗ Branch 5 not taken.
2621 if (width != s->width || height != s->height || bits != s->bits ||
427
1/2
✓ Branch 0 taken 2240 times.
✗ Branch 1 not taken.
2240 memcmp(s->h_count, h_count, sizeof(h_count)) ||
428
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2240 times.
2240 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 2240 size_change = 0;
464 }
465
466
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2618 times.
2621 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 2598 times.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 15 times.
✗ Branch 5 not taken.
2621 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 2333 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.
2606 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 2180 times.
✓ Branch 1 taken 221 times.
2401 else if (!s->lossless)
481 2180 s->rgb = 0;
482 /* XXX: not complete test ! */
483 2606 pix_fmt_id = ((unsigned)s->h_count[0] << 28) | (s->v_count[0] << 24) |
484 2606 (s->h_count[1] << 20) | (s->v_count[1] << 16) |
485 2606 (s->h_count[2] << 12) | (s->v_count[2] << 8) |
486 2606 (s->h_count[3] << 4) | s->v_count[3];
487 2606 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 2606 times.
2606 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 2194 times.
2606 if (!(pix_fmt_id & 0x0D0D0D0D))
493 412 pix_fmt_id -= (pix_fmt_id & 0x0F0F0F0F) >> 1;
494
495
2/2
✓ Branch 0 taken 20848 times.
✓ Branch 1 taken 2606 times.
23454 for (i = 0; i < 8; i++) {
496 20848 int j = 6 + (i&1) - (i&6);
497 20848 int is = (pix_fmt_id >> (4*i)) & 0xF;
498 20848 int js = (pix_fmt_id >> (4*j)) & 0xF;
499
500
7/8
✓ Branch 0 taken 11470 times.
✓ Branch 1 taken 9378 times.
✓ Branch 2 taken 11462 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 11462 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1132 times.
✓ Branch 7 taken 10330 times.
20848 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 11470 times.
✓ Branch 1 taken 9378 times.
✓ Branch 2 taken 11460 times.
✓ Branch 3 taken 10 times.
✓ Branch 4 taken 11460 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1130 times.
✓ Branch 7 taken 10330 times.
20848 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 11470 times.
✓ Branch 1 taken 9378 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 11460 times.
20848 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 2606 times.
2606 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 1919 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
2606 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 1919 case 0x22111100:
668 case 0x23111100:
669 case 0x42111100:
670 case 0x24111100:
671
3/4
✓ Branch 0 taken 1919 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 205 times.
✓ Branch 3 taken 1714 times.
1919 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 1714 times.
1919 s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG;
674
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1919 times.
1919 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 1919 times.
1919 } 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 1919 times.
1919 } 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 1919 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 2594 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2594 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 12 times.
2606 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 2385 times.
2606 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 2606 s->pix_desc = av_pix_fmt_desc_get(s->avctx->pix_fmt);
722
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2606 times.
2606 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 2420 times.
✓ Branch 1 taken 186 times.
✓ Branch 2 taken 2217 times.
✓ Branch 3 taken 203 times.
2606 if (s->avctx->pix_fmt == s->hwaccel_sw_pix_fmt && !size_change) {
728 2217 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 2520 times.
2606 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 2520 av_frame_unref(s->picture_ptr);
756
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2520 times.
2520 if (ff_get_buffer(s->avctx, s->picture_ptr, AV_GET_BUFFER_FLAG_REF) < 0)
757 return -1;
758 2520 s->picture_ptr->pict_type = AV_PICTURE_TYPE_I;
759 2520 s->picture_ptr->flags |= AV_FRAME_FLAG_KEY;
760 2520 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 2512 times.
2520 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 10080 times.
✓ Branch 1 taken 2520 times.
12600 for (i = 0; i < 4; i++)
767 10080 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 2330 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 205 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
2535 if ((s->rgb && !s->lossless && !s->ls) ||
776
5/6
✓ Branch 0 taken 2330 times.
✓ Branch 1 taken 205 times.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 2314 times.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
2535 (!s->rgb && s->ls && s->nb_components > 1) ||
777
3/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 2527 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
2535 (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 2528 times.
2535 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 2535 times.
2535 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 2535 return 0;
814 }
815
816 26816672 static inline int mjpeg_decode_dc(MJpegDecodeContext *s, int dc_index)
817 {
818 int code;
819 26816672 code = get_vlc2(&s->gb, s->vlcs[0][dc_index].table, 9, 2);
820
2/4
✓ Branch 0 taken 26816672 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 26816672 times.
26816672 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 23774597 times.
✓ Branch 1 taken 3042075 times.
26816672 if (code)
828 23774597 return get_xbits(&s->gb, code);
829 else
830 3042075 return 0;
831 }
832
833 /* decode block and dequantize */
834 3919496 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 3919496 val = mjpeg_decode_dc(s, dc_index);
841
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3919496 times.
3919496 if (val == 0xfffff) {
842 av_log(s->avctx, AV_LOG_ERROR, "error dc\n");
843 return AVERROR_INVALIDDATA;
844 }
845 3919496 val = val * (unsigned)quant_matrix[0] + s->last_dc[component];
846 3919496 val = av_clip_int16(val);
847 3919496 s->last_dc[component] = val;
848 3919496 block[0] = val;
849 /* AC coefs */
850 3919496 i = 0;
851 3919496 {OPEN_READER(re, &s->gb);
852 do {
853 36247169 UPDATE_CACHE(re, &s->gb);
854
2/2
✓ Branch 1 taken 364781 times.
✓ Branch 2 taken 35882388 times.
36247169 GET_VLC(code, re, &s->gb, s->vlcs[1][ac_index].table, 9, 2);
855
856 36247169 i += ((unsigned)code) >> 4;
857 36247169 code &= 0xf;
858
2/2
✓ Branch 0 taken 32378415 times.
✓ Branch 1 taken 3868754 times.
36247169 if (code) {
859
2/2
✓ Branch 0 taken 485 times.
✓ Branch 1 taken 32377930 times.
32378415 if (code > MIN_CACHE_BITS - 16)
860 485 UPDATE_CACHE(re, &s->gb);
861
862 {
863 32378415 int cache = GET_CACHE(re, &s->gb);
864 32378415 int sign = (~cache) >> 31;
865 32378415 level = (NEG_USR32(sign ^ cache,code) ^ sign) - sign;
866 }
867
868 32378415 LAST_SKIP_BITS(re, &s->gb, code);
869
870
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32378415 times.
32378415 if (i > 63) {
871 av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i);
872 return AVERROR_INVALIDDATA;
873 }
874 32378415 j = s->permutated_scantable[i];
875 32378415 block[j] = level * quant_matrix[i];
876 }
877
2/2
✓ Branch 0 taken 32327673 times.
✓ Branch 1 taken 3919496 times.
36247169 } while (i < 63);
878 3919496 CLOSE_READER(re, &s->gb);}
879
880 3919496 return 0;
881 }
882
883 876 static int decode_dc_progressive(MJpegDecodeContext *s, int16_t *block,
884 int component, int dc_index,
885 uint16_t *quant_matrix, int Al)
886 {
887 unsigned val;
888 876 s->bdsp.clear_block(block);
889 876 val = mjpeg_decode_dc(s, dc_index);
890
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 876 times.
876 if (val == 0xfffff) {
891 av_log(s->avctx, AV_LOG_ERROR, "error dc\n");
892 return AVERROR_INVALIDDATA;
893 }
894 876 val = (val * (quant_matrix[0] << Al)) + s->last_dc[component];
895 876 s->last_dc[component] = val;
896 876 block[0] = val;
897 876 return 0;
898 }
899
900 /* decode block and dequantize - progressive JPEG version */
901 1336 static int decode_block_progressive(MJpegDecodeContext *s, int16_t *block,
902 uint8_t *last_nnz, int ac_index,
903 uint16_t *quant_matrix,
904 int ss, int se, int Al, int *EOBRUN)
905 {
906 int code, i, j, val, run;
907 unsigned level;
908
909
2/2
✓ Branch 0 taken 340 times.
✓ Branch 1 taken 996 times.
1336 if (*EOBRUN) {
910 340 (*EOBRUN)--;
911 340 return 0;
912 }
913
914 {
915 996 OPEN_READER(re, &s->gb);
916 996 for (i = ss; ; i++) {
917 5910 UPDATE_CACHE(re, &s->gb);
918
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);
919
920 6906 run = ((unsigned) code) >> 4;
921 6906 code &= 0xF;
922
2/2
✓ Branch 0 taken 6037 times.
✓ Branch 1 taken 869 times.
6906 if (code) {
923 6037 i += run;
924
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6037 times.
6037 if (code > MIN_CACHE_BITS - 16)
925 UPDATE_CACHE(re, &s->gb);
926
927 {
928 6037 int cache = GET_CACHE(re, &s->gb);
929 6037 int sign = (~cache) >> 31;
930 6037 level = (NEG_USR32(sign ^ cache,code) ^ sign) - sign;
931 }
932
933 6037 LAST_SKIP_BITS(re, &s->gb, code);
934
935
2/2
✓ Branch 0 taken 139 times.
✓ Branch 1 taken 5898 times.
6037 if (i >= se) {
936
1/2
✓ Branch 0 taken 139 times.
✗ Branch 1 not taken.
139 if (i == se) {
937 139 j = s->permutated_scantable[se];
938 139 block[j] = level * (quant_matrix[se] << Al);
939 139 break;
940 }
941 av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i);
942 return AVERROR_INVALIDDATA;
943 }
944 5898 j = s->permutated_scantable[i];
945 5898 block[j] = level * (quant_matrix[i] << Al);
946 } else {
947
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 857 times.
869 if (run == 0xF) {// ZRL - skip 15 coefficients
948 12 i += 15;
949
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (i >= se) {
950 av_log(s->avctx, AV_LOG_ERROR, "ZRL overflow: %d\n", i);
951 return AVERROR_INVALIDDATA;
952 }
953 } else {
954 857 val = (1 << run);
955
2/2
✓ Branch 0 taken 149 times.
✓ Branch 1 taken 708 times.
857 if (run) {
956 149 UPDATE_CACHE(re, &s->gb);
957 149 val += NEG_USR32(GET_CACHE(re, &s->gb), run);
958 149 LAST_SKIP_BITS(re, &s->gb, run);
959 }
960 857 *EOBRUN = val - 1;
961 857 break;
962 }
963 }
964 }
965 996 CLOSE_READER(re, &s->gb);
966 }
967
968
1/2
✓ Branch 0 taken 996 times.
✗ Branch 1 not taken.
996 if (i > *last_nnz)
969 996 *last_nnz = i;
970
971 996 return 0;
972 }
973
974 #define REFINE_BIT(j) { \
975 UPDATE_CACHE(re, &s->gb); \
976 sign = block[j] >> 15; \
977 block[j] += SHOW_UBITS(re, &s->gb, 1) * \
978 ((quant_matrix[i] ^ sign) - sign) << Al; \
979 LAST_SKIP_BITS(re, &s->gb, 1); \
980 }
981
982 #define ZERO_RUN \
983 for (; ; i++) { \
984 if (i > last) { \
985 i += run; \
986 if (i > se) { \
987 av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i); \
988 return -1; \
989 } \
990 break; \
991 } \
992 j = s->permutated_scantable[i]; \
993 if (block[j]) \
994 REFINE_BIT(j) \
995 else if (run-- == 0) \
996 break; \
997 }
998
999 /* decode block and dequantize - progressive JPEG refinement pass */
1000 1080 static int decode_block_refinement(MJpegDecodeContext *s, int16_t *block,
1001 uint8_t *last_nnz,
1002 int ac_index, uint16_t *quant_matrix,
1003 int ss, int se, int Al, int *EOBRUN)
1004 {
1005 1080 int code, i = ss, j, sign, val, run;
1006 1080 int last = FFMIN(se, *last_nnz);
1007
1008 1080 OPEN_READER(re, &s->gb);
1009
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 960 times.
1080 if (*EOBRUN) {
1010 120 (*EOBRUN)--;
1011 } else {
1012 9339 for (; ; i++) {
1013 9339 UPDATE_CACHE(re, &s->gb);
1014
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);
1015
1016
2/2
✓ Branch 0 taken 9342 times.
✓ Branch 1 taken 957 times.
10299 if (code & 0xF) {
1017 9342 run = ((unsigned) code) >> 4;
1018 9342 UPDATE_CACHE(re, &s->gb);
1019 9342 val = SHOW_UBITS(re, &s->gb, 1);
1020 9342 LAST_SKIP_BITS(re, &s->gb, 1);
1021
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;
1022 9342 j = s->permutated_scantable[i];
1023 9342 val--;
1024 9342 block[j] = ((quant_matrix[i] << Al) ^ val) - val;
1025
2/2
✓ Branch 0 taken 63 times.
✓ Branch 1 taken 9279 times.
9342 if (i == se) {
1026
1/2
✓ Branch 0 taken 63 times.
✗ Branch 1 not taken.
63 if (i > *last_nnz)
1027 63 *last_nnz = i;
1028 63 CLOSE_READER(re, &s->gb);
1029 63 return 0;
1030 }
1031 } else {
1032 957 run = ((unsigned) code) >> 4;
1033
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 897 times.
957 if (run == 0xF) {
1034
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;
1035 } else {
1036 897 val = run;
1037 897 run = (1 << run);
1038
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 874 times.
897 if (val) {
1039 23 UPDATE_CACHE(re, &s->gb);
1040 23 run += SHOW_UBITS(re, &s->gb, val);
1041 23 LAST_SKIP_BITS(re, &s->gb, val);
1042 }
1043 897 *EOBRUN = run - 1;
1044 897 break;
1045 }
1046 }
1047 }
1048
1049
2/2
✓ Branch 0 taken 804 times.
✓ Branch 1 taken 93 times.
897 if (i > *last_nnz)
1050 804 *last_nnz = i;
1051 }
1052
1053
2/2
✓ Branch 0 taken 879 times.
✓ Branch 1 taken 1017 times.
1896 for (; i <= last; i++) {
1054 879 j = s->permutated_scantable[i];
1055
2/2
✓ Branch 0 taken 188 times.
✓ Branch 1 taken 691 times.
879 if (block[j])
1056 188 REFINE_BIT(j)
1057 }
1058 1017 CLOSE_READER(re, &s->gb);
1059
1060 1017 return 0;
1061 }
1062 #undef REFINE_BIT
1063 #undef ZERO_RUN
1064
1065 781008 static int handle_rstn(MJpegDecodeContext *s, int nb_components)
1066 {
1067 int i;
1068 781008 int reset = 0;
1069
1070
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 781008 times.
781008 if (s->restart_interval) {
1071 s->restart_count--;
1072 if(s->restart_count == 0 && s->avctx->codec_id == AV_CODEC_ID_THP){
1073 align_get_bits(&s->gb);
1074 for (i = 0; i < nb_components; i++) /* reset dc */
1075 s->last_dc[i] = (4 << s->bits);
1076 }
1077
1078 i = 8 + ((-get_bits_count(&s->gb)) & 7);
1079 /* skip RSTn */
1080 if (s->restart_count == 0) {
1081 if( show_bits(&s->gb, i) == (1 << i) - 1
1082 || show_bits(&s->gb, i) == 0xFF) {
1083 int pos = get_bits_count(&s->gb);
1084 align_get_bits(&s->gb);
1085 while (get_bits_left(&s->gb) >= 8 && show_bits(&s->gb, 8) == 0xFF)
1086 skip_bits(&s->gb, 8);
1087 if (get_bits_left(&s->gb) >= 8 && (get_bits(&s->gb, 8) & 0xF8) == 0xD0) {
1088 for (i = 0; i < nb_components; i++) /* reset dc */
1089 s->last_dc[i] = (4 << s->bits);
1090 reset = 1;
1091 } else
1092 skip_bits_long(&s->gb, pos - get_bits_count(&s->gb));
1093 }
1094 }
1095 }
1096 781008 return reset;
1097 }
1098
1099 /* Handles 1 to 4 components */
1100 static int ljpeg_decode_rgb_scan(MJpegDecodeContext *s, int nb_components, int predictor, int point_transform)
1101 {
1102 int i, mb_x, mb_y;
1103 unsigned width;
1104 uint16_t (*buffer)[4];
1105 int left[4], top[4], topleft[4];
1106 const int linesize = s->linesize[0];
1107 const int mask = ((1 << s->bits) - 1) << point_transform;
1108 int resync_mb_y = 0;
1109 int resync_mb_x = 0;
1110 int vpred[6];
1111
1112 if (!s->bayer && s->nb_components < 3)
1113 return AVERROR_INVALIDDATA;
1114 if (s->bayer && s->nb_components > 2)
1115 return AVERROR_INVALIDDATA;
1116 if (s->nb_components <= 0 || s->nb_components > 4)
1117 return AVERROR_INVALIDDATA;
1118 if (s->v_max != 1 || s->h_max != 1 || !s->lossless)
1119 return AVERROR_INVALIDDATA;
1120 if (s->bayer) {
1121 if (s->rct || s->pegasus_rct)
1122 return AVERROR_INVALIDDATA;
1123 }
1124
1125
1126 s->restart_count = s->restart_interval;
1127
1128 if (s->restart_interval == 0)
1129 s->restart_interval = INT_MAX;
1130
1131 if (s->bayer)
1132 width = s->mb_width / nb_components; /* Interleaved, width stored is the total so need to divide */
1133 else
1134 width = s->mb_width;
1135
1136 av_fast_malloc(&s->ljpeg_buffer, &s->ljpeg_buffer_size, width * 4 * sizeof(s->ljpeg_buffer[0][0]));
1137 if (!s->ljpeg_buffer)
1138 return AVERROR(ENOMEM);
1139
1140 buffer = s->ljpeg_buffer;
1141
1142 for (i = 0; i < 4; i++)
1143 buffer[0][i] = 1 << (s->bits - 1);
1144
1145 for (mb_y = 0; mb_y < s->mb_height; mb_y++) {
1146 uint8_t *ptr = s->picture_ptr->data[0] + (linesize * mb_y);
1147
1148 if (s->interlaced && s->bottom_field)
1149 ptr += linesize >> 1;
1150
1151 for (i = 0; i < 4; i++)
1152 top[i] = left[i] = topleft[i] = buffer[0][i];
1153
1154 if ((mb_y * s->width) % s->restart_interval == 0) {
1155 for (i = 0; i < 6; i++)
1156 vpred[i] = 1 << (s->bits-1);
1157 }
1158
1159 for (mb_x = 0; mb_x < width; mb_x++) {
1160 int modified_predictor = predictor;
1161
1162 if (get_bits_left(&s->gb) < 1) {
1163 av_log(s->avctx, AV_LOG_ERROR, "bitstream end in rgb_scan\n");
1164 return AVERROR_INVALIDDATA;
1165 }
1166
1167 if (s->restart_interval && !s->restart_count){
1168 s->restart_count = s->restart_interval;
1169 resync_mb_x = mb_x;
1170 resync_mb_y = mb_y;
1171 for(i=0; i<4; i++)
1172 top[i] = left[i]= topleft[i]= 1 << (s->bits - 1);
1173 }
1174 if (mb_y == resync_mb_y || mb_y == resync_mb_y+1 && mb_x < resync_mb_x || !mb_x)
1175 modified_predictor = 1;
1176
1177 for (i=0;i<nb_components;i++) {
1178 int pred, dc;
1179
1180 topleft[i] = top[i];
1181 top[i] = buffer[mb_x][i];
1182
1183 dc = mjpeg_decode_dc(s, s->dc_index[i]);
1184 if(dc == 0xFFFFF)
1185 return -1;
1186
1187 if (!s->bayer || mb_x) {
1188 pred = left[i];
1189 } else { /* This path runs only for the first line in bayer images */
1190 vpred[i] += dc;
1191 pred = vpred[i] - dc;
1192 }
1193
1194 PREDICT(pred, topleft[i], top[i], pred, modified_predictor);
1195
1196 left[i] = buffer[mb_x][i] =
1197 mask & (pred + (unsigned)(dc * (1 << point_transform)));
1198 }
1199
1200 if (s->restart_interval && !--s->restart_count) {
1201 align_get_bits(&s->gb);
1202 skip_bits(&s->gb, 16); /* skip RSTn */
1203 }
1204 }
1205 if (s->rct && s->nb_components == 4) {
1206 for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
1207 ptr[4*mb_x + 2] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2] - 0x200) >> 2);
1208 ptr[4*mb_x + 1] = buffer[mb_x][1] + ptr[4*mb_x + 2];
1209 ptr[4*mb_x + 3] = buffer[mb_x][2] + ptr[4*mb_x + 2];
1210 ptr[4*mb_x + 0] = buffer[mb_x][3];
1211 }
1212 } else if (s->nb_components == 4) {
1213 for(i=0; i<nb_components; i++) {
1214 int c= s->comp_index[i];
1215 if (s->bits <= 8) {
1216 for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
1217 ptr[4*mb_x+3-c] = buffer[mb_x][i];
1218 }
1219 } else if(s->bits == 9) {
1220 return AVERROR_PATCHWELCOME;
1221 } else {
1222 for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
1223 ((uint16_t*)ptr)[4*mb_x+c] = buffer[mb_x][i];
1224 }
1225 }
1226 }
1227 } else if (s->rct) {
1228 for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
1229 ptr[3*mb_x + 1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2] - 0x200) >> 2);
1230 ptr[3*mb_x + 0] = buffer[mb_x][1] + ptr[3*mb_x + 1];
1231 ptr[3*mb_x + 2] = buffer[mb_x][2] + ptr[3*mb_x + 1];
1232 }
1233 } else if (s->pegasus_rct) {
1234 for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
1235 ptr[3*mb_x + 1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2]) >> 2);
1236 ptr[3*mb_x + 0] = buffer[mb_x][1] + ptr[3*mb_x + 1];
1237 ptr[3*mb_x + 2] = buffer[mb_x][2] + ptr[3*mb_x + 1];
1238 }
1239 } else if (s->bayer) {
1240 if (s->bits <= 8)
1241 return AVERROR_PATCHWELCOME;
1242 if (nb_components == 1) {
1243 /* Leave decoding to the TIFF/DNG decoder (see comment in ff_mjpeg_decode_sof) */
1244 for (mb_x = 0; mb_x < width; mb_x++)
1245 ((uint16_t*)ptr)[mb_x] = buffer[mb_x][0];
1246 } else if (nb_components == 2) {
1247 for (mb_x = 0; mb_x < width; mb_x++) {
1248 ((uint16_t*)ptr)[2*mb_x + 0] = buffer[mb_x][0];
1249 ((uint16_t*)ptr)[2*mb_x + 1] = buffer[mb_x][1];
1250 }
1251 }
1252 } else {
1253 for(i=0; i<nb_components; i++) {
1254 int c= s->comp_index[i];
1255 if (s->bits <= 8) {
1256 for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
1257 ptr[3*mb_x+2-c] = buffer[mb_x][i];
1258 }
1259 } else if(s->bits == 9) {
1260 return AVERROR_PATCHWELCOME;
1261 } else {
1262 for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
1263 ((uint16_t*)ptr)[3*mb_x+2-c] = buffer[mb_x][i];
1264 }
1265 }
1266 }
1267 }
1268 }
1269 return 0;
1270 }
1271
1272 200 static int ljpeg_decode_yuv_scan(MJpegDecodeContext *s, int predictor,
1273 int point_transform, int nb_components)
1274 {
1275 int i, mb_x, mb_y, mask;
1276 200 int bits= (s->bits+7)&~7;
1277 200 int resync_mb_y = 0;
1278 200 int resync_mb_x = 0;
1279
1280 200 point_transform += bits - s->bits;
1281 200 mask = ((1 << s->bits) - 1) << point_transform;
1282
1283
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);
1284
1285
2/2
✓ Branch 0 taken 22450 times.
✓ Branch 1 taken 200 times.
22650 for (mb_y = 0; mb_y < s->mb_height; mb_y++) {
1286
2/2
✓ Branch 0 taken 3816050 times.
✓ Branch 1 taken 22450 times.
3838500 for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
1287
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3816050 times.
3816050 if (get_bits_left(&s->gb) < 1) {
1288 av_log(s->avctx, AV_LOG_ERROR, "bitstream end in yuv_scan\n");
1289 return AVERROR_INVALIDDATA;
1290 }
1291
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){
1292 s->restart_count = s->restart_interval;
1293 resync_mb_x = mb_x;
1294 resync_mb_y = mb_y;
1295 }
1296
1297
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){
1298
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;
1299
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;
1300
2/2
✓ Branch 0 taken 148500 times.
✓ Branch 1 taken 49500 times.
198000 for (i = 0; i < nb_components; i++) {
1301 uint8_t *ptr;
1302 uint16_t *ptr16;
1303 int n, h, v, x, y, c, j, linesize;
1304 148500 n = s->nb_blocks[i];
1305 148500 c = s->comp_index[i];
1306 148500 h = s->h_scount[i];
1307 148500 v = s->v_scount[i];
1308 148500 x = 0;
1309 148500 y = 0;
1310 148500 linesize= s->linesize[c];
1311
1312
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 148500 times.
148500 if(bits>8) linesize /= 2;
1313
1314
2/2
✓ Branch 0 taken 297000 times.
✓ Branch 1 taken 148500 times.
445500 for(j=0; j<n; j++) {
1315 int pred, dc;
1316
1317 297000 dc = mjpeg_decode_dc(s, s->dc_index[i]);
1318
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 297000 times.
297000 if(dc == 0xFFFFF)
1319 return -1;
1320
1/2
✓ Branch 0 taken 297000 times.
✗ Branch 1 not taken.
297000 if ( h * mb_x + x >= s->width
1321
1/2
✓ Branch 0 taken 297000 times.
✗ Branch 1 not taken.
297000 || v * mb_y + y >= s->height) {
1322 // Nothing to do
1323
1/2
✓ Branch 0 taken 297000 times.
✗ Branch 1 not taken.
297000 } else if (bits<=8) {
1324 297000 ptr = s->picture_ptr->data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
1325
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){
1326
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){
1327 600 pred= 1 << (bits - 1);
1328 }else{
1329 108400 pred= ptr[-1];
1330 }
1331 }else{
1332
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){
1333 89200 pred= ptr[-linesize];
1334 }else{
1335
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);
1336 }
1337 }
1338
1339
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)
1340 ptr += linesize >> 1;
1341 297000 pred &= mask;
1342 297000 *ptr= pred + ((unsigned)dc << point_transform);
1343 }else{
1344 ptr16 = (uint16_t*)(s->picture_ptr->data[c] + 2*(linesize * (v * mb_y + y)) + 2*(h * mb_x + x)); //FIXME optimize this crap
1345 if(y==0 && toprow){
1346 if(x==0 && leftcol){
1347 pred= 1 << (bits - 1);
1348 }else{
1349 pred= ptr16[-1];
1350 }
1351 }else{
1352 if(x==0 && leftcol){
1353 pred= ptr16[-linesize];
1354 }else{
1355 PREDICT(pred, ptr16[-linesize-1], ptr16[-linesize], ptr16[-1], predictor);
1356 }
1357 }
1358
1359 if (s->interlaced && s->bottom_field)
1360 ptr16 += linesize >> 1;
1361 pred &= mask;
1362 *ptr16= pred + ((unsigned)dc << point_transform);
1363 }
1364
2/2
✓ Branch 0 taken 198000 times.
✓ Branch 1 taken 99000 times.
297000 if (++x == h) {
1365 198000 x = 0;
1366 198000 y++;
1367 }
1368 }
1369 }
1370 } else {
1371
2/2
✓ Branch 0 taken 11299650 times.
✓ Branch 1 taken 3766550 times.
15066200 for (i = 0; i < nb_components; i++) {
1372 uint8_t *ptr;
1373 uint16_t *ptr16;
1374 int n, h, v, x, y, c, j, linesize, dc;
1375 11299650 n = s->nb_blocks[i];
1376 11299650 c = s->comp_index[i];
1377 11299650 h = s->h_scount[i];
1378 11299650 v = s->v_scount[i];
1379 11299650 x = 0;
1380 11299650 y = 0;
1381 11299650 linesize = s->linesize[c];
1382
1383
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11299650 times.
11299650 if(bits>8) linesize /= 2;
1384
1385
2/2
✓ Branch 0 taken 22599300 times.
✓ Branch 1 taken 11299650 times.
33898950 for (j = 0; j < n; j++) {
1386 int pred;
1387
1388 22599300 dc = mjpeg_decode_dc(s, s->dc_index[i]);
1389
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22599300 times.
22599300 if(dc == 0xFFFFF)
1390 return -1;
1391
1/2
✓ Branch 0 taken 22599300 times.
✗ Branch 1 not taken.
22599300 if ( h * mb_x + x >= s->width
1392
1/2
✓ Branch 0 taken 22599300 times.
✗ Branch 1 not taken.
22599300 || v * mb_y + y >= s->height) {
1393 // Nothing to do
1394
1/2
✓ Branch 0 taken 22599300 times.
✗ Branch 1 not taken.
22599300 } else if (bits<=8) {
1395 22599300 ptr = s->picture_ptr->data[c] +
1396 22599300 (linesize * (v * mb_y + y)) +
1397 22599300 (h * mb_x + x); //FIXME optimize this crap
1398
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);
1399
1400 22599300 pred &= mask;
1401 22599300 *ptr = pred + ((unsigned)dc << point_transform);
1402 }else{
1403 ptr16 = (uint16_t*)(s->picture_ptr->data[c] + 2*(linesize * (v * mb_y + y)) + 2*(h * mb_x + x)); //FIXME optimize this crap
1404 PREDICT(pred, ptr16[-linesize-1], ptr16[-linesize], ptr16[-1], predictor);
1405
1406 pred &= mask;
1407 *ptr16= pred + ((unsigned)dc << point_transform);
1408 }
1409
1410
2/2
✓ Branch 0 taken 15066200 times.
✓ Branch 1 taken 7533100 times.
22599300 if (++x == h) {
1411 15066200 x = 0;
1412 15066200 y++;
1413 }
1414 }
1415 }
1416 }
1417
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) {
1418 align_get_bits(&s->gb);
1419 skip_bits(&s->gb, 16); /* skip RSTn */
1420 }
1421 }
1422 }
1423 200 return 0;
1424 }
1425
1426 786684 static av_always_inline void mjpeg_copy_block(MJpegDecodeContext *s,
1427 uint8_t *dst, const uint8_t *src,
1428 int linesize, int lowres)
1429 {
1430
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) {
1431 786684 case 0: s->hdsp.put_pixels_tab[1][0](dst, src, linesize, 8);
1432 786684 break;
1433 case 1: copy_block4(dst, src, linesize, linesize, 4);
1434 break;
1435 case 2: copy_block2(dst, src, linesize, linesize, 2);
1436 break;
1437 case 3: *dst = *src;
1438 break;
1439 }
1440 786684 }
1441
1442 11750 static void shift_output(MJpegDecodeContext *s, uint8_t *ptr, int linesize)
1443 {
1444 int block_x, block_y;
1445 11750 int size = 8 >> s->avctx->lowres;
1446
1/2
✓ Branch 0 taken 11750 times.
✗ Branch 1 not taken.
11750 if (s->bits > 8) {
1447
2/2
✓ Branch 0 taken 94000 times.
✓ Branch 1 taken 11750 times.
105750 for (block_y=0; block_y<size; block_y++)
1448
2/2
✓ Branch 0 taken 752000 times.
✓ Branch 1 taken 94000 times.
846000 for (block_x=0; block_x<size; block_x++)
1449 752000 *(uint16_t*)(ptr + 2*block_x + block_y*linesize) <<= 16 - s->bits;
1450 } else {
1451 for (block_y=0; block_y<size; block_y++)
1452 for (block_x=0; block_x<size; block_x++)
1453 *(ptr + block_x + block_y*linesize) <<= 8 - s->bits;
1454 }
1455 11750 }
1456
1457 2144 static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int Ah,
1458 int Al, const uint8_t *mb_bitmask,
1459 int mb_bitmask_size,
1460 const AVFrame *reference)
1461 {
1462 int i, mb_x, mb_y, chroma_h_shift, chroma_v_shift, chroma_width, chroma_height;
1463 uint8_t *data[MAX_COMPONENTS];
1464 const uint8_t *reference_data[MAX_COMPONENTS];
1465 int linesize[MAX_COMPONENTS];
1466 2144 GetBitContext mb_bitmask_gb = {0}; // initialize to silence gcc warning
1467
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2143 times.
2144 int bytes_per_pixel = 1 + (s->bits > 8);
1468
1469
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 2113 times.
2144 if (mb_bitmask) {
1470
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
31 if (mb_bitmask_size != (s->mb_width * s->mb_height + 7)>>3) {
1471 av_log(s->avctx, AV_LOG_ERROR, "mb_bitmask_size mismatches\n");
1472 return AVERROR_INVALIDDATA;
1473 }
1474 31 init_get_bits(&mb_bitmask_gb, mb_bitmask, s->mb_width * s->mb_height);
1475 }
1476
1477 2144 s->restart_count = 0;
1478
1479 2144 av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt, &chroma_h_shift,
1480 &chroma_v_shift);
1481 2144 chroma_width = AV_CEIL_RSHIFT(s->width, chroma_h_shift);
1482 2144 chroma_height = AV_CEIL_RSHIFT(s->height, chroma_v_shift);
1483
1484
2/2
✓ Branch 0 taken 6424 times.
✓ Branch 1 taken 2144 times.
8568 for (i = 0; i < nb_components; i++) {
1485 6424 int c = s->comp_index[i];
1486 6424 data[c] = s->picture_ptr->data[c];
1487
2/2
✓ Branch 0 taken 93 times.
✓ Branch 1 taken 6331 times.
6424 reference_data[c] = reference ? reference->data[c] : NULL;
1488 6424 linesize[c] = s->linesize[c];
1489 6424 s->coefs_finished[c] |= 1;
1490 }
1491
1492
2/2
✓ Branch 0 taken 28476 times.
✓ Branch 1 taken 2144 times.
30620 for (mb_y = 0; mb_y < s->mb_height; mb_y++) {
1493
2/2
✓ Branch 0 taken 778592 times.
✓ Branch 1 taken 28476 times.
807068 for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
1494
4/4
✓ Branch 0 taken 148800 times.
✓ Branch 1 taken 629792 times.
✓ Branch 3 taken 131114 times.
✓ Branch 4 taken 17686 times.
778592 const int copy_mb = mb_bitmask && !get_bits1(&mb_bitmask_gb);
1495
1496
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 778592 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
778592 if (s->restart_interval && !s->restart_count)
1497 s->restart_count = s->restart_interval;
1498
1499
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 778592 times.
778592 if (get_bits_left(&s->gb) < 0) {
1500 av_log(s->avctx, AV_LOG_ERROR, "overread %d\n",
1501 -get_bits_left(&s->gb));
1502 return AVERROR_INVALIDDATA;
1503 }
1504
2/2
✓ Branch 0 taken 2312060 times.
✓ Branch 1 taken 778592 times.
3090652 for (i = 0; i < nb_components; i++) {
1505 uint8_t *ptr;
1506 int n, h, v, x, y, c, j;
1507 int block_offset;
1508 2312060 n = s->nb_blocks[i];
1509 2312060 c = s->comp_index[i];
1510 2312060 h = s->h_scount[i];
1511 2312060 v = s->v_scount[i];
1512 2312060 x = 0;
1513 2312060 y = 0;
1514
2/2
✓ Branch 0 taken 4707056 times.
✓ Branch 1 taken 2312060 times.
7019116 for (j = 0; j < n; j++) {
1515 4707056 block_offset = (((linesize[c] * (v * mb_y + y) * 8) +
1516 4707056 (h * mb_x + x) * 8 * bytes_per_pixel) >> s->avctx->lowres);
1517
1518
4/4
✓ Branch 0 taken 21440 times.
✓ Branch 1 taken 4685616 times.
✓ Branch 2 taken 10720 times.
✓ Branch 3 taken 10720 times.
4707056 if (s->interlaced && s->bottom_field)
1519 10720 block_offset += linesize[c] >> 1;
1520
6/6
✓ Branch 0 taken 3760506 times.
✓ Branch 1 taken 946550 times.
✓ Branch 2 taken 2814056 times.
✓ Branch 3 taken 946450 times.
✓ Branch 4 taken 4704856 times.
✓ Branch 5 taken 2200 times.
4707056 if ( 8*(h * mb_x + x) < ((c == 1) || (c == 2) ? chroma_width : s->width)
1521
6/6
✓ Branch 0 taken 3758314 times.
✓ Branch 1 taken 946542 times.
✓ Branch 2 taken 2811864 times.
✓ Branch 3 taken 946450 times.
✓ Branch 4 taken 4698747 times.
✓ Branch 5 taken 6109 times.
4704856 && 8*(v * mb_y + y) < ((c == 1) || (c == 2) ? chroma_height : s->height)) {
1522 4698747 ptr = data[c] + block_offset;
1523 } else
1524 8309 ptr = NULL;
1525
2/2
✓ Branch 0 taken 4706180 times.
✓ Branch 1 taken 876 times.
4707056 if (!s->progressive) {
1526
2/2
✓ Branch 0 taken 786684 times.
✓ Branch 1 taken 3919496 times.
4706180 if (copy_mb) {
1527
1/2
✓ Branch 0 taken 786684 times.
✗ Branch 1 not taken.
786684 if (ptr)
1528 786684 mjpeg_copy_block(s, ptr, reference_data[c] + block_offset,
1529 786684 linesize[c], s->avctx->lowres);
1530
1531 } else {
1532 3919496 s->bdsp.clear_block(s->block);
1533
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3919496 times.
3919496 if (decode_block(s, s->block, i,
1534 s->dc_index[i], s->ac_index[i],
1535 3919496 s->quant_matrixes[s->quant_sindex[i]]) < 0) {
1536 av_log(s->avctx, AV_LOG_ERROR,
1537 "error y=%d x=%d\n", mb_y, mb_x);
1538 return AVERROR_INVALIDDATA;
1539 }
1540
3/4
✓ Branch 0 taken 3911203 times.
✓ Branch 1 taken 8293 times.
✓ Branch 2 taken 3911203 times.
✗ Branch 3 not taken.
3919496 if (ptr && linesize[c]) {
1541 3911203 s->idsp.idct_put(ptr, linesize[c], s->block);
1542
2/2
✓ Branch 0 taken 11750 times.
✓ Branch 1 taken 3899453 times.
3911203 if (s->bits & 7)
1543 11750 shift_output(s, ptr, linesize[c]);
1544 }
1545 }
1546 } else {
1547 876 int block_idx = s->block_stride[c] * (v * mb_y + y) +
1548 876 (h * mb_x + x);
1549 876 int16_t *block = s->blocks[c][block_idx];
1550
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 876 times.
876 if (Ah)
1551 block[0] += get_bits1(&s->gb) *
1552 s->quant_matrixes[s->quant_sindex[i]][0] << Al;
1553
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 876 times.
876 else if (decode_dc_progressive(s, block, i, s->dc_index[i],
1554 876 s->quant_matrixes[s->quant_sindex[i]],
1555 Al) < 0) {
1556 av_log(s->avctx, AV_LOG_ERROR,
1557 "error y=%d x=%d\n", mb_y, mb_x);
1558 return AVERROR_INVALIDDATA;
1559 }
1560 }
1561 ff_dlog(s->avctx, "mb: %d %d processed\n", mb_y, mb_x);
1562 ff_dlog(s->avctx, "%d %d %d %d %d %d %d %d \n",
1563 mb_x, mb_y, x, y, c, s->bottom_field,
1564 (v * mb_y + y) * 8, (h * mb_x + x) * 8);
1565
2/2
✓ Branch 0 taken 3425613 times.
✓ Branch 1 taken 1281443 times.
4707056 if (++x == h) {
1566 3425613 x = 0;
1567 3425613 y++;
1568 }
1569 }
1570 }
1571
1572 778592 handle_rstn(s, nb_components);
1573 }
1574 }
1575 2144 return 0;
1576 }
1577
1578 59 static int mjpeg_decode_scan_progressive_ac(MJpegDecodeContext *s, int ss,
1579 int se, int Ah, int Al)
1580 {
1581 int mb_x, mb_y;
1582 59 int EOBRUN = 0;
1583 59 int c = s->comp_index[0];
1584 59 uint16_t *quant_matrix = s->quant_matrixes[s->quant_sindex[0]];
1585
1586
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);
1587
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) {
1588 av_log(s->avctx, AV_LOG_ERROR, "SS/SE %d/%d is invalid\n", ss, se);
1589 return AVERROR_INVALIDDATA;
1590 }
1591
1592 // s->coefs_finished is a bitmask for coefficients coded
1593 // ss and se are parameters telling start and end coefficients
1594 59 s->coefs_finished[c] |= (2ULL << se) - (1ULL << ss);
1595
1596 59 s->restart_count = 0;
1597
1598
2/2
✓ Branch 0 taken 412 times.
✓ Branch 1 taken 59 times.
471 for (mb_y = 0; mb_y < s->mb_height; mb_y++) {
1599 412 int block_idx = mb_y * s->block_stride[c];
1600 412 int16_t (*block)[64] = &s->blocks[c][block_idx];
1601 412 uint8_t *last_nnz = &s->last_nnz[c][block_idx];
1602
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 412 times.
412 if (get_bits_left(&s->gb) <= 0) {
1603 av_log(s->avctx, AV_LOG_ERROR, "bitstream truncated in mjpeg_decode_scan_progressive_ac\n");
1604 return AVERROR_INVALIDDATA;
1605 }
1606
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++) {
1607 int ret;
1608
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)
1609 s->restart_count = s->restart_interval;
1610
1611
2/2
✓ Branch 0 taken 1080 times.
✓ Branch 1 taken 1336 times.
2416 if (Ah)
1612 1080 ret = decode_block_refinement(s, *block, last_nnz, s->ac_index[0],
1613 quant_matrix, ss, se, Al, &EOBRUN);
1614 else
1615 1336 ret = decode_block_progressive(s, *block, last_nnz, s->ac_index[0],
1616 quant_matrix, ss, se, Al, &EOBRUN);
1617
1618
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)
1619 ret = AVERROR_INVALIDDATA;
1620
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2416 times.
2416 if (ret < 0) {
1621 av_log(s->avctx, AV_LOG_ERROR,
1622 "error y=%d x=%d\n", mb_y, mb_x);
1623 return AVERROR_INVALIDDATA;
1624 }
1625
1626
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2416 times.
2416 if (handle_rstn(s, 0))
1627 EOBRUN = 0;
1628 }
1629 }
1630 59 return 0;
1631 }
1632
1633 7 static void mjpeg_idct_scan_progressive_ac(MJpegDecodeContext *s)
1634 {
1635 int mb_x, mb_y;
1636 int c;
1637
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 const int bytes_per_pixel = 1 + (s->bits > 8);
1638
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 const int block_size = s->lossless ? 1 : 8;
1639
1640
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 7 times.
28 for (c = 0; c < s->nb_components; c++) {
1641 21 uint8_t *data = s->picture_ptr->data[c];
1642 21 int linesize = s->linesize[c];
1643 21 int h = s->h_max / s->h_count[c];
1644 21 int v = s->v_max / s->v_count[c];
1645 21 int mb_width = (s->width + h * block_size - 1) / (h * block_size);
1646 21 int mb_height = (s->height + v * block_size - 1) / (v * block_size);
1647
1648
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 if (~s->coefs_finished[c])
1649 av_log(s->avctx, AV_LOG_WARNING, "component %d is incomplete\n", c);
1650
1651
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)
1652 data += linesize >> 1;
1653
1654
2/2
✓ Branch 0 taken 153 times.
✓ Branch 1 taken 21 times.
174 for (mb_y = 0; mb_y < mb_height; mb_y++) {
1655 153 uint8_t *ptr = data + (mb_y * linesize * 8 >> s->avctx->lowres);
1656 153 int block_idx = mb_y * s->block_stride[c];
1657 153 int16_t (*block)[64] = &s->blocks[c][block_idx];
1658
2/2
✓ Branch 0 taken 860 times.
✓ Branch 1 taken 153 times.
1013 for (mb_x = 0; mb_x < mb_width; mb_x++, block++) {
1659 860 s->idsp.idct_put(ptr, linesize, *block);
1660
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 860 times.
860 if (s->bits & 7)
1661 shift_output(s, ptr, linesize);
1662 860 ptr += bytes_per_pixel*8 >> s->avctx->lowres;
1663 }
1664 }
1665 }
1666 7 }
1667
1668 2616 int ff_mjpeg_decode_sos(MJpegDecodeContext *s, const uint8_t *mb_bitmask,
1669 int mb_bitmask_size, const AVFrame *reference)
1670 {
1671 int len, nb_components, i, h, v, predictor, point_transform;
1672 int index, id, ret;
1673
2/2
✓ Branch 0 taken 413 times.
✓ Branch 1 taken 2203 times.
2616 const int block_size = s->lossless ? 1 : 8;
1674 int ilv, prev_shift;
1675
1676
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2616 times.
2616 if (!s->got_picture) {
1677 av_log(s->avctx, AV_LOG_WARNING,
1678 "Can not process SOS before SOF, skipping\n");
1679 return -1;
1680 }
1681
1682
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 2585 times.
2616 if (reference) {
1683
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 if (reference->width != s->picture_ptr->width ||
1684
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 reference->height != s->picture_ptr->height ||
1685
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
31 reference->format != s->picture_ptr->format) {
1686 av_log(s->avctx, AV_LOG_ERROR, "Reference mismatching\n");
1687 return AVERROR_INVALIDDATA;
1688 }
1689 }
1690
1691 /* XXX: verify len field validity */
1692 2616 len = get_bits(&s->gb, 16);
1693 2616 nb_components = get_bits(&s->gb, 8);
1694
2/4
✓ Branch 0 taken 2616 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2616 times.
2616 if (nb_components == 0 || nb_components > MAX_COMPONENTS) {
1695 avpriv_report_missing_feature(s->avctx,
1696 "decode_sos: nb_components (%d)",
1697 nb_components);
1698 return AVERROR_PATCHWELCOME;
1699 }
1700
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2616 times.
2616 if (len != 6 + 2 * nb_components) {
1701 av_log(s->avctx, AV_LOG_ERROR, "decode_sos: invalid len (%d)\n", len);
1702 return AVERROR_INVALIDDATA;
1703 }
1704
2/2
✓ Branch 0 taken 7706 times.
✓ Branch 1 taken 2616 times.
10322 for (i = 0; i < nb_components; i++) {
1705 7706 id = get_bits(&s->gb, 8);
1706 7706 av_log(s->avctx, AV_LOG_DEBUG, "component: %d\n", id);
1707 /* find component index */
1708
1/2
✓ Branch 0 taken 15401 times.
✗ Branch 1 not taken.
15401 for (index = 0; index < s->nb_components; index++)
1709
2/2
✓ Branch 0 taken 7706 times.
✓ Branch 1 taken 7695 times.
15401 if (id == s->component_id[index])
1710 7706 break;
1711
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7706 times.
7706 if (index == s->nb_components) {
1712 av_log(s->avctx, AV_LOG_ERROR,
1713 "decode_sos: index(%d) out of components\n", index);
1714 return AVERROR_INVALIDDATA;
1715 }
1716 /* Metasoft MJPEG codec has Cb and Cr swapped */
1717
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7706 times.
7706 if (s->avctx->codec_tag == MKTAG('M', 'T', 'S', 'J')
1718 && nb_components == 3 && s->nb_components == 3 && i)
1719 index = 3 - i;
1720
1721 7706 s->quant_sindex[i] = s->quant_index[index];
1722 7706 s->nb_blocks[i] = s->h_count[index] * s->v_count[index];
1723 7706 s->h_scount[i] = s->h_count[index];
1724 7706 s->v_scount[i] = s->v_count[index];
1725
1726 7706 s->comp_index[i] = index;
1727
1728 7706 s->dc_index[i] = get_bits(&s->gb, 4);
1729 7706 s->ac_index[i] = get_bits(&s->gb, 4);
1730
1731
2/4
✓ Branch 0 taken 7706 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7706 times.
✗ Branch 3 not taken.
7706 if (s->dc_index[i] < 0 || s->ac_index[i] < 0 ||
1732
2/4
✓ Branch 0 taken 7706 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7706 times.
7706 s->dc_index[i] >= 4 || s->ac_index[i] >= 4)
1733 goto out_of_range;
1734
5/8
✓ Branch 0 taken 7706 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80 times.
✓ Branch 3 taken 7626 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 80 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 7626 times.
7706 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))
1735 goto out_of_range;
1736 }
1737
1738 2616 predictor = get_bits(&s->gb, 8); /* JPEG Ss / lossless JPEG predictor /JPEG-LS NEAR */
1739 2616 ilv = get_bits(&s->gb, 8); /* JPEG Se / JPEG-LS ILV */
1740
1/2
✓ Branch 0 taken 2616 times.
✗ Branch 1 not taken.
2616 if(s->avctx->codec_tag != AV_RL32("CJPG")){
1741 2616 prev_shift = get_bits(&s->gb, 4); /* Ah */
1742 2616 point_transform = get_bits(&s->gb, 4); /* Al */
1743 }else
1744 prev_shift = point_transform = 0;
1745
1746
2/2
✓ Branch 0 taken 2545 times.
✓ Branch 1 taken 71 times.
2616 if (nb_components > 1) {
1747 /* interleaved stream */
1748 2545 s->mb_width = (s->width + s->h_max * block_size - 1) / (s->h_max * block_size);
1749 2545 s->mb_height = (s->height + s->v_max * block_size - 1) / (s->v_max * block_size);
1750
2/2
✓ Branch 0 taken 63 times.
✓ Branch 1 taken 8 times.
71 } else if (!s->ls) { /* skip this for JPEG-LS */
1751 63 h = s->h_max / s->h_scount[0];
1752 63 v = s->v_max / s->v_scount[0];
1753 63 s->mb_width = (s->width + h * block_size - 1) / (h * block_size);
1754 63 s->mb_height = (s->height + v * block_size - 1) / (v * block_size);
1755 63 s->nb_blocks[0] = 1;
1756 63 s->h_scount[0] = 1;
1757 63 s->v_scount[0] = 1;
1758 }
1759
1760
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2616 times.
2616 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
1761 av_log(s->avctx, AV_LOG_DEBUG, "%s %s p:%d >>:%d ilv:%d bits:%d skip:%d %s comp:%d\n",
1762 s->lossless ? "lossless" : "sequential DCT", s->rgb ? "RGB" : "",
1763 predictor, point_transform, ilv, s->bits, s->mjpb_skiptosod,
1764 s->pegasus_rct ? "PRCT" : (s->rct ? "RCT" : ""), nb_components);
1765
1766
1767 /* mjpeg-b can have padding bytes between sos and image data, skip them */
1768
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2616 times.
2638 for (i = s->mjpb_skiptosod; i > 0; i--)
1769 22 skip_bits(&s->gb, 8);
1770
1771 2616 next_field:
1772
2/2
✓ Branch 0 taken 7706 times.
✓ Branch 1 taken 2616 times.
10322 for (i = 0; i < nb_components; i++)
1773 7706 s->last_dc[i] = (4 << s->bits);
1774
1775
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2616 times.
2616 if (s->avctx->hwaccel) {
1776 int bytes_to_start = get_bits_count(&s->gb) / 8;
1777 av_assert0(bytes_to_start >= 0 &&
1778 s->raw_scan_buffer_size >= bytes_to_start);
1779
1780 ret = FF_HW_CALL(s->avctx, decode_slice,
1781 s->raw_scan_buffer + bytes_to_start,
1782 s->raw_scan_buffer_size - bytes_to_start);
1783 if (ret < 0)
1784 return ret;
1785
1786
2/2
✓ Branch 0 taken 413 times.
✓ Branch 1 taken 2203 times.
2616 } else if (s->lossless) {
1787
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 413 times.
413 av_assert0(s->picture_ptr == s->picture);
1788
2/2
✓ Branch 0 taken 213 times.
✓ Branch 1 taken 200 times.
413 if (CONFIG_JPEGLS_DECODER && s->ls) {
1789 // for () {
1790 // reset_ls_coding_parameters(s, 0);
1791
1792
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 213 times.
213 if ((ret = ff_jpegls_decode_picture(s, predictor,
1793 point_transform, ilv)) < 0)
1794 return ret;
1795 } else {
1796
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) {
1797 if ((ret = ljpeg_decode_rgb_scan(s, nb_components, predictor, point_transform)) < 0)
1798 return ret;
1799 } else {
1800
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 200 times.
200 if ((ret = ljpeg_decode_yuv_scan(s, predictor,
1801 point_transform,
1802 nb_components)) < 0)
1803 return ret;
1804 }
1805 }
1806 } else {
1807
4/4
✓ Branch 0 taken 68 times.
✓ Branch 1 taken 2135 times.
✓ Branch 2 taken 59 times.
✓ Branch 3 taken 9 times.
2203 if (s->progressive && predictor) {
1808
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
59 av_assert0(s->picture_ptr == s->picture);
1809
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 59 times.
59 if ((ret = mjpeg_decode_scan_progressive_ac(s, predictor,
1810 ilv, prev_shift,
1811 point_transform)) < 0)
1812 return ret;
1813 } else {
1814
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2144 times.
2144 if ((ret = mjpeg_decode_scan(s, nb_components,
1815 prev_shift, point_transform,
1816 mb_bitmask, mb_bitmask_size, reference)) < 0)
1817 return ret;
1818 }
1819 }
1820
1821
4/4
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 2588 times.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 13 times.
2644 if (s->interlaced &&
1822
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 15 times.
43 get_bits_left(&s->gb) > 32 &&
1823 15 show_bits(&s->gb, 8) == 0xFF) {
1824 GetBitContext bak = s->gb;
1825 align_get_bits(&bak);
1826 if (show_bits(&bak, 16) == 0xFFD1) {
1827 av_log(s->avctx, AV_LOG_DEBUG, "AVRn interlaced picture marker found\n");
1828 s->gb = bak;
1829 skip_bits(&s->gb, 16);
1830 s->bottom_field ^= 1;
1831
1832 goto next_field;
1833 }
1834 }
1835
1836 2616 emms_c();
1837 2616 return 0;
1838 out_of_range:
1839 av_log(s->avctx, AV_LOG_ERROR, "decode_sos: ac/dc index out of range\n");
1840 return AVERROR_INVALIDDATA;
1841 }
1842
1843 16 static int mjpeg_decode_dri(MJpegDecodeContext *s)
1844 {
1845
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
16 if (get_bits(&s->gb, 16) != 4)
1846 return AVERROR_INVALIDDATA;
1847 16 s->restart_interval = get_bits(&s->gb, 16);
1848 16 s->restart_count = 0;
1849 16 av_log(s->avctx, AV_LOG_DEBUG, "restart interval: %d\n",
1850 s->restart_interval);
1851
1852 16 return 0;
1853 }
1854
1855 224 static int mjpeg_decode_app(MJpegDecodeContext *s)
1856 {
1857 int len, id, i;
1858
1859 224 len = get_bits(&s->gb, 16);
1860
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 224 times.
224 if (len < 6) {
1861 if (s->bayer) {
1862 // Pentax K-1 (digital camera) JPEG images embedded in DNG images contain unknown APP0 markers
1863 av_log(s->avctx, AV_LOG_WARNING, "skipping APPx (len=%"PRId32") for bayer-encoded image\n", len);
1864 skip_bits(&s->gb, len);
1865 return 0;
1866 } else
1867 return AVERROR_INVALIDDATA;
1868 }
1869
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 224 times.
224 if (8 * len > get_bits_left(&s->gb))
1870 return AVERROR_INVALIDDATA;
1871
1872 224 id = get_bits_long(&s->gb, 32);
1873 224 len -= 6;
1874
1875
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 224 times.
224 if (s->avctx->debug & FF_DEBUG_STARTCODE)
1876 av_log(s->avctx, AV_LOG_DEBUG, "APPx (%s / %8X) len=%d\n",
1877 av_fourcc2str(av_bswap32(id)), id, len);
1878
1879 /* Buggy AVID, it puts EOI only at every 10th frame. */
1880 /* Also, this fourcc is used by non-avid files too, it holds some
1881 information, but it's always present in AVID-created files. */
1882
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 205 times.
224 if (id == AV_RB32("AVI1")) {
1883 /* structure:
1884 4bytes AVI1
1885 1bytes polarity
1886 1bytes always zero
1887 4bytes field_size
1888 4bytes field_size_less_padding
1889 */
1890 19 s->buggy_avid = 1;
1891 19 i = get_bits(&s->gb, 8); len--;
1892 19 av_log(s->avctx, AV_LOG_DEBUG, "polarity %d\n", i);
1893 19 goto out;
1894 }
1895
1896
2/2
✓ Branch 0 taken 150 times.
✓ Branch 1 taken 55 times.
205 if (id == AV_RB32("JFIF")) {
1897 int t_w, t_h, v1, v2;
1898
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 150 times.
150 if (len < 8)
1899 goto out;
1900 150 skip_bits(&s->gb, 8); /* the trailing zero-byte */
1901 150 v1 = get_bits(&s->gb, 8);
1902 150 v2 = get_bits(&s->gb, 8);
1903 150 skip_bits(&s->gb, 8);
1904
1905 150 s->avctx->sample_aspect_ratio.num = get_bits(&s->gb, 16);
1906 150 s->avctx->sample_aspect_ratio.den = get_bits(&s->gb, 16);
1907
1/2
✓ Branch 0 taken 150 times.
✗ Branch 1 not taken.
150 if ( s->avctx->sample_aspect_ratio.num <= 0
1908
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 150 times.
150 || s->avctx->sample_aspect_ratio.den <= 0) {
1909 s->avctx->sample_aspect_ratio.num = 0;
1910 s->avctx->sample_aspect_ratio.den = 1;
1911 }
1912
1913
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 150 times.
150 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
1914 av_log(s->avctx, AV_LOG_INFO,
1915 "mjpeg: JFIF header found (version: %x.%x) SAR=%d/%d\n",
1916 v1, v2,
1917 s->avctx->sample_aspect_ratio.num,
1918 s->avctx->sample_aspect_ratio.den);
1919
1920 150 len -= 8;
1921
2/2
✓ Branch 0 taken 148 times.
✓ Branch 1 taken 2 times.
150 if (len >= 2) {
1922 148 t_w = get_bits(&s->gb, 8);
1923 148 t_h = get_bits(&s->gb, 8);
1924
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 148 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
148 if (t_w && t_h) {
1925 /* skip thumbnail */
1926 if (len -10 - (t_w * t_h * 3) > 0)
1927 len -= t_w * t_h * 3;
1928 }
1929 148 len -= 2;
1930 }
1931 150 goto out;
1932 }
1933
1934
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 42 times.
55 if ( id == AV_RB32("Adob")
1935
1/2
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
13 && len >= 7
1936
1/2
✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
13 && show_bits(&s->gb, 8) == 'e'
1937
1/2
✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
13 && show_bits_long(&s->gb, 32) != AV_RB32("e_CM")) {
1938 13 skip_bits(&s->gb, 8); /* 'e' */
1939 13 skip_bits(&s->gb, 16); /* version */
1940 13 skip_bits(&s->gb, 16); /* flags0 */
1941 13 skip_bits(&s->gb, 16); /* flags1 */
1942 13 s->adobe_transform = get_bits(&s->gb, 8);
1943
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
13 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
1944 av_log(s->avctx, AV_LOG_INFO, "mjpeg: Adobe header found, transform=%d\n", s->adobe_transform);
1945 13 len -= 7;
1946 13 goto out;
1947 }
1948
1949
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
42 if (id == AV_RB32("LJIF")) {
1950 int rgb = s->rgb;
1951 int pegasus_rct = s->pegasus_rct;
1952 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
1953 av_log(s->avctx, AV_LOG_INFO,
1954 "Pegasus lossless jpeg header found\n");
1955 skip_bits(&s->gb, 16); /* version ? */
1956 skip_bits(&s->gb, 16); /* unknown always 0? */
1957 skip_bits(&s->gb, 16); /* unknown always 0? */
1958 skip_bits(&s->gb, 16); /* unknown always 0? */
1959 switch (i=get_bits(&s->gb, 8)) {
1960 case 1:
1961 rgb = 1;
1962 pegasus_rct = 0;
1963 break;
1964 case 2:
1965 rgb = 1;
1966 pegasus_rct = 1;
1967 break;
1968 default:
1969 av_log(s->avctx, AV_LOG_ERROR, "unknown colorspace %d\n", i);
1970 }
1971
1972 len -= 9;
1973 if (s->bayer)
1974 goto out;
1975 if (s->got_picture)
1976 if (rgb != s->rgb || pegasus_rct != s->pegasus_rct) {
1977 av_log(s->avctx, AV_LOG_WARNING, "Mismatching LJIF tag\n");
1978 goto out;
1979 }
1980
1981 s->rgb = rgb;
1982 s->pegasus_rct = pegasus_rct;
1983
1984 goto out;
1985 }
1986
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) {
1987 8 s->colr = get_bits(&s->gb, 8);
1988
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
1989 av_log(s->avctx, AV_LOG_INFO, "COLR %d\n", s->colr);
1990 8 len --;
1991 8 goto out;
1992 }
1993
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) {
1994 s->xfrm = get_bits(&s->gb, 8);
1995 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
1996 av_log(s->avctx, AV_LOG_INFO, "XFRM %d\n", s->xfrm);
1997 len --;
1998 goto out;
1999 }
2000
2001 /* JPS extension by VRex */
2002
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) {
2003 int flags, layout, type;
2004 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
2005 av_log(s->avctx, AV_LOG_INFO, "_JPSJPS_\n");
2006
2007 skip_bits(&s->gb, 32); len -= 4; /* JPS_ */
2008 skip_bits(&s->gb, 16); len -= 2; /* block length */
2009 skip_bits(&s->gb, 8); /* reserved */
2010 flags = get_bits(&s->gb, 8);
2011 layout = get_bits(&s->gb, 8);
2012 type = get_bits(&s->gb, 8);
2013 len -= 4;
2014
2015 av_freep(&s->stereo3d);
2016 s->stereo3d = av_stereo3d_alloc();
2017 if (!s->stereo3d) {
2018 goto out;
2019 }
2020 if (type == 0) {
2021 s->stereo3d->type = AV_STEREO3D_2D;
2022 } else if (type == 1) {
2023 switch (layout) {
2024 case 0x01:
2025 s->stereo3d->type = AV_STEREO3D_LINES;
2026 break;
2027 case 0x02:
2028 s->stereo3d->type = AV_STEREO3D_SIDEBYSIDE;
2029 break;
2030 case 0x03:
2031 s->stereo3d->type = AV_STEREO3D_TOPBOTTOM;
2032 break;
2033 }
2034 if (!(flags & 0x04)) {
2035 s->stereo3d->flags = AV_STEREO3D_FLAG_INVERT;
2036 }
2037 }
2038 goto out;
2039 }
2040
2041 /* EXIF metadata */
2042
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) {
2043 GetByteContext gbytes;
2044 int ret, le, ifd_offset, bytes_read;
2045 const uint8_t *aligned;
2046
2047 18 skip_bits(&s->gb, 16); // skip padding
2048 18 len -= 2;
2049
2050 // init byte wise reading
2051 18 aligned = align_get_bits(&s->gb);
2052 18 bytestream2_init(&gbytes, aligned, len);
2053
2054 // read TIFF header
2055 18 ret = ff_tdecode_header(&gbytes, &le, &ifd_offset);
2056
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (ret) {
2057 av_log(s->avctx, AV_LOG_ERROR, "mjpeg: invalid TIFF header in EXIF data\n");
2058 } else {
2059 18 bytestream2_seek(&gbytes, ifd_offset, SEEK_SET);
2060
2061 // read 0th IFD and store the metadata
2062 // (return values > 0 indicate the presence of subimage metadata)
2063 18 ret = ff_exif_decode_ifd(s->avctx, &gbytes, le, 0, &s->exif_metadata);
2064
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (ret < 0) {
2065 av_log(s->avctx, AV_LOG_ERROR, "mjpeg: error decoding EXIF data\n");
2066 }
2067 }
2068
2069 18 bytes_read = bytestream2_tell(&gbytes);
2070 18 skip_bits(&s->gb, bytes_read << 3);
2071 18 len -= bytes_read;
2072
2073 18 goto out;
2074 }
2075
2076 /* Apple MJPEG-A */
2077
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))) {
2078 2 id = get_bits_long(&s->gb, 32);
2079 2 len -= 4;
2080 /* Apple MJPEG-A */
2081
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (id == AV_RB32("mjpg")) {
2082 /* structure:
2083 4bytes field size
2084 4bytes pad field size
2085 4bytes next off
2086 4bytes quant off
2087 4bytes huff off
2088 4bytes image off
2089 4bytes scan off
2090 4bytes data off
2091 */
2092 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
2093 av_log(s->avctx, AV_LOG_INFO, "mjpeg: Apple MJPEG-A header found\n");
2094 }
2095 }
2096
2097
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) {
2098 int id2;
2099 unsigned seqno;
2100 unsigned nummarkers;
2101
2102 10 id = get_bits_long(&s->gb, 32);
2103 10 id2 = get_bits(&s->gb, 24);
2104 10 len -= 7;
2105
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")) {
2106 av_log(s->avctx, AV_LOG_WARNING, "Invalid ICC_PROFILE header in APP2\n");
2107 goto out;
2108 }
2109
2110 10 skip_bits(&s->gb, 8);
2111 10 seqno = get_bits(&s->gb, 8);
2112 10 len -= 2;
2113
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (seqno == 0) {
2114 av_log(s->avctx, AV_LOG_WARNING, "Invalid sequence number in APP2\n");
2115 goto out;
2116 }
2117
2118 10 nummarkers = get_bits(&s->gb, 8);
2119 10 len -= 1;
2120
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (nummarkers == 0) {
2121 av_log(s->avctx, AV_LOG_WARNING, "Invalid number of markers coded in APP2\n");
2122 goto out;
2123
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) {
2124 av_log(s->avctx, AV_LOG_WARNING, "Mistmatch in coded number of ICC markers between markers\n");
2125 goto out;
2126
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 } else if (seqno > nummarkers) {
2127 av_log(s->avctx, AV_LOG_WARNING, "Mismatching sequence number and coded number of ICC markers\n");
2128 goto out;
2129 }
2130
2131 /* Allocate if this is the first APP2 we've seen. */
2132
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if (s->iccnum == 0) {
2133
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
10 if (!FF_ALLOCZ_TYPED_ARRAY(s->iccentries, nummarkers)) {
2134 av_log(s->avctx, AV_LOG_ERROR, "Could not allocate ICC data arrays\n");
2135 return AVERROR(ENOMEM);
2136 }
2137 10 s->iccnum = nummarkers;
2138 }
2139
2140
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (s->iccentries[seqno - 1].data) {
2141 av_log(s->avctx, AV_LOG_WARNING, "Duplicate ICC sequence number\n");
2142 goto out;
2143 }
2144
2145 10 s->iccentries[seqno - 1].length = len;
2146 10 s->iccentries[seqno - 1].data = av_malloc(len);
2147
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (!s->iccentries[seqno - 1].data) {
2148 av_log(s->avctx, AV_LOG_ERROR, "Could not allocate ICC data buffer\n");
2149 return AVERROR(ENOMEM);
2150 }
2151
2152 10 memcpy(s->iccentries[seqno - 1].data, align_get_bits(&s->gb), len);
2153 10 skip_bits(&s->gb, len << 3);
2154 10 len = 0;
2155 10 s->iccread++;
2156
2157
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if (s->iccread > s->iccnum)
2158 av_log(s->avctx, AV_LOG_WARNING, "Read more ICC markers than are supposed to be coded\n");
2159 }
2160
2161 16 out:
2162 /* slow but needed for extreme adobe jpegs */
2163
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 224 times.
224 if (len < 0)
2164 av_log(s->avctx, AV_LOG_ERROR,
2165 "mjpeg: error, decode_app parser read over the end\n");
2166
2/2
✓ Branch 0 taken 107450 times.
✓ Branch 1 taken 224 times.
107674 while (--len > 0)
2167 107450 skip_bits(&s->gb, 8);
2168
2169 224 return 0;
2170 }
2171
2172 234 static int mjpeg_decode_com(MJpegDecodeContext *s)
2173 {
2174 234 int len = get_bits(&s->gb, 16);
2175
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)) {
2176 int i;
2177 234 char *cbuf = av_malloc(len - 1);
2178
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 234 times.
234 if (!cbuf)
2179 return AVERROR(ENOMEM);
2180
2181
2/2
✓ Branch 0 taken 3571 times.
✓ Branch 1 taken 234 times.
3805 for (i = 0; i < len - 2; i++)
2182 3571 cbuf[i] = get_bits(&s->gb, 8);
2183
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')
2184 10 cbuf[i - 1] = 0;
2185 else
2186 224 cbuf[i] = 0;
2187
2188
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 234 times.
234 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
2189 av_log(s->avctx, AV_LOG_INFO, "comment: '%s'\n", cbuf);
2190
2191 /* buggy avid, it puts EOI only at every 10th frame */
2192
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 223 times.
234 if (!strncmp(cbuf, "AVID", 4)) {
2193 11 parse_avid(s, cbuf, len);
2194
2/2
✓ Branch 0 taken 205 times.
✓ Branch 1 taken 18 times.
223 } else if (!strcmp(cbuf, "CS=ITU601"))
2195 205 s->cs_itu601 = 1;
2196
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) ||
2197
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 (!strncmp(cbuf, "Metasoft MJPEG Codec", 20)))
2198 s->flipped = 1;
2199
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 else if (!strcmp(cbuf, "MULTISCOPE II")) {
2200 s->avctx->sample_aspect_ratio = (AVRational) { 1, 2 };
2201 s->multiscope = 2;
2202 }
2203
2204 234 av_free(cbuf);
2205 }
2206
2207 234 return 0;
2208 }
2209
2210 /* return the 8 bit start code value and update the search
2211 state. Return -1 if no start code found */
2212 16600 static int find_marker(const uint8_t **pbuf_ptr, const uint8_t *buf_end)
2213 {
2214 const uint8_t *buf_ptr;
2215 unsigned int v, v2;
2216 int val;
2217 16600 int skipped = 0;
2218
2219 16600 buf_ptr = *pbuf_ptr;
2220
2/2
✓ Branch 0 taken 284907 times.
✓ Branch 1 taken 12 times.
284919 while (buf_end - buf_ptr > 1) {
2221 284907 v = *buf_ptr++;
2222 284907 v2 = *buf_ptr;
2223
7/8
✓ Branch 0 taken 19107 times.
✓ Branch 1 taken 265800 times.
✓ Branch 2 taken 16609 times.
✓ Branch 3 taken 2498 times.
✓ Branch 4 taken 16588 times.
✓ Branch 5 taken 21 times.
✓ Branch 6 taken 16588 times.
✗ Branch 7 not taken.
284907 if ((v == 0xff) && (v2 >= SOF0) && (v2 <= COM) && buf_ptr < buf_end) {
2224 16588 val = *buf_ptr++;
2225 16588 goto found;
2226 }
2227 268319 skipped++;
2228 }
2229 12 buf_ptr = buf_end;
2230 12 val = -1;
2231 16600 found:
2232 ff_dlog(NULL, "find_marker skipped %d bytes\n", skipped);
2233 16600 *pbuf_ptr = buf_ptr;
2234 16600 return val;
2235 }
2236
2237 16600 int ff_mjpeg_find_marker(MJpegDecodeContext *s,
2238 const uint8_t **buf_ptr, const uint8_t *buf_end,
2239 const uint8_t **unescaped_buf_ptr,
2240 int *unescaped_buf_size)
2241 {
2242 int start_code;
2243 16600 start_code = find_marker(buf_ptr, buf_end);
2244
2245 16600 av_fast_padded_malloc(&s->buffer, &s->buffer_size, buf_end - *buf_ptr);
2246
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16600 times.
16600 if (!s->buffer)
2247 return AVERROR(ENOMEM);
2248
2249 /* unescape buffer of SOS, use special treatment for JPEG-LS */
2250
4/4
✓ Branch 0 taken 2735 times.
✓ Branch 1 taken 13865 times.
✓ Branch 2 taken 2522 times.
✓ Branch 3 taken 213 times.
19122 if (start_code == SOS && !s->ls) {
2251 2522 const uint8_t *src = *buf_ptr;
2252 2522 const uint8_t *ptr = src;
2253 2522 uint8_t *dst = s->buffer;
2254
2255 #define copy_data_segment(skip) do { \
2256 ptrdiff_t length = (ptr - src) - (skip); \
2257 if (length > 0) { \
2258 memcpy(dst, src, length); \
2259 dst += length; \
2260 src = ptr; \
2261 } \
2262 } while (0)
2263
2264
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 2448 times.
2522 if (s->avctx->codec_id == AV_CODEC_ID_THP) {
2265 74 ptr = buf_end;
2266
1/2
✓ Branch 0 taken 74 times.
✗ Branch 1 not taken.
74 copy_data_segment(0);
2267 } else {
2268
1/2
✓ Branch 0 taken 43286705 times.
✗ Branch 1 not taken.
43289153 while (ptr < buf_end) {
2269 43286705 uint8_t x = *(ptr++);
2270
2271
2/2
✓ Branch 0 taken 43100817 times.
✓ Branch 1 taken 185888 times.
43286705 if (x == 0xff) {
2272 185888 ptrdiff_t skip = 0;
2273
4/4
✓ Branch 0 taken 369467 times.
✓ Branch 1 taken 2323 times.
✓ Branch 2 taken 185902 times.
✓ Branch 3 taken 183565 times.
371790 while (ptr < buf_end && x == 0xff) {
2274 185902 x = *(ptr++);
2275 185902 skip++;
2276 }
2277
2278 /* 0xFF, 0xFF, ... */
2279
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 185881 times.
185888 if (skip > 1) {
2280
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 copy_data_segment(skip);
2281
2282 /* decrement src as it is equal to ptr after the
2283 * copy_data_segment macro and we might want to
2284 * copy the current value of x later on */
2285 7 src--;
2286 }
2287
2288
4/4
✓ Branch 0 taken 2430 times.
✓ Branch 1 taken 183458 times.
✓ Branch 2 taken 2354 times.
✓ Branch 3 taken 76 times.
185888 if (x < RST0 || x > RST7) {
2289
2/2
✓ Branch 0 taken 185805 times.
✓ Branch 1 taken 7 times.
185812 copy_data_segment(1);
2290
2/2
✓ Branch 0 taken 2448 times.
✓ Branch 1 taken 183364 times.
185812 if (x)
2291 2448 break;
2292 }
2293 }
2294 }
2295
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 2441 times.
2448 if (src < ptr)
2296
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 copy_data_segment(0);
2297 }
2298 #undef copy_data_segment
2299
2300 2522 *unescaped_buf_ptr = s->buffer;
2301 2522 *unescaped_buf_size = dst - s->buffer;
2302 2522 memset(s->buffer + *unescaped_buf_size, 0,
2303 AV_INPUT_BUFFER_PADDING_SIZE);
2304
2305 2522 av_log(s->avctx, AV_LOG_DEBUG, "escaping removed %"PTRDIFF_SPECIFIER" bytes\n",
2306 2522 (buf_end - *buf_ptr) - (dst - s->buffer));
2307
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) {
2308 213 const uint8_t *src = *buf_ptr;
2309 213 uint8_t *dst = s->buffer;
2310 213 int bit_count = 0;
2311 213 int t = 0, b = 0;
2312 PutBitContext pb;
2313
2314 /* find marker */
2315
1/2
✓ Branch 0 taken 27487079 times.
✗ Branch 1 not taken.
27487292 while (src + t < buf_end) {
2316 27487079 uint8_t x = src[t++];
2317
2/2
✓ Branch 0 taken 27333028 times.
✓ Branch 1 taken 154051 times.
27487079 if (x == 0xff) {
2318
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)
2319 154051 x = src[t++];
2320
2/2
✓ Branch 0 taken 213 times.
✓ Branch 1 taken 153838 times.
154051 if (x & 0x80) {
2321 213 t -= FFMIN(2, t);
2322 213 break;
2323 }
2324 }
2325 }
2326 213 bit_count = t * 8;
2327 213 init_put_bits(&pb, dst, t);
2328
2329 /* unescape bitstream */
2330
2/2
✓ Branch 0 taken 27486866 times.
✓ Branch 1 taken 213 times.
27487079 while (b < t) {
2331 27486866 uint8_t x = src[b++];
2332 27486866 put_bits(&pb, 8, x);
2333
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) {
2334 153838 x = src[b++];
2335
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 153838 times.
153838 if (x & 0x80) {
2336 av_log(s->avctx, AV_LOG_WARNING, "Invalid escape sequence\n");
2337 x &= 0x7f;
2338 }
2339 153838 put_bits(&pb, 7, x);
2340 153838 bit_count--;
2341 }
2342 }
2343 213 flush_put_bits(&pb);
2344
2345 213 *unescaped_buf_ptr = dst;
2346 213 *unescaped_buf_size = (bit_count + 7) >> 3;
2347 213 memset(s->buffer + *unescaped_buf_size, 0,
2348 AV_INPUT_BUFFER_PADDING_SIZE);
2349 } else {
2350 13865 *unescaped_buf_ptr = *buf_ptr;
2351 13865 *unescaped_buf_size = buf_end - *buf_ptr;
2352 }
2353
2354 16600 return start_code;
2355 }
2356
2357 211 static void reset_icc_profile(MJpegDecodeContext *s)
2358 {
2359 int i;
2360
2361
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 201 times.
211 if (s->iccentries) {
2362
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 for (i = 0; i < s->iccnum; i++)
2363 10 av_freep(&s->iccentries[i].data);
2364 10 av_freep(&s->iccentries);
2365 }
2366
2367 211 s->iccread = 0;
2368 211 s->iccnum = 0;
2369 211 }
2370
2371 2586 int ff_mjpeg_decode_frame_from_buf(AVCodecContext *avctx, AVFrame *frame,
2372 int *got_frame, const AVPacket *avpkt,
2373 const uint8_t *buf, const int buf_size)
2374 {
2375 2586 MJpegDecodeContext *s = avctx->priv_data;
2376 const uint8_t *buf_end, *buf_ptr;
2377 const uint8_t *unescaped_buf_ptr;
2378 int hshift, vshift;
2379 int unescaped_buf_size;
2380 int start_code;
2381 int i, index;
2382 2586 int ret = 0;
2383 int is16bit;
2384 2586 AVDictionaryEntry *e = NULL;
2385
2386 2586 s->force_pal8 = 0;
2387
2388 2586 s->buf_size = buf_size;
2389
2390 2586 av_dict_free(&s->exif_metadata);
2391 2586 av_freep(&s->stereo3d);
2392 2586 s->adobe_transform = -1;
2393
2394
1/2
✓ Branch 0 taken 2586 times.
✗ Branch 1 not taken.
2586 if (s->iccnum != 0)
2395 reset_icc_profile(s);
2396
2397 2586 redo_for_pal8:
2398 2594 buf_ptr = buf;
2399 2594 buf_end = buf + buf_size;
2400
1/2
✓ Branch 0 taken 16398 times.
✗ Branch 1 not taken.
16398 while (buf_ptr < buf_end) {
2401 /* find start next marker */
2402 16398 start_code = ff_mjpeg_find_marker(s, &buf_ptr, buf_end,
2403 &unescaped_buf_ptr,
2404 &unescaped_buf_size);
2405 /* EOF */
2406
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 16386 times.
16398 if (start_code < 0) {
2407 12 break;
2408
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16386 times.
16386 } else if (unescaped_buf_size > INT_MAX / 8) {
2409 av_log(avctx, AV_LOG_ERROR,
2410 "MJPEG packet 0x%x too big (%d/%d), corrupt data?\n",
2411 start_code, unescaped_buf_size, buf_size);
2412 return AVERROR_INVALIDDATA;
2413 }
2414 16386 av_log(avctx, AV_LOG_DEBUG, "marker=%x avail_size_in_buf=%"PTRDIFF_SPECIFIER"\n",
2415 start_code, buf_end - buf_ptr);
2416
2417 16386 ret = init_get_bits8(&s->gb, unescaped_buf_ptr, unescaped_buf_size);
2418
2419
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16386 times.
16386 if (ret < 0) {
2420 av_log(avctx, AV_LOG_ERROR, "invalid buffer\n");
2421 goto fail;
2422 }
2423
2424 16386 s->start_code = start_code;
2425
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16386 times.
16386 if (avctx->debug & FF_DEBUG_STARTCODE)
2426 av_log(avctx, AV_LOG_DEBUG, "startcode: %X\n", start_code);
2427
2428 /* process markers */
2429
4/4
✓ Branch 0 taken 11177 times.
✓ Branch 1 taken 5209 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 11175 times.
16386 if (start_code >= RST0 && start_code <= RST7) {
2430 2 av_log(avctx, AV_LOG_DEBUG,
2431 "restart marker: %d\n", start_code & 0x0f);
2432 /* APP fields */
2433
4/4
✓ Branch 0 taken 695 times.
✓ Branch 1 taken 15689 times.
✓ Branch 2 taken 224 times.
✓ Branch 3 taken 471 times.
16384 } else if (start_code >= APP0 && start_code <= APP15) {
2434
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 224 times.
224 if ((ret = mjpeg_decode_app(s)) < 0)
2435 av_log(avctx, AV_LOG_ERROR, "unable to decode APP fields: %s\n",
2436 av_err2str(ret));
2437 /* Comment */
2438
2/2
✓ Branch 0 taken 234 times.
✓ Branch 1 taken 15926 times.
16160 } else if (start_code == COM) {
2439 234 ret = mjpeg_decode_com(s);
2440
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 234 times.
234 if (ret < 0)
2441 return ret;
2442
2/2
✓ Branch 0 taken 2580 times.
✓ Branch 1 taken 13346 times.
15926 } else if (start_code == DQT) {
2443 2580 ret = ff_mjpeg_decode_dqt(s);
2444
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2580 times.
2580 if (ret < 0)
2445 return ret;
2446 }
2447
2448 16386 ret = -1;
2449
2450 if (!CONFIG_JPEGLS_DECODER &&
2451 (start_code == SOF48 || start_code == LSE)) {
2452 av_log(avctx, AV_LOG_ERROR, "JPEG-LS support not enabled.\n");
2453 return AVERROR(ENOSYS);
2454 }
2455
2456
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 15558 times.
16386 if (avctx->skip_frame == AVDISCARD_ALL) {
2457
2/2
✓ Branch 0 taken 391 times.
✓ Branch 1 taken 437 times.
828 switch(start_code) {
2458 391 case SOF0:
2459 case SOF1:
2460 case SOF2:
2461 case SOF3:
2462 case SOF48:
2463 case SOI:
2464 case SOS:
2465 case EOI:
2466 391 break;
2467 437 default:
2468 437 goto skip;
2469 }
2470 }
2471
2472
11/12
✓ Branch 0 taken 2597 times.
✓ Branch 1 taken 2624 times.
✓ Branch 2 taken 2157 times.
✓ Branch 3 taken 14 times.
✓ Branch 4 taken 205 times.
✓ Branch 5 taken 221 times.
✓ Branch 6 taken 16 times.
✓ Branch 7 taken 2578 times.
✓ Branch 8 taken 2704 times.
✓ Branch 9 taken 16 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2817 times.
15949 switch (start_code) {
2473 2597 case SOI:
2474 2597 s->restart_interval = 0;
2475 2597 s->restart_count = 0;
2476 2597 s->raw_image_buffer = buf_ptr;
2477 2597 s->raw_image_buffer_size = buf_end - buf_ptr;
2478 /* nothing to do on SOI */
2479 2597 break;
2480 2624 case DHT:
2481
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2624 times.
2624 if ((ret = ff_mjpeg_decode_dht(s)) < 0) {
2482 av_log(avctx, AV_LOG_ERROR, "huffman table decode error\n");
2483 goto fail;
2484 }
2485 2624 break;
2486 2157 case SOF0:
2487 case SOF1:
2488
2/2
✓ Branch 0 taken 2155 times.
✓ Branch 1 taken 2 times.
2157 if (start_code == SOF0)
2489 2155 avctx->profile = AV_PROFILE_MJPEG_HUFFMAN_BASELINE_DCT;
2490 else
2491 2 avctx->profile = AV_PROFILE_MJPEG_HUFFMAN_EXTENDED_SEQUENTIAL_DCT;
2492 2157 s->lossless = 0;
2493 2157 s->ls = 0;
2494 2157 s->progressive = 0;
2495
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2157 times.
2157 if ((ret = ff_mjpeg_decode_sof(s)) < 0)
2496 goto fail;
2497 2157 break;
2498 14 case SOF2:
2499 14 avctx->profile = AV_PROFILE_MJPEG_HUFFMAN_PROGRESSIVE_DCT;
2500 14 s->lossless = 0;
2501 14 s->ls = 0;
2502 14 s->progressive = 1;
2503
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
14 if ((ret = ff_mjpeg_decode_sof(s)) < 0)
2504 goto fail;
2505 14 break;
2506 205 case SOF3:
2507 205 avctx->profile = AV_PROFILE_MJPEG_HUFFMAN_LOSSLESS;
2508 205 avctx->properties |= FF_CODEC_PROPERTY_LOSSLESS;
2509 205 s->lossless = 1;
2510 205 s->ls = 0;
2511 205 s->progressive = 0;
2512
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 205 times.
205 if ((ret = ff_mjpeg_decode_sof(s)) < 0)
2513 goto fail;
2514 205 break;
2515 221 case SOF48:
2516 221 avctx->profile = AV_PROFILE_MJPEG_JPEG_LS;
2517 221 avctx->properties |= FF_CODEC_PROPERTY_LOSSLESS;
2518 221 s->lossless = 1;
2519 221 s->ls = 1;
2520 221 s->progressive = 0;
2521
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 221 times.
221 if ((ret = ff_mjpeg_decode_sof(s)) < 0)
2522 goto fail;
2523 221 break;
2524 16 case LSE:
2525
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if (!CONFIG_JPEGLS_DECODER ||
2526 16 (ret = ff_jpegls_decode_lse(s)) < 0)
2527 goto fail;
2528
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
16 if (ret == 1)
2529 8 goto redo_for_pal8;
2530 8 break;
2531 case EOI:
2532 2589 eoi_parser:
2533
3/4
✓ Branch 0 taken 2589 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2502 times.
✓ Branch 3 taken 87 times.
2589 if (!avctx->hwaccel && avctx->skip_frame != AVDISCARD_ALL &&
2534
4/6
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 2495 times.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
2502 s->progressive && s->cur_scan && s->got_picture)
2535 7 mjpeg_idct_scan_progressive_ac(s);
2536 2589 s->cur_scan = 0;
2537
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2589 times.
2589 if (!s->got_picture) {
2538 av_log(avctx, AV_LOG_WARNING,
2539 "Found EOI before any SOF, ignoring\n");
2540 break;
2541 }
2542
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 2581 times.
2589 if (s->interlaced) {
2543 8 s->bottom_field ^= 1;
2544 /* if not bottom field, do not output image yet */
2545
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 if (s->bottom_field == !s->interlace_polarity)
2546 4 break;
2547 }
2548
2/2
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 2499 times.
2585 if (avctx->skip_frame == AVDISCARD_ALL) {
2549 86 s->got_picture = 0;
2550 86 goto the_end_no_picture;
2551 }
2552
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2499 times.
2499 if (avctx->hwaccel) {
2553 ret = FF_HW_SIMPLE_CALL(avctx, end_frame);
2554 if (ret < 0)
2555 return ret;
2556
2557 av_freep(&s->hwaccel_picture_private);
2558 }
2559
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2499 times.
2499 if ((ret = av_frame_ref(frame, s->picture_ptr)) < 0)
2560 return ret;
2561 2499 *got_frame = 1;
2562 2499 s->got_picture = 0;
2563
2564
3/4
✓ Branch 0 taken 2086 times.
✓ Branch 1 taken 413 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2086 times.
2499 if (!s->lossless && avctx->debug & FF_DEBUG_QP) {
2565 int qp = FFMAX3(s->qscale[0],
2566 s->qscale[1],
2567 s->qscale[2]);
2568
2569 av_log(avctx, AV_LOG_DEBUG, "QP: %d\n", qp);
2570 }
2571
2572 2499 goto the_end;
2573 2704 case SOS:
2574 2704 s->raw_scan_buffer = buf_ptr;
2575 2704 s->raw_scan_buffer_size = buf_end - buf_ptr;
2576
2577 2704 s->cur_scan++;
2578
2/2
✓ Branch 0 taken 141 times.
✓ Branch 1 taken 2563 times.
2704 if (avctx->skip_frame == AVDISCARD_ALL) {
2579 141 skip_bits(&s->gb, get_bits_left(&s->gb));
2580 141 break;
2581 }
2582
2583
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2563 times.
2563 if ((ret = ff_mjpeg_decode_sos(s, NULL, 0, NULL)) < 0 &&
2584 (avctx->err_recognition & AV_EF_EXPLODE))
2585 goto fail;
2586 2563 break;
2587 16 case DRI:
2588
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
16 if ((ret = mjpeg_decode_dri(s)) < 0)
2589 return ret;
2590 16 break;
2591 case SOF5:
2592 case SOF6:
2593 case SOF7:
2594 case SOF9:
2595 case SOF10:
2596 case SOF11:
2597 case SOF13:
2598 case SOF14:
2599 case SOF15:
2600 case JPG:
2601 av_log(avctx, AV_LOG_ERROR,
2602 "mjpeg: unsupported coding type (%x)\n", start_code);
2603 break;
2604 }
2605
2606 13804 skip:
2607 /* eof process start code */
2608 13804 buf_ptr += (get_bits_count(&s->gb) + 7) / 8;
2609 27608 av_log(avctx, AV_LOG_DEBUG,
2610 "marker parser used %d bytes (%d bits)\n",
2611 13804 (get_bits_count(&s->gb) + 7) / 8, get_bits_count(&s->gb));
2612 }
2613
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) {
2614 11 av_log(avctx, AV_LOG_WARNING, "EOI missing, emulating\n");
2615 11 goto eoi_parser;
2616 }
2617 1 av_log(avctx, AV_LOG_FATAL, "No JPEG data found in image\n");
2618 1 return AVERROR_INVALIDDATA;
2619 fail:
2620 s->got_picture = 0;
2621 return ret;
2622 2499 the_end:
2623
2624 2499 is16bit = av_pix_fmt_desc_get(avctx->pix_fmt)->comp[0].step > 1;
2625
2626
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2493 times.
2499 if (AV_RB32(s->upscale_h)) {
2627 int p;
2628
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 ||
2629 avctx->pix_fmt == AV_PIX_FMT_YUV444P ||
2630 avctx->pix_fmt == AV_PIX_FMT_YUVJ440P ||
2631 avctx->pix_fmt == AV_PIX_FMT_YUV440P ||
2632 avctx->pix_fmt == AV_PIX_FMT_YUVA444P ||
2633 avctx->pix_fmt == AV_PIX_FMT_YUVJ422P ||
2634 avctx->pix_fmt == AV_PIX_FMT_YUV422P ||
2635 avctx->pix_fmt == AV_PIX_FMT_YUVJ420P ||
2636 avctx->pix_fmt == AV_PIX_FMT_YUV420P ||
2637 avctx->pix_fmt == AV_PIX_FMT_YUV420P16||
2638 avctx->pix_fmt == AV_PIX_FMT_YUVA420P ||
2639 avctx->pix_fmt == AV_PIX_FMT_YUVA420P16||
2640 avctx->pix_fmt == AV_PIX_FMT_GBRP ||
2641 avctx->pix_fmt == AV_PIX_FMT_GBRAP
2642 );
2643 6 ret = av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &hshift, &vshift);
2644
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (ret)
2645 return ret;
2646
2647
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));
2648
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 6 times.
24 for (p = 0; p<s->nb_components; p++) {
2649 18 uint8_t *line = s->picture_ptr->data[p];
2650 18 int w = s->width;
2651 18 int h = s->height;
2652
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if (!s->upscale_h[p])
2653 9 continue;
2654
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) {
2655 7 w = AV_CEIL_RSHIFT(w, hshift);
2656 7 h = AV_CEIL_RSHIFT(h, vshift);
2657 }
2658
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8 times.
9 if (s->upscale_v[p] == 1)
2659 1 h = (h+1)>>1;
2660
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 av_assert0(w > 0);
2661
2/2
✓ Branch 0 taken 534 times.
✓ Branch 1 taken 9 times.
543 for (i = 0; i < h; i++) {
2662
2/2
✓ Branch 0 taken 214 times.
✓ Branch 1 taken 320 times.
534 if (s->upscale_h[p] == 1) {
2663
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];
2664 214 else line[w - 1] = line[(w - 1) / 2];
2665
2/2
✓ Branch 0 taken 11220 times.
✓ Branch 1 taken 214 times.
11434 for (index = w - 2; index > 0; index--) {
2666
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11220 times.
11220 if (is16bit)
2667 ((uint16_t*)line)[index] = (((uint16_t*)line)[index / 2] + ((uint16_t*)line)[(index + 1) / 2]) >> 1;
2668 else
2669 11220 line[index] = (line[index / 2] + line[(index + 1) / 2]) >> 1;
2670 }
2671
2/2
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 64 times.
320 } else if (s->upscale_h[p] == 2) {
2672
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 256 times.
256 if (is16bit) {
2673 ((uint16_t*)line)[w - 1] = ((uint16_t*)line)[(w - 1) / 3];
2674 if (w > 1)
2675 ((uint16_t*)line)[w - 2] = ((uint16_t*)line)[w - 1];
2676 } else {
2677 256 line[w - 1] = line[(w - 1) / 3];
2678
1/2
✓ Branch 0 taken 256 times.
✗ Branch 1 not taken.
256 if (w > 1)
2679 256 line[w - 2] = line[w - 1];
2680 }
2681
2/2
✓ Branch 0 taken 15616 times.
✓ Branch 1 taken 256 times.
15872 for (index = w - 3; index > 0; index--) {
2682 15616 line[index] = (line[index / 3] + line[(index + 1) / 3] + line[(index + 2) / 3] + 1) / 3;
2683 }
2684
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 } else if (s->upscale_h[p] == 4){
2685
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 64 times.
64 if (is16bit) {
2686 uint16_t *line16 = (uint16_t *) line;
2687 line16[w - 1] = line16[(w - 1) >> 2];
2688 if (w > 1)
2689 line16[w - 2] = (line16[(w - 1) >> 2] * 3 + line16[(w - 2) >> 2]) >> 2;
2690 if (w > 2)
2691 line16[w - 3] = (line16[(w - 1) >> 2] + line16[(w - 2) >> 2]) >> 1;
2692 } else {
2693 64 line[w - 1] = line[(w - 1) >> 2];
2694
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 if (w > 1)
2695 64 line[w - 2] = (line[(w - 1) >> 2] * 3 + line[(w - 2) >> 2]) >> 2;
2696
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 if (w > 2)
2697 64 line[w - 3] = (line[(w - 1) >> 2] + line[(w - 2) >> 2]) >> 1;
2698 }
2699
2/2
✓ Branch 0 taken 3840 times.
✓ Branch 1 taken 64 times.
3904 for (index = w - 4; index > 0; index--)
2700 3840 line[index] = (line[(index + 3) >> 2] + line[(index + 2) >> 2]
2701 3840 + line[(index + 1) >> 2] + line[index >> 2]) >> 2;
2702 }
2703 534 line += s->linesize[p];
2704 }
2705 }
2706 }
2707
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2498 times.
2499 if (AV_RB32(s->upscale_v)) {
2708 int p;
2709
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 ||
2710 avctx->pix_fmt == AV_PIX_FMT_YUV444P ||
2711 avctx->pix_fmt == AV_PIX_FMT_YUVJ422P ||
2712 avctx->pix_fmt == AV_PIX_FMT_YUV422P ||
2713 avctx->pix_fmt == AV_PIX_FMT_YUVJ420P ||
2714 avctx->pix_fmt == AV_PIX_FMT_YUV420P ||
2715 avctx->pix_fmt == AV_PIX_FMT_YUV440P ||
2716 avctx->pix_fmt == AV_PIX_FMT_YUVJ440P ||
2717 avctx->pix_fmt == AV_PIX_FMT_YUVA444P ||
2718 avctx->pix_fmt == AV_PIX_FMT_YUVA420P ||
2719 avctx->pix_fmt == AV_PIX_FMT_YUVA420P16||
2720 avctx->pix_fmt == AV_PIX_FMT_GBRP ||
2721 avctx->pix_fmt == AV_PIX_FMT_GBRAP
2722 );
2723 1 ret = av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &hshift, &vshift);
2724
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret)
2725 return ret;
2726
2727
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));
2728
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 for (p = 0; p < s->nb_components; p++) {
2729 uint8_t *dst;
2730 3 int w = s->width;
2731 3 int h = s->height;
2732
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if (!s->upscale_v[p])
2733 2 continue;
2734
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) {
2735 1 w = AV_CEIL_RSHIFT(w, hshift);
2736 1 h = AV_CEIL_RSHIFT(h, vshift);
2737 }
2738 1 dst = &((uint8_t *)s->picture_ptr->data[p])[(h - 1) * s->linesize[p]];
2739
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 1 times.
43 for (i = h - 1; i; i--) {
2740 42 uint8_t *src1 = &((uint8_t *)s->picture_ptr->data[p])[i * s->upscale_v[p] / (s->upscale_v[p] + 1) * s->linesize[p]];
2741 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]];
2742
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)) {
2743 21 memcpy(dst, src1, w);
2744 } else {
2745
2/2
✓ Branch 0 taken 1344 times.
✓ Branch 1 taken 21 times.
1365 for (index = 0; index < w; index++)
2746 1344 dst[index] = (src1[index] + src2[index]) >> 1;
2747 }
2748 42 dst -= s->linesize[p];
2749 }
2750 }
2751 }
2752
3/4
✓ Branch 0 taken 368 times.
✓ Branch 1 taken 2131 times.
✓ Branch 2 taken 368 times.
✗ Branch 3 not taken.
2499 if (s->flipped && !s->rgb) {
2753 368 ret = av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &hshift, &vshift);
2754
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 368 times.
368 if (ret)
2755 return ret;
2756
2757
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 368 times.
368 av_assert0(s->nb_components == av_pix_fmt_count_planes(frame->format));
2758
2/2
✓ Branch 0 taken 1104 times.
✓ Branch 1 taken 368 times.
1472 for (index=0; index<s->nb_components; index++) {
2759 1104 int h = frame->height;
2760
3/4
✓ Branch 0 taken 736 times.
✓ Branch 1 taken 368 times.
✓ Branch 2 taken 736 times.
✗ Branch 3 not taken.
1104 if (index && index < 3)
2761 736 h = AV_CEIL_RSHIFT(h, vshift);
2762
1/2
✓ Branch 0 taken 1104 times.
✗ Branch 1 not taken.
1104 if (frame->data[index]) {
2763 1104 frame->data[index] += (h - 1) * frame->linesize[index];
2764 1104 frame->linesize[index] *= -1;
2765 }
2766 }
2767 }
2768
2769
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2494 times.
2499 if (avctx->pix_fmt == AV_PIX_FMT_GBRP) {
2770
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 av_assert0(s->nb_components == 3);
2771 5 FFSWAP(uint8_t *, frame->data[0], frame->data[2]);
2772 5 FFSWAP(uint8_t *, frame->data[0], frame->data[1]);
2773 5 FFSWAP(int, frame->linesize[0], frame->linesize[2]);
2774 5 FFSWAP(int, frame->linesize[0], frame->linesize[1]);
2775 }
2776
2777
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2495 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
2499 if (s->adobe_transform == 0 && avctx->pix_fmt == AV_PIX_FMT_GBRAP) {
2778 int w = s->picture_ptr->width;
2779 int h = s->picture_ptr->height;
2780 av_assert0(s->nb_components == 4);
2781 for (i=0; i<h; i++) {
2782 int j;
2783 uint8_t *dst[4];
2784 for (index=0; index<4; index++) {
2785 dst[index] = s->picture_ptr->data[index]
2786 + s->picture_ptr->linesize[index]*i;
2787 }
2788 for (j=0; j<w; j++) {
2789 int k = dst[3][j];
2790 int r = dst[0][j] * k;
2791 int g = dst[1][j] * k;
2792 int b = dst[2][j] * k;
2793 dst[0][j] = g*257 >> 16;
2794 dst[1][j] = b*257 >> 16;
2795 dst[2][j] = r*257 >> 16;
2796 }
2797 memset(dst[3], 255, w);
2798 }
2799 }
2800
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2499 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2499 if (s->adobe_transform == 2 && avctx->pix_fmt == AV_PIX_FMT_YUVA444P) {
2801 int w = s->picture_ptr->width;
2802 int h = s->picture_ptr->height;
2803 av_assert0(s->nb_components == 4);
2804 for (i=0; i<h; i++) {
2805 int j;
2806 uint8_t *dst[4];
2807 for (index=0; index<4; index++) {
2808 dst[index] = s->picture_ptr->data[index]
2809 + s->picture_ptr->linesize[index]*i;
2810 }
2811 for (j=0; j<w; j++) {
2812 int k = dst[3][j];
2813 int r = (255 - dst[0][j]) * k;
2814 int g = (128 - dst[1][j]) * k;
2815 int b = (128 - dst[2][j]) * k;
2816 dst[0][j] = r*257 >> 16;
2817 dst[1][j] = (g*257 >> 16) + 128;
2818 dst[2][j] = (b*257 >> 16) + 128;
2819 }
2820 memset(dst[3], 255, w);
2821 }
2822 }
2823
2824
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2499 times.
2499 if (s->stereo3d) {
2825 AVStereo3D *stereo = av_stereo3d_create_side_data(frame);
2826 if (stereo) {
2827 stereo->type = s->stereo3d->type;
2828 stereo->flags = s->stereo3d->flags;
2829 }
2830 av_freep(&s->stereo3d);
2831 }
2832
2833
3/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2494 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
2499 if (s->iccnum != 0 && s->iccnum == s->iccread) {
2834 AVFrameSideData *sd;
2835 5 size_t offset = 0;
2836 5 int total_size = 0;
2837 int i;
2838
2839 /* Sum size of all parts. */
2840
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 for (i = 0; i < s->iccnum; i++)
2841 5 total_size += s->iccentries[i].length;
2842
2843 5 ret = ff_frame_new_side_data(avctx, frame, AV_FRAME_DATA_ICC_PROFILE, total_size, &sd);
2844
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (ret < 0) {
2845 av_log(avctx, AV_LOG_ERROR, "Could not allocate frame side data\n");
2846 return ret;
2847 }
2848
2849
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (sd) {
2850 /* Reassemble the parts, which are now in-order. */
2851
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 for (i = 0; i < s->iccnum; i++) {
2852 5 memcpy(sd->data + offset, s->iccentries[i].data, s->iccentries[i].length);
2853 5 offset += s->iccentries[i].length;
2854 }
2855 }
2856 }
2857
2858
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2498 times.
2499 if (e = av_dict_get(s->exif_metadata, "Orientation", e, AV_DICT_IGNORE_SUFFIX)) {
2859 1 char *value = e->value + strspn(e->value, " \n\t\r"), *endptr;
2860 1 int orientation = strtol(value, &endptr, 0);
2861
2862
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (!*endptr) {
2863 1 AVFrameSideData *sd = NULL;
2864
2865
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) {
2866 int32_t *matrix;
2867
2868 sd = av_frame_new_side_data(frame, AV_FRAME_DATA_DISPLAYMATRIX, sizeof(int32_t) * 9);
2869 if (!sd) {
2870 av_log(avctx, AV_LOG_ERROR, "Could not allocate frame side data\n");
2871 return AVERROR(ENOMEM);
2872 }
2873
2874 matrix = (int32_t *)sd->data;
2875
2876 switch (orientation) {
2877 case 2:
2878 av_display_rotation_set(matrix, 0.0);
2879 av_display_matrix_flip(matrix, 1, 0);
2880 break;
2881 case 3:
2882 av_display_rotation_set(matrix, 180.0);
2883 break;
2884 case 4:
2885 av_display_rotation_set(matrix, 180.0);
2886 av_display_matrix_flip(matrix, 1, 0);
2887 break;
2888 case 5:
2889 av_display_rotation_set(matrix, 90.0);
2890 av_display_matrix_flip(matrix, 1, 0);
2891 break;
2892 case 6:
2893 av_display_rotation_set(matrix, 90.0);
2894 break;
2895 case 7:
2896 av_display_rotation_set(matrix, -90.0);
2897 av_display_matrix_flip(matrix, 1, 0);
2898 break;
2899 case 8:
2900 av_display_rotation_set(matrix, -90.0);
2901 break;
2902 default:
2903 av_assert0(0);
2904 }
2905 }
2906 }
2907 }
2908
2909 2499 av_dict_copy(&frame->metadata, s->exif_metadata, 0);
2910 2499 av_dict_free(&s->exif_metadata);
2911
2912
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2496 times.
2499 if (avctx->codec_id != AV_CODEC_ID_SMVJPEG &&
2913
1/2
✓ Branch 0 taken 2496 times.
✗ Branch 1 not taken.
2496 (avctx->codec_tag == MKTAG('A', 'V', 'R', 'n') ||
2914
2/2
✓ Branch 0 taken 2486 times.
✓ Branch 1 taken 10 times.
2496 avctx->codec_tag == MKTAG('A', 'V', 'D', 'J')) &&
2915
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 avctx->coded_height > s->orig_height) {
2916 10 frame->height = AV_CEIL_RSHIFT(avctx->coded_height, avctx->lowres);
2917 10 frame->crop_top = frame->height - avctx->height;
2918 }
2919
2920 2489 the_end_no_picture:
2921 2585 av_log(avctx, AV_LOG_DEBUG, "decode frame unused %"PTRDIFF_SPECIFIER" bytes\n",
2922 buf_end - buf_ptr);
2923 2585 return buf_ptr - buf;
2924 }
2925
2926 2207 int ff_mjpeg_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame,
2927 AVPacket *avpkt)
2928 {
2929 4414 return ff_mjpeg_decode_frame_from_buf(avctx, frame, got_frame,
2930 2207 avpkt, avpkt->data, avpkt->size);
2931 }
2932
2933
2934 /* mxpeg may call the following function (with a blank MJpegDecodeContext)
2935 * even without having called ff_mjpeg_decode_init(). */
2936 211 av_cold int ff_mjpeg_decode_end(AVCodecContext *avctx)
2937 {
2938 211 MJpegDecodeContext *s = avctx->priv_data;
2939 int i, j;
2940
2941
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) {
2942 av_log(avctx, AV_LOG_INFO, "Single field\n");
2943 }
2944
2945
2/2
✓ Branch 0 taken 209 times.
✓ Branch 1 taken 2 times.
211 if (s->picture) {
2946 209 av_frame_free(&s->picture);
2947 209 s->picture_ptr = NULL;
2948
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 } else if (s->picture_ptr)
2949 av_frame_unref(s->picture_ptr);
2950
2951 211 av_frame_free(&s->smv_frame);
2952
2953 211 av_freep(&s->buffer);
2954 211 av_freep(&s->stereo3d);
2955 211 av_freep(&s->ljpeg_buffer);
2956 211 s->ljpeg_buffer_size = 0;
2957
2958
2/2
✓ Branch 0 taken 633 times.
✓ Branch 1 taken 211 times.
844 for (i = 0; i < 3; i++) {
2959
2/2
✓ Branch 0 taken 2532 times.
✓ Branch 1 taken 633 times.
3165 for (j = 0; j < 4; j++)
2960 2532 ff_vlc_free(&s->vlcs[i][j]);
2961 }
2962
2/2
✓ Branch 0 taken 844 times.
✓ Branch 1 taken 211 times.
1055 for (i = 0; i < MAX_COMPONENTS; i++) {
2963 844 av_freep(&s->blocks[i]);
2964 844 av_freep(&s->last_nnz[i]);
2965 }
2966 211 av_dict_free(&s->exif_metadata);
2967
2968 211 reset_icc_profile(s);
2969
2970 211 av_freep(&s->hwaccel_picture_private);
2971 211 av_freep(&s->jls_state);
2972
2973 211 return 0;
2974 }
2975
2976 4 static void decode_flush(AVCodecContext *avctx)
2977 {
2978 4 MJpegDecodeContext *s = avctx->priv_data;
2979 4 s->got_picture = 0;
2980
2981 4 s->smv_next_frame = 0;
2982 4 av_frame_unref(s->smv_frame);
2983 4 }
2984
2985 #if CONFIG_MJPEG_DECODER
2986 #define OFFSET(x) offsetof(MJpegDecodeContext, x)
2987 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
2988 static const AVOption options[] = {
2989 { "extern_huff", "Use external huffman table.",
2990 OFFSET(extern_huff), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
2991 { NULL },
2992 };
2993
2994 static const AVClass mjpegdec_class = {
2995 .class_name = "MJPEG decoder",
2996 .item_name = av_default_item_name,
2997 .option = options,
2998 .version = LIBAVUTIL_VERSION_INT,
2999 };
3000
3001 const FFCodec ff_mjpeg_decoder = {
3002 .p.name = "mjpeg",
3003 CODEC_LONG_NAME("MJPEG (Motion JPEG)"),
3004 .p.type = AVMEDIA_TYPE_VIDEO,
3005 .p.id = AV_CODEC_ID_MJPEG,
3006 .priv_data_size = sizeof(MJpegDecodeContext),
3007 .init = ff_mjpeg_decode_init,
3008 .close = ff_mjpeg_decode_end,
3009 FF_CODEC_DECODE_CB(ff_mjpeg_decode_frame),
3010 .flush = decode_flush,
3011 .p.capabilities = AV_CODEC_CAP_DR1,
3012 .p.max_lowres = 3,
3013 .p.priv_class = &mjpegdec_class,
3014 .p.profiles = NULL_IF_CONFIG_SMALL(ff_mjpeg_profiles),
3015 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
3016 FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM |
3017 FF_CODEC_CAP_ICC_PROFILES,
3018 .hw_configs = (const AVCodecHWConfigInternal *const []) {
3019 #if CONFIG_MJPEG_NVDEC_HWACCEL
3020 HWACCEL_NVDEC(mjpeg),
3021 #endif
3022 #if CONFIG_MJPEG_VAAPI_HWACCEL
3023 HWACCEL_VAAPI(mjpeg),
3024 #endif
3025 NULL
3026 },
3027 };
3028 #endif
3029 #if CONFIG_THP_DECODER
3030 const FFCodec ff_thp_decoder = {
3031 .p.name = "thp",
3032 CODEC_LONG_NAME("Nintendo Gamecube THP video"),
3033 .p.type = AVMEDIA_TYPE_VIDEO,
3034 .p.id = AV_CODEC_ID_THP,
3035 .priv_data_size = sizeof(MJpegDecodeContext),
3036 .init = ff_mjpeg_decode_init,
3037 .close = ff_mjpeg_decode_end,
3038 FF_CODEC_DECODE_CB(ff_mjpeg_decode_frame),
3039 .flush = decode_flush,
3040 .p.capabilities = AV_CODEC_CAP_DR1,
3041 .p.max_lowres = 3,
3042 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
3043 };
3044 #endif
3045
3046 #if CONFIG_SMVJPEG_DECODER
3047 // SMV JPEG just stacks several output frames into one JPEG picture
3048 // we handle that by setting up the cropping parameters appropriately
3049 13 static void smv_process_frame(AVCodecContext *avctx, AVFrame *frame)
3050 {
3051 13 MJpegDecodeContext *s = avctx->priv_data;
3052
3053
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
13 av_assert0((s->smv_next_frame + 1) * avctx->height <= avctx->coded_height);
3054
3055 13 frame->width = avctx->coded_width;
3056 13 frame->height = avctx->coded_height;
3057 13 frame->crop_top = FFMIN(s->smv_next_frame * avctx->height, frame->height);
3058 13 frame->crop_bottom = frame->height - (s->smv_next_frame + 1) * avctx->height;
3059
3060
1/2
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
13 if (s->smv_frame->pts != AV_NOPTS_VALUE)
3061 13 s->smv_frame->pts += s->smv_frame->duration;
3062 13 s->smv_next_frame = (s->smv_next_frame + 1) % s->smv_frames_per_jpeg;
3063
3064
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 11 times.
13 if (s->smv_next_frame == 0)
3065 2 av_frame_unref(s->smv_frame);
3066 13 }
3067
3068 16 static int smvjpeg_receive_frame(AVCodecContext *avctx, AVFrame *frame)
3069 {
3070 16 MJpegDecodeContext *s = avctx->priv_data;
3071 16 AVPacket *const pkt = avctx->internal->in_pkt;
3072 16 int got_frame = 0;
3073 int ret;
3074
3075
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 6 times.
16 if (s->smv_next_frame > 0)
3076 10 goto return_frame;
3077
3078 6 ret = ff_decode_get_packet(avctx, pkt);
3079
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if (ret < 0)
3080 3 return ret;
3081
3082 3 av_frame_unref(s->smv_frame);
3083
3084 3 ret = ff_mjpeg_decode_frame(avctx, s->smv_frame, &got_frame, pkt);
3085 3 s->smv_frame->pkt_dts = pkt->dts;
3086 3 av_packet_unref(pkt);
3087
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (ret < 0)
3088 return ret;
3089
3090
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!got_frame)
3091 return AVERROR(EAGAIN);
3092
3093 // packet duration covers all the frames in the packet
3094 3 s->smv_frame->duration /= s->smv_frames_per_jpeg;
3095
3096 13 return_frame:
3097
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
13 av_assert0(s->smv_frame->buf[0]);
3098 13 ret = av_frame_ref(frame, s->smv_frame);
3099
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
13 if (ret < 0)
3100 return ret;
3101
3102 13 smv_process_frame(avctx, frame);
3103 13 return 0;
3104 }
3105
3106 const FFCodec ff_smvjpeg_decoder = {
3107 .p.name = "smvjpeg",
3108 CODEC_LONG_NAME("SMV JPEG"),
3109 .p.type = AVMEDIA_TYPE_VIDEO,
3110 .p.id = AV_CODEC_ID_SMVJPEG,
3111 .priv_data_size = sizeof(MJpegDecodeContext),
3112 .init = ff_mjpeg_decode_init,
3113 .close = ff_mjpeg_decode_end,
3114 FF_CODEC_RECEIVE_FRAME_CB(smvjpeg_receive_frame),
3115 .flush = decode_flush,
3116 .p.capabilities = AV_CODEC_CAP_DR1,
3117 .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING |
3118 FF_CODEC_CAP_INIT_CLEANUP,
3119 };
3120 #endif
3121