jbig2dec
Ralph Giles <[email protected]> Sat, 22 Jun 2002 14:20:40 -0700
| Newsgroups | gmane.comp.printing.ghostscript.jbig2dec.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/jbig2dec/jbig2dec
In directory usw-pr-cvs1:/tmp/cvs-serv14965
Modified Files:
jbig2_symbol_dict.c jbig2_symbol_dict.h
Log Message:
Store the decoded symbol dictionary in the result field of the corresponding
segment.
Index: jbig2_symbol_dict.c
===================================================================
RCS file: /cvsroot/jbig2dec/jbig2dec/jbig2_symbol_dict.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- jbig2_symbol_dict.c 22 Jun 2002 16:05:45 -0000 1.10
+++ jbig2_symbol_dict.c 22 Jun 2002 21:20:38 -0000 1.11
@@ -9,11 +9,14 @@
(at your option) any later version.
$Id$
+
+ symbol dictionary segment decode and support
*/
#include <stddef.h>
#include <stdint.h>
+#include "config.h"
#include "jbig2.h"
#include "jbig2_priv.h"
#include "jbig2_arith.h"
@@ -21,7 +24,7 @@
#include "jbig2_generic.h"
#include "jbig2_symbol_dict.h"
-#ifdef OUTPUT_PBM
+#if OUTPUT_PBM || HAVE_LIBPNG
#include <stdio.h>
#include "jbig2_image.h"
#endif
@@ -45,14 +48,30 @@
int8_t sdrat[4];
} Jbig2SymbolDictParams;
+#ifdef HAVE_LIBPNG
+void
+jbig2_dump_symbol_dict(Jbig2SymbolDict *dict)
+{
+ int index;
+ char filename[24];
+
+ fprintf(stderr, "dumping symbol dict as %d individual png files\n", dict->n_symbols);
+ for (index = 0; index < dict->n_symbols; index++) {
+ snprintf(filename, sizeof(filename), "symbol_%04d.png", index);
+ jbig2_image_write_png_file(dict->glyphs[index], filename);
+ }
+}
+#endif /* HAVE_LIBPNG */
+
/* 6.5 */
-int
+Jbig2SymbolDict *
jbig2_decode_symbol_dict(Jbig2Ctx *ctx,
Jbig2Segment *segment,
const Jbig2SymbolDictParams *params,
const byte *data, size_t size,
Jbig2ArithCx *GB_stats)
{
+ Jbig2SymbolDict *SDNEWSYMS;
int32_t HCHEIGHT;
uint32_t NSYMSDECODED;
int32_t SYMWIDTH, TOTWIDTH;
@@ -74,6 +93,10 @@
IADW = jbig2_arith_int_ctx_new(ctx);
}
+ SDNEWSYMS = jbig2_alloc(ctx->allocator, params->SDNUMNEWSYMS * sizeof(*SDNEWSYMS));
+ SDNEWSYMS->n_symbols = params->SDNUMNEWSYMS;
+ SDNEWSYMS->glyphs = (Jbig2Image **)jbig2_alloc(ctx->allocator, SDNEWSYMS->n_symbols * sizeof(Jbig2Image*));
+
/* 6.5.5 (4a) */
while (NSYMSDECODED < params->SDNUMNEWSYMS)
{
@@ -94,9 +117,12 @@
HCFIRSTSYM = NSYMSDECODED;
if (HCHEIGHT < 0)
- /* todo: mem cleanup */
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
+ {
+ /* todo: mem cleanup */
+ code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"Invalid HCHEIGHT value");
+ return NULL;
+ }
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"HCHEIGHT = %d", HCHEIGHT);
@@ -117,9 +143,12 @@
SYMWIDTH = SYMWIDTH + DW;
TOTWIDTH = TOTWIDTH + SYMWIDTH;
if (SYMWIDTH < 0)
- /* todo: mem cleanup */
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
- "Invalid SYMWIDTH value");
+ {
+ /* todo: mem cleanup */
+ code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
+ "Invalid SYMWIDTH value");
+ return NULL;
+ }
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"SYMWIDTH = %d", SYMWIDTH);
@@ -143,12 +172,12 @@
image = jbig2_image_new(ctx, SYMWIDTH, HCHEIGHT);
- code = jbig2_decode_generic_region(ctx, segment,
- ®ion_params,
- as,
- image, GB_stats);
+ code = jbig2_decode_generic_region(ctx, segment, ®ion_params,
+ as, image, GB_stats);
/* todo: handle errors */
- /* todo: stash image in SDNEWSYMS */
+
+ SDNEWSYMS->glyphs[NSYMSDECODED] = image;
+
#ifdef OUTPUT_PBM
jbig2_image_write_pbm(image, stdout);
#endif
@@ -164,7 +193,7 @@
jbig2_free(ctx->allocator, GB_stats);
- return 0;
+ return SDNEWSYMS;
}
/* 7.4.2 */
@@ -255,11 +284,16 @@
"segment marks bitmap coding context as retained (NYI)");
}
- return jbig2_decode_symbol_dict(ctx, segment,
+ segment->result = (void *)jbig2_decode_symbol_dict(ctx, segment,
¶ms,
segment_data + offset,
segment->data_length - offset,
GB_stats);
+#ifdef HAVE_LIBPNG
+ jbig2_dump_symbol_dict(segment->result);
+#endif
+
+ return 0;
/* todo: retain or free GB_stats */
Index: jbig2_symbol_dict.h
===================================================================
RCS file: /cvsroot/jbig2dec/jbig2dec/jbig2_symbol_dict.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- jbig2_symbol_dict.h 22 Jun 2002 16:05:45 -0000 1.3
+++ jbig2_symbol_dict.h 22 Jun 2002 21:20:38 -0000 1.4
@@ -9,8 +9,17 @@
(at your option) any later version.
$Id$
-*/
+ symbol dictionary header
+ */
+
+/* the results of decoding a symbol dictionary */
+typedef struct {
+ int n_symbols;
+ Jbig2Image **glyphs;
+} Jbig2SymbolDict;
+
+/* decode a symbol dictionary segment and store the results */
int
jbig2_symbol_dictionary(Jbig2Ctx *ctx, Jbig2Segment *segment,
const byte *segment_data);