summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libavcodec/j2k.c58
-rw-r--r--libavcodec/j2k.h3
-rw-r--r--libavcodec/j2kdec.c2
-rw-r--r--libavcodec/j2kenc.c9
-rw-r--r--libavcodec/jpeg2000.c8
5 files changed, 64 insertions, 16 deletions
diff --git a/libavcodec/j2k.c b/libavcodec/j2k.c
index 1409f1f24c..171a10150b 100644
--- a/libavcodec/j2k.c
+++ b/libavcodec/j2k.c
@@ -173,10 +173,13 @@ void ff_j2k_set_significant(Jpeg2000T1Context *t1, int x, int y,
t1->flags[y - 1][x - 1] |= JPEG2000_T1_SIG_SE;
}
+static const uint8_t lut_gain[2][4] = { { 0, 0, 0, 0 }, { 0, 1, 1, 2 } };
+
int ff_j2k_init_component(Jpeg2000Component *comp,
Jpeg2000CodingStyle *codsty,
Jpeg2000QuantStyle *qntsty,
- int cbps, int dx, int dy)
+ int cbps, int dx, int dy,
+ AVCodecContext *avctx)
{
uint8_t log2_band_prec_width, log2_band_prec_height;
int reslevelno, bandno, gbandno = 0, ret, i, j, csize = 1;
@@ -245,16 +248,53 @@ int ff_j2k_init_component(Jpeg2000Component *comp,
Jpeg2000Band *band = reslevel->band + bandno;
int cblkno, precno;
int nb_precincts;
+ double stepsize;
- if (qntsty->quantsty != JPEG2000_QSTY_NONE) {
- static const uint8_t lut_gain[2][4] = {{0, 0, 0, 0}, {0, 1, 1, 2}};
+ /* TODO: Implementation of quantization step not finished,
+ * see ISO/IEC 15444-1:2002 E.1 and A.6.4. */
+ switch (qntsty->quantsty) {
+ uint8_t gain;
int numbps;
-
- numbps = cbps + lut_gain[codsty->transform][bandno + reslevelno>0];
- band->stepsize = SHL(2048 + qntsty->mant[gbandno], 2 + numbps - qntsty->expn[gbandno]);
- } else
- band->stepsize = 1 << 13;
-
+ case JPEG2000_QSTY_NONE:
+ /* TODO: to verify. No quantization in this case */
+ stepsize = 1;
+ break;
+ case JPEG2000_QSTY_SI:
+ /*TODO: Compute formula to implement. */
+ numbps = cbps +
+ lut_gain[codsty->transform][bandno + reslevelno > 0];
+ stepsize = SHL(2048 + qntsty->mant[gbandno],
+ 2 + numbps - qntsty->expn[gbandno]);
+ break;
+ case JPEG2000_QSTY_SE:
+ /* Exponent quantization step.
+ * Formula:
+ * delta_b = 2 ^ (R_b - expn_b) * (1 + (mant_b / 2 ^ 11))
+ * R_b = R_I + log2 (gain_b )
+ * see ISO/IEC 15444-1:2002 E.1.1 eqn. E-3 and E-4 */
+ /* TODO/WARN: value of log2 (gain_b ) not taken into account
+ * but it works (compared to OpenJPEG). Why?
+ * Further investigation needed. */
+ gain = cbps;
+ stepsize = pow(2.0, gain - qntsty->expn[gbandno]);
+ stepsize *= (qntsty->mant[gbandno] / 2048.0 + 1.0);
+ /* FIXME: In openjepg code stespize = stepsize * 0.5. Why?
+ * If not set output of entropic decoder is not correct. */
+// stepsize *= 0.5;
+ break;
+ default:
+ stepsize = 0;
+ av_log(avctx, AV_LOG_ERROR, "Unknown quantization format\n");
+ break;
+ }
+ /* BITEXACT computing case --> convert to int */
+// if (avctx->flags & CODEC_FLAG_BITEXACT)
+ band->stepsize = stepsize * (1 << 13);
+
+ /* computation of tbx_0, tbx_1, tby_0, tby_1
+ * see ISO/IEC 15444-1:2002 B.5 eq. B-15 and tbl B.1
+ * codeblock width and height is computed for
+ * DCI JPEG 2000 codeblock_width = codeblock_width = 32 = 2 ^ 5 */
if (reslevelno == 0) {
/* for reslevelno = 0, only one band, x0_b = y0_b = 0 */
for (i = 0; i < 2; i++)
diff --git a/libavcodec/j2k.h b/libavcodec/j2k.h
index a981208798..788f2fcf34 100644
--- a/libavcodec/j2k.h
+++ b/libavcodec/j2k.h
@@ -252,7 +252,8 @@ static inline int ff_jpeg2000_getsgnctxno(int flag, int *xorbit)
int ff_j2k_init_component(Jpeg2000Component *comp,
Jpeg2000CodingStyle *codsty,
Jpeg2000QuantStyle *qntsty,
- int cbps, int dx, int dy);
+ int cbps, int dx, int dy,
+ AVCodecContext *avctx);
void ff_j2k_reinit(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty);
void ff_j2k_cleanup(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty);
diff --git a/libavcodec/j2kdec.c b/libavcodec/j2kdec.c
index 1881ba062c..b349c97111 100644
--- a/libavcodec/j2kdec.c
+++ b/libavcodec/j2kdec.c
@@ -439,7 +439,7 @@ static int init_tile(Jpeg2000DecoderContext *s, int tileno)
comp->coord[1][0] = FFMAX(tiley * s->tile_height + s->tile_offset_y, s->image_offset_y);
comp->coord[1][1] = FFMIN((tiley+1)*s->tile_height + s->tile_offset_y, s->height);
- if (ret = ff_j2k_init_component(comp, codsty, qntsty, s->cbps[compno], s->cdx[compno], s->cdy[compno]))
+ if (ret = ff_j2k_init_component(comp, codsty, qntsty, s->cbps[compno], s->cdx[compno], s->cdy[compno], s->avctx))
return ret;
}
return 0;
diff --git a/libavcodec/j2kenc.c b/libavcodec/j2kenc.c
index d673daf1c9..aea12f3218 100644
--- a/libavcodec/j2kenc.c
+++ b/libavcodec/j2kenc.c
@@ -366,7 +366,14 @@ static int init_tiles(Jpeg2000EncoderContext *s)
for (j = 0; j < 2; j++)
comp->coord[i][j] = ff_jpeg2000_ceildivpow2(comp->coord[i][j], s->chroma_shift[i]);
- if (ret = ff_j2k_init_component(comp, codsty, qntsty, s->cbps[compno], compno?1<<s->chroma_shift[0]:1, compno?1<<s->chroma_shift[1]:1))
+ if (ret = ff_j2k_init_component(comp,
+ codsty,
+ qntsty,
+ s->cbps[compno],
+ compno?1<<s->chroma_shift[0]:1,
+ compno?1<<s->chroma_shift[1]:1,
+ s->avctx
+ ))
return ret;
}
}
diff --git a/libavcodec/jpeg2000.c b/libavcodec/jpeg2000.c
index 988adeba5f..5b15efcc29 100644
--- a/libavcodec/jpeg2000.c
+++ b/libavcodec/jpeg2000.c
@@ -267,15 +267,15 @@ int ff_jpeg2000_init_component(Jpeg2000Component *comp,
int numbps;
case JPEG2000_QSTY_NONE:
/* TODO: to verify. No quantization in this case */
+ band->stepsize = (float) (1 << 13);
+ break;
+ case JPEG2000_QSTY_SI:
+ /*TODO: Compute formula to implement. */
numbps = cbps +
lut_gain[codsty->transform][bandno + reslevelno > 0];
band->stepsize = (float)SHL(2048 + qntsty->mant[gbandno],
2 + numbps - qntsty->expn[gbandno]);
break;
- case JPEG2000_QSTY_SI:
- /*TODO: Compute formula to implement. */
- band->stepsize = (float) (1 << 13);
- break;
case JPEG2000_QSTY_SE:
/* Exponent quantization step.
* Formula: