[Pixman] [PATCH 2/7] test/utils.[ch]: Add pixel_checker_convert_pixel_to_color()

Søren Sandmann sandmann at cs.au.dk
Thu Jan 24 07:52:54 PST 2013


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

This function takes a pixel in the format corresponding to the pixel
checker, and converts to a color_t.
---
 test/utils.c |   36 ++++++++++++++++++++++++++++++++++++
 test/utils.h |    4 ++++
 2 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/test/utils.c b/test/utils.c
index 27d8fd9..eed2476 100644
--- a/test/utils.c
+++ b/test/utils.c
@@ -1421,6 +1421,42 @@ pixel_checker_split_pixel (const pixel_checker_t *checker, uint32_t pixel,
     *b = (pixel & checker->bm) >> checker->bs;
 }
 
+void
+pixel_checker_convert_pixel_to_color (const pixel_checker_t *checker,
+                                      uint32_t pixel, color_t *color)
+{
+    int a, r, g, b;
+
+    pixel_checker_split_pixel (checker, pixel, &a, &r, &g, &b);
+
+    if (checker->am == 0)
+        color->a = 1.0;
+    else
+        color->a = a / (double)(checker->am >> checker->as);
+
+    if (checker->rm == 0)
+        color->r = 0.0;
+    else
+        color->r = r / (double)(checker->rm >> checker->rs);
+
+    if (checker->gm == 0)
+        color->g = 0.0;
+    else
+        color->g = g / (double)(checker->gm >> checker->gs);
+
+    if (checker->bm == 0)
+        color->b = 0.0;
+    else
+        color->b = b / (double)(checker->bm >> checker->bs);
+
+    if (PIXMAN_FORMAT_TYPE (checker->format) == PIXMAN_TYPE_ARGB_SRGB)
+    {
+	color->r = convert_srgb_to_linear (color->r);
+	color->g = convert_srgb_to_linear (color->g);
+	color->b = convert_srgb_to_linear (color->b);
+    }
+}
+
 static int32_t
 convert (double v, uint32_t width, uint32_t mask, uint32_t shift, double def)
 {
diff --git a/test/utils.h b/test/utils.h
index 162aacb..f6dc193 100644
--- a/test/utils.h
+++ b/test/utils.h
@@ -225,3 +225,7 @@ pixel_checker_get_min (const pixel_checker_t *checker, color_t *color,
 pixman_bool_t
 pixel_checker_check (const pixel_checker_t *checker,
 		     uint32_t pixel, color_t *color);
+
+void
+pixel_checker_convert_pixel_to_color (const pixel_checker_t *checker,
+                                      uint32_t pixel, color_t *color);
-- 
1.7.4



More information about the Pixman mailing list