mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
jpeg2000: Refactor SOT marker parsing
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
This commit is contained in:
parent
daeb4e3042
commit
aa16bbaf9b
@ -41,9 +41,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;
|
||||||
|
|
||||||
@ -55,6 +54,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 {
|
||||||
@ -503,25 +503,19 @@ static int get_sot(Jpeg2000DecoderContext *s, int n)
|
|||||||
return AVERROR_PATCHWELCOME;
|
return AVERROR_PATCHWELCOME;
|
||||||
}
|
}
|
||||||
|
|
||||||
tp = s->tile[s->curtileno].tile_part + TPsot;
|
s->tile[Isot].tp_idx = TPsot;
|
||||||
|
tp = s->tile[Isot].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;
|
|
||||||
|
|
||||||
/* Start of bit stream. Pointer to SOD marker
|
if (!TPsot) {
|
||||||
* Check SOD marker is present. */
|
Jpeg2000Tile *tile = s->tile + s->curtileno;
|
||||||
if (JPEG2000_SOD == bytestream2_get_be16(&s->g)) {
|
|
||||||
bytestream2_init(&tp->tpg, s->g.buffer, tp->tp_len - n - 4);
|
/* copy defaults */
|
||||||
bytestream2_skip(&s->g, tp->tp_len - n - 4);
|
memcpy(tile->codsty, s->codsty, s->ncomponents * sizeof(Jpeg2000CodingStyle));
|
||||||
} else {
|
memcpy(tile->qntsty, s->qntsty, s->ncomponents * sizeof(Jpeg2000QuantStyle));
|
||||||
av_log(s->avctx, AV_LOG_ERROR, "SOD marker not found \n");
|
|
||||||
return AVERROR_INVALIDDATA;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* End address of bit stream =
|
|
||||||
* start address + (Psot - size of SOT HEADER(n)
|
|
||||||
* - size of SOT MARKER(2) - size of SOD marker(2) */
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -577,12 +571,6 @@ static int init_tile(Jpeg2000DecoderContext *s, int tileno)
|
|||||||
if (!tile->comp)
|
if (!tile->comp)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
/* copy codsty, qnsty to tile. TODO: Is it the best way?
|
|
||||||
* codsty, qnsty is an array of 4 structs Jpeg2000CodingStyle
|
|
||||||
* and Jpeg2000QuantStyle */
|
|
||||||
memcpy(tile->codsty, s->codsty, s->ncomponents * sizeof(*tile->codsty));
|
|
||||||
memcpy(tile->qntsty, s->qntsty, s->ncomponents * sizeof(*tile->qntsty));
|
|
||||||
|
|
||||||
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;
|
||||||
@ -1269,7 +1257,11 @@ static int jpeg2000_read_main_headers(Jpeg2000DecoderContext *s)
|
|||||||
ret = get_qcd(s, len, qntsty, properties);
|
ret = get_qcd(s, len, qntsty, properties);
|
||||||
break;
|
break;
|
||||||
case JPEG2000_SOT:
|
case JPEG2000_SOT:
|
||||||
ret = get_sot(s, len);
|
if (!(ret = get_sot(s, len))) {
|
||||||
|
codsty = s->tile[s->curtileno].codsty;
|
||||||
|
qntsty = s->tile[s->curtileno].qntsty;
|
||||||
|
properties = s->tile[s->curtileno].properties;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case JPEG2000_COM:
|
case JPEG2000_COM:
|
||||||
// the comment is ignored
|
// the comment is ignored
|
||||||
@ -1286,7 +1278,7 @@ static int jpeg2000_read_main_headers(Jpeg2000DecoderContext *s)
|
|||||||
bytestream2_skip(&s->g, len - 2);
|
bytestream2_skip(&s->g, len - 2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (((bytestream2_tell(&s->g) - oldpos != len) && (marker != JPEG2000_SOT)) || ret) {
|
if (bytestream2_tell(&s->g) - oldpos != len || ret) {
|
||||||
av_log(s->avctx, AV_LOG_ERROR,
|
av_log(s->avctx, AV_LOG_ERROR,
|
||||||
"error during processing marker segment %.4x\n", marker);
|
"error during processing marker segment %.4x\n", marker);
|
||||||
return ret ? ret : -1;
|
return ret ? ret : -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user