On Tue, Apr 16, 2013 at 05:03:51PM +0200, Nicolas Bertrand wrote:
> ---
> libavcodec/jpeg2000.c | 9 +-
> libavcodec/jpeg2000dec.c | 122 +++++++++++++++++------
> libavcodec/jpeg2000dwt.c | 156
> ++++++++++++++++++++++++------
> libavcodec/jpeg2000dwt.h | 3 +-
> tests/fate/video.mak | 3 +
> tests/ref/fate/jpeg2000-dcinema-bitexact | 3 +
> 6 files changed, 234 insertions(+), 62 deletions(-)
> create mode 100644 tests/ref/fate/jpeg2000-dcinema-bitexact
>
> diff --git a/libavcodec/jpeg2000.c b/libavcodec/jpeg2000.c
> index 78c7a38..e96ee10 100644
> --- a/libavcodec/jpeg2000.c
> +++ b/libavcodec/jpeg2000.c
> @@ -200,7 +200,7 @@ int ff_jpeg2000_init_component(Jpeg2000Component *comp,
> Jpeg2000CodingStyle *codsty,
> Jpeg2000QuantStyle *qntsty,
> int cbps, int dx, int dy,
> - AVCodecContext *ctx)
> + AVCodecContext *avctx)
> {
> uint8_t log2_band_prec_width, log2_band_prec_height;
> int reslevelno, bandno, gbandno = 0, ret, i, j;
> @@ -275,7 +275,7 @@ int ff_jpeg2000_init_component(Jpeg2000Component *comp,
> int nb_precincts;
>
> /* TODO: Implementation of quantization step not finished,
> - * see ISO/IEC 15444-1:2002 §E.1 and §A.6.4. */
> + * see ISO/IEC 15444-1:2002 E.1 and A.6.4. */
> switch (qntsty->quantsty) {
> uint8_t gain;
> int numbps;
> @@ -308,9 +308,12 @@ int ff_jpeg2000_init_component(Jpeg2000Component *comp,
> break;
> default:
> band->stepsize = 0;
> - av_log(ctx, AV_LOG_ERROR, "Unknown quantization format\n");
> + 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 = (int32_t)(band->stepsize * (1<<16));
>
> /* 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
> diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
> index 0eb6e07..cf20ef8 100644
> --- a/libavcodec/jpeg2000dec.c
> +++ b/libavcodec/jpeg2000dec.c
> @@ -266,7 +266,11 @@ static int get_cox(Jpeg2000DecoderContext *s,
> Jpeg2000CodingStyle *c)
> av_log(s->avctx, AV_LOG_ERROR, "no extra cblk styles supported\n");
> return -1;
> }
> - c->transform = bytestream_get_byte(&s->buf); // transformation
> + c->transform = bytestream_get_byte(&s->buf); // DWT transformation type
> + /* set integer 9/7 DWT in case of BITEXACT flag*/
> + if ((s->avctx->flags & CODEC_FLAG_BITEXACT) && (c->transform ==
> FF_DWT97))
> + c->transform = FF_DWT97_INT;
> +
> if (c->csty & JPEG2000_CSTY_PREC) {
> int i;
> for (i = 0; i < c->nreslevels; i++) {
> @@ -881,9 +885,59 @@ static int decode_cblk(Jpeg2000DecoderContext *s,
> Jpeg2000CodingStyle *codsty,
> return 0;
> }
>
> +/* TODO: Verify dequantization in case of 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,
> + Jpeg2000T1Context *t1, Jpeg2000Band *band) {
> + int i, j, idx;
> + float *datap = &comp->data[(comp->coord[0][1] - comp->coord[0][0]) * y +
> x];
> + for (j = 0; j < (cblk->coord[1][1] - cblk->coord[1][0]); ++j)
> + for (i = 0; i < (cblk->coord[0][1] - cblk->coord[0][0]); ++i) {
> + idx = (comp->coord[0][1] - comp->coord[0][0]) * j + i;
> + datap[idx] = (float)(t1->data[j][i]) * ((float)band->stepsize);
> + }
> + return;
> +}
> +
> +/* Integer dequantization of a codeblock.*/
> +static void dequantization_int(int x, int y, Jpeg2000Cblk *cblk,
> + Jpeg2000Component *comp,
> + Jpeg2000T1Context *t1, Jpeg2000Band *band) {
> + int i, j, idx;
> + int32_t *datap =
> + (int32_t *) &comp->data[(comp->coord[0][1] - comp->coord[0][0]) * y
> + x];
> + for (j = 0; j < (cblk->coord[1][1] - cblk->coord[1][0]); ++j)
> + for (i = 0; i < (cblk->coord[0][1] - cblk->coord[0][0]); ++i) {
> + idx = (comp->coord[0][1] - comp->coord[0][0]) *
> j + i;
> + ((int32_t *)datap)[idx] =
> + ((int32_t)(t1->data[j][i]) * ((int32_t)band->stepsize) +
> (1<<15)) >> 16;
> + }
> + return;
this is not LISP or C++ - many useless parentheses and casts see I here
> +}
> +
> +/* Inverse ICT parameters in float and integer.
> + * int value = (float value) * (1<<16) */
> +static const float f_ict_params[4] = {
> + 1.402f,
> + 0.34413f,
> + 0.71414f,
> + 1.772f };
> +static const int i_ict_params[4] = {
> + 91881,
> + 22553,
> + 46802,
> + 116130
> +};
formatting like that Diego likes not
> +
> static void mct_decode(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
> {
> - int i, *src[3], i0, i1, i2, csize = 1;
> + int32_t i, *src[3], i0, i1, i2, csize = 1;
> float *srcf[3];
> float i0f, i1f, i2f;
>
> @@ -891,21 +945,34 @@ static void mct_decode(Jpeg2000DecoderContext *s,
> Jpeg2000Tile *tile)
> if (tile->codsty[0].transform == FF_DWT97)
> srcf[i] = tile->comp[i].data;
> else
> - src[i] = (int *)tile->comp[i].data;
> + src[i] = (int32_t *)tile->comp[i].data;
>
> for (i = 0; i < 2; i++)
> csize *= tile->comp[0].coord[i][1] - tile->comp[0].coord[i][0];
> -
> - if (tile->codsty[0].transform == FF_DWT97) {
> + switch (tile->codsty[0].transform) {
> + case FF_DWT97:
> for (i = 0; i < csize; i++) {
> - i0f = *srcf[0] + (1.402f * *srcf[2]);
> - i1f = *srcf[0] - (0.34413f * *srcf[1]) - (0.71414f * *srcf[2]);
> - i2f = *srcf[0] + (1.772f * *srcf[1]);
> + i0f = *srcf[0] + (f_ict_params[0] * *srcf[2]);
> + i1f = *srcf[0] - (f_ict_params[1] * *srcf[1])
> + - (f_ict_params[2] * *srcf[2]);
> + i2f = *srcf[0] + (f_ict_params[3] * *srcf[1]);
> *srcf[0]++ = i0f;
> *srcf[1]++ = i1f;
> *srcf[2]++ = i2f;
> }
> - } else {
> + break;
> + case FF_DWT97_INT:
> + for (i = 0; i < csize; i++) {
> + i0 = *src[0] + (((i_ict_params[0] * *src[2]) + (1 << 15)) >> 16);
> + i1 = *src[0] - (((i_ict_params[1] * *src[1]) + (1 << 15)) >> 16)
> + - (((i_ict_params[2] * *src[2]) + (1 << 15)) >> 16);
> + i2 = *src[0] + (((i_ict_params[3] * *src[1]) + (1 << 15)) >> 16);
> + *src[0]++ = i0;
> + *src[1]++ = i1;
> + *src[2]++ = i2;
> + }
> + break;
> + case FF_DWT53:
> for (i = 0; i < csize; i++) {
> i1 = *src[0] - (*src[2] + *src[1] >> 2);
> i0 = i1 + *src[2];
> @@ -914,6 +981,9 @@ static void mct_decode(Jpeg2000DecoderContext *s,
> Jpeg2000Tile *tile)
> *src[1]++ = i1;
> *src[2]++ = i2;
> }
> + break;
> + default:
> + break;
useless this chunk is
> }
> }
>
In general does not look that different from floating-point version, probably
OK
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel