From: Søren Sandmann Pedersen Date: Mon, 2 Apr 2012 19:09:16 +0000 (-0400) Subject: test/utils.c: Rename and export the pngify_pixels() function. X-Git-Tag: pixman-0.25.6~32 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d1ec1467f607c21a4d8b445eab5465ca60a12a97;p=platform%2Fupstream%2Fpixman.git test/utils.c: Rename and export the pngify_pixels() function. This function converts from a8r8g8b8 to non-premultiplied RGBA (the PNG or GdkPixbuf format that has the channels in this order: R, G, B, A in memory regardless of the computer's endianness). The function's new name is a8r8g8b8_to_rgba_np(). --- diff --git a/test/utils.c b/test/utils.c index 379bd71..cc0365a 100644 --- a/test/utils.c +++ b/test/utils.c @@ -340,17 +340,15 @@ make_random_bytes (int n_bytes) return bytes; } -#ifdef HAVE_LIBPNG - -static void -pngify_pixels (uint32_t *pixels, int n_pixels) +void +a8r8g8b8_to_rgba_np (uint32_t *dst, uint32_t *src, int n_pixels) { + uint8_t *dst8 = (uint8_t *)dst; int i; for (i = 0; i < n_pixels; ++i) { - uint32_t p = pixels[i]; - uint8_t *out = (uint8_t *)&(pixels[i]); + uint32_t p = src[i]; uint8_t a, r, g, b; a = (p & 0xff000000) >> 24; @@ -365,13 +363,15 @@ pngify_pixels (uint32_t *pixels, int n_pixels) b = (b * 255) / a; } - *out++ = r; - *out++ = g; - *out++ = b; - *out++ = a; + *dst8++ = r; + *dst8++ = g; + *dst8++ = b; + *dst8++ = a; } } +#ifdef HAVE_LIBPNG + pixman_bool_t write_png (pixman_image_t *image, const char *filename) { @@ -398,7 +398,7 @@ write_png (pixman_image_t *image, const char *filename) pixman_image_composite32 ( PIXMAN_OP_SRC, image, NULL, copy, 0, 0, 0, 0, 0, 0, width, height); - pngify_pixels (data, height * width); + a8r8g8b8_to_rgba_np (data, data, height * width); for (i = 0; i < height; ++i) row_pointers[i] = (png_bytep)(data + i * width); diff --git a/test/utils.h b/test/utils.h index 3c0647b..01af316 100644 --- a/test/utils.h +++ b/test/utils.h @@ -107,6 +107,15 @@ fail_after (int seconds, const char *msg); /* If possible, enable traps for floating point exceptions */ void enable_fp_exceptions(void); +/* Converts a8r8g8b8 pixels to pixels that + * - are not premultiplied, + * - are stored in this order in memory: R, G, B, A, regardless of + * the endianness of the computer. + * It is allowed for @src and @dst to point to the same memory buffer. + */ +void +a8r8g8b8_to_rgba_np (uint32_t *dst, uint32_t *src, int n_pixels); + pixman_bool_t write_png (pixman_image_t *image, const char *filename);