ref: 0c8fe23adba1f24273186b4a7379f588437d9f5d
parent: ef32d14a8d786981905bed84313d250d39b6dead
author: giles <giles@ded80894-8fb9-0310-811b-c03f3676ab4d>
date: Wed Sep 29 10:15:40 EDT 2004
Work in progress of refinement region support. Call logic for refagg symbol dictionary entries. git-svn-id: http://svn.ghostscript.com/jbig2dec/trunk@323 ded80894-8fb9-0310-811b-c03f3676ab4d
--- a/Makefile.am
+++ b/Makefile.am
@@ -2,7 +2,7 @@
## process this file with automake to generate Makefile.in
# require automake 1.7
-AUTOMAKE_OPTIONS = foreign 1.7 dist-bzip2 dist-zip
+AUTOMAKE_OPTIONS = foreign 1.7 dist-bzip2 dist-zip -Wall
lib_LIBRARIES = libjbig2dec.a
include_HEADERS = jbig2.h
@@ -11,7 +11,7 @@
jbig2_arith.c jbig2_arith_int.c jbig2_arith_iaid.c jbig2_huffman.c \
jbig2_segment.c jbig2_page.c \
jbig2_symbol_dict.c jbig2_text.c \
- jbig2_generic.c jbig2_mmr.c \
+ jbig2_generic.c jbig2_refinement.c jbig2_mmr.c \
jbig2_image.c jbig2_image_pbm.c \
os_types.h config_types.h config_win32.h \
jbig2.h jbig2_priv.h jbig2_image.h \
--- a/jbig2_refinement.c
+++ b/jbig2_refinement.c
@@ -1,7 +1,7 @@
/*
jbig2dec
- Copyright (c) 2002-2004 artofcode LLC.
+ Copyright (c) 2004 artofcode LLC.
This software is provided AS-IS with no warranty,
either express or implied.
@@ -16,7 +16,7 @@
Artifex Software, Inc., 101 Lucas Valley Road #110,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
- $Id: jbig2_refinement.c 318 2004-08-13 00:00:17Z giles $
+ $Id$
*/
/**
@@ -41,6 +41,31 @@
#include "jbig2_generic.h"
#include "jbig2_mmr.h"
+static int
+jbig2_decode_refinement_template0(Jbig2Ctx *ctx,
+ Jbig2Segment *segment,
+ const Jbig2RefinementRegionParams *params,
+ Jbig2ArithState *as,
+ Jbig2Image *image,
+ Jbig2ArithCx *GB_stats)
+{
+ return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
+ "refinement region template 0 NYI");
+}
+
+static int
+jbig2_decode_refinement_template1(Jbig2Ctx *ctx,
+ Jbig2Segment *segment,
+ const Jbig2RefinementRegionParams *params,
+ Jbig2ArithState *as,
+ Jbig2Image *image,
+ Jbig2ArithCx *GB_stats)
+{
+ return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
+ "refinement region template 1 NYI");
+}
+
+
/**
* jbig2_decode_refinement_region: Decode a generic refinement region.
* @ctx: The context for allocation and error reporting.
@@ -47,11 +72,11 @@
* @segment: A segment reference for error reporting.
* @params: Decoding parameter set.
* @as: Arithmetic decoder state.
- * @image: Where to store the decoded data.
+ * @image: Where to store the decoded image.
* @GB_stats: Arithmetic stats.
*
- * Decodes a generic region, according to section 6.2. The caller should
- * pass an already allocated Jbig2Image object for @image
+ * Decodes a generic refinement region, according to section 6.3.
+ * an already allocated Jbig2Image object in @image for the result.
*
* Because this API is based on an arithmetic decoding state, it is
* not suitable for MMR decoding.
@@ -66,5 +91,21 @@
Jbig2Image *image,
Jbig2ArithCx *GB_stats)
{
-
+ {
+ jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
+ "decoding generic refinement region with offset %dx%x,\n"
+ " GRTEMPLATE=%d, TPGDON=%d, RA1=(%d,%d) RA2=(%d,%d)\n",
+ params->DX, params->DY, params->GRTEMPLATE, params->TPGDON,
+ params->grat[0], params->grat[1], params->grat[2], params->grat[3]);
+ }
+ if (params->TPGDON)
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
+ "decode_refinement_region: typical prediction coding NYI");
+ if (params->GRTEMPLATE)
+ return jbig2_decode_refinement_template1(ctx, segment, params,
+ as, image, GB_stats);
+ else
+ return jbig2_decode_refinement_template0(ctx, segment, params,
+ as, image, GB_stats);
}
+
--- a/jbig2_symbol_dict.c
+++ b/jbig2_symbol_dict.c
@@ -1,7 +1,7 @@
/*
jbig2dec
- Copyright (C) 2001-2003 artofcode LLC.
+ Copyright (C) 2001-2004 artofcode LLC.
This software is distributed under license and may not
be copied, modified or distributed except as expressly
@@ -364,8 +364,11 @@
} else {
/* 6.5.8.2.2 */
bool SBHUFF = params->SDHUFF;
+ Jbig2RefinementRegionParams rparams;
+ Jbig2Image *image;
uint32_t ID;
int32_t RDX, RDY;
+ int ninsyms = params->SDINSYMS->n_symbols;
if (params->SDHUFF) {
/* todo */
@@ -378,6 +381,22 @@
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"symbol is a refinement of id %d with the refinement applied at (%d,%d)",
ID, RDX, RDY);
+
+ image = jbig2_image_new(ctx, SYMWIDTH, HCHEIGHT);
+
+ /* Table 18 */
+ rparams.GRTEMPLATE = params->SDRTEMPLATE;
+ rparams.reference = (ninsyms > ID) ?
+ params->SDINSYMS->glyphs[ID] :
+ SDNEWSYMS->glyphs[ID-ninsyms];
+ rparams.DX = RDX;
+ rparams.DY = RDY;
+ rparams.TPGDON = 0;
+ memcpy(rparams.grat, params->sdrat, 4);
+ jbig2_decode_refinement_region(ctx, segment,
+ &rparams, as, image, GB_stats);
+
+ SDNEWSYMS->glyphs[NSYMSDECODED] = image;
}
}