[jbig2-cvs] rev 289 - trunk
giles at ghostscript.com
giles at ghostscript.com
Tue Nov 11 05:51:17 PST 2003
Author: giles
Date: 2003-11-11 05:15:00 -0800 (Tue, 11 Nov 2003)
New Revision: 289
Modified:
trunk/jbig2_symbol_dict.c
trunk/jbig2_symbol_dict.h
trunk/jbig2_text.c
Log:
Make the symbol dict lookup code public and move it out of jbig2_text.c.
Modified: trunk/jbig2_symbol_dict.c
===================================================================
--- trunk/jbig2_symbol_dict.c 2003-11-10 20:54:09 UTC (rev 288)
+++ trunk/jbig2_symbol_dict.c 2003-11-11 13:15:00 UTC (rev 289)
@@ -211,6 +211,88 @@
return SDNEWSYMS;
}
+/* count the number of dictionary segments referred to by the given segment */
+int
+jbig2_sd_count_referred(Jbig2Ctx *ctx, Jbig2Segment *segment)
+{
+ int index;
+ Jbig2Segment *rsegment;
+ int n_dicts = 0;
+
+ for (index = 0; index < segment->referred_to_segment_count; index++) {
+ rsegment = jbig2_find_segment(ctx, segment->referred_to_segments[index]);
+ if (rsegment && ((rsegment->flags & 63) == 0)) {
+ n_dicts++;
+ n_dicts+= jbig2_sd_count_referred(ctx, rsegment);
+ }
+ }
+
+ return (n_dicts);
+}
+
+/* return an array of pointers to symbol dictionaries referred to by the given segment */
+Jbig2SymbolDict **
+jbig2_sd_list_referred(Jbig2Ctx *ctx, Jbig2Segment *segment)
+{
+ int index;
+ Jbig2Segment *rsegment;
+ Jbig2SymbolDict **dicts, **rdicts;
+ int n_dicts = jbig2_sd_count_referred(ctx, segment);
+ int dindex = 0;
+
+ dicts = jbig2_alloc(ctx->allocator, sizeof(Jbig2SymbolDict *) * n_dicts);
+ for (index = 0; index < segment->referred_to_segment_count; index++) {
+ rsegment = jbig2_find_segment(ctx, segment->referred_to_segments[index]);
+ if (rsegment && ((rsegment->flags & 63) == 0)) {
+ /* recurse for imported symbols */
+ int j, n_rdicts = jbig2_sd_count_referred(ctx, rsegment);
+ if (n_rdicts > 0) {
+ rdicts = jbig2_sd_list_referred(ctx, rsegment);
+ for (j = 0; j < n_rdicts; j++)
+ dicts[dindex++] = rdicts[j];
+ jbig2_free(ctx->allocator, rdicts);
+ }
+ /* add this referred to symbol dictionary */
+ dicts[dindex++] = (Jbig2SymbolDict *)rsegment->result;
+ }
+ }
+
+ if (dindex != n_dicts) {
+ /* should never happen */
+ jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
+ "counted %d symbol dictionaries but build a list with %d.\n",
+ n_dicts, dindex);
+ }
+
+ return (dicts);
+}
+
+/* generate a new symbol dictionary by concatenating a list of
+ existing dictionaries */
+Jbig2SymbolDict *
+jbig2_sd_cat(Jbig2Ctx *ctx, int n_dicts, Jbig2SymbolDict **dicts)
+{
+ int i,j,k, symbols;
+ Jbig2SymbolDict *new = NULL;
+
+ new = (Jbig2SymbolDict *)jbig2_alloc(ctx->allocator, sizeof(Jbig2SymbolDict));
+
+ if (new != NULL) {
+ /* count the imported symbols and allocate a new array */
+ symbols = 0;
+ for(i = 0; i < n_dicts; i++)
+ symbols += dicts[i]->n_symbols;
+ new->glyphs = (Jbig2Image **)jbig2_alloc(ctx->allocator, symbols);
+ /* fill the new array with cloned glyph pointers */
+ k = 0;
+ for (i = 0; i < n_dicts; i++)
+ for (j = 0; j < dicts[i]->n_symbols; j++)
+ new->glyphs[k++] = jbig2_image_clone(ctx, dicts[i]->glyphs[j]);
+ }
+
+ return new;
+}
+
/* 7.4.2 */
int
jbig2_symbol_dictionary(Jbig2Ctx *ctx, Jbig2Segment *segment,
@@ -221,6 +303,7 @@
int sdat_bytes;
int offset;
Jbig2ArithCx *GB_stats = NULL;
+ Jbig2SymbolDict *SDNEWSYMS;
if (segment->data_length < 10)
goto too_short;
@@ -299,15 +382,18 @@
"segment marks bitmap coding context as retained (NYI)");
}
- segment->result = (void *)jbig2_decode_symbol_dict(ctx, segment,
+ SDNEWSYMS = jbig2_decode_symbol_dict(ctx, segment,
¶ms,
segment_data + offset,
segment->data_length - offset,
GB_stats);
#ifdef DUMP_SYMDICT
- if (segment->result) jbig2_dump_symbol_dict(segment->result);
+ if (segment->result) jbig2_dump_symbol_dict(SDNEWSYMS);
#endif
+ /* FIXME: assume for now everything is exported */
+ segment->result = (void *)SDNEWSYMS;
+
return (segment->result != NULL) ? 0 : -1;
/* todo: retain or free GB_stats */
Modified: trunk/jbig2_symbol_dict.h
===================================================================
--- trunk/jbig2_symbol_dict.h 2003-11-10 20:54:09 UTC (rev 288)
+++ trunk/jbig2_symbol_dict.h 2003-11-11 13:15:00 UTC (rev 289)
@@ -13,7 +13,7 @@
Artifex Software, Inc., 101 Lucas Valley Road #110,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
- $Id: jbig2_symbol_dict.h,v 1.4 2002/06/22 21:20:38 giles Exp $
+ $Id$
symbol dictionary header
*/
@@ -28,3 +28,20 @@
int
jbig2_symbol_dictionary(Jbig2Ctx *ctx, Jbig2Segment *segment,
const byte *segment_data);
+
+/* generate a new symbol dictionary by concatenating a list of
+ existing dictionaries */
+Jbig2SymbolDict *
+jbig2_sd_cat(Jbig2Ctx *ctx, int n_dicts,
+ Jbig2SymbolDict **dicts);
+
+/* count the number of dictionary segments referred
+ to by the given segment */
+int
+jbig2_sd_count_referred(Jbig2Ctx *ctx, Jbig2Segment *segment);
+
+/* return an array of pointers to symbol dictionaries referred
+ to by a segment */
+Jbig2SymbolDict **
+jbig2_sd_list_referred(Jbig2Ctx *ctx, Jbig2Segment *segment);
+
Modified: trunk/jbig2_text.c
===================================================================
--- trunk/jbig2_text.c 2003-11-10 20:54:09 UTC (rev 288)
+++ trunk/jbig2_text.c 2003-11-11 13:15:00 UTC (rev 289)
@@ -279,62 +279,6 @@
return 0;
}
-/* count the number of dictionary segments referred to by the given segment */
-static int
-count_referred_dicts(Jbig2Ctx *ctx, Jbig2Segment *segment)
-{
- int index;
- Jbig2Segment *rsegment;
- int n_dicts = 0;
-
- for (index = 0; index < segment->referred_to_segment_count; index++) {
- rsegment = jbig2_find_segment(ctx, segment->referred_to_segments[index]);
- if (rsegment && ((rsegment->flags & 63) == 0)) {
- n_dicts++;
- n_dicts+= count_referred_dicts(ctx, rsegment);
- }
- }
-
- return (n_dicts);
-}
-
-/* return an array of pointers to symbol dictionaries referred to by the given segment */
-static Jbig2SymbolDict **
-list_referred_dicts(Jbig2Ctx *ctx, Jbig2Segment *segment)
-{
- int index;
- Jbig2Segment *rsegment;
- Jbig2SymbolDict **dicts, **rdicts;
- int n_dicts = count_referred_dicts(ctx, segment);
- int dindex = 0;
-
- dicts = jbig2_alloc(ctx->allocator, sizeof(Jbig2SymbolDict *) * n_dicts);
- for (index = 0; index < segment->referred_to_segment_count; index++) {
- rsegment = jbig2_find_segment(ctx, segment->referred_to_segments[index]);
- if (rsegment && ((rsegment->flags & 63) == 0)) {
- /* recurse for imported symbols */
- int j, n_rdicts = count_referred_dicts(ctx, rsegment);
- if (n_rdicts > 0) {
- rdicts = list_referred_dicts(ctx, rsegment);
- for (j = 0; j < n_rdicts; j++)
- dicts[dindex++] = rdicts[j];
- jbig2_free(ctx->allocator, rdicts);
- }
- /* add this referred to symbol dictionary */
- dicts[dindex++] = (Jbig2SymbolDict *)rsegment->result;
- }
- }
-
- if (dindex != n_dicts) {
- /* should never happen */
- jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
- "counted %d symbol dictionaries but build a list with %d.\n",
- n_dicts, dindex);
- }
-
- return (dicts);
-}
-
/**
* jbig2_read_text_info: read a text region segment header
**/
@@ -427,9 +371,9 @@
}
/* compose the list of symbol dictionaries */
- n_dicts = count_referred_dicts(ctx, segment);
+ n_dicts = jbig2_sd_count_referred(ctx, segment);
if (n_dicts != 0) {
- dicts = list_referred_dicts(ctx, segment);
+ dicts = jbig2_sd_list_referred(ctx, segment);
} else {
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"text region refers to no symbol dictionaries!");
More information about the jbig2-cvs
mailing list