[gs-cvs] rev 8868 - trunk/gs/src

mvrhel at ghostscript.com mvrhel at ghostscript.com
Wed Jul 23 16:29:42 PDT 2008


Author: mvrhel
Date: 2008-07-23 16:29:39 -0700 (Wed, 23 Jul 2008)
New Revision: 8868

Modified:
   trunk/gs/src/gscindex.h
   trunk/gs/src/gscolor2.c
   trunk/gs/src/gxcolor2.h
   trunk/gs/src/gximage.h
   trunk/gs/src/gxiscale.c
   trunk/gs/src/lib.mak
Log:
Fix for Bug 689246.  When performing interpolation, the interpolation is now performed in the source colorspace as opposed to the device space.  Custom color callback is no longer bypassed by direct concretization as it was previously.

DETAILS:

Previous code would take device color 8 bit values and do the interpolation.  That portion of the code is the same.   For cases where we have nondevice color the handling is now different.  Indexed colors are mapped to their base space and interpolated.  This is followed by a remap operation.  Device independent colors are interpolated followed by a remap operation.  

Note that for cases where there is a significant enlargement occurring and we are not in a device color space, there can be a performance cost due to current inefficiencies in our color remapping operations.  This can be costly if you have a CMYK CRD MLUT for example.  There is currently a project underway to improve the efficiency of the color flow.  For the current time, if this is an issue, improved speed can be achieved by invoking -dNOINTERPOLATION

EXPECTED DIFFERENCES:

148-11.PS
12-07B.PS
23-32.PS
13-03.PS
13-12.PS

The first two files have interpolation defined as on for some of their images. Hence there will be differences.  With this change we more closely match the AR output for 12-07B.PS.  148-11.ps  has only a minor difference in its coloring due to the interpolation in the different color space.  The other files are nondeterministic.



Modified: trunk/gs/src/gscindex.h
===================================================================
--- trunk/gs/src/gscindex.h	2008-07-23 22:52:50 UTC (rev 8867)
+++ trunk/gs/src/gscindex.h	2008-07-23 23:29:39 UTC (rev 8868)
@@ -18,6 +18,7 @@
 #  define gscindex_INCLUDED
 
 #include "gscspace.h"
+#include "gxfrac.h"
 
 /*
  * Indexed color spaces.
@@ -71,4 +72,12 @@
 int gs_cspace_indexed_lookup(const gs_color_space *, int,
 			     gs_client_color *);
 
+/* Look up an index in an Indexed color space. Return as a byte */
+int gs_cspace_indexed_lookup_bytes(const gs_color_space *pcs, float index_float,
+			unsigned char *output);
+
+/* Look up an index in an Indexed color space. Return as a frac */
+int gs_cspace_indexed_lookup_frac(const gs_color_space *pcs, float index_float,
+			frac *output);
+
 #endif /* gscindex_INCLUDED */

Modified: trunk/gs/src/gscolor2.c
===================================================================
--- trunk/gs/src/gscolor2.c	2008-07-23 22:52:50 UTC (rev 8867)
+++ trunk/gs/src/gscolor2.c	2008-07-23 23:29:39 UTC (rev 8868)
@@ -25,6 +25,7 @@
 #include "gxpcolor.h"
 #include "stream.h"
 #include "gxcie.h"  
+#include "gxfrac.h"
 
 /* ---------------- General colors and color spaces ---------------- */
 
@@ -477,6 +478,156 @@
     }
 }
 
