2 * Copyright © 2000 SuSE, Inc.
3 * Copyright © 2007 Red Hat, Inc.
4 * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
5 * 2005 Lars Knoll & Zack Rusin, Trolltech
7 * Permission to use, copy, modify, distribute, and sell this software and its
8 * documentation for any purpose is hereby granted without fee, provided that
9 * the above copyright notice appear in all copies and that both that
10 * copyright notice and this permission notice appear in supporting
11 * documentation, and that the name of Keith Packard not be used in
12 * advertising or publicity pertaining to distribution of the software without
13 * specific, written prior permission. Keith Packard makes no
14 * representations about the suitability of this software for any purpose. It
15 * is provided "as is" without express or implied warranty.
17 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
18 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
19 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
21 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
22 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
23 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
29 #include "pixman-private.h"
32 conical_gradient_get_scanline_32 (pixman_image_t *image, int x, int y,
33 int width, uint32_t *buffer,
34 const uint32_t *mask, uint32_t maskBits)
36 source_image_t *source = (source_image_t *)image;
37 gradient_t *gradient = (gradient_t *)source;
38 conical_gradient_t *conical = (conical_gradient_t *)image;
39 uint32_t *end = buffer + width;
40 pixman_gradient_walker_t walker;
41 pixman_bool_t affine = TRUE;
48 double a = conical->angle/(180.*65536);
50 _pixman_gradient_walker_init (&walker, gradient, source->common.repeat);
52 if (source->common.transform) {
54 /* reference point is the center of the pixel */
55 v.vector[0] = pixman_int_to_fixed(x) + pixman_fixed_1/2;
56 v.vector[1] = pixman_int_to_fixed(y) + pixman_fixed_1/2;
57 v.vector[2] = pixman_fixed_1;
58 if (!pixman_transform_point_3d (source->common.transform, &v))
61 cx = source->common.transform->matrix[0][0]/65536.;
62 cy = source->common.transform->matrix[1][0]/65536.;
63 cz = source->common.transform->matrix[2][0]/65536.;
64 rx = v.vector[0]/65536.;
65 ry = v.vector[1]/65536.;
66 rz = v.vector[2]/65536.;
67 affine = source->common.transform->matrix[2][0] == 0 && v.vector[2] == pixman_fixed_1;
71 rx -= conical->center.x/65536.;
72 ry -= conical->center.y/65536.;
74 while (buffer < end) {
77 if (!mask || *mask++ & maskBits)
79 pixman_fixed_48_16_t t;
81 angle = atan2(ry, rx) + a;
82 t = (pixman_fixed_48_16_t) (angle * (65536. / (2*M_PI)));
84 *(buffer) = _pixman_gradient_walker_pixel (&walker, t);
92 while (buffer < end) {
96 if (!mask || *mask++ & maskBits)
98 pixman_fixed_48_16_t t;
106 x -= conical->center.x/65536.;
107 y -= conical->center.y/65536.;
108 angle = atan2(y, x) + a;
109 t = (pixman_fixed_48_16_t) (angle * (65536. / (2*M_PI)));
111 *(buffer) = _pixman_gradient_walker_pixel (&walker, t);
123 conical_gradient_property_changed (pixman_image_t *image)
125 image->common.get_scanline_32 = conical_gradient_get_scanline_32;
126 image->common.get_scanline_64 = _pixman_image_get_scanline_64_generic;
129 PIXMAN_EXPORT pixman_image_t *
130 pixman_image_create_conical_gradient (pixman_point_fixed_t *center,
131 pixman_fixed_t angle,
132 const pixman_gradient_stop_t *stops,
135 pixman_image_t *image = _pixman_image_allocate();
136 conical_gradient_t *conical;
141 conical = &image->conical;
143 if (!_pixman_init_gradient (&conical->common, stops, n_stops))
149 image->type = CONICAL;
150 conical->center = *center;
151 conical->angle = angle;
153 image->common.property_changed = conical_gradient_property_changed;
155 conical_gradient_property_changed (image);