40c76ce4f93bdb13e81f7751f9071c0a3cc5d52c
[profile/ivi/pixman.git] / pixman / pixman-radial-gradient.c
1 /*
2  * Copyright © 2000 SuSE, Inc.
3  * Copyright © 2007 Red Hat, Inc.
4  *
5  * Permission to use, copy, modify, distribute, and sell this software and its
6  * documentation for any purpose is hereby granted without fee, provided that
7  * the above copyright notice appear in all copies and that both that
8  * copyright notice and this permission notice appear in supporting
9  * documentation, and that the name of SuSE not be used in advertising or
10  * publicity pertaining to distribution of the software without specific,
11  * written prior permission.  SuSE makes no representations about the
12  * suitability of this software for any purpose.  It is provided "as is"
13  * without express or implied warranty.
14  *
15  * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
17  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
19  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21  */
22
23 #include <config.h>
24 #include <stdlib.h>
25 #include "pixman-private.h"
26
27 static void
28 radial_gradient_property_changed (pixman_image_t *image)
29 {
30     image->common.get_scanline_32 = (scanFetchProc)pixmanFetchGradient;
31     image->common.get_scanline_64 = (scanFetchProc)_pixman_image_get_scanline_64_generic;
32 }
33
34 PIXMAN_EXPORT pixman_image_t *
35 pixman_image_create_radial_gradient (pixman_point_fixed_t         *inner,
36                                      pixman_point_fixed_t         *outer,
37                                      pixman_fixed_t                inner_radius,
38                                      pixman_fixed_t                outer_radius,
39                                      const pixman_gradient_stop_t *stops,
40                                      int                           n_stops)
41 {
42     pixman_image_t *image;
43     radial_gradient_t *radial;
44
45     return_val_if_fail (n_stops >= 2, NULL);
46
47     image = _pixman_image_allocate();
48
49     if (!image)
50         return NULL;
51
52     radial = &image->radial;
53
54     if (!_pixman_init_gradient (&radial->common, stops, n_stops))
55     {
56         free (image);
57         return NULL;
58     }
59
60     image->type = RADIAL;
61
62     radial->c1.x = inner->x;
63     radial->c1.y = inner->y;
64     radial->c1.radius = inner_radius;
65     radial->c2.x = outer->x;
66     radial->c2.y = outer->y;
67     radial->c2.radius = outer_radius;
68     radial->cdx = pixman_fixed_to_double (radial->c2.x - radial->c1.x);
69     radial->cdy = pixman_fixed_to_double (radial->c2.y - radial->c1.y);
70     radial->dr = pixman_fixed_to_double (radial->c2.radius - radial->c1.radius);
71     radial->A = (radial->cdx * radial->cdx
72                  + radial->cdy * radial->cdy
73                  - radial->dr  * radial->dr);
74
75     image->common.property_changed = radial_gradient_property_changed;
76
77     radial_gradient_property_changed (image);
78     
79     return image;
80 }
81