+/* Look up an index in an Indexed color space, return value as byte value(s). */
+int
+gs_cspace_indexed_lookup_bytes(const gs_color_space *pcs, float index_float,
+			unsigned char *output)
+{
+    const gs_indexed_params *pip = &pcs->params.indexed;
+    const gs_color_space *pbcs = pcs->base_space;
+    int m = cs_num_components(pbcs);
+    int index;
+ 
+    index = (is_fneg(index_float) ? 0 :
+    index_float >= pcs->params.indexed.hival ? pcs->params.indexed.hival :
+    (int) index_float);
+
+    if (pip->use_proc) {
+
+        float values[GS_CLIENT_COLOR_MAX_COMPONENTS];
+        int ok;
+
+        ok = pip->lookup.map->proc.lookup_index(pcs, index, values); 
+
+        /* Get out of float and to uchar. 
+           Note the fall through in the switch statement to 
+           handle the number of channels */
+
+        switch (m) {
+            default: {		/* DeviceN */
+	        int i;
+
+	        for (i = 0; i < m; ++i)
+	            output[i] = float_color_to_byte_color(values[i]);
+            }
+	        break;
+            case 4:
+	        output[3] = float_color_to_byte_color(values[3]);
+            case 3:
+	        output[2] = float_color_to_byte_color(values[2]);
+            case 2:
+	        output[1] = float_color_to_byte_color(values[1]);
+            case 1:
+	        output[0] = float_color_to_byte_color(values[0]);
+        }
+
+        return ok; 
+
+    } else {
+
+        /* Here it uses a 1-D LUT. Again the fall through
+            in the switch statement */
+
+        const byte *pcomp = pip->lookup.table.data + m * index;
+
+        switch (m) {
+            default: {		/* DeviceN */
+	        int i;
+
+	        for (i = 0; i < m; ++i)
+	            output[i] = pcomp[i];
+            }
+	        break;
+            case 4:
+	        output[3] = pcomp[3];
+            case 3:
+	        output[2] = pcomp[2];
+            case 2:
+	        output[1] = pcomp[1];
+            case 1:
+	        output[0] = pcomp[0];
+        }
+        return 0;
+    }
+}
+
+
+/* Look up an index in an Indexed color space, return value as frac value(s). */
+int
+gs_cspace_indexed_lookup_frac(const gs_color_space *pcs, float index_float,
+			frac *output)
+{
+    const gs_indexed_params *pip = &pcs->params.indexed;
+    const gs_color_space *pbcs = pcs->base_space;
+    int m = cs_num_components(pbcs);
+    int index;
+ 
+    index = (is_fneg(index_float) ? 0 :
+    index_float >= pcs->params.indexed.hival ? pcs->params.indexed.hival :
+    (int) index_float);
+
+    if (pip->use_proc) {
+
+        float values[GS_CLIENT_COLOR_MAX_COMPONENTS];
+        int ok;
+
+        ok = pip->lookup.map->proc.lookup_index(pcs, index, values); 
+
+        /* Get out of float and to frac. 
+           Note the fall through in the switch statement to 
+           handle the number of channels */
+
+        switch (m) {
+            default: {		/* DeviceN */
+	        int i;
+
+	        for (i = 0; i < m; ++i)
+	            output[i] = float2frac(values[i]);
+            }
+	        break;
+            case 4:
+	        output[3] = float2frac(values[3]);
+            case 3:
+	        output[2] = float2frac(values[2]);
+            case 2:
+	        output[1] = float2frac(values[1]);
+            case 1:
+	        output[0] = float2frac(values[0]);
+        }
+
+        return ok; 
+
+    } else {
+
+        /* Here it uses a 1-D LUT 
+           Again the fall through */
+
+        const byte *pcomp = pip->lookup.table.data + m * index;
+
+        switch (m) {
+            default: {		/* DeviceN */
+	        int i;
+
+	        for (i = 0; i < m; ++i)
+	            output[i] = byte2frac(pcomp[i]);
+            }
+	        break;
+            case 4:
+	        output[3] = byte2frac(pcomp[3]);
+            case 3:
+	        output[2] = byte2frac(pcomp[2]);
+            case 2:
+	        output[1] = byte2frac(pcomp[1]);
+            case 1:
+	        output[0] = byte2frac(pcomp[0]);
+        }
+        return 0;
+    }
+}
+
+
+
+
 /* Look up with restriction */
 
 int

Modified: trunk/gs/src/gxcolor2.h
===================================================================
--- trunk/gs/src/gxcolor2.h	2008-07-23 22:52:50 UTC (rev 8867)
+++ trunk/gs/src/gxcolor2.h	2008-07-23 23:29:39 UTC (rev 8868)
@@ -89,4 +89,11 @@
     "gs_pattern1_instance_t", pattern1_instance_enum_ptrs,\
     pattern1_instance_reloc_ptrs)
 
+/* This is used for the case where we have float outputs due to the use of a procedure in 
+   the indexed image, but we desire to have byte outputs.  Used with interpolated images. */
+
+#define float_color_to_byte_color(float_color) ( (0.0 < float_color && float_color < 1.0) ? \
+    ((unsigned char) (float_color*255.0)) :  ( (float_color <= 0.0) ? 0x00 : 0xFF  ))
+
+
 #endif /* gxcolor2_INCLUDED */

