tests: implement visualize_image_difference()
Useful for pointing out where the image comparisons fail.
Internal-screenshot-test is modified to save the visualization if the
test fails.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Daniel Stone <daniels@collabora.com>
diff --git a/tests/internal-screenshot-test.c b/tests/internal-screenshot-test.c
index 81ff013..458ebdb 100644
--- a/tests/internal-screenshot-test.c
+++ b/tests/internal-screenshot-test.c
@@ -68,6 +68,7 @@
struct buffer *screenshot = NULL;
pixman_image_t *reference_good = NULL;
pixman_image_t *reference_bad = NULL;
+ pixman_image_t *diffimg;
struct rectangle clip;
const char *fname;
bool match = false;
@@ -139,6 +140,12 @@
printf("Clip: %d,%d %d x %d\n", clip.x, clip.y, clip.width, clip.height);
match = check_images_match(screenshot->image, reference_good, &clip);
printf("Screenshot %s reference image in clipped area\n", match? "matches" : "doesn't match");
+ if (!match) {
+ diffimg = visualize_image_difference(screenshot->image, reference_good, &clip);
+ fname = screenshot_output_filename("internal-screenshot-error", 0);
+ write_image_as_png(diffimg, fname);
+ pixman_image_unref(diffimg);
+ }
pixman_image_unref(reference_good);
/* Test dumping of non-matching images */