2 * Copyright © 2000 SuSE, Inc.
3 * Copyright © 2007 Red Hat, Inc.
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.
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.
25 #include "pixman-private.h"
27 static source_pict_class_t
28 linear_gradient_classify (pixman_image_t *image,
34 linear_gradient_t *linear = (linear_gradient_t *)image;
36 pixman_fixed_32_32_t l;
37 pixman_fixed_48_16_t dx, dy, a, b, off;
38 pixman_fixed_48_16_t factors[4];
41 image->source.class = SOURCE_IMAGE_CLASS_UNKNOWN;
43 dx = linear->p2.x - linear->p1.x;
44 dy = linear->p2.y - linear->p1.y;
45 l = dx * dx + dy * dy;
56 off = (-a * linear->p1.x
57 -b * linear->p1.y) >> 16;
59 for (i = 0; i < 3; i++)
61 v.vector[0] = pixman_int_to_fixed ((i % 2) * (width - 1) + x);
62 v.vector[1] = pixman_int_to_fixed ((i / 2) * (height - 1) + y);
63 v.vector[2] = pixman_fixed_1;
65 if (image->common.transform)
67 if (!pixman_transform_point_3d (image->common.transform, &v))
69 image->source.class = SOURCE_IMAGE_CLASS_UNKNOWN;
71 return image->source.class;
75 factors[i] = ((a * v.vector[0] + b * v.vector[1]) >> 16) + off;
78 if (factors[2] == factors[0])
79 image->source.class = SOURCE_IMAGE_CLASS_HORIZONTAL;
80 else if (factors[1] == factors[0])
81 image->source.class = SOURCE_IMAGE_CLASS_VERTICAL;
83 return image->source.class;
87 linear_gradient_property_changed (pixman_image_t *image)
92 PIXMAN_EXPORT pixman_image_t *
93 pixman_image_create_linear_gradient (pixman_point_fixed_t *p1,
94 pixman_point_fixed_t *p2,
95 const pixman_gradient_stop_t *stops,
98 pixman_image_t *image;
99 linear_gradient_t *linear;
101 return_val_if_fail (n_stops >= 2, NULL);
103 image = _pixman_image_allocate();
108 linear = &image->linear;
110 if (!_pixman_init_gradient (&linear->common, stops, n_stops))
119 image->type = LINEAR;
120 image->source.class = SOURCE_IMAGE_CLASS_UNKNOWN;
121 image->common.classify = linear_gradient_classify;
122 image->common.property_changed = linear_gradient_property_changed;
124 linear_gradient_property_changed (image);