[cairo-commit] src/cairo-color.c src/cairo-gstate.c src/cairoint.h src/cairo-pattern.c src/cairo-pdf-surface.c src/cairo-ps-surface.c src/cairo-svg-surface.c src/cairo-types-private.h

Chris Wilson ickle at kemper.freedesktop.org
Thu May 13 02:01:34 PDT 2010


 src/cairo-color.c         |    4 ++--
 src/cairo-gstate.c        |    2 +-
 src/cairo-pattern.c       |    2 +-
 src/cairo-pdf-surface.c   |    9 ---------
 src/cairo-ps-surface.c    |   32 ++------------------------------
 src/cairo-svg-surface.c   |    4 ++--
 src/cairo-types-private.h |   17 ++++++++++++++++-
 src/cairoint.h            |    4 ++--
 8 files changed, 26 insertions(+), 48 deletions(-)

New commits:
commit 18b48a6ebc044c07f08bafd0abcb68c595c5746c
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu May 13 10:00:18 2010 +0100

    Make cairo_color_stop_t a unique type.
    
    Hopefully reduce the occurrence of the confusion between the
    premultiplied shorts in cairo_color_t and the non-premultiplied shorts
    in cairo_color_stop_t.
    
    The existence of the two separate types is debatable and open for
    review.

diff --git a/src/cairo-color.c b/src/cairo-color.c
index d6c6c3d..ddba5ca 100644
--- a/src/cairo-color.c
+++ b/src/cairo-color.c
@@ -176,8 +176,8 @@ _cairo_color_equal (const cairo_color_t *color_a,
 }
 
 cairo_bool_t
