pixman-solid-fill.c revision 317c648b
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
24317c648bSmrg#include <config.h>
25317c648bSmrg#include "pixman-private.h"
26317c648bSmrg
27317c648bSmrgstatic void
28317c648bSmrgsolid_fill_get_scanline_32 (pixman_image_t *image, int x, int y, int width,
29317c648bSmrg			    uint32_t *buffer, uint32_t *mask, uint32_t maskBits)
30317c648bSmrg{
31317c648bSmrg    uint32_t *end = buffer + width;
32317c648bSmrg    register uint32_t color = ((solid_fill_t *)image)->color;
33317c648bSmrg
34317c648bSmrg    while (buffer < end)
35317c648bSmrg	*(buffer++) = color;
36317c648bSmrg
37317c648bSmrg    return;
38317c648bSmrg}
39317c648bSmrg
40317c648bSmrgstatic source_pict_class_t
41317c648bSmrgsolid_fill_classify (pixman_image_t *image,
42317c648bSmrg		     int	     x,
43317c648bSmrg		     int	     y,
44317c648bSmrg		     int	     width,
45317c648bSmrg		     int	     height)
46317c648bSmrg{
47317c648bSmrg    return (image->source.class = SOURCE_IMAGE_CLASS_HORIZONTAL);
48317c648bSmrg}
49317c648bSmrg
50317c648bSmrgstatic void
51317c648bSmrgsolid_fill_property_changed (pixman_image_t *image)
52317c648bSmrg{
53317c648bSmrg    image->common.get_scanline_32 = (scanFetchProc)solid_fill_get_scanline_32;
54317c648bSmrg    image->common.get_scanline_64 = (scanFetchProc)_pixman_image_get_scanline_64_generic;
55317c648bSmrg}
56317c648bSmrg
57317c648bSmrgstatic uint32_t
58317c648bSmrgcolor_to_uint32 (const pixman_color_t *color)
59317c648bSmrg{
60317c648bSmrg    return
61317c648bSmrg	(color->alpha >> 8 << 24) |
62317c648bSmrg	(color->red >> 8 << 16) |
63317c648bSmrg        (color->green & 0xff00) |
64317c648bSmrg	(color->blue >> 8);
65317c648bSmrg}
66317c648bSmrg
67317c648bSmrgPIXMAN_EXPORT pixman_image_t *
68317c648bSmrgpixman_image_create_solid_fill (pixman_color_t *color)
69317c648bSmrg{
70317c648bSmrg    pixman_image_t *img = _pixman_image_allocate();
71317c648bSmrg
72317c648bSmrg    if (!img)
73317c648bSmrg	return NULL;
74317c648bSmrg
75317c648bSmrg    img->type = SOLID;
76317c648bSmrg    img->solid.color = color_to_uint32 (color);
77317c648bSmrg
78317c648bSmrg    img->source.class = SOURCE_IMAGE_CLASS_UNKNOWN;
79317c648bSmrg    img->common.classify = solid_fill_classify;
80317c648bSmrg    img->common.property_changed = solid_fill_property_changed;
81317c648bSmrg
82317c648bSmrg    solid_fill_property_changed (img);
83317c648bSmrg
84317c648bSmrg    return img;
85317c648bSmrg}
86