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

henrys at ghostscript.com henrys at ghostscript.com
Mon Dec 3 13:31:16 PST 2007


Author: henrys
Date: 2007-12-03 13:31:16 -0800 (Mon, 03 Dec 2007)
New Revision: 8422

Modified:
   trunk/gs/src/gscdevn.c
   trunk/gs/src/gscsepr.c
   trunk/gs/src/gxcmap.c
   trunk/gs/src/gxcmap.h
Log:
Replace the "tricky" unit_frac macro with a normal function call.  The
macro produced a false positive in valgrind and seems to cause
incorrect code generation on gcc 4.1.2 with optimization but we did
not study it in detail.  The change should be equivalent to the
previous code, reviewed by Ralph Giles.


Modified: trunk/gs/src/gscdevn.c
===================================================================
--- trunk/gs/src/gscdevn.c	2007-12-03 20:07:05 UTC (rev 8421)
+++ trunk/gs/src/gscdevn.c	2007-12-03 21:31:16 UTC (rev 8422)
@@ -379,7 +379,7 @@
 	int i;
 
 	for (i = pcs->params.device_n.num_components; --i >= 0;)
-	    pconc[i] = unit_frac(pc->paint.values[i], ftemp);
+	    pconc[i] = gx_unit_frac(pc->paint.values[i]);
 	return 0;
     }
     return (code < 0 || tcode == 0 ? code : tcode);

Modified: trunk/gs/src/gscsepr.c
===================================================================
--- trunk/gs/src/gscsepr.c	2007-12-03 20:07:05 UTC (rev 8421)
+++ trunk/gs/src/gscsepr.c	2007-12-03 21:31:16 UTC (rev 8422)
@@ -335,7 +335,7 @@
 	return cs_concretize_color(&cc, pacs, pconc, pis);
     }
     else {
-    	pconc[0] = unit_frac(pc->paint.values[0], ftemp);
+    	pconc[0] = gx_unit_frac(pc->paint.values[0]);
     }
     return 0;
 }

Modified: trunk/gs/src/gxcmap.c
===================================================================
--- trunk/gs/src/gxcmap.c	2007-12-03 20:07:05 UTC (rev 8421)
+++ trunk/gs/src/gxcmap.c	2007-12-03 21:31:16 UTC (rev 8422)
@@ -610,9 +610,7 @@
 gx_concretize_DeviceGray(const gs_client_color * pc, const gs_color_space * pcs,
 			 frac * pconc, const gs_imager_state * pis)
 {
-    float ftemp;
-
-    pconc[0] = unit_frac(pc->paint.values[0], ftemp);
+    pconc[0] = gx_unit_frac(pc->paint.values[0]);
     return 0;
 }
 int
