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