shithub: jbig2

Download patch

ref: 0a9dae0a3c665ce5c758f1575e0c8f08075aaf3c
parent: d78f4fbaac91f43bd14ac7d54c60e8edb0fa5bfe
author: giles <giles@ded80894-8fb9-0310-811b-c03f3676ab4d>
date: Mon May 23 23:49:47 EDT 2005

Update the arith and huffman tests to run with the new code. We now
compile with -DTEST and link to the rest of the library since that's
required to access the allocator. In theory, that means we have duplicate
symbols, but GNU ld seems to cope. If it's a problem the test programs can
be split into separate source files.

Note that the arith test doesn't actually verify its results; it just
prints the results when compiled with -DJBIG2_DEBUG.



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

--- a/Makefile.am
+++ b/Makefile.am
@@ -37,9 +37,11 @@
 test_sha1_SOURCES = sha1.c sha1.h
 test_sha1_CFLAGS = -DTEST
 
-test_arith_SOURCES = sha1.c sha1.h
+test_arith_SOURCES = jbig2_arith.c
 test_arith_CFLAGS = -DTEST
+test_arith_LDADD = libjbig2dec.a
 
-test_huffman_SOURCES = sha1.c sha1.h
+test_huffman_SOURCES = jbig2_huffman.c
 test_huffman_CFLAGS = -DTEST
+test_huffman_LDADD = libjbig2dec.a
 
--- a/jbig2_arith.c
+++ b/jbig2_arith.c
@@ -344,7 +344,7 @@
 
 #ifdef TEST
 
-static int32_t
+static uint32_t
 test_get_word (Jbig2WordStream *self, int offset)
 {
   byte stream[] = {
@@ -363,14 +363,19 @@
 int
 main (int argc, char **argv)
 {
+  Jbig2Ctx *ctx;
   Jbig2WordStream ws;
   Jbig2ArithState *as;
   int i;
   Jbig2ArithCx cx = 0;
 
+  ctx = jbig2_ctx_new(NULL, 0, NULL, NULL, NULL);
+
   ws.get_next_word = test_get_word;
-  as = jbig2_arith_new (NULL, &ws);
+  as = jbig2_arith_new (ctx, &ws);
+#ifdef JBIG2_DEBUG
   jbig2_arith_trace (as, cx);
+#endif
 
   for (i = 0; i < 256; i++)
     {
@@ -377,10 +382,16 @@
       bool D;
 
       D = jbig2_arith_decode (as, &cx);
+#ifdef JBIG2_DEBUG
       printf ("%3d: D = %d, ", i, D);
       jbig2_arith_trace (as, cx);
-      
+#endif      
     }
+
+  jbig2_free(ctx->allocator, as);
+
+  jbig2_ctx_free(ctx);
+
   return 0;
 }
 #endif
--- a/jbig2_huffman.c
+++ b/jbig2_huffman.c
@@ -305,6 +305,7 @@
 int
 main (int argc, char **argv)
 {
+  Jbig2Ctx *ctx;
   Jbig2HuffmanTable *tables[5];
   Jbig2HuffmanState *hs;
   Jbig2WordStream ws;
@@ -311,13 +312,15 @@
   bool oob;
   int32_t code;
   
+  ctx = jbig2_ctx_new(NULL, 0, NULL, NULL, NULL);
+
   tables[0] = NULL;
-  tables[1] = jbig2_build_huffman_table (&jbig_huffman_params_A);
-  tables[2] = jbig2_build_huffman_table (&jbig_huffman_params_B);
+  tables[1] = jbig2_build_huffman_table (ctx, &jbig2_huffman_params_A);
+  tables[2] = jbig2_build_huffman_table (ctx, &jbig2_huffman_params_B);
   tables[3] = NULL;
-  tables[4] = jbig2_build_huffman_table (&jbig_huffman_params_D);
+  tables[4] = jbig2_build_huffman_table (ctx, &jbig2_huffman_params_D);
   ws.get_next_word = test_get_word;
-  hs = jbig2_huffman_new (&ws);
+  hs = jbig2_huffman_new (ctx, &ws);
 
   printf("testing jbig2 huffmann decoding...");
   printf("\t(should be 8 5 (oob) 8)\n");
@@ -334,6 +337,8 @@
   }
   
   printf("\n");
+
+  jbig2_ctx_free(ctx);
   
   return 0;
 }
--- a/jbig2_symbol_dict.c
+++ b/jbig2_symbol_dict.c
@@ -274,7 +274,7 @@
 
       /* 6.5.6 */
       if (params->SDHUFF) {
-	; /* todo */
+	  HCDH = jbig2_huffman_get(hs, params->SDHUFFDH, &code);
       } else {
 	  code = jbig2_arith_int_decode(IADH, as, &HCDH);
       }
@@ -314,7 +314,7 @@
 	    }
 	  /* 6.5.7 */
 	  if (params->SDHUFF) {
-	    ; /* todo */
+	      DW = jbig2_huffman_get(hs, params->SDHUFFDW, &code);
 	  } else {
 	      code = jbig2_arith_int_decode(IADW, as, &DW);
 	  }
@@ -327,8 +327,9 @@
 	  }
 	  SYMWIDTH = SYMWIDTH + DW;
 	  TOTWIDTH = TOTWIDTH + SYMWIDTH;
-        jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
-        "  decoded symbol %d width %d (total width now %d)", NSYMSDECODED, SYMWIDTH, TOTWIDTH); 
+	  jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
+		"decoded symbol %d width %d (total width now %d)", 
+		NSYMSDECODED, SYMWIDTH, TOTWIDTH); 
 	  if (SYMWIDTH < 0) {
 	      /* todo: mem cleanup */
               code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
@@ -370,7 +371,7 @@
                   uint32_t REFAGGNINST;
 
 		  if (params->SDHUFF) {
-		      /* todo */
+		      REFAGGNINST = jbig2_huffman_get(hs, params->SDHUFFAGGINST, &code);
 		  } else {
 		      code = jbig2_arith_int_decode(IAAI, as, (int32_t*)&REFAGGNINST);
 		  }
@@ -552,8 +553,6 @@
   params.SDHUFFAGGINST = NULL;
 
   if (params.SDHUFF) {
-    jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
-        "symbol dictionary uses the Huffman encoding variant (NYI)");
     switch ((flags & 0x000c) >> 2) {
       case 0: /* Table B.4 */
 	params.SDHUFFDH = jbig2_build_huffman_table(ctx,