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> (cherry picked from commit ce626fb3939b0f200d85ccdf32809608b879212d)
This commit is contained in:
parent
364f232507
commit
9a8a26270c
@ -173,6 +173,29 @@ compare_component (int a, int b)
|
|||||||
return ABS (a - b) <= 1;
|
return ABS (a - b) <= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
void
|
||||||
test_utils_compare_pixel (const uint8_t *screen_pixel, uint32_t expected_pixel)
|
test_utils_compare_pixel (const uint8_t *screen_pixel, uint32_t expected_pixel)
|
||||||
{
|
{
|
||||||
|
@ -102,6 +102,19 @@ test_utils_check_region (CoglFramebuffer *framebuffer,
|
|||||||
void
|
void
|
||||||
test_utils_compare_pixel (const uint8_t *screen_pixel, uint32_t expected_pixel);
|
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:
|
* test_utils_create_color_texture:
|
||||||
* @context: A #CoglContext
|
* @context: A #CoglContext
|
||||||
|
@ -12,22 +12,14 @@ static void
|
|||||||
test_color (CoglTexture *texture,
|
test_color (CoglTexture *texture,
|
||||||
uint32_t expected_pixel)
|
uint32_t expected_pixel)
|
||||||
{
|
{
|
||||||
uint32_t received_pixel;
|
uint8_t received_pixel[4];
|
||||||
char *received_value_str;
|
|
||||||
char *expected_value_str;
|
|
||||||
|
|
||||||
cogl_texture_get_data (texture,
|
cogl_texture_get_data (texture,
|
||||||
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
||||||
4, /* rowstride */
|
4, /* rowstride */
|
||||||
(uint8_t *) &received_pixel);
|
received_pixel);
|
||||||
|
|
||||||
received_pixel = GUINT32_FROM_BE (received_pixel);
|
test_utils_compare_pixel_and_alpha (received_pixel, expected_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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user