diff options
author | Andrea Canciani <ranma42@gmail.com> | 2010-12-29 00:56:22 +0100 |
---|---|---|
committer | Andrea Canciani <ranma42@gmail.com> | 2010-12-29 00:56:22 +0100 |
commit | a2afb7b65c6aa30c8559d75b911e803dd5e24232 (patch) | |
tree | 0f435e33171b531fcd72cf058115c44807808bca | |
parent | 6ba74aa10ed96dcddb6c5402c7c80ff368350c3f (diff) |
wipwip/cs5
-rw-r--r-- | src/cairo-gstate.c | 10 | ||||
-rw-r--r-- | src/cairo-pattern.c | 89 | ||||
-rw-r--r-- | src/cairo.c | 4 | ||||
-rw-r--r-- | src/cairo.h | 4 | ||||
-rw-r--r-- | src/cairoint.h | 8 |
5 files changed, 91 insertions, 24 deletions
diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c index e60cf64c1..0a6b0733b 100644 --- a/src/cairo-gstate.c +++ b/src/cairo-gstate.c @@ -878,21 +878,19 @@ _cairo_gstate_copy_pattern (cairo_pattern_t *pattern, */ if (_cairo_pattern_is_clear (original)) { - _cairo_pattern_init_solid ((cairo_solid_pattern_t *) pattern, - CAIRO_COLOR_CLEAR); + _cairo_pattern_init_solid ((cairo_solid_pattern_t *) pattern, NULL, NULL, 0); return; } if (original->type == CAIRO_PATTERN_TYPE_LINEAR || original->type == CAIRO_PATTERN_TYPE_RADIAL) { - cairo_color_t color; + double components[MAX_COLOR_COMPONENTS], alpha; if (_cairo_gradient_pattern_is_solid ((cairo_gradient_pattern_t *) original, - NULL, - &color)) + NULL, &components, &alpha)) { _cairo_pattern_init_solid ((cairo_solid_pattern_t *) pattern, - &color); + components, alpha); return; } } diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c index c75447fb8..9008923b1 100644 --- a/src/cairo-pattern.c +++ b/src/cairo-pattern.c @@ -420,12 +420,12 @@ _cairo_pattern_create_copy (cairo_pattern_t **pattern_out, void _cairo_pattern_init_solid (cairo_solid_pattern_t *pattern, - const cairo_color_t *color) + cairo_color_space_t *color_space, + const double *components, + double alpha) { _cairo_pattern_init (&pattern->base, CAIRO_PATTERN_TYPE_SOLID); - pattern->color = *color; - cairo_color_space_reference (pattern->color.color_space); - /* TODO: make pattern->color a cairo_color_t* */ + cairo_color_create_alpha (&pattern->color, color_space, components, alpha); } void @@ -579,18 +579,47 @@ cairo_pattern_t * cairo_pattern_create_rgba (double red, double green, double blue, double alpha) { - cairo_color_t color; + double components[3]; - red = _cairo_restrict_value (red, 0.0, 1.0); - green = _cairo_restrict_value (green, 0.0, 1.0); - blue = _cairo_restrict_value (blue, 0.0, 1.0); + components[0] = _cairo_restrict_value (red, 0.0, 1.0); + components[1] = _cairo_restrict_value (green, 0.0, 1.0); + components[2] = _cairo_restrict_value (blue, 0.0, 1.0); alpha = _cairo_restrict_value (alpha, 0.0, 1.0); - _cairo_color_init_rgba (&color, red, green, blue, alpha); + return cairo_pattern_create_color (CAIRO_COLOR_SPACE_DEVICE_RGB, + components, alpha); +} +slim_hidden_def (cairo_pattern_create_rgba); +/** + * cairo_pattern_create_rgba: + * @red: red component of the color + * @green: green component of the color + * @blue: blue component of the color + * @alpha: alpha component of the color + * + * Creates a new #cairo_pattern_t corresponding to a translucent color. + * The color components are floating point numbers in the range 0 to + * 1. If the values passed in are outside that range, they will be + * clamped. + * + * Return value: the newly created #cairo_pattern_t if successful, or + * an error pattern in case of no memory. The caller owns the + * returned object and should call cairo_pattern_destroy() when + * finished with it. + * + * This function will always return a valid pointer, but if an error + * occurred the pattern status will be set to an error. To inspect + * the status of a pattern use cairo_pattern_status(). + **/ +cairo_pattern_t * +cairo_pattern_create_color (cairo_color_space_t *color_space, + double *components, + double alpha) +{ CAIRO_MUTEX_INITIALIZE (); - return _cairo_pattern_create_solid (&color); + return _cairo_pattern_create_solid (color_space, components, alpha); } slim_hidden_def (cairo_pattern_create_rgba); @@ -759,6 +788,44 @@ cairo_pattern_t * cairo_pattern_create_radial (double cx0, double cy0, double radius0, double cx1, double cy1, double radius1) { + return cairo_pattern_create_radial_with_color_space (CAIRO_COLOR_SPACE_DEVICE_RGB, + cx0, cy0, radius0, + cx1, cy1, radius1); +} + +/** + * cairo_pattern_create_radial: + * @cx0: x coordinate for the center of the start circle + * @cy0: y coordinate for the center of the start circle + * @radius0: radius of the start circle + * @cx1: x coordinate for the center of the end circle + * @cy1: y coordinate for the center of the end circle + * @radius1: radius of the end circle + * + * Creates a new radial gradient #cairo_pattern_t between the two + * circles defined by (cx0, cy0, radius0) and (cx1, cy1, radius1). Before using the + * gradient pattern, a number of color stops should be defined using + * cairo_pattern_add_color_stop_rgb() or + * cairo_pattern_add_color_stop_rgba(). + * + * Note: The coordinates here are in pattern space. For a new pattern, + * pattern space is identical to user space, but the relationship + * between the spaces can be changed with cairo_pattern_set_matrix(). + * + * Return value: the newly created #cairo_pattern_t if successful, or + * an error pattern in case of no memory. The caller owns the + * returned object and should call cairo_pattern_destroy() when + * finished with it. + * + * This function will always return a valid pointer, but if an error + * occurred the pattern status will be set to an error. To inspect + * the status of a pattern use cairo_pattern_status(). + **/ +cairo_pattern_t * +cairo_pattern_create_radial_with_color_space (cairo_color_space_t *color_space, + double cx0, double cy0, double radius0, + double cx1, double cy1, double radius1) +{ cairo_radial_pattern_t *pattern; pattern = @@ -773,7 +840,7 @@ cairo_pattern_create_radial (double cx0, double cy0, double radius0, CAIRO_MUTEX_INITIALIZE (); - _cairo_pattern_init_radial (pattern, cx0, cy0, radius0, cx1, cy1, radius1); + _cairo_pattern_init_radial (pattern, color_space, cx0, cy0, radius0, cx1, cy1, radius1); CAIRO_REFERENCE_COUNT_INIT (&pattern->base.base.ref_count, 1); return &pattern->base.base; diff --git a/src/cairo.c b/src/cairo.c index 5e405c754..a56aea2b9 100644 --- a/src/cairo.c +++ b/src/cairo.c @@ -2262,7 +2262,6 @@ cairo_paint_with_alpha (cairo_t *cr, double alpha) { cairo_status_t status; - cairo_color_t color; cairo_solid_pattern_t pattern; if (unlikely (cr->status)) @@ -2278,8 +2277,7 @@ cairo_paint_with_alpha (cairo_t *cr, return; } - _cairo_color_init_rgba (&color, 0., 0., 0., alpha); - _cairo_pattern_init_solid (&pattern, &color); + _cairo_pattern_init_solid (&pattern, NULL, NULL, alpha); status = _cairo_gstate_mask (cr->gstate, &pattern.base); if (unlikely (status)) diff --git a/src/cairo.h b/src/cairo.h index b3b178177..ab6228a22 100644 --- a/src/cairo.h +++ b/src/cairo.h @@ -2420,7 +2420,9 @@ cairo_pattern_create_rgba (double red, double green, double blue, double alpha); cairo_public cairo_pattern_t * -cairo_pattern_create_color (cairo_color_t *color); +cairo_pattern_create_color (cairo_color_space_t *color_space, + double *components, + double alpha); cairo_public cairo_pattern_t * cairo_pattern_create_for_surface (cairo_surface_t *surface); diff --git a/src/cairoint.h b/src/cairoint.h index 9aca6c80b..a8208fc33 100644 --- a/src/cairoint.h +++ b/src/cairoint.h @@ -2201,8 +2201,10 @@ _cairo_pattern_init_snapshot (cairo_pattern_t *pattern, const cairo_pattern_t *other); cairo_private void -_cairo_pattern_init_solid (cairo_solid_pattern_t *pattern, - const cairo_color_t *color); +_cairo_pattern_init_solid (cairo_solid_pattern_t *pattern, + cairo_color_space_t *color_space, + const double *components, + double alpha); cairo_private void _cairo_pattern_init_for_surface (cairo_surface_pattern_t *pattern, @@ -2225,7 +2227,7 @@ _cairo_pattern_alpha_range (const cairo_pattern_t *gradient, cairo_private cairo_bool_t _cairo_gradient_pattern_is_solid (const cairo_gradient_pattern_t *gradient, const cairo_rectangle_int_t *extents, - cairo_color_t *color); + double *components, double alpha); cairo_private void _cairo_gradient_pattern_box_to_parameter (const cairo_gradient_pattern_t *gradient, |