Duplicate some code that was shared between radial and conical gradients.
[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 static void
35 radial_gradient_get_scanline_32 (pixman_image_t *image, int x, int y, int width,
36                                  uint32_t *buffer, uint32_t *mask, uint32_t maskBits)
37 {
38     
39 }
40
41 PIXMAN_EXPORT pixman_image_t *
42 pixman_image_create_radial_gradient (pixman_point_fixed_t         *inner,
43                                      pixman_point_fixed_t         *outer,
44                                      pixman_fixed_t                inner_radius,
45                                      pixman_fixed_t                outer_radius,
46                                      const pixman_gradient_stop_t *stops,
47                                      int                           n_stops)
48 {
49     pixman_image_t *image;
50     radial_gradient_t *radial;
51
52     return_val_if_fail (n_stops >= 2, NULL);
53
54     image = _pixman_image_allocate();
55
56     if (!image)
57         return NULL;
58
59     radial = &image->radial;
60
61     if (!_pixman_init_gradient (&radial->common, stops, n_stops))
62     {
63         free (image);
64         return NULL;
65     }
66
67     image->type = RADIAL;
68
69     radial->c1.x = inner->x;
70     radial->c1.y = inner->y;
71     radial->c1.radius = inner_radius;
72     radial->c2.x = outer->x;
73     radial->c2.y = outer->y;
74     radial->c2.radius = outer_radius;
75     radial->cdx = pixman_fixed_to_double (radial->c2.x - radial->c1.x);
76     radial->cdy = pixman_fixed_to_double (radial->c2.y - radial->c1.y);
77     radial->dr = pixman_fixed_to_double (radial->c2.radius - radial->c1.radius);
78     radial->A = (radial->cdx * radial->cdx
79                  + radial->cdy * radial->cdy
80                  - radial->dr  * radial->dr);
81
82     image->common.property_changed = radial_gradient_property_changed;
83
84     radial_gradient_property_changed (image);
85     
86     return image;
87 }
88