[jbig2-cvs] rev 432 - trunk
giles at ghostscript.com
giles at ghostscript.com
Mon Dec 5 16:02:26 PST 2005
Author: giles
Date: 2005-08-25 01:14:21 -0700 (Thu, 25 Aug 2005)
New Revision: 432
Modified:
trunk/jbig2_huffman.c
trunk/jbig2_text.c
Log:
Work-in-progress commit of huffman text region support. Fix a number
of bugs in jbig2_huffman_get_bits() and implement symbol id huffman
table decode (a custom table is always included inline in the text
region segment header.)
However, the constructed table gives an out-of-bounds symbol id on
the first read with the UBC test file.
Modified: trunk/jbig2_huffman.c
===================================================================
--- trunk/jbig2_huffman.c 2005-08-23 06:09:55 UTC (rev 431)
+++ trunk/jbig2_huffman.c 2005-08-25 08:14:21 UTC (rev 432)
@@ -90,6 +90,7 @@
/** debug routines **/
#ifdef JBIG2_DEBUG
+#include <stdio.h>
/** print current huffman state */
void jbig2_dump_huffman_state(Jbig2HuffmanState *hs)
{
@@ -175,9 +176,18 @@
int32_t result;
result = this_word >> (32 - bits);
- hs->this_word = (this_word << bits) |
- (hs->next_word >> (32 - bits));
hs->offset_bits += bits;
+ if (hs->offset_bits >= 32) {
+ hs->offset += 4;
+ hs->offset_bits -= 32;
+ hs->this_word = hs->next_word;
+ hs->next_word = hs->ws->get_next_word(hs->ws, hs->offset + 4);
+ hs->this_word = (hs->this_word << hs->offset_bits) |
+ (hs->next_word >> (32 - hs->offset_bits));
+ } else {
+ hs->this_word = (this_word << bits) |
+ (hs->next_word >> (32 - hs->offset_bits));
+ }
return result;
}
Modified: trunk/jbig2_text.c
===================================================================
--- trunk/jbig2_text.c 2005-08-23 06:09:55 UTC (rev 431)
+++ trunk/jbig2_text.c 2005-08-25 08:14:21 UTC (rev 432)
@@ -157,7 +157,7 @@
Jbig2HuffmanLine runcodelengths[35];
Jbig2HuffmanLine *symcodelengths;
Jbig2HuffmanParams symcodeparams;
- int code, err, range, r;
+ int code, err, len, range, r;
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"huffman coded text region");
@@ -173,7 +173,7 @@
runcodelengths[index].RANGELEN = 0;
runcodelengths[index].RANGELOW = index;
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
- " read runcode%d length %d", index, runcodelengths[index]);
+ " read runcode%d length %d", index, runcodelengths[index].PREFLEN);
}
runcodeparams.HTOOB = 0;
runcodeparams.lines = runcodelengths;
@@ -193,20 +193,34 @@
"memory allocation failure reading symbol ID huffman table!");
return -1;
}
- for (index = 0; index < SBNUMSYMS; index++) {
+ index = 0;
+ while (index < SBNUMSYMS) {
code = jbig2_huffman_get(hs, runcodes, &err);
if (err != 0 || code < 0 || code >= 35) {
jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"error reading symbol ID huffman table!");
- return err;
+ return err ? err : -1;
}
- if (code < 32) range = 0;
- else if (code == 32) range = jbig2_huffman_get_bits(hs, 2);
- else if (code == 34) range = jbig2_huffman_get_bits(hs, 3);
- else if (code == 35) range = jbig2_huffman_get_bits(hs, 7);
- for (r = 0; r < range + 1; r++) {
- symcodelengths[index+r].PREFLEN = code;
+ if (code < 32) {
+ len = code;
+ range = 1;
+ } else {
+ if (index < 1) {
+ jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
+ "error decoding symbol id table: run length with no antecedent!");
+ /* todo: memory cleanup */
+ return -1;
+ }
+ len = symcodelengths[index-1].PREFLEN;
+ if (code == 32) range = jbig2_huffman_get_bits(hs, 2) + 3;
+ else if (code == 33) range = jbig2_huffman_get_bits(hs, 3) + 3;
+ else if (code == 34) range = jbig2_huffman_get_bits(hs, 7) + 11;
+ }
+ jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
+ " read runcode%d at index %d (length %d range %d)", code, index, len, range);
+ for (r = 0; r < range; r++) {
+ symcodelengths[index+r].PREFLEN = len;
symcodelengths[index+r].RANGELEN = 0;
symcodelengths[index+r].RANGELOW = index;
}
More information about the jbig2-cvs
mailing list