diff options
author | Andrea Canciani <ranma42@gmail.com> | 2011-01-12 12:37:33 +0100 |
---|---|---|
committer | Andrea Canciani <ranma42@gmail.com> | 2011-02-15 08:08:01 +0100 |
commit | d196d6926b9d57cbea35a0187b6f1d1ab50d2e27 (patch) | |
tree | 2fb5e075ae7e3f5d1c046b6f5ba62b5a0f1bd02f | |
parent | dc886401df6ac789b5c788f75f1902d17f9e0c4f (diff) |
pattern
-rw-r--r-- | src/cairo-pattern.c | 162 | ||||
-rw-r--r-- | src/cairo.h | 10 |
2 files changed, 150 insertions, 22 deletions
diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c index 1d488dd49..5f5fa51e7 100644 --- a/src/cairo-pattern.c +++ b/src/cairo-pattern.c @@ -497,21 +497,24 @@ _cairo_pattern_init_for_surface (cairo_surface_pattern_t *pattern, static void _cairo_pattern_init_gradient (cairo_gradient_pattern_t *pattern, - cairo_pattern_type_t type) + cairo_color_space_t *color_space, + cairo_pattern_type_t type) { _cairo_pattern_init (&pattern->base, type); - pattern->color_space = (cairo_color_space_t *) &_cairo_color_space_device_rgb; - pattern->n_stops = 0; - pattern->stops_size = 0; - pattern->stops = NULL; + pattern->color_space = cairo_color_space_reference (color_space); + pattern->n_stops = 0; + pattern->stops_size = 0; + pattern->stops = NULL; } static void _cairo_pattern_init_linear (cairo_linear_pattern_t *pattern, + cairo_color_space_t *color_space, double x0, double y0, double x1, double y1) { - _cairo_pattern_init_gradient (&pattern->base, CAIRO_PATTERN_TYPE_LINEAR); + _cairo_pattern_init_gradient (&pattern->base, color_space, + CAIRO_PATTERN_TYPE_LINEAR); pattern->pd1.x = x0; pattern->pd1.y = y0; @@ -521,10 +524,12 @@ _cairo_pattern_init_linear (cairo_linear_pattern_t *pattern, static void _cairo_pattern_init_radial (cairo_radial_pattern_t *pattern, + cairo_color_space_t *color_space, double cx0, double cy0, double radius0, double cx1, double cy1, double radius1) { - _cairo_pattern_init_gradient (&pattern->base, CAIRO_PATTERN_TYPE_RADIAL); + _cairo_pattern_init_gradient (&pattern->base, color_space, + CAIRO_PATTERN_TYPE_RADIAL); pattern->cd1.center.x = cx0; pattern->cd1.center.y = cy0; @@ -626,16 +631,56 @@ cairo_pattern_t * cairo_pattern_create_rgba (double red, double green, double blue, double alpha) { - cairo_color_components_t components; + double components[3]; + + 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); - components.argb.red = _cairo_restrict_value (red, 0.0, 1.0); - components.argb.green = _cairo_restrict_value (green, 0.0, 1.0); - components.argb.blue = _cairo_restrict_value (blue, 0.0, 1.0); - components.argb.alpha = _cairo_restrict_value (alpha, 0.0, 1.0); + 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_color_components_t c; + int i, n; + + n = cairo_color_space_get_number_of_components (color_space); + c = *CAIRO_COMPONENTS_CLEAR; + c.generic.alpha = alpha; + for (i = 0; i < n; i++) + c.generic.c[i] = components[i]; CAIRO_MUTEX_INITIALIZE (); - return _cairo_pattern_create_solid (CAIRO_COLOR_SPACE_DEVICE_RGB, &components); + return _cairo_pattern_create_solid (color_space, &c); } slim_hidden_def (cairo_pattern_create_rgba); @@ -715,6 +760,43 @@ slim_hidden_def (cairo_pattern_create_for_surface); cairo_pattern_t * cairo_pattern_create_linear (double x0, double y0, double x1, double y1) { + return cairo_pattern_create_linear_with_color_space (CAIRO_COLOR_SPACE_DEVICE_RGB, + x0, y0, x1, y1); +} + +/** + * cairo_pattern_create_linear_with_color_space: + * @x0: x coordinate of the start point + * @y0: y coordinate of the start point + * @x1: x coordinate of the end point + * @y1: y coordinate of the end point + * + * Create a new linear gradient #cairo_pattern_t along the line defined + * by (x0, y0) and (x1, y1). 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_linear_with_color_space (cairo_color_space_t *color_space, + double x0, + double y0, + double x1, + double y1) +{ cairo_linear_pattern_t *pattern; pattern = @@ -729,7 +811,7 @@ cairo_pattern_create_linear (double x0, double y0, double x1, double y1) CAIRO_MUTEX_INITIALIZE (); - _cairo_pattern_init_linear (pattern, x0, y0, x1, y1); + _cairo_pattern_init_linear (pattern, color_space, x0, y0, x1, y1); CAIRO_REFERENCE_COUNT_INIT (&pattern->base.base.ref_count, 1); return &pattern->base.base; @@ -767,6 +849,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 = @@ -781,7 +901,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; @@ -2163,7 +2283,7 @@ _cairo_pattern_acquire_surface_for_gradient (const cairo_gradient_pattern_t *pat image = (cairo_image_surface_t *) _cairo_image_surface_create_for_pixman_image (pixman_image, PIXMAN_a8r8g8b8, - (cairo_color_space_t *) &_cairo_color_space_device_rgb); + CAIRO_COLOR_SPACE_DEVICE_RGB); if (image->base.status) { pixman_image_unref (pixman_image); @@ -4630,6 +4750,8 @@ cairo_pattern_get_color_space (cairo_pattern_t *pattern) return cairo_color_space_reference (punion->gradient.base.color_space); case CAIRO_PATTERN_TYPE_SURFACE: return cairo_color_space_reference (punion->surface.surface->color_space); + case CAIRO_PATTERN_TYPE_MESH: + return cairo_color_space_reference (punion->mesh.color_space); default: ASSERT_NOT_REACHED; return NULL; @@ -4665,9 +4787,7 @@ cairo_pattern_get_rgba (cairo_pattern_t *pattern, if (pattern->type != CAIRO_PATTERN_TYPE_SOLID) return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH); - assert (solid->color_space == CAIRO_COLOR_SPACE_DEVICE_RGB); - - if (solid->color_space != &_cairo_color_space_device_rgb) + if (solid->color_space != CAIRO_COLOR_SPACE_DEVICE_RGB) return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH); // COLORSPACE_MISMATCH? if (red) @@ -4754,9 +4874,7 @@ cairo_pattern_get_color_stop_rgba (cairo_pattern_t *pattern, if (index < 0 || (unsigned int) index >= gradient->n_stops) return _cairo_error (CAIRO_STATUS_INVALID_INDEX); - assert (gradient->color_space == CAIRO_COLOR_SPACE_DEVICE_RGB); - - if (gradient->color_space != &_cairo_color_space_device_rgb) + if (gradient->color_space != CAIRO_COLOR_SPACE_DEVICE_RGB) return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH); // COLORSPACE_MISMATCH? if (offset) diff --git a/src/cairo.h b/src/cairo.h index 8f5a31c95..42b0e929c 100644 --- a/src/cairo.h +++ b/src/cairo.h @@ -2394,10 +2394,20 @@ cairo_pattern_create_linear (double x0, double y0, double x1, double y1); cairo_public cairo_pattern_t * +cairo_pattern_create_linear_with_color_space (cairo_color_space_t *color_space, + double x0, double y0, + double x1, double y1); + +cairo_public cairo_pattern_t * cairo_pattern_create_radial (double cx0, double cy0, double radius0, double cx1, double cy1, double radius1); cairo_public 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_public cairo_pattern_t * cairo_pattern_create_mesh (void); cairo_public cairo_pattern_t * |