[Pixman] [PATCH 1/3] test/utils.[ch]: Add utility function to draw a checkerboard

Søren Sandmann sandmann at cs.au.dk
Sat Dec 8 10:05:45 PST 2012


From: Søren Sandmann Pedersen <ssp at redhat.com>

This is useful in demo programs to display the alpha channel.
---
 test/utils.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 test/utils.h |  5 +++++
 2 files changed, 59 insertions(+)

diff --git a/test/utils.c b/test/utils.c
index 66c8dcb..08eaabb 100644
--- a/test/utils.c
+++ b/test/utils.c
@@ -548,6 +548,60 @@ write_png (pixman_image_t *image, const char *filename)
 
 #endif
 
+static void
+color8_to_color16 (uint32_t color8, pixman_color_t *color16)
+{
+    color16->alpha = ((color8 & 0xff000000) >> 24);
+    color16->red =   ((color8 & 0x00ff0000) >> 16);
+    color16->green = ((color8 & 0x0000ff00) >> 8);
+    color16->blue =  ((color8 & 0x000000ff) >> 0);
+
+    color16->alpha |= color16->alpha << 8;
+    color16->red   |= color16->red << 8;
+    color16->blue  |= color16->blue << 8;
+    color16->green |= color16->green << 8;
+}
+
+void
+draw_checkerboard (pixman_image_t *image,
+		   int check_size,
+		   uint32_t color1, uint32_t color2)
+{
+    pixman_color_t check1, check2;
+    pixman_image_t *c1, *c2;
+    int n_checks_x, n_checks_y;
+    int i, j;
+
+    color8_to_color16 (color1, &check1);
+    color8_to_color16 (color2, &check2);
+    
+    c1 = pixman_image_create_solid_fill (&check1);
+    c2 = pixman_image_create_solid_fill (&check2);
+
+    n_checks_x = (
+	pixman_image_get_width (image) + check_size - 1) / check_size;
+    n_checks_y = (
+	pixman_image_get_height (image) + check_size - 1) / check_size;
+
+    for (j = 0; j < n_checks_y; j++)
+    {
+	for (i = 0; i < n_checks_x; i++)
+	{
+	    pixman_image_t *src;
+
+	    if (((i ^ j) & 1))
+		src = c1;
+	    else
+		src = c2;
+
+	    pixman_image_composite32 (PIXMAN_OP_SRC, src, NULL, image,
+				      0, 0, 0, 0,
+				      i * check_size, j * check_size,
+				      check_size, check_size);
+	}
+    }
+}
+
 /*
  * A function, which can be used as a core part of the test programs,
  * intended to detect various problems with the help of fuzzing input
diff --git a/test/utils.h b/test/utils.h
index 78cf0d1..45b457e 100644
--- a/test/utils.h
+++ b/test/utils.h
@@ -124,6 +124,11 @@ 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);
 
+void
+draw_checkerboard (pixman_image_t *image,
+		   int check_size,
+		   uint32_t color1, uint32_t color2);
+
 /* A pair of macros which can help to detect corruption of
  * floating point registers after a function call. This may
  * happen if _mm_empty() call is forgotten in MMX/SSE2 fast
-- 
1.7.11.7



More information about the Pixman mailing list