[gs-cvs] rev 7456 - in trunk/gs/jasper/src/libjasper: jp2 jpc

giles at ghostscript.com giles at ghostscript.com
Wed Dec 6 14:25:01 PST 2006


Author: giles
Date: 2006-12-06 14:25:01 -0800 (Wed, 06 Dec 2006)
New Revision: 7456

Modified:
   trunk/gs/jasper/src/libjasper/jp2/jp2_dec.c
   trunk/gs/jasper/src/libjasper/jpc/jpc_dec.c
Log:
Add a 'raw' option key to jp2_decode() to pass the raw palette
data back to the client without applying the included palette
for indexed images or otherwise remapping the data. Required
for Colorspace override when embedded in PDF documents.
Partial fix for bug 688869.


Modified: trunk/gs/jasper/src/libjasper/jp2/jp2_dec.c
===================================================================
--- trunk/gs/jasper/src/libjasper/jp2/jp2_dec.c	2006-12-06 22:23:19 UTC (rev 7455)
+++ trunk/gs/jasper/src/libjasper/jp2/jp2_dec.c	2006-12-06 22:25:01 UTC (rev 7456)
@@ -64,7 +64,7 @@
 /*
  * JP2 Library
  *
- * $Id$
+ * $Id: $
  */
 
 /******************************************************************************\
@@ -74,6 +74,7 @@
 #include "jasper/jas_image.h"
 #include "jasper/jas_stream.h"
 #include "jasper/jas_math.h"
+#include "jasper/jas_tvp.h"
 #include "jasper/jas_debug.h"
 #include "jasper/jas_malloc.h"
 #include "jasper/jas_version.h"
@@ -81,10 +82,32 @@
 #include "jp2_cod.h"
 #include "jp2_dec.h"
 
+/******************************************************************************\
+* Local types for option parsing.
+\******************************************************************************/
+
+typedef struct {
+	jas_bool raw;
+} jp2_decopts_t;
+
+typedef enum {
+	OPT_RAW_PALETTE
+} jp2_optid_t;
+
+jas_taginfo_t jp2_opttab[] = {
+	{OPT_RAW_PALETTE, "raw"}, /* needed for PDF */
+	{-1, 0}
+};
+
+/******************************************************************************\
+* Local function prototypes.
+\******************************************************************************/
+
 #define	JP2_VALIDATELEN	(JAS_MIN(JP2_JP_LEN + 16, JAS_STREAM_MAXPUTBACK))
 
 static jp2_dec_t *jp2_dec_create(void);
 static void jp2_dec_destroy(jp2_dec_t *dec);
+static int jp2_parsedecopts(char *optstr, jp2_decopts_t *decopts);
 static int jp2_getcs(jp2_colr_t *colr);
 static int fromiccpcs(int cs);
 static int jp2_getct(int colorspace, int type, int assoc);
@@ -101,6 +124,7 @@
 	jp2_dec_t *dec;
 	jas_bool samedtype;
 	int dtype;
+	jp2_decopts_t decopts;
 	unsigned int i;
 	jp2_cmap_t *cmapd;
 	jp2_pclr_t *pclrd;
@@ -120,6 +144,16 @@
 	box = 0;
 	image = 0;
 
+	/* Parse the decoder option string. */
+	if (jp2_parsedecopts(optstr, &decopts)) {
+		jas_eprintf("invalid jp2 decoder options specified\n");
+		goto error;
+	}
+	if (decopts.raw) {
+		jas_eprintf("got raw palette key\n");
+	}
+
+	/* Create our decoder context. */
 	if (!(dec = jp2_dec_create())) {
 		goto error;
 	}
@@ -246,7 +280,7 @@
 	}
 
 	/* Is the component data type indicated in the IHDR box consistent
-	  with the data in the code stream? */
+	   with the data in the code stream? */
 	if ((samedtype && dec->ihdr->data.ihdr.bpc != JP2_DTYPETOBPC(dtype)) ||
 	  (!samedtype && dec->ihdr->data.ihdr.bpc != JP2_IHDR_BPCNULL)) {
 		jas_eprintf("warning: component data type mismatch\n");
@@ -315,6 +349,13 @@
 		dec->pclr = 0;
 	}
 
