shithub: jbig2

Download patch

ref: ef06d243c1a26abd9223181b8c5751ceb051258e
parent: 5613e3f978e406268fe5c42b7da322c0e4bfa7a9
author: giles <giles@ded80894-8fb9-0310-811b-c03f3676ab4d>
date: Mon Jun 24 19:28:13 EDT 2002

another checkpoint of text region decoding work. referred-to segment info is correct now.


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

--- a/jbig2.c
+++ b/jbig2.c
@@ -8,7 +8,7 @@
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
         
-    $Id: jbig2.c,v 1.9 2002/06/22 16:05:45 giles Exp $
+    $Id: jbig2.c,v 1.10 2002/06/24 23:28:13 giles Exp $
 */
 
 #include <stdint.h>
@@ -276,8 +276,8 @@
 	    return 0;
 	  code = jbig2_write_segment(ctx, segment, ctx->buf + ctx->buf_rd_ix);
 	  ctx->buf_rd_ix += segment->data_length;
-	  jbig2_free_segment(ctx, segment);
-	  ctx->segments[ctx->segment_index] = NULL;
+//	  jbig2_free_segment(ctx, segment);
+//	  ctx->segments[ctx->segment_index] = NULL;
 	  if (ctx->state == JBIG2_FILE_RANDOM_BODIES)
 	    {
 	      ctx->segment_index++;
--- a/jbig2_priv.h
+++ b/jbig2_priv.h
@@ -8,7 +8,7 @@
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
         
-    $Id: jbig2_priv.h,v 1.9 2002/06/24 15:51:57 giles Exp $
+    $Id: jbig2_priv.h,v 1.10 2002/06/24 23:28:13 giles Exp $
     
     shared library internals
 */
@@ -110,10 +110,10 @@
 int jbig2_complete_page (Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *segment_data);
 
 typedef enum {
-    JBIG2_COMPOSE_OR,
-    JBIG2_COMPOSE_AND,
-    JBIG2_COMPOSE_XOR,
-    JBIG2_COMPOSE_XNOR
+    JBIG2_COMPOSE_OR = 0,
+    JBIG2_COMPOSE_AND = 1,
+    JBIG2_COMPOSE_XOR = 2,
+    JBIG2_COMPOSE_XNOR = 3
 } Jbig2ComposeOp;
 
 int jbig2_image_compose(Jbig2Ctx *ctx, Jbig2Image *dst, Jbig2Image *src, int x, int y, Jbig2ComposeOp op);
--- a/jbig2_segment.c
+++ b/jbig2_segment.c
@@ -8,7 +8,7 @@
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
 
-    $Id: jbig2_segment.c,v 1.8 2002/06/24 18:44:45 giles Exp $
+    $Id: jbig2_segment.c,v 1.9 2002/06/24 23:28:13 giles Exp $
 */
 
 #include <stdio.h>
@@ -70,7 +70,6 @@
       referred_to_segments = jbig2_alloc(ctx->allocator, referred_to_segment_count * referred_to_segment_size);
     
       for (i = 0; i < referred_to_segment_count; i++) {
-        
         referred_to_segments[i] = 
           (referred_to_segment_size == 1) ? buf[offset] :
           (referred_to_segment_size == 2) ? jbig2_get_int16(buf+offset) :
--- a/jbig2_text.c
+++ b/jbig2_text.c
@@ -8,11 +8,12 @@
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
 
-    $Id: jbig2_text.c,v 1.4 2002/06/24 19:09:47 giles Exp $
+    $Id: jbig2_text.c,v 1.5 2002/06/24 23:28:13 giles Exp $
 */
 
 #include <stddef.h>
 #include <stdint.h>
+#include <stdio.h>
 #include <string.h> /* memset() */
 
 #ifdef HAVE_CONFIG_H
@@ -229,7 +230,7 @@
     Jbig2SymbolDict **dicts;
     int n_dicts;
     uint32_t num_instances;
-    uint16_t segment_flags;
+    uint16_t flags;
     uint16_t huffman_flags;
     int8_t sbrat[4];
     int index;
@@ -242,19 +243,32 @@
     offset += 17;
     
     /* 7.4.3.1.1 */
-    segment_flags = jbig2_get_int16(segment_data + offset);
+    flags = jbig2_get_int16(segment_data + offset);
     offset += 2;
     
-    if (segment_flags & 0x01)	/* Huffman coding */
+    params.SBHUFF = flags & 0x0001;
+    params.SBREFINE = flags & 0x0002;
+    params.REFCORNER = (flags & 0x0030) >> 4;
+    params.TRANSPOSED = flags & 0x0040;
+    params.SBCOMBOP = (flags & 0x00e0) >> 7;
+    params.SBDEFPIXEL = flags & 0x0100;
+    params.SBDSOFFSET = (flags & 0x7C00) >> 10;
+    params.SBRTEMPLATE = flags & 0x8000;
+    
+    if (params.SBHUFF)	/* Huffman coding */
       {
         /* 7.4.3.1.2 */
         huffman_flags = jbig2_get_int16(segment_data + offset);
         offset += 2;
+        
+        if (huffman_flags & 0x8000)
+            jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
+                "reserved bit 15 of text region huffman flags is not zero");
       }
     else	/* arithmetic coding */
       {
         /* 7.4.3.1.3 */
-        if ((segment_flags & 0x02) && !(segment_flags & 0x80)) /* SBREFINE & !SBRTEMPLATE */
+        if ((params.SBREFINE) && !(params.SBRTEMPLATE))
           {
             sbrat[0] = segment_data[offset];
             sbrat[0] = segment_data[offset + 1];
@@ -267,10 +281,26 @@
     num_instances = jbig2_get_int32(segment_data + offset);
     offset += 4;
     
-    /* 7.4.3.1.7 */
-    if (segment_flags & 0x01) {
+    if (params.SBHUFF) {
+        /* 7.4.3.1.5 */
+        /* todo: symbol ID huffman decoding table decoding */
+        
         jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
             "symbol id huffman table decoding NYI");
+            
+        /* 7.4.3.1.6 */
+        params.SBHUFFFS = (huffman_flags & 0x0003);
+        params.SBHUFFDS = (huffman_flags & 0x000c) >> 2;
+        params.SBHUFFDT = (huffman_flags & 0x0030) >> 4;
+        params.SBHUFFRDW = (huffman_flags & 0x00c0) >> 6;
+        params.SBHUFFRDH = (huffman_flags & 0x0300) >> 8;
+        params.SBHUFFRDX = (huffman_flags & 0x0c00) >> 10;
+        params.SBHUFFRDY = (huffman_flags & 0x3000) >> 12;
+        /* todo: conformance */
+        params.SBHUFFRSIZE = huffman_flags & 0x8000;
+        
+        /* 7.4.3.1.7 */
+        /* todo: symbol ID huffman table decoding */
     }
     
     jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
@@ -282,15 +312,19 @@
     /* compose the list of symbol dictionaries */
     n_dicts = 0;
     for (index = 0; index < segment->referred_to_segment_count; index++) {
-        if (ctx->segments[segment->referred_to_segments[index]]->flags & 63 == 0)
+        int sindex = segment->referred_to_segments[index];
+        if ((ctx->segments[sindex]->flags & 63) == 0)
             n_dicts++;
     }
     dicts = jbig2_alloc(ctx->allocator, sizeof(Jbig2SymbolDict *) * n_dicts);
     for (index = 0; index < segment->referred_to_segment_count; index++) {
+        int sindex = segment->referred_to_segments[index];
         int dindex = 0;
-        if (ctx->segments[segment->referred_to_segments[index]]->flags & 63 == 0)
-            dicts[dindex++] = (Jbig2SymbolDict *)ctx->segments[segment->referred_to_segments[index]]->result;
+        if ((ctx->segments[sindex]->flags & 63) == 0)
+            dicts[dindex++] = (Jbig2SymbolDict *)ctx->segments[sindex]->result;
     }
+    jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
+        "refers to %d symbol dictionaries", n_dicts);
     
     page_image = ctx->pages[ctx->current_page].image;
     image = jbig2_image_new(ctx, region_info.width, region_info.height);