Move iterator initialization to the respective image files
[profile/ivi/pixman.git] / pixman / pixman-solid-fill.c
1 /*
2  * Copyright © 2000 SuSE, Inc.
3  * Copyright © 2007, 2009 Red Hat, Inc.
4  * Copyright © 2009 Soren Sandmann
5  *
6  * Permission to use, copy, modify, distribute, and sell this software and its
7  * documentation for any purpose is hereby granted without fee, provided that
8  * the above copyright notice appear in all copies and that both that
9  * copyright notice and this permission notice appear in supporting
10  * documentation, and that the name of SuSE not be used in advertising or
11  * publicity pertaining to distribution of the software without specific,
12  * written prior permission.  SuSE makes no representations about the
13  * suitability of this software for any purpose.  It is provided "as is"
14  * without express or implied warranty.
15  *
16  * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
18  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27 #include "pixman-private.h"
28
29 static void
30 solid_fill_get_scanline_32 (pixman_image_t *image,
31                             int             x,
32                             int             y,
33                             int             width,
34                             uint32_t *      buffer,
35                             const uint32_t *mask)
36 {
37     uint32_t *end = buffer + width;
38     uint32_t color = image->solid.color_32;
39
40     while (buffer < end)
41         *(buffer++) = color;
42
43     return;
44 }
45
46 static void
47 solid_fill_get_scanline_64 (pixman_image_t *image,
48                             int             x,
49                             int             y,
50                             int             width,
51                             uint32_t *      buffer,
52                             const uint32_t *mask)
53 {
54     uint64_t *b = (uint64_t *)buffer;
55     uint64_t *e = b + width;
56     uint64_t color = image->solid.color_64;
57
58     while (b < e)
59         *(b++) = color;
60 }
61
62 static source_image_class_t
63 solid_fill_classify (pixman_image_t *image,
64                      int             x,
65                      int             y,
66                      int             width,
67                      int             height)
68 {
69     return SOURCE_IMAGE_CLASS_HORIZONTAL;
70 }
71
72 static void
73 solid_fill_property_changed (pixman_image_t *image)
74 {
75     image->common.get_scanline_32 = solid_fill_get_scanline_32;
76     image->common.get_scanline_64 = solid_fill_get_scanline_64;
77 }
78
79 void
80 _pixman_solid_fill_iter_init (pixman_image_t *image,
81                               pixman_iter_t  *iter,
82                               int x, int y, int width, int height,
83                               uint8_t *buffer, iter_flags_t flags)
84 {
85     if (flags & ITER_NARROW)
86     {
87         solid_fill_get_scanline_32 (
88             image, x, y, width, (uint32_t *)buffer, NULL);
89     }
90     else
91     {
92         solid_fill_get_scanline_64 (
93             image, x, y, width, (uint32_t *)buffer, NULL);
94     }
95
96     iter->get_scanline = _pixman_iter_get_scanline_noop;
97 }
98
99 static uint32_t
100 color_to_uint32 (const pixman_color_t *color)
101 {
102     return
103         (color->alpha >> 8 << 24) |
104         (color->red >> 8 << 16) |
105         (color->green & 0xff00) |
106         (color->blue >> 8);
107 }
108
109 static uint64_t
110 color_to_uint64 (const pixman_color_t *color)
111 {
112     return
113         ((uint64_t)color->alpha << 48) |
114         ((uint64_t)color->red << 32) |
115         ((uint64_t)color->green << 16) |
116         ((uint64_t)color->blue);
117 }
118
119 PIXMAN_EXPORT pixman_image_t *
120 pixman_image_create_solid_fill (pixman_color_t *color)
121 {
122     pixman_image_t *img = _pixman_image_allocate ();
123
124     if (!img)
125         return NULL;
126
127     img->type = SOLID;
128     img->solid.color = *color;
129     img->solid.color_32 = color_to_uint32 (color);
130     img->solid.color_64 = color_to_uint64 (color);
131
132     img->common.classify = solid_fill_classify;
133     img->common.property_changed = solid_fill_property_changed;
134
135     return img;
136 }
137