shithub: jbig2

Download patch

ref: 47a138b6362c314be4cfd91977ac61b3cf772e0f
parent: 83513ef82b18de95374d8e6c229658735d76af32
author: giles <giles@ded80894-8fb9-0310-811b-c03f3676ab4d>
date: Thu Jun 14 19:09:23 EDT 2001

complain if the file uses the 'random access' layout which we don't handle yet.


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

--- a/jbig2dec.c
+++ b/jbig2dec.c
@@ -8,7 +8,7 @@
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
 
-    $Id: jbig2dec.c,v 1.7 2001/06/14 08:25:01 giles Exp $
+    $Id: jbig2dec.c,v 1.8 2001/06/14 23:09:23 giles Exp $
 */
 
 #include <stdio.h>
@@ -21,14 +21,20 @@
 typedef struct _Jbig2SymbolDictionary Jbig2SymbolDictionary;
 typedef struct _Jbig2PageInfo Jbig2PageInfo;
 
+/* our main 'context' structure for decoding a jbig2 bitstream */
 struct _Jbig2Ctx {
   FILE *f;
   int offset;
-
-  byte flags;
+  
   int32 n_pages;
+  byte flags;
 };
 
+/* useful masks for parsing the flags field */
+#define JBIG2_FILE_FLAGS_SEQUENTIAL_ACCESS	0x01
+#define JBIG2_FILE_FLAGS_PAGECOUNT_UNKNOWN	0x02
+
+
 struct _Jbig2SegmentHeader {
   int32 segment_number;
   byte flags;
@@ -105,7 +111,7 @@
       return NULL;
     }
   ctx->flags = buf[8];
-  if (ctx->flags & 2)
+  if (ctx->flags & JBIG2_FILE_FLAGS_PAGECOUNT_UNKNOWN)
     {
       ctx->offset = 9;	/* number of pages unknown */
 	  ctx->n_pages = 0;
@@ -115,6 +121,14 @@
       ctx->offset = 13;
       ctx->n_pages = get_int32 (ctx, 9);
 	}
+  
+  if(!ctx->flags & JBIG2_FILE_FLAGS_SEQUENTIAL_ACCESS) {
+	printf("warning: random access header organization.\n");
+	printf("we don't handle that yet.\n");
+	free(ctx);
+	return NULL;
+  }
+	
   return ctx;
 }