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

tim at ghostscript.com tim at ghostscript.com
Sat Jun 16 12:24:23 PDT 2007


Author: tim
Date: 2007-06-16 12:24:22 -0700 (Sat, 16 Jun 2007)
New Revision: 8053

Modified:
   trunk/gs/src/gsdparam.c
Log:
Fix to limit GraphicsAlphaBits and TextAlphaBits to legal values.

DETAILS:

Bug 688020 reported that when a user set the GraphicsAlphaBits and TextAlphaBits
to values not supported by the current device unexpected images would be
generated. This fix limits the internal values used to those which are supported
by the current output device.

EXPECTED DIFFERENCES:

None.



Modified: trunk/gs/src/gsdparam.c
===================================================================
--- trunk/gs/src/gsdparam.c	2007-06-15 18:55:34 UTC (rev 8052)
+++ trunk/gs/src/gsdparam.c	2007-06-16 19:24:22 UTC (rev 8053)
@@ -21,6 +21,7 @@
 #include "gsparam.h"
 #include "gxdevice.h"
 #include "gxfixed.h"
+#include "math.h"			/* for log10 */
 
 /* Define whether we accept PageSize as a synonym for MediaSize. */
 /* This is for backward compatibility only. */
@@ -382,6 +383,7 @@
 /* ================ Putting parameters ================ */
 
 /* Forward references */
+private int param_normalize_anti_alias_bits( uint max_gray, int bits );
 private int param_anti_alias_bits(gs_param_list *, gs_param_name, int *);
 private int param_MediaSize(gs_param_list *, gs_param_name,
 			    const float *, gs_param_float_array *);
@@ -802,8 +804,10 @@
 	dev->ImagingBBox_set = false;
     }
     dev->UseCIEColor = ucc;
-    dev->color_info.anti_alias.text_bits = tab;
-    dev->color_info.anti_alias.graphics_bits = gab;
+    dev->color_info.anti_alias.text_bits =
+    	param_normalize_anti_alias_bits(dev->color_info.max_gray, tab);
+    dev->color_info.anti_alias.graphics_bits =
+    	param_normalize_anti_alias_bits(dev->color_info.max_gray, gab);;
     dev->LockSafetyParams = locksafe;
     gx_device_decache_colors(dev);
     return 0;
@@ -817,6 +821,20 @@
 	LEADINGEDGE_REQ_BIT;
 }
 
+/* Limit the anti-alias bit values to the maximum legal value for the
+ * current color depth.
+ */
+private int
+param_normalize_anti_alias_bits( uint max_gray, int bits )
+{
+	/* Use log2(x) = log10(x) / Log10(2) as log2 might not be available
+	 * with all compilers
+	 */
+	double	max_bits = log10((double)max_gray + 1.0) / 0.30102999;
+	
+	return  (bits > max_bits ? (int)max_bits : bits);
+}
+
 /* Read TextAlphaBits or GraphicsAlphaBits. */
 private int
 param_anti_alias_bits(gs_param_list * plist, gs_param_name param_name, int *pa)



More information about the gs-cvs mailing list