shithub: jbig2

Download patch

ref: 41b78a49bf9e00d0d78532581b7e72836935f3d5
parent: 4cec0516180e0a8a79e88de5fbb12a28b3f64439
author: giles <giles@ded80894-8fb9-0310-811b-c03f3676ab4d>
date: Mon Feb 5 18:42:18 EST 2007

Export jbig2_decode_text_region() for use in aggregate symbol encoding 
and stub out the setup for the call. Work in progress implementing 
support for this function.


git-svn-id: http://svn.ghostscript.com/jbig2dec/trunk@453 ded80894-8fb9-0310-811b-c03f3676ab4d

--- a/jbig2_refinement.c
+++ b/jbig2_refinement.c
@@ -91,7 +91,7 @@
       jbig2_image_set_pixel(image, x, y, bit);
     }
   }
-#ifdef JBIG2_DEBUG
+#ifdef JBIG2_DEBUG_REFINEMENT
   {
     static count = 0;
     char name[32];
@@ -266,6 +266,10 @@
 			    Jbig2ArithCx *GR_stats)
 {
   {
+    jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
+      "decoding generic refinement region with offset %d,%x,\n"
+      "  GRTEMPLATE=%d, TPGRON=%d\n",
+      params->DX, params->DY, params->GRTEMPLATE, params->TPGRON);
     jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
       "decoding generic refinement region with offset %d,%x,\n"
       "  GRTEMPLATE=%d, TPGRON=%d, RA1=(%d,%d) RA2=(%d,%d)\n",
--- a/jbig2_symbol_dict.c
+++ b/jbig2_symbol_dict.c
@@ -35,6 +35,7 @@
 #include "jbig2_generic.h"
 #include "jbig2_mmr.h"
 #include "jbig2_symbol_dict.h"
+#include "jbig2_text.h"
 
 #if defined(OUTPUT_PBM) || defined(DUMP_SYMDICT)
 #include <stdio.h>
@@ -391,10 +392,68 @@
 		    "aggregate symbol coding (%d instances)", REFAGGNINST);
 
 		  if (REFAGGNINST > 1) {
-		      code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
-			"aggregate coding with REFAGGNINST=%d", REFAGGNINST);
+		      /* multiple symbols are embedded text regions */ 
+		      Jbig2TextRegionParams rparams;
+		      Jbig2SymbolDict *SBSYMS[2];
+		      Jbig2Image *image;
+
+		      rparams.SBHUFF = params->SDHUFF;
+		      rparams.SBREFINE = 1;
+		      rparams.SBDEFPIXEL = 0;
+		      rparams.SBCOMBOP = JBIG2_COMPOSE_OR;
+		      rparams.TRANSPOSED = 0;
+		      rparams.REFCORNER = JBIG2_CORNER_TOPLEFT;
+		      rparams.SBDSOFFSET = 0;
+		      rparams.SBNUMINSTANCES = REFAGGNINST;
+		      rparams.LOGSBSTRIPS = 0;
+		      rparams.SBSTRIPS = 1;
+		      if (rparams.SBHUFF) {
+			rparams.SBHUFFFS = jbig2_build_huffman_table(ctx,
+				&jbig2_huffman_params_F);
+			rparams.SBHUFFDS = jbig2_build_huffman_table(ctx,
+				&jbig2_huffman_params_H);
+			rparams.SBHUFFDT = jbig2_build_huffman_table(ctx,
+				&jbig2_huffman_params_K);
+			rparams.SBHUFFRDW = jbig2_build_huffman_table(ctx,
+				&jbig2_huffman_params_O);
+			rparams.SBHUFFRDH = jbig2_build_huffman_table(ctx,
+				&jbig2_huffman_params_O);
+			rparams.SBHUFFRDX = jbig2_build_huffman_table(ctx,
+				&jbig2_huffman_params_O);
+			rparams.SBHUFFRDY = jbig2_build_huffman_table(ctx,
+				&jbig2_huffman_params_O);
+			rparams.SBHUFFRSIZE = jbig2_build_huffman_table(ctx,
+				&jbig2_huffman_params_A);
+		      }
+		      rparams.SBRTEMPLATE = params->SDRTEMPLATE;
+		      rparams.sbrat[0] = params->sdrat[0];
+		      rparams.sbrat[1] = params->sdrat[1];
+		      rparams.sbrat[2] = params->sdrat[2];
+		      rparams.sbrat[3] = params->sdrat[3];
+
+		      SBSYMS[0] = params->SDINSYMS;
+		      SBSYMS[1] = SDNEWSYMS;
+		      image = jbig2_image_new(ctx, SYMWIDTH, HCHEIGHT);
+		      code = jbig2_decode_text_region(ctx, segment, &rparams,
+			(const Jbig2SymbolDict * const *)SBSYMS, 2, 
+			image, data, size, NULL);
+		      jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
+			"text region decode returned %d", code);
+
+		      if (rparams.SBHUFF) {
+			jbig2_release_huffman_table(ctx, rparams.SBHUFFFS);
+			jbig2_release_huffman_table(ctx, rparams.SBHUFFDS);
+			jbig2_release_huffman_table(ctx, rparams.SBHUFFDT);
+			jbig2_release_huffman_table(ctx, rparams.SBHUFFRDW);
+			jbig2_release_huffman_table(ctx, rparams.SBHUFFRDH);
+			jbig2_release_huffman_table(ctx, rparams.SBHUFFRDX);
+			jbig2_release_huffman_table(ctx, rparams.SBHUFFRDY);
+			jbig2_release_huffman_table(ctx, rparams.SBHUFFRSIZE);	
+		      }
+		
+		      code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
+			"NYI aggregate coding with REFAGGNINST=%d", REFAGGNINST);
 		      return NULL;
