]> git.cworth.org Git - apitrace/blobdiff - scripts/snapdiff.py
Filter to mitigate rasterization differences.
[apitrace] / scripts / snapdiff.py
index b7bad72336d0e06818c5e1315a7f381c385da7df..bf3768646acfceb1e296ebb431e5ab97346ad8cf 100755 (executable)
@@ -39,10 +39,12 @@ import operator
 from PIL import Image
 from PIL import ImageChops
 from PIL import ImageEnhance
+from PIL import ImageFilter
 
 
 thumb_size = 320, 320
 
+gaussian_kernel = ImageFilter.Kernel((3, 3), [1, 2, 1, 2, 4, 2, 1, 2, 1], 16)
 
 class Comparer:
     '''Image comparer.'''
@@ -80,12 +82,16 @@ class Comparer:
         diff_im = Image.blend(self.src_im, diff_im, 0xcc/255.0)
         diff_im.save(diff_image)
 
-    def precision(self):
+    def precision(self, filter=False):
         if self.size_mismatch():
             return 0.0
 
+        diff = self.diff
+        if filter:
+            diff = diff.filter(gaussian_kernel)
+
         # See also http://effbot.org/zone/pil-comparing-images.htm
-        h = self.diff.histogram()
+        h = diff.histogram()
         square_error = 0
         for i in range(1, 256):
             square_error += sum(h[i : 3*256: 256])*i*i
@@ -121,10 +127,11 @@ def surface(html, image):
 
 
 def is_image(path):
-    return \
-        path.endswith('.png') \
-        and not path.endswith('.diff.png') \
-        and not path.endswith('.thumb.png')
+    name = os.path.basename(path)
+    name, ext1 = os.path.splitext(name)
+    name, ext2 = os.path.splitext(name)
+    print name, ext1, ext2
+    return ext1 in ('.png', '.bmp') and ext2 not in ('.diff', '.thumb')
 
 
 def find_images(prefix):