pixman-solid-fill.c revision 952204ab
1317c648bSmrg/*
2317c648bSmrg * Copyright © 2000 SuSE, Inc.
3317c648bSmrg * Copyright © 2007, 2009 Red Hat, Inc.
4317c648bSmrg * Copyright © 2009 Soren Sandmann
5317c648bSmrg *
6317c648bSmrg * Permission to use, copy, modify, distribute, and sell this software and its
7317c648bSmrg * documentation for any purpose is hereby granted without fee, provided that
8317c648bSmrg * the above copyright notice appear in all copies and that both that
9317c648bSmrg * copyright notice and this permission notice appear in supporting
10317c648bSmrg * documentation, and that the name of SuSE not be used in advertising or
11317c648bSmrg * publicity pertaining to distribution of the software without specific,
12317c648bSmrg * written prior permission.  SuSE makes no representations about the
13317c648bSmrg * suitability of this software for any purpose.  It is provided "as is"
14317c648bSmrg * without express or implied warranty.
15317c648bSmrg *
16317c648bSmrg * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17317c648bSmrg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
18317c648bSmrg * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19317c648bSmrg * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20317c648bSmrg * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21317c648bSmrg * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22317c648bSmrg */
23317c648bSmrg
24a450e446Smrg#ifdef HAVE_CONFIG_H
25317c648bSmrg#include <config.h>
26a450e446Smrg#endif
27317c648bSmrg#include "pixman-private.h"
28317c648bSmrg
29317c648bSmrgstatic void
30d0321353Smrgsolid_fill_get_scanline_32 (pixman_image_t *image,
31d0321353Smrg                            int             x,
32d0321353Smrg                            int             y,
33d0321353Smrg                            int             width,
34d0321353Smrg                            uint32_t *      buffer,
35d0321353Smrg                            const uint32_t *mask,
36d0321353Smrg                            uint32_t        mask_bits)
37317c648bSmrg{
38317c648bSmrg    uint32_t *end = buffer + width;
39952204abSmrg    uint32_t color = image->solid.color_32;
40d0321353Smrg
41317c648bSmrg    while (buffer < end)
42317c648bSmrg	*(buffer++) = color;
43d0321353Smrg
44317c648bSmrg    return;
45317c648bSmrg}
46317c648bSmrg
47952204abSmrgstatic void
48952204abSmrgsolid_fill_get_scanline_64 (pixman_image_t *image,
49952204abSmrg			    int             x,
50952204abSmrg			    int             y,
51952204abSmrg			    int             width,
52952204abSmrg			    uint32_t *      buffer,
53952204abSmrg			    const uint32_t *mask,
54952204abSmrg			    uint32_t        mask_bits)
55952204abSmrg{
56952204abSmrg    uint64_t *b = (uint64_t *)buffer;
57952204abSmrg    uint64_t *e = b + width;
58952204abSmrg    uint64_t color = image->solid.color_64;
59952204abSmrg
60952204abSmrg    while (b < e)
61952204abSmrg	*(b++) = color;
62952204abSmrg}
63952204abSmrg
64a450e446Smrgstatic source_image_class_t
65317c648bSmrgsolid_fill_classify (pixman_image_t *image,
66d0321353Smrg                     int             x,
67d0321353Smrg                     int             y,
68d0321353Smrg                     int             width,
69d0321353Smrg                     int             height)
70317c648bSmrg{
71317c648bSmrg    return (image->source.class = SOURCE_IMAGE_CLASS_HORIZONTAL);
72317c648bSmrg}
73317c648bSmrg
74317c648bSmrgstatic void
75317c648bSmrgsolid_fill_property_changed (pixman_image_t *image)
76317c648bSmrg{
77dc259aabSmrg    image->common.get_scanline_32 = solid_fill_get_scanline_32;
78952204abSmrg    image->common.get_scanline_64 = solid_fill_get_scanline_64;
79317c648bSmrg}
80317c648bSmrg
81317c648bSmrgstatic uint32_t
82317c648bSmrgcolor_to_uint32 (const pixman_color_t *color)
83317c648bSmrg{
84317c648bSmrg    return
85d0321353Smrg        (color->alpha >> 8 << 24) |
86d0321353Smrg        (color->red >> 8 << 16) |
87317c648bSmrg        (color->green & 0xff00) |
88d0321353Smrg        (color->blue >> 8);
89317c648bSmrg}
90317c648bSmrg
91952204abSmrgstatic uint64_t
92952204abSmrgcolor_to_uint64 (const pixman_color_t *color)
93952204abSmrg{
94952204abSmrg    return
95952204abSmrg        ((uint64_t)color->alpha << 48) |
96952204abSmrg        ((uint64_t)color->red << 32) |
97952204abSmrg        ((uint64_t)color->green << 16) |
98952204abSmrg        ((uint64_t)color->blue);
99952204abSmrg}
100952204abSmrg
101317c648bSmrgPIXMAN_EXPORT pixman_image_t *
102317c648bSmrgpixman_image_create_solid_fill (pixman_color_t *color)
103317c648bSmrg{
104d0321353Smrg    pixman_image_t *img = _pixman_image_allocate ();
105d0321353Smrg
106317c648bSmrg    if (!img)
107317c648bSmrg	return NULL;
108317c648bSmrg
109317c648bSmrg    img->type = SOLID;
110952204abSmrg    img->solid.color = *color;
111952204abSmrg    img->solid.color_32 = color_to_uint32 (color);
112952204abSmrg    img->solid.color_64 = color_to_uint64 (color);
113317c648bSmrg
114317c648bSmrg    img->source.class = SOURCE_IMAGE_CLASS_UNKNOWN;
115317c648bSmrg    img->common.classify = solid_fill_classify;
116317c648bSmrg    img->common.property_changed = solid_fill_property_changed;
117317c648bSmrg
118317c648bSmrg    return img;
119317c648bSmrg}
120d0321353Smrg
121