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