Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions libavcodec/jpeg2000dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,25 @@ static int get_siz(Jpeg2000DecoderContext *s)
return AVERROR_INVALIDDATA;
}

for (i = 0; i < s->ncomponents; i++) {
if (s->cdef[i] < 0) {
for (i = 0; i < s->ncomponents; i++) {
s->cdef[i] = i + 1;
}
if ((s->ncomponents & 1) == 0)
s->cdef[s->ncomponents-1] = 0;
}
}
// after here we no longer have to consider negative cdef

int cdef_used = 0;
for (i = 0; i < s->ncomponents; i++)
cdef_used |= 1<<s->cdef[i];

// Check that the channels we have are what we expect for the number of components
if (cdef_used != ((int[]){0,2,3,14,15})[s->ncomponents])
return AVERROR_INVALIDDATA;

for (i = 0; i < s->ncomponents; i++) { // Ssiz_i XRsiz_i, YRsiz_i
uint8_t x = bytestream2_get_byteu(&s->g);
s->cbps[i] = (x & 0x7f) + 1;
Expand All @@ -283,7 +302,9 @@ static int get_siz(Jpeg2000DecoderContext *s)
av_log(s->avctx, AV_LOG_ERROR, "Invalid sample separation %d/%d\n", s->cdx[i], s->cdy[i]);
return AVERROR_INVALIDDATA;
}
log2_chroma_wh |= s->cdy[i] >> 1 << i * 4 | s->cdx[i] >> 1 << i * 4 + 2;
int i_remapped = s->cdef[i] ? s->cdef[i]-1 : (s->ncomponents-1);

log2_chroma_wh |= s->cdy[i] >> 1 << i_remapped * 4 | s->cdx[i] >> 1 << i_remapped * 4 + 2;
}

s->numXtiles = ff_jpeg2000_ceildiv(s->width - s->tile_offset_x, s->tile_width);
Expand Down Expand Up @@ -2853,17 +2874,6 @@ static int jpeg2000_decode_frame(AVCodecContext *avctx, AVFrame *picture,
if (ret = jpeg2000_read_bitstream_packets(s))
goto end;

for (int x = 0; x < s->ncomponents; x++) {
if (s->cdef[x] < 0) {
for (x = 0; x < s->ncomponents; x++) {
s->cdef[x] = x + 1;
}
if ((s->ncomponents & 1) == 0)
s->cdef[s->ncomponents-1] = 0;
break;
}
}

avctx->execute2(avctx, jpeg2000_decode_tile, picture, NULL, s->numXtiles * s->numYtiles);

jpeg2000_dec_cleanup(s);
Expand Down