ca52c11e3955f3a8c284fef80e1adda813a64f26
[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     
31 }
32
33 PIXMAN_EXPORT pixman_image_t *
34 pixman_image_create_radial_gradient (pixman_point_fixed_t         *inner,
35                                      pixman_point_fixed_t         *outer,
36                                      pixman_fixed_t                inner_radius,
37                                      pixman_fixed_t                outer_radius,
38                                      const pixman_gradient_stop_t *stops,
39                                      int                           n_stops)
40 {
41     pixman_image_t *image;
42     radial_gradient_t *radial;
43
44     return_val_if_fail (n_stops >= 2, NULL);
45
46     image = _pixman_image_allocate();
47
48     if (!image)
49         return NULL;
50
51     radial = &image->radial;
52
53     if (!_pixman_init_gradient (&radial->common, stops, n_stops))
54     {
55         free (image);
56         return NULL;
57     }
58
59     image->type = RADIAL;
60
61     radial->c1.x = inner->x;
62     radial->c1.y = inner->y;
63     radial->c1.radius = inner_radius;
64     radial->c2.x = outer->x;
65     radial->c2.y = outer->y;
66     radial->c2.radius = outer_radius;
67     radial->cdx = pixman_fixed_to_double (radial->c2.x - radial->c1.x);
68     radial->cdy = pixman_fixed_to_double (radial->c2.y - radial->c1.y);
69     radial->dr = pixman_fixed_to_double (radial->c2.radius - radial->c1.radius);
70     radial->A = (radial->cdx * radial->cdx
71                  + radial->cdy * radial->cdy
72                  - radial->dr  * radial->dr);
73
74     image->common.property_changed = radial_gradient_property_changed;
75
76     radial_gradient_property_changed (image);
77     
78     return image;
79 }
80