@@ -649,8 +647,7 @@
 	gx_device_color * pdc, const gs_imager_state * pis, gx_device * dev,
 		    gs_color_select_t select)
 {
-    float ftemp;
-    frac fgray = unit_frac(pc->paint.values[0], ftemp);
+    frac fgray = gx_unit_frac(pc->paint.values[0]);
 
     /* Save original color space and color info into dev color */
     pdc->ccolor.paint.values[0] = pc->paint.values[0];
@@ -685,11 +682,9 @@
 gx_concretize_DeviceRGB(const gs_client_color * pc, const gs_color_space * pcs,
 			frac * pconc, const gs_imager_state * pis)
 {
-    float ftemp;
-
-    pconc[0] = unit_frac(pc->paint.values[0], ftemp);
-    pconc[1] = unit_frac(pc->paint.values[1], ftemp);
-    pconc[2] = unit_frac(pc->paint.values[2], ftemp);
+    pconc[0] = gx_unit_frac(pc->paint.values[0]);
+    pconc[1] = gx_unit_frac(pc->paint.values[1]);
+    pconc[2] = gx_unit_frac(pc->paint.values[2]);
     return 0;
 }
 int
@@ -725,9 +720,8 @@
 	gx_device_color * pdc, const gs_imager_state * pis, gx_device * dev,
 		   gs_color_select_t select)
 {
-    float ftemp;
-    frac fred = unit_frac(pc->paint.values[0], ftemp), fgreen = unit_frac(pc->paint.values[1], ftemp),
-         fblue = unit_frac(pc->paint.values[2], ftemp);
+    frac fred = gx_unit_frac(pc->paint.values[0]), fgreen = gx_unit_frac(pc->paint.values[1]),
+         fblue = gx_unit_frac(pc->paint.values[2]);
 
     /* Save original color space and color info into dev color */
     pdc->ccolor.paint.values[0] = pc->paint.values[0];
@@ -768,12 +762,10 @@
 gx_concretize_DeviceCMYK(const gs_client_color * pc, const gs_color_space * pcs,
 			 frac * pconc, const gs_imager_state * pis)
 {
-    float ftemp;
-
-    pconc[0] = unit_frac(pc->paint.values[0], ftemp);
-    pconc[1] = unit_frac(pc->paint.values[1], ftemp);
-    pconc[2] = unit_frac(pc->paint.values[2], ftemp);
-    pconc[3] = unit_frac(pc->paint.values[3], ftemp);
+    pconc[0] = gx_unit_frac(pc->paint.values[0]);
+    pconc[1] = gx_unit_frac(pc->paint.values[1]);
+    pconc[2] = gx_unit_frac(pc->paint.values[2]);
+    pconc[3] = gx_unit_frac(pc->paint.values[3]);
     return 0;
 }
 int
@@ -806,8 +798,6 @@
 		    gs_color_select_t select)
 {
 /****** IGNORE alpha ******/
-    float ft0, ft1, ft2, ft3;
-
     /* Save original color space and color info into dev color */
     pdc->ccolor.paint.values[0] = pc->paint.values[0];
     pdc->ccolor.paint.values[1] = pc->paint.values[1];
@@ -824,10 +814,10 @@
 	    frac conc[4];
 	    int code;
 
-	    conc[0] = (frac)unit_frac(pc->paint.values[0], ft0);
-	    conc[1] = (frac)unit_frac(pc->paint.values[1], ft1);
-	    conc[2] = (frac)unit_frac(pc->paint.values[2], ft2);
-	    conc[3] = (frac)unit_frac(pc->paint.values[3], ft3);
+	    conc[0] = gx_unit_frac(pc->paint.values[0]);
+	    conc[1] = gx_unit_frac(pc->paint.values[1]);
+	    conc[2] = gx_unit_frac(pc->paint.values[2]);
+	    conc[3] = gx_unit_frac(pc->paint.values[3]);
 	    code = pcb->client_procs->remap_DeviceCMYK(pcb, conc,
 						pcs, pdc, pis, dev, select);
 	    if (code == 0)
@@ -835,10 +825,10 @@
 	}
     }
 #endif
-    gx_remap_concrete_cmyk((frac)unit_frac(pc->paint.values[0], ft0),
-			   (frac)unit_frac(pc->paint.values[1], ft1),
-			   (frac)unit_frac(pc->paint.values[2], ft2),
-			   (frac)unit_frac(pc->paint.values[3], ft3),
+    gx_remap_concrete_cmyk(gx_unit_frac(pc->paint.values[0]),
+			   gx_unit_frac(pc->paint.values[1]),
+			   gx_unit_frac(pc->paint.values[2]),
+			   gx_unit_frac(pc->paint.values[3]),
 			   pdc, pis, dev, select);
     return 0;
 }
@@ -1609,3 +1599,16 @@
     prgba[3] = gx_max_color_value;	/* alpha = 1 */
     return (*dev_proc(dev, map_color_rgb)) (dev, color, prgba);
 }
+
+frac
+gx_unit_frac(float fvalue)
+{
+    frac f = frac_0;
+    if (is_fneg(fvalue))
+        f = frac_0;
+    else if (is_fge1(fvalue))
+        f = frac_1;
+    else
+        f = float2frac(fvalue);
+    return f;
+}

Modified: trunk/gs/src/gxcmap.h
===================================================================
--- trunk/gs/src/gxcmap.h	2007-12-03 20:07:05 UTC (rev 8421)
+++ trunk/gs/src/gxcmap.h	2007-12-03 21:31:16 UTC (rev 8422)
@@ -279,9 +279,10 @@
 dev_proc_decode_color(gx_error_decode_color);
 dev_proc_decode_color(gx_default_decode_color);
 
+/*
+ * convert a float paint value to a fractional value with clamping to
+ * [0,1]
+ */
+frac gx_unit_frac(float fvalue);
 
-#define unit_frac(v, ftemp)\
-  (ftemp = (v),\
-   (is_fneg(ftemp) ? frac_0 : is_fge1(ftemp) ? frac_1 : float2frac(ftemp)))
-
 #endif /* gxcmap_INCLUDED */



More information about the gs-cvs mailing list