1 /* cairo - a vector graphics library with display and print output
3 * Copyright © 2005 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it either under the terms of the GNU Lesser General Public
7 * License version 2.1 as published by the Free Software Foundation
8 * (the "LGPL") or, at your option, under the terms of the Mozilla
9 * Public License Version 1.1 (the "MPL"). If you do not alter this
10 * notice, a recipient may use your version of this file under either
11 * the MPL or the LGPL.
13 * You should have received a copy of the LGPL along with this library
14 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
16 * You should have received a copy of the MPL along with this library
17 * in the file COPYING-MPL-1.1
19 * The contents of this file are subject to the Mozilla Public License
20 * Version 1.1 (the "License"); you may not use this file except in
21 * compliance with the License. You may obtain a copy of the License at
22 * http://www.mozilla.org/MPL/
24 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
25 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
26 * the specific language governing rights and limitations.
28 * The Original Code is the cairo graphics library.
30 * The Initial Developer of the Original Code is Red Hat, Inc.
33 * Carl D. Worth <cworth@redhat.com>
36 #ifndef CAIRO_PATTERN_PRIVATE_H
37 #define CAIRO_PATTERN_PRIVATE_H
39 #include "cairo-error-private.h"
40 #include "cairo-types-private.h"
41 #include "cairo-list-private.h"
42 #include "cairo-surface-private.h"
44 #include <stdio.h> /* FILE* */
48 typedef struct _cairo_pattern_observer cairo_pattern_observer_t;
51 CAIRO_PATTERN_NOTIFY_MATRIX = 0x1,
52 CAIRO_PATTERN_NOTIFY_FILTER = 0x2,
53 CAIRO_PATTERN_NOTIFY_EXTEND = 0x4,
54 CAIRO_PATTERN_NOTIFY_OPACITY = 0x9,
57 struct _cairo_pattern_observer {
58 void (*notify) (cairo_pattern_observer_t *,
59 cairo_pattern_t *pattern,
64 struct _cairo_pattern {
65 cairo_reference_count_t ref_count;
66 cairo_status_t status;
67 cairo_user_data_array_t user_data;
68 cairo_list_t observers;
70 cairo_pattern_type_t type;
72 cairo_filter_t filter;
73 cairo_extend_t extend;
74 cairo_bool_t has_component_alpha;
76 cairo_matrix_t matrix;
80 struct _cairo_solid_pattern {
85 typedef struct _cairo_surface_pattern {
88 cairo_surface_t *surface;
89 } cairo_surface_pattern_t;
91 typedef struct _cairo_gradient_stop {
93 cairo_color_stop_t color;
94 } cairo_gradient_stop_t;
96 typedef struct _cairo_gradient_pattern {
100 unsigned int stops_size;
101 cairo_gradient_stop_t *stops;
102 cairo_gradient_stop_t stops_embedded[2];
103 } cairo_gradient_pattern_t;
105 typedef struct _cairo_linear_pattern {
106 cairo_gradient_pattern_t base;
108 cairo_point_double_t pd1;
109 cairo_point_double_t pd2;
110 } cairo_linear_pattern_t;
112 typedef struct _cairo_radial_pattern {
113 cairo_gradient_pattern_t base;
115 cairo_circle_double_t cd1;
116 cairo_circle_double_t cd2;
117 } cairo_radial_pattern_t;
120 cairo_gradient_pattern_t base;
122 cairo_linear_pattern_t linear;
123 cairo_radial_pattern_t radial;
124 } cairo_gradient_pattern_union_t;
127 * A mesh patch is a tensor-product patch (bicubic Bezier surface
128 * patch). It has 16 control points. Each set of 4 points along the
129 * sides of the 4x4 grid of control points is a Bezier curve that
130 * defines one side of the patch. A color is assigned to each
131 * corner. The inner 4 points provide additional control over the
132 * shape and the color mapping.
134 * Cairo uses the same convention as the PDF Reference for numbering
135 * the points and side of the patch.
140 * p[0][3] p[1][3] p[2][3] p[3][3]
141 * Side 0 p[0][2] p[1][2] p[2][2] p[3][2] Side 2
142 * p[0][1] p[1][1] p[2][1] p[3][1]
143 * p[0][0] p[1][0] p[2][0] p[3][0]
149 * -------------------------
150 * points[0][0] colors[0]
151 * points[0][3] colors[1]
152 * points[3][3] colors[2]
153 * points[3][0] colors[3]
156 typedef struct _cairo_mesh_patch {
157 cairo_point_double_t points[4][4];
158 cairo_color_t colors[4];
159 } cairo_mesh_patch_t;
161 typedef struct _cairo_mesh_pattern {
162 cairo_pattern_t base;
164 cairo_array_t patches;
165 cairo_mesh_patch_t *current_patch;
167 cairo_bool_t has_control_point[4];
168 cairo_bool_t has_color[4];
169 } cairo_mesh_pattern_t;
171 typedef struct _cairo_raster_source_pattern {
172 cairo_pattern_t base;
174 cairo_content_t content;
175 cairo_rectangle_int_t extents;
177 cairo_raster_source_acquire_func_t acquire;
178 cairo_raster_source_release_func_t release;
179 cairo_raster_source_snapshot_func_t snapshot;
180 cairo_raster_source_copy_func_t copy;
181 cairo_raster_source_finish_func_t finish;
183 /* an explicit pre-allocated member in preference to the general user-data */
185 } cairo_raster_source_pattern_t;
188 cairo_pattern_t base;
190 cairo_solid_pattern_t solid;
191 cairo_surface_pattern_t surface;
192 cairo_gradient_pattern_union_t gradient;
193 cairo_mesh_pattern_t mesh;
194 cairo_raster_source_pattern_t raster_source;
195 } cairo_pattern_union_t;
197 /* cairo-pattern.c */
199 cairo_private cairo_pattern_t *
200 _cairo_pattern_create_in_error (cairo_status_t status);
202 cairo_private cairo_status_t
203 _cairo_pattern_create_copy (cairo_pattern_t **pattern,
204 const cairo_pattern_t *other);
207 _cairo_pattern_init (cairo_pattern_t *pattern,
208 cairo_pattern_type_t type);
210 cairo_private cairo_status_t
211 _cairo_pattern_init_copy (cairo_pattern_t *pattern,
212 const cairo_pattern_t *other);
215 _cairo_pattern_init_static_copy (cairo_pattern_t *pattern,
216 const cairo_pattern_t *other);
218 cairo_private cairo_status_t
219 _cairo_pattern_init_snapshot (cairo_pattern_t *pattern,
220 const cairo_pattern_t *other);
223 _cairo_pattern_init_solid (cairo_solid_pattern_t *pattern,
224 const cairo_color_t *color);
227 _cairo_pattern_init_for_surface (cairo_surface_pattern_t *pattern,
228 cairo_surface_t *surface);
231 _cairo_pattern_fini (cairo_pattern_t *pattern);
234 _cairo_pattern_fini_snapshot (cairo_pattern_t *pattern);
236 cairo_private cairo_pattern_t *
237 _cairo_pattern_create_solid (const cairo_color_t *color);
240 _cairo_pattern_transform (cairo_pattern_t *pattern,
241 const cairo_matrix_t *ctm_inverse);
243 cairo_private cairo_bool_t
244 _cairo_pattern_is_opaque_solid (const cairo_pattern_t *pattern);
246 cairo_private cairo_bool_t
247 _cairo_pattern_is_opaque (const cairo_pattern_t *pattern,
248 const cairo_rectangle_int_t *extents);
250 cairo_private cairo_bool_t
251 _cairo_pattern_is_clear (const cairo_pattern_t *pattern);
253 cairo_private cairo_bool_t
254 _cairo_gradient_pattern_is_solid (const cairo_gradient_pattern_t *gradient,
255 const cairo_rectangle_int_t *extents,
256 cairo_color_t *color);
259 _cairo_gradient_pattern_fit_to_range (const cairo_gradient_pattern_t *gradient,
261 cairo_matrix_t *out_matrix,
262 cairo_circle_double_t out_circle[2]);
264 cairo_private cairo_bool_t
265 _cairo_radial_pattern_focus_is_inside (const cairo_radial_pattern_t *radial);
268 _cairo_gradient_pattern_box_to_parameter (const cairo_gradient_pattern_t *gradient,
269 double x0, double y0,
270 double x1, double y1,
272 double out_range[2]);
275 _cairo_gradient_pattern_interpolate (const cairo_gradient_pattern_t *gradient,
277 cairo_circle_double_t *out_circle);
280 _cairo_pattern_alpha_range (const cairo_pattern_t *pattern,
284 cairo_private cairo_bool_t
285 _cairo_mesh_pattern_coord_box (const cairo_mesh_pattern_t *mesh,
291 cairo_private_no_warn cairo_filter_t
292 _cairo_pattern_sampled_area (const cairo_pattern_t *pattern,
293 const cairo_rectangle_int_t *extents,
294 cairo_rectangle_int_t *sample);
297 _cairo_pattern_get_extents (const cairo_pattern_t *pattern,
298 cairo_rectangle_int_t *extents);
300 cairo_private cairo_int_status_t
301 _cairo_pattern_get_ink_extents (const cairo_pattern_t *pattern,
302 cairo_rectangle_int_t *extents);
304 cairo_private unsigned long
305 _cairo_pattern_hash (const cairo_pattern_t *pattern);
307 cairo_private unsigned long
308 _cairo_linear_pattern_hash (unsigned long hash,
309 const cairo_linear_pattern_t *linear);
311 cairo_private unsigned long
312 _cairo_radial_pattern_hash (unsigned long hash,
313 const cairo_radial_pattern_t *radial);
315 cairo_private cairo_bool_t
316 _cairo_linear_pattern_equal (const cairo_linear_pattern_t *a,
317 const cairo_linear_pattern_t *b);
319 cairo_private unsigned long
320 _cairo_pattern_size (const cairo_pattern_t *pattern);
322 cairo_private cairo_bool_t
323 _cairo_radial_pattern_equal (const cairo_radial_pattern_t *a,
324 const cairo_radial_pattern_t *b);
326 cairo_private cairo_bool_t
327 _cairo_pattern_equal (const cairo_pattern_t *a,
328 const cairo_pattern_t *b);
330 /* cairo-mesh-pattern-rasterizer.c */
333 _cairo_mesh_pattern_rasterize (const cairo_mesh_pattern_t *mesh,
341 cairo_private cairo_surface_t *
342 _cairo_raster_source_pattern_acquire (const cairo_pattern_t *abstract_pattern,
343 cairo_surface_t *target,
344 const cairo_rectangle_int_t *extents);
347 _cairo_raster_source_pattern_release (const cairo_pattern_t *abstract_pattern,
348 cairo_surface_t *surface);
350 cairo_private cairo_status_t
351 _cairo_raster_source_pattern_snapshot (cairo_pattern_t *abstract_pattern);
353 cairo_private cairo_status_t
354 _cairo_raster_source_pattern_init_copy (cairo_pattern_t *pattern,
355 const cairo_pattern_t *other);
358 _cairo_raster_source_pattern_finish (cairo_pattern_t *abstract_pattern);
361 _cairo_debug_print_pattern (FILE *file, const cairo_pattern_t *pattern);
365 #endif /* CAIRO_PATTERN_PRIVATE */