[FFmpeg-devel] [RFC PATCH v6 4/4] libavcodec/jpeg2000: fix tag tree reset

gautamramk at gmail.com gautamramk at gmail.com
Wed Aug 26 18:58:18 EEST 2020


From: Gautam Ramakrishnan <gautamramk at gmail.com>

The implementation of the tag tree did not
set the correct reset value for the encoder.
This lead to inefficent tag tree being encoded.
This patch fixes the implementation of the
ff_tag_tree_zero() function.
---
 libavcodec/j2kenc.c                      | 4 ++--
 libavcodec/jpeg2000.c                    | 8 ++++----
 libavcodec/jpeg2000.h                    | 2 +-
 tests/ref/vsynth/vsynth1-jpeg2000        | 4 ++--
 tests/ref/vsynth/vsynth1-jpeg2000-97     | 4 ++--
 tests/ref/vsynth/vsynth2-jpeg2000        | 4 ++--
 tests/ref/vsynth/vsynth2-jpeg2000-97     | 4 ++--
 tests/ref/vsynth/vsynth3-jpeg2000        | 4 ++--
 tests/ref/vsynth/vsynth3-jpeg2000-97     | 4 ++--
 tests/ref/vsynth/vsynth_lena-jpeg2000    | 4 ++--
 tests/ref/vsynth/vsynth_lena-jpeg2000-97 | 4 ++--
 11 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/libavcodec/j2kenc.c b/libavcodec/j2kenc.c
