From: José Fonseca Date: Sun, 11 Dec 2011 12:34:40 +0000 (+0000) Subject: Fail image comparison when there is a size mismatch. X-Git-Tag: 2.0_alpha^2~387 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ff1c0f2e00d211a38e52bfcddadb2771b0f63c2a;p=tools%2Fapitrace.git Fail image comparison when there is a size mismatch. --- diff --git a/scripts/snapdiff.py b/scripts/snapdiff.py index 9253d16..857c0df 100755 --- a/scripts/snapdiff.py +++ b/scripts/snapdiff.py @@ -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 @@ -89,6 +95,10 @@ class Comparer: 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])