summaryrefslogtreecommitdiff
path: root/libavcodec/jpeg2000dec.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavcodec/jpeg2000dec.c')
-rw-r--r--libavcodec/jpeg2000dec.c67
1 files changed, 31 insertions, 36 deletions
diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index 3d518e3c4c..1090f37b68 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -439,11 +439,6 @@ static int get_cox(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c)
return AVERROR_INVALIDDATA;
}
- if (c->log2_cblk_width > 7 || c->log2_cblk_height > 7) {
- avpriv_request_sample(s->avctx, "cblk size > 128");
- return AVERROR_PATCHWELCOME;
- }
-
c->cblk_style = bytestream2_get_byteu(&s->g);
if (c->cblk_style != 0) { // cblk style
av_log(s->avctx, AV_LOG_WARNING, "extra cblk styles %X\n", c->cblk_style);
@@ -1233,20 +1228,20 @@ static void decode_sigpass(Jpeg2000T1Context *t1, int width, int height,
int flags_mask = -1;
if (vert_causal_ctx_csty_symbol && y == y0 + 3)
flags_mask &= ~(JPEG2000_T1_SIG_S | JPEG2000_T1_SIG_SW | JPEG2000_T1_SIG_SE | JPEG2000_T1_SGN_S);
- if ((t1->flags[y+1][x+1] & JPEG2000_T1_SIG_NB & flags_mask)
- && !(t1->flags[y+1][x+1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS))) {
- 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] & flags_mask, &xorbit);
+ if ((t1->flags[(y+1) * t1->stride + x+1] & JPEG2000_T1_SIG_NB & flags_mask)
+ && !(t1->flags[(y+1) * t1->stride + x+1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS))) {
+ if (ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ff_jpeg2000_getsigctxno(t1->flags[(y+1) * t1->stride + x+1] & flags_mask, bandno))) {
+ int xorbit, ctxno = ff_jpeg2000_getsgnctxno(t1->flags[(y+1) * t1->stride + x+1] & flags_mask, &xorbit);
if (t1->mqc.raw)
- t1->data[y][x] = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ctxno) ? -mask : mask;
+ t1->data[(y) * t1->stride + x] = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ctxno) ? -mask : mask;
else
- t1->data[y][x] = (ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ctxno) ^ xorbit) ?
+ t1->data[(y) * t1->stride + x] = (ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ctxno) ^ xorbit) ?
-mask : mask;
ff_jpeg2000_set_significance(t1, x, y,
- t1->data[y][x] < 0);
+ t1->data[(y) * t1->stride + x] < 0);
}
- t1->flags[y + 1][x + 1] |= JPEG2000_T1_VIS;
+ t1->flags[(y + 1) * t1->stride + x + 1] |= JPEG2000_T1_VIS;
}
}
}
@@ -1263,15 +1258,15 @@ static void decode_refpass(Jpeg2000T1Context *t1, int width, int height,
for (y0 = 0; y0 < height; y0 += 4)
for (x = 0; x < width; x++)
for (y = y0; y < height && y < y0 + 4; y++)
- if ((t1->flags[y + 1][x + 1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS)) == JPEG2000_T1_SIG) {
+ if ((t1->flags[(y + 1) * t1->stride + x + 1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS)) == JPEG2000_T1_SIG) {
int flags_mask = (vert_causal_ctx_csty_symbol && y == y0 + 3) ?
~(JPEG2000_T1_SIG_S | JPEG2000_T1_SIG_SW | JPEG2000_T1_SIG_SE | JPEG2000_T1_SGN_S) : -1;
- int ctxno = ff_jpeg2000_getrefctxno(t1->flags[y + 1][x + 1] & flags_mask);
+ int ctxno = ff_jpeg2000_getrefctxno(t1->flags[(y + 1) * t1->stride + x + 1] & flags_mask);
int r = ff_mqc_decode(&t1->mqc,
t1->mqc.cx_states + ctxno)
? phalf : nhalf;
- t1->data[y][x] += t1->data[y][x] < 0 ? -r : r;
- t1->flags[y + 1][x + 1] |= JPEG2000_T1_REF;
+ t1->data[(y) * t1->stride + x] += t1->data[(y) * t1->stride + x] < 0 ? -r : r;
+ t1->flags[(y + 1) * t1->stride + x + 1] |= JPEG2000_T1_REF;
}
}
@@ -1287,10 +1282,10 @@ static void decode_clnpass(Jpeg2000DecoderContext *s, Jpeg2000T1Context *t1,
if (vert_causal_ctx_csty_symbol)
flags_mask &= ~(JPEG2000_T1_SIG_S | JPEG2000_T1_SIG_SW | JPEG2000_T1_SIG_SE | JPEG2000_T1_SGN_S);
if (y0 + 3 < height &&
- !((t1->flags[y0 + 1][x + 1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||
- (t1->flags[y0 + 2][x + 1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||
- (t1->flags[y0 + 3][x + 1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||
- (t1->flags[y0 + 4][x + 1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG) & flags_mask))) {
+ !((t1->flags[(y0 + 1) * t1->stride + x + 1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||
+ (t1->flags[(y0 + 2) * t1->stride + x + 1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||
+ (t1->flags[(y0 + 3) * t1->stride + x + 1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||
+ (t1->flags[(y0 + 4) * t1->stride + x + 1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG) & flags_mask))) {
if (!ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_RL))
continue;
runlen = ff_mqc_decode(&t1->mqc,
@@ -1309,23 +1304,23 @@ static void decode_clnpass(Jpeg2000DecoderContext *s, Jpeg2000T1Context *t1,
if (vert_causal_ctx_csty_symbol && y == y0 + 3)
flags_mask &= ~(JPEG2000_T1_SIG_S | JPEG2000_T1_SIG_SW | JPEG2000_T1_SIG_SE | JPEG2000_T1_SGN_S);
if (!dec) {
- if (!(t1->flags[y+1][x+1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS))) {
- dec = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ff_jpeg2000_getsigctxno(t1->flags[y+1][x+1] & flags_mask,
+ if (!(t1->flags[(y+1) * t1->stride + x+1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS))) {
+ dec = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ff_jpeg2000_getsigctxno(t1->flags[(y+1) * t1->stride + x+1] & flags_mask,
bandno));
}
}
if (dec) {
int xorbit;
- int ctxno = ff_jpeg2000_getsgnctxno(t1->flags[y + 1][x + 1] & flags_mask,
+ int ctxno = ff_jpeg2000_getsgnctxno(t1->flags[(y + 1) * t1->stride + x + 1] & flags_mask,
&xorbit);
- t1->data[y][x] = (ff_mqc_decode(&t1->mqc,
+ t1->data[(y) * t1->stride + x] = (ff_mqc_decode(&t1->mqc,
t1->mqc.cx_states + ctxno) ^
xorbit)
? -mask : mask;
- ff_jpeg2000_set_significance(t1, x, y, t1->data[y][x] < 0);
+ ff_jpeg2000_set_significance(t1, x, y, t1->data[(y) * t1->stride + x] < 0);
}
dec = 0;
- t1->flags[y + 1][x + 1] &= ~JPEG2000_T1_VIS;
+ t1->flags[(y + 1) * t1->stride + x + 1] &= ~JPEG2000_T1_VIS;
}
}
}
@@ -1351,18 +1346,16 @@ static int decode_cblk(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *codsty,
int term_cnt = 0;
int coder_type;
- av_assert0(width <= JPEG2000_MAX_CBLKW);
- av_assert0(height <= JPEG2000_MAX_CBLKH);
+ av_assert0(width <= 1024U && height <= 1024U);
+ av_assert0(width*height <= 4096);
- for (y = 0; y < height; y++)
- memset(t1->data[y], 0, width * sizeof(**t1->data));
+ memset(t1->data, 0, t1->stride * height * sizeof(*t1->data));
/* If code-block contains no compressed data: nothing to do. */
if (!cblk->length)
return 0;
- for (y = 0; y < height + 2; y++)
- memset(t1->flags[y], 0, (width + 2) * sizeof(**t1->flags));
+ memset(t1->flags, 0, t1->stride * (height + 2) * sizeof(*t1->flags));
cblk->data[cblk->length] = 0xff;
cblk->data[cblk->length+1] = 0xff;
@@ -1426,7 +1419,7 @@ static void dequantization_float(int x, int y, Jpeg2000Cblk *cblk,
int w = cblk->coord[0][1] - cblk->coord[0][0];
for (j = 0; j < (cblk->coord[1][1] - cblk->coord[1][0]); ++j) {
float *datap = &comp->f_data[(comp->coord[0][1] - comp->coord[0][0]) * (y + j) + x];
- int *src = t1->data[j];
+ int *src = t1->data + j*t1->stride;
for (i = 0; i < w; ++i)
datap[i] = src[i] * band->f_stepsize;
}
@@ -1441,7 +1434,7 @@ static void dequantization_int(int x, int y, Jpeg2000Cblk *cblk,
int w = cblk->coord[0][1] - cblk->coord[0][0];
for (j = 0; j < (cblk->coord[1][1] - cblk->coord[1][0]); ++j) {
int32_t *datap = &comp->i_data[(comp->coord[0][1] - comp->coord[0][0]) * (y + j) + x];
- int *src = t1->data[j];
+ int *src = t1->data + j*t1->stride;
if (band->i_stepsize == 16384) {
for (i = 0; i < w; ++i)
datap[i] = src[i] / 2;
@@ -1461,7 +1454,7 @@ static void dequantization_int_97(int x, int y, Jpeg2000Cblk *cblk,
int w = cblk->coord[0][1] - cblk->coord[0][0];
for (j = 0; j < (cblk->coord[1][1] - cblk->coord[1][0]); ++j) {
int32_t *datap = &comp->i_data[(comp->coord[0][1] - comp->coord[0][0]) * (y + j) + x];
- int *src = t1->data[j];
+ int *src = t1->data + j*t1->stride;
for (i = 0; i < w; ++i)
datap[i] = (src[i] * (int64_t)band->i_stepsize + (1<<14)) >> 15;
}
@@ -1512,6 +1505,8 @@ static int jpeg2000_decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
Jpeg2000Component *comp = tile->comp + compno;
Jpeg2000CodingStyle *codsty = tile->codsty + compno;
+ t1.stride = (1<<codsty->log2_cblk_width) + 2;
+
/* Loop on resolution levels */
for (reslevelno = 0; reslevelno < codsty->nreslevels2decode; reslevelno++) {
Jpeg2000ResLevel *rlevel = comp->reslevel + reslevelno;