index 8dab18cdd6..ed3ad73c8e 100644
--- a/libavcodec/j2kenc.c
+++ b/libavcodec/j2kenc.c
@@ -801,8 +801,8 @@ static int encode_packet(Jpeg2000EncoderContext *s, Jpeg2000ResLevel *rlevel, in
                 Jpeg2000Prec *prec = band->prec + precno;
                 int nb_cblks = prec->nb_codeblocks_height * prec->nb_codeblocks_width;
                 int pos;
-                ff_tag_tree_zero(prec->zerobits, prec->nb_codeblocks_width, prec->nb_codeblocks_height);
-                ff_tag_tree_zero(prec->cblkincl, prec->nb_codeblocks_width, prec->nb_codeblocks_height);
+                ff_tag_tree_zero(prec->zerobits, prec->nb_codeblocks_width, prec->nb_codeblocks_height, 99);
+                ff_tag_tree_zero(prec->cblkincl, prec->nb_codeblocks_width, prec->nb_codeblocks_height, 99);
                 for (pos = 0; pos < nb_cblks; pos++) {
                     Jpeg2000Cblk *cblk = &prec->cblk[pos];
                     prec->zerobits[pos].val = expn[bandno] + numgbits - 1 - cblk->nonzerobits;
diff --git a/libavcodec/jpeg2000.c b/libavcodec/jpeg2000.c
index 6501de0d04..56d98c8a89 100644
--- a/libavcodec/jpeg2000.c
+++ b/libavcodec/jpeg2000.c
@@ -82,12 +82,12 @@ static Jpeg2000TgtNode *ff_jpeg2000_tag_tree_init(int w, int h)
     return res;
 }
 
-void ff_tag_tree_zero(Jpeg2000TgtNode *t, int w, int h)
+void ff_tag_tree_zero(Jpeg2000TgtNode *t, int w, int h, int val)
 {
     int i, siz = ff_tag_tree_size(w, h);
 
     for (i = 0; i < siz; i++) {
-        t[i].val = 0;
+        t[i].val = val;
         t[i].temp_val = 0;
         t[i].vis = 0;
     }
@@ -575,8 +575,8 @@ void ff_jpeg2000_reinit(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
             Jpeg2000Band *band = rlevel->band + bandno;
             for(precno = 0; precno < rlevel->num_precincts_x * rlevel->num_precincts_y; precno++) {
                 Jpeg2000Prec *prec = band->prec + precno;
-                ff_tag_tree_zero(prec->zerobits, prec->nb_codeblocks_width, prec->nb_codeblocks_height);
-                ff_tag_tree_zero(prec->cblkincl, prec->nb_codeblocks_width, prec->nb_codeblocks_height);
+                ff_tag_tree_zero(prec->zerobits, prec->nb_codeblocks_width, prec->nb_codeblocks_height, 0);
+                ff_tag_tree_zero(prec->cblkincl, prec->nb_codeblocks_width, prec->nb_codeblocks_height, 0);
                 for (cblkno = 0; cblkno < prec->nb_codeblocks_width * prec->nb_codeblocks_height; cblkno++) {
                     Jpeg2000Cblk *cblk = prec->cblk + cblkno;
                     cblk->length = 0;
diff --git a/libavcodec/jpeg2000.h b/libavcodec/jpeg2000.h
index a7ba8aa7f3..612832c872 100644
--- a/libavcodec/jpeg2000.h
+++ b/libavcodec/jpeg2000.h
@@ -302,6 +302,6 @@ static inline int needs_termination(int style, int passno) {
 }
 
 int32_t ff_tag_tree_size(int w, int h);
-void ff_tag_tree_zero(Jpeg2000TgtNode *t, int w, int h);
+void ff_tag_tree_zero(Jpeg2000TgtNode *t, int w, int h, int val);
 
 #endif /* AVCODEC_JPEG2000_H */
diff --git a/tests/ref/vsynth/vsynth1-jpeg2000 b/tests/ref/vsynth/vsynth1-jpeg2000
index 5081507459..f8e987f95d 100644
--- a/tests/ref/vsynth/vsynth1-jpeg2000
+++ b/tests/ref/vsynth/vsynth1-jpeg2000
@@ -1,4 +1,4 @@
-dd66b25f2ebc965eae4c29cfacdd960f *tests/data/fate/vsynth1-jpeg2000.avi
-2274950 tests/data/fate/vsynth1-jpeg2000.avi
+95add005faf68fcf8f16e86eab079ca2 *tests/data/fate/vsynth1-jpeg2000.avi
+2263192 tests/data/fate/vsynth1-jpeg2000.avi
 b7f48a8965f78011c76483277befc6fc *tests/data/fate/vsynth1-jpeg2000.out.rawvideo
 stddev:    5.35 PSNR: 33.56 MAXDIFF:   59 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth1-jpeg2000-97 b/tests/ref/vsynth/vsynth1-jpeg2000-97
index 7e18f20e25..6ab5aa4237 100644
--- a/tests/ref/vsynth/vsynth1-jpeg2000-97
+++ b/tests/ref/vsynth/vsynth1-jpeg2000-97
@@ -1,4 +1,4 @@
-f22ad99de77f8f4382c6cf10d5af42b5 *tests/data/fate/vsynth1-jpeg2000-97.avi
-3661422 tests/data/fate/vsynth1-jpeg2000-97.avi
+e4d03b2e3c03e56c7f831b1e662c4031 *tests/data/fate/vsynth1-jpeg2000-97.avi
+3643928 tests/data/fate/vsynth1-jpeg2000-97.avi
 a2262f1da2f49bc196b780a6b47ec4e8 *tests/data/fate/vsynth1-jpeg2000-97.out.rawvideo
 stddev:    4.23 PSNR: 35.59 MAXDIFF:   53 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-jpeg2000 b/tests/ref/vsynth/vsynth2-jpeg2000
index 7b70e99ed9..d0df0099ea 100644
--- a/tests/ref/vsynth/vsynth2-jpeg2000
+++ b/tests/ref/vsynth/vsynth2-jpeg2000
@@ -1,4 +1,4 @@
-49df1372d20dae57b4ff28ac4d81bb78 *tests/data/fate/vsynth2-jpeg2000.avi
-1551520 tests/data/fate/vsynth2-jpeg2000.avi
+8c8a68ca748190c71b3ea43e5ab7f502 *tests/data/fate/vsynth2-jpeg2000.avi
+1538736 tests/data/fate/vsynth2-jpeg2000.avi
 64fadc87447268cf90503cb294db7f61 *tests/data/fate/vsynth2-jpeg2000.out.rawvideo
 stddev:    4.91 PSNR: 34.29 MAXDIFF:   55 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-jpeg2000-97 b/tests/ref/vsynth/vsynth2-jpeg2000-97
index 3400760573..33c1fb2425 100644
--- a/tests/ref/vsynth/vsynth2-jpeg2000-97
+++ b/tests/ref/vsynth/vsynth2-jpeg2000-97
@@ -1,4 +1,4 @@
-8443e3ae43675212be9a8274cfe5d5be *tests/data/fate/vsynth2-jpeg2000-97.avi
-2484530 tests/data/fate/vsynth2-jpeg2000-97.avi
+c8f76055f59804ca72dbd66eb4db83a2 *tests/data/fate/vsynth2-jpeg2000-97.avi
+2464138 tests/data/fate/vsynth2-jpeg2000-97.avi
 1f63c8b065e847e4c63d57ce23442ea8 *tests/data/fate/vsynth2-jpeg2000-97.out.rawvideo
 stddev:    3.21 PSNR: 37.99 MAXDIFF:   26 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth3-jpeg2000 b/tests/ref/vsynth/vsynth3-jpeg2000
index 2c3a0d9026..ecc286b9a4 100644
--- a/tests/ref/vsynth/vsynth3-jpeg2000
+++ b/tests/ref/vsynth/vsynth3-jpeg2000
@@ -1,4 +1,4 @@
-548df443acb32593455bbcd8f531c00b *tests/data/fate/vsynth3-jpeg2000.avi
-67658 tests/data/fate/vsynth3-jpeg2000.avi
+776bf3234cbf25002f129b89baab42ea *tests/data/fate/vsynth3-jpeg2000.avi
+67400 tests/data/fate/vsynth3-jpeg2000.avi
 098f5980667e1fcd50452b1dc1a74f61 *tests/data/fate/vsynth3-jpeg2000.out.rawvideo
 stddev:    5.47 PSNR: 33.36 MAXDIFF:   48 bytes:    86700/    86700
diff --git a/tests/ref/vsynth/vsynth3-jpeg2000-97 b/tests/ref/vsynth/vsynth3-jpeg2000-97
index 1b805f04ad..df10f43270 100644
--- a/tests/ref/vsynth/vsynth3-jpeg2000-97
+++ b/tests/ref/vsynth/vsynth3-jpeg2000-97
@@ -1,4 +1,4 @@
-494464d224d5aa2726bc6a8630a390aa *tests/data/fate/vsynth3-jpeg2000-97.avi
-86016 tests/data/fate/vsynth3-jpeg2000-97.avi
+cd023db503f03ef72dd83e4617a90c7b *tests/data/fate/vsynth3-jpeg2000-97.avi
+85606 tests/data/fate/vsynth3-jpeg2000-97.avi
 8def36ad1413ab3a5c2af2e1af4603f9 *tests/data/fate/vsynth3-jpeg2000-97.out.rawvideo
 stddev:    4.51 PSNR: 35.04 MAXDIFF:   47 bytes:    86700/    86700
diff --git a/tests/ref/vsynth/vsynth_lena-jpeg2000 b/tests/ref/vsynth/vsynth_lena-jpeg2000
index 2b4560ab54..88629add21 100644
--- a/tests/ref/vsynth/vsynth_lena-jpeg2000
+++ b/tests/ref/vsynth/vsynth_lena-jpeg2000
@@ -1,4 +1,4 @@
-e4cf380b198e6bcb00ec338914f6ebb3 *tests/data/fate/vsynth_lena-jpeg2000.avi
-1202516 tests/data/fate/vsynth_lena-jpeg2000.avi
+b8aaa45236f77a2a626791d462fd8ac1 *tests/data/fate/vsynth_lena-jpeg2000.avi
+1188886 tests/data/fate/vsynth_lena-jpeg2000.avi
 39a2c5b61cd0cf2821c6fb4cceba2fa8 *tests/data/fate/vsynth_lena-jpeg2000.out.rawvideo
 stddev:    4.30 PSNR: 35.45 MAXDIFF:   45 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-jpeg2000-97 b/tests/ref/vsynth/vsynth_lena-jpeg2000-97
index 1343dbc21b..b6f5f75f77 100644
--- a/tests/ref/vsynth/vsynth_lena-jpeg2000-97
+++ b/tests/ref/vsynth/vsynth_lena-jpeg2000-97
@@ -1,4 +1,4 @@
-29dd43765363e17179c2de4167b32399 *tests/data/fate/vsynth_lena-jpeg2000-97.avi
-1958334 tests/data/fate/vsynth_lena-jpeg2000-97.avi
+b2d9525433c6300674f504922d762437 *tests/data/fate/vsynth_lena-jpeg2000-97.avi
+1937232 tests/data/fate/vsynth_lena-jpeg2000-97.avi
 1b97333a8dc115a5ba609b0070d89d4d *tests/data/fate/vsynth_lena-jpeg2000-97.out.rawvideo
 stddev:    2.82 PSNR: 39.10 MAXDIFF:   24 bytes:  7603200/  7603200
-- 
2.17.1



More information about the ffmpeg-devel mailing list