Constify the mask argument to scanline fetchers.
[profile/ivi/pixman.git] / pixman / pixman-conical-gradient.c
1 /*
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
6  *
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.
16  *
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
24  * SOFTWARE.
25  */
26 #include <config.h>
27 #include <stdlib.h>
28 #include <math.h>
29 #include "pixman-private.h"
30
31 static void
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)
35 {
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;
42     double cx = 1.;
43     double cy = 0.;
44     double cz = 0.;
45     double rx = x + 0.5;
46     double ry = y + 0.5;
47     double rz = 1.;
48     double a = conical->angle/(180.*65536);
49
50     _pixman_gradient_walker_init (&walker, gradient, source->common.repeat);
51     
52     if (source->common.transform) {
53         pixman_vector_t v;
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))
59             return;
60         
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;
68     }
69     
70     if (affine) {
71         rx -= conical->center.x/65536.;
72         ry -= conical->center.y/65536.;
73         
74         while (buffer < end) {
75             double angle;
76             
77             if (!mask || *mask++ & maskBits)
78             {
79                 pixman_fixed_48_16_t   t;
80                 
81                 angle = atan2(ry, rx) + a;
82                 t     = (pixman_fixed_48_16_t) (angle * (65536. / (2*M_PI)));
83                 
84                 *(buffer) = _pixman_gradient_walker_pixel (&walker, t);
85             }
86             
87             ++buffer;
88             rx += cx;
89             ry += cy;
90         }
91     } else {
92         while (buffer < end) {
93             double x, y;
94             double angle;
95             
96             if (!mask || *mask++ & maskBits)
97             {
98                 pixman_fixed_48_16_t  t;
99                 
100                 if (rz != 0) {
101                     x = rx/rz;
102                     y = ry/rz;
103                 } else {
104                     x = y = 0.;
105                 }
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)));
110                 
111                 *(buffer) = _pixman_gradient_walker_pixel (&walker, t);
112             }
113             
114             ++buffer;
115             rx += cx;
116             ry += cy;
117             rz += cz;
118         }
119     }
120 }
121
122 static void
123 conical_gradient_property_changed (pixman_image_t *image)
124 {
125     image->common.get_scanline_32 = conical_gradient_get_scanline_32;
126     image->common.get_scanline_64 = _pixman_image_get_scanline_64_generic;
127 }
128
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,
133                                       int                           n_stops)
134 {
135     pixman_image_t *image = _pixman_image_allocate();
136     conical_gradient_t *conical;
137     
138     if (!image)
139         return NULL;
140     
141     conical = &image->conical;
142     
143     if (!_pixman_init_gradient (&conical->common, stops, n_stops))
144     {
145         free (image);
146         return NULL;
147     }
148     
149     image->type = CONICAL;
150     conical->center = *center;
151     conical->angle = angle;
152     
153     image->common.property_changed = conical_gradient_property_changed;
154     
155     conical_gradient_property_changed (image);
156     
157     return image;
158 }