Commit f471b5fa authored by Michael Niedermayer's avatar Michael Niedermayer

j2k: restructure bitstream decoding

This is based on jpeg2000 but differs because of
problems with the design from jpeg2000 with currently
supported files

More files can be decoded after this commit, though they
show heavy artifacts
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent cdb86136
...@@ -43,9 +43,8 @@ ...@@ -43,9 +43,8 @@
#define HAD_QCC 0x02 #define HAD_QCC 0x02
typedef struct Jpeg2000TilePart { typedef struct Jpeg2000TilePart {
uint16_t tp_idx; // Tile-part index
uint8_t tile_index; // Tile index who refers the tile-part uint8_t tile_index; // Tile index who refers the tile-part
uint32_t tp_len; // Length of tile-part const uint8_t *tp_end;
GetByteContext tpg; // bit stream in tile-part GetByteContext tpg; // bit stream in tile-part
} Jpeg2000TilePart; } Jpeg2000TilePart;
...@@ -57,6 +56,7 @@ typedef struct Jpeg2000Tile { ...@@ -57,6 +56,7 @@ typedef struct Jpeg2000Tile {
Jpeg2000CodingStyle codsty[4]; Jpeg2000CodingStyle codsty[4];
Jpeg2000QuantStyle qntsty[4]; Jpeg2000QuantStyle qntsty[4];
Jpeg2000TilePart tile_part[3]; Jpeg2000TilePart tile_part[3];
uint16_t tp_idx; // Tile-part index
} Jpeg2000Tile; } Jpeg2000Tile;
typedef struct Jpeg2000DecoderContext { typedef struct Jpeg2000DecoderContext {
...@@ -464,10 +464,10 @@ static int get_sot(Jpeg2000DecoderContext *s, int n) ...@@ -464,10 +464,10 @@ static int get_sot(Jpeg2000DecoderContext *s, int n)
return AVERROR_PATCHWELCOME; return AVERROR_PATCHWELCOME;
} }
s->tile[s->curtileno].tp_idx = TPsot;
tp = s->tile[s->curtileno].tile_part + TPsot; tp = s->tile[s->curtileno].tile_part + TPsot;
tp->tile_index = Isot; tp->tile_index = Isot;
tp->tp_len = Psot; tp->tp_end = s->g.buffer + Psot - n - 2;
tp->tp_idx = TPsot;
if (!TPsot) { if (!TPsot) {
Jpeg2000Tile *tile = s->tile + s->curtileno; Jpeg2000Tile *tile = s->tile + s->curtileno;
...@@ -531,6 +531,7 @@ static int init_tile(Jpeg2000DecoderContext *s, int tileno) ...@@ -531,6 +531,7 @@ static int init_tile(Jpeg2000DecoderContext *s, int tileno)
if (!tile->comp) if (!tile->comp)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
for (compno = 0; compno < s->ncomponents; compno++) { for (compno = 0; compno < s->ncomponents; compno++) {
Jpeg2000Component *comp = tile->comp + compno; Jpeg2000Component *comp = tile->comp + compno;
Jpeg2000CodingStyle *codsty = tile->codsty + compno; Jpeg2000CodingStyle *codsty = tile->codsty + compno;
...@@ -1106,7 +1107,7 @@ static void jpeg2000_dec_cleanup(Jpeg2000DecoderContext *s) ...@@ -1106,7 +1107,7 @@ static void jpeg2000_dec_cleanup(Jpeg2000DecoderContext *s)
av_freep(&s->tile); av_freep(&s->tile);
} }
static int jpeg2000_decode_codestream(Jpeg2000DecoderContext *s) static int jpeg2000_read_main_headers(Jpeg2000DecoderContext *s)
{ {
Jpeg2000CodingStyle *codsty = s->codsty; Jpeg2000CodingStyle *codsty = s->codsty;
Jpeg2000QuantStyle *qntsty = s->qntsty; Jpeg2000QuantStyle *qntsty = s->qntsty;
...@@ -1127,14 +1128,11 @@ static int jpeg2000_decode_codestream(Jpeg2000DecoderContext *s) ...@@ -1127,14 +1128,11 @@ static int jpeg2000_decode_codestream(Jpeg2000DecoderContext *s)
if (marker == JPEG2000_SOD) { if (marker == JPEG2000_SOD) {
Jpeg2000Tile *tile = s->tile + s->curtileno; Jpeg2000Tile *tile = s->tile + s->curtileno;
if (ret = init_tile(s, s->curtileno)) { Jpeg2000TilePart *tp = tile->tile_part + tile->tp_idx;
av_log(s->avctx, AV_LOG_ERROR, "tile initialization failed\n");
return ret; bytestream2_init(&tp->tpg, s->g.buffer, tp->tp_end - s->g.buffer);
} bytestream2_skip(&s->g, tp->tp_end - s->g.buffer);
if (ret = jpeg2000_decode_packets(s, tile)) {
av_log(s->avctx, AV_LOG_ERROR, "packets decoding failed\n");
return ret;
}
continue; continue;
} }
if (marker == JPEG2000_EOC) if (marker == JPEG2000_EOC)
...@@ -1196,12 +1194,18 @@ static int jpeg2000_decode_codestream(Jpeg2000DecoderContext *s) ...@@ -1196,12 +1194,18 @@ static int jpeg2000_decode_codestream(Jpeg2000DecoderContext *s)
static int jpeg2000_read_bitstream_packets(Jpeg2000DecoderContext *s) static int jpeg2000_read_bitstream_packets(Jpeg2000DecoderContext *s)
{ {
int ret = 0; int ret = 0;
Jpeg2000Tile *tile = s->tile + s->curtileno; int tileno;
for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++) {
Jpeg2000Tile *tile = s->tile + tileno;
if (ret = init_tile(s, s->curtileno)) if (ret = init_tile(s, tileno))
return ret; return ret;
s->g = tile->tile_part[0].tpg;
if (ret = jpeg2000_decode_packets(s, tile)) if (ret = jpeg2000_decode_packets(s, tile))
return ret; return ret;
}
return 0; return 0;
} }
...@@ -1269,7 +1273,10 @@ static int jpeg2000_decode_frame(AVCodecContext *avctx, void *data, ...@@ -1269,7 +1273,10 @@ static int jpeg2000_decode_frame(AVCodecContext *avctx, void *data,
ret = -1; ret = -1;
goto err_out; goto err_out;
} }
if (ret = jpeg2000_decode_codestream(s)) if (ret = jpeg2000_read_main_headers(s))
goto err_out;
if (ret = jpeg2000_read_bitstream_packets(s))
goto err_out; goto err_out;
for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++) for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment