if (is_ac)
huff_sym[0] = 16 * 256;
- return init_vlc_sparse(vlc, 9, nb_codes, huff_size, 1, 1,
- huff_code, 2, 2, huff_sym, 2, 2, use_static);
+ return ff_init_vlc_sparse(vlc, 9, nb_codes, huff_size, 1, 1,
+ huff_code, 2, 2, huff_sym, 2, 2, use_static);
}
static void build_basic_mjpeg_vlc(MJpegDecodeContext *s)
avcodec_get_frame_defaults(&s->picture);
s->avctx = avctx;
- dsputil_init(&s->dsp, avctx);
+ ff_dsputil_init(&s->dsp, avctx);
ff_init_scantable(s->dsp.idct_permutation, &s->scantable, ff_zigzag_direct);
s->buffer_size = 0;
s->buffer = NULL;
build_basic_mjpeg_vlc(s);
-#if FF_API_MJPEG_GLOBAL_OPTS
- if (avctx->flags & CODEC_FLAG_EXTERN_HUFF)
- s->extern_huff = 1;
-#endif
if (s->extern_huff) {
av_log(avctx, AV_LOG_INFO, "mjpeg: using external huffman table\n");
init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size * 8);
len -= n;
/* build VLC and flush previous vlc if present */
- free_vlc(&s->vlcs[class][index]);
+ ff_free_vlc(&s->vlcs[class][index]);
av_log(s->avctx, AV_LOG_DEBUG, "class=%d index=%d nb_codes=%d\n",
class, index, code_max + 1);
if (build_vlc(&s->vlcs[class][index], bits_table, val_table,
return -1;
if (class > 0) {
- free_vlc(&s->vlcs[2][index]);
+ ff_free_vlc(&s->vlcs[2][index]);
if (build_vlc(&s->vlcs[2][index], bits_table, val_table,
code_max + 1, 0, 0) < 0)
return -1;
int len, nb_components, i, width, height, pix_fmt_id;
s->cur_scan = 0;
+ s->upscale_h = s->upscale_v = 0;
/* XXX: verify len field validity */
len = get_bits(&s->gb, 16);
return -1;
}
if (s->ls) {
+ s->upscale_h = s->upscale_v = 0;
if (s->nb_components > 1)
s->avctx->pix_fmt = PIX_FMT_RGB24;
else if (s->bits <= 8)
int resync_mb_y = 0;
int resync_mb_x = 0;
+ s->restart_count = s->restart_interval;
+
av_fast_malloc(&s->ljpeg_buffer, &s->ljpeg_buffer_size,
(unsigned)s->mb_width * 4 * sizeof(s->ljpeg_buffer[0][0]));
buffer = s->ljpeg_buffer;
if (s->restart_interval) {
s->restart_count--;
+ if(s->restart_count == 0 && s->avctx->codec_id == CODEC_ID_THP){
+ align_get_bits(&s->gb);
+ for (i = 0; i < nb_components; i++) /* reset dc */
+ s->last_dc[i] = 1024;
+ }
+
i = 8 + ((-get_bits_count(&s->gb)) & 7);
/* skip RSTn */
if (show_bits(&s->gb, i) == (1 << i) - 1) {
return -1;
}
}
- if (s->upscale_h) {
- uint8_t *line = s->picture_ptr->data[s->upscale_h];
- for (i = 0; i < s->chroma_height; i++) {
- for (index = s->width - 1; index; index--)
- line[index] = (line[index / 2] + line[(index + 1) / 2]) >> 1;
- line += s->linesize[s->upscale_h];
- }
- }
- if (s->upscale_v) {
- uint8_t *dst = &((uint8_t *)s->picture_ptr->data[s->upscale_v])[(s->height - 1) * s->linesize[s->upscale_v]];
- for (i = s->height - 1; i; i--) {
- uint8_t *src1 = &((uint8_t *)s->picture_ptr->data[s->upscale_v])[i / 2 * s->linesize[s->upscale_v]];
- uint8_t *src2 = &((uint8_t *)s->picture_ptr->data[s->upscale_v])[(i + 1) / 2 * s->linesize[s->upscale_v]];
- if (src1 == src2) {
- memcpy(dst, src1, s->width);
- } else {
- for (index = 0; index < s->width; index++)
- dst[index] = (src1[index] + src2[index]) >> 1;
- }
- dst -= s->linesize[s->upscale_v];
- }
- }
emms_c();
return 0;
out_of_range:
int start_code;
start_code = find_marker(buf_ptr, buf_end);
- if ((buf_end - *buf_ptr) > s->buffer_size) {
- av_free(s->buffer);
- s->buffer_size = buf_end - *buf_ptr;
- s->buffer = av_malloc(s->buffer_size + FF_INPUT_BUFFER_PADDING_SIZE);
- av_log(s->avctx, AV_LOG_DEBUG,
- "buffer too small, expanding to %d bytes\n", s->buffer_size);
- }
+ av_fast_padded_malloc(&s->buffer, &s->buffer_size, buf_end - *buf_ptr);
+ if (!s->buffer)
+ return AVERROR(ENOMEM);
/* unescape buffer of SOS, use special treatment for JPEG-LS */
if (start_code == SOS && !s->ls) {
const uint8_t *unescaped_buf_ptr;
int unescaped_buf_size;
int start_code;
+ int i, index;
AVFrame *picture = data;
s->got_picture = 0; // picture from previous image can not be reused
av_log(avctx, AV_LOG_FATAL, "No JPEG data found in image\n");
return -1;
the_end:
+ if (s->upscale_h) {
+ uint8_t *line = s->picture_ptr->data[s->upscale_h];
+ av_assert0(avctx->pix_fmt == PIX_FMT_YUVJ444P ||
+ avctx->pix_fmt == PIX_FMT_YUV444P ||
+ avctx->pix_fmt == PIX_FMT_YUVJ440P ||
+ avctx->pix_fmt == PIX_FMT_YUV440P);
+ for (i = 0; i < s->chroma_height; i++) {
+ for (index = s->width - 1; index; index--)
+ line[index] = (line[index / 2] + line[(index + 1) / 2]) >> 1;
+ line += s->linesize[s->upscale_h];
+ }
+ }
+ if (s->upscale_v) {
+ uint8_t *dst = &((uint8_t *)s->picture_ptr->data[s->upscale_v])[(s->height - 1) * s->linesize[s->upscale_v]];
+ av_assert0(avctx->pix_fmt == PIX_FMT_YUVJ444P ||
+ avctx->pix_fmt == PIX_FMT_YUV444P ||
+ avctx->pix_fmt == PIX_FMT_YUVJ422P ||
+ avctx->pix_fmt == PIX_FMT_YUV422P);
+ for (i = s->height - 1; i; i--) {
+ uint8_t *src1 = &((uint8_t *)s->picture_ptr->data[s->upscale_v])[i / 2 * s->linesize[s->upscale_v]];
+ uint8_t *src2 = &((uint8_t *)s->picture_ptr->data[s->upscale_v])[(i + 1) / 2 * s->linesize[s->upscale_v]];
+ if (src1 == src2) {
+ memcpy(dst, src1, s->width);
+ } else {
+ for (index = 0; index < s->width; index++)
+ dst[index] = (src1[index] + src2[index]) >> 1;
+ }
+ dst -= s->linesize[s->upscale_v];
+ }
+ }
av_log(avctx, AV_LOG_DEBUG, "mjpeg decode frame unused %td bytes\n",
buf_end - buf_ptr);
// return buf_end - buf_ptr;
for (i = 0; i < 3; i++) {
for (j = 0; j < 4; j++)
- free_vlc(&s->vlcs[i][j]);
+ ff_free_vlc(&s->vlcs[i][j]);
}
for (i = 0; i < MAX_COMPONENTS; i++) {
av_freep(&s->blocks[i]);