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