pixman-solid-fill.c revision 953d7d37
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 29void 30_pixman_solid_fill_iter_init (pixman_image_t *image, 31 pixman_iter_t *iter, 32 int x, int y, int width, int height, 33 uint8_t *buffer, iter_flags_t flags) 34{ 35 if (flags & ITER_NARROW) 36 { 37 uint32_t *b = (uint32_t *)buffer; 38 uint32_t *e = b + width; 39 uint32_t color = image->solid.color_32; 40 41 while (b < e) 42 *(b++) = color; 43 } 44 else 45 { 46 uint64_t *b = (uint64_t *)buffer; 47 uint64_t *e = b + width; 48 uint64_t color = image->solid.color_64; 49 50 while (b < e) 51 *(b++) = color; 52 } 53 54 iter->get_scanline = _pixman_iter_get_scanline_noop; 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 67static uint64_t 68color_to_uint64 (const pixman_color_t *color) 69{ 70 return 71 ((uint64_t)color->alpha << 48) | 72 ((uint64_t)color->red << 32) | 73 ((uint64_t)color->green << 16) | 74 ((uint64_t)color->blue); 75} 76 77PIXMAN_EXPORT pixman_image_t * 78pixman_image_create_solid_fill (pixman_color_t *color) 79{ 80 pixman_image_t *img = _pixman_image_allocate (); 81 82 if (!img) 83 return NULL; 84 85 img->type = SOLID; 86 img->solid.color = *color; 87 img->solid.color_32 = color_to_uint32 (color); 88 img->solid.color_64 = color_to_uint64 (color); 89 90 return img; 91} 92 93