-_cairo_color_stop_equal (const cairo_color_t *color_a,
-			 const cairo_color_t *color_b)
+_cairo_color_stop_equal (const cairo_color_stop_t *color_a,
+			 const cairo_color_stop_t *color_b)
 {
     uint16_t a, b;
 
diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c
index c3f63db..0012558 100644
--- a/src/cairo-gstate.c
+++ b/src/cairo-gstate.c
@@ -837,7 +837,7 @@ _cairo_gstate_path_extents (cairo_gstate_t     *gstate,
 
 static void
 _init_solid_for_color_stop (cairo_solid_pattern_t *solid,
-			    const cairo_color_t *color)
+			    const cairo_color_stop_t *color)
 {
     cairo_color_t premult;
 
diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c
index 2fea11a..d3dca9d 100644
--- a/src/cairo-pattern.c
+++ b/src/cairo-pattern.c
@@ -2201,7 +2201,7 @@ _cairo_pattern_acquire_surface_for_surface (const cairo_surface_pattern_t   *pat
 
 static void
 _init_solid_for_color_stop (cairo_solid_pattern_t *solid,
-			    const cairo_color_t *color)
+			    const cairo_color_stop_t *color)
 {
     cairo_color_t premult;
 
diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index da51295..091ed58 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -3419,15 +3419,6 @@ _cairo_pdf_surface_select_pattern (cairo_pdf_surface_t *surface,
 	solid_color = &solid->color;
     }
 
-    if (pattern->type == CAIRO_PATTERN_TYPE_LINEAR ||
-	pattern->type == CAIRO_PATTERN_TYPE_RADIAL)
-    {
-	cairo_gradient_pattern_t *gradient = (cairo_gradient_pattern_t *) pattern;
-
-	if (gradient->n_stops == 1)
-	    solid_color = &gradient->stops[0].color;
-    }
-
     if (solid_color != NULL) {
 	if (surface->current_pattern_is_solid_color == FALSE ||
 	    surface->current_color_red != solid_color->red ||
diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 8bfdc5a..71d10b8 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -3176,21 +3176,7 @@ _cairo_ps_surface_emit_linear_pattern (cairo_ps_surface_t     *surface,
     double first_stop, last_stop;
     int repeat_begin = 0, repeat_end = 1;
 
-    if (pattern->base.n_stops == 0)
-        return CAIRO_INT_STATUS_NOTHING_TO_DO;
-
-    if (pattern->base.n_stops == 1) {
-	cairo_solid_pattern_t solid;
-
-	_cairo_pattern_init_solid (&solid,
-				   &pattern->base.stops[0].color,
-				   CAIRO_CONTENT_COLOR_ALPHA);
-	_cairo_ps_surface_emit_solid_pattern (surface,
-					      &solid);
-	_cairo_pattern_fini (&solid.base);
-
-	return CAIRO_STATUS_SUCCESS;
-    }
+    assert (pattern->base.n_stops >= 2);
 
     extend = cairo_pattern_get_extend (&pattern->base.base);
 
@@ -3316,21 +3302,7 @@ _cairo_ps_surface_emit_radial_pattern (cairo_ps_surface_t     *surface,
     cairo_extend_t extend;
     cairo_status_t status;
 
-    if (pattern->base.n_stops == 0)
-        return CAIRO_INT_STATUS_NOTHING_TO_DO;
-
-    if (pattern->base.n_stops == 1) {
-	cairo_solid_pattern_t solid;
-
-	_cairo_pattern_init_solid (&solid,
-				   &pattern->base.stops[0].color,
-				   CAIRO_CONTENT_COLOR_ALPHA);
-	_cairo_ps_surface_emit_solid_pattern (surface,
-					      &solid);
-	_cairo_pattern_fini (&solid.base);
-
-	return CAIRO_STATUS_SUCCESS;
-    }
+    assert (pattern->base.n_stops >= 2);
 
     extend = cairo_pattern_get_extend (&pattern->base.base);
 
diff --git a/src/cairo-svg-surface.c b/src/cairo-svg-surface.c
index 4247415..f83e44c 100644
--- a/src/cairo-svg-surface.c
+++ b/src/cairo-svg-surface.c
@@ -1643,14 +1643,14 @@ _cairo_svg_surface_emit_pattern_stops (cairo_output_stream_t          *output,
     else {
 	cairo_bool_t found = FALSE;
 	unsigned int offset_index;
-	cairo_color_t offset_color_start, offset_color_stop;
+	cairo_color_stop_t offset_color_start, offset_color_stop;
 
 	for (i = 0; i < n_stops; i++) {
 	    if (stops[i].offset >= -start_offset) {
 		if (i > 0) {
 		    if (stops[i].offset != stops[i-1].offset) {
 			double x0, x1;
-			cairo_color_t *color0, *color1;
+			cairo_color_stop_t *color0, *color1;
 
 			x0 = stops[i-1].offset;
 			x1 = stops[i].offset;
diff --git a/src/cairo-types-private.h b/src/cairo-types-private.h
index 6657de8..fa65677 100644
--- a/src/cairo-types-private.h
+++ b/src/cairo-types-private.h
@@ -52,6 +52,7 @@ typedef struct _cairo_composite_rectangles cairo_composite_rectangles_t;
 typedef struct _cairo_clip cairo_clip_t;
 typedef struct _cairo_clip_path cairo_clip_path_t;
 typedef struct _cairo_color cairo_color_t;
+typedef struct _cairo_color_stop cairo_color_stop_t;
 typedef struct _cairo_device_backend cairo_device_backend_t;
 typedef struct _cairo_font_face_backend     cairo_font_face_backend_t;
 typedef struct _cairo_gstate cairo_gstate_t;
@@ -147,6 +148,20 @@ struct _cairo_color {
     unsigned short alpha_short;
 };
 
+struct _cairo_color_stop {
+    /* unpremultiplied */
+    double red;
+    double green;
+    double blue;
+    double alpha;
+
+    /* unpremultipled, for convenience */
+    uint16_t red_short;
+    uint16_t green_short;
+    uint16_t blue_short;
+    uint16_t alpha_short;
+};
+
 typedef enum _cairo_paginated_mode {
     CAIRO_PAGINATED_MODE_ANALYZE,	/* analyze page regions */
     CAIRO_PAGINATED_MODE_RENDER,	/* render page contents */
@@ -352,7 +367,7 @@ typedef struct _cairo_surface_pattern {
 
 typedef struct _cairo_gradient_stop {
     double offset;
-    cairo_color_t color;
+    cairo_color_stop_t color;
 } cairo_gradient_stop_t;
 
 typedef struct _cairo_gradient_pattern {
diff --git a/src/cairoint.h b/src/cairoint.h
index 6fe3702..d283c69 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -1310,8 +1310,8 @@ _cairo_color_equal (const cairo_color_t *color_a,
                     const cairo_color_t *color_b) cairo_pure;
 
 cairo_private cairo_bool_t
-_cairo_color_stop_equal (const cairo_color_t *color_a,
-			 const cairo_color_t *color_b) cairo_pure;
+_cairo_color_stop_equal (const cairo_color_stop_t *color_a,
+			 const cairo_color_stop_t *color_b) cairo_pure;
 
 /* cairo-font-face.c */
 


More information about the cairo-commit mailing list