#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 {
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
+
+ /* 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;
/* 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;
}
return 0;
}
-/* read the number of coding passes */
+/* Read the number of coding passes. */
static int getnpasses(Jpeg2000DecoderContext *s)
{
int num;
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,
} /* 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 */
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;
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;
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++) {
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);
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]) {