jbig2dec

Ralph Giles <[email protected]> Mon, 24 Jun 2002 16:28:16 -0700
Newsgroups gmane.comp.printing.ghostscript.jbig2dec.cvs
Message-ID <[email protected]>
Update of /cvsroot/jbig2dec/jbig2dec
In directory usw-pr-cvs1:/tmp/cvs-serv22007

Modified Files:
	jbig2.c jbig2_priv.h jbig2_segment.c jbig2_text.c 
Log Message:
another checkpoint of text region decoding work. referred-to segment info is correct now.


Index: jbig2.c
===================================================================
RCS file: /cvsroot/jbig2dec/jbig2dec/jbig2.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- jbig2.c	22 Jun 2002 16:05:45 -0000	1.9
+++ jbig2.c	24 Jun 2002 23:28:13 -0000	1.10
@@ -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++;

Index: jbig2_priv.h
===================================================================
RCS file: /cvsroot/jbig2dec/jbig2dec/jbig2_priv.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- jbig2_priv.h	24 Jun 2002 15:51:57 -0000	1.9
+++ jbig2_priv.h	24 Jun 2002 23:28:13 -0000	1.10
@@ -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);

Index: jbig2_segment.c
===================================================================
RCS file: /cvsroot/jbig2dec/jbig2dec/jbig2_segment.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- jbig2_segment.c	24 Jun 2002 18:44:45 -0000	1.8
+++ jbig2_segment.c	24 Jun 2002 23:28:13 -0000	1.9
@@ -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) :

Index: jbig2_text.c
===================================================================
RCS file: /cvsroot/jbig2dec/jbig2dec/jbig2_text.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- jbig2_text.c	24 Jun 2002 19:09:47 -0000	1.4
+++ jbig2_text.c	24 Jun 2002 23:28:13 -0000	1.5
@@ -13,6 +13,7 @@
 
 #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);