+	/* If the client passed the raw option, just return the raw 
+	   palette index data as returned by jpc_decode(). */
+	if (decopts.raw) {
+		goto done;
+	}
+	/* otherwise, sort out the decoded channels */
+	
 	/* Determine the number of channels (which is essentially the number
 	  of components after any palette mappings have been applied). */
 	dec->numchans = dec->cmap ? dec->cmap->data.cmap.numchans : JAS_CAST(uint, jas_image_numcmpts(dec->image));
@@ -360,6 +401,7 @@
 				dec->chantocmptlut[channo] = channo;
 #endif
 			} else if (cmapent->map == JP2_CMAP_PALETTE) {
+			    if (!decopts.raw) {
 				lutents = jas_malloc(pclrd->numlutents * sizeof(int_fast32_t));
 				for (i = 0; i < pclrd->numlutents; ++i) {
 					lutents[i] = pclrd->lutdata[cmapent->pcol + i * pclrd->numchans];
@@ -378,6 +420,7 @@
 				jas_image_setcmpttype(dec->image, newcmptno, jp2_getct(jas_image_clrspc(dec->image), 0, channo + 1));
 				}
 #endif
+			    }
 			}
 		}
 	}
@@ -427,6 +470,7 @@
 jas_eprintf("no of components is %d\n", jas_image_numcmpts(dec->image));
 #endif
 
+done:
 	/* Prevent the image from being destroyed later. */
 	image = dec->image;
 	dec->image = 0;
@@ -533,6 +577,42 @@
 	jas_free(dec);
 }
 
+/* parse the encoder options strig. */
+static int jp2_parsedecopts(char *optstr, jp2_decopts_t *decopts)
+{
+	jas_tvparser_t *tvp;
+	int ret;
+
+	tvp = 0;
+
+	/* Initialize default values for decoder options */
+	decopts->raw = jas_false;
+
+	/* Create the tag-value parser. */
+	if (!(tvp = jas_tvparser_create(optstr ? optstr : ""))) {
+		return -1;
+	}
+
+	/* Get tag-value pairs, and process as necessary. */
+	while (!(ret = jas_tvparser_next(tvp))) {
+		switch (jas_taginfo_nonull(jas_taginfos_lookup(jp2_opttab,
+		  jas_tvparser_gettag(tvp)))->id) {
+		case OPT_RAW_PALETTE:
+                        decopts->raw = jas_true;
+			break;
+		default:
+			jas_eprintf("warning: ignoring invalid option %s\n",
+			  jas_tvparser_gettag(tvp));
+			break;
+		}
+	}
+
+	if (tvp) {
+		jas_tvparser_destroy(tvp);
+	}
+	return (ret < 0) ? -1 : 0;
+}
+
 static int jp2_getct(int colorspace, int type, int assoc)
 {
 	if (type == 1 && assoc == 0) {

Modified: trunk/gs/jasper/src/libjasper/jpc/jpc_dec.c
===================================================================
--- trunk/gs/jasper/src/libjasper/jpc/jpc_dec.c	2006-12-06 22:23:19 UTC (rev 7455)
+++ trunk/gs/jasper/src/libjasper/jpc/jpc_dec.c	2006-12-06 22:25:01 UTC (rev 7456)
@@ -289,13 +289,15 @@
 typedef enum {
 	OPT_MAXLYRS,
 	OPT_MAXPKTS,
-	OPT_DEBUG
+	OPT_DEBUG,
+	OPT_RAW_PALETTE
 } optid_t;
 
 jas_taginfo_t decopts[] = {
 	{OPT_MAXLYRS, "maxlyrs"},
 	{OPT_MAXPKTS, "maxpkts"},
 	{OPT_DEBUG, "debug"},
+	{OPT_RAW_PALETTE, "raw"},
 	{-1, 0}
 };
 
@@ -323,6 +325,9 @@
 		case OPT_MAXPKTS:
 			opts->maxpkts = atoi(jas_tvparser_getval(tvp));
 			break;
+		case OPT_RAW_PALETTE:
+			/* this is just for passthrough from jp2_decode */
+			break;
 		default:
 			jas_eprintf("warning: ignoring invalid option %s\n",
 			  jas_tvparser_gettag(tvp));



More information about the gs-cvs mailing list