summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Canciani <ranma42@gmail.com>2010-05-23 19:15:35 +0200
committerAndrea Canciani <ranma42@gmail.com>2010-06-13 22:25:08 +0200
commit3474752d081ad91e2e1449a233f67756c009734a (patch)
tree279bed9f042427217ab1d6a566524adfc7d4e729
parentcfdf115c040dc87162cf0c6801bb6300f872a80e (diff)
-rw-r--r--src/cairo-color.c107
-rw-r--r--src/cairo-gstate.c20
-rw-r--r--src/cairo-types-private.h25
-rw-r--r--src/cairo.c2
-rw-r--r--src/cairoint.h7
5 files changed, 62 insertions, 99 deletions
diff --git a/src/cairo-color.c b/src/cairo-color.c
index 170316ae9..096ddcba4 100644
--- a/src/cairo-color.c
+++ b/src/cairo-color.c
@@ -48,12 +48,14 @@ static cairo_color_t const cairo_color_nil = {
CAIRO_REFERENCE_COUNT_INVALID,
CAIRO_STATUS_NO_MEMORY,
NULL,
- 0.0,
{
- 0.0, 0.0, 0.0, 0.0,
- 0.0, 0.0, 0.0, 0.0,
- 0.0, 0.0, 0.0, 0.0,
- 0.0, 0.0, 0.0
+ 0.0,
+ {
+ 0.0, 0.0, 0.0, 0.0,
+ 0.0, 0.0, 0.0, 0.0,
+ 0.0, 0.0, 0.0, 0.0,
+ 0.0, 0.0, 0.0
+ }
}
};
@@ -61,12 +63,14 @@ static cairo_color_t const cairo_color_white = {
CAIRO_REFERENCE_COUNT_INVALID,
CAIRO_STATUS_SUCCESS,
NULL,
- 1.0,
{
- 1.0, 0.0, 0.0, 0.0,
- 0.0, 0.0, 0.0, 0.0,
- 0.0, 0.0, 0.0, 0.0,
- 0.0, 0.0, 0.0
+ 1.0,
+ {
+ 1.0, 0.0, 0.0, 0.0,
+ 0.0, 0.0, 0.0, 0.0,
+ 0.0, 0.0, 0.0, 0.0,
+ 0.0, 0.0, 0.0
+ }
}
};
@@ -74,12 +78,14 @@ static cairo_color_t const cairo_color_black = {
CAIRO_REFERENCE_COUNT_INVALID,
CAIRO_STATUS_SUCCESS,
NULL,
- 1.0,
{
- 0.0, 0.0, 0.0, 0.0,
- 0.0, 0.0, 0.0, 0.0,
- 0.0, 0.0, 0.0, 0.0,
- 0.0, 0.0, 0.0
+ 1.0,
+ {
+ 0.0, 0.0, 0.0, 0.0,
+ 0.0, 0.0, 0.0, 0.0,
+ 0.0, 0.0, 0.0, 0.0,
+ 0.0, 0.0, 0.0
+ }
}
};
@@ -87,12 +93,14 @@ static cairo_color_t const cairo_color_transparent = {
CAIRO_REFERENCE_COUNT_INVALID,
CAIRO_STATUS_SUCCESS,
NULL,
- 0.0,
{
- 0.0, 0.0, 0.0, 0.0,
- 0.0, 0.0, 0.0, 0.0,
- 0.0, 0.0, 0.0, 0.0,
- 0.0, 0.0, 0.0
+ 0.0,
+ {
+ 0.0, 0.0, 0.0, 0.0,
+ 0.0, 0.0, 0.0, 0.0,
+ 0.0, 0.0, 0.0, 0.0,
+ 0.0, 0.0, 0.0
+ }
}
};
@@ -100,12 +108,14 @@ static cairo_color_t const cairo_color_magenta = {
CAIRO_REFERENCE_COUNT_INVALID,
CAIRO_STATUS_SUCCESS,
NULL,
- 1.0,
{
- 1.0, 0.0, 1.0, 0.0,
- 0.0, 0.0, 0.0, 0.0,
- 0.0, 0.0, 0.0, 0.0,
- 0.0, 0.0, 0.0
+ 1.0,
+ {
+ 1.0, 0.0, 1.0, 0.0,
+ 0.0, 0.0, 0.0, 0.0,
+ 0.0, 0.0, 0.0, 0.0,
+ 0.0, 0.0, 0.0
+ }
}
};
@@ -148,8 +158,8 @@ _cairo_color_init (cairo_color_t *color, cairo_color_space_t *color_space,
CAIRO_REFERENCE_COUNT_INIT (&color->ref_count, 0);
color->status = CAIRO_STATUS_SUCCESS;
color->color_space = color_space;
- color->alpha = alpha;
- memcpy (color->components, components,
+ color->components.alpha = alpha;
+ memcpy (color->components.c, components,
cairo_color_space_get_number_of_components (color_space) * sizeof (double));
}
@@ -378,7 +388,7 @@ cairo_color_get_components (const cairo_color_t *color,
double *components)
{
if (color != NULL)
- memcpy (components, color->components,
+ memcpy (components, color->components.c,
cairo_color_space_get_number_of_components (color->color_space) * sizeof (double));
}
@@ -388,7 +398,7 @@ cairo_color_get_alpha (const cairo_color_t *color)
if (color == NULL)
return 0.0;
- return color->alpha;
+ return color->components.alpha;
}
cairo_bool_t
@@ -398,41 +408,16 @@ _cairo_color_equal (const cairo_color_t *color_a,
if (color_a == color_b)
return TRUE;
- return color_a->status == color_b->status &&
- color_a->alpha == color_b->alpha &&
- _cairo_color_space_equal (color_a->color_space, color_b->color_space) &&
- !memcmp (color_a->components, color_b->components,
- cairo_color_space_get_number_of_components (color_a->color_space) * sizeof (double));
-}
-
-cairo_bool_t
-_cairo_color_stop_equal (const cairo_color_stop_t *color_a,
- const cairo_color_stop_t *color_b)
-{
- uint16_t a, b;
-
- if (color_a == color_b)
- return TRUE;
-
- if (color_a->alpha_short != color_b->alpha_short)
- return FALSE;
-
- a = _cairo_color_double_to_short (color_a->red * color_a->alpha);
- b = _cairo_color_double_to_short (color_b->red * color_b->alpha);
- if (a != b)
+ if (color_a->status != color_b->status ||
+ color_a->components.alpha != color_b->components.alpha)
return FALSE;
- a = _cairo_color_double_to_short (color_a->green * color_a->alpha);
- b = _cairo_color_double_to_short (color_b->green * color_b->alpha);
- if (a != b)
- return FALSE;
-
- a = _cairo_color_double_to_short (color_a->blue * color_a->alpha);
- b = _cairo_color_double_to_short (color_b->blue * color_b->alpha);
- if (a != b)
- return FALSE;
+ if (CAIRO_COLOR_IS_CLEAR (color_a))
+ return TRUE;
- return TRUE;
+ return _cairo_color_space_equal (color_a->color_space, color_b->color_space) &&
+ !memcmp (color_a->components.c, color_b->components.c,
+ cairo_color_space_get_number_of_components (color_a->color_space) * sizeof (double));
}
cairo_content_t
diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c
index b05e7c3ad..c10bc3630 100644
--- a/src/cairo-gstate.c
+++ b/src/cairo-gstate.c
@@ -991,24 +991,8 @@ _reduce_op (cairo_gstate_t *gstate)
if (op != CAIRO_OPERATOR_SOURCE)
return op;
- pattern = gstate->source;
- if (pattern->type == CAIRO_PATTERN_TYPE_SOLID) {
- const cairo_solid_pattern_t *solid = (cairo_solid_pattern_t *) pattern;
- if (solid->color.alpha_short <= 0x00ff) {
- op = CAIRO_OPERATOR_CLEAR;
- }
- } else if (pattern->type == CAIRO_PATTERN_TYPE_SURFACE) {
- const cairo_surface_pattern_t *surface = (cairo_surface_pattern_t *) pattern;
- if (surface->surface->is_clear &&
- surface->surface->content & CAIRO_CONTENT_ALPHA)
- {
- op = CAIRO_OPERATOR_CLEAR;
- }
- } else {
- const cairo_gradient_pattern_t *gradient = (cairo_gradient_pattern_t *) pattern;
- if (gradient->n_stops == 0)
- op = CAIRO_OPERATOR_CLEAR;
- }
+ if (_cairo_pattern_is_clear (pattern))
+ op = CAIRO_OPERATOR_CLEAR;
return op;
}
diff --git a/src/cairo-types-private.h b/src/cairo-types-private.h
index 7f280994e..cab5b90c6 100644
--- a/src/cairo-types-private.h
+++ b/src/cairo-types-private.h
@@ -48,6 +48,7 @@ typedef struct _cairo_array cairo_array_t;
typedef struct _cairo_backend cairo_backend_t;
typedef struct _cairo_boxes_t cairo_boxes_t;
typedef struct _cairo_cache cairo_cache_t;
+typedef struct _cairo_color_components cairo_color_components_t;
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;
@@ -142,26 +143,16 @@ struct _cairo_color_space {
#define MAX_COLOR_COMPONENTS 15
+struct _cairo_color_components {
+ double alpha;
+ double c[MAX_COLOR_COMPONENTS];
+};
+
struct _cairo_color {
cairo_reference_count_t ref_count;
cairo_status_t status;
cairo_color_space_t *color_space;
- double alpha;
- double components[MAX_COLOR_COMPONENTS];
-};
-
-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;
+ cairo_color_components_t components;
};
typedef enum _cairo_paginated_mode {
@@ -368,7 +359,7 @@ typedef struct _cairo_surface_pattern {
typedef struct _cairo_gradient_stop {
double offset;
- cairo_color_stop_t color;
+ cairo_color_components_t components;
} cairo_gradient_stop_t;
typedef struct _cairo_gradient_pattern {
diff --git a/src/cairo.c b/src/cairo.c
index 9d28aeeb3..aebb42094 100644
--- a/src/cairo.c
+++ b/src/cairo.c
@@ -2193,7 +2193,7 @@ cairo_paint_with_alpha (cairo_t *cr,
return;
}
- if (CAIRO_ALPHA_IS_ZERO (alpha) &&
+ if (CAIRO_ALPHA_IS_CLEAR (alpha) &&
_cairo_operator_bounded_by_mask (cr->gstate->op)) {
return;
}
diff --git a/src/cairoint.h b/src/cairoint.h
index a560c1d5c..102df7493 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -148,8 +148,11 @@ do { \
#define CAIRO_ALPHA_IS_OPAQUE(alpha) ((alpha) >= 1.0)
#define CAIRO_ALPHA_IS_CLEAR(alpha) ((alpha) <= 0.0)
-#define CAIRO_COLOR_IS_OPAQUE(color) CAIRO_ALPHA_IS_OPAQUE ((color)->alpha)
-#define CAIRO_COLOR_IS_CLEAR(color) CAIRO_ALPHA_IS_CLEAR ((color)->alpha)
+#define CAIRO_COMPONENTS_IS_OPAQUE(c) CAIRO_ALPHA_IS_OPAQUE ((c)->alpha)
+#define CAIRO_COMPONENTS_IS_CLEAR(c) CAIRO_ALPHA_IS_CLEAR ((c)->alpha)
+
+#define CAIRO_COLOR_IS_OPAQUE(color) CAIRO_COMPONENTS_IS_OPAQUE (&(color)->components)
+#define CAIRO_COLOR_IS_CLEAR(color) CAIRO_COMPONENTS_IS_CLEAR (&(color)->components)
/* Reverse the bits in a byte with 7 operations (no 64-bit):
* Devised by Sean Anderson, July 13, 2001.