pixman-solid-fill.c revision 952204ab
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 29static void 30solid_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 uint32_t mask_bits) 37{ 38 uint32_t *end = buffer + width; 39 uint32_t color = image->solid.color_32; 40 41 while (buffer < end) 42 *(buffer++) = color; 43 44 return; 45} 46 47static void 48solid_fill_get_scanline_64 (pixman_image_t *image, 49 int x, 50 int y, 51 int width, 52 uint32_t * buffer, 53 const uint32_t *mask, 54 uint32_t mask_bits) 55{ 56 uint64_t *b = (uint64_t *)buffer; 57 uint64_t *e = b + width; 58 uint64_t color = image->solid.color_64; 59 60 while (b < e) 61 *(b++) = color; 62} 63 64static source_image_class_t 65solid_fill_classify (pixman_image_t *image, 66 int x, 67 int y, 68 int width, 69 int height) 70{ 71 return (image->source.class = SOURCE_IMAGE_CLASS_HORIZONTAL); 72} 73 74static void 75solid_fill_property_changed (pixman_image_t *image) 76{ 77 image->common.get_scanline_32 = solid_fill_get_scanline_32; 78 image->common.get_scanline_64 = solid_fill_get_scanline_64; 79} 80 81static uint32_t 82color_to_uint32 (const pixman_color_t *color) 83{ 84 return 85 (color->alpha >> 8 << 24) | 86 (color->red >> 8 << 16) | 87 (color->green & 0xff00) | 88 (color->blue >> 8); 89} 90 91static uint64_t 92color_to_uint64 (const pixman_color_t *color) 93{ 94 return 95 ((uint64_t)color->alpha << 48) | 96 ((uint64_t)color->red << 32) | 97 ((uint64_t)color->green << 16) | 98 ((uint64_t)color->blue); 99} 100 101PIXMAN_EXPORT pixman_image_t * 102pixman_image_create_solid_fill (pixman_color_t *color) 103{ 104 pixman_image_t *img = _pixman_image_allocate (); 105 106 if (!img) 107 return NULL; 108 109 img->type = SOLID; 110 img->solid.color = *color; 111 img->solid.color_32 = color_to_uint32 (color); 112 img->solid.color_64 = color_to_uint64 (color); 113 114 img->source.class = SOURCE_IMAGE_CLASS_UNKNOWN; 115 img->common.classify = solid_fill_classify; 116 img->common.property_changed = solid_fill_property_changed; 117 118 return img; 119} 120 121