Commit cdb86136 authored by Michael Niedermayer's avatar Michael Niedermayer

j2k/jpeg2000: merge some of the tilepart related code

Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent a5203d86
...@@ -42,11 +42,21 @@ ...@@ -42,11 +42,21 @@
#define HAD_COC 0x01 #define HAD_COC 0x01
#define HAD_QCC 0x02 #define HAD_QCC 0x02
typedef struct Jpeg2000TilePart {
uint16_t tp_idx; // Tile-part index
uint8_t tile_index; // Tile index who refers the tile-part
uint32_t tp_len; // Length of tile-part
GetByteContext tpg; // bit stream in tile-part
} Jpeg2000TilePart;
/* RMK: For JPEG2000 DCINEMA 3 tile-parts in a tile
* one per component, so tile_part elements have a size of 3 */
typedef struct Jpeg2000Tile { typedef struct Jpeg2000Tile {
Jpeg2000Component *comp; Jpeg2000Component *comp;
uint8_t properties[4]; uint8_t properties[4];
Jpeg2000CodingStyle codsty[4]; Jpeg2000CodingStyle codsty[4];
Jpeg2000QuantStyle qntsty[4]; Jpeg2000QuantStyle qntsty[4];
Jpeg2000TilePart tile_part[3];
} Jpeg2000Tile; } Jpeg2000Tile;
typedef struct Jpeg2000DecoderContext { typedef struct Jpeg2000DecoderContext {
...@@ -427,28 +437,45 @@ static int get_qcc(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q, ...@@ -427,28 +437,45 @@ static int get_qcc(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q,
return get_qcx(s, n - 1, q + compno); return get_qcx(s, n - 1, q + compno);
} }
/* get start of tile segment */ /* Get start of tile segment. */
static int get_sot(Jpeg2000DecoderContext *s) static int get_sot(Jpeg2000DecoderContext *s, int n)
{ {
Jpeg2000TilePart *tp;
uint16_t Isot;
uint32_t Psot;
uint8_t TPsot;
if (bytestream2_get_bytes_left(&s->g) < 8) if (bytestream2_get_bytes_left(&s->g) < 8)
return AVERROR(EINVAL); return AVERROR(EINVAL);
s->curtileno = bytestream2_get_be16u(&s->g); ///< Isot s->curtileno = Isot = bytestream2_get_be16u(&s->g); // Isot
if ((unsigned)s->curtileno >= s->numXtiles * s->numYtiles) { if ((unsigned)s->curtileno >= s->numXtiles * s->numYtiles) {
s->curtileno=0; s->curtileno=0;
return AVERROR(EINVAL); return AVERROR(EINVAL);
} }
Psot = bytestream2_get_be32u(&s->g); // Psot
TPsot = bytestream2_get_byteu(&s->g); // TPsot
/* Read TNSot but not used */
bytestream2_get_byteu(&s->g); // TNsot
if (TPsot >= FF_ARRAY_ELEMS(s->tile[s->curtileno].tile_part)) {
av_log(s->avctx, AV_LOG_ERROR, "TPsot %d too big\n", TPsot);
return AVERROR_PATCHWELCOME;
}
bytestream2_skipu(&s->g, 4); ///< Psot (ignored) tp = s->tile[s->curtileno].tile_part + TPsot;
tp->tile_index = Isot;
tp->tp_len = Psot;
tp->tp_idx = TPsot;
if (!bytestream2_get_byteu(&s->g)) { ///< TPsot if (!TPsot) {
Jpeg2000Tile *tile = s->tile + s->curtileno; Jpeg2000Tile *tile = s->tile + s->curtileno;
/* copy defaults */ /* copy defaults */
memcpy(tile->codsty, s->codsty, s->ncomponents * sizeof(Jpeg2000CodingStyle)); memcpy(tile->codsty, s->codsty, s->ncomponents * sizeof(Jpeg2000CodingStyle));
memcpy(tile->qntsty, s->qntsty, s->ncomponents * sizeof(Jpeg2000QuantStyle)); memcpy(tile->qntsty, s->qntsty, s->ncomponents * sizeof(Jpeg2000QuantStyle));
} }
bytestream2_get_byteu(&s->g); ///< TNsot
return 0; return 0;
} }
...@@ -526,7 +553,7 @@ static int init_tile(Jpeg2000DecoderContext *s, int tileno) ...@@ -526,7 +553,7 @@ static int init_tile(Jpeg2000DecoderContext *s, int tileno)
return 0; return 0;
} }
/* read the number of coding passes */ /* Read the number of coding passes. */
static int getnpasses(Jpeg2000DecoderContext *s) static int getnpasses(Jpeg2000DecoderContext *s)
{ {
int num; int num;
...@@ -835,6 +862,12 @@ static int decode_cblk(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *codsty, ...@@ -835,6 +862,12 @@ static int decode_cblk(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *codsty,
return 0; return 0;
} }
/* TODO: Verify dequantization for lossless case
* comp->data can be float or int
* band->stepsize can be float or int
* depending on the type of DWT transformation.
* see ISO/IEC 15444-1:2002 A.6.1 */
/* Float dequantization of a codeblock.*/ /* Float dequantization of a codeblock.*/
static void dequantization_float(int x, int y, Jpeg2000Cblk *cblk, static void dequantization_float(int x, int y, Jpeg2000Cblk *cblk,
Jpeg2000Component *comp, Jpeg2000Component *comp,
...@@ -985,6 +1018,7 @@ static int jpeg2000_decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile, ...@@ -985,6 +1018,7 @@ static int jpeg2000_decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
} /* end band */ } /* end band */
} /* end reslevel */ } /* end reslevel */
/* inverse DWT */
ff_dwt_decode(&comp->dwt, codsty->transform == FF_DWT97 ? (void*)comp->f_data : (void*)comp->i_data); ff_dwt_decode(&comp->dwt, codsty->transform == FF_DWT97 ? (void*)comp->f_data : (void*)comp->i_data);
} /*end comp */ } /*end comp */
...@@ -1128,7 +1162,7 @@ static int jpeg2000_decode_codestream(Jpeg2000DecoderContext *s) ...@@ -1128,7 +1162,7 @@ static int jpeg2000_decode_codestream(Jpeg2000DecoderContext *s)
ret = get_qcd(s, len, qntsty, properties); ret = get_qcd(s, len, qntsty, properties);
break; break;
case JPEG2000_SOT: case JPEG2000_SOT:
if (!(ret = get_sot(s))) { if (!(ret = get_sot(s, len))) {
codsty = s->tile[s->curtileno].codsty; codsty = s->tile[s->curtileno].codsty;
qntsty = s->tile[s->curtileno].qntsty; qntsty = s->tile[s->curtileno].qntsty;
properties = s->tile[s->curtileno].properties; properties = s->tile[s->curtileno].properties;
...@@ -1158,6 +1192,20 @@ static int jpeg2000_decode_codestream(Jpeg2000DecoderContext *s) ...@@ -1158,6 +1192,20 @@ static int jpeg2000_decode_codestream(Jpeg2000DecoderContext *s)
return 0; return 0;
} }
/* Read bit stream packets --> T2 operation. */
static int jpeg2000_read_bitstream_packets(Jpeg2000DecoderContext *s)
{
int ret = 0;
Jpeg2000Tile *tile = s->tile + s->curtileno;
if (ret = init_tile(s, s->curtileno))
return ret;
if (ret = jpeg2000_decode_packets(s, tile))
return ret;
return 0;
}
static int jp2_find_codestream(Jpeg2000DecoderContext *s) static int jp2_find_codestream(Jpeg2000DecoderContext *s)
{ {
uint32_t atom_size, atom; uint32_t atom_size, atom;
......
...@@ -975,6 +975,7 @@ static void mct_decode(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile) ...@@ -975,6 +975,7 @@ static void mct_decode(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
csize *= tile->comp[0].coord[i][1] - tile->comp[0].coord[i][0]; csize *= tile->comp[0].coord[i][1] - tile->comp[0].coord[i][0];
switch (tile->codsty[0].transform) { switch (tile->codsty[0].transform) {
case FF_DWT97: case FF_DWT97:
for (i = 0; i < csize; i++) { for (i = 0; i < csize; i++) {
...@@ -1024,12 +1025,13 @@ static int jpeg2000_decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile, ...@@ -1024,12 +1025,13 @@ static int jpeg2000_decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
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;
/* Loop on resolution levels */ /* Loop on resolution levels */
for (reslevelno = 0; reslevelno < codsty->nreslevels2decode; reslevelno++) { for (reslevelno = 0; reslevelno < codsty->nreslevels2decode; reslevelno++) {
Jpeg2000ResLevel *rlevel = comp->reslevel + reslevelno; Jpeg2000ResLevel *rlevel = comp->reslevel + reslevelno;
/* Loop on bands */ /* Loop on bands */
for (bandno = 0; bandno < rlevel->nbands; bandno++) { for (bandno = 0; bandno < rlevel->nbands; bandno++) {
uint16_t nb_precincts, precno; int nb_precincts, precno;
Jpeg2000Band *band = rlevel->band + bandno; Jpeg2000Band *band = rlevel->band + bandno;
int cblkno = 0, bandpos; int cblkno = 0, bandpos;
bandpos = bandno + (reslevelno > 0); bandpos = bandno + (reslevelno > 0);
...@@ -1110,6 +1112,7 @@ static int jpeg2000_decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile, ...@@ -1110,6 +1112,7 @@ static int jpeg2000_decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
linel = (uint16_t *)picture->data[0] + y * (picture->linesize[0] >> 1); linel = (uint16_t *)picture->data[0] + y * (picture->linesize[0] >> 1);
for (; y < tile->comp[compno].coord[1][1] - s->image_offset_y; y += s->cdy[compno]) { for (; y < tile->comp[compno].coord[1][1] - s->image_offset_y; y += s->cdy[compno]) {
uint16_t *dst; uint16_t *dst;
x = tile->comp[compno].coord[0][0] - s->image_offset_x; x = tile->comp[compno].coord[0][0] - s->image_offset_x;
dst = linel + (x * s->ncomponents + compno); dst = linel + (x * s->ncomponents + compno);
for (; x < s->avctx->width; x += s->cdx[compno]) { for (; x < s->avctx->width; x += s->cdx[compno]) {
......
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