shithub: jbig2

Download patch

ref: 872c0bb40abd41f305e2cd27a3673fe2f28b9ea6
parent: 441dc4f503432969833a7124b45e1e98ffe7cb81
author: giles <giles@ded80894-8fb9-0310-811b-c03f3676ab4d>
date: Thu Oct 7 21:29:10 EDT 2004

correct shift offsets

git-svn-id: http://svn.ghostscript.com/jbig2dec/trunk@326 ded80894-8fb9-0310-811b-c03f3676ab4d

--- a/jbig2_refinement.c
+++ b/jbig2_refinement.c
@@ -79,12 +79,12 @@
 
     line_m1 = (y >= 1) ? grreg_line[-stride] : 0;
     refline_m1 = (y >= 1) ? grref_line[-stride] << 2: 0;
-    refline_0  = grref_line[0] << 5;
-    refline_1  = (y < GBW - 1) ? grref_line[+stride] << 8 : 0;
-    CONTEXT = ((line_m1 >> 3) & 0x00e) |
-	      ((refline_1 >> 3) & 0x030) |
-	      ((refline_0 >> 3) & 0x1c0) |
-	      ((refline_m1 >> 3) & 0x200);
+    refline_0  = grref_line[0] << 4;
+    refline_1  = (y < GBW - 1) ? grref_line[+stride] << 7 : 0;
+    CONTEXT = ((line_m1 >> 5) & 0x00e) |
+	      ((refline_1 >> 5) & 0x030) |
+	      ((refline_0 >> 5) & 0x1c0) |
+	      ((refline_m1 >> 5) & 0x200);
 
     for (x = 0; x < padded_width; x += 8) {
       byte result = 0;
@@ -99,11 +99,11 @@
       }
 
       refline_0 = (refline_0 << 8) |
-	  (x + 8 < GBW ? grref_line[(x >> 3) + 1] << 5 : 0);
+	  (x + 8 < GBW ? grref_line[(x >> 3) + 1] << 4 : 0);
 
       if (y < GBH - 1)
 	refline_1 = (refline_1 << 8) |
-	  (x + 8 < GBW ? grref_line[+refstride + (x >> 3) + 1] << 8 : 0);
+	  (x + 8 < GBW ? grref_line[+refstride + (x >> 3) + 1] << 7 : 0);
       else
 	refline_1 = 0;
 
@@ -114,10 +114,10 @@
 	bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
 	result |= bit << (7 - x_minor);
 	CONTEXT = ((CONTEXT & 0x0d6) << 1) | bit |
-	  ((line_m1 >> (10 - x_minor)) & 0x002) |
-	  ((refline_1 >> (10 - x_minor)) & 0x010) |
-	  ((refline_0 >> (10 - x_minor)) & 0x040) |
-	  ((refline_m1 >> (10 - x_minor)) & 0x200);
+	  ((line_m1 >> (9 - x_minor)) & 0x002) |
+	  ((refline_1 >> (9 - x_minor)) & 0x010) |
+	  ((refline_0 >> (9 - x_minor)) & 0x040) |
+	  ((refline_m1 >> (9 - x_minor)) & 0x200);
       }
 
       grreg_line[x>>3] = result;