]> git.cworth.org Git - apitrace/blobdiff - scripts/snapdiff.py
Move trace dumping to a separate module. Add option to not dump arg names.
[apitrace] / scripts / snapdiff.py
index 0ed3937a8f8e669accf577c4b06d6472784e3c57..857c0dfbdc00415435f69c3c947a1cec180381ae 100755 (executable)
@@ -65,6 +65,9 @@ class Comparer:
 
         self.diff = ImageChops.difference(self.src_im, self.ref_im)
 
+    def size_mismatch(self):
+        return self.ref_im.size != self.src_im.size
+
     def write_diff(self, diff_image, fuzz = 0.05):
         # make a difference image similar to ImageMagick's compare utility
         mask = ImageEnhance.Brightness(self.diff).enhance(1.0/fuzz)
@@ -78,6 +81,9 @@ class Comparer:
         diff_im.save(diff_image)
 
     def precision(self):
+        if self.size_mismatch():
+            return 0.0
+
         # See also http://effbot.org/zone/pil-comparing-images.htm
         h = self.diff.histogram()
         square_error = 0
@@ -87,8 +93,12 @@ class Comparer:
         bits = -math.log(rel_error)/math.log(2.0)
         return bits
 
-    def ae(self):
+    def ae(self, fuzz = 0.05):
         # Compute absolute error
+
+        if self.size_mismatch():
+            return sys.maxint
+
         # TODO: this is approximate due to the grayscale conversion
         h = self.diff.convert('L').histogram()
         ae = sum(h[int(255 * fuzz) + 1 : 256])
@@ -138,8 +148,7 @@ def main():
     global options
 
     optparser = optparse.OptionParser(
-        usage="\n\t%prog [options] <ref_prefix> <src_prefix>",
-        version="%%prog")
+        usage="\n\t%prog [options] <ref_prefix> <src_prefix>")
     optparser.add_option(
         '-o', '--output', metavar='FILE',
         type="string", dest="output", default='index.html',