Modified: trunk/gs/src/gximage.h
===================================================================
--- trunk/gs/src/gximage.h	2008-07-23 22:52:50 UTC (rev 8867)
+++ trunk/gs/src/gximage.h	2008-07-23 23:29:39 UTC (rev 8868)
@@ -115,6 +115,12 @@
   cc.paint.values[i] =\
     penum->map[i].decode_base + (frac_value) * penum->map[i].decode_factor
 
+
+/* Decode a frac value, to our 16 bit frac form. */
+#define DECODE_FRAC_FRAC(frac_value, frac_value_out, i)\
+  frac_value_out =\
+    gx_unit_frac(penum->map[i].decode_base + (frac_value) * penum->map[i].decode_factor)
+
 /*
  * Declare the pointer that holds the 12-bit unpacking procedure
  * if 12-bit samples are supported, 0 otherwise.

Modified: trunk/gs/src/gxiscale.c
===================================================================
--- trunk/gs/src/gxiscale.c	2008-07-23 22:52:50 UTC (rev 8867)
+++ trunk/gs/src/gxiscale.c	2008-07-23 23:29:39 UTC (rev 8868)
@@ -37,8 +37,14 @@
 #include "siscale.h"		/* for Mitchell filtering */
 #include "sidscale.h"		/* for special case downscale filter */
 #include "vdtrace.h"
+#include "gscindex.h"           /* included for proper handling of index color spaces 
+                                and keeping data in source color space */
 
-/*
+
+static void 
+decode_sample_frac_to_float(gx_image_enum *penum, frac sample_value, gs_client_color *cc, int i);
+
+    /*
  * Define whether we are using Mitchell filtering or spatial
  * interpolation to implement Interpolate.  (The latter doesn't work yet.)
  */
@@ -49,7 +55,9 @@
 /* Check the prototype. */
 iclass_proc(gs_image_class_0_interpolate);
 
-/* If we're interpolating, use special logic. */
+/* If we're interpolating, use special logic. 
+   This function just gets interpolation stucture
+   initialized and allocates buffer space if needed */
 static irender_proc(image_render_interpolate);
 irender_proc_t
 gs_image_class_0_interpolate(gx_image_enum * penum)
@@ -61,18 +69,21 @@
     const stream_template *template;
     byte *line;
     const gs_color_space *pcs = penum->pcs;
-    const gs_color_space *pccs;
     gs_point dst_xy;
     uint in_size;
+#ifdef INTERPDEBUG
+    FILE *fid;
+#endif
 
     if (!penum->interpolate) 
 	return 0;
     if (penum->use_mask_color || penum->posture != image_portrait ||
-    	penum->masked || penum->alpha ) {
+    	penum->masked || penum->alpha) {
 	/* We can't handle these cases yet.  Punt. */
 	penum->interpolate = false;
 	return 0;
     }
