From d45b3168db2362eaaa8ee29fc653509bc8f67e65 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 5 Sep 2008 06:58:56 +0100 Subject: [PATCH] [ps] Use a color_t rather than open-code. Simplify the code by tracking the current solid color with a cairo_color_t. --- src/cairo-ps-surface-private.h | 5 +---- src/cairo-ps-surface.c | 10 ++-------- src/cairo-types-private.h | 18 ++++++++++++++++++ src/cairoint.h | 18 ------------------ 4 files changed, 21 insertions(+), 30 deletions(-) diff --git a/src/cairo-ps-surface-private.h b/src/cairo-ps-surface-private.h index 79ac983ae..e78833d05 100644 --- a/src/cairo-ps-surface-private.h +++ b/src/cairo-ps-surface-private.h @@ -72,10 +72,7 @@ typedef struct cairo_ps_surface { cairo_bool_t use_string_datasource; cairo_bool_t current_pattern_is_solid_color; - double current_color_red; - double current_color_green; - double current_color_blue; - double current_color_alpha; + cairo_color_t current_color; int num_pages; diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c index bb80651d5..c1ec6ad6d 100644 --- a/src/cairo-ps-surface.c +++ b/src/cairo-ps-surface.c @@ -2818,10 +2818,7 @@ _cairo_ps_surface_emit_pattern (cairo_ps_surface_t *surface, cairo_solid_pattern_t *solid = (cairo_solid_pattern_t *) pattern; if (surface->current_pattern_is_solid_color == FALSE || - surface->current_color_red != solid->color.red || - surface->current_color_green != solid->color.green || - surface->current_color_blue != solid->color.blue || - surface->current_color_alpha != solid->color.alpha) + ! _cairo_color_equal (&surface->current_color, &solid->color)) { status = _cairo_pdf_operators_flush (&surface->pdf_operators); if (status) @@ -2830,10 +2827,7 @@ _cairo_ps_surface_emit_pattern (cairo_ps_surface_t *surface, _cairo_ps_surface_emit_solid_pattern (surface, (cairo_solid_pattern_t *) pattern); surface->current_pattern_is_solid_color = TRUE; - surface->current_color_red = solid->color.red; - surface->current_color_green = solid->color.green; - surface->current_color_blue = solid->color.blue; - surface->current_color_alpha = solid->color.alpha; + surface->current_color = solid->color; } return CAIRO_STATUS_SUCCESS; diff --git a/src/cairo-types-private.h b/src/cairo-types-private.h index 91bfa8a5d..c2d962def 100644 --- a/src/cairo-types-private.h +++ b/src/cairo-types-private.h @@ -134,6 +134,24 @@ struct _cairo_cache { int freeze_count; }; +/* XXX: Right now, the _cairo_color structure puts unpremultiplied + color in the doubles and premultiplied color in the shorts. Yes, + this is crazy insane, (but at least we don't export this + madness). I'm still working on a cleaner API, but in the meantime, + at least this does prevent precision loss in color when changing + alpha. */ +struct _cairo_color { + double red; + double green; + double blue; + double alpha; + + unsigned short red_short; + unsigned short green_short; + unsigned short blue_short; + unsigned short alpha_short; +}; + typedef enum _cairo_paginated_mode { CAIRO_PAGINATED_MODE_ANALYZE, /* analyze page regions */ CAIRO_PAGINATED_MODE_RENDER, /* render page contents */ diff --git a/src/cairoint.h b/src/cairoint.h index bffceb3e0..654fd196b 100644 --- a/src/cairoint.h +++ b/src/cairoint.h @@ -818,24 +818,6 @@ struct _cairo_image_surface { extern const cairo_private cairo_surface_backend_t _cairo_image_surface_backend; -/* XXX: Right now, the _cairo_color structure puts unpremultiplied - color in the doubles and premultiplied color in the shorts. Yes, - this is crazy insane, (but at least we don't export this - madness). I'm still working on a cleaner API, but in the meantime, - at least this does prevent precision loss in color when changing - alpha. */ -struct _cairo_color { - double red; - double green; - double blue; - double alpha; - - unsigned short red_short; - unsigned short green_short; - unsigned short blue_short; - unsigned short alpha_short; -}; - #define CAIRO_EXTEND_SURFACE_DEFAULT CAIRO_EXTEND_NONE #define CAIRO_EXTEND_GRADIENT_DEFAULT CAIRO_EXTEND_PAD #define CAIRO_FILTER_DEFAULT CAIRO_FILTER_GOOD