pixman-solid-fill.c revision d0321353
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#include <config.h>
25#include "pixman-private.h"
26
27static void
28solid_fill_get_scanline_32 (pixman_image_t *image,
29                            int             x,
30                            int             y,
31                            int             width,
32                            uint32_t *      buffer,
33                            const uint32_t *mask,
34                            uint32_t        mask_bits)
35{
36    uint32_t *end = buffer + width;
37    register uint32_t color = ((solid_fill_t *)image)->color;
38
39    while (buffer < end)
40	*(buffer++) = color;
41
42    return;
43}
44
45static source_pict_class_t
46solid_fill_classify (pixman_image_t *image,
47                     int             x,
48                     int             y,
49                     int             width,
50                     int             height)
51{
52    return (image->source.class = SOURCE_IMAGE_CLASS_HORIZONTAL);
53}
54
55static void
56solid_fill_property_changed (pixman_image_t *image)
57{
58    image->common.get_scanline_32 = solid_fill_get_scanline_32;
59    image->common.get_scanline_64 = _pixman_image_get_scanline_generic_64;
60}
61
62static uint32_t
63color_to_uint32 (const pixman_color_t *color)
64{
65    return
66        (color->alpha >> 8 << 24) |
67        (color->red >> 8 << 16) |
68        (color->green & 0xff00) |
69        (color->blue >> 8);
70}
71
72PIXMAN_EXPORT pixman_image_t *
73pixman_image_create_solid_fill (pixman_color_t *color)
74{
75    pixman_image_t *img = _pixman_image_allocate ();
76
77    if (!img)
78	return NULL;
79
80    img->type = SOLID;
81    img->solid.color = color_to_uint32 (color);
82
83    img->source.class = SOURCE_IMAGE_CLASS_UNKNOWN;
84    img->common.classify = solid_fill_classify;
85    img->common.property_changed = solid_fill_property_changed;
86
87    solid_fill_property_changed (img);
88
89    return img;
90}
91
92