[FFmpeg-cvslog] j2kdec/jpeg2000dec: partially merge quantization code

Michael Niedermayer git at videolan.org
Tue May 28 19:09:45 CEST 2013


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Tue May 28 14:27:49 2013 +0200| [32475f56f38d321b123fce116bc4521f6af0d738] | committer: Michael Niedermayer

j2kdec/jpeg2000dec: partially merge quantization code

The quantization code needs more work, not so much work
merging but more work investigating what is correct.

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=32475f56f38d321b123fce116bc4521f6af0d738
---

 libavcodec/j2k.c                |    7 ++++---
 libavcodec/j2kdec.c             |   37 ++++++++++++++++++-------------------
 libavcodec/jpeg2000.c           |    6 +++---
 tests/ref/vsynth/vsynth1-j2k    |    4 ++--
 tests/ref/vsynth/vsynth1-j2k-97 |    4 ++--
 tests/ref/vsynth/vsynth2-j2k    |    4 ++--
 tests/ref/vsynth/vsynth2-j2k-97 |    4 ++--
 7 files changed, 33 insertions(+), 33 deletions(-)

diff --git a/libavcodec/j2k.c b/libavcodec/j2k.c
index 2a86dce..7da05a8 100644
--- a/libavcodec/j2k.c
+++ b/libavcodec/j2k.c
@@ -278,15 +278,16 @@ int ff_j2k_init_component(Jpeg2000Component *comp,
                 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;
             }
+            /* FIXME: In openjepg code stespize = stepsize * 0.5. Why?
+             * If not set output of entropic decoder is not correct. */
+            if (!av_codec_is_encoder(avctx->codec))
+                stepsize *= 0.5;
             /* BITEXACT computing case --> convert to int */
 //             if (avctx->flags & CODEC_FLAG_BITEXACT)
             band->stepsize = stepsize * (1 << 16);
diff --git a/libavcodec/j2kdec.c b/libavcodec/j2kdec.c
index d2e003c..42862b9 100644
--- a/libavcodec/j2kdec.c
+++ b/libavcodec/j2kdec.c
@@ -26,6 +26,7 @@
  * @author Kamil Nowosad
  */
 
+#include "libavutil/avassert.h"
 #include "libavutil/common.h"
 #include "libavutil/opt.h"
 #include "avcodec.h"
@@ -814,6 +815,22 @@ static int decode_cblk(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *codsty,
     return 0;
 }
 
+/* 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;
+            datap[idx] =
+                ((int32_t)(t1->data[j][i]) * ((int32_t)band->stepsize) + (1 << 15)) >> 16;
+        }
+}
+
 static void mct_decode(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
 {
     int i, *src[3], i0, i1, i2, csize = 1;
@@ -890,25 +907,7 @@ static int decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
                         x = cblk->coord[0][0];
                         y = cblk->coord[1][0];
 
-                        if (codsty->transform == FF_DWT53) {
-                            for (j = 0; j < (cblk->coord[1][1] - cblk->coord[1][0]); ++j) {
-                                int *datap = &comp->data[(comp->coord[0][1] - comp->coord[0][0]) * (y+j) + x];
-                                int *ptr = t1.data[j];
-                                for (i = 0; i < (cblk->coord[0][1] - cblk->coord[0][0]); ++i) {
-                                    datap[i] = ptr[i] >> 1;
-                                }
-                            }
-                        } else{
-                            for (j = 0; j < (cblk->coord[1][1] - cblk->coord[1][0]); ++j) {
-                                int *datap = &comp->data[(comp->coord[0][1] - comp->coord[0][0]) * (y+j) + x];
-                                int *ptr = t1.data[j];
-                                for (i = 0; i < (cblk->coord[0][1] - cblk->coord[0][0]); ++i) {
-                                    int tmp = ((int64_t)ptr[i]) * ((int64_t)band->stepsize) >> 16, tmp2;
-                                    tmp2 = FFABS(tmp>>1) + (tmp&1);
-                                    datap[i] = tmp < 0 ? -tmp2 : tmp2;
-                                }
-                            }
-                        }
+                        dequantization_int(x, y, cblk, comp, &t1, band);
                    } /* end cblk */
                 } /*end prec */
             } /* end band */
