test-utils: Add some fuzz to the pixel comparison routine
When comparing a pixel, the comparison routines now allow each component to be off by +/- 1. This is to compensate for varying rounding across drivers. https://bugzilla.gnome.org/show_bug.cgi?id=665723 Reviewed-by: Robert Bragg <robert@linux.intel.com>
This commit is contained in:
parent
39203cb8f1
commit
4c8966122f
@ -79,24 +79,43 @@ test_utils_fini (TestUtilsGTestFixture *fixture,
|
||||
cogl_object_unref (state->ctx);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
compare_component (int a, int b)
|
||||
{
|
||||
return ABS (a - b) <= 1;
|
||||
}
|
||||
|
||||
static void
|
||||
compare_pixel (const guint8 *screen_pixel, guint32 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))
|
||||
{
|
||||
guint32 screen_pixel_num = GUINT32_FROM_BE (*(guint32 *) screen_pixel);
|
||||
char *screen_pixel_string =
|
||||
g_strdup_printf ("#%06x", screen_pixel_num >> 8);
|
||||
char *expected_pixel_string =
|
||||
g_strdup_printf ("#%06x", expected_pixel >> 8);
|
||||
|
||||
g_assert_cmpstr (screen_pixel_string, ==, expected_pixel_string);
|
||||
|
||||
g_free (screen_pixel_string);
|
||||
g_free (expected_pixel_string);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
test_utils_check_pixel (int x, int y, guint32 expected_pixel)
|
||||
{
|
||||
guint32 pixel;
|
||||
char *screen_pixel;
|
||||
char *intended_pixel;
|
||||
guint8 pixel[4];
|
||||
|
||||
cogl_read_pixels (x, y, 1, 1, COGL_READ_PIXELS_COLOR_BUFFER,
|
||||
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
||||
(guint8 *) &pixel);
|
||||
pixel);
|
||||
|
||||
screen_pixel = g_strdup_printf ("#%06x", GUINT32_FROM_BE (pixel) >> 8);
|
||||
intended_pixel = g_strdup_printf ("#%06x", expected_pixel >> 8);
|
||||
|
||||
g_assert_cmpstr (screen_pixel, ==, intended_pixel);
|
||||
|
||||
g_free (screen_pixel);
|
||||
g_free (intended_pixel);
|
||||
compare_pixel (pixel, expected_pixel);
|
||||
}
|
||||
|
||||
void
|
||||
@ -110,7 +129,6 @@ test_utils_check_region (int x, int y,
|
||||
int width, int height,
|
||||
guint32 expected_rgba)
|
||||
{
|
||||
guint32 reference = expected_rgba >> 8;
|
||||
guint8 *pixels, *p;
|
||||
|
||||
pixels = p = g_malloc (width * height * 4);
|
||||
@ -126,14 +144,7 @@ test_utils_check_region (int x, int y,
|
||||
for (y = 0; y < height; y++)
|
||||
for (x = 0; x < width; x++)
|
||||
{
|
||||
guint32 current = GUINT32_FROM_BE (*((guint32 *)p)) >> 8;
|
||||
if (current != reference)
|
||||
{
|
||||
/* Ensure we have a meaningful error message... */
|
||||
char *screen_pixel = g_strdup_printf ("#%06x", current);
|
||||
char *intended_pixel = g_strdup_printf ("#%06x", reference);
|
||||
g_assert_cmpstr (screen_pixel, == ,intended_pixel);
|
||||
}
|
||||
compare_pixel (p, expected_rgba);
|
||||
p += 4;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user