File: reftest_compare_surfaces-Report-how-much-the-images-diffe.patch

package info (click to toggle)
gtk%2B3.0 3.24.49-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 181,504 kB
  • sloc: ansic: 669,492; xml: 8,780; javascript: 6,630; python: 1,322; sh: 674; perl: 370; makefile: 212; cpp: 34
file content (142 lines) | stat: -rw-r--r-- 5,232 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
From: Simon McVittie <smcv@debian.org>
Date: Sat, 13 Feb 2021 18:26:24 +0000
Subject: reftest_compare_surfaces: Report how much the images differ

In unattended/non-interactive/autobuilder environments where the images
are not trivially accessible, this provides a way to distinguish between
totally different rendering and more subtle issues.

Signed-off-by: Simon McVittie <smcv@debian.org>
Forwarded: https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/3195
Applied-upstream: no, upstream want reftests to be a strict pass/fail with identical results required
---
 testsuite/reftests/gtk-reftest.c     |  9 ++++++++-
 testsuite/reftests/reftest-compare.c | 28 +++++++++++++++++++++++++---
 testsuite/reftests/reftest-compare.h |  5 ++++-
 3 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/testsuite/reftests/gtk-reftest.c b/testsuite/reftests/gtk-reftest.c
index 88d8a84..814dc67 100644
--- a/testsuite/reftests/gtk-reftest.c
+++ b/testsuite/reftests/gtk-reftest.c
@@ -266,6 +266,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);
 
@@ -285,12 +288,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 ();
     }
diff --git a/testsuite/reftests/reftest-compare.c b/testsuite/reftests/reftest-compare.c
index 84c560c..33379eb 100644
--- a/testsuite/reftests/reftest-compare.c
+++ b/testsuite/reftests/reftest-compare.c
@@ -84,12 +84,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++)
     {
@@ -125,6 +129,10 @@ buffer_diff_core (const guchar *buf_a,
               guint diff;
 
               diff = ABS (value_a - value_b);
+
+              if (diff > max_diff)
+                max_diff = diff;
+
               diff *= 4;  /* emphasize */
               if (diff)
                 diff += 128; /* make sure it's visible */
@@ -133,6 +141,8 @@ buffer_diff_core (const guchar *buf_a,
               diff_pixel |= diff << (channel*8);
             }
 
+          pixels_changed++;
+
           if ((diff_pixel & 0x00ffffff) == 0)
             {
               /* alpha only difference, convert to luminance */
@@ -144,12 +154,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 *diff;
@@ -165,7 +184,10 @@ reftest_compare_surfaces (cairo_surface_t *surface1,
                            cairo_image_surface_get_stride (surface1),
                            cairo_image_surface_get_data (surface2),
                            cairo_image_surface_get_stride (surface2),
-                           w, h);
+                           w, h, max_diff_out, pixels_changed_out);
+
+  if (pixels_out != NULL)
+    *pixels_out = w * h;
 
   return diff;
 }
diff --git a/testsuite/reftests/reftest-compare.h b/testsuite/reftests/reftest-compare.h
index 551b1c5..c6e001c 100644
--- a/testsuite/reftests/reftest-compare.h
+++ b/testsuite/reftests/reftest-compare.h
@@ -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