rev 407 - trunk

[email protected] Mon, 23 May 2005 20:49:48 -0700 (PDT)
Newsgroups gmane.comp.printing.ghostscript.jbig2dec.cvs
Message-ID <[email protected]>
Author: giles
Date: 2005-05-23 20:49:47 -0700 (Mon, 23 May 2005)
New Revision: 407

Modified:
   trunk/Makefile.am
   trunk/jbig2_arith.c
   trunk/jbig2_huffman.c
   trunk/jbig2_symbol_dict.c
Log:
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 ca=
n
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.



Modified: trunk/Makefile.am
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/Makefile.am	2005-05-18 00:42:24 UTC (rev 406)
+++ trunk/Makefile.am	2005-05-24 03:49:47 UTC (rev 407)
@@ -37,9 +37,11 @@
 test_sha1_SOURCES =3D sha1.c sha1.h
 test_sha1_CFLAGS =3D -DTEST
=20
-test_arith_SOURCES =3D sha1.c sha1.h
+test_arith_SOURCES =3D jbig2_arith.c
 test_arith_CFLAGS =3D -DTEST
+test_arith_LDADD =3D libjbig2dec.a
=20
-test_huffman_SOURCES =3D sha1.c sha1.h
+test_huffman_SOURCES =3D jbig2_huffman.c
 test_huffman_CFLAGS =3D -DTEST
+test_huffman_LDADD =3D libjbig2dec.a
=20

Modified: trunk/jbig2_arith.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/jbig2_arith.c	2005-05-18 00:42:24 UTC (rev 406)
+++ trunk/jbig2_arith.c	2005-05-24 03:49:47 UTC (rev 407)
@@ -344,7 +344,7 @@
=20
 #ifdef TEST
=20
-static int32_t
+static uint32_t
 test_get_word (Jbig2WordStream *self, int offset)
 {
   byte stream[] =3D {
@@ -363,24 +363,35 @@
 int
 main (int argc, char **argv)
 {
+  Jbig2Ctx *ctx;
   Jbig2WordStream ws;
   Jbig2ArithState *as;
   int i;
   Jbig2ArithCx cx =3D 0;
=20
+  ctx =3D jbig2_ctx_new(NULL, 0, NULL, NULL, NULL);
+
   ws.get_next_word =3D test_get_word;
-  as =3D jbig2_arith_new (NULL, &ws);
+  as =3D jbig2_arith_new (ctx, &ws);
+#ifdef JBIG2_DEBUG
   jbig2_arith_trace (as, cx);
+#endif
=20
   for (i =3D 0; i < 256; i++)
     {
       bool D;
=20
       D =3D jbig2_arith_decode (as, &cx);
+#ifdef JBIG2_DEBUG
       printf ("%3d: D =3D %d, ", i, D);
       jbig2_arith_trace (as, cx);
-     =20
+#endif     =20
     }
+
+  jbig2_free(ctx->allocator, as);
+
+  jbig2_ctx_free(ctx);
+
   return 0;
 }
 #endif

Modified: trunk/jbig2_huffman.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/jbig2_huffman.c	2005-05-18 00:42:24 UTC (rev 406)
+++ trunk/jbig2_huffman.c	2005-05-24 03:49:47 UTC (rev 407)
@@ -305,19 +305,22 @@
 int
 main (int argc, char **argv)
 {
+  Jbig2Ctx *ctx;
   Jbig2HuffmanTable *tables[5];
   Jbig2HuffmanState *hs;
   Jbig2WordStream ws;
   bool oob;
   int32_t code;
  =20
+  ctx =3D jbig2_ctx_new(NULL, 0, NULL, NULL, NULL);
+
   tables[0] =3D NULL;
-  tables[1] =3D jbig2_build_huffman_table (&jbig_huffman_params_A);
-  tables[2] =3D jbig2_build_huffman_table (&jbig_huffman_params_B);
+  tables[1] =3D jbig2_build_huffman_table (ctx, &jbig2_huffman_params_A)=
;
+  tables[2] =3D jbig2_build_huffman_table (ctx, &jbig2_huffman_params_B)=
;
   tables[3] =3D NULL;
-  tables[4] =3D jbig2_build_huffman_table (&jbig_huffman_params_D);
+  tables[4] =3D jbig2_build_huffman_table (ctx, &jbig2_huffman_params_D)=
;
   ws.get_next_word =3D test_get_word;
-  hs =3D jbig2_huffman_new (&ws);
+  hs =3D jbig2_huffman_new (ctx, &ws);
=20
   printf("testing jbig2 huffmann decoding...");
   printf("\t(should be 8 5 (oob) 8)\n");
@@ -334,6 +337,8 @@
   }
  =20
   printf("\n");
+
+  jbig2_ctx_free(ctx);
  =20
   return 0;
 }

Modified: trunk/jbig2_symbol_dict.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/jbig2_symbol_dict.c	2005-05-18 00:42:24 UTC (rev 406)
+++ trunk/jbig2_symbol_dict.c	2005-05-24 03:49:47 UTC (rev 407)
@@ -274,7 +274,7 @@
=20
       /* 6.5.6 */
       if (params->SDHUFF) {
-	; /* todo */
+	  HCDH =3D jbig2_huffman_get(hs, params->SDHUFFDH, &code);
       } else {
 	  code =3D jbig2_arith_int_decode(IADH, as, &HCDH);
       }
@@ -314,7 +314,7 @@
 	    }
 	  /* 6.5.7 */
 	  if (params->SDHUFF) {
-	    ; /* todo */
+	      DW =3D jbig2_huffman_get(hs, params->SDHUFFDW, &code);
 	  } else {
 	      code =3D jbig2_arith_int_decode(IADW, as, &DW);
 	  }
@@ -327,8 +327,9 @@
 	  }
 	  SYMWIDTH =3D SYMWIDTH + DW;
 	  TOTWIDTH =3D TOTWIDTH + SYMWIDTH;
-        jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
-        "  decoded symbol %d width %d (total width now %d)", NSYMSDECODE=
D, SYMWIDTH, TOTWIDTH);=20
+	  jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
+		"decoded symbol %d width %d (total width now %d)",=20
+		NSYMSDECODED, SYMWIDTH, TOTWIDTH);=20
 	  if (SYMWIDTH < 0) {
 	      /* todo: mem cleanup */
               code =3D jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->n=
umber,
@@ -370,7 +371,7 @@
                   uint32_t REFAGGNINST;
=20
 		  if (params->SDHUFF) {
-		      /* todo */
+		      REFAGGNINST =3D jbig2_huffman_get(hs, params->SDHUFFAGGINST, &co=
de);
 		  } else {
 		      code =3D jbig2_arith_int_decode(IAAI, as, (int32_t*)&REFAGGNINST=
);
 		  }
@@ -552,8 +553,6 @@
   params.SDHUFFAGGINST =3D NULL;
=20
   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 =3D jbig2_build_huffman_table(ctx,=20