[cogl] test-write-texture-formats: Add fuzziness to the pixel comparisons



commit ce626fb3939b0f200d85ccdf32809608b879212d
Author: Neil Roberts <neil linux intel com>
Date:   Mon Jan 21 18:43:24 2013 +0000

    test-write-texture-formats: Add fuzziness to the pixel comparisons
    
    The rounding used when storing 10-bit per component data into an 8-bit
    per component texture seems to have changed in recent versions of Mesa
    which was causing this test to fail. I've also noticed this failing on
    the NVidia binary driver. This patch adds some fuzziness to the
    comparison so that it will pass. There is a new test_utils function
    called test_utils_compare_pixel_and_alpha which is the same as
    test_utils_compare_pixel except that it also compares the alpha
    component.
    
    Reviewed-by: Robert Bragg <robert linux intel com>

 tests/conform/test-utils.c                 |   23 +++++++++++++++++++++++
 tests/conform/test-utils.h                 |   13 +++++++++++++
 tests/conform/test-write-texture-formats.c |   14 +++-----------
 3 files changed, 39 insertions(+), 11 deletions(-)
---
diff --git a/tests/conform/test-utils.c b/tests/conform/test-utils.c
index b085301..653791e 100644
--- a/tests/conform/test-utils.c
+++ b/tests/conform/test-utils.c
@@ -173,6 +173,29 @@ compare_component (int a, int b)
 }
 
 void
+test_utils_compare_pixel_and_alpha (const uint8_t *screen_pixel,
+                                    uint32_t expected_pixel)
+{
+  /* Compare each component with a small fuzz factor */
+  if (!compare_component (screen_pixel[0], expected_pixel >> 24) ||
+      !compare_component (screen_pixel[1], (expected_pixel >> 16) & 0xff) ||
+      !compare_component (screen_pixel[2], (expected_pixel >> 8) & 0xff) ||
+      !compare_component (screen_pixel[3], (expected_pixel >> 0) & 0xff))
+    {
+      uint32_t screen_pixel_num = GUINT32_FROM_BE (*(uint32_t *) screen_pixel);
+      char *screen_pixel_string =
+        g_strdup_printf ("#%08x", screen_pixel_num);
+      char *expected_pixel_string =
+        g_strdup_printf ("#%08x", expected_pixel);
+
+      g_assert_cmpstr (screen_pixel_string, ==, expected_pixel_string);
+
+      g_free (screen_pixel_string);
+      g_free (expected_pixel_string);
+    }
+}
+
+void
 test_utils_compare_pixel (const uint8_t *screen_pixel, uint32_t expected_pixel)
 {
   /* Compare each component with a small fuzz factor */
diff --git a/tests/conform/test-utils.h b/tests/conform/test-utils.h
index e698f32..3f9cdc6 100644
--- a/tests/conform/test-utils.h
+++ b/tests/conform/test-utils.h
@@ -103,6 +103,19 @@ void
 test_utils_compare_pixel (const uint8_t *screen_pixel, uint32_t expected_pixel);
 
 /*
+ * test_utils_compare_pixel_and_alpha:
+ * @screen_pixel: A pixel stored in memory
+ * @expected_pixel: The expected RGBA value
+ *
+ * Compares a pixel from a buffer to an expected value. This is
+ * similar to test_utils_compare_pixel() except that it doesn't ignore
+ * the alpha component.
+ */
+void
+test_utils_compare_pixel_and_alpha (const uint8_t *screen_pixel,
+                                    uint32_t expected_pixel);
+
+/*
  * test_utils_create_color_texture:
  * @context: A #CoglContext
  * @color: A color to put in the texture
diff --git a/tests/conform/test-write-texture-formats.c b/tests/conform/test-write-texture-formats.c
index 8745014..9181a58 100644
--- a/tests/conform/test-write-texture-formats.c
+++ b/tests/conform/test-write-texture-formats.c
@@ -12,22 +12,14 @@ static void
 test_color (CoglTexture *texture,
             uint32_t expected_pixel)
 {
-  uint32_t received_pixel;
-  char *received_value_str;
-  char *expected_value_str;
+  uint8_t received_pixel[4];
 
   cogl_texture_get_data (texture,
                          COGL_PIXEL_FORMAT_RGBA_8888_PRE,
                          4, /* rowstride */
-                         (uint8_t *) &received_pixel);
+                         received_pixel);
 
-  received_pixel = GUINT32_FROM_BE (received_pixel);
-
-  received_value_str = g_strdup_printf ("0x%08x", received_pixel);
-  expected_value_str = g_strdup_printf ("0x%08x", expected_pixel);
-  g_assert_cmpstr (received_value_str, ==, expected_value_str);
-  g_free (received_value_str);
-  g_free (expected_value_str);
+  test_utils_compare_pixel_and_alpha (received_pixel, expected_pixel);
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]