[cairo] Two small patches

Behdad Esfahbod behdad at cs.toronto.edu
Tue Aug 2 18:38:03 PDT 2005


Hi,

Attached are the following patches:

* cairo-path-noop.patch:  This basically modifies
cairo_append_path in a number of ways:

  - Checks are moved before the actually call.  This is a bug fix.

  - Does not err if there are excess elements in the path.
Means, if there are more points than needed for an operation.
This way applications may store private data in a path structure.
Would be good to know if people see any obvious problem with
allowing that.

  - Adds a CAIRO_PATH_NOOP operation, that cairo simply ignores.
That's to expand the functionality from last item, to allow for
application-specific operations.


* cairo-color.patch should be self-explanatory.


--behdad
http://behdad.org/
-------------- next part --------------
Index: src/cairo.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo.h,v
retrieving revision 1.144
diff -u -p -r1.144 cairo.h
--- src/cairo.h	1 Aug 2005 20:33:47 -0000	1.144
+++ src/cairo.h	3 Aug 2005 01:18:49 -0000
@@ -998,6 +996,11 @@ cairo_get_target (cairo_t *cr);
  *	    case CAIRO_PATH_CLOSE_PATH:
  *		do_close_path_things ();
  *		break;
+ *	    case CAIRO_PATH_NOOP:
+ *		// do nothing, simply skip
+ *		break;
+ *	    default:
+ *		error_invalid_path ();
  *	    }
  *	}
  *
@@ -1008,7 +1011,8 @@ typedef enum _cairo_path_data_type {
     CAIRO_PATH_MOVE_TO,
     CAIRO_PATH_LINE_TO,
     CAIRO_PATH_CURVE_TO,
-    CAIRO_PATH_CLOSE_PATH
+    CAIRO_PATH_CLOSE_PATH,
+    CAIRO_PATH_NOOP
 } cairo_path_data_type_t;
 
 typedef union {
Index: src/cairo-path-data.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-path-data.c,v
retrieving revision 1.9
diff -u -p -r1.9 cairo-path-data.c
--- src/cairo-path-data.c	28 Jul 2005 16:46:38 -0000	1.9
+++ src/cairo-path-data.c	3 Aug 2005 01:18:49 -0000
@@ -454,28 +454,32 @@ _cairo_path_data_append_to_context (cair
 	p = &path->data[i];
 	switch (p->header.type) {
 	case CAIRO_PATH_MOVE_TO:
+	    if (p->header.length < 2)
+		return CAIRO_STATUS_INVALID_PATH_DATA;
 	    cairo_move_to (cr,
 			   p[1].point.x, p[1].point.y);
-	    if (p->header.length != 2)
-		return CAIRO_STATUS_INVALID_PATH_DATA;
 	    break;
 	case CAIRO_PATH_LINE_TO:
+	    if (p->header.length < 2)
+		return CAIRO_STATUS_INVALID_PATH_DATA;
 	    cairo_line_to (cr,
 			   p[1].point.x, p[1].point.y);
-	    if (p->header.length != 2)
-		return CAIRO_STATUS_INVALID_PATH_DATA;
 	    break;
 	case CAIRO_PATH_CURVE_TO:
+	    if (p->header.length < 4)
+		return CAIRO_STATUS_INVALID_PATH_DATA;
 	    cairo_curve_to (cr,
 			    p[1].point.x, p[1].point.y,
 			    p[2].point.x, p[2].point.y,
 			    p[3].point.x, p[3].point.y);
-	    if (p->header.length != 4)
-		return CAIRO_STATUS_INVALID_PATH_DATA;
 	    break;
 	case CAIRO_PATH_CLOSE_PATH:
+	    if (p->header.length < 1)
+		return CAIRO_STATUS_INVALID_PATH_DATA;
 	    cairo_close_path (cr);
-	    if (p->header.length != 1)
+	    break;
+	case CAIRO_PATH_NOOP:
+	    if (p->header.length < 1)
 		return CAIRO_STATUS_INVALID_PATH_DATA;
 	    break;
 	default:
-------------- next part --------------
Index: src/cairo-color.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-color.c,v
retrieving revision 1.14
diff -u -p -r1.14 cairo-color.c
--- src/cairo-color.c	14 Apr 2005 21:42:26 -0000	1.14
+++ src/cairo-color.c	3 Aug 2005 01:32:54 -0000
@@ -89,29 +89,19 @@ _cairo_color_init_rgb (cairo_color_t *co
     _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 COLOR_MAGIC_MULT (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 * COLOR_MAGIC_MULT;
+    color->green_short = color->green * color->alpha * COLOR_MAGIC_MULT;
+    color->blue_short  = color->blue  * color->alpha * COLOR_MAGIC_MULT;
+    color->alpha_short = color->alpha * COLOR_MAGIC_MULT;
 }
 
 void


More information about the cairo mailing list