[jbig2-cvs] rev 407 - trunk
giles at ghostscript.com
giles at ghostscript.com
Mon May 23 20:49:48 PDT 2005
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 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.
Modified: trunk/Makefile.am
===================================================================
--- 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 = 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
Modified: trunk/jbig2_arith.c
===================================================================
--- 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 @@
#ifdef TEST
-static int32_t
+static uint32_t
test_get_word (Jbig2WordStream *self, int offset)
{
byte stream[] = {
@@ -363,24 +363,35 @@
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++)
{
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
Modified: trunk/jbig2_huffman.c
===================================================================
--- 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;
+ 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;
}
Modified: trunk/jbig2_symbol_dict.c
===================================================================
--- 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 @@
/* 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,
More information about the jbig2-cvs
mailing list