From 1bbb46ff7126d71256b710645acf6cbfad857a23 Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <michaelni@gmx.at>
Date: Mon, 27 May 2013 19:57:42 +0200
Subject: [PATCH] j2k_dwt: fix scaling of 9/7 dwt

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
---
 libavcodec/j2k_dwt.c            | 16 ++++++++--------
 tests/ref/vsynth/vsynth1-j2k-97 |  8 ++++----
 tests/ref/vsynth/vsynth2-j2k-97 |  8 ++++----
 3 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/libavcodec/j2k_dwt.c b/libavcodec/j2k_dwt.c
index 6f1457fc226..8494ecd9fc8 100644
--- a/libavcodec/j2k_dwt.c
+++ b/libavcodec/j2k_dwt.c
@@ -160,9 +160,9 @@ static void dwt_encode97(DWTContext *s, int *t)
 
             // copy back and deinterleave
             for (i =   mh; i < lh; i+=2, j++)
-                t[w*lp + j] = scale97[mh] * l[i] / 2;
+                t[w*lp + j] = scale97[0] * l[i] / 2;
             for (i = 1-mh; i < lh; i+=2, j++)
-                t[w*lp + j] = scale97[mh] * l[i] / 2;
+                t[w*lp + j] = scale97[1] * l[i] / 2;
         }
 
         // VER_SD
@@ -177,9 +177,9 @@ static void dwt_encode97(DWTContext *s, int *t)
 
             // copy back and deinterleave
             for (i =   mv; i < lv; i+=2, j++)
-                t[w*j + lp] = scale97[mv] * l[i] / 2;
+                t[w*j + lp] = scale97[0] * l[i] / 2;
             for (i = 1-mv; i < lv; i+=2, j++)
-                t[w*j + lp] = scale97[mv] * l[i] / 2;
+                t[w*j + lp] = scale97[1] * l[i] / 2;
         }
     }
 }
@@ -288,9 +288,9 @@ static void dwt_decode97(DWTContext *s, int *t)
             int i, j = 0;
             // copy with interleaving
             for (i =   mh; i < lh; i+=2, j++)
-                l[i] = scale97[1-mh] * t[w*lp + j];
+                l[i] = scale97[1] * t[w*lp + j];
             for (i = 1-mh; i < lh; i+=2, j++)
-                l[i] = scale97[1-mh] * t[w*lp + j];
+                l[i] = scale97[0] * t[w*lp + j];
 
             sr_1d97(line, mh, mh + lh);
 
@@ -304,9 +304,9 @@ static void dwt_decode97(DWTContext *s, int *t)
             int i, j = 0;
             // copy with interleaving
             for (i =   mv; i < lv; i+=2, j++)
-                l[i] = scale97[1-mv] * t[w*j + lp];
+                l[i] = scale97[1] * t[w*j + lp];
             for (i = 1-mv; i < lv; i+=2, j++)
-                l[i] = scale97[1-mv] * t[w*j + lp];
+                l[i] = scale97[0] * t[w*j + lp];
 
             sr_1d97(line, mv, mv + lv);
 
diff --git a/tests/ref/vsynth/vsynth1-j2k-97 b/tests/ref/vsynth/vsynth1-j2k-97
index fb1ad8b0233..5b564c649a9 100644
--- a/tests/ref/vsynth/vsynth1-j2k-97
+++ b/tests/ref/vsynth/vsynth1-j2k-97
@@ -1,4 +1,4 @@
-a8e2db2dc6fcd4c9ea3150dc8d6d7619 *tests/data/fate/vsynth1-j2k-97.avi
-2963264 tests/data/fate/vsynth1-j2k-97.avi
-68f26a8d366fce47cbd003cadc861cd8 *tests/data/fate/vsynth1-j2k-97.out.rawvideo
-stddev:    7.66 PSNR: 30.44 MAXDIFF:   58 bytes:  7603200/  7603200
+fc02bacb438c091a96ab327ab7aca5f9 *tests/data/fate/vsynth1-j2k-97.avi
+2034146 tests/data/fate/vsynth1-j2k-97.avi
+5975c315f9fd79e57e26bda1f749e8f6 *tests/data/fate/vsynth1-j2k-97.out.rawvideo
+stddev:    8.77 PSNR: 29.26 MAXDIFF:  104 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-j2k-97 b/tests/ref/vsynth/vsynth2-j2k-97
index b799d181067..27562e7817c 100644
--- a/tests/ref/vsynth/vsynth2-j2k-97
+++ b/tests/ref/vsynth/vsynth2-j2k-97
@@ -1,4 +1,4 @@
-245c0ab429b553b39cac5989bb23c0ce *tests/data/fate/vsynth2-j2k-97.avi
-1444170 tests/data/fate/vsynth2-j2k-97.avi
-61c52045d566b70886113e2aeb8ddde4 *tests/data/fate/vsynth2-j2k-97.out.rawvideo
-stddev:    7.13 PSNR: 31.06 MAXDIFF:   53 bytes:  7603200/  7603200
+316ae4cce1ba8cf0b359c9d25322711f *tests/data/fate/vsynth2-j2k-97.avi
+1005146 tests/data/fate/vsynth2-j2k-97.avi
+b7826bc75f9c04754d12fa01b3e69a4a *tests/data/fate/vsynth2-j2k-97.out.rawvideo
+stddev:    7.91 PSNR: 30.16 MAXDIFF:   64 bytes:  7603200/  7603200
-- 
GitLab