reftest_compare_surfaces: Report how much the images differ

Some of the reftests don't produce *identical* results on all
architectures, but do produce results that are visually
indistinguishable. Report how many pixels differ and by how much, so we
can get an idea of what's a rounding error and what's a serious problem.

Signed-off-by: Simon McVittie <smcv@debian.org>
This commit is contained in:
Simon McVittie
2021-02-13 18:26:24 +00:00
parent 9448e97385
commit 724908065b
4 changed files with 46 additions and 6 deletions

View File

@@ -232,11 +232,19 @@ main (int argc, char **argv)
}
else
{
guint max_diff = 0;
guint pixels_changed = 0;
guint pixels = 0;
/* Now compare the two */
diff_surface = reftest_compare_surfaces (rendered_surface, reference_surface);
diff_surface = reftest_compare_surfaces (rendered_surface, reference_surface,
&max_diff, &pixels_changed, &pixels);
if (diff_surface)
{
g_print ("%u (out of %u) pixels differ from reference by up to %u levels\n",
pixels_changed, pixels, max_diff);
save_image (diff_surface, node_file, ".diff.png");
cairo_surface_destroy (diff_surface);
success = FALSE;

View File

@@ -296,6 +296,9 @@ test_ui_file (GFile *file)
char *ui_file, *reference_file;
cairo_surface_t *ui_image, *reference_image, *diff_image;
GtkStyleProvider *provider;
guint max_diff = 0;
guint pixels_changed = 0;
guint pixels = 0;
ui_file = g_file_get_path (file);
@@ -315,12 +318,16 @@ test_ui_file (GFile *file)
}
g_free (reference_file);
diff_image = reftest_compare_surfaces (ui_image, reference_image);
diff_image = reftest_compare_surfaces (ui_image, reference_image,
&max_diff, &pixels_changed, &pixels);
save_image (ui_image, ui_file, ".out.png");
save_image (reference_image, ui_file, ".ref.png");
if (diff_image)
{
g_test_message ("%u (out of %u) pixels differ from reference by up to %u levels",
pixels_changed, pixels, max_diff);
save_image (diff_image, ui_file, ".diff.png");
g_test_fail ();
}

View File

@@ -83,12 +83,16 @@ buffer_diff_core (const guchar *buf_a,
const guchar *buf_b,
int stride_b,
int width,
int height)
int height,
guint *max_diff_out,
guint *pixels_changed_out)
{
int x, y;
guchar *buf_diff = NULL;
int stride_diff = 0;
cairo_surface_t *diff = NULL;
guint max_diff = 0;
guint pixels_changed = 0;
for (y = 0; y < height; y++)
{
@@ -124,6 +128,10 @@ buffer_diff_core (const guchar *buf_a,
guint channel_diff;
channel_diff = ABS (value_a - value_b);
if (channel_diff > max_diff)
max_diff = channel_diff;
channel_diff *= 4; /* emphasize */
if (channel_diff)
channel_diff += 128; /* make sure it's visible */
@@ -132,6 +140,8 @@ buffer_diff_core (const guchar *buf_a,
diff_pixel |= channel_diff << (channel * 8);
}
pixels_changed++;
if ((diff_pixel & 0x00ffffff) == 0)
{
/* alpha only difference, convert to luminance */
@@ -143,12 +153,21 @@ buffer_diff_core (const guchar *buf_a,
}
}
if (max_diff_out != NULL)
*max_diff_out = max_diff;
if (pixels_changed_out != NULL)
*pixels_changed_out = pixels_changed;
return diff;
}
cairo_surface_t *
reftest_compare_surfaces (cairo_surface_t *surface1,
cairo_surface_t *surface2)
cairo_surface_t *surface2,
guint *max_diff_out,
guint *pixels_changed_out,
guint *pixels_out)
{
int w1, h1, w2, h2, w, h;
cairo_surface_t *coerced1, *coerced2, *diff;
@@ -164,11 +183,14 @@ reftest_compare_surfaces (cairo_surface_t *surface1,
cairo_image_surface_get_stride (coerced1),
cairo_image_surface_get_data (coerced2),
cairo_image_surface_get_stride (coerced2),
w, h);
w, h, max_diff_out, pixels_changed_out);
cairo_surface_destroy (coerced1);
cairo_surface_destroy (coerced2);
if (pixels_out != NULL)
*pixels_out = w * h;
return diff;
}

View File

@@ -24,7 +24,10 @@ G_BEGIN_DECLS
G_MODULE_EXPORT
cairo_surface_t * reftest_compare_surfaces (cairo_surface_t *surface1,
cairo_surface_t *surface2);
cairo_surface_t *surface2,
guint *max_diff_out,
guint *pixels_changed_out,
guint *pixels_out);
G_END_DECLS