diff --git a/libavcodec/jpeg2000.c b/libavcodec/jpeg2000.c
index 5b15efc..c5fc35d 100644
--- a/libavcodec/jpeg2000.c
+++ b/libavcodec/jpeg2000.c
@@ -288,15 +288,15 @@ int ff_jpeg2000_init_component(Jpeg2000Component *comp,
                 gain            = cbps;
                 band->stepsize  = pow(2.0, gain - qntsty->expn[gbandno]);
                 band->stepsize *= (float)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. */
-                band->stepsize *= 0.5;
                 break;
             default:
                 band->stepsize = 0;
                 av_log(avctx, AV_LOG_ERROR, "Unknown quantization format\n");
                 break;
             }
+            /* FIXME: In openjepg code stespize = stepsize * 0.5. Why?
+                * If not set output of entropic decoder is not correct. */
+            band->stepsize *= 0.5;
             /* BITEXACT computing case --> convert to int */
             if (avctx->flags & CODEC_FLAG_BITEXACT)
                 band->stepsize = (int32_t)(band->stepsize * (1 << 16));
diff --git a/tests/ref/vsynth/vsynth1-j2k b/tests/ref/vsynth/vsynth1-j2k
index 1e2f3f2..726d452 100644
--- a/tests/ref/vsynth/vsynth1-j2k
+++ b/tests/ref/vsynth/vsynth1-j2k
@@ -1,4 +1,4 @@
 e6e3d338eeb394d6fadc7bbb55fa9e6e *tests/data/fate/vsynth1-j2k.avi
 2306902 tests/data/fate/vsynth1-j2k.avi
-ee9b245b3b07eed90bc6f2147bbd916c *tests/data/fate/vsynth1-j2k.out.rawvideo
-stddev:    5.47 PSNR: 33.37 MAXDIFF:   64 bytes:  7603200/  7603200
+1774b621bd92a53a24712cb77e9f0b28 *tests/data/fate/vsynth1-j2k.out.rawvideo
+stddev:    5.37 PSNR: 33.52 MAXDIFF:   63 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth1-j2k-97 b/tests/ref/vsynth/vsynth1-j2k-97
index 3c59e79..1cc197a 100644
--- a/tests/ref/vsynth/vsynth1-j2k-97
+++ b/tests/ref/vsynth/vsynth1-j2k-97
@@ -1,4 +1,4 @@
 c135eb14e9f219242180270c2a242634 *tests/data/fate/vsynth1-j2k-97.avi
 2243132 tests/data/fate/vsynth1-j2k-97.avi
-c8dc404072bf57d3ca823c0adaac013c *tests/data/fate/vsynth1-j2k-97.out.rawvideo
-stddev:    6.79 PSNR: 31.49 MAXDIFF:   77 bytes:  7603200/  7603200
+30a9c13e18fe4acaf28062b5003bb671 *tests/data/fate/vsynth1-j2k-97.out.rawvideo
+stddev:    6.41 PSNR: 31.99 MAXDIFF:   75 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-j2k b/tests/ref/vsynth/vsynth2-j2k
index 4f038fe..1120b90 100644
--- a/tests/ref/vsynth/vsynth2-j2k
+++ b/tests/ref/vsynth/vsynth2-j2k
@@ -1,4 +1,4 @@
 fc49816ba28731689872f5c87ca91c10 *tests/data/fate/vsynth2-j2k.avi
 1151144 tests/data/fate/vsynth2-j2k.avi
-ec5218eec33a021945c28c72093382a5 *tests/data/fate/vsynth2-j2k.out.rawvideo
-stddev:    4.54 PSNR: 34.99 MAXDIFF:   61 bytes:  7603200/  7603200
+e7d79c9e11d0fe97f03e38be66c34e4f *tests/data/fate/vsynth2-j2k.out.rawvideo
+stddev:    4.41 PSNR: 35.23 MAXDIFF:   63 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-j2k-97 b/tests/ref/vsynth/vsynth2-j2k-97
index ed5bcc9..5232802 100644
--- a/tests/ref/vsynth/vsynth2-j2k-97
+++ b/tests/ref/vsynth/vsynth2-j2k-97
@@ -1,4 +1,4 @@
 3ac3e49a89136bddde9e44bac3e5b4ed *tests/data/fate/vsynth2-j2k-97.avi
 1118952 tests/data/fate/vsynth2-j2k-97.avi
-a9434a726d6976facf53ff63d1466a99 *tests/data/fate/vsynth2-j2k-97.out.rawvideo
-stddev:    5.81 PSNR: 32.84 MAXDIFF:   59 bytes:  7603200/  7603200
+9d69ac6d46152ed2d6dd6a90d5793c80 *tests/data/fate/vsynth2-j2k-97.out.rawvideo
+stddev:    5.32 PSNR: 33.61 MAXDIFF:   60 bytes:  7603200/  7603200



More information about the ffmpeg-cvslog mailing list