[gs-cvs] rev 7072 - in trunk/gs/jasper/src/libjasper: base include/jasper jp2

giles at ghostscript.com giles at ghostscript.com
Wed Sep 27 13:37:42 PDT 2006


Author: giles
Date: 2006-09-27 13:37:41 -0700 (Wed, 27 Sep 2006)
New Revision: 7072

Modified:
   trunk/gs/jasper/src/libjasper/base/jas_image.c
   trunk/gs/jasper/src/libjasper/include/jasper/jas_image.h
   trunk/gs/jasper/src/libjasper/jp2/jp2_dec.c
Log:
Duplicate JPX image channels if the cmap box has multiple references to
satisfy the expectations of later parsing. Bug 688869.

DETAILS:

A paletted jpx image must contain a 'cmap' box that describes how to
build the output image channel by channel out of some combination of
decoded image components, which can be used either directly, or mapped
through a component of the included palette.

Previously, jasper created a new image component whenever a palette 
mapping was satisfied, but did nothing when the cmap specified a decoded
component was meant to be used directly. This created two problems: first
the cmap value was ignored, so if the direct mapping output channels were
in a different order from the decoded components, the would not be marked
correctly. Second, if multiple channels were mapped from the single decoded
component, this was not recorded and the image passed up from the decoder
would be "missing" a channel because component lookups don't go through
the decoded cmap table.

As I read the specification, we should really be creating a completely new
image by applying the cmap data to the decoded image. However, for PDF we
need access to the raw indexed image component before palette application,
and just duplicating directly references components within the same image
is a less invasive change.


Modified: trunk/gs/jasper/src/libjasper/base/jas_image.c
===================================================================
--- trunk/gs/jasper/src/libjasper/base/jas_image.c	2006-09-25 21:50:55 UTC (rev 7071)
+++ trunk/gs/jasper/src/libjasper/base/jas_image.c	2006-09-27 20:37:41 UTC (rev 7072)
@@ -113,6 +113,7 @@
   int newprec);
 static void jas_image_calcbbox2(jas_image_t *image, jas_image_coord_t *tlx,
   jas_image_coord_t *tly, jas_image_coord_t *brx, jas_image_coord_t *bry);
+static void jas_image_dump(jas_image_t *image, FILE *out);
 
 /******************************************************************************\
 * Global data.
@@ -825,7 +826,7 @@
 	return 0;
 }
 
-void jas_image_dump(jas_image_t *image, FILE *out)
+static void jas_image_dump(jas_image_t *image, FILE *out)
 {
 	long buf[1024];
 	int cmptno;
@@ -865,7 +866,22 @@
 	}
 }
 
+int jas_image_dupl_cmpt(jas_image_t *image, int cmptno, int newcmptno)
+{
+	if (cmptno >= image->numcmpts_) return -1;
+        if (newcmptno >= image->maxcmpts_) {
+                if (jas_image_growcmpts(image, newcmptno + 3)) {
+                        return -1;
+                }
+        }
+	if (!(image->cmpts_[newcmptno] = jas_image_cmpt_copy(image->cmpts_[cmptno]))) {
+		return -1;
+	}
+        ++image->numcmpts_;
 
+	return 0;
+}
+
 int jas_image_depalettize(jas_image_t *image, int cmptno, int numlutents,
   int_fast32_t *lutents, int dtype, int newcmptno)
 {

Modified: trunk/gs/jasper/src/libjasper/include/jasper/jas_image.h
===================================================================
--- trunk/gs/jasper/src/libjasper/include/jasper/jas_image.h	2006-09-25 21:50:55 UTC (rev 7071)
+++ trunk/gs/jasper/src/libjasper/include/jasper/jas_image.h	2006-09-27 20:37:41 UTC (rev 7072)
@@ -442,6 +442,8 @@
 #define	jas_image_cmptdtype(image, cmptno) \
 	(JAS_IMAGE_CDT_SETSGND((image)->cmpts_[cmptno]->sgnd_) | JAS_IMAGE_CDT_SETPREC((image)->cmpts_[cmptno]->prec_))
 
+int jas_image_dupl_cmpt(jas_image_t *image, int cmptno, int newcmptno);
+
 int jas_image_depalettize(jas_image_t *image, int cmptno, int numlutents,
   int_fast32_t *lutents, int dtype, int newcmptno);
 

Modified: trunk/gs/jasper/src/libjasper/jp2/jp2_dec.c
===================================================================
--- trunk/gs/jasper/src/libjasper/jp2/jp2_dec.c	2006-09-25 21:50:55 UTC (rev 7071)
+++ trunk/gs/jasper/src/libjasper/jp2/jp2_dec.c	2006-09-27 20:37:41 UTC (rev 7072)
@@ -352,7 +352,13 @@
 		for (channo = 0; channo < cmapd->numchans; ++channo) {
 			cmapent = &cmapd->ents[channo];
 			if (cmapent->map == JP2_CMAP_DIRECT) {
+#if 1
+				newcmptno = jas_image_numcmpts(dec->image);
+				jas_image_dupl_cmpt(dec->image, cmapent->cmptno, newcmptno);
+				dec->chantocmptlut[channo] = newcmptno;
+#else
 				dec->chantocmptlut[channo] = channo;
+#endif
 			} else if (cmapent->map == JP2_CMAP_PALETTE) {
 				lutents = jas_malloc(pclrd->numlutents * sizeof(int_fast32_t));
 				for (i = 0; i < pclrd->numlutents; ++i) {
@@ -382,14 +388,15 @@
 		jas_image_setcmpttype(dec->image, i, JAS_IMAGE_CT_UNKNOWN);
 	}
 
-	/* Determine the type of each component. */
-	/* work around for gs bug 688869 - RG */
-	if (dec->numchans > dec->image->numcmpts_) {
+	/* From gs bug 688869, should no longer happen - RG */
+	if (dec->numchans > jas_image_numcmpts(dec->image)) {
 		jas_eprintf("error: too few components in decoded image!"
 			" (%d instead of %d)\n",
 			dec->image->numcmpts_, dec->numchans);
 		goto error;
 	}
+
+	/* Determine the type of each component. */
 	if (dec->cdef) {
 		for (i = 0; i < dec->numchans; ++i) {
 			jas_image_setcmpttype(dec->image,



More information about the gs-cvs mailing list