FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/mjpegdec.c
Date: 2026-01-23 19:11:46
Exec Total Coverage
Lines: 1232 1830 67.3%
Functions: 33 34 97.1%
Branches: 912 1689 54.0%

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