shithub: jbig2

Download patch

ref: 281958c01ba5b205e1d70a0babe7599c6e896a16
parent: 14ae8a7fc45563b7623d96fb22e4003ae665a093
author: Sebastian Rasmussen <[email protected]>
date: Sat Apr 21 21:45:15 EDT 2018

jbig2dec: Fix and use decoder for template 3 generic regions.

Previously an optimized implementation for template generic
regions was commented out, presumably because it was faulty,
but now once the implementation is fixed it may be used.

The PDF in bug 693617 has an object 25 that contains a JBIG2
bitstream that can use this fix optimized decoder. Without
the fix in the optimized decoder the rendered output image
is incorrect.

--- a/jbig2_generic.c
+++ b/jbig2_generic.c
@@ -374,7 +374,6 @@
     return 0;
 }
 
-#ifdef UNUSED
 static int
 jbig2_decode_generic_template3(Jbig2Ctx *ctx,
                                Jbig2Segment *segment,
@@ -385,9 +384,8 @@
     const int rowstride = image->stride;
     byte *gbreg_line = (byte *) image->data;
     int x, y;
+    int code;
 
-    /* this routine only handles the nominal AT location */
-
 #ifdef OUTPUT_PBM
     printf("P4\n%d %d\n", GBW, GBH);
 #endif
@@ -420,7 +418,7 @@
                 if (code)
                     return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to decode arithmetic code when handling generic template3");
                 result |= bit << (7 - x_minor);
-                CONTEXT = ((CONTEXT & 0x1f7) << 1) | bit | ((line_m1 >> (10 - x_minor)) & 0x010);
+                CONTEXT = ((CONTEXT & 0x1f7) << 1) | bit | ((line_m1 >> (8 - x_minor)) & 0x10);
             }
             gbreg_line[x >> 3] = result;
         }
@@ -432,7 +430,6 @@
 
     return 0;
 }
-#endif
 
 static int
 jbig2_decode_generic_template3_unopt(Jbig2Ctx *ctx,
@@ -752,7 +749,7 @@
             return jbig2_decode_generic_template2_unopt(ctx, segment, params, as, image, GB_stats);
     } else if (!params->MMR && params->GBTEMPLATE == 3) {
         if (gbat[0] == 2 && gbat[1] == -1)
-            return jbig2_decode_generic_template3_unopt(ctx, segment, params, as, image, GB_stats);
+            return jbig2_decode_generic_template3(ctx, segment, params, as, image, GB_stats);
         else
             return jbig2_decode_generic_template3_unopt(ctx, segment, params, as, image, GB_stats);
     }