Rev 1891 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1891 | Rev 3931 | ||
---|---|---|---|
Line 29... | Line 29... | ||
29 | #include |
29 | #include |
30 | #endif |
30 | #endif |
31 | #include |
31 | #include |
32 | #include "pixman-private.h" |
32 | #include "pixman-private.h" |
Line 33... | Line 33... | ||
33 | 33 | ||
34 | static source_image_class_t |
34 | static pixman_bool_t |
35 | linear_gradient_classify (pixman_image_t *image, |
35 | linear_gradient_is_horizontal (pixman_image_t *image, |
36 | int x, |
36 | int x, |
37 | int y, |
37 | int y, |
38 | int width, |
38 | int width, |
39 | int height) |
39 | int height) |
40 | { |
- | |
41 | source_image_t *source = (source_image_t *)image; |
40 | { |
42 | linear_gradient_t *linear = (linear_gradient_t *)image; |
41 | linear_gradient_t *linear = (linear_gradient_t *)image; |
43 | pixman_vector_t v; |
42 | pixman_vector_t v; |
44 | pixman_fixed_32_32_t l; |
43 | pixman_fixed_32_32_t l; |
45 | pixman_fixed_48_16_t dx, dy; |
44 | pixman_fixed_48_16_t dx, dy; |
46 | double inc; |
- | |
Line 47... | Line -... | ||
47 | source_image_class_t class; |
- | |
48 | - | ||
49 | class = SOURCE_IMAGE_CLASS_UNKNOWN; |
45 | double inc; |
50 | 46 | ||
51 | if (source->common.transform) |
47 | if (image->common.transform) |
52 | { |
48 | { |
53 | /* projective transformation */ |
49 | /* projective transformation */ |
54 | if (source->common.transform->matrix[2][0] != 0 || |
50 | if (image->common.transform->matrix[2][0] != 0 || |
55 | source->common.transform->matrix[2][1] != 0 || |
51 | image->common.transform->matrix[2][1] != 0 || |
56 | source->common.transform->matrix[2][2] == 0) |
52 | image->common.transform->matrix[2][2] == 0) |
57 | { |
53 | { |
Line 58... | Line 54... | ||
58 | return class; |
54 | return FALSE; |
59 | } |
55 | } |
60 | 56 | ||
61 | v.vector[0] = source->common.transform->matrix[0][1]; |
57 | v.vector[0] = image->common.transform->matrix[0][1]; |
62 | v.vector[1] = source->common.transform->matrix[1][1]; |
58 | v.vector[1] = image->common.transform->matrix[1][1]; |
63 | v.vector[2] = source->common.transform->matrix[2][2]; |
59 | v.vector[2] = image->common.transform->matrix[2][2]; |
64 | } |
60 | } |
65 | else |
61 | else |
Line 73... | Line 69... | ||
73 | dy = linear->p2.y - linear->p1.y; |
69 | dy = linear->p2.y - linear->p1.y; |
Line 74... | Line 70... | ||
74 | 70 | ||
Line 75... | Line 71... | ||
75 | l = dx * dx + dy * dy; |
71 | l = dx * dx + dy * dy; |
76 | 72 | ||
Line 77... | Line 73... | ||
77 | if (l == 0) |
73 | if (l == 0) |
78 | return class; |
74 | return FALSE; |
79 | 75 | ||
80 | /* |
76 | /* |
Line 85... | Line 81... | ||
85 | (dx * v.vector[0] + dy * v.vector[1]) / |
81 | (dx * v.vector[0] + dy * v.vector[1]) / |
86 | (v.vector[2] * (double) l); |
82 | (v.vector[2] * (double) l); |
Line 87... | Line 83... | ||
87 | 83 | ||
88 | /* check that casting to integer would result in 0 */ |
84 | /* check that casting to integer would result in 0 */ |
89 | if (-1 < inc && inc < 1) |
85 | if (-1 < inc && inc < 1) |
Line 90... | Line 86... | ||
90 | class = SOURCE_IMAGE_CLASS_HORIZONTAL; |
86 | return TRUE; |
91 | 87 | ||
Line 92... | Line 88... | ||
92 | return class; |
88 | return FALSE; |
93 | } |
89 | } |
94 | - | ||
95 | static void |
- | |
96 | linear_gradient_get_scanline_32 (pixman_image_t *image, |
- | |
97 | int x, |
- | |
98 | int y, |
90 | |
99 | int width, |
91 | static uint32_t * |
- | 92 | linear_get_scanline_narrow (pixman_iter_t *iter, |
|
- | 93 | const uint32_t *mask) |
|
- | 94 | { |
|
- | 95 | pixman_image_t *image = iter->image; |
|
- | 96 | int x = iter->x; |
|
- | 97 | int y = iter->y; |
|
100 | uint32_t * buffer, |
98 | int width = iter->width; |
101 | const uint32_t *mask) |
99 | uint32_t * buffer = iter->buffer; |
102 | { |
100 | |
103 | pixman_vector_t v, unit; |
101 | pixman_vector_t v, unit; |
104 | pixman_fixed_32_32_t l; |
- | |
105 | pixman_fixed_48_16_t dx, dy; |
102 | pixman_fixed_32_32_t l; |
106 | gradient_t *gradient = (gradient_t *)image; |
103 | pixman_fixed_48_16_t dx, dy; |
107 | source_image_t *source = (source_image_t *)image; |
104 | gradient_t *gradient = (gradient_t *)image; |
Line 108... | Line 105... | ||
108 | linear_gradient_t *linear = (linear_gradient_t *)image; |
105 | linear_gradient_t *linear = (linear_gradient_t *)image; |
Line 109... | Line 106... | ||
109 | uint32_t *end = buffer + width; |
106 | uint32_t *end = buffer + width; |
110 | pixman_gradient_walker_t walker; |
107 | pixman_gradient_walker_t walker; |
111 | 108 | ||
112 | _pixman_gradient_walker_init (&walker, gradient, source->common.repeat); |
109 | _pixman_gradient_walker_init (&walker, gradient, image->common.repeat); |
Line 113... | Line 110... | ||
113 | 110 | ||
114 | /* reference point is the center of the pixel */ |
111 | /* reference point is the center of the pixel */ |
115 | v.vector[0] = pixman_int_to_fixed (x) + pixman_fixed_1 / 2; |
112 | v.vector[0] = pixman_int_to_fixed (x) + pixman_fixed_1 / 2; |
116 | v.vector[1] = pixman_int_to_fixed (y) + pixman_fixed_1 / 2; |
113 | v.vector[1] = pixman_int_to_fixed (y) + pixman_fixed_1 / 2; |
Line 117... | Line 114... | ||
117 | v.vector[2] = pixman_fixed_1; |
114 | v.vector[2] = pixman_fixed_1; |
118 | 115 | ||
119 | if (source->common.transform) |
116 | if (image->common.transform) |
120 | { |
117 | { |
121 | if (!pixman_transform_point_3d (source->common.transform, &v)) |
118 | if (!pixman_transform_point_3d (image->common.transform, &v)) |
122 | return; |
119 | return iter->buffer; |
123 | 120 | ||
124 | unit.vector[0] = source->common.transform->matrix[0][0]; |
121 | unit.vector[0] = image->common.transform->matrix[0][0]; |
Line 217... | Line 214... | ||
217 | v.vector[0] += unit.vector[0]; |
214 | v.vector[0] += unit.vector[0]; |
218 | v.vector[1] += unit.vector[1]; |
215 | v.vector[1] += unit.vector[1]; |
219 | v.vector[2] += unit.vector[2]; |
216 | v.vector[2] += unit.vector[2]; |
220 | } |
217 | } |
221 | } |
218 | } |
- | 219 | ||
- | 220 | iter->y++; |
|
- | 221 | ||
- | 222 | return iter->buffer; |
|
- | 223 | } |
|
- | 224 | ||
- | 225 | static uint32_t * |
|
- | 226 | linear_get_scanline_wide (pixman_iter_t *iter, const uint32_t *mask) |
|
- | 227 | { |
|
- | 228 | uint32_t *buffer = linear_get_scanline_narrow (iter, NULL); |
|
- | 229 | ||
- | 230 | pixman_expand_to_float ( |
|
- | 231 | (argb_t *)buffer, buffer, PIXMAN_a8r8g8b8, iter->width); |
|
- | 232 | ||
- | 233 | return buffer; |
|
222 | } |
234 | } |
Line 223... | Line 235... | ||
223 | 235 | ||
224 | static void |
236 | void |
- | 237 | _pixman_linear_gradient_iter_init (pixman_image_t *image, pixman_iter_t *iter) |
|
- | 238 | { |
|
- | 239 | if (linear_gradient_is_horizontal ( |
|
- | 240 | iter->image, iter->x, iter->y, iter->width, iter->height)) |
|
- | 241 | { |
|
- | 242 | if (iter->iter_flags & ITER_NARROW) |
|
- | 243 | linear_get_scanline_narrow (iter, NULL); |
|
- | 244 | else |
|
- | 245 | linear_get_scanline_wide (iter, NULL); |
|
- | 246 | ||
- | 247 | iter->get_scanline = _pixman_iter_get_scanline_noop; |
|
- | 248 | } |
|
225 | linear_gradient_property_changed (pixman_image_t *image) |
249 | else |
- | 250 | { |
|
226 | { |
251 | if (iter->iter_flags & ITER_NARROW) |
- | 252 | iter->get_scanline = linear_get_scanline_narrow; |
|
227 | image->common.get_scanline_32 = linear_gradient_get_scanline_32; |
253 | else |
- | 254 | iter->get_scanline = linear_get_scanline_wide; |
|
228 | image->common.get_scanline_64 = _pixman_image_get_scanline_generic_64; |
255 | } |
Line 229... | Line 256... | ||
229 | } |
256 | } |
230 | 257 | ||
231 | PIXMAN_EXPORT pixman_image_t * |
258 | PIXMAN_EXPORT pixman_image_t * |
232 | pixman_image_create_linear_gradient (pixman_point_fixed_t * p1, |
259 | pixman_image_create_linear_gradient (const pixman_point_fixed_t * p1, |
233 | pixman_point_fixed_t * p2, |
260 | const pixman_point_fixed_t * p2, |
234 | const pixman_gradient_stop_t *stops, |
261 | const pixman_gradient_stop_t *stops, |
235 | int n_stops) |
262 | int n_stops) |
236 | { |
263 | { |
Line 252... | Line 279... | ||
252 | 279 | ||
253 | linear->p1 = *p1; |
280 | linear->p1 = *p1; |
Line 254... | Line 281... | ||
254 | linear->p2 = *p2; |
281 | linear->p2 = *p2; |
255 | - | ||
256 | image->type = LINEAR; |
- | |
Line 257... | Line 282... | ||
257 | image->common.classify = linear_gradient_classify; |
282 | |
258 | image->common.property_changed = linear_gradient_property_changed; |
283 | image->type = LINEAR; |