j2k/jpeg2000: merge some of the tilepart related code
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
parent
a5203d86b3
commit
cdb86136f7
@ -42,11 +42,21 @@
|
||||
#define HAD_COC 0x01
|
||||
#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 {
|
||||
Jpeg2000Component *comp;
|
||||
uint8_t properties[4];
|
||||
Jpeg2000CodingStyle codsty[4];
|
||||
Jpeg2000QuantStyle qntsty[4];
|
||||
Jpeg2000TilePart tile_part[3];
|
||||
} Jpeg2000Tile;
|
||||
|
||||
typedef struct Jpeg2000DecoderContext {
|
||||
@ -427,28 +437,45 @@ static int get_qcc(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q,
|
||||
return get_qcx(s, n - 1, q + compno);
|
||||
}
|
||||
|
||||
/* get start of tile segment */
|
||||
static int get_sot(Jpeg2000DecoderContext *s)
|
||||
/* Get start of tile segment. */
|
||||
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)
|
||||
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) {
|
||||
s->curtileno=0;
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
Psot = bytestream2_get_be32u(&s->g); // Psot
|
||||
TPsot = bytestream2_get_byteu(&s->g); // TPsot
|
||||
|
||||
bytestream2_skipu(&s->g, 4); ///< Psot (ignored)
|
||||
/* Read TNSot but not used */
|
||||
bytestream2_get_byteu(&s->g); // TNsot
|
||||
|
||||
if (!bytestream2_get_byteu(&s->g)) { ///< TPsot
|
||||
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;
|
||||
}
|
||||
|
||||
tp = s->tile[s->curtileno].tile_part + TPsot;
|
||||
tp->tile_index = Isot;
|
||||
tp->tp_len = Psot;
|
||||
tp->tp_idx = TPsot;
|
||||
|
||||
if (!TPsot) {
|
||||
Jpeg2000Tile *tile = s->tile + s->curtileno;
|
||||
|
||||
/* copy defaults */
|
||||
memcpy(tile->codsty, s->codsty, s->ncomponents * sizeof(Jpeg2000CodingStyle));
|
||||
memcpy(tile->qntsty, s->qntsty, s->ncomponents * sizeof(Jpeg2000QuantStyle));
|
||||
}
|
||||
bytestream2_get_byteu(&s->g); ///< TNsot
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -526,7 +553,7 @@ static int init_tile(Jpeg2000DecoderContext *s, int tileno)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* read the number of coding passes */
|
||||
/* Read the number of coding passes. */
|
||||
static int getnpasses(Jpeg2000DecoderContext *s)
|
||||
{
|
||||
int num;
|
||||
@ -835,6 +862,12 @@ static int decode_cblk(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *codsty,
|
||||
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.*/
|
||||
static void dequantization_float(int x, int y, Jpeg2000Cblk *cblk,
|
||||
Jpeg2000Component *comp,
|
||||
@ -985,6 +1018,7 @@ static int jpeg2000_decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
|
||||
} /* end band */
|
||||
} /* end reslevel */
|
||||
|
||||
/* inverse DWT */
|
||||
ff_dwt_decode(&comp->dwt, codsty->transform == FF_DWT97 ? (void*)comp->f_data : (void*)comp->i_data);
|
||||
} /*end comp */
|
||||
|
||||
@ -1128,7 +1162,7 @@ static int jpeg2000_decode_codestream(Jpeg2000DecoderContext *s)
|
||||
ret = get_qcd(s, len, qntsty, properties);
|
||||
break;
|
||||
case JPEG2000_SOT:
|
||||
if (!(ret = get_sot(s))) {
|
||||
if (!(ret = get_sot(s, len))) {
|
||||
codsty = s->tile[s->curtileno].codsty;
|
||||
qntsty = s->tile[s->curtileno].qntsty;
|
||||
properties = s->tile[s->curtileno].properties;
|
||||
@ -1158,6 +1192,20 @@ static int jpeg2000_decode_codestream(Jpeg2000DecoderContext *s)
|
||||
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)
|
||||
{
|
||||
uint32_t atom_size, atom;
|
||||
|
@ -975,6 +975,7 @@ static void mct_decode(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
csize *= tile->comp[0].coord[i][1] - tile->comp[0].coord[i][0];
|
||||
|
||||
switch (tile->codsty[0].transform) {
|
||||
case FF_DWT97:
|
||||
for (i = 0; i < csize; i++) {
|
||||
@ -1024,12 +1025,13 @@ static int jpeg2000_decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
|
||||
for (compno = 0; compno < s->ncomponents; compno++) {
|
||||
Jpeg2000Component *comp = tile->comp + compno;
|
||||
Jpeg2000CodingStyle *codsty = tile->codsty + compno;
|
||||
|
||||
/* Loop on resolution levels */
|
||||
for (reslevelno = 0; reslevelno < codsty->nreslevels2decode; reslevelno++) {
|
||||
Jpeg2000ResLevel *rlevel = comp->reslevel + reslevelno;
|
||||
/* Loop on bands */
|
||||
for (bandno = 0; bandno < rlevel->nbands; bandno++) {
|
||||
uint16_t nb_precincts, precno;
|
||||
int nb_precincts, precno;
|
||||
Jpeg2000Band *band = rlevel->band + bandno;
|
||||
int cblkno = 0, bandpos;
|
||||
bandpos = bandno + (reslevelno > 0);
|
||||
@ -1110,6 +1112,7 @@ static int jpeg2000_decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
|
||||
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]) {
|
||||
uint16_t *dst;
|
||||
|
||||
x = tile->comp[compno].coord[0][0] - s->image_offset_x;
|
||||
dst = linel + (x * s->ncomponents + compno);
|
||||
for (; x < s->avctx->width; x += s->cdx[compno]) {
|
||||
|
Loading…
Reference in New Issue
Block a user