rev 428 - trunk
[email protected] Tue, 16 Aug 2005 14:41:38 -0700 (PDT)
| Newsgroups | gmane.comp.printing.ghostscript.jbig2dec.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: giles
Date: 2005-08-16 14:41:38 -0700 (Tue, 16 Aug 2005)
New Revision: 428
Modified:
trunk/jbig2_symbol_dict.c
Log:
Copy out the collective bitmap symbols for huffman symbol dictionaries.
Also, some additional debug print pruning.
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-08-16 21:16:22 UTC (rev 427)
+++ trunk/jbig2_symbol_dict.c 2005-08-16 21:41:38 UTC (rev 428)
@@ -319,8 +319,6 @@
/* 6.5.7 */
if (params->SDHUFF) {
DW =3D jbig2_huffman_get(hs, params->SDHUFFDW, &code);
- jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
- "decoded symbol delta width %d", DW);
} else {
code =3D jbig2_arith_int_decode(IADW, as, &DW);
}
@@ -333,9 +331,6 @@
}
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)",=20
- NSYMSDECODED, SYMWIDTH, TOTWIDTH);=20
if (SYMWIDTH < 0) {
/* todo: mem cleanup */
code =3D jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->n=
umber,
@@ -344,12 +339,14 @@
}
#ifdef JBIG2_DEBUG
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
- "SYMWIDTH =3D %d", SYMWIDTH);
+ "SYMWIDTH =3D %d TOTWIDTH =3D %d", SYMWIDTH, TOTWIDTH);
#endif
/* 6.5.5 (4c.ii) */
if (!params->SDHUFF || params->SDREFAGG) {
+#ifdef JBIG2_DEBUG
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"SDHUFF =3D %d; SDREFAGG =3D %d", params->SDHUFF, params->SDREFAGG);
+#endif
/* 6.5.8 */
if (!params->SDREFAGG) {
Jbig2GenericRegionParams region_params;
@@ -464,12 +461,14 @@
SDNEWSYMWIDTHS[NSYMSDECODED] =3D SYMWIDTH;
}
=09
+ jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
+ "decoded symbol %d of %d (%dx%d)",
+ NSYMSDECODED, params->SDNUMNEWSYMS,
+ SYMWIDTH, HCHEIGHT);
+
/* 6.5.5 (4c.iv) */
NSYMSDECODED =3D NSYMSDECODED + 1;
=20
- jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
- "%d of %d decoded", NSYMSDECODED, params->SDNUMNEWSYMS);
-
} /* end height class decode loop */
=20
/* 6.5.5 (4d) */
@@ -477,13 +476,18 @@
/* 6.5.9 */
Jbig2Image *image;
int BMSIZE =3D jbig2_huffman_get(hs, params->SDHUFFBMSIZE, &code);
+ int j, x;
+
if (code || (BMSIZE < 0)) {
jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"error decoding size of collective bitmap!");
/* todo: memory cleanup */
return NULL;
}
+
+ /* skip any bits before the next byte boundary */
jbig2_huffman_skip(hs);
+
image =3D jbig2_image_new(ctx, TOTWIDTH, HCHEIGHT);
if (image =3D=3D NULL) {
jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
@@ -491,17 +495,19 @@
/* todo: memory cleanup */
return NULL;
}
+
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"reading %dx%d collective bitmap for %d symbols (%d bytes)",
image->width, image->height, NSYMSDECODED - HCFIRSTSYM,
BMSIZE);
+
if (BMSIZE =3D=3D 0) {
/* if BMSIZE =3D=3D 0 bitmap is uncompressed */
const byte *src =3D data + jbig2_huffman_offset(hs);
const int stride =3D (image->width >> 3) +=20
(image->width & 7) ? 1 : 0;
byte *dst =3D image->data;
- int j;
+
for (j =3D 0; j < image->height; j++) {
memcpy(dst, src, stride);
dst +=3D image->stride;
@@ -510,12 +516,32 @@
BMSIZE =3D image->height * stride;
} else {
Jbig2GenericRegionParams rparams;
+
rparams.MMR =3D 1;
code =3D jbig2_decode_generic_mmr(ctx, segment, &rparams,
data + jbig2_huffman_offset(hs), BMSIZE, image);
+ if (code) {
+ jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
+ "error decoding MMR bitmap image!");
+ /* todo: memory cleanup */
+ return NULL;
+ }
}
+
/* advance past the data we've just read */
jbig2_huffman_advance(hs, BMSIZE);
+
+ /* copy the collective bitmap into the symbol dictionary */
+ x =3D 0;
+ for (j =3D HCFIRSTSYM; j < NSYMSDECODED; j++) {
+ Jbig2Image *glyph;
+ glyph =3D jbig2_image_new(ctx, SDNEWSYMWIDTHS[j], HCHEIGHT);
+ jbig2_image_compose(ctx, glyph, image,=20
+ -x, 0, JBIG2_COMPOSE_REPLACE);
+ x +=3D SDNEWSYMWIDTHS[j];
+ SDNEWSYMS->glyphs[j] =3D glyph;=20
+ }
+ jbig2_image_release(ctx, image);
}
=20
} /* end of symbol decode loop */