shithub: jbig2

Download patch

ref: a9d42d067a6cd01c9f1fd73b00ff9c69c6ba85c6
parent: 994516f6db541df5f57d3de4851313af6a260f68
author: giles <giles@ded80894-8fb9-0310-811b-c03f3676ab4d>
date: Mon Dec 5 20:47:35 EST 2005

The SBDSOFFSET field is a *signed* 5 bit integer, so we need to sign 
extend when reading the field to get the proper value. We now correctly
handle the 042_20.jb2 test stream.


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

--- a/jbig2_text.c
+++ b/jbig2_text.c
@@ -494,6 +494,9 @@
     /* 7.4.3.1.1 */
     flags = jbig2_get_int16(segment_data + offset);
     offset += 2;
+
+    jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
+	"text region header flags 0x%04x", flags);
     
     params.SBHUFF = flags & 0x0001;
     params.SBREFINE = flags & 0x0002;
@@ -503,8 +506,15 @@
     params.TRANSPOSED = flags & 0x0040;
     params.SBCOMBOP = (flags & 0x0180) >> 7;
     params.SBDEFPIXEL = flags & 0x0200;
+    /* SBDSOFFSET is a signed 5 bit integer */
     params.SBDSOFFSET = (flags & 0x7C00) >> 10;
+    if (params.SBDSOFFSET > 0x0f) params.SBDSOFFSET -= 0x20;
     params.SBRTEMPLATE = flags & 0x8000;
+
+    if (params.SBDSOFFSET) {
+      jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
+	"text region has SBDSOFFSET %d", params.SBDSOFFSET);
+    }
 
     if (params.SBHUFF)	/* Huffman coding */
       {