pixman-solid-fill.c revision 953d7d37
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 24a450e446Smrg#ifdef HAVE_CONFIG_H 25317c648bSmrg#include <config.h> 26a450e446Smrg#endif 27317c648bSmrg#include "pixman-private.h" 28317c648bSmrg 29953d7d37Smrgvoid 30953d7d37Smrg_pixman_solid_fill_iter_init (pixman_image_t *image, 31953d7d37Smrg pixman_iter_t *iter, 32953d7d37Smrg int x, int y, int width, int height, 33953d7d37Smrg uint8_t *buffer, iter_flags_t flags) 34317c648bSmrg{ 35953d7d37Smrg if (flags & ITER_NARROW) 36953d7d37Smrg { 37953d7d37Smrg uint32_t *b = (uint32_t *)buffer; 38953d7d37Smrg uint32_t *e = b + width; 39953d7d37Smrg uint32_t color = image->solid.color_32; 40953d7d37Smrg 41953d7d37Smrg while (b < e) 42953d7d37Smrg *(b++) = color; 43953d7d37Smrg } 44953d7d37Smrg else 45953d7d37Smrg { 46953d7d37Smrg uint64_t *b = (uint64_t *)buffer; 47953d7d37Smrg uint64_t *e = b + width; 48953d7d37Smrg uint64_t color = image->solid.color_64; 49953d7d37Smrg 50953d7d37Smrg while (b < e) 51953d7d37Smrg *(b++) = color; 52953d7d37Smrg } 53953d7d37Smrg 54953d7d37Smrg iter->get_scanline = _pixman_iter_get_scanline_noop; 55317c648bSmrg} 56317c648bSmrg 57317c648bSmrgstatic uint32_t 58317c648bSmrgcolor_to_uint32 (const pixman_color_t *color) 59317c648bSmrg{ 60317c648bSmrg return 61d0321353Smrg (color->alpha >> 8 << 24) | 62d0321353Smrg (color->red >> 8 << 16) | 63317c648bSmrg (color->green & 0xff00) | 64d0321353Smrg (color->blue >> 8); 65317c648bSmrg} 66317c648bSmrg 67952204abSmrgstatic uint64_t 68952204abSmrgcolor_to_uint64 (const pixman_color_t *color) 69952204abSmrg{ 70952204abSmrg return 71952204abSmrg ((uint64_t)color->alpha << 48) | 72952204abSmrg ((uint64_t)color->red << 32) | 73952204abSmrg ((uint64_t)color->green << 16) | 74952204abSmrg ((uint64_t)color->blue); 75952204abSmrg} 76952204abSmrg 77317c648bSmrgPIXMAN_EXPORT pixman_image_t * 78317c648bSmrgpixman_image_create_solid_fill (pixman_color_t *color) 79317c648bSmrg{ 80d0321353Smrg pixman_image_t *img = _pixman_image_allocate (); 81d0321353Smrg 82317c648bSmrg if (!img) 83317c648bSmrg return NULL; 84317c648bSmrg 85317c648bSmrg img->type = SOLID; 86952204abSmrg img->solid.color = *color; 87952204abSmrg img->solid.color_32 = color_to_uint32 (color); 88952204abSmrg img->solid.color_64 = color_to_uint64 (color); 89317c648bSmrg 90317c648bSmrg return img; 91317c648bSmrg} 92d0321353Smrg 93