rev 416 - trunk
[email protected] Wed, 13 Jul 2005 09:51:14 -0700 (PDT)
| Newsgroups | gmane.comp.printing.ghostscript.jbig2dec.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: giles
Date: 2005-07-13 09:51:13 -0700 (Wed, 13 Jul 2005)
New Revision: 416
Modified:
trunk/jbig2_huffman.c
trunk/jbig2_huffman.h
trunk/jbig2_symbol_dict.c
Log:
Work-in-progress check in of huffman symbol dictionary support.
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-07-13 16:28:44 UTC (rev 415)
+++ trunk/jbig2_huffman.c 2005-07-13 16:51:13 UTC (rev 416)
@@ -84,7 +84,63 @@
return;
}
=20
+/** Skip bits up to the next byte boundary
+ */
+void
+jbig2_huffman_skip(Jbig2HuffmanState *hs)
+{
+ int bits =3D hs->offset_bits & 7;
+
+ if (bits) hs->offset_bits +=3D 8 - bits;
+
+ if (hs->offset_bits >=3D 32) {
+ Jbig2WordStream *ws =3D hs->ws;
+ hs->this_word =3D hs->next_word;
+ hs->offset +=3D 4;
+ hs->next_word =3D ws->get_next_word (ws, hs->offset + 4);
+ hs->offset_bits -=3D 32;
+ }
+}
+
+/* skip ahead a specified number of bytes in the word stream
+ */
+void jbig2_huffman_advance(Jbig2HuffmanState *hs, int offset)
+{
+ Jbig2WordStream *ws =3D hs->ws;
+
+ hs->offset +=3D offset;
+ hs->offset_bits =3D 0;
+ hs->this_word =3D ws->get_next_word (ws, hs->offset);
+ hs->next_word =3D ws->get_next_word (ws, hs->offset + 4);
+}
+
+/* return the offset of the huffman decode pointer (in bytes)
+ * from the beginning of the WordStream
+ */
+int=20
+jbig2_huffman_offset(Jbig2HuffmanState *hs)
+{
+ return hs->offset + (hs->offset_bits >> 4);
+}
+
+/* read a number of bits directly from the huffman state
+ * without decoding against a table
+ */
int32_t
+jbig2_huffman_get_bits (Jbig2HuffmanState *hs, const int bits)
+{
+ uint32_t this_word =3D hs->this_word;
+ int32_t result;
+=09
+ result =3D this_word >> (32 - bits);
+ hs->this_word =3D (this_word << bits) |
+ (hs->next_word >> (32 - bits));
+ hs->offset_bits +=3D bits;
+
+ return result;
+}
+
+int32_t
jbig2_huffman_get (Jbig2HuffmanState *hs,
const Jbig2HuffmanTable *table, bool *oob)
{
Modified: trunk/jbig2_huffman.h
=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.h 2005-07-13 16:28:44 UTC (rev 415)
+++ trunk/jbig2_huffman.h 2005-07-13 16:51:13 UTC (rev 416)
@@ -61,10 +61,21 @@
void
jbig2_huffman_free (Jbig2Ctx *ctx, Jbig2HuffmanState *hs);
=20
+void
+jbig2_huffman_skip(Jbig2HuffmanState *hs);
+
+void jbig2_huffman_advance(Jbig2HuffmanState *hs, int offset);
+
+int=20
+jbig2_huffman_offset(Jbig2HuffmanState *hs);
+
int32_t
jbig2_huffman_get (Jbig2HuffmanState *hs,
const Jbig2HuffmanTable *table, bool *oob);
=20
+int32_t
+jbig2_huffman_get_bits (Jbig2HuffmanState *hs, const int bits);
+
Jbig2HuffmanTable *
jbig2_build_huffman_table (Jbig2Ctx *ctx, const Jbig2HuffmanParams *para=
ms);
=20
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-07-13 16:28:44 UTC (rev 415)
+++ trunk/jbig2_symbol_dict.c 2005-07-13 16:51:13 UTC (rev 416)
@@ -33,6 +33,7 @@
#include "jbig2_arith_iaid.h"
#include "jbig2_huffman.h"
#include "jbig2_generic.h"
+#include "jbig2_mmr.h"
#include "jbig2_symbol_dict.h"
=20
#if defined(OUTPUT_PBM) || defined(DUMP_SYMDICT)
@@ -219,8 +220,10 @@
int32_t SYMWIDTH, TOTWIDTH;
uint32_t HCFIRSTSYM;
uint32_t *SDNEWSYMWIDTHS =3D NULL;
+ int SBSYMCODELEN =3D 0;
Jbig2WordStream *ws =3D NULL;
Jbig2HuffmanState *hs =3D NULL;
+ Jbig2HuffmanTable *SDHUFFRDX =3D NULL;
Jbig2ArithState *as =3D NULL;
Jbig2ArithIntCtx *IADH =3D NULL;
Jbig2ArithIntCtx *IADW =3D NULL;
@@ -245,7 +248,6 @@
IAAI =3D jbig2_arith_int_ctx_new(ctx);
if (params->SDREFAGG) {
int tmp =3D params->SDINSYMS->n_symbols + params->SDNUMNEWSYMS;
- int SBSYMCODELEN;
for (SBSYMCODELEN =3D 0; (1 << SBSYMCODELEN) < tmp; SBSYMCODELEN++);
IAID =3D jbig2_arith_iaid_ctx_new(ctx, SBSYMCODELEN);
IARDX =3D jbig2_arith_int_ctx_new(ctx);
@@ -255,6 +257,8 @@
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"huffman coded symbol dictionary");
hs =3D jbig2_huffman_new(ctx, ws);
+ SDHUFFRDX =3D jbig2_build_huffman_table(ctx,
+ &jbig2_huffman_params_O);
if (!params->SDREFAGG) {
SDNEWSYMWIDTHS =3D jbig2_alloc(ctx->allocator,
sizeof(*SDNEWSYMWIDTHS)*params->SDNUMNEWSYMS);
@@ -399,14 +403,15 @@
int ninsyms =3D params->SDINSYMS->n_symbols;
=20
if (params->SDHUFF) {
- /* todo */
+ ID =3D jbig2_huffman_get_bits(hs, SBSYMCODELEN);
+ RDX =3D jbig2_huffman_get(hs, SDHUFFRDX, &code);
+ RDY =3D jbig2_huffman_get(hs, SDHUFFRDX, &code);
} else {
code =3D jbig2_arith_iaid_decode(IAID, as, (int32_t*)&ID);
code =3D jbig2_arith_int_decode(IARDX, as, &RDX);
code =3D jbig2_arith_int_decode(IARDY, as, &RDY);
}
=20
-
if (ID >=3D ninsyms+NSYMSDECODED) {
code =3D jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"refinement references unknown symbol %d", ID);
@@ -465,17 +470,46 @@
"%d of %d decoded", NSYMSDECODED, params->SDNUMNEWSYMS);
#endif
=20
- /* 6.5.5 (4d) */
- if (params->SDHUFF && !params->SDREFAGG) {
- /* 6.5.9 */
- jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
- "unhandled collective bitmap");
- return NULL;
- }
+ jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
+ "at end of height class decode loop...");
+ } /* end height class decode loop */
=20
+ jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
+ "left height class decode loop");
+
+ /* 6.5.5 (4d) */
+ if (params->SDHUFF && !params->SDREFAGG) {
+ /* 6.5.9 */
+ Jbig2GenericRegionParams rparams;
+ Jbig2Image *image;
+ int BMSIZE =3D jbig2_huffman_get(hs, params->SDHUFFBMSIZE, &code);
+ if (code || (BMSIZE < 0)) {
+ jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
+ "error decoding size of collective bitmap!");
+ /* todo: memory cleanup */
+ return NULL;
}
- }
+ 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,
+ "could not allocate collective bitmap image!");
+ /* todo: memory cleanup */
+ return NULL;
+ }
+ /* todo: if BMSIZE =3D=3D 0 bitmap is uncompressed */
+ 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);
+ rparams.MMR =3D 1;
+ code =3D jbig2_decode_generic_mmr(ctx, segment, &rparams,
+ data + jbig2_huffman_offset(hs), BMSIZE, image);
+ jbig2_image_write_pbm_file(image, "collective.pbm");
+ jbig2_huffman_advance(hs, BMSIZE);
+ }
=20
+ } /* end of symbol decode loop */
+
jbig2_free(ctx->allocator, GB_stats);
=20
/* 6.5.10 */
@@ -524,6 +558,7 @@
if (params->SDREFAGG) {
jbig2_free(ctx->allocator, SDNEWSYMWIDTHS);
}
+ jbig2_release_huffman_table(ctx, SDHUFFRDX);
jbig2_free(ctx->allocator, hs);
}
=20