MCPcopy Create free account
hub / github.com/apitrace/apitrace / write_diff

Method write_diff

scripts/snapdiff.py:74–95  ·  view source on GitHub ↗
(self, diff_image, fuzz = 0.05)

Source from the content-addressed store, hash-verified

72 return self.ref_im.size != self.src_im.size
73
74 def write_diff(self, diff_image, fuzz = 0.05):
75 if self.size_mismatch():
76 return
77
78 # Make a difference image similar to ImageMagick's compare utility.
79 #
80 # Basically produces a brightened/faded version of the source image,
81 # but where every pixel for which absolute error is larger than
82 # 255*fuzz will be colored strong red.
83
84 # Take the maximum error across all channels
85 diff_max = reduce(ImageChops.lighter, self.diff.split())
86
87 # Scale values so that pixels equal or above 255*fuzz become 255
88 mask = diff_max.point(lambda x: min(x/fuzz, 255), 'L')
89
90 lowlight = Image.new('RGB', self.src_im.size, (0xff, 0xff, 0xff))
91 highlight = Image.new('RGB', self.src_im.size, (0xf1, 0x00, 0x1e))
92 diff_im = Image.composite(highlight, lowlight, mask)
93
94 diff_im = Image.blend(self.src_im, diff_im, 0xcc/255.0)
95 diff_im.save(diff_image)
96
97 def precision(self, filter=False):
98 if self.size_mismatch():

Callers 2

mainFunction · 0.95
mainFunction · 0.95

Calls 2

size_mismatchMethod · 0.95
saveMethod · 0.80

Tested by

no test coverage detected