mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
j2k/jpeg2000dec: merge
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
parent
fd7e119037
commit
9d56ccf5af
@ -243,8 +243,7 @@ OBJS-$(CONFIG_INDEO5_DECODER) += indeo5.o ivi_common.o ivi_dsp.o
|
|||||||
OBJS-$(CONFIG_INTERPLAY_DPCM_DECODER) += dpcm.o
|
OBJS-$(CONFIG_INTERPLAY_DPCM_DECODER) += dpcm.o
|
||||||
OBJS-$(CONFIG_INTERPLAY_VIDEO_DECODER) += interplayvideo.o
|
OBJS-$(CONFIG_INTERPLAY_VIDEO_DECODER) += interplayvideo.o
|
||||||
OBJS-$(CONFIG_JACOSUB_DECODER) += jacosubdec.o ass.o
|
OBJS-$(CONFIG_JACOSUB_DECODER) += jacosubdec.o ass.o
|
||||||
OBJS-$(CONFIG_J2K_DECODER) += j2kdec.o mqcdec.o mqc.o jpeg2000.o
|
OBJS-$(CONFIG_JPEG2000_ENCODER) += j2kenc.o mqcenc.o mqc.o jpeg2000.o
|
||||||
OBJS-$(CONFIG_J2K_ENCODER) += j2kenc.o mqcenc.o mqc.o jpeg2000.o
|
|
||||||
OBJS-$(CONFIG_JPEG2000_DECODER) += jpeg2000dec.o jpeg2000.o \
|
OBJS-$(CONFIG_JPEG2000_DECODER) += jpeg2000dec.o jpeg2000.o \
|
||||||
jpeg2000dwt.o mqcdec.o mqc.o
|
jpeg2000dwt.o mqcdec.o mqc.o
|
||||||
OBJS-$(CONFIG_JPEGLS_DECODER) += jpeglsdec.o jpegls.o \
|
OBJS-$(CONFIG_JPEGLS_DECODER) += jpeglsdec.o jpegls.o \
|
||||||
|
@ -172,8 +172,7 @@ void avcodec_register_all(void)
|
|||||||
REGISTER_DECODER(INDEO4, indeo4);
|
REGISTER_DECODER(INDEO4, indeo4);
|
||||||
REGISTER_DECODER(INDEO5, indeo5);
|
REGISTER_DECODER(INDEO5, indeo5);
|
||||||
REGISTER_DECODER(INTERPLAY_VIDEO, interplay_video);
|
REGISTER_DECODER(INTERPLAY_VIDEO, interplay_video);
|
||||||
REGISTER_ENCDEC (J2K, j2k);
|
REGISTER_ENCDEC (JPEG2000, jpeg2000);
|
||||||
REGISTER_DECODER(JPEG2000, jpeg2000);
|
|
||||||
REGISTER_ENCDEC (JPEGLS, jpegls);
|
REGISTER_ENCDEC (JPEGLS, jpegls);
|
||||||
REGISTER_DECODER(JV, jv);
|
REGISTER_DECODER(JV, jv);
|
||||||
REGISTER_DECODER(KGV1, kgv1);
|
REGISTER_DECODER(KGV1, kgv1);
|
||||||
|
1396
libavcodec/j2kdec.c
1396
libavcodec/j2kdec.c
File diff suppressed because it is too large
Load Diff
@ -1036,8 +1036,8 @@ static int j2kenc_destroy(AVCodecContext *avctx)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
AVCodec ff_j2k_encoder = {
|
AVCodec ff_jpeg2000_encoder = {
|
||||||
.name = "j2k",
|
.name = "jpeg2000",
|
||||||
.type = AVMEDIA_TYPE_VIDEO,
|
.type = AVMEDIA_TYPE_VIDEO,
|
||||||
.id = AV_CODEC_ID_JPEG2000,
|
.id = AV_CODEC_ID_JPEG2000,
|
||||||
.priv_data_size = sizeof(Jpeg2000EncoderContext),
|
.priv_data_size = sizeof(Jpeg2000EncoderContext),
|
||||||
|
@ -492,7 +492,7 @@ void ff_jpeg2000_reinit(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
|
|||||||
void ff_jpeg2000_cleanup(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
|
void ff_jpeg2000_cleanup(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
|
||||||
{
|
{
|
||||||
int reslevelno, bandno, precno;
|
int reslevelno, bandno, precno;
|
||||||
for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++) {
|
for (reslevelno = 0; comp->reslevel && reslevelno < codsty->nreslevels; reslevelno++) {
|
||||||
Jpeg2000ResLevel *reslevel = comp->reslevel + reslevelno;
|
Jpeg2000ResLevel *reslevel = comp->reslevel + reslevelno;
|
||||||
|
|
||||||
for (bandno = 0; bandno < reslevel->nbands; bandno++) {
|
for (bandno = 0; bandno < reslevel->nbands; bandno++) {
|
||||||
|
@ -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 {
|
||||||
@ -122,6 +122,9 @@ static int tag_tree_decode(Jpeg2000DecoderContext *s, Jpeg2000TgtNode *node,
|
|||||||
Jpeg2000TgtNode *stack[30];
|
Jpeg2000TgtNode *stack[30];
|
||||||
int sp = -1, curval = 0;
|
int sp = -1, curval = 0;
|
||||||
|
|
||||||
|
if (!node)
|
||||||
|
return AVERROR(EINVAL);
|
||||||
|
|
||||||
while (node && !node->vis) {
|
while (node && !node->vis) {
|
||||||
stack[++sp] = node;
|
stack[++sp] = node;
|
||||||
node = node->parent;
|
node = node->parent;
|
||||||
@ -188,6 +191,9 @@ static int get_siz(Jpeg2000DecoderContext *s)
|
|||||||
s->sgnd[i] = !!(x & 0x80);
|
s->sgnd[i] = !!(x & 0x80);
|
||||||
s->cdx[i] = bytestream2_get_byteu(&s->g);
|
s->cdx[i] = bytestream2_get_byteu(&s->g);
|
||||||
s->cdy[i] = bytestream2_get_byteu(&s->g);
|
s->cdy[i] = bytestream2_get_byteu(&s->g);
|
||||||
|
if (s->cdx[i] != 1 || s->cdy[i] != 1) {
|
||||||
|
av_log(s->avctx, AV_LOG_ERROR, "unsupported/ CDxy values\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s->numXtiles = ff_jpeg2000_ceildiv(s->width - s->tile_offset_x, s->tile_width);
|
s->numXtiles = ff_jpeg2000_ceildiv(s->width - s->tile_offset_x, s->tile_width);
|
||||||
@ -277,8 +283,7 @@ static int get_cox(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c)
|
|||||||
|
|
||||||
c->cblk_style = bytestream2_get_byteu(&s->g);
|
c->cblk_style = bytestream2_get_byteu(&s->g);
|
||||||
if (c->cblk_style != 0) { // cblk style
|
if (c->cblk_style != 0) { // cblk style
|
||||||
av_log(s->avctx, AV_LOG_ERROR, "no extra cblk styles supported\n");
|
av_log(s->avctx, AV_LOG_WARNING, "extra cblk styles %X\n", c->cblk_style);
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
c->transform = bytestream2_get_byteu(&s->g); // DWT transformation type
|
c->transform = bytestream2_get_byteu(&s->g); // DWT transformation type
|
||||||
/* set integer 9/7 DWT in case of BITEXACT flag */
|
/* set integer 9/7 DWT in case of BITEXACT flag */
|
||||||
@ -433,11 +438,6 @@ static int get_sot(Jpeg2000DecoderContext *s, int n)
|
|||||||
s->curtileno=0;
|
s->curtileno=0;
|
||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
}
|
}
|
||||||
if (Isot) {
|
|
||||||
av_log(s->avctx, AV_LOG_ERROR,
|
|
||||||
"Not a DCINEMA JP2K file: more than one tile\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
Psot = bytestream2_get_be32u(&s->g); // Psot
|
Psot = bytestream2_get_be32u(&s->g); // Psot
|
||||||
TPsot = bytestream2_get_byteu(&s->g); // TPsot
|
TPsot = bytestream2_get_byteu(&s->g); // TPsot
|
||||||
|
|
||||||
@ -449,25 +449,19 @@ 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;
|
|
||||||
|
|
||||||
/* 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 -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -523,12 +517,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;
|
||||||
@ -674,6 +662,7 @@ static int jpeg2000_decode_packets(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile
|
|||||||
s->bit_index = 8;
|
s->bit_index = 8;
|
||||||
switch (tile->codsty[0].prog_order) {
|
switch (tile->codsty[0].prog_order) {
|
||||||
case JPEG2000_PGOD_LRCP:
|
case JPEG2000_PGOD_LRCP:
|
||||||
|
case JPEG2000_PGOD_RLCP:
|
||||||
for (layno = 0; layno < tile->codsty[0].nlayers; layno++) {
|
for (layno = 0; layno < tile->codsty[0].nlayers; layno++) {
|
||||||
ok_reslevel = 1;
|
ok_reslevel = 1;
|
||||||
for (reslevelno = 0; ok_reslevel; reslevelno++) {
|
for (reslevelno = 0; ok_reslevel; reslevelno++) {
|
||||||
@ -758,32 +747,33 @@ static int jpeg2000_decode_packets(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile
|
|||||||
|
|
||||||
/* TIER-1 routines */
|
/* TIER-1 routines */
|
||||||
static void decode_sigpass(Jpeg2000T1Context *t1, int width, int height,
|
static void decode_sigpass(Jpeg2000T1Context *t1, int width, int height,
|
||||||
int bpno, int bandno)
|
int bpno, int bandno, int bpass_csty_symbol,
|
||||||
|
int vert_causal_ctx_csty_symbol)
|
||||||
{
|
{
|
||||||
int mask = 3 << (bpno - 1), y0, x, y;
|
int mask = 3 << (bpno - 1), y0, x, y;
|
||||||
|
|
||||||
for (y0 = 0; y0 < height; y0 += 4)
|
for (y0 = 0; y0 < height; y0 += 4)
|
||||||
for (x = 0; x < width; x++)
|
for (x = 0; x < width; x++)
|
||||||
for (y = y0; y < height && y < y0 + 4; y++)
|
for (y = y0; y < height && y < y0 + 4; y++) {
|
||||||
if ((t1->flags[y + 1][x + 1] & JPEG2000_T1_SIG_NB)
|
if ((t1->flags[y+1][x+1] & JPEG2000_T1_SIG_NB)
|
||||||
&& !(t1->flags[y + 1][x + 1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS))) {
|
&& !(t1->flags[y+1][x+1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS))) {
|
||||||
if (ff_mqc_decode(&t1->mqc,
|
int flags_mask = -1;
|
||||||
t1->mqc.cx_states +
|
if (vert_causal_ctx_csty_symbol && y == y0 + 3)
|
||||||
ff_jpeg2000_getsigctxno(t1->flags[y + 1][x + 1],
|
flags_mask &= ~(JPEG2000_T1_SIG_S | JPEG2000_T1_SIG_SW | JPEG2000_T1_SIG_SE);
|
||||||
bandno))) {
|
if (ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ff_jpeg2000_getsigctxno(t1->flags[y+1][x+1] & flags_mask, bandno))) {
|
||||||
int xorbit, ctxno = ff_jpeg2000_getsgnctxno(t1->flags[y + 1][x + 1],
|
int xorbit, ctxno = ff_jpeg2000_getsgnctxno(t1->flags[y+1][x+1], &xorbit);
|
||||||
&xorbit);
|
if (bpass_csty_symbol)
|
||||||
|
t1->data[y][x] = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ctxno) ? -mask : mask;
|
||||||
t1->data[y][x] =
|
else
|
||||||
(ff_mqc_decode(&t1->mqc,
|
t1->data[y][x] = (ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ctxno) ^ xorbit) ?
|
||||||
t1->mqc.cx_states + ctxno) ^ xorbit)
|
-mask : mask;
|
||||||
? -mask : mask;
|
|
||||||
|
|
||||||
ff_jpeg2000_set_significance(t1, x, y,
|
ff_jpeg2000_set_significance(t1, x, y,
|
||||||
t1->data[y][x] < 0);
|
t1->data[y][x] < 0);
|
||||||
}
|
}
|
||||||
t1->flags[y + 1][x + 1] |= JPEG2000_T1_VIS;
|
t1->flags[y + 1][x + 1] |= JPEG2000_T1_VIS;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void decode_refpass(Jpeg2000T1Context *t1, int width, int height,
|
static void decode_refpass(Jpeg2000T1Context *t1, int width, int height,
|
||||||
@ -810,11 +800,11 @@ static void decode_refpass(Jpeg2000T1Context *t1, int width, int height,
|
|||||||
|
|
||||||
static void decode_clnpass(Jpeg2000DecoderContext *s, Jpeg2000T1Context *t1,
|
static void decode_clnpass(Jpeg2000DecoderContext *s, Jpeg2000T1Context *t1,
|
||||||
int width, int height, int bpno, int bandno,
|
int width, int height, int bpno, int bandno,
|
||||||
int seg_symbols)
|
int seg_symbols, int vert_causal_ctx_csty_symbol)
|
||||||
{
|
{
|
||||||
int mask = 3 << (bpno - 1), y0, x, y, runlen, dec;
|
int mask = 3 << (bpno - 1), y0, x, y, runlen, dec;
|
||||||
|
|
||||||
for (y0 = 0; y0 < height; y0 += 4)
|
for (y0 = 0; y0 < height; y0 += 4) {
|
||||||
for (x = 0; x < width; x++) {
|
for (x = 0; x < width; x++) {
|
||||||
if (y0 + 3 < height &&
|
if (y0 + 3 < height &&
|
||||||
!((t1->flags[y0 + 1][x + 1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||
|
!((t1->flags[y0 + 1][x + 1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||
|
||||||
@ -836,12 +826,14 @@ static void decode_clnpass(Jpeg2000DecoderContext *s, Jpeg2000T1Context *t1,
|
|||||||
|
|
||||||
for (y = y0 + runlen; y < y0 + 4 && y < height; y++) {
|
for (y = y0 + runlen; y < y0 + 4 && y < height; y++) {
|
||||||
if (!dec) {
|
if (!dec) {
|
||||||
if (!(t1->flags[y + 1][x + 1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS)))
|
if (!(t1->flags[y+1][x+1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS))) {
|
||||||
dec = ff_mqc_decode(&t1->mqc,
|
int flags_mask = -1;
|
||||||
t1->mqc.cx_states +
|
if (vert_causal_ctx_csty_symbol && y == y0 + 3)
|
||||||
ff_jpeg2000_getsigctxno(t1->flags[y + 1][x + 1],
|
flags_mask &= ~(JPEG2000_T1_SIG_S | JPEG2000_T1_SIG_SW | JPEG2000_T1_SIG_SE);
|
||||||
|
dec = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ff_jpeg2000_getsigctxno(t1->flags[y+1][x+1] & flags_mask,
|
||||||
bandno));
|
bandno));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (dec) {
|
if (dec) {
|
||||||
int xorbit;
|
int xorbit;
|
||||||
int ctxno = ff_jpeg2000_getsgnctxno(t1->flags[y + 1][x + 1],
|
int ctxno = ff_jpeg2000_getsgnctxno(t1->flags[y + 1][x + 1],
|
||||||
@ -856,6 +848,7 @@ static void decode_clnpass(Jpeg2000DecoderContext *s, Jpeg2000T1Context *t1,
|
|||||||
t1->flags[y + 1][x + 1] &= ~JPEG2000_T1_VIS;
|
t1->flags[y + 1][x + 1] &= ~JPEG2000_T1_VIS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (seg_symbols) {
|
if (seg_symbols) {
|
||||||
int val;
|
int val;
|
||||||
val = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI);
|
val = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI);
|
||||||
@ -872,7 +865,9 @@ static int decode_cblk(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *codsty,
|
|||||||
Jpeg2000T1Context *t1, Jpeg2000Cblk *cblk,
|
Jpeg2000T1Context *t1, Jpeg2000Cblk *cblk,
|
||||||
int width, int height, int bandpos)
|
int width, int height, int bandpos)
|
||||||
{
|
{
|
||||||
int passno = cblk->npasses, pass_t = 2, bpno = cblk->nonzerobits - 1, y;
|
int passno = cblk->npasses, pass_t = 2, bpno = cblk->nonzerobits - 1, y, clnpass_cnt = 0;
|
||||||
|
int bpass_csty_symbol = JPEG2000_CBLK_BYPASS & codsty->cblk_style;
|
||||||
|
int vert_causal_ctx_csty_symbol = JPEG2000_CBLK_VSC & codsty->cblk_style;
|
||||||
|
|
||||||
for (y = 0; y < height; y++)
|
for (y = 0; y < height; y++)
|
||||||
memset(t1->data[y], 0, width * sizeof(**t1->data));
|
memset(t1->data[y], 0, width * sizeof(**t1->data));
|
||||||
@ -880,24 +875,31 @@ static int decode_cblk(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *codsty,
|
|||||||
/* If code-block contains no compressed data: nothing to do. */
|
/* If code-block contains no compressed data: nothing to do. */
|
||||||
if (!cblk->length)
|
if (!cblk->length)
|
||||||
return 0;
|
return 0;
|
||||||
for (y = 0; y < height + 2; y++)
|
|
||||||
memset(t1->flags[y], 0, (width + 2) * sizeof(**t1->flags));
|
for (y = 0; y < height+2; y++)
|
||||||
|
memset(t1->flags[y], 0, (width + 2)*sizeof(**t1->flags));
|
||||||
|
|
||||||
cblk->data[cblk->length] = 0xff;
|
cblk->data[cblk->length] = 0xff;
|
||||||
cblk->data[cblk->length + 1] = 0xff;
|
cblk->data[cblk->length+1] = 0xff;
|
||||||
ff_mqc_initdec(&t1->mqc, cblk->data);
|
ff_mqc_initdec(&t1->mqc, cblk->data);
|
||||||
|
|
||||||
while (passno--) {
|
while (passno--) {
|
||||||
switch (pass_t) {
|
switch(pass_t) {
|
||||||
case 0:
|
case 0:
|
||||||
decode_sigpass(t1, width, height, bpno + 1, bandpos);
|
decode_sigpass(t1, width, height, bpno + 1, bandpos,
|
||||||
|
bpass_csty_symbol && (clnpass_cnt >= 4), vert_causal_ctx_csty_symbol);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
decode_refpass(t1, width, height, bpno + 1);
|
decode_refpass(t1, width, height, bpno + 1);
|
||||||
|
if (bpass_csty_symbol && clnpass_cnt >= 4)
|
||||||
|
ff_mqc_initdec(&t1->mqc, cblk->data);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
decode_clnpass(s, t1, width, height, bpno + 1, bandpos,
|
decode_clnpass(s, t1, width, height, bpno + 1, bandpos,
|
||||||
codsty->cblk_style & JPEG2000_CBLK_SEGSYM);
|
codsty->cblk_style & JPEG2000_CBLK_SEGSYM, vert_causal_ctx_csty_symbol);
|
||||||
|
clnpass_cnt = clnpass_cnt + 1;
|
||||||
|
if (bpass_csty_symbol && clnpass_cnt >= 4)
|
||||||
|
ff_mqc_initdec(&t1->mqc, cblk->data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1033,8 +1035,12 @@ static int jpeg2000_decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
|
|||||||
int 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);
|
||||||
|
|
||||||
|
if (band->coord[0][0] == band->coord[0][1] || band->coord[1][0] == band->coord[1][1])
|
||||||
|
continue;
|
||||||
|
|
||||||
nb_precincts = rlevel->num_precincts_x * rlevel->num_precincts_y;
|
nb_precincts = rlevel->num_precincts_x * rlevel->num_precincts_y;
|
||||||
/* Loop on precincts */
|
/* Loop on precincts */
|
||||||
for (precno = 0; precno < nb_precincts; precno++) {
|
for (precno = 0; precno < nb_precincts; precno++) {
|
||||||
@ -1114,7 +1120,7 @@ static int jpeg2000_decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
|
|||||||
|
|
||||||
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 < tile->comp[compno].coord[0][1] - s->image_offset_x; x += s-> cdx[compno]) {
|
||||||
int val;
|
int val;
|
||||||
/* DC level shift and clip see ISO 15444-1:2002 G.1.2 */
|
/* DC level shift and clip see ISO 15444-1:2002 G.1.2 */
|
||||||
if (tile->codsty->transform == FF_DWT97)
|
if (tile->codsty->transform == FF_DWT97)
|
||||||
@ -1169,6 +1175,15 @@ static int jpeg2000_read_main_headers(Jpeg2000DecoderContext *s)
|
|||||||
marker = bytestream2_get_be16u(&s->g);
|
marker = bytestream2_get_be16u(&s->g);
|
||||||
oldpos = bytestream2_tell(&s->g);
|
oldpos = bytestream2_tell(&s->g);
|
||||||
|
|
||||||
|
if (marker == JPEG2000_SOD) {
|
||||||
|
Jpeg2000Tile *tile = s->tile + s->curtileno;
|
||||||
|
Jpeg2000TilePart *tp = tile->tile_part + tile->tp_idx;
|
||||||
|
|
||||||
|
bytestream2_init(&tp->tpg, s->g.buffer, tp->tp_end - s->g.buffer);
|
||||||
|
bytestream2_skip(&s->g, tp->tp_end - s->g.buffer);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (marker == JPEG2000_EOC)
|
if (marker == JPEG2000_EOC)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1194,7 +1209,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
|
||||||
@ -1211,7 +1230,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;
|
||||||
@ -1224,12 +1243,18 @@ static int jpeg2000_read_main_headers(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;
|
||||||
|
|
||||||
if (ret = init_tile(s, s->curtileno))
|
for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++) {
|
||||||
|
Jpeg2000Tile *tile = s->tile + tileno;
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
@ -1267,13 +1292,15 @@ static int jpeg2000_decode_frame(AVCodecContext *avctx, void *data,
|
|||||||
|
|
||||||
s->avctx = avctx;
|
s->avctx = avctx;
|
||||||
bytestream2_init(&s->g, avpkt->data, avpkt->size);
|
bytestream2_init(&s->g, avpkt->data, avpkt->size);
|
||||||
s->curtileno = 0; // TODO: only one tile in DCI JP2K. to implement for more tiles
|
s->curtileno = -1;
|
||||||
|
|
||||||
// reduction factor, i.e number of resolution levels to skip
|
// reduction factor, i.e number of resolution levels to skip
|
||||||
s->reduction_factor = s->lowres;
|
s->reduction_factor = s->lowres;
|
||||||
|
|
||||||
if (bytestream2_get_bytes_left(&s->g) < 2)
|
if (bytestream2_get_bytes_left(&s->g) < 2) {
|
||||||
return AVERROR(EINVAL);
|
ret = AVERROR(EINVAL);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
// check if the image is in jp2 format
|
// check if the image is in jp2 format
|
||||||
if (bytestream2_get_bytes_left(&s->g) >= 12 &&
|
if (bytestream2_get_bytes_left(&s->g) >= 12 &&
|
||||||
@ -1283,17 +1310,17 @@ static int jpeg2000_decode_frame(AVCodecContext *avctx, void *data,
|
|||||||
if (!jp2_find_codestream(s)) {
|
if (!jp2_find_codestream(s)) {
|
||||||
av_log(avctx, AV_LOG_ERROR,
|
av_log(avctx, AV_LOG_ERROR,
|
||||||
"couldn't find jpeg2k codestream atom\n");
|
"couldn't find jpeg2k codestream atom\n");
|
||||||
return -1;
|
ret = -1;
|
||||||
|
goto end;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bytestream2_seek(&s->g, 0, SEEK_SET);
|
bytestream2_seek(&s->g, 0, SEEK_SET);
|
||||||
if (bytestream2_peek_be16(&s->g) != JPEG2000_SOC /*&& AV_RB32(s->buf + 4) == JP2_CODESTREAM*/)
|
|
||||||
bytestream2_skip(&s->g, 8);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytestream2_get_be16u(&s->g) != JPEG2000_SOC) {
|
if (bytestream2_get_be16u(&s->g) != JPEG2000_SOC) {
|
||||||
av_log(avctx, AV_LOG_ERROR, "SOC marker not present\n");
|
av_log(avctx, AV_LOG_ERROR, "SOC marker not present\n");
|
||||||
return -1;
|
ret = -1;
|
||||||
|
goto end;
|
||||||
}
|
}
|
||||||
if (ret = jpeg2000_read_main_headers(s))
|
if (ret = jpeg2000_read_main_headers(s))
|
||||||
goto end;
|
goto end;
|
||||||
@ -1308,9 +1335,11 @@ static int jpeg2000_decode_frame(AVCodecContext *avctx, void *data,
|
|||||||
|
|
||||||
if (ret = jpeg2000_read_bitstream_packets(s))
|
if (ret = jpeg2000_read_bitstream_packets(s))
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++)
|
for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++)
|
||||||
if (ret = jpeg2000_decode_tile(s, s->tile + tileno, picture))
|
if (ret = jpeg2000_decode_tile(s, s->tile + tileno, picture))
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
jpeg2000_dec_cleanup(s);
|
jpeg2000_dec_cleanup(s);
|
||||||
|
|
||||||
*got_frame = 1;
|
*got_frame = 1;
|
||||||
@ -1361,9 +1390,6 @@ AVCodec ff_jpeg2000_decoder = {
|
|||||||
.init_static_data = jpeg2000_init_static_data,
|
.init_static_data = jpeg2000_init_static_data,
|
||||||
.decode = jpeg2000_decode_frame,
|
.decode = jpeg2000_decode_frame,
|
||||||
.priv_class = &class,
|
.priv_class = &class,
|
||||||
.pix_fmts = (enum AVPixelFormat[]) { AV_PIX_FMT_XYZ12,
|
|
||||||
AV_PIX_FMT_GRAY8,
|
|
||||||
-1 },
|
|
||||||
.max_lowres = 5,
|
.max_lowres = 5,
|
||||||
.profiles = NULL_IF_CONFIG_SMALL(profiles)
|
.profiles = NULL_IF_CONFIG_SMALL(profiles)
|
||||||
};
|
};
|
||||||
|
@ -89,11 +89,11 @@ FATE_VCODEC-$(call ENCDEC, JPEGLS, AVI) += jpegls
|
|||||||
fate-vsynth%-jpegls: ENCOPTS = -sws_flags neighbor+full_chroma_int
|
fate-vsynth%-jpegls: ENCOPTS = -sws_flags neighbor+full_chroma_int
|
||||||
fate-vsynth%-jpegls: DECOPTS = -sws_flags area
|
fate-vsynth%-jpegls: DECOPTS = -sws_flags area
|
||||||
|
|
||||||
FATE_VCODEC-$(call ENCDEC, J2K, AVI) += j2k j2k-97
|
FATE_VCODEC-$(call ENCDEC, JPEG2000, AVI) += jpeg2000 jpeg2000-97
|
||||||
fate-vsynth%-j2k: ENCOPTS = -qscale 7 -strict experimental -pred 1 -pix_fmt rgb24
|
fate-vsynth%-jpeg2000: ENCOPTS = -qscale 7 -strict experimental -pred 1 -pix_fmt rgb24
|
||||||
fate-vsynth%-j2k: DECINOPTS = -vcodec j2k -strict experimental
|
fate-vsynth%-jpeg2000: DECINOPTS = -vcodec jpeg2000
|
||||||
fate-vsynth%-j2k-97: ENCOPTS = -qscale 7 -strict experimental -pix_fmt rgb24
|
fate-vsynth%-jpeg2000-97: ENCOPTS = -qscale 7 -strict experimental -pix_fmt rgb24
|
||||||
fate-vsynth%-j2k-97: DECINOPTS = -vcodec j2k -strict experimental
|
fate-vsynth%-jpeg2000-97: DECINOPTS = -vcodec jpeg2000
|
||||||
|
|
||||||
FATE_VCODEC-$(call ENCDEC, LJPEG MJPEG, AVI) += ljpeg
|
FATE_VCODEC-$(call ENCDEC, LJPEG MJPEG, AVI) += ljpeg
|
||||||
fate-vsynth%-ljpeg: ENCOPTS = -strict -1
|
fate-vsynth%-ljpeg: ENCOPTS = -strict -1
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
e6e3d338eeb394d6fadc7bbb55fa9e6e *tests/data/fate/vsynth1-j2k.avi
|
|
||||||
2306902 tests/data/fate/vsynth1-j2k.avi
|
|
||||||
1774b621bd92a53a24712cb77e9f0b28 *tests/data/fate/vsynth1-j2k.out.rawvideo
|
|
||||||
stddev: 5.37 PSNR: 33.52 MAXDIFF: 63 bytes: 7603200/ 7603200
|
|
@ -1,4 +0,0 @@
|
|||||||
c135eb14e9f219242180270c2a242634 *tests/data/fate/vsynth1-j2k-97.avi
|
|
||||||
2243132 tests/data/fate/vsynth1-j2k-97.avi
|
|
||||||
30a9c13e18fe4acaf28062b5003bb671 *tests/data/fate/vsynth1-j2k-97.out.rawvideo
|
|
||||||
stddev: 6.41 PSNR: 31.99 MAXDIFF: 75 bytes: 7603200/ 7603200
|
|
4
tests/ref/vsynth/vsynth1-jpeg2000
Normal file
4
tests/ref/vsynth/vsynth1-jpeg2000
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
e6e3d338eeb394d6fadc7bbb55fa9e6e *tests/data/fate/vsynth1-jpeg2000.avi
|
||||||
|
2306902 tests/data/fate/vsynth1-jpeg2000.avi
|
||||||
|
1774b621bd92a53a24712cb77e9f0b28 *tests/data/fate/vsynth1-jpeg2000.out.rawvideo
|
||||||
|
stddev: 5.37 PSNR: 33.52 MAXDIFF: 63 bytes: 7603200/ 7603200
|
4
tests/ref/vsynth/vsynth1-jpeg2000-97
Normal file
4
tests/ref/vsynth/vsynth1-jpeg2000-97
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
c135eb14e9f219242180270c2a242634 *tests/data/fate/vsynth1-jpeg2000-97.avi
|
||||||
|
2243132 tests/data/fate/vsynth1-jpeg2000-97.avi
|
||||||
|
30a9c13e18fe4acaf28062b5003bb671 *tests/data/fate/vsynth1-jpeg2000-97.out.rawvideo
|
||||||
|
stddev: 6.41 PSNR: 31.99 MAXDIFF: 75 bytes: 7603200/ 7603200
|
@ -1,4 +0,0 @@
|
|||||||
fc49816ba28731689872f5c87ca91c10 *tests/data/fate/vsynth2-j2k.avi
|
|
||||||
1151144 tests/data/fate/vsynth2-j2k.avi
|
|
||||||
e7d79c9e11d0fe97f03e38be66c34e4f *tests/data/fate/vsynth2-j2k.out.rawvideo
|
|
||||||
stddev: 4.41 PSNR: 35.23 MAXDIFF: 63 bytes: 7603200/ 7603200
|
|
@ -1,4 +0,0 @@
|
|||||||
3ac3e49a89136bddde9e44bac3e5b4ed *tests/data/fate/vsynth2-j2k-97.avi
|
|
||||||
1118952 tests/data/fate/vsynth2-j2k-97.avi
|
|
||||||
9d69ac6d46152ed2d6dd6a90d5793c80 *tests/data/fate/vsynth2-j2k-97.out.rawvideo
|
|
||||||
stddev: 5.32 PSNR: 33.61 MAXDIFF: 60 bytes: 7603200/ 7603200
|
|
4
tests/ref/vsynth/vsynth2-jpeg2000
Normal file
4
tests/ref/vsynth/vsynth2-jpeg2000
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
fc49816ba28731689872f5c87ca91c10 *tests/data/fate/vsynth2-jpeg2000.avi
|
||||||
|
1151144 tests/data/fate/vsynth2-jpeg2000.avi
|
||||||
|
e7d79c9e11d0fe97f03e38be66c34e4f *tests/data/fate/vsynth2-jpeg2000.out.rawvideo
|
||||||
|
stddev: 4.41 PSNR: 35.23 MAXDIFF: 63 bytes: 7603200/ 7603200
|
4
tests/ref/vsynth/vsynth2-jpeg2000-97
Normal file
4
tests/ref/vsynth/vsynth2-jpeg2000-97
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
3ac3e49a89136bddde9e44bac3e5b4ed *tests/data/fate/vsynth2-jpeg2000-97.avi
|
||||||
|
1118952 tests/data/fate/vsynth2-jpeg2000-97.avi
|
||||||
|
9d69ac6d46152ed2d6dd6a90d5793c80 *tests/data/fate/vsynth2-jpeg2000-97.out.rawvideo
|
||||||
|
stddev: 5.32 PSNR: 33.61 MAXDIFF: 60 bytes: 7603200/ 7603200
|
Loading…
Reference in New Issue
Block a user