+
 /*
  * USE_CONSERVATIVE_INTERPOLATION_RULES is normally NOT defined since
  * the MITCHELL digital filter seems OK as long as we are going out to
@@ -113,20 +124,66 @@
     iss.EntireHeightIn = penum->Height;
     iss.EntireWidthOut = fixed2int_pixround(any_abs(penum->dst_width));
     iss.EntireHeightOut = fixed2int_pixround(any_abs(penum->dst_height));
-    pccs = cs_concrete_space(pcs, pis);
-    iss.Colors = cs_num_components(pccs);
-    if (penum->bps <= 8 && penum->device_color) {
+
+    /* If we are in an indexed space then we need to use the number of components
+       in the base space.  Otherwise we use the number of components in the source space */
+
+    if (pcs->type->index == gs_color_space_index_Indexed) {
+
+        /* Use the number of colors in the base space */
+        iss.Colors = cs_num_components(pcs->base_space);
+
+    } else {
+
+        /* Use the number of colors that exist in the source space
+        as this is where we are doing our interpolation */
+        iss.Colors = cs_num_components(pcs);
+
+    }
+
+    if (penum->bps <= 8 ) {
+
+       /* If the input is ICC or other device independent format, go ahead 
+          and do the interpolation in that space. 
+          If we have more than 8 bits per channel then we will need to 
+          handle that in a slightly different manner so
+          that the interpolation algorithm handles it properly. 
+          The interpolation will still be in the source 
+          color space.  Note that if image data was less the 8 bps
+          It is handed here to us in 8 bit form already decoded. */
+
 	iss.BitsPerComponentIn = 8;
 	iss.MaxValueIn = 0xff;
-	in_size =
-	    (penum->matrix.xx < 0 ?
-	     /* We need a buffer for reversing each scan line. */
-	     iss.WidthIn * iss.Colors : 0);
+
+        /* If it is an index color space we will need to allocate for the decoded data */
+
+       if (pcs->type->index == gs_color_space_index_Indexed) {
+        
+           in_size = iss.WidthIn * iss.Colors;
+
+       } else {
+
+           /* Non indexed case, we either use the data as 
+           is, or allocate space if it is reversed in X */
+	    in_size =
+	        (penum->matrix.xx < 0 ?
+	         /* We need a buffer for reversing each scan line. */
+	         iss.WidthIn * iss.Colors : 0);  
+            /* If it is not reversed, and we have 8 bit/color channel data then            
+            no need to allocate extra as we will use the source directly */
+
+       }
+
     } else {
+
+        /* If it has more than 8 bits per color channel then we will go to frac 
+           for the interpolation to mantain precision.  */
+
 	iss.BitsPerComponentIn = sizeof(frac) * 8;
 	iss.MaxValueIn = frac_1;
 	in_size = round_up(iss.WidthIn * iss.Colors * sizeof(frac),
-			   align_bitmap_mod);
+			   align_bitmap_mod);   
+        /* Size to allocate space to store the input as frac type */
     }
 #ifdef USE_MITCHELL_FILTER
     template = &s_IScale_template;
@@ -160,9 +217,16 @@
     {
 	uint out_size =
 	    iss.WidthOut * max(iss.Colors * (iss.BitsPerComponentOut / 8),
-			       arch_sizeof_color_index);
+			       arch_sizeof_color_index);  
+        /* Allocate based upon frac size (as BitsPerComponentOut=16) */
 
-	line = gs_alloc_bytes(mem, in_size + out_size,
+        /* output scan line input plus output */
+        /* The outsize may have an adjustment for word boundary on it.
+           Need to account for that now */
+
+ 	out_size += align_bitmap_mod;  
+
+	line = gs_alloc_bytes(mem, in_size + out_size,       
 			      "image scale src+dst line");
     }
     pss = (stream_image_scale_state *)
@@ -177,7 +241,7 @@
 	penum->interpolate = false;
 	return 0;
     }
-    penum->line = line;
+    penum->line = line;  /* Set to the input and output buffer */
     penum->scaler = pss;
     penum->line_xy = 0;
     {
@@ -192,6 +256,7 @@
 				    * penum->dst_height / penum->Height))
 		* (penum->matrix.yy > 0 ? 1 : -1);
     if_debug0('b', "[b]render=interpolate\n");
+
     return &image_render_interpolate;
 }
 
@@ -208,72 +273,219 @@
     int c = pss->params.Colors;
     stream_cursor_read r;
     stream_cursor_write w;
