[cairo-commit] cairo/src cairo-color.c,1.14,1.15

Behdad Esfahbod commit at pdx.freedesktop.org
Sat Aug 13 01:04:57 PDT 2005


Committed by: behdad

Update of /cvs/cairo/cairo/src
In directory gabe:/tmp/cvs-serv30046/src

Modified Files:
	cairo-color.c 
Log Message:
2005-08-13  Behdad Esfahbod  <behdad at behdad.org>

        * src/cairo-color.c: Fix conversion to short, to get a uniform
        range even for 0xffff.  In other words, a color component of
        of (1.0 - epsilon) would convert to 0xffff, not 0xfffe.



Index: cairo-color.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-color.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- cairo-color.c	14 Apr 2005 21:42:26 -0000	1.14
+++ cairo-color.c	13 Aug 2005 08:04:55 -0000	1.15
@@ -89,29 +89,19 @@
     _cairo_color_init_rgba (color, red, green, blue, 1.0);
 }
 
+/* We multiply colors by (0x10000 - epsilon), such that we get a uniform
+ * range even for 0xffff.  In other words, (1.0 - epsilon) would convert
+ * to 0xffff, not 0xfffe.
+ */
+#define CAIRO_COLOR_ONE_MINUS_EPSILON (65536.0 - 1e-5)
 
-/* XXX: The calculation of:
-
-		channel * 0xffff
-
-	isn't really what we want since:
-
-		(1.0 - epsilon) * 0xffff = 0xfffe
-
-	In other words, given an input range of [0.0, 1.0], we have an
-	infinitely small range tha maps to the output value 0xffff,
-	(while having large, uniformly sized input ranges for all
-	other output values). This is undesirable, particularly when
-	we want to do optimizations for "opaque" colors specfied as
-	floating-point.
-*/
 static void
 _cairo_color_compute_shorts (cairo_color_t *color)
 {
-    color->red_short   = color->red   * color->alpha * 0xffff;
-    color->green_short = color->green * color->alpha * 0xffff;
-    color->blue_short  = color->blue  * color->alpha * 0xffff;
-    color->alpha_short = color->alpha * 0xffff;
+    color->red_short   = color->red   * color->alpha * CAIRO_COLOR_ONE_MINUS_EPSILON;
+    color->green_short = color->green * color->alpha * CAIRO_COLOR_ONE_MINUS_EPSILON;
+    color->blue_short  = color->blue  * color->alpha * CAIRO_COLOR_ONE_MINUS_EPSILON;
+    color->alpha_short = color->alpha * CAIRO_COLOR_ONE_MINUS_EPSILON;
 }
 
 void




More information about the cairo-commit mailing list