1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

jpeg2000dec: parse CDEF

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

Conflicts:

	libavcodec/jpeg2000dec.c

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2013-07-08 00:57:32 +02:00
parent ed8c34a766
commit 99de97cabf

View File

@ -77,6 +77,7 @@ typedef struct Jpeg2000DecoderContext {
int colour_space; int colour_space;
uint32_t palette[256]; uint32_t palette[256];
int8_t pal8; int8_t pal8;
int cdef[4];
int tile_width, tile_height; int tile_width, tile_height;
unsigned numXtiles, numYtiles; unsigned numXtiles, numYtiles;
int maxtilelen; int maxtilelen;
@ -1229,6 +1230,13 @@ static int jpeg2000_decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
if (tile->codsty[0].mct) if (tile->codsty[0].mct)
mct_decode(s, tile); mct_decode(s, tile);
if (s->cdef[0] < 0) {
for (x = 0; x < s->ncomponents; x++)
s->cdef[x] = x + 1;
if ((s->ncomponents & 1) == 0)
s->cdef[s->ncomponents-1] = 0;
}
if (s->precision <= 8) { if (s->precision <= 8) {
for (compno = 0; compno < s->ncomponents; compno++) { for (compno = 0; compno < s->ncomponents; compno++) {
Jpeg2000Component *comp = tile->comp + compno; Jpeg2000Component *comp = tile->comp + compno;
@ -1535,6 +1543,21 @@ static int jp2_find_codestream(Jpeg2000DecoderContext *s)
atom2_size -= size; atom2_size -= size;
bytestream2_skipu(&s->g, atom2_size); bytestream2_skipu(&s->g, atom2_size);
atom_size -= atom2_size; atom_size -= atom2_size;
} else if (atom2 == MKBETAG('c','d','e','f') && atom2_size >= 2 &&
bytestream2_get_bytes_left(&s->g) >= atom2_size) {
int n = bytestream2_get_be16u(&s->g);
atom_size -= 2;
atom2_size -= 2;
for (; n>0; n--) {
int cn = bytestream2_get_be16(&s->g);
int typ = bytestream2_get_be16(&s->g);
int asoc = bytestream2_get_be16(&s->g);
if (cn < 4 || asoc < 4)
s->cdef[cn] = asoc;
atom_size -= 6;
atom2_size -= 6;
}
bytestream2_skipu(&s->g, atom2_size);
} else { } else {
bytestream2_skipu(&s->g, atom2_size); bytestream2_skipu(&s->g, atom2_size);
atom_size -= atom2_size; atom_size -= atom2_size;
@ -1565,6 +1588,7 @@ static int jpeg2000_decode_frame(AVCodecContext *avctx, void *data,
s->avctx = avctx; s->avctx = avctx;
bytestream2_init(&s->g, avpkt->data, avpkt->size); bytestream2_init(&s->g, avpkt->data, avpkt->size);
s->curtileno = -1; s->curtileno = -1;
memset(s->cdef, -1, sizeof(s->cdef));
if (bytestream2_get_bytes_left(&s->g) < 2) { if (bytestream2_get_bytes_left(&s->g) < 2) {
ret = AVERROR_INVALIDDATA; ret = AVERROR_INVALIDDATA;