-    byte *out = penum->line;
+    unsigned char index_space;
+    byte *out = penum->line;   /* buffer for output scan line.  It may be large
+                               enough to hold a temporary converted input scan
+                               line also depending upon what occured in
+                               gs_image_class_0_interpolate */
 
     if (h != 0) {
+
 	/* Convert the unpacked data to concrete values in */
 	/* the source buffer. */
 	int sizeofPixelIn = pss->params.BitsPerComponentIn / 8;
 	uint row_size = pss->params.WidthIn * c * sizeofPixelIn;
-	const byte *bdata = buffer + data_x * c * sizeofPixelIn;
+	const unsigned char *bdata = buffer + data_x * c * sizeofPixelIn;    /* raw input data */       
+        index_space = 0;
 
+        /* We have the following cases to worry about 
+
+          1) Device 8 bit color or nondevice but not indexed (e.g. ICC).  Use as is directly. Remap after interpolation.
+          2) Indexed 8 bit color.  Get to the base space. We will then be in the same state as 1.  
+          3) 16 bit not indexed.  Remap after interpolation.  
+          4) Indexed 16bit color.   Get to base space in 16bit frac form. We will then be in same state as 3.  
+
+       */
+
 	if (sizeofPixelIn == 1) {
-	    /* Easy case: 8-bit device color values. */
-	    if (penum->matrix.xx >= 0) {
-		/* Use the input data directly. */
-		r.ptr = bdata - 1;
-	    } else {
-		/* Mirror the data in X. */
-		const byte *p = bdata + row_size - c;
-		byte *q = out;
-		int i;
 
-		for (i = 0; i < pss->params.WidthIn; p -= c, q += c, ++i)
-		    memcpy(q, p, c);
-		r.ptr = out - 1;
-		out = q;
-	    }
+            if (pcs->type->index != gs_color_space_index_Indexed) {
+
+                /* 8-bit color values, possibly device 
+                indep. or device depend., not indexed. */
+                if (penum->matrix.xx >= 0) {
+	            /* Use the input data directly. */
+	            r.ptr = bdata - 1;   /* sets up data in the stream buffere structure */
+                } else {
+	            /* Mirror the data in X. */
+	            const byte *p = bdata + row_size - c;
+	            byte *q = out;
+	            int i;
+
+	            for (i = 0; i < pss->params.WidthIn; p -= c, q += c, ++i)
+	                memcpy(q, p, c);
+	            r.ptr = out - 1;
+	            out = q;
+                }
+
+            } else {
+
+                /* indexed 8 bit color values, possibly a device indep. or device depend. base space 
+                   We need to get out of the indexed space and into the base color space.
+                   Note that we need to worry about the decode function for the index values. */
+
+      	        int bps = penum->bps;
+	        int dc = penum->spp;
+	        const byte *pdata = bdata; /* Input buffer */
+	        unsigned char *psrc = (unsigned char *) penum->line;  /* Output buffer */
+	        int i;
+                int dpd = dc * (bps <= 8 ? 1 : sizeof(frac));
+                float max_range;
+
+                /* Get max of decode range */
+
+                max_range = (penum->map[0].decode_factor < 0 ? 
+                    penum->map[0].decode_base : 
+                penum->map[0].decode_base + 255.0 * penum->map[0].decode_factor);
+
+                index_space = 1;
+
+                /* flip the horizontal direction if indicated by the matrix value */
+                if (penum->matrix.xx < 0) {
+                  pdata += (pss->params.WidthIn - 1) * dpd;
+                  dpd = - dpd;
+                }
+	        r.ptr = (byte *) psrc - 1;
+
+	        for (i = 0; i < pss->params.WidthIn; i++, psrc += c) {
+
+                    /* Let's get directly to a decoded byte type loaded into psrc, 
+                        and do the interpolation in the source space 
+                        Then we will do the appropriate remap function after interpolation. */
+
+                    /* First we need to get the properly decoded value. */
+
+                    float decode_value;
+
+                    switch ( penum->map[0].decoding )
+                    {
+                    case sd_none:
+
+                     /* while our indexin is going to be 0 to 255.0 due to what is getting handed to us,
+                        the range of our original data may not have been as such and we may need to rescale, 
+                        to properly lookup at the correct location (or do the proc correctly) during the 
+                        index look-up.  This occurs even if decoding was set to sd_none.  */
+
+                        decode_value = (float) pdata[0] * (float)max_range / 255.0; 
+
+                    break;
+
+                    case sd_lookup:	
+                        decode_value = 
+                          (float) penum->map[0].decode_lookup[pdata[0] >> 4];
+                    break;
+
+                    case sd_compute:
+                        decode_value =   
+                          penum->map[0].decode_base + ((float) pdata[0]) * penum->map[0].decode_factor;
+                  }
+
+                  gs_cspace_indexed_lookup_bytes(pcs, decode_value,psrc);	
+	          pdata ++;  
+
+                 }
+
+                 /* We need to set the output to the end of the input buffer 
+                    moving it to the next desired word boundary.  This must
+                    be accounted for in the memory allocation of gs_image_class_0_interpolate */
+
+ 	         out += round_up(pss->params.WidthIn*c, align_bitmap_mod);  
+              }
+
+	  //  r.limit = r.ptr + row_size;
+
 	} else {
-	    /* Messy case: concretize each sample. */
-	    int bps = penum->bps;
-	    int dc = penum->spp;
-	    const byte *pdata = bdata;
-	    frac *psrc = (frac *) penum->line;
-	    gs_client_color cc;
-	    int i, j;
-            int dpd = dc * (bps <= 8 ? 1 : sizeof(frac));
 
-            if (penum->matrix.xx < 0) {
-              pdata += (pss->params.WidthIn - 1) * dpd;
-              dpd = - dpd;
-            }
-	    r.ptr = (byte *) psrc - 1;
-	    if_debug0('B', "[B]Concrete row:\n[B]");
-	    for (i = 0; i < pss->params.WidthIn; i++, psrc += c) {
-		if (bps <= 8) {
-		    for (j = 0; j < dc;  ++j) {
-			decode_sample(pdata[j], cc, j);
+	    /* More than 8-bits/color values */
+            /* Even in this case we need to worry about an indexed color space. 
+               We need to get to the base color space for the interpolation and
+               then if necessary do the remap to the device space */
+
+            if (pcs->type->index != gs_color_space_index_Indexed) {
+
+	        int bps = penum->bps;
+	        int dc = penum->spp;
+	        const byte *pdata = bdata;
+	        frac *psrc = (frac *) penum->line;
+	        int i, j;
+                int dpd = dc * (bps <= 8 ? 1 : sizeof(frac));
+
+                if (penum->matrix.xx < 0) {
+                  pdata += (pss->params.WidthIn - 1) * dpd;
+                  dpd = - dpd;
+                }
+	        r.ptr = (byte *) psrc - 1;
+	        if_debug0('B', "[B]Remap row:\n[B]");
+	        for (i = 0; i < pss->params.WidthIn; i++, psrc += c) {
+
+                    /* Lets get directly to a frac type loaded into psrc, and do 
+                        the interpolation in the source space. 
+                           Then we will do the appropriate remap 
+                           function after interpolation. */
+
+                    for (j = 0; j < dc;  ++j) {
+	                DECODE_FRAC_FRAC(((const frac *)pdata)[j], psrc[j], j);
                     }
-		} else {	/* bps == 12 */
-		    for (j = 0; j < dc;  ++j) {
-			decode_frac(((const frac *)pdata)[j], cc, j);
-		    }
+
+	            pdata += dpd;
+        #ifdef DEBUG
+	            if (gs_debug_c('B')) {
+	                int ci;
+
+	                for (ci = 0; ci < c; ++ci)
+		            dprintf2("%c%04x", (ci == 0 ? ' ' : ','), psrc[ci]);
+	            }
+        #endif
                 }
-		pdata += dpd;
-                (*pcs->type->concretize_color) (&cc, pcs, psrc, pis);
-#ifdef DEBUG
-		if (gs_debug_c('B')) {
-		    int ci;
 
-		    for (ci = 0; ci < c; ++ci)
-			dprintf2("%c%04x", (ci == 0 ? ' ' : ','), psrc[ci]);
-		}
-#endif
-	    }
-	    out += round_up(pss->params.WidthIn * c * sizeof(frac),
-			    align_bitmap_mod);
-	    if_debug0('B', "\n");
-	}
+	        out += round_up(pss->params.WidthIn * c * sizeof(frac),
+			        align_bitmap_mod);
+	        if_debug0('B', "\n");
+
+
+            } else {
+                
+                /* indexed and more than 8bps.  Need to get to the base space */
+
+      	        int bps = penum->bps;
+	        int dc = penum->spp;
+	        const byte *pdata = bdata; /* Input buffer */
+	        frac *psrc = (frac *) penum->line;    /* Output buffer */
+	        int i;
+                int dpd = dc * (bps <= 8 ? 1 : sizeof(frac));
+                float decode_value;
+
+                index_space = 1;
+
+                /* flip the horizontal direction if indicated by the matrix value */
+                if (penum->matrix.xx < 0) {
+                  pdata += (pss->params.WidthIn - 1) * dpd;
+                  dpd = - dpd;
+                }
+	        r.ptr = (byte *) psrc - 1;
+
+	        for (i = 0; i < pss->params.WidthIn; i++, psrc += c) {
+
+                    /* Lets get the decoded value. Then we need to do the lookup of this */
+
+                    decode_value = penum->map[i].decode_base + (((const frac *)pdata)[0]) * penum->map[i].decode_factor;
+
+                     /* Now we need to do the lookup of this value, and stick it in psrc as a frac, which is what
+                        the interpolator is expecting, since we had more than 8 bits of original image data */
+
+                      gs_cspace_indexed_lookup_frac(pcs, decode_value,psrc);	
+	              pdata += dpd;  
+
+                }
+
+                 /* We need to set the output to the end of the input buffer 
+                    moving it to the next desired word boundary.  This must
+                    be accounted for in the memory allocation of gs_image_class_0_interpolate */
+ 	         out += round_up(pss->params.WidthIn*c, align_bitmap_mod);                 
+
+            } /* end of else on indexed */
+	}  /* end of else on more than 8 bps */
+
 	r.limit = r.ptr + row_size;
     } else			/* h == 0 */
 	r.ptr = 0, r.limit = 0;
@@ -288,10 +500,13 @@
 	int yo = penum->xyi.y;
 	int width = pss->params.WidthOut;
 	int sizeofPixelOut = pss->params.BitsPerComponentOut / 8;
+        int sizeofPixelIn = pss->params.BitsPerComponentIn / 8;
 	int dy;
-	const gs_color_space *pconcs = cs_concrete_space(pcs, pis);
+	const gs_color_space *pconcs;
+        const gs_color_space *pactual_cs;
 	int bpp = dev->color_info.depth;
 	uint raster = bitmap_raster(width * bpp);
+        bool device_color;
 
 	if (penum->matrix.yy > 0)
 	    dy = 1;
@@ -310,8 +525,19 @@
 		max(c * sizeofPixelOut, arch_sizeof_color_index) - 1;
 	    w.ptr = w.limit - width * c * sizeofPixelOut;
 	    psrc = (const frac *)(w.ptr + 1);
-	    status = (*pss->template->process)
+
+            /* This is where the rescale takes place */
+ /*    z=_CrtCheckMemory();
+    if (z != 1)
+        z = 0; */
+            
+            status = (*pss->template->process)
 		((stream_state *) pss, &r, &w, h == 0);
+
+  /*  z=_CrtCheckMemory();
+    if (z != 1)
+        z = 0;  */
+
 	    if (status < 0 && status != EOFC)
 		return_error(gs_error_ioerror);
 	    if (w.ptr == w.limit) {
@@ -320,6 +546,7 @@
 		if_debug1('B', "[B]Interpolated row %d:\n[B]",
 			  penum->line_xy);
 		for (x = xo; x < xe;) {
+
 #ifdef DEBUG
 		    if (gs_debug_c('B')) {
 			int ci;
@@ -328,9 +555,64 @@
 			    dprintf2("%c%04x", (ci == 0 ? ' ' : ','),
 				     psrc[ci]);
 		    }
-#endif
-		    code = (*pconcs->type->remap_concrete_color)
-			(psrc, pcs, &devc, pis, dev, gs_color_select_source);
+#endif                   
+
+                    /* if we are in a non device space then work 
+                       from the pcs not from the concrete space 
+                       also handle index case, where base case was device type */
+            
+                    if (pcs->type->index == gs_color_space_index_Indexed) {
+
+                        pactual_cs = pcs->base_space;
+
+                    } else {
+
+                        pactual_cs = pcs;
+                    }
+
+                    pconcs = cs_concrete_space(pactual_cs, pis);
+	            device_color = (pactual_cs->type->concrete_space) (pactual_cs, pis) == pactual_cs;
+
+                    if (device_color) {
+
+                        /* Use the underlying concrete space remap */
+                       	
+                        code = (*pconcs->type->remap_concrete_color)
+		        (psrc, pactual_cs, &devc, pis, dev, gs_color_select_source);
+
+                    } else {
+
+                          /* if we are device dependent we need to get back to float 
+                            prior to remap.  This stuff needs to be reworked  as 
+                            part of the ICC flow update.  In such a flow, we will want
+                            the interpolation algorithm output likely to be 8 bit (if the
+                            input were 8 bit) and hit that buffer of values directly 
+                            with the linked transform */
+
+	                  gs_client_color cc;
+                          int j;
+                          int num_components = gs_color_space_num_components(pactual_cs);
+
+                          for (j = 0; j < num_components;  ++j) {
+
+                            /* If we were indexed, dont use the decode procedure for the index values just get to float directly */
+                            if (index_space)
+                            {
+		            
+                                cc.paint.values[j] = frac2float(psrc[j]); 
+
+                            } else {
+
+                                decode_sample_frac_to_float(penum, psrc[j], &cc, j);
+                            }
+
+                          }
+
+                            code = (pactual_cs->type->remap_color)
+                                (&cc, pactual_cs, &devc, pis, dev, gs_color_select_source);
+
+                    }
+
 		    if (code < 0)
 			return code;
 		    if (color_is_pure(&devc)) {
@@ -389,6 +671,29 @@
 		break;
 	}
     }
-
+    
     return (h == 0 ? 0 : 1);
 }
+
+
+/* Decode a 16-bit sample into a floating point color component. 
+   This is used for cases where the spatial interpolation function output is 16 bit.
+   It is only used here, hence the static declaration for now. */
+
+static void 
+decode_sample_frac_to_float(gx_image_enum *penum, frac sample_value, gs_client_color *cc, int i)
+{
+  switch ( penum->map[i].decoding )
+  {
+  case sd_none:
+    cc->paint.values[i] = frac2float(sample_value);  
+    break;
+  case sd_lookup:	
+    cc->paint.values[i] =
+      penum->map[i].decode_lookup[(frac2byte(sample_value)) >> 4];
+    break;
+  case sd_compute:
+    cc->paint.values[i] =
+      penum->map[i].decode_base + frac2float(sample_value)*255.0 * penum->map[i].decode_factor;
+  }
+}
\ No newline at end of file

Modified: trunk/gs/src/lib.mak
===================================================================
--- trunk/gs/src/lib.mak	2008-07-23 22:52:50 UTC (rev 8867)
+++ trunk/gs/src/lib.mak	2008-07-23 23:29:39 UTC (rev 8868)
@@ -420,7 +420,7 @@
 gscrdp_h=$(GLSRC)gscrdp.h $(gscie_h) $(gsparam_h)
 gscdevn_h=$(GLSRC)gscdevn.h $(gscspace_h)
 gxdevndi_h=$(GLSRC)gxdevndi.h $(gxfrac_h)
-gscindex_h=$(GLSRC)gscindex.h $(gscspace_h)
+gscindex_h=$(GLSRC)gscindex.h $(gscspace_h) $(gxfrac_h)
 gscolor2_h=$(GLSRC)gscolor2.h $(gscindex_h) $(gsptype1_h)
 gscsepr_h=$(GLSRC)gscsepr.h $(gscspace_h)
 gxdcconv_h=$(GLSRC)gxdcconv.h $(gxfrac_h)
@@ -2295,7 +2295,8 @@
 
 $(GLOBJ)gscolor2.$(OBJ) : $(GLSRC)gscolor2.c $(GXERR) $(memory__h)\
  $(gxarith_h) $(gxfixed_h) $(gxmatrix_h) $(gxcspace_h)\
- $(gxcolor2_h) $(gzstate_h) $(gxpcolor_h) $(stream_h) $(gxcie_h)
+ $(gxcolor2_h) $(gzstate_h) $(gxpcolor_h) $(stream_h) $(gxcie_h)\
+ $(gxfrac_h)
 	$(GLCC) $(GLO_)gscolor2.$(OBJ) $(C_) $(GLSRC)gscolor2.c
 
 $(GLD)psl2lib.dev : $(LIB_MAK) $(ECHOGS_XE) \
@@ -2308,8 +2309,8 @@
  $(gsccolor_h) $(gspaint_h)\
  $(gxarith_h) $(gxcmap_h) $(gxcpath_h) $(gxdcolor_h) $(gxdevice_h)\
  $(gxdevmem_h) $(gxfixed_h) $(gxfrac_h) $(gximage_h) $(gxistate_h)\
- $(gxmatrix_h)\
- $(siinterp_h) $(siscale_h) $(stream_h) $(vdtrace_h)
+ $(gxmatrix_h) $(siinterp_h) $(siscale_h) $(stream_h) $(vdtrace_h)\
+ $(gxcindex_h)
 	$(GLCC) $(GLO_)gxiscale.$(OBJ) $(C_) $(GLSRC)gxiscale.c
 
 # ---------------- Display Postscript / Level 2 support ---------------- #



More information about the gs-cvs mailing list