• Home
  • Raw
  • Download

Lines Matching +full:- +full:s

5  * Copyright (c) 2003-2004 Michael Niedermayer
8 * aspecting, new decode_frame mechanism and apple mjpeg-b support
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
54 static int init_default_huffman_tables(MJpegDecodeContext *s) in init_default_huffman_tables() argument
79 ff_free_vlc(&s->vlcs[ht[i].class][ht[i].index]); in init_default_huffman_tables()
80 ret = ff_mjpeg_build_vlc(&s->vlcs[ht[i].class][ht[i].index], in init_default_huffman_tables()
82 ht[i].class == 1, s->avctx); in init_default_huffman_tables()
87 memcpy(s->raw_huffman_lengths[ht[i].class][ht[i].index], in init_default_huffman_tables()
89 memcpy(s->raw_huffman_values[ht[i].class][ht[i].index], in init_default_huffman_tables()
97 static void parse_avid(MJpegDecodeContext *s, uint8_t *buf, int len) in parse_avid() argument
99 s->buggy_avid = 1; in parse_avid()
100 if (len > 14 && buf[12] == 1) /* 1 - NTSC */ in parse_avid()
101 s->interlace_polarity = 1; in parse_avid()
102 if (len > 14 && buf[12] == 2) /* 2 - PAL */ in parse_avid()
103 s->interlace_polarity = 0; in parse_avid()
104 if (s->avctx->debug & FF_DEBUG_PICT_INFO) in parse_avid()
105 av_log(s->avctx, AV_LOG_INFO, "AVID: len:%d %d\n", len, len > 14 ? buf[12] : -1); in parse_avid()
110 MJpegDecodeContext *s = avctx->priv_data; in init_idct() local
112 ff_idctdsp_init(&s->idsp, avctx); in init_idct()
113 ff_init_scantable(s->idsp.idct_permutation, &s->scantable, in init_idct()
119 MJpegDecodeContext *s = avctx->priv_data; in ff_mjpeg_decode_init() local
122 if (!s->picture_ptr) { in ff_mjpeg_decode_init()
123 s->picture = av_frame_alloc(); in ff_mjpeg_decode_init()
124 if (!s->picture) in ff_mjpeg_decode_init()
126 s->picture_ptr = s->picture; in ff_mjpeg_decode_init()
129 s->pkt = av_packet_alloc(); in ff_mjpeg_decode_init()
130 if (!s->pkt) in ff_mjpeg_decode_init()
133 s->avctx = avctx; in ff_mjpeg_decode_init()
134 ff_blockdsp_init(&s->bdsp, avctx); in ff_mjpeg_decode_init()
135 ff_hpeldsp_init(&s->hdsp, avctx->flags); in ff_mjpeg_decode_init()
137 s->buffer_size = 0; in ff_mjpeg_decode_init()
138 s->buffer = NULL; in ff_mjpeg_decode_init()
139 s->start_code = -1; in ff_mjpeg_decode_init()
140 s->first_picture = 1; in ff_mjpeg_decode_init()
141 s->got_picture = 0; in ff_mjpeg_decode_init()
142 s->orig_height = avctx->coded_height; in ff_mjpeg_decode_init()
143 avctx->chroma_sample_location = AVCHROMA_LOC_CENTER; in ff_mjpeg_decode_init()
144 avctx->colorspace = AVCOL_SPC_BT470BG; in ff_mjpeg_decode_init()
145 s->hwaccel_pix_fmt = s->hwaccel_sw_pix_fmt = AV_PIX_FMT_NONE; in ff_mjpeg_decode_init()
147 if ((ret = init_default_huffman_tables(s)) < 0) in ff_mjpeg_decode_init()
150 if (s->extern_huff) { in ff_mjpeg_decode_init()
152 if ((ret = init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size * 8)) < 0) in ff_mjpeg_decode_init()
154 if (ff_mjpeg_decode_dht(s)) { in ff_mjpeg_decode_init()
157 if ((ret = init_default_huffman_tables(s)) < 0) in ff_mjpeg_decode_init()
161 if (avctx->field_order == AV_FIELD_BB) { /* quicktime icefloe 019 */ in ff_mjpeg_decode_init()
162 s->interlace_polarity = 1; /* bottom field first */ in ff_mjpeg_decode_init()
164 } else if (avctx->field_order == AV_FIELD_UNKNOWN) { in ff_mjpeg_decode_init()
165 if (avctx->codec_tag == AV_RL32("MJPG")) in ff_mjpeg_decode_init()
166 s->interlace_polarity = 1; in ff_mjpeg_decode_init()
169 if (avctx->codec_id == AV_CODEC_ID_SMVJPEG) { in ff_mjpeg_decode_init()
170 if (avctx->extradata_size >= 4) in ff_mjpeg_decode_init()
171 s->smv_frames_per_jpeg = AV_RL32(avctx->extradata); in ff_mjpeg_decode_init()
173 if (s->smv_frames_per_jpeg <= 0) { in ff_mjpeg_decode_init()
178 s->smv_frame = av_frame_alloc(); in ff_mjpeg_decode_init()
179 if (!s->smv_frame) in ff_mjpeg_decode_init()
181 } else if (avctx->extradata_size > 8 in ff_mjpeg_decode_init()
182 && AV_RL32(avctx->extradata) == 0x2C in ff_mjpeg_decode_init()
183 && AV_RL32(avctx->extradata+4) == 0x18) { in ff_mjpeg_decode_init()
184 parse_avid(s, avctx->extradata, avctx->extradata_size); in ff_mjpeg_decode_init()
187 if (avctx->codec->id == AV_CODEC_ID_AMV) in ff_mjpeg_decode_init()
188 s->flipped = 1; in ff_mjpeg_decode_init()
195 int ff_mjpeg_decode_dqt(MJpegDecodeContext *s) in ff_mjpeg_decode_dqt() argument
199 len = get_bits(&s->gb, 16) - 2; in ff_mjpeg_decode_dqt()
201 if (8*len > get_bits_left(&s->gb)) { in ff_mjpeg_decode_dqt()
202 av_log(s->avctx, AV_LOG_ERROR, "dqt: len %d is too large\n", len); in ff_mjpeg_decode_dqt()
207 int pr = get_bits(&s->gb, 4); in ff_mjpeg_decode_dqt()
209 av_log(s->avctx, AV_LOG_ERROR, "dqt: invalid precision\n"); in ff_mjpeg_decode_dqt()
212 index = get_bits(&s->gb, 4); in ff_mjpeg_decode_dqt()
214 return -1; in ff_mjpeg_decode_dqt()
215 av_log(s->avctx, AV_LOG_DEBUG, "index=%d\n", index); in ff_mjpeg_decode_dqt()
218 s->quant_matrixes[index][i] = get_bits(&s->gb, pr ? 16 : 8); in ff_mjpeg_decode_dqt()
219 if (s->quant_matrixes[index][i] == 0) { in ff_mjpeg_decode_dqt()
220 av_log(s->avctx, AV_LOG_ERROR, "dqt: 0 quant value\n"); in ff_mjpeg_decode_dqt()
225 // XXX FIXME fine-tune, and perhaps add dc too in ff_mjpeg_decode_dqt()
226 s->qscale[index] = FFMAX(s->quant_matrixes[index][1], in ff_mjpeg_decode_dqt()
227 s->quant_matrixes[index][8]) >> 1; in ff_mjpeg_decode_dqt()
228 av_log(s->avctx, AV_LOG_DEBUG, "qscale[%d]: %d\n", in ff_mjpeg_decode_dqt()
229 index, s->qscale[index]); in ff_mjpeg_decode_dqt()
230 len -= 1 + 64 * (1+pr); in ff_mjpeg_decode_dqt()
236 int ff_mjpeg_decode_dht(MJpegDecodeContext *s) in ff_mjpeg_decode_dht() argument
243 len = get_bits(&s->gb, 16) - 2; in ff_mjpeg_decode_dht()
245 if (8*len > get_bits_left(&s->gb)) { in ff_mjpeg_decode_dht()
246 av_log(s->avctx, AV_LOG_ERROR, "dht: len %d is too large\n", len); in ff_mjpeg_decode_dht()
253 class = get_bits(&s->gb, 4); in ff_mjpeg_decode_dht()
256 index = get_bits(&s->gb, 4); in ff_mjpeg_decode_dht()
261 bits_table[i] = get_bits(&s->gb, 8); in ff_mjpeg_decode_dht()
264 len -= 17; in ff_mjpeg_decode_dht()
269 v = get_bits(&s->gb, 8); in ff_mjpeg_decode_dht()
272 len -= n; in ff_mjpeg_decode_dht()
275 ff_free_vlc(&s->vlcs[class][index]); in ff_mjpeg_decode_dht()
276 av_log(s->avctx, AV_LOG_DEBUG, "class=%d index=%d nb_codes=%d\n", in ff_mjpeg_decode_dht()
278 if ((ret = ff_mjpeg_build_vlc(&s->vlcs[class][index], bits_table, in ff_mjpeg_decode_dht()
279 val_table, class > 0, s->avctx)) < 0) in ff_mjpeg_decode_dht()
283 ff_free_vlc(&s->vlcs[2][index]); in ff_mjpeg_decode_dht()
284 if ((ret = ff_mjpeg_build_vlc(&s->vlcs[2][index], bits_table, in ff_mjpeg_decode_dht()
285 val_table, 0, s->avctx)) < 0) in ff_mjpeg_decode_dht()
290 s->raw_huffman_lengths[class][index][i] = bits_table[i + 1]; in ff_mjpeg_decode_dht()
292 s->raw_huffman_values[class][index][i] = val_table[i]; in ff_mjpeg_decode_dht()
297 int ff_mjpeg_decode_sof(MJpegDecodeContext *s) in ff_mjpeg_decode_sof() argument
304 s->cur_scan = 0; in ff_mjpeg_decode_sof()
305 memset(s->upscale_h, 0, sizeof(s->upscale_h)); in ff_mjpeg_decode_sof()
306 memset(s->upscale_v, 0, sizeof(s->upscale_v)); in ff_mjpeg_decode_sof()
308 len = get_bits(&s->gb, 16); in ff_mjpeg_decode_sof()
309 bits = get_bits(&s->gb, 8); in ff_mjpeg_decode_sof()
312 av_log(s->avctx, AV_LOG_ERROR, "bits %d is invalid\n", bits); in ff_mjpeg_decode_sof()
316 if (s->avctx->bits_per_raw_sample != bits) { in ff_mjpeg_decode_sof()
317 …av_log(s->avctx, s->avctx->bits_per_raw_sample > 0 ? AV_LOG_INFO : AV_LOG_DEBUG, "Changing bps fro… in ff_mjpeg_decode_sof()
318 s->avctx->bits_per_raw_sample = bits; in ff_mjpeg_decode_sof()
319 init_idct(s->avctx); in ff_mjpeg_decode_sof()
321 if (s->pegasus_rct) in ff_mjpeg_decode_sof()
323 if (bits == 9 && !s->pegasus_rct) in ff_mjpeg_decode_sof()
324 s->rct = 1; // FIXME ugly in ff_mjpeg_decode_sof()
326 if(s->lossless && s->avctx->lowres){ in ff_mjpeg_decode_sof()
327 av_log(s->avctx, AV_LOG_ERROR, "lowres is not possible with lossless jpeg\n"); in ff_mjpeg_decode_sof()
328 return -1; in ff_mjpeg_decode_sof()
331 height = get_bits(&s->gb, 16); in ff_mjpeg_decode_sof()
332 width = get_bits(&s->gb, 16); in ff_mjpeg_decode_sof()
335 if (s->interlaced && s->width == width && s->height == height + 1) in ff_mjpeg_decode_sof()
336 height= s->height; in ff_mjpeg_decode_sof()
338 av_log(s->avctx, AV_LOG_DEBUG, "sof0: picture: %dx%d\n", width, height); in ff_mjpeg_decode_sof()
339 if (av_image_check_size(width, height, 0, s->avctx) < 0) in ff_mjpeg_decode_sof()
341 if (s->buf_size && (width + 7) / 8 * ((height + 7) / 8) > s->buf_size * 4LL) in ff_mjpeg_decode_sof()
344 nb_components = get_bits(&s->gb, 8); in ff_mjpeg_decode_sof()
347 return -1; in ff_mjpeg_decode_sof()
348 if (s->interlaced && (s->bottom_field == !s->interlace_polarity)) { in ff_mjpeg_decode_sof()
349 if (nb_components != s->nb_components) { in ff_mjpeg_decode_sof()
350 av_log(s->avctx, AV_LOG_ERROR, in ff_mjpeg_decode_sof()
355 if (s->ls && !(bits <= 8 || nb_components == 1)) { in ff_mjpeg_decode_sof()
356 avpriv_report_missing_feature(s->avctx, in ff_mjpeg_decode_sof()
357 "JPEG-LS that is not <= 8 " in ff_mjpeg_decode_sof()
358 "bits/component or 16-bit gray"); in ff_mjpeg_decode_sof()
362 …av_log(s->avctx, AV_LOG_ERROR, "decode_sof0: error, len(%d) mismatch %d components\n", len, nb_com… in ff_mjpeg_decode_sof()
366 s->nb_components = nb_components; in ff_mjpeg_decode_sof()
367 s->h_max = 1; in ff_mjpeg_decode_sof()
368 s->v_max = 1; in ff_mjpeg_decode_sof()
371 s->component_id[i] = get_bits(&s->gb, 8) - 1; in ff_mjpeg_decode_sof()
372 h_count[i] = get_bits(&s->gb, 4); in ff_mjpeg_decode_sof()
373 v_count[i] = get_bits(&s->gb, 4); in ff_mjpeg_decode_sof()
375 if (h_count[i] > s->h_max) in ff_mjpeg_decode_sof()
376 s->h_max = h_count[i]; in ff_mjpeg_decode_sof()
377 if (v_count[i] > s->v_max) in ff_mjpeg_decode_sof()
378 s->v_max = v_count[i]; in ff_mjpeg_decode_sof()
379 s->quant_index[i] = get_bits(&s->gb, 8); in ff_mjpeg_decode_sof()
380 if (s->quant_index[i] >= 4) { in ff_mjpeg_decode_sof()
381 av_log(s->avctx, AV_LOG_ERROR, "quant_index is invalid\n"); in ff_mjpeg_decode_sof()
385 av_log(s->avctx, AV_LOG_ERROR, in ff_mjpeg_decode_sof()
391 av_log(s->avctx, AV_LOG_DEBUG, "component %d %d:%d id: %d quant:%d\n", in ff_mjpeg_decode_sof()
393 s->component_id[i], s->quant_index[i]); in ff_mjpeg_decode_sof()
396 && s->component_id[0] == 'C' - 1 in ff_mjpeg_decode_sof()
397 && s->component_id[1] == 'M' - 1 in ff_mjpeg_decode_sof()
398 && s->component_id[2] == 'Y' - 1 in ff_mjpeg_decode_sof()
399 && s->component_id[3] == 'K' - 1) in ff_mjpeg_decode_sof()
400 s->adobe_transform = 0; in ff_mjpeg_decode_sof()
402 if (s->ls && (s->h_max > 1 || s->v_max > 1)) { in ff_mjpeg_decode_sof()
403 avpriv_report_missing_feature(s->avctx, "Subsampling in JPEG-LS"); in ff_mjpeg_decode_sof()
407 if (s->bayer) { in ff_mjpeg_decode_sof()
421 if (width != s->width || height != s->height || bits != s->bits || in ff_mjpeg_decode_sof()
422 memcmp(s->h_count, h_count, sizeof(h_count)) || in ff_mjpeg_decode_sof()
423 memcmp(s->v_count, v_count, sizeof(v_count))) { in ff_mjpeg_decode_sof()
426 s->width = width; in ff_mjpeg_decode_sof()
427 s->height = height; in ff_mjpeg_decode_sof()
428 s->bits = bits; in ff_mjpeg_decode_sof()
429 memcpy(s->h_count, h_count, sizeof(h_count)); in ff_mjpeg_decode_sof()
430 memcpy(s->v_count, v_count, sizeof(v_count)); in ff_mjpeg_decode_sof()
431 s->interlaced = 0; in ff_mjpeg_decode_sof()
432 s->got_picture = 0; in ff_mjpeg_decode_sof()
435 if (s->first_picture && in ff_mjpeg_decode_sof()
436 (s->multiscope != 2 || s->avctx->time_base.den >= 25 * s->avctx->time_base.num) && in ff_mjpeg_decode_sof()
437 s->orig_height != 0 && in ff_mjpeg_decode_sof()
438 s->height < ((s->orig_height * 3) / 4)) { in ff_mjpeg_decode_sof()
439 s->interlaced = 1; in ff_mjpeg_decode_sof()
440 s->bottom_field = s->interlace_polarity; in ff_mjpeg_decode_sof()
441 s->picture_ptr->interlaced_frame = 1; in ff_mjpeg_decode_sof()
442 s->picture_ptr->top_field_first = !s->interlace_polarity; in ff_mjpeg_decode_sof()
446 ret = ff_set_dimensions(s->avctx, width, height); in ff_mjpeg_decode_sof()
450 if ((s->avctx->codec_tag == MKTAG('A', 'V', 'R', 'n') || in ff_mjpeg_decode_sof()
451 s->avctx->codec_tag == MKTAG('A', 'V', 'D', 'J')) && in ff_mjpeg_decode_sof()
452 s->orig_height < height) in ff_mjpeg_decode_sof()
453 s->avctx->height = AV_CEIL_RSHIFT(s->orig_height, s->avctx->lowres); in ff_mjpeg_decode_sof()
455 s->first_picture = 0; in ff_mjpeg_decode_sof()
460 if (s->avctx->codec_id == AV_CODEC_ID_SMVJPEG) { in ff_mjpeg_decode_sof()
461 s->avctx->height = s->avctx->coded_height / s->smv_frames_per_jpeg; in ff_mjpeg_decode_sof()
462 if (s->avctx->height <= 0) in ff_mjpeg_decode_sof()
466 if (s->got_picture && s->interlaced && (s->bottom_field == !s->interlace_polarity)) { in ff_mjpeg_decode_sof()
467 if (s->progressive) { in ff_mjpeg_decode_sof()
468 avpriv_request_sample(s->avctx, "progressively coded interlaced picture"); in ff_mjpeg_decode_sof()
472 … if (s->v_max == 1 && s->h_max == 1 && s->lossless==1 && (nb_components==3 || nb_components==4)) in ff_mjpeg_decode_sof()
473 s->rgb = 1; in ff_mjpeg_decode_sof()
474 else if (!s->lossless) in ff_mjpeg_decode_sof()
475 s->rgb = 0; in ff_mjpeg_decode_sof()
477 pix_fmt_id = ((unsigned)s->h_count[0] << 28) | (s->v_count[0] << 24) | in ff_mjpeg_decode_sof()
478 (s->h_count[1] << 20) | (s->v_count[1] << 16) | in ff_mjpeg_decode_sof()
479 (s->h_count[2] << 12) | (s->v_count[2] << 8) | in ff_mjpeg_decode_sof()
480 (s->h_count[3] << 4) | s->v_count[3]; in ff_mjpeg_decode_sof()
481 av_log(s->avctx, AV_LOG_DEBUG, "pix fmt id %x\n", pix_fmt_id); in ff_mjpeg_decode_sof()
485 pix_fmt_id -= (pix_fmt_id & 0xF0F0F0F0) >> 1; in ff_mjpeg_decode_sof()
487 pix_fmt_id -= (pix_fmt_id & 0x0F0F0F0F) >> 1; in ff_mjpeg_decode_sof()
490 int j = 6 + (i&1) - (i&6); in ff_mjpeg_decode_sof()
500 if (i & 1) s->upscale_h[j/2] = 1; in ff_mjpeg_decode_sof()
501 else s->upscale_v[j/2] = 1; in ff_mjpeg_decode_sof()
505 if (s->bayer) { in ff_mjpeg_decode_sof()
511 case 0x11110000: /* for bayer-encoded huffman lossless JPEGs embedded in DNGs */ in ff_mjpeg_decode_sof()
512 if (!s->bayer) in ff_mjpeg_decode_sof()
514 s->avctx->pix_fmt = AV_PIX_FMT_GRAY16LE; in ff_mjpeg_decode_sof()
517 if (s->rgb) in ff_mjpeg_decode_sof()
518 s->avctx->pix_fmt = s->bits <= 9 ? AV_PIX_FMT_BGR24 : AV_PIX_FMT_BGR48; in ff_mjpeg_decode_sof()
520 if ( s->adobe_transform == 0 in ff_mjpeg_decode_sof()
521 …|| s->component_id[0] == 'R' - 1 && s->component_id[1] == 'G' - 1 && s->component_id[2] == 'B' - 1… in ff_mjpeg_decode_sof()
522 s->avctx->pix_fmt = s->bits <= 8 ? AV_PIX_FMT_GBRP : AV_PIX_FMT_GBRP16; in ff_mjpeg_decode_sof()
524 … if (s->bits <= 8) s->avctx->pix_fmt = s->cs_itu601 ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_YUVJ444P; in ff_mjpeg_decode_sof()
525 else s->avctx->pix_fmt = AV_PIX_FMT_YUV444P16; in ff_mjpeg_decode_sof()
526 s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG; in ff_mjpeg_decode_sof()
529 av_assert0(s->nb_components == 3); in ff_mjpeg_decode_sof()
532 if (s->rgb) in ff_mjpeg_decode_sof()
533 s->avctx->pix_fmt = s->bits <= 9 ? AV_PIX_FMT_ABGR : AV_PIX_FMT_RGBA64; in ff_mjpeg_decode_sof()
535 if (s->adobe_transform == 0 && s->bits <= 8) { in ff_mjpeg_decode_sof()
536 s->avctx->pix_fmt = AV_PIX_FMT_GBRAP; in ff_mjpeg_decode_sof()
538 s->avctx->pix_fmt = s->bits <= 8 ? AV_PIX_FMT_YUVA444P : AV_PIX_FMT_YUVA444P16; in ff_mjpeg_decode_sof()
539 s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG; in ff_mjpeg_decode_sof()
542 av_assert0(s->nb_components == 4); in ff_mjpeg_decode_sof()
546 if (s->adobe_transform == 0 && s->bits <= 8) { in ff_mjpeg_decode_sof()
547 s->avctx->pix_fmt = AV_PIX_FMT_GBRAP; in ff_mjpeg_decode_sof()
548 s->upscale_v[1] = s->upscale_v[2] = 1; in ff_mjpeg_decode_sof()
549 s->upscale_h[1] = s->upscale_h[2] = 1; in ff_mjpeg_decode_sof()
550 } else if (s->adobe_transform == 2 && s->bits <= 8) { in ff_mjpeg_decode_sof()
551 s->avctx->pix_fmt = AV_PIX_FMT_YUVA444P; in ff_mjpeg_decode_sof()
552 s->upscale_v[1] = s->upscale_v[2] = 1; in ff_mjpeg_decode_sof()
553 s->upscale_h[1] = s->upscale_h[2] = 1; in ff_mjpeg_decode_sof()
554 s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG; in ff_mjpeg_decode_sof()
556 if (s->bits <= 8) s->avctx->pix_fmt = AV_PIX_FMT_YUVA420P; in ff_mjpeg_decode_sof()
557 else s->avctx->pix_fmt = AV_PIX_FMT_YUVA420P16; in ff_mjpeg_decode_sof()
558 s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG; in ff_mjpeg_decode_sof()
560 av_assert0(s->nb_components == 4); in ff_mjpeg_decode_sof()
569 … if (s->bits <= 8) s->avctx->pix_fmt = s->cs_itu601 ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_YUVJ444P; in ff_mjpeg_decode_sof()
572 s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG; in ff_mjpeg_decode_sof()
583 if(s->bits <= 8) in ff_mjpeg_decode_sof()
584 s->avctx->pix_fmt = AV_PIX_FMT_GRAY8; in ff_mjpeg_decode_sof()
586 s->avctx->pix_fmt = AV_PIX_FMT_GRAY16; in ff_mjpeg_decode_sof()
593 … if (s->component_id[0] == 'Q' && s->component_id[1] == 'F' && s->component_id[2] == 'A') { in ff_mjpeg_decode_sof()
594 if (s->bits <= 8) s->avctx->pix_fmt = AV_PIX_FMT_GBRP; in ff_mjpeg_decode_sof()
597 s->upscale_v[0] = s->upscale_v[1] = 1; in ff_mjpeg_decode_sof()
600 s->upscale_v[1] = s->upscale_v[2] = 1; in ff_mjpeg_decode_sof()
601 … if (s->bits <= 8) s->avctx->pix_fmt = s->cs_itu601 ? AV_PIX_FMT_YUV440P : AV_PIX_FMT_YUVJ440P; in ff_mjpeg_decode_sof()
604 s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG; in ff_mjpeg_decode_sof()
608 … if (s->component_id[0] == 'Q' && s->component_id[1] == 'F' && s->component_id[2] == 'A') { in ff_mjpeg_decode_sof()
609 if (s->bits <= 8) s->avctx->pix_fmt = AV_PIX_FMT_GBRP; in ff_mjpeg_decode_sof()
612 s->upscale_h[0] = s->upscale_h[1] = 1; in ff_mjpeg_decode_sof()
614 … if (s->bits <= 8) s->avctx->pix_fmt = s->cs_itu601 ? AV_PIX_FMT_YUV422P : AV_PIX_FMT_YUVJ422P; in ff_mjpeg_decode_sof()
615 else s->avctx->pix_fmt = AV_PIX_FMT_YUV422P16; in ff_mjpeg_decode_sof()
616 s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG; in ff_mjpeg_decode_sof()
620 if (s->bits > 8) in ff_mjpeg_decode_sof()
622 s->avctx->pix_fmt = s->cs_itu601 ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_YUVJ444P; in ff_mjpeg_decode_sof()
623 s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG; in ff_mjpeg_decode_sof()
624 s->upscale_h[1] = s->upscale_h[2] = 2; in ff_mjpeg_decode_sof()
628 … if (s->bits <= 8) s->avctx->pix_fmt = s->cs_itu601 ? AV_PIX_FMT_YUV422P : AV_PIX_FMT_YUVJ422P; in ff_mjpeg_decode_sof()
631 s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG; in ff_mjpeg_decode_sof()
637 … if (s->bits <= 8) s->avctx->pix_fmt = s->cs_itu601 ? AV_PIX_FMT_YUV420P : AV_PIX_FMT_YUVJ420P; in ff_mjpeg_decode_sof()
638 else s->avctx->pix_fmt = AV_PIX_FMT_YUV420P16; in ff_mjpeg_decode_sof()
639 s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG; in ff_mjpeg_decode_sof()
641 if (s->bits > 8) in ff_mjpeg_decode_sof()
643 s->upscale_h[1] = s->upscale_h[2] = 1; in ff_mjpeg_decode_sof()
645 if (s->bits > 8) in ff_mjpeg_decode_sof()
647 s->upscale_v[1] = s->upscale_v[2] = 1; in ff_mjpeg_decode_sof()
649 if (s->bits > 8) in ff_mjpeg_decode_sof()
651 s->upscale_v[1] = s->upscale_v[2] = 2; in ff_mjpeg_decode_sof()
655 … if (s->bits <= 8) s->avctx->pix_fmt = s->cs_itu601 ? AV_PIX_FMT_YUV411P : AV_PIX_FMT_YUVJ411P; in ff_mjpeg_decode_sof()
658 s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG; in ff_mjpeg_decode_sof()
662 … avpriv_report_missing_feature(s->avctx, "Pixel format 0x%x bits:%d", pix_fmt_id, s->bits); in ff_mjpeg_decode_sof()
663 memset(s->upscale_h, 0, sizeof(s->upscale_h)); in ff_mjpeg_decode_sof()
664 memset(s->upscale_v, 0, sizeof(s->upscale_v)); in ff_mjpeg_decode_sof()
667 if ((AV_RB32(s->upscale_h) || AV_RB32(s->upscale_v)) && s->avctx->lowres) { in ff_mjpeg_decode_sof()
668 avpriv_report_missing_feature(s->avctx, "Lowres for weird subsampling"); in ff_mjpeg_decode_sof()
671 …if ((AV_RB32(s->upscale_h) || AV_RB32(s->upscale_v)) && s->progressive && s->avctx->pix_fmt == AV_… in ff_mjpeg_decode_sof()
672 avpriv_report_missing_feature(s->avctx, "progressive for weird subsampling"); in ff_mjpeg_decode_sof()
675 if (s->ls) { in ff_mjpeg_decode_sof()
676 memset(s->upscale_h, 0, sizeof(s->upscale_h)); in ff_mjpeg_decode_sof()
677 memset(s->upscale_v, 0, sizeof(s->upscale_v)); in ff_mjpeg_decode_sof()
678 if (s->nb_components == 3) { in ff_mjpeg_decode_sof()
679 s->avctx->pix_fmt = AV_PIX_FMT_RGB24; in ff_mjpeg_decode_sof()
680 } else if (s->nb_components != 1) { in ff_mjpeg_decode_sof()
681 … av_log(s->avctx, AV_LOG_ERROR, "Unsupported number of components %d\n", s->nb_components); in ff_mjpeg_decode_sof()
683 } else if (s->palette_index && s->bits <= 8) in ff_mjpeg_decode_sof()
684 s->avctx->pix_fmt = AV_PIX_FMT_PAL8; in ff_mjpeg_decode_sof()
685 else if (s->bits <= 8) in ff_mjpeg_decode_sof()
686 s->avctx->pix_fmt = AV_PIX_FMT_GRAY8; in ff_mjpeg_decode_sof()
688 s->avctx->pix_fmt = AV_PIX_FMT_GRAY16; in ff_mjpeg_decode_sof()
691 s->pix_desc = av_pix_fmt_desc_get(s->avctx->pix_fmt); in ff_mjpeg_decode_sof()
692 if (!s->pix_desc) { in ff_mjpeg_decode_sof()
693 av_log(s->avctx, AV_LOG_ERROR, "Could not get a pixel format descriptor.\n"); in ff_mjpeg_decode_sof()
697 if (s->avctx->pix_fmt == s->hwaccel_sw_pix_fmt && !size_change) { in ff_mjpeg_decode_sof()
698 s->avctx->pix_fmt = s->hwaccel_pix_fmt; in ff_mjpeg_decode_sof()
707 s->avctx->pix_fmt, in ff_mjpeg_decode_sof() enumerator
710 s->hwaccel_pix_fmt = ff_get_format(s->avctx, pix_fmts); in ff_mjpeg_decode_sof()
711 if (s->hwaccel_pix_fmt < 0) in ff_mjpeg_decode_sof()
714 s->hwaccel_sw_pix_fmt = s->avctx->pix_fmt; in ff_mjpeg_decode_sof()
715 s->avctx->pix_fmt = s->hwaccel_pix_fmt; in ff_mjpeg_decode_sof()
718 if (s->avctx->skip_frame == AVDISCARD_ALL) { in ff_mjpeg_decode_sof()
719 s->picture_ptr->pict_type = AV_PICTURE_TYPE_I; in ff_mjpeg_decode_sof()
720 s->picture_ptr->key_frame = 1; in ff_mjpeg_decode_sof()
721 s->got_picture = 1; in ff_mjpeg_decode_sof()
725 av_frame_unref(s->picture_ptr); in ff_mjpeg_decode_sof()
726 if (ff_get_buffer(s->avctx, s->picture_ptr, AV_GET_BUFFER_FLAG_REF) < 0) in ff_mjpeg_decode_sof()
727 return -1; in ff_mjpeg_decode_sof()
728 s->picture_ptr->pict_type = AV_PICTURE_TYPE_I; in ff_mjpeg_decode_sof()
729 s->picture_ptr->key_frame = 1; in ff_mjpeg_decode_sof()
730 s->got_picture = 1; in ff_mjpeg_decode_sof()
733 s->linesize[i] = s->picture_ptr->linesize[i] << s->interlaced; in ff_mjpeg_decode_sof()
735 ff_dlog(s->avctx, "%d %d %d %d %d %d\n", in ff_mjpeg_decode_sof()
736 s->width, s->height, s->linesize[0], s->linesize[1], in ff_mjpeg_decode_sof()
737 s->interlaced, s->avctx->height); in ff_mjpeg_decode_sof()
741 if ((s->rgb && !s->lossless && !s->ls) || in ff_mjpeg_decode_sof()
742 (!s->rgb && s->ls && s->nb_components > 1) || in ff_mjpeg_decode_sof()
743 (s->avctx->pix_fmt == AV_PIX_FMT_PAL8 && !s->ls) in ff_mjpeg_decode_sof()
745 av_log(s->avctx, AV_LOG_ERROR, "Unsupported coding and pixel format combination\n"); in ff_mjpeg_decode_sof()
750 if (s->progressive) { in ff_mjpeg_decode_sof()
751 int bw = (width + s->h_max * 8 - 1) / (s->h_max * 8); in ff_mjpeg_decode_sof()
752 int bh = (height + s->v_max * 8 - 1) / (s->v_max * 8); in ff_mjpeg_decode_sof()
753 for (i = 0; i < s->nb_components; i++) { in ff_mjpeg_decode_sof()
754 int size = bw * bh * s->h_count[i] * s->v_count[i]; in ff_mjpeg_decode_sof()
755 av_freep(&s->blocks[i]); in ff_mjpeg_decode_sof()
756 av_freep(&s->last_nnz[i]); in ff_mjpeg_decode_sof()
757 s->blocks[i] = av_mallocz_array(size, sizeof(**s->blocks)); in ff_mjpeg_decode_sof()
758 s->last_nnz[i] = av_mallocz_array(size, sizeof(**s->last_nnz)); in ff_mjpeg_decode_sof()
759 if (!s->blocks[i] || !s->last_nnz[i]) in ff_mjpeg_decode_sof()
761 s->block_stride[i] = bw * s->h_count[i]; in ff_mjpeg_decode_sof()
763 memset(s->coefs_finished, 0, sizeof(s->coefs_finished)); in ff_mjpeg_decode_sof()
766 if (s->avctx->hwaccel) { in ff_mjpeg_decode_sof()
767 s->hwaccel_picture_private = in ff_mjpeg_decode_sof()
768 av_mallocz(s->avctx->hwaccel->frame_priv_data_size); in ff_mjpeg_decode_sof()
769 if (!s->hwaccel_picture_private) in ff_mjpeg_decode_sof()
772 ret = s->avctx->hwaccel->start_frame(s->avctx, s->raw_image_buffer, in ff_mjpeg_decode_sof()
773 s->raw_image_buffer_size); in ff_mjpeg_decode_sof()
781 static inline int mjpeg_decode_dc(MJpegDecodeContext *s, int dc_index) in mjpeg_decode_dc() argument
784 code = get_vlc2(&s->gb, s->vlcs[0][dc_index].table, 9, 2); in mjpeg_decode_dc()
786 av_log(s->avctx, AV_LOG_WARNING, in mjpeg_decode_dc()
788 0, dc_index, &s->vlcs[0][dc_index]); in mjpeg_decode_dc()
793 return get_xbits(&s->gb, code); in mjpeg_decode_dc()
799 static int decode_block(MJpegDecodeContext *s, int16_t *block, int component, in decode_block() argument
805 val = mjpeg_decode_dc(s, dc_index); in decode_block()
807 av_log(s->avctx, AV_LOG_ERROR, "error dc\n"); in decode_block()
810 val = val * (unsigned)quant_matrix[0] + s->last_dc[component]; in decode_block()
812 s->last_dc[component] = val; in decode_block()
816 {OPEN_READER(re, &s->gb); in decode_block()
818 UPDATE_CACHE(re, &s->gb); in decode_block()
819 GET_VLC(code, re, &s->gb, s->vlcs[1][ac_index].table, 9, 2); in decode_block()
824 if (code > MIN_CACHE_BITS - 16) in decode_block()
825 UPDATE_CACHE(re, &s->gb); in decode_block()
828 int cache = GET_CACHE(re, &s->gb); in decode_block()
830 level = (NEG_USR32(sign ^ cache,code) ^ sign) - sign; in decode_block()
833 LAST_SKIP_BITS(re, &s->gb, code); in decode_block()
836 av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i); in decode_block()
839 j = s->scantable.permutated[i]; in decode_block()
843 CLOSE_READER(re, &s->gb);} in decode_block()
848 static int decode_dc_progressive(MJpegDecodeContext *s, int16_t *block, in decode_dc_progressive() argument
853 s->bdsp.clear_block(block); in decode_dc_progressive()
854 val = mjpeg_decode_dc(s, dc_index); in decode_dc_progressive()
856 av_log(s->avctx, AV_LOG_ERROR, "error dc\n"); in decode_dc_progressive()
859 val = (val * (quant_matrix[0] << Al)) + s->last_dc[component]; in decode_dc_progressive()
860 s->last_dc[component] = val; in decode_dc_progressive()
865 /* decode block and dequantize - progressive JPEG version */
866 static int decode_block_progressive(MJpegDecodeContext *s, int16_t *block, in decode_block_progressive() argument
875 (*EOBRUN)--; in decode_block_progressive()
880 OPEN_READER(re, &s->gb); in decode_block_progressive()
882 UPDATE_CACHE(re, &s->gb); in decode_block_progressive()
883 GET_VLC(code, re, &s->gb, s->vlcs[2][ac_index].table, 9, 2); in decode_block_progressive()
889 if (code > MIN_CACHE_BITS - 16) in decode_block_progressive()
890 UPDATE_CACHE(re, &s->gb); in decode_block_progressive()
893 int cache = GET_CACHE(re, &s->gb); in decode_block_progressive()
895 level = (NEG_USR32(sign ^ cache,code) ^ sign) - sign; in decode_block_progressive()
898 LAST_SKIP_BITS(re, &s->gb, code); in decode_block_progressive()
902 j = s->scantable.permutated[se]; in decode_block_progressive()
906 av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i); in decode_block_progressive()
909 j = s->scantable.permutated[i]; in decode_block_progressive()
912 if (run == 0xF) {// ZRL - skip 15 coefficients in decode_block_progressive()
915 av_log(s->avctx, AV_LOG_ERROR, "ZRL overflow: %d\n", i); in decode_block_progressive()
921 UPDATE_CACHE(re, &s->gb); in decode_block_progressive()
922 val += NEG_USR32(GET_CACHE(re, &s->gb), run); in decode_block_progressive()
923 LAST_SKIP_BITS(re, &s->gb, run); in decode_block_progressive()
925 *EOBRUN = val - 1; in decode_block_progressive()
930 CLOSE_READER(re, &s->gb); in decode_block_progressive()
940 UPDATE_CACHE(re, &s->gb); \
942 block[j] += SHOW_UBITS(re, &s->gb, 1) * \
943 ((quant_matrix[i] ^ sign) - sign) << Al; \
944 LAST_SKIP_BITS(re, &s->gb, 1); \
952 av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i); \
953 return -1; \
957 j = s->scantable.permutated[i]; \
960 else if (run-- == 0) \
964 /* decode block and dequantize - progressive JPEG refinement pass */
965 static int decode_block_refinement(MJpegDecodeContext *s, int16_t *block, in decode_block_refinement() argument
973 OPEN_READER(re, &s->gb); in decode_block_refinement()
975 (*EOBRUN)--; in decode_block_refinement()
978 UPDATE_CACHE(re, &s->gb); in decode_block_refinement()
979 GET_VLC(code, re, &s->gb, s->vlcs[2][ac_index].table, 9, 2); in decode_block_refinement()
983 UPDATE_CACHE(re, &s->gb); in decode_block_refinement()
984 val = SHOW_UBITS(re, &s->gb, 1); in decode_block_refinement()
985 LAST_SKIP_BITS(re, &s->gb, 1); in decode_block_refinement()
987 j = s->scantable.permutated[i]; in decode_block_refinement()
988 val--; in decode_block_refinement()
989 block[j] = ((quant_matrix[i] << Al) ^ val) - val; in decode_block_refinement()
993 CLOSE_READER(re, &s->gb); in decode_block_refinement()
1004 UPDATE_CACHE(re, &s->gb); in decode_block_refinement()
1005 run += SHOW_UBITS(re, &s->gb, val); in decode_block_refinement()
1006 LAST_SKIP_BITS(re, &s->gb, val); in decode_block_refinement()
1008 *EOBRUN = run - 1; in decode_block_refinement()
1019 j = s->scantable.permutated[i]; in decode_block_refinement()
1023 CLOSE_READER(re, &s->gb); in decode_block_refinement()
1030 static int handle_rstn(MJpegDecodeContext *s, int nb_components) in handle_rstn() argument
1035 if (s->restart_interval) { in handle_rstn()
1036 s->restart_count--; in handle_rstn()
1037 if(s->restart_count == 0 && s->avctx->codec_id == AV_CODEC_ID_THP){ in handle_rstn()
1038 align_get_bits(&s->gb); in handle_rstn()
1040 s->last_dc[i] = (4 << s->bits); in handle_rstn()
1043 i = 8 + ((-get_bits_count(&s->gb)) & 7); in handle_rstn()
1045 if (s->restart_count == 0) { in handle_rstn()
1046 if( show_bits(&s->gb, i) == (1 << i) - 1 in handle_rstn()
1047 || show_bits(&s->gb, i) == 0xFF) { in handle_rstn()
1048 int pos = get_bits_count(&s->gb); in handle_rstn()
1049 align_get_bits(&s->gb); in handle_rstn()
1050 while (get_bits_left(&s->gb) >= 8 && show_bits(&s->gb, 8) == 0xFF) in handle_rstn()
1051 skip_bits(&s->gb, 8); in handle_rstn()
1052 if (get_bits_left(&s->gb) >= 8 && (get_bits(&s->gb, 8) & 0xF8) == 0xD0) { in handle_rstn()
1054 s->last_dc[i] = (4 << s->bits); in handle_rstn()
1057 skip_bits_long(&s->gb, pos - get_bits_count(&s->gb)); in handle_rstn()
1065 static int ljpeg_decode_rgb_scan(MJpegDecodeContext *s, int nb_components, int predictor, int point… in ljpeg_decode_rgb_scan() argument
1071 const int linesize = s->linesize[0]; in ljpeg_decode_rgb_scan()
1072 const int mask = ((1 << s->bits) - 1) << point_transform; in ljpeg_decode_rgb_scan()
1077 if (!s->bayer && s->nb_components < 3) in ljpeg_decode_rgb_scan()
1079 if (s->bayer && s->nb_components > 2) in ljpeg_decode_rgb_scan()
1081 if (s->nb_components <= 0 || s->nb_components > 4) in ljpeg_decode_rgb_scan()
1083 if (s->v_max != 1 || s->h_max != 1 || !s->lossless) in ljpeg_decode_rgb_scan()
1087 s->restart_count = s->restart_interval; in ljpeg_decode_rgb_scan()
1089 if (s->restart_interval == 0) in ljpeg_decode_rgb_scan()
1090 s->restart_interval = INT_MAX; in ljpeg_decode_rgb_scan()
1092 if (s->bayer) in ljpeg_decode_rgb_scan()
1093 …width = s->mb_width / nb_components; /* Interleaved, width stored is the total so need to divide */ in ljpeg_decode_rgb_scan()
1095 width = s->mb_width; in ljpeg_decode_rgb_scan()
1097 …av_fast_malloc(&s->ljpeg_buffer, &s->ljpeg_buffer_size, width * 4 * sizeof(s->ljpeg_buffer[0][0])); in ljpeg_decode_rgb_scan()
1098 if (!s->ljpeg_buffer) in ljpeg_decode_rgb_scan()
1101 buffer = s->ljpeg_buffer; in ljpeg_decode_rgb_scan()
1104 buffer[0][i] = 1 << (s->bits - 1); in ljpeg_decode_rgb_scan()
1106 for (mb_y = 0; mb_y < s->mb_height; mb_y++) { in ljpeg_decode_rgb_scan()
1107 uint8_t *ptr = s->picture_ptr->data[0] + (linesize * mb_y); in ljpeg_decode_rgb_scan()
1109 if (s->interlaced && s->bottom_field) in ljpeg_decode_rgb_scan()
1115 if ((mb_y * s->width) % s->restart_interval == 0) { in ljpeg_decode_rgb_scan()
1117 vpred[i] = 1 << (s->bits-1); in ljpeg_decode_rgb_scan()
1123 if (get_bits_left(&s->gb) < 1) { in ljpeg_decode_rgb_scan()
1124 av_log(s->avctx, AV_LOG_ERROR, "bitstream end in rgb_scan\n"); in ljpeg_decode_rgb_scan()
1128 if (s->restart_interval && !s->restart_count){ in ljpeg_decode_rgb_scan()
1129 s->restart_count = s->restart_interval; in ljpeg_decode_rgb_scan()
1133 top[i] = left[i]= topleft[i]= 1 << (s->bits - 1); in ljpeg_decode_rgb_scan()
1144 dc = mjpeg_decode_dc(s, s->dc_index[i]); in ljpeg_decode_rgb_scan()
1146 return -1; in ljpeg_decode_rgb_scan()
1148 if (!s->bayer || mb_x) { in ljpeg_decode_rgb_scan()
1152 pred = vpred[i] - dc; in ljpeg_decode_rgb_scan()
1161 if (s->restart_interval && !--s->restart_count) { in ljpeg_decode_rgb_scan()
1162 align_get_bits(&s->gb); in ljpeg_decode_rgb_scan()
1163 skip_bits(&s->gb, 16); /* skip RSTn */ in ljpeg_decode_rgb_scan()
1166 if (s->rct && s->nb_components == 4) { in ljpeg_decode_rgb_scan()
1167 for (mb_x = 0; mb_x < s->mb_width; mb_x++) { in ljpeg_decode_rgb_scan()
1168 … ptr[4*mb_x + 2] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2] - 0x200) >> 2); in ljpeg_decode_rgb_scan()
1173 } else if (s->nb_components == 4) { in ljpeg_decode_rgb_scan()
1175 int c= s->comp_index[i]; in ljpeg_decode_rgb_scan()
1176 if (s->bits <= 8) { in ljpeg_decode_rgb_scan()
1177 for(mb_x = 0; mb_x < s->mb_width; mb_x++) { in ljpeg_decode_rgb_scan()
1178 ptr[4*mb_x+3-c] = buffer[mb_x][i]; in ljpeg_decode_rgb_scan()
1180 } else if(s->bits == 9) { in ljpeg_decode_rgb_scan()
1183 for(mb_x = 0; mb_x < s->mb_width; mb_x++) { in ljpeg_decode_rgb_scan()
1188 } else if (s->rct) { in ljpeg_decode_rgb_scan()
1189 for (mb_x = 0; mb_x < s->mb_width; mb_x++) { in ljpeg_decode_rgb_scan()
1190 … ptr[3*mb_x + 1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2] - 0x200) >> 2); in ljpeg_decode_rgb_scan()
1194 } else if (s->pegasus_rct) { in ljpeg_decode_rgb_scan()
1195 for (mb_x = 0; mb_x < s->mb_width; mb_x++) { in ljpeg_decode_rgb_scan()
1196 ptr[3*mb_x + 1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2]) >> 2); in ljpeg_decode_rgb_scan()
1200 } else if (s->bayer) { in ljpeg_decode_rgb_scan()
1213 int c= s->comp_index[i]; in ljpeg_decode_rgb_scan()
1214 if (s->bits <= 8) { in ljpeg_decode_rgb_scan()
1215 for(mb_x = 0; mb_x < s->mb_width; mb_x++) { in ljpeg_decode_rgb_scan()
1216 ptr[3*mb_x+2-c] = buffer[mb_x][i]; in ljpeg_decode_rgb_scan()
1218 } else if(s->bits == 9) { in ljpeg_decode_rgb_scan()
1221 for(mb_x = 0; mb_x < s->mb_width; mb_x++) { in ljpeg_decode_rgb_scan()
1222 ((uint16_t*)ptr)[3*mb_x+2-c] = buffer[mb_x][i]; in ljpeg_decode_rgb_scan()
1231 static int ljpeg_decode_yuv_scan(MJpegDecodeContext *s, int predictor, in ljpeg_decode_yuv_scan() argument
1235 int bits= (s->bits+7)&~7; in ljpeg_decode_yuv_scan()
1239 point_transform += bits - s->bits; in ljpeg_decode_yuv_scan()
1240 mask = ((1 << s->bits) - 1) << point_transform; in ljpeg_decode_yuv_scan()
1244 for (mb_y = 0; mb_y < s->mb_height; mb_y++) { in ljpeg_decode_yuv_scan()
1245 for (mb_x = 0; mb_x < s->mb_width; mb_x++) { in ljpeg_decode_yuv_scan()
1246 if (get_bits_left(&s->gb) < 1) { in ljpeg_decode_yuv_scan()
1247 av_log(s->avctx, AV_LOG_ERROR, "bitstream end in yuv_scan\n"); in ljpeg_decode_yuv_scan()
1250 if (s->restart_interval && !s->restart_count){ in ljpeg_decode_yuv_scan()
1251 s->restart_count = s->restart_interval; in ljpeg_decode_yuv_scan()
1256 … if(!mb_x || mb_y == resync_mb_y || mb_y == resync_mb_y+1 && mb_x < resync_mb_x || s->interlaced){ in ljpeg_decode_yuv_scan()
1263 n = s->nb_blocks[i]; in ljpeg_decode_yuv_scan()
1264 c = s->comp_index[i]; in ljpeg_decode_yuv_scan()
1265 h = s->h_scount[i]; in ljpeg_decode_yuv_scan()
1266 v = s->v_scount[i]; in ljpeg_decode_yuv_scan()
1269 linesize= s->linesize[c]; in ljpeg_decode_yuv_scan()
1276 dc = mjpeg_decode_dc(s, s->dc_index[i]); in ljpeg_decode_yuv_scan()
1278 return -1; in ljpeg_decode_yuv_scan()
1279 if ( h * mb_x + x >= s->width in ljpeg_decode_yuv_scan()
1280 || v * mb_y + y >= s->height) { in ljpeg_decode_yuv_scan()
1283 …ptr = s->picture_ptr->data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize thi… in ljpeg_decode_yuv_scan()
1286 pred= 1 << (bits - 1); in ljpeg_decode_yuv_scan()
1288 pred= ptr[-1]; in ljpeg_decode_yuv_scan()
1292 pred= ptr[-linesize]; in ljpeg_decode_yuv_scan()
1294 … PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor); in ljpeg_decode_yuv_scan()
1298 if (s->interlaced && s->bottom_field) in ljpeg_decode_yuv_scan()
1303 …ptr16 = (uint16_t*)(s->picture_ptr->data[c] + 2*(linesize * (v * mb_y + y)) + 2*(h * mb_x + x)); /… in ljpeg_decode_yuv_scan()
1306 pred= 1 << (bits - 1); in ljpeg_decode_yuv_scan()
1308 pred= ptr16[-1]; in ljpeg_decode_yuv_scan()
1312 pred= ptr16[-linesize]; in ljpeg_decode_yuv_scan()
1314 … PREDICT(pred, ptr16[-linesize-1], ptr16[-linesize], ptr16[-1], predictor); in ljpeg_decode_yuv_scan()
1318 if (s->interlaced && s->bottom_field) in ljpeg_decode_yuv_scan()
1334 n = s->nb_blocks[i]; in ljpeg_decode_yuv_scan()
1335 c = s->comp_index[i]; in ljpeg_decode_yuv_scan()
1336 h = s->h_scount[i]; in ljpeg_decode_yuv_scan()
1337 v = s->v_scount[i]; in ljpeg_decode_yuv_scan()
1340 linesize = s->linesize[c]; in ljpeg_decode_yuv_scan()
1347 dc = mjpeg_decode_dc(s, s->dc_index[i]); in ljpeg_decode_yuv_scan()
1349 return -1; in ljpeg_decode_yuv_scan()
1350 if ( h * mb_x + x >= s->width in ljpeg_decode_yuv_scan()
1351 || v * mb_y + y >= s->height) { in ljpeg_decode_yuv_scan()
1354 ptr = s->picture_ptr->data[c] + in ljpeg_decode_yuv_scan()
1357 PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor); in ljpeg_decode_yuv_scan()
1362 …ptr16 = (uint16_t*)(s->picture_ptr->data[c] + 2*(linesize * (v * mb_y + y)) + 2*(h * mb_x + x)); /… in ljpeg_decode_yuv_scan()
1363 … PREDICT(pred, ptr16[-linesize-1], ptr16[-linesize], ptr16[-1], predictor); in ljpeg_decode_yuv_scan()
1376 if (s->restart_interval && !--s->restart_count) { in ljpeg_decode_yuv_scan()
1377 align_get_bits(&s->gb); in ljpeg_decode_yuv_scan()
1378 skip_bits(&s->gb, 16); /* skip RSTn */ in ljpeg_decode_yuv_scan()
1385 static av_always_inline void mjpeg_copy_block(MJpegDecodeContext *s, in mjpeg_copy_block() argument
1390 case 0: s->hdsp.put_pixels_tab[1][0](dst, src, linesize, 8); in mjpeg_copy_block()
1401 static void shift_output(MJpegDecodeContext *s, uint8_t *ptr, int linesize) in shift_output() argument
1404 int size = 8 >> s->avctx->lowres; in shift_output()
1405 if (s->bits > 8) { in shift_output()
1408 *(uint16_t*)(ptr + 2*block_x + block_y*linesize) <<= 16 - s->bits; in shift_output()
1412 *(ptr + block_x + block_y*linesize) <<= 8 - s->bits; in shift_output()
1416 static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int Ah, in mjpeg_decode_scan() argument
1426 int bytes_per_pixel = 1 + (s->bits > 8); in mjpeg_decode_scan()
1429 if (mb_bitmask_size != (s->mb_width * s->mb_height + 7)>>3) { in mjpeg_decode_scan()
1430 av_log(s->avctx, AV_LOG_ERROR, "mb_bitmask_size mismatches\n"); in mjpeg_decode_scan()
1433 init_get_bits(&mb_bitmask_gb, mb_bitmask, s->mb_width * s->mb_height); in mjpeg_decode_scan()
1436 s->restart_count = 0; in mjpeg_decode_scan()
1438 av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt, &chroma_h_shift, in mjpeg_decode_scan()
1440 chroma_width = AV_CEIL_RSHIFT(s->width, chroma_h_shift); in mjpeg_decode_scan()
1441 chroma_height = AV_CEIL_RSHIFT(s->height, chroma_v_shift); in mjpeg_decode_scan()
1444 int c = s->comp_index[i]; in mjpeg_decode_scan()
1445 data[c] = s->picture_ptr->data[c]; in mjpeg_decode_scan()
1446 reference_data[c] = reference ? reference->data[c] : NULL; in mjpeg_decode_scan()
1447 linesize[c] = s->linesize[c]; in mjpeg_decode_scan()
1448 s->coefs_finished[c] |= 1; in mjpeg_decode_scan()
1451 for (mb_y = 0; mb_y < s->mb_height; mb_y++) { in mjpeg_decode_scan()
1452 for (mb_x = 0; mb_x < s->mb_width; mb_x++) { in mjpeg_decode_scan()
1455 if (s->restart_interval && !s->restart_count) in mjpeg_decode_scan()
1456 s->restart_count = s->restart_interval; in mjpeg_decode_scan()
1458 if (get_bits_left(&s->gb) < 0) { in mjpeg_decode_scan()
1459 av_log(s->avctx, AV_LOG_ERROR, "overread %d\n", in mjpeg_decode_scan()
1460 -get_bits_left(&s->gb)); in mjpeg_decode_scan()
1467 n = s->nb_blocks[i]; in mjpeg_decode_scan()
1468 c = s->comp_index[i]; in mjpeg_decode_scan()
1469 h = s->h_scount[i]; in mjpeg_decode_scan()
1470 v = s->v_scount[i]; in mjpeg_decode_scan()
1475 (h * mb_x + x) * 8 * bytes_per_pixel) >> s->avctx->lowres); in mjpeg_decode_scan()
1477 if (s->interlaced && s->bottom_field) in mjpeg_decode_scan()
1479 if ( 8*(h * mb_x + x) < ((c == 1) || (c == 2) ? chroma_width : s->width) in mjpeg_decode_scan()
1480 && 8*(v * mb_y + y) < ((c == 1) || (c == 2) ? chroma_height : s->height)) { in mjpeg_decode_scan()
1484 if (!s->progressive) { in mjpeg_decode_scan()
1487 mjpeg_copy_block(s, ptr, reference_data[c] + block_offset, in mjpeg_decode_scan()
1488 linesize[c], s->avctx->lowres); in mjpeg_decode_scan()
1491 s->bdsp.clear_block(s->block); in mjpeg_decode_scan()
1492 if (decode_block(s, s->block, i, in mjpeg_decode_scan()
1493 s->dc_index[i], s->ac_index[i], in mjpeg_decode_scan()
1494 s->quant_matrixes[s->quant_sindex[i]]) < 0) { in mjpeg_decode_scan()
1495 av_log(s->avctx, AV_LOG_ERROR, in mjpeg_decode_scan()
1500 s->idsp.idct_put(ptr, linesize[c], s->block); in mjpeg_decode_scan()
1501 if (s->bits & 7) in mjpeg_decode_scan()
1502 shift_output(s, ptr, linesize[c]); in mjpeg_decode_scan()
1506 int block_idx = s->block_stride[c] * (v * mb_y + y) + in mjpeg_decode_scan()
1508 int16_t *block = s->blocks[c][block_idx]; in mjpeg_decode_scan()
1510 block[0] += get_bits1(&s->gb) * in mjpeg_decode_scan()
1511 s->quant_matrixes[s->quant_sindex[i]][0] << Al; in mjpeg_decode_scan()
1512 else if (decode_dc_progressive(s, block, i, s->dc_index[i], in mjpeg_decode_scan()
1513 s->quant_matrixes[s->quant_sindex[i]], in mjpeg_decode_scan()
1515 av_log(s->avctx, AV_LOG_ERROR, in mjpeg_decode_scan()
1520 ff_dlog(s->avctx, "mb: %d %d processed\n", mb_y, mb_x); in mjpeg_decode_scan()
1521 ff_dlog(s->avctx, "%d %d %d %d %d %d %d %d \n", in mjpeg_decode_scan()
1522 mb_x, mb_y, x, y, c, s->bottom_field, in mjpeg_decode_scan()
1531 handle_rstn(s, nb_components); in mjpeg_decode_scan()
1537 static int mjpeg_decode_scan_progressive_ac(MJpegDecodeContext *s, int ss, in mjpeg_decode_scan_progressive_ac() argument
1542 int c = s->comp_index[0]; in mjpeg_decode_scan_progressive_ac()
1543 uint16_t *quant_matrix = s->quant_matrixes[s->quant_sindex[0]]; in mjpeg_decode_scan_progressive_ac()
1547 av_log(s->avctx, AV_LOG_ERROR, "SS/SE %d/%d is invalid\n", ss, se); in mjpeg_decode_scan_progressive_ac()
1551 // s->coefs_finished is a bitmask for coefficients coded in mjpeg_decode_scan_progressive_ac()
1553 s->coefs_finished[c] |= (2ULL << se) - (1ULL << ss); in mjpeg_decode_scan_progressive_ac()
1555 s->restart_count = 0; in mjpeg_decode_scan_progressive_ac()
1557 for (mb_y = 0; mb_y < s->mb_height; mb_y++) { in mjpeg_decode_scan_progressive_ac()
1558 int block_idx = mb_y * s->block_stride[c]; in mjpeg_decode_scan_progressive_ac()
1559 int16_t (*block)[64] = &s->blocks[c][block_idx]; in mjpeg_decode_scan_progressive_ac()
1560 uint8_t *last_nnz = &s->last_nnz[c][block_idx]; in mjpeg_decode_scan_progressive_ac()
1561 if (get_bits_left(&s->gb) <= 0) { in mjpeg_decode_scan_progressive_ac()
1562 … av_log(s->avctx, AV_LOG_ERROR, "bitstream truncated in mjpeg_decode_scan_progressive_ac\n"); in mjpeg_decode_scan_progressive_ac()
1565 for (mb_x = 0; mb_x < s->mb_width; mb_x++, block++, last_nnz++) { in mjpeg_decode_scan_progressive_ac()
1567 if (s->restart_interval && !s->restart_count) in mjpeg_decode_scan_progressive_ac()
1568 s->restart_count = s->restart_interval; in mjpeg_decode_scan_progressive_ac()
1571 ret = decode_block_refinement(s, *block, last_nnz, s->ac_index[0], in mjpeg_decode_scan_progressive_ac()
1574 ret = decode_block_progressive(s, *block, last_nnz, s->ac_index[0], in mjpeg_decode_scan_progressive_ac()
1577 if (ret >= 0 && get_bits_left(&s->gb) < 0) in mjpeg_decode_scan_progressive_ac()
1580 av_log(s->avctx, AV_LOG_ERROR, in mjpeg_decode_scan_progressive_ac()
1585 if (handle_rstn(s, 0)) in mjpeg_decode_scan_progressive_ac()
1592 static void mjpeg_idct_scan_progressive_ac(MJpegDecodeContext *s) in mjpeg_idct_scan_progressive_ac() argument
1596 const int bytes_per_pixel = 1 + (s->bits > 8); in mjpeg_idct_scan_progressive_ac()
1597 const int block_size = s->lossless ? 1 : 8; in mjpeg_idct_scan_progressive_ac()
1599 for (c = 0; c < s->nb_components; c++) { in mjpeg_idct_scan_progressive_ac()
1600 uint8_t *data = s->picture_ptr->data[c]; in mjpeg_idct_scan_progressive_ac()
1601 int linesize = s->linesize[c]; in mjpeg_idct_scan_progressive_ac()
1602 int h = s->h_max / s->h_count[c]; in mjpeg_idct_scan_progressive_ac()
1603 int v = s->v_max / s->v_count[c]; in mjpeg_idct_scan_progressive_ac()
1604 int mb_width = (s->width + h * block_size - 1) / (h * block_size); in mjpeg_idct_scan_progressive_ac()
1605 int mb_height = (s->height + v * block_size - 1) / (v * block_size); in mjpeg_idct_scan_progressive_ac()
1607 if (~s->coefs_finished[c]) in mjpeg_idct_scan_progressive_ac()
1608 av_log(s->avctx, AV_LOG_WARNING, "component %d is incomplete\n", c); in mjpeg_idct_scan_progressive_ac()
1610 if (s->interlaced && s->bottom_field) in mjpeg_idct_scan_progressive_ac()
1614 uint8_t *ptr = data + (mb_y * linesize * 8 >> s->avctx->lowres); in mjpeg_idct_scan_progressive_ac()
1615 int block_idx = mb_y * s->block_stride[c]; in mjpeg_idct_scan_progressive_ac()
1616 int16_t (*block)[64] = &s->blocks[c][block_idx]; in mjpeg_idct_scan_progressive_ac()
1618 s->idsp.idct_put(ptr, linesize, *block); in mjpeg_idct_scan_progressive_ac()
1619 if (s->bits & 7) in mjpeg_idct_scan_progressive_ac()
1620 shift_output(s, ptr, linesize); in mjpeg_idct_scan_progressive_ac()
1621 ptr += bytes_per_pixel*8 >> s->avctx->lowres; in mjpeg_idct_scan_progressive_ac()
1627 int ff_mjpeg_decode_sos(MJpegDecodeContext *s, const uint8_t *mb_bitmask, in ff_mjpeg_decode_sos() argument
1632 const int block_size = s->lossless ? 1 : 8; in ff_mjpeg_decode_sos()
1635 if (!s->got_picture) { in ff_mjpeg_decode_sos()
1636 av_log(s->avctx, AV_LOG_WARNING, in ff_mjpeg_decode_sos()
1638 return -1; in ff_mjpeg_decode_sos()
1642 if (reference->width != s->picture_ptr->width || in ff_mjpeg_decode_sos()
1643 reference->height != s->picture_ptr->height || in ff_mjpeg_decode_sos()
1644 reference->format != s->picture_ptr->format) { in ff_mjpeg_decode_sos()
1645 av_log(s->avctx, AV_LOG_ERROR, "Reference mismatching\n"); in ff_mjpeg_decode_sos()
1651 len = get_bits(&s->gb, 16); in ff_mjpeg_decode_sos()
1652 nb_components = get_bits(&s->gb, 8); in ff_mjpeg_decode_sos()
1654 avpriv_report_missing_feature(s->avctx, in ff_mjpeg_decode_sos()
1660 av_log(s->avctx, AV_LOG_ERROR, "decode_sos: invalid len (%d)\n", len); in ff_mjpeg_decode_sos()
1664 id = get_bits(&s->gb, 8) - 1; in ff_mjpeg_decode_sos()
1665 av_log(s->avctx, AV_LOG_DEBUG, "component: %d\n", id); in ff_mjpeg_decode_sos()
1667 for (index = 0; index < s->nb_components; index++) in ff_mjpeg_decode_sos()
1668 if (id == s->component_id[index]) in ff_mjpeg_decode_sos()
1670 if (index == s->nb_components) { in ff_mjpeg_decode_sos()
1671 av_log(s->avctx, AV_LOG_ERROR, in ff_mjpeg_decode_sos()
1676 if (s->avctx->codec_tag == MKTAG('M', 'T', 'S', 'J') in ff_mjpeg_decode_sos()
1677 && nb_components == 3 && s->nb_components == 3 && i) in ff_mjpeg_decode_sos()
1678 index = 3 - i; in ff_mjpeg_decode_sos()
1680 s->quant_sindex[i] = s->quant_index[index]; in ff_mjpeg_decode_sos()
1681 s->nb_blocks[i] = s->h_count[index] * s->v_count[index]; in ff_mjpeg_decode_sos()
1682 s->h_scount[i] = s->h_count[index]; in ff_mjpeg_decode_sos()
1683 s->v_scount[i] = s->v_count[index]; in ff_mjpeg_decode_sos()
1685 …if((nb_components == 1 || nb_components == 3) && s->nb_components == 3 && s->avctx->pix_fmt == AV_… in ff_mjpeg_decode_sos()
1688 s->comp_index[i] = index; in ff_mjpeg_decode_sos()
1690 s->dc_index[i] = get_bits(&s->gb, 4); in ff_mjpeg_decode_sos()
1691 s->ac_index[i] = get_bits(&s->gb, 4); in ff_mjpeg_decode_sos()
1693 if (s->dc_index[i] < 0 || s->ac_index[i] < 0 || in ff_mjpeg_decode_sos()
1694 s->dc_index[i] >= 4 || s->ac_index[i] >= 4) in ff_mjpeg_decode_sos()
1696 …if (!s->vlcs[0][s->dc_index[i]].table || !(s->progressive ? s->vlcs[2][s->ac_index[0]].table : s->… in ff_mjpeg_decode_sos()
1700 predictor = get_bits(&s->gb, 8); /* JPEG Ss / lossless JPEG predictor /JPEG-LS NEAR */ in ff_mjpeg_decode_sos()
1701 ilv = get_bits(&s->gb, 8); /* JPEG Se / JPEG-LS ILV */ in ff_mjpeg_decode_sos()
1702 if(s->avctx->codec_tag != AV_RL32("CJPG")){ in ff_mjpeg_decode_sos()
1703 prev_shift = get_bits(&s->gb, 4); /* Ah */ in ff_mjpeg_decode_sos()
1704 point_transform = get_bits(&s->gb, 4); /* Al */ in ff_mjpeg_decode_sos()
1710 s->mb_width = (s->width + s->h_max * block_size - 1) / (s->h_max * block_size); in ff_mjpeg_decode_sos()
1711 s->mb_height = (s->height + s->v_max * block_size - 1) / (s->v_max * block_size); in ff_mjpeg_decode_sos()
1712 } else if (!s->ls) { /* skip this for JPEG-LS */ in ff_mjpeg_decode_sos()
1713 h = s->h_max / s->h_scount[0]; in ff_mjpeg_decode_sos()
1714 v = s->v_max / s->v_scount[0]; in ff_mjpeg_decode_sos()
1715 s->mb_width = (s->width + h * block_size - 1) / (h * block_size); in ff_mjpeg_decode_sos()
1716 s->mb_height = (s->height + v * block_size - 1) / (v * block_size); in ff_mjpeg_decode_sos()
1717 s->nb_blocks[0] = 1; in ff_mjpeg_decode_sos()
1718 s->h_scount[0] = 1; in ff_mjpeg_decode_sos()
1719 s->v_scount[0] = 1; in ff_mjpeg_decode_sos()
1722 if (s->avctx->debug & FF_DEBUG_PICT_INFO) in ff_mjpeg_decode_sos()
1723 av_log(s->avctx, AV_LOG_DEBUG, "%s %s p:%d >>:%d ilv:%d bits:%d skip:%d %s comp:%d\n", in ff_mjpeg_decode_sos()
1724 s->lossless ? "lossless" : "sequential DCT", s->rgb ? "RGB" : "", in ff_mjpeg_decode_sos()
1725 predictor, point_transform, ilv, s->bits, s->mjpb_skiptosod, in ff_mjpeg_decode_sos()
1726 s->pegasus_rct ? "PRCT" : (s->rct ? "RCT" : ""), nb_components); in ff_mjpeg_decode_sos()
1729 /* mjpeg-b can have padding bytes between sos and image data, skip them */ in ff_mjpeg_decode_sos()
1730 for (i = s->mjpb_skiptosod; i > 0; i--) in ff_mjpeg_decode_sos()
1731 skip_bits(&s->gb, 8); in ff_mjpeg_decode_sos()
1735 s->last_dc[i] = (4 << s->bits); in ff_mjpeg_decode_sos()
1737 if (s->avctx->hwaccel) { in ff_mjpeg_decode_sos()
1738 int bytes_to_start = get_bits_count(&s->gb) / 8; in ff_mjpeg_decode_sos()
1740 s->raw_scan_buffer_size >= bytes_to_start); in ff_mjpeg_decode_sos()
1742 ret = s->avctx->hwaccel->decode_slice(s->avctx, in ff_mjpeg_decode_sos()
1743 s->raw_scan_buffer + bytes_to_start, in ff_mjpeg_decode_sos()
1744 s->raw_scan_buffer_size - bytes_to_start); in ff_mjpeg_decode_sos()
1748 } else if (s->lossless) { in ff_mjpeg_decode_sos()
1749 av_assert0(s->picture_ptr == s->picture); in ff_mjpeg_decode_sos()
1750 if (CONFIG_JPEGLS_DECODER && s->ls) { in ff_mjpeg_decode_sos()
1752 // reset_ls_coding_parameters(s, 0); in ff_mjpeg_decode_sos()
1754 if ((ret = ff_jpegls_decode_picture(s, predictor, in ff_mjpeg_decode_sos()
1758 if (s->rgb || s->bayer) { in ff_mjpeg_decode_sos()
1759 if ((ret = ljpeg_decode_rgb_scan(s, nb_components, predictor, point_transform)) < 0) in ff_mjpeg_decode_sos()
1762 if ((ret = ljpeg_decode_yuv_scan(s, predictor, in ff_mjpeg_decode_sos()
1769 if (s->progressive && predictor) { in ff_mjpeg_decode_sos()
1770 av_assert0(s->picture_ptr == s->picture); in ff_mjpeg_decode_sos()
1771 if ((ret = mjpeg_decode_scan_progressive_ac(s, predictor, in ff_mjpeg_decode_sos()
1776 if ((ret = mjpeg_decode_scan(s, nb_components, in ff_mjpeg_decode_sos()
1783 if (s->interlaced && in ff_mjpeg_decode_sos()
1784 get_bits_left(&s->gb) > 32 && in ff_mjpeg_decode_sos()
1785 show_bits(&s->gb, 8) == 0xFF) { in ff_mjpeg_decode_sos()
1786 GetBitContext bak = s->gb; in ff_mjpeg_decode_sos()
1789 av_log(s->avctx, AV_LOG_DEBUG, "AVRn interlaced picture marker found\n"); in ff_mjpeg_decode_sos()
1790 s->gb = bak; in ff_mjpeg_decode_sos()
1791 skip_bits(&s->gb, 16); in ff_mjpeg_decode_sos()
1792 s->bottom_field ^= 1; in ff_mjpeg_decode_sos()
1801 av_log(s->avctx, AV_LOG_ERROR, "decode_sos: ac/dc index out of range\n"); in ff_mjpeg_decode_sos()
1805 static int mjpeg_decode_dri(MJpegDecodeContext *s) in mjpeg_decode_dri() argument
1807 if (get_bits(&s->gb, 16) != 4) in mjpeg_decode_dri()
1809 s->restart_interval = get_bits(&s->gb, 16); in mjpeg_decode_dri()
1810 s->restart_count = 0; in mjpeg_decode_dri()
1811 av_log(s->avctx, AV_LOG_DEBUG, "restart interval: %d\n", in mjpeg_decode_dri()
1812 s->restart_interval); in mjpeg_decode_dri()
1817 static int mjpeg_decode_app(MJpegDecodeContext *s) in mjpeg_decode_app() argument
1821 len = get_bits(&s->gb, 16); in mjpeg_decode_app()
1823 if (s->bayer) { in mjpeg_decode_app()
1824 … // Pentax K-1 (digital camera) JPEG images embedded in DNG images contain unknown APP0 markers in mjpeg_decode_app()
1825 … av_log(s->avctx, AV_LOG_WARNING, "skipping APPx (len=%"PRId32") for bayer-encoded image\n", len); in mjpeg_decode_app()
1826 skip_bits(&s->gb, len); in mjpeg_decode_app()
1831 if (8 * len > get_bits_left(&s->gb)) in mjpeg_decode_app()
1834 id = get_bits_long(&s->gb, 32); in mjpeg_decode_app()
1835 len -= 6; in mjpeg_decode_app()
1837 if (s->avctx->debug & FF_DEBUG_STARTCODE) in mjpeg_decode_app()
1838 av_log(s->avctx, AV_LOG_DEBUG, "APPx (%s / %8X) len=%d\n", in mjpeg_decode_app()
1842 /* Also, this fourcc is used by non-avid files too, it holds some in mjpeg_decode_app()
1843 information, but it's always present in AVID-created files. */ in mjpeg_decode_app()
1852 s->buggy_avid = 1; in mjpeg_decode_app()
1853 i = get_bits(&s->gb, 8); len--; in mjpeg_decode_app()
1854 av_log(s->avctx, AV_LOG_DEBUG, "polarity %d\n", i); in mjpeg_decode_app()
1862 skip_bits(&s->gb, 8); /* the trailing zero-byte */ in mjpeg_decode_app()
1863 v1 = get_bits(&s->gb, 8); in mjpeg_decode_app()
1864 v2 = get_bits(&s->gb, 8); in mjpeg_decode_app()
1865 skip_bits(&s->gb, 8); in mjpeg_decode_app()
1867 s->avctx->sample_aspect_ratio.num = get_bits(&s->gb, 16); in mjpeg_decode_app()
1868 s->avctx->sample_aspect_ratio.den = get_bits(&s->gb, 16); in mjpeg_decode_app()
1869 if ( s->avctx->sample_aspect_ratio.num <= 0 in mjpeg_decode_app()
1870 || s->avctx->sample_aspect_ratio.den <= 0) { in mjpeg_decode_app()
1871 s->avctx->sample_aspect_ratio.num = 0; in mjpeg_decode_app()
1872 s->avctx->sample_aspect_ratio.den = 1; in mjpeg_decode_app()
1875 if (s->avctx->debug & FF_DEBUG_PICT_INFO) in mjpeg_decode_app()
1876 av_log(s->avctx, AV_LOG_INFO, in mjpeg_decode_app()
1879 s->avctx->sample_aspect_ratio.num, in mjpeg_decode_app()
1880 s->avctx->sample_aspect_ratio.den); in mjpeg_decode_app()
1882 len -= 8; in mjpeg_decode_app()
1884 t_w = get_bits(&s->gb, 8); in mjpeg_decode_app()
1885 t_h = get_bits(&s->gb, 8); in mjpeg_decode_app()
1888 if (len -10 - (t_w * t_h * 3) > 0) in mjpeg_decode_app()
1889 len -= t_w * t_h * 3; in mjpeg_decode_app()
1891 len -= 2; in mjpeg_decode_app()
1898 && show_bits(&s->gb, 8) == 'e' in mjpeg_decode_app()
1899 && show_bits_long(&s->gb, 32) != AV_RB32("e_CM")) { in mjpeg_decode_app()
1900 skip_bits(&s->gb, 8); /* 'e' */ in mjpeg_decode_app()
1901 skip_bits(&s->gb, 16); /* version */ in mjpeg_decode_app()
1902 skip_bits(&s->gb, 16); /* flags0 */ in mjpeg_decode_app()
1903 skip_bits(&s->gb, 16); /* flags1 */ in mjpeg_decode_app()
1904 s->adobe_transform = get_bits(&s->gb, 8); in mjpeg_decode_app()
1905 if (s->avctx->debug & FF_DEBUG_PICT_INFO) in mjpeg_decode_app()
1906 … av_log(s->avctx, AV_LOG_INFO, "mjpeg: Adobe header found, transform=%d\n", s->adobe_transform); in mjpeg_decode_app()
1907 len -= 7; in mjpeg_decode_app()
1912 int rgb = s->rgb; in mjpeg_decode_app()
1913 int pegasus_rct = s->pegasus_rct; in mjpeg_decode_app()
1914 if (s->avctx->debug & FF_DEBUG_PICT_INFO) in mjpeg_decode_app()
1915 av_log(s->avctx, AV_LOG_INFO, in mjpeg_decode_app()
1917 skip_bits(&s->gb, 16); /* version ? */ in mjpeg_decode_app()
1918 skip_bits(&s->gb, 16); /* unknown always 0? */ in mjpeg_decode_app()
1919 skip_bits(&s->gb, 16); /* unknown always 0? */ in mjpeg_decode_app()
1920 skip_bits(&s->gb, 16); /* unknown always 0? */ in mjpeg_decode_app()
1921 switch (i=get_bits(&s->gb, 8)) { in mjpeg_decode_app()
1931 av_log(s->avctx, AV_LOG_ERROR, "unknown colorspace %d\n", i); in mjpeg_decode_app()
1934 len -= 9; in mjpeg_decode_app()
1935 if (s->got_picture) in mjpeg_decode_app()
1936 if (rgb != s->rgb || pegasus_rct != s->pegasus_rct) { in mjpeg_decode_app()
1937 av_log(s->avctx, AV_LOG_WARNING, "Mismatching LJIF tag\n"); in mjpeg_decode_app()
1941 s->rgb = rgb; in mjpeg_decode_app()
1942 s->pegasus_rct = pegasus_rct; in mjpeg_decode_app()
1947 s->colr = get_bits(&s->gb, 8); in mjpeg_decode_app()
1948 if (s->avctx->debug & FF_DEBUG_PICT_INFO) in mjpeg_decode_app()
1949 av_log(s->avctx, AV_LOG_INFO, "COLR %d\n", s->colr); in mjpeg_decode_app()
1950 len --; in mjpeg_decode_app()
1954 s->xfrm = get_bits(&s->gb, 8); in mjpeg_decode_app()
1955 if (s->avctx->debug & FF_DEBUG_PICT_INFO) in mjpeg_decode_app()
1956 av_log(s->avctx, AV_LOG_INFO, "XFRM %d\n", s->xfrm); in mjpeg_decode_app()
1957 len --; in mjpeg_decode_app()
1962 if (s->start_code == APP3 && id == AV_RB32("_JPS") && len >= 10) { in mjpeg_decode_app()
1964 if (s->avctx->debug & FF_DEBUG_PICT_INFO) in mjpeg_decode_app()
1965 av_log(s->avctx, AV_LOG_INFO, "_JPSJPS_\n"); in mjpeg_decode_app()
1967 skip_bits(&s->gb, 32); len -= 4; /* JPS_ */ in mjpeg_decode_app()
1968 skip_bits(&s->gb, 16); len -= 2; /* block length */ in mjpeg_decode_app()
1969 skip_bits(&s->gb, 8); /* reserved */ in mjpeg_decode_app()
1970 flags = get_bits(&s->gb, 8); in mjpeg_decode_app()
1971 layout = get_bits(&s->gb, 8); in mjpeg_decode_app()
1972 type = get_bits(&s->gb, 8); in mjpeg_decode_app()
1973 len -= 4; in mjpeg_decode_app()
1975 av_freep(&s->stereo3d); in mjpeg_decode_app()
1976 s->stereo3d = av_stereo3d_alloc(); in mjpeg_decode_app()
1977 if (!s->stereo3d) { in mjpeg_decode_app()
1981 s->stereo3d->type = AV_STEREO3D_2D; in mjpeg_decode_app()
1985 s->stereo3d->type = AV_STEREO3D_LINES; in mjpeg_decode_app()
1988 s->stereo3d->type = AV_STEREO3D_SIDEBYSIDE; in mjpeg_decode_app()
1991 s->stereo3d->type = AV_STEREO3D_TOPBOTTOM; in mjpeg_decode_app()
1995 s->stereo3d->flags = AV_STEREO3D_FLAG_INVERT; in mjpeg_decode_app()
2002 if (s->start_code == APP1 && id == AV_RB32("Exif") && len >= 2) { in mjpeg_decode_app()
2007 skip_bits(&s->gb, 16); // skip padding in mjpeg_decode_app()
2008 len -= 2; in mjpeg_decode_app()
2011 aligned = align_get_bits(&s->gb); in mjpeg_decode_app()
2017 av_log(s->avctx, AV_LOG_ERROR, "mjpeg: invalid TIFF header in EXIF data\n"); in mjpeg_decode_app()
2023 ret = ff_exif_decode_ifd(s->avctx, &gbytes, le, 0, &s->exif_metadata); in mjpeg_decode_app()
2025 av_log(s->avctx, AV_LOG_ERROR, "mjpeg: error decoding EXIF data\n"); in mjpeg_decode_app()
2030 skip_bits(&s->gb, bytes_read << 3); in mjpeg_decode_app()
2031 len -= bytes_read; in mjpeg_decode_app()
2036 /* Apple MJPEG-A */ in mjpeg_decode_app()
2037 if ((s->start_code == APP1) && (len > (0x28 - 8))) { in mjpeg_decode_app()
2038 id = get_bits_long(&s->gb, 32); in mjpeg_decode_app()
2039 len -= 4; in mjpeg_decode_app()
2040 /* Apple MJPEG-A */ in mjpeg_decode_app()
2052 if (s->avctx->debug & FF_DEBUG_PICT_INFO) in mjpeg_decode_app()
2053 av_log(s->avctx, AV_LOG_INFO, "mjpeg: Apple MJPEG-A header found\n"); in mjpeg_decode_app()
2057 if (s->start_code == APP2 && id == AV_RB32("ICC_") && len >= 10) { in mjpeg_decode_app()
2062 id = get_bits_long(&s->gb, 32); in mjpeg_decode_app()
2063 id2 = get_bits(&s->gb, 24); in mjpeg_decode_app()
2064 len -= 7; in mjpeg_decode_app()
2066 av_log(s->avctx, AV_LOG_WARNING, "Invalid ICC_PROFILE header in APP2\n"); in mjpeg_decode_app()
2070 skip_bits(&s->gb, 8); in mjpeg_decode_app()
2071 seqno = get_bits(&s->gb, 8); in mjpeg_decode_app()
2072 len -= 2; in mjpeg_decode_app()
2074 av_log(s->avctx, AV_LOG_WARNING, "Invalid sequence number in APP2\n"); in mjpeg_decode_app()
2078 nummarkers = get_bits(&s->gb, 8); in mjpeg_decode_app()
2079 len -= 1; in mjpeg_decode_app()
2081 av_log(s->avctx, AV_LOG_WARNING, "Invalid number of markers coded in APP2\n"); in mjpeg_decode_app()
2083 } else if (s->iccnum != 0 && nummarkers != s->iccnum) { in mjpeg_decode_app()
2084 … av_log(s->avctx, AV_LOG_WARNING, "Mistmatch in coded number of ICC markers between markers\n"); in mjpeg_decode_app()
2087 … av_log(s->avctx, AV_LOG_WARNING, "Mismatching sequence number and coded number of ICC markers\n"); in mjpeg_decode_app()
2092 if (s->iccnum == 0) { in mjpeg_decode_app()
2093 if (!FF_ALLOCZ_TYPED_ARRAY(s->iccentries, nummarkers)) { in mjpeg_decode_app()
2094 av_log(s->avctx, AV_LOG_ERROR, "Could not allocate ICC data arrays\n"); in mjpeg_decode_app()
2097 s->iccnum = nummarkers; in mjpeg_decode_app()
2100 if (s->iccentries[seqno - 1].data) { in mjpeg_decode_app()
2101 av_log(s->avctx, AV_LOG_WARNING, "Duplicate ICC sequence number\n"); in mjpeg_decode_app()
2105 s->iccentries[seqno - 1].length = len; in mjpeg_decode_app()
2106 s->iccentries[seqno - 1].data = av_malloc(len); in mjpeg_decode_app()
2107 if (!s->iccentries[seqno - 1].data) { in mjpeg_decode_app()
2108 av_log(s->avctx, AV_LOG_ERROR, "Could not allocate ICC data buffer\n"); in mjpeg_decode_app()
2112 memcpy(s->iccentries[seqno - 1].data, align_get_bits(&s->gb), len); in mjpeg_decode_app()
2113 skip_bits(&s->gb, len << 3); in mjpeg_decode_app()
2115 s->iccread++; in mjpeg_decode_app()
2117 if (s->iccread > s->iccnum) in mjpeg_decode_app()
2118 … av_log(s->avctx, AV_LOG_WARNING, "Read more ICC markers than are supposed to be coded\n"); in mjpeg_decode_app()
2124 av_log(s->avctx, AV_LOG_ERROR, in mjpeg_decode_app()
2126 while (--len > 0) in mjpeg_decode_app()
2127 skip_bits(&s->gb, 8); in mjpeg_decode_app()
2132 static int mjpeg_decode_com(MJpegDecodeContext *s) in mjpeg_decode_com() argument
2134 int len = get_bits(&s->gb, 16); in mjpeg_decode_com()
2135 if (len >= 2 && 8 * len - 16 <= get_bits_left(&s->gb)) { in mjpeg_decode_com()
2137 char *cbuf = av_malloc(len - 1); in mjpeg_decode_com()
2141 for (i = 0; i < len - 2; i++) in mjpeg_decode_com()
2142 cbuf[i] = get_bits(&s->gb, 8); in mjpeg_decode_com()
2143 if (i > 0 && cbuf[i - 1] == '\n') in mjpeg_decode_com()
2144 cbuf[i - 1] = 0; in mjpeg_decode_com()
2148 if (s->avctx->debug & FF_DEBUG_PICT_INFO) in mjpeg_decode_com()
2149 av_log(s->avctx, AV_LOG_INFO, "comment: '%s'\n", cbuf); in mjpeg_decode_com()
2153 parse_avid(s, cbuf, len); in mjpeg_decode_com()
2155 s->cs_itu601 = 1; in mjpeg_decode_com()
2156 else if ((!strncmp(cbuf, "Intel(R) JPEG Library, version 1", 32) && s->avctx->codec_tag) || in mjpeg_decode_com()
2158 s->flipped = 1; in mjpeg_decode_com()
2160 s->avctx->sample_aspect_ratio = (AVRational) { 1, 2 }; in mjpeg_decode_com()
2161 s->multiscope = 2; in mjpeg_decode_com()
2171 state. Return -1 if no start code found */
2180 while (buf_end - buf_ptr > 1) { in find_marker()
2190 val = -1; in find_marker()
2197 int ff_mjpeg_find_marker(MJpegDecodeContext *s, in ff_mjpeg_find_marker() argument
2205 av_fast_padded_malloc(&s->buffer, &s->buffer_size, buf_end - *buf_ptr); in ff_mjpeg_find_marker()
2206 if (!s->buffer) in ff_mjpeg_find_marker()
2209 /* unescape buffer of SOS, use special treatment for JPEG-LS */ in ff_mjpeg_find_marker()
2210 if (start_code == SOS && !s->ls) { in ff_mjpeg_find_marker()
2213 uint8_t *dst = s->buffer; in ff_mjpeg_find_marker()
2216 ptrdiff_t length = (ptr - src) - (skip); \ in ff_mjpeg_find_marker()
2224 if (s->avctx->codec_id == AV_CODEC_ID_THP) { in ff_mjpeg_find_marker()
2245 src--; in ff_mjpeg_find_marker()
2260 *unescaped_buf_ptr = s->buffer; in ff_mjpeg_find_marker()
2261 *unescaped_buf_size = dst - s->buffer; in ff_mjpeg_find_marker()
2262 memset(s->buffer + *unescaped_buf_size, 0, in ff_mjpeg_find_marker()
2265 av_log(s->avctx, AV_LOG_DEBUG, "escaping removed %"PTRDIFF_SPECIFIER" bytes\n", in ff_mjpeg_find_marker()
2266 (buf_end - *buf_ptr) - (dst - s->buffer)); in ff_mjpeg_find_marker()
2267 } else if (start_code == SOS && s->ls) { in ff_mjpeg_find_marker()
2269 uint8_t *dst = s->buffer; in ff_mjpeg_find_marker()
2281 t -= FFMIN(2, t); in ff_mjpeg_find_marker()
2296 av_log(s->avctx, AV_LOG_WARNING, "Invalid escape sequence\n"); in ff_mjpeg_find_marker()
2300 bit_count--; in ff_mjpeg_find_marker()
2307 memset(s->buffer + *unescaped_buf_size, 0, in ff_mjpeg_find_marker()
2311 *unescaped_buf_size = buf_end - *buf_ptr; in ff_mjpeg_find_marker()
2317 static void reset_icc_profile(MJpegDecodeContext *s) in reset_icc_profile() argument
2321 if (s->iccentries) { in reset_icc_profile()
2322 for (i = 0; i < s->iccnum; i++) in reset_icc_profile()
2323 av_freep(&s->iccentries[i].data); in reset_icc_profile()
2324 av_freep(&s->iccentries); in reset_icc_profile()
2327 s->iccread = 0; in reset_icc_profile()
2328 s->iccnum = 0; in reset_icc_profile()
2335 MJpegDecodeContext *s = avctx->priv_data; in smv_process_frame() local
2338 if (s->smv_next_frame > 0) { in smv_process_frame()
2339 av_assert0(s->smv_frame->buf[0]); in smv_process_frame()
2341 ret = av_frame_ref(frame, s->smv_frame); in smv_process_frame()
2345 av_assert0(frame->buf[0]); in smv_process_frame()
2346 av_frame_unref(s->smv_frame); in smv_process_frame()
2347 ret = av_frame_ref(s->smv_frame, frame); in smv_process_frame()
2352 av_assert0((s->smv_next_frame + 1) * avctx->height <= avctx->coded_height); in smv_process_frame()
2354 frame->width = avctx->coded_width; in smv_process_frame()
2355 frame->height = avctx->coded_height; in smv_process_frame()
2356 frame->crop_top = FFMIN(s->smv_next_frame * avctx->height, frame->height); in smv_process_frame()
2357 frame->crop_bottom = frame->height - (s->smv_next_frame + 1) * avctx->height; in smv_process_frame()
2359 s->smv_next_frame = (s->smv_next_frame + 1) % s->smv_frames_per_jpeg; in smv_process_frame()
2361 if (s->smv_next_frame == 0) in smv_process_frame()
2362 av_frame_unref(s->smv_frame); in smv_process_frame()
2369 MJpegDecodeContext *s = avctx->priv_data; in mjpeg_get_packet() local
2372 av_packet_unref(s->pkt); in mjpeg_get_packet()
2373 ret = ff_decode_get_packet(avctx, s->pkt); in mjpeg_get_packet()
2378 if (avctx->codec_id == AV_CODEC_ID_SP5X || in mjpeg_get_packet()
2379 avctx->codec_id == AV_CODEC_ID_AMV) { in mjpeg_get_packet()
2380 ret = ff_sp5x_process_packet(avctx, s->pkt); in mjpeg_get_packet()
2386 s->buf_size = s->pkt->size; in mjpeg_get_packet()
2393 MJpegDecodeContext *s = avctx->priv_data; in ff_mjpeg_receive_frame() local
2403 if (avctx->codec_id == AV_CODEC_ID_SMVJPEG && s->smv_next_frame > 0) in ff_mjpeg_receive_frame()
2406 av_dict_free(&s->exif_metadata); in ff_mjpeg_receive_frame()
2407 av_freep(&s->stereo3d); in ff_mjpeg_receive_frame()
2408 s->adobe_transform = -1; in ff_mjpeg_receive_frame()
2410 if (s->iccnum != 0) in ff_mjpeg_receive_frame()
2411 reset_icc_profile(s); in ff_mjpeg_receive_frame()
2417 buf_ptr = s->pkt->data; in ff_mjpeg_receive_frame()
2418 buf_end = s->pkt->data + s->pkt->size; in ff_mjpeg_receive_frame()
2421 start_code = ff_mjpeg_find_marker(s, &buf_ptr, buf_end, in ff_mjpeg_receive_frame()
2430 start_code, unescaped_buf_size, s->pkt->size); in ff_mjpeg_receive_frame()
2434 start_code, buf_end - buf_ptr); in ff_mjpeg_receive_frame()
2436 ret = init_get_bits8(&s->gb, unescaped_buf_ptr, unescaped_buf_size); in ff_mjpeg_receive_frame()
2443 s->start_code = start_code; in ff_mjpeg_receive_frame()
2444 if (s->avctx->debug & FF_DEBUG_STARTCODE) in ff_mjpeg_receive_frame()
2453 if ((ret = mjpeg_decode_app(s)) < 0) in ff_mjpeg_receive_frame()
2454 av_log(avctx, AV_LOG_ERROR, "unable to decode APP fields: %s\n", in ff_mjpeg_receive_frame()
2458 ret = mjpeg_decode_com(s); in ff_mjpeg_receive_frame()
2462 ret = ff_mjpeg_decode_dqt(s); in ff_mjpeg_receive_frame()
2467 ret = -1; in ff_mjpeg_receive_frame()
2471 av_log(avctx, AV_LOG_ERROR, "JPEG-LS support not enabled.\n"); in ff_mjpeg_receive_frame()
2475 if (avctx->skip_frame == AVDISCARD_ALL) { in ff_mjpeg_receive_frame()
2493 s->restart_interval = 0; in ff_mjpeg_receive_frame()
2494 s->restart_count = 0; in ff_mjpeg_receive_frame()
2495 s->raw_image_buffer = buf_ptr; in ff_mjpeg_receive_frame()
2496 s->raw_image_buffer_size = buf_end - buf_ptr; in ff_mjpeg_receive_frame()
2500 if ((ret = ff_mjpeg_decode_dht(s)) < 0) { in ff_mjpeg_receive_frame()
2508 s->avctx->profile = FF_PROFILE_MJPEG_HUFFMAN_BASELINE_DCT; in ff_mjpeg_receive_frame()
2510 s->avctx->profile = FF_PROFILE_MJPEG_HUFFMAN_EXTENDED_SEQUENTIAL_DCT; in ff_mjpeg_receive_frame()
2511 s->lossless = 0; in ff_mjpeg_receive_frame()
2512 s->ls = 0; in ff_mjpeg_receive_frame()
2513 s->progressive = 0; in ff_mjpeg_receive_frame()
2514 if ((ret = ff_mjpeg_decode_sof(s)) < 0) in ff_mjpeg_receive_frame()
2518 s->avctx->profile = FF_PROFILE_MJPEG_HUFFMAN_PROGRESSIVE_DCT; in ff_mjpeg_receive_frame()
2519 s->lossless = 0; in ff_mjpeg_receive_frame()
2520 s->ls = 0; in ff_mjpeg_receive_frame()
2521 s->progressive = 1; in ff_mjpeg_receive_frame()
2522 if ((ret = ff_mjpeg_decode_sof(s)) < 0) in ff_mjpeg_receive_frame()
2526 s->avctx->profile = FF_PROFILE_MJPEG_HUFFMAN_LOSSLESS; in ff_mjpeg_receive_frame()
2527 s->avctx->properties |= FF_CODEC_PROPERTY_LOSSLESS; in ff_mjpeg_receive_frame()
2528 s->lossless = 1; in ff_mjpeg_receive_frame()
2529 s->ls = 0; in ff_mjpeg_receive_frame()
2530 s->progressive = 0; in ff_mjpeg_receive_frame()
2531 if ((ret = ff_mjpeg_decode_sof(s)) < 0) in ff_mjpeg_receive_frame()
2535 s->avctx->profile = FF_PROFILE_MJPEG_JPEG_LS; in ff_mjpeg_receive_frame()
2536 s->avctx->properties |= FF_CODEC_PROPERTY_LOSSLESS; in ff_mjpeg_receive_frame()
2537 s->lossless = 1; in ff_mjpeg_receive_frame()
2538 s->ls = 1; in ff_mjpeg_receive_frame()
2539 s->progressive = 0; in ff_mjpeg_receive_frame()
2540 if ((ret = ff_mjpeg_decode_sof(s)) < 0) in ff_mjpeg_receive_frame()
2545 (ret = ff_jpegls_decode_lse(s)) < 0) in ff_mjpeg_receive_frame()
2550 if (!avctx->hwaccel && avctx->skip_frame != AVDISCARD_ALL && in ff_mjpeg_receive_frame()
2551 s->progressive && s->cur_scan && s->got_picture) in ff_mjpeg_receive_frame()
2552 mjpeg_idct_scan_progressive_ac(s); in ff_mjpeg_receive_frame()
2553 s->cur_scan = 0; in ff_mjpeg_receive_frame()
2554 if (!s->got_picture) { in ff_mjpeg_receive_frame()
2559 if (s->interlaced) { in ff_mjpeg_receive_frame()
2560 s->bottom_field ^= 1; in ff_mjpeg_receive_frame()
2562 if (s->bottom_field == !s->interlace_polarity) in ff_mjpeg_receive_frame()
2565 if (avctx->skip_frame == AVDISCARD_ALL) { in ff_mjpeg_receive_frame()
2566 s->got_picture = 0; in ff_mjpeg_receive_frame()
2570 if (s->avctx->hwaccel) { in ff_mjpeg_receive_frame()
2571 ret = s->avctx->hwaccel->end_frame(s->avctx); in ff_mjpeg_receive_frame()
2575 av_freep(&s->hwaccel_picture_private); in ff_mjpeg_receive_frame()
2577 if ((ret = av_frame_ref(frame, s->picture_ptr)) < 0) in ff_mjpeg_receive_frame()
2579 s->got_picture = 0; in ff_mjpeg_receive_frame()
2581 frame->pkt_dts = s->pkt->dts; in ff_mjpeg_receive_frame()
2583 if (!s->lossless && avctx->debug & FF_DEBUG_QP) { in ff_mjpeg_receive_frame()
2584 int qp = FFMAX3(s->qscale[0], in ff_mjpeg_receive_frame()
2585 s->qscale[1], in ff_mjpeg_receive_frame()
2586 s->qscale[2]); in ff_mjpeg_receive_frame()
2593 s->raw_scan_buffer = buf_ptr; in ff_mjpeg_receive_frame()
2594 s->raw_scan_buffer_size = buf_end - buf_ptr; in ff_mjpeg_receive_frame()
2596 s->cur_scan++; in ff_mjpeg_receive_frame()
2597 if (avctx->skip_frame == AVDISCARD_ALL) { in ff_mjpeg_receive_frame()
2598 skip_bits(&s->gb, get_bits_left(&s->gb)); in ff_mjpeg_receive_frame()
2602 if ((ret = ff_mjpeg_decode_sos(s, NULL, 0, NULL)) < 0 && in ff_mjpeg_receive_frame()
2603 (avctx->err_recognition & AV_EF_EXPLODE)) in ff_mjpeg_receive_frame()
2607 if ((ret = mjpeg_decode_dri(s)) < 0) in ff_mjpeg_receive_frame()
2627 buf_ptr += (get_bits_count(&s->gb) + 7) / 8; in ff_mjpeg_receive_frame()
2630 (get_bits_count(&s->gb) + 7) / 8, get_bits_count(&s->gb)); in ff_mjpeg_receive_frame()
2632 if (s->got_picture && s->cur_scan) { in ff_mjpeg_receive_frame()
2639 s->got_picture = 0; in ff_mjpeg_receive_frame()
2643 is16bit = av_pix_fmt_desc_get(s->avctx->pix_fmt)->comp[0].step > 1; in ff_mjpeg_receive_frame()
2645 if (AV_RB32(s->upscale_h)) { in ff_mjpeg_receive_frame()
2647 av_assert0(avctx->pix_fmt == AV_PIX_FMT_YUVJ444P || in ff_mjpeg_receive_frame()
2648 avctx->pix_fmt == AV_PIX_FMT_YUV444P || in ff_mjpeg_receive_frame()
2649 avctx->pix_fmt == AV_PIX_FMT_YUVJ440P || in ff_mjpeg_receive_frame()
2650 avctx->pix_fmt == AV_PIX_FMT_YUV440P || in ff_mjpeg_receive_frame()
2651 avctx->pix_fmt == AV_PIX_FMT_YUVA444P || in ff_mjpeg_receive_frame()
2652 avctx->pix_fmt == AV_PIX_FMT_YUVJ420P || in ff_mjpeg_receive_frame()
2653 avctx->pix_fmt == AV_PIX_FMT_YUV420P || in ff_mjpeg_receive_frame()
2654 avctx->pix_fmt == AV_PIX_FMT_YUV420P16|| in ff_mjpeg_receive_frame()
2655 avctx->pix_fmt == AV_PIX_FMT_YUVA420P || in ff_mjpeg_receive_frame()
2656 avctx->pix_fmt == AV_PIX_FMT_YUVA420P16|| in ff_mjpeg_receive_frame()
2657 avctx->pix_fmt == AV_PIX_FMT_GBRP || in ff_mjpeg_receive_frame()
2658 avctx->pix_fmt == AV_PIX_FMT_GBRAP in ff_mjpeg_receive_frame()
2660 ret = av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt, &hshift, &vshift); in ff_mjpeg_receive_frame()
2664 av_assert0(s->nb_components == av_pix_fmt_count_planes(s->picture_ptr->format)); in ff_mjpeg_receive_frame()
2665 for (p = 0; p<s->nb_components; p++) { in ff_mjpeg_receive_frame()
2666 uint8_t *line = s->picture_ptr->data[p]; in ff_mjpeg_receive_frame()
2667 int w = s->width; in ff_mjpeg_receive_frame()
2668 int h = s->height; in ff_mjpeg_receive_frame()
2669 if (!s->upscale_h[p]) in ff_mjpeg_receive_frame()
2675 if (s->upscale_v[p] == 1) in ff_mjpeg_receive_frame()
2679 if (s->upscale_h[p] == 1) { in ff_mjpeg_receive_frame()
2680 if (is16bit) ((uint16_t*)line)[w - 1] = ((uint16_t*)line)[(w - 1) / 2]; in ff_mjpeg_receive_frame()
2681 else line[w - 1] = line[(w - 1) / 2]; in ff_mjpeg_receive_frame()
2682 for (index = w - 2; index > 0; index--) { in ff_mjpeg_receive_frame()
2688 } else if (s->upscale_h[p] == 2) { in ff_mjpeg_receive_frame()
2690 ((uint16_t*)line)[w - 1] = ((uint16_t*)line)[(w - 1) / 3]; in ff_mjpeg_receive_frame()
2692 ((uint16_t*)line)[w - 2] = ((uint16_t*)line)[w - 1]; in ff_mjpeg_receive_frame()
2694 line[w - 1] = line[(w - 1) / 3]; in ff_mjpeg_receive_frame()
2696 line[w - 2] = line[w - 1]; in ff_mjpeg_receive_frame()
2698 for (index = w - 3; index > 0; index--) { in ff_mjpeg_receive_frame()
2702 line += s->linesize[p]; in ff_mjpeg_receive_frame()
2706 if (AV_RB32(s->upscale_v)) { in ff_mjpeg_receive_frame()
2708 av_assert0(avctx->pix_fmt == AV_PIX_FMT_YUVJ444P || in ff_mjpeg_receive_frame()
2709 avctx->pix_fmt == AV_PIX_FMT_YUV444P || in ff_mjpeg_receive_frame()
2710 avctx->pix_fmt == AV_PIX_FMT_YUVJ422P || in ff_mjpeg_receive_frame()
2711 avctx->pix_fmt == AV_PIX_FMT_YUV422P || in ff_mjpeg_receive_frame()
2712 avctx->pix_fmt == AV_PIX_FMT_YUVJ420P || in ff_mjpeg_receive_frame()
2713 avctx->pix_fmt == AV_PIX_FMT_YUV420P || in ff_mjpeg_receive_frame()
2714 avctx->pix_fmt == AV_PIX_FMT_YUV440P || in ff_mjpeg_receive_frame()
2715 avctx->pix_fmt == AV_PIX_FMT_YUVJ440P || in ff_mjpeg_receive_frame()
2716 avctx->pix_fmt == AV_PIX_FMT_YUVA444P || in ff_mjpeg_receive_frame()
2717 avctx->pix_fmt == AV_PIX_FMT_YUVA420P || in ff_mjpeg_receive_frame()
2718 avctx->pix_fmt == AV_PIX_FMT_YUVA420P16|| in ff_mjpeg_receive_frame()
2719 avctx->pix_fmt == AV_PIX_FMT_GBRP || in ff_mjpeg_receive_frame()
2720 avctx->pix_fmt == AV_PIX_FMT_GBRAP in ff_mjpeg_receive_frame()
2722 ret = av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt, &hshift, &vshift); in ff_mjpeg_receive_frame()
2726 av_assert0(s->nb_components == av_pix_fmt_count_planes(s->picture_ptr->format)); in ff_mjpeg_receive_frame()
2727 for (p = 0; p < s->nb_components; p++) { in ff_mjpeg_receive_frame()
2729 int w = s->width; in ff_mjpeg_receive_frame()
2730 int h = s->height; in ff_mjpeg_receive_frame()
2731 if (!s->upscale_v[p]) in ff_mjpeg_receive_frame()
2737 dst = &((uint8_t *)s->picture_ptr->data[p])[(h - 1) * s->linesize[p]]; in ff_mjpeg_receive_frame()
2738 for (i = h - 1; i; i--) { in ff_mjpeg_receive_frame()
2739 …uint8_t *src1 = &((uint8_t *)s->picture_ptr->data[p])[i * s->upscale_v[p] / (s->upscale_v[p] + 1) … in ff_mjpeg_receive_frame()
2740 …uint8_t *src2 = &((uint8_t *)s->picture_ptr->data[p])[(i + 1) * s->upscale_v[p] / (s->upscale_v[p]… in ff_mjpeg_receive_frame()
2741 if (s->upscale_v[p] != 2 && (src1 == src2 || i == h - 1)) { in ff_mjpeg_receive_frame()
2747 dst -= s->linesize[p]; in ff_mjpeg_receive_frame()
2751 if (s->flipped && !s->rgb) { in ff_mjpeg_receive_frame()
2753 ret = av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt, &hshift, &vshift); in ff_mjpeg_receive_frame()
2757 av_assert0(s->nb_components == av_pix_fmt_count_planes(s->picture_ptr->format)); in ff_mjpeg_receive_frame()
2758 for (index=0; index<s->nb_components; index++) { in ff_mjpeg_receive_frame()
2759 uint8_t *dst = s->picture_ptr->data[index]; in ff_mjpeg_receive_frame()
2760 int w = s->picture_ptr->width; in ff_mjpeg_receive_frame()
2761 int h = s->picture_ptr->height; in ff_mjpeg_receive_frame()
2767 uint8_t *dst2 = dst + s->picture_ptr->linesize[index]*(h-1); in ff_mjpeg_receive_frame()
2771 dst += s->picture_ptr->linesize[index]; in ff_mjpeg_receive_frame()
2772 dst2 -= s->picture_ptr->linesize[index]; in ff_mjpeg_receive_frame()
2777 if (s->adobe_transform == 0 && s->avctx->pix_fmt == AV_PIX_FMT_GBRAP) { in ff_mjpeg_receive_frame()
2778 int w = s->picture_ptr->width; in ff_mjpeg_receive_frame()
2779 int h = s->picture_ptr->height; in ff_mjpeg_receive_frame()
2780 av_assert0(s->nb_components == 4); in ff_mjpeg_receive_frame()
2785 dst[index] = s->picture_ptr->data[index] in ff_mjpeg_receive_frame()
2786 + s->picture_ptr->linesize[index]*i; in ff_mjpeg_receive_frame()
2800 if (s->adobe_transform == 2 && s->avctx->pix_fmt == AV_PIX_FMT_YUVA444P) { in ff_mjpeg_receive_frame()
2801 int w = s->picture_ptr->width; in ff_mjpeg_receive_frame()
2802 int h = s->picture_ptr->height; in ff_mjpeg_receive_frame()
2803 av_assert0(s->nb_components == 4); in ff_mjpeg_receive_frame()
2808 dst[index] = s->picture_ptr->data[index] in ff_mjpeg_receive_frame()
2809 + s->picture_ptr->linesize[index]*i; in ff_mjpeg_receive_frame()
2813 int r = (255 - dst[0][j]) * k; in ff_mjpeg_receive_frame()
2814 int g = (128 - dst[1][j]) * k; in ff_mjpeg_receive_frame()
2815 int b = (128 - dst[2][j]) * k; in ff_mjpeg_receive_frame()
2824 if (s->stereo3d) { in ff_mjpeg_receive_frame()
2827 stereo->type = s->stereo3d->type; in ff_mjpeg_receive_frame()
2828 stereo->flags = s->stereo3d->flags; in ff_mjpeg_receive_frame()
2830 av_freep(&s->stereo3d); in ff_mjpeg_receive_frame()
2833 if (s->iccnum != 0 && s->iccnum == s->iccread) { in ff_mjpeg_receive_frame()
2840 for (i = 0; i < s->iccnum; i++) in ff_mjpeg_receive_frame()
2841 total_size += s->iccentries[i].length; in ff_mjpeg_receive_frame()
2845 av_log(s->avctx, AV_LOG_ERROR, "Could not allocate frame side data\n"); in ff_mjpeg_receive_frame()
2849 /* Reassemble the parts, which are now in-order. */ in ff_mjpeg_receive_frame()
2850 for (i = 0; i < s->iccnum; i++) { in ff_mjpeg_receive_frame()
2851 memcpy(sd->data + offset, s->iccentries[i].data, s->iccentries[i].length); in ff_mjpeg_receive_frame()
2852 offset += s->iccentries[i].length; in ff_mjpeg_receive_frame()
2856 av_dict_copy(&frame->metadata, s->exif_metadata, 0); in ff_mjpeg_receive_frame()
2857 av_dict_free(&s->exif_metadata); in ff_mjpeg_receive_frame()
2859 if (avctx->codec_id == AV_CODEC_ID_SMVJPEG) { in ff_mjpeg_receive_frame()
2866 if ((avctx->codec_tag == MKTAG('A', 'V', 'R', 'n') || in ff_mjpeg_receive_frame()
2867 avctx->codec_tag == MKTAG('A', 'V', 'D', 'J')) && in ff_mjpeg_receive_frame()
2868 avctx->coded_height > s->orig_height) { in ff_mjpeg_receive_frame()
2869 frame->height = AV_CEIL_RSHIFT(avctx->coded_height, avctx->lowres); in ff_mjpeg_receive_frame()
2870 frame->crop_top = frame->height - avctx->height; in ff_mjpeg_receive_frame()
2877 buf_end - buf_ptr); in ff_mjpeg_receive_frame()
2886 MJpegDecodeContext *s = avctx->priv_data; in ff_mjpeg_decode_end() local
2889 …if (s->interlaced && s->bottom_field == !s->interlace_polarity && s->got_picture && !avctx->frame_… in ff_mjpeg_decode_end()
2893 if (s->picture) { in ff_mjpeg_decode_end()
2894 av_frame_free(&s->picture); in ff_mjpeg_decode_end()
2895 s->picture_ptr = NULL; in ff_mjpeg_decode_end()
2896 } else if (s->picture_ptr) in ff_mjpeg_decode_end()
2897 av_frame_unref(s->picture_ptr); in ff_mjpeg_decode_end()
2899 av_packet_free(&s->pkt); in ff_mjpeg_decode_end()
2901 av_frame_free(&s->smv_frame); in ff_mjpeg_decode_end()
2903 av_freep(&s->buffer); in ff_mjpeg_decode_end()
2904 av_freep(&s->stereo3d); in ff_mjpeg_decode_end()
2905 av_freep(&s->ljpeg_buffer); in ff_mjpeg_decode_end()
2906 s->ljpeg_buffer_size = 0; in ff_mjpeg_decode_end()
2910 ff_free_vlc(&s->vlcs[i][j]); in ff_mjpeg_decode_end()
2913 av_freep(&s->blocks[i]); in ff_mjpeg_decode_end()
2914 av_freep(&s->last_nnz[i]); in ff_mjpeg_decode_end()
2916 av_dict_free(&s->exif_metadata); in ff_mjpeg_decode_end()
2918 reset_icc_profile(s); in ff_mjpeg_decode_end()
2920 av_freep(&s->hwaccel_picture_private); in ff_mjpeg_decode_end()
2927 MJpegDecodeContext *s = avctx->priv_data; in decode_flush() local
2928 s->got_picture = 0; in decode_flush()
2930 s->smv_next_frame = 0; in decode_flush()
2931 av_frame_unref(s->smv_frame); in decode_flush()