-		      /* todo: multiple symbols are like a text region */
 		  } else {
 		      /* 6.5.8.2.2 */
 		      bool SBHUFF = params->SDHUFF;
--- a/jbig2_text.c
+++ b/jbig2_text.c
@@ -1,7 +1,7 @@
 /*
     jbig2dec
     
-    Copyright (C) 2002-2005 artofcode LLC.
+    Copyright (C) 2002-2006 artofcode LLC.
     
     This software is distributed under license and may not
     be copied, modified or distributed except as expressly
@@ -32,44 +32,8 @@
 #include "jbig2_huffman.h"
 #include "jbig2_generic.h"
 #include "jbig2_symbol_dict.h"
+#include "jbig2_text.h"
 
-typedef enum {
-    JBIG2_CORNER_BOTTOMLEFT = 0,
-    JBIG2_CORNER_TOPLEFT = 1,
-    JBIG2_CORNER_BOTTOMRIGHT = 2,
-    JBIG2_CORNER_TOPRIGHT = 3
-} Jbig2RefCorner;
-
-typedef struct {
-    bool SBHUFF;
-    bool SBREFINE;
-    bool SBDEFPIXEL;
-    Jbig2ComposeOp SBCOMBOP;
-    bool TRANSPOSED;
-    Jbig2RefCorner REFCORNER;
-    int SBDSOFFSET;
-    /* SBW */
-    /* SBH */
-    uint32_t SBNUMINSTANCES;
-    int LOGSBSTRIPS;
-    int SBSTRIPS;
-    /* SBNUMSYMS */
-    /* SBSYMCODES */
-    /* SBSYMCODELEN */
-    /* SBSYMS */
-    Jbig2HuffmanTable *SBHUFFFS;
-    Jbig2HuffmanTable *SBHUFFDS;
-    Jbig2HuffmanTable *SBHUFFDT;
-    Jbig2HuffmanTable *SBHUFFRDW;
-    Jbig2HuffmanTable *SBHUFFRDH;
-    Jbig2HuffmanTable *SBHUFFRDX;
-    Jbig2HuffmanTable *SBHUFFRDY;
-    Jbig2HuffmanTable *SBHUFFRSIZE;
-    bool SBRTEMPLATE;
-    int8_t sbrat[4];
-} Jbig2TextRegionParams;
-
-
 /**
  * jbig2_decode_text_region: decode a text region segment
  *
@@ -87,7 +51,7 @@
  *
  * returns: 0 on success
  **/
-static int
+int
 jbig2_decode_text_region(Jbig2Ctx *ctx, Jbig2Segment *segment,
                              const Jbig2TextRegionParams *params,
                              const Jbig2SymbolDict * const *dicts, const int n_dicts,