2 ##########################################################################
4 # Copyright 2008-2009 VMware, Inc.
7 # Permission is hereby granted, free of charge, to any person obtaining a copy
8 # of this software and associated documentation files (the "Software"), to deal
9 # in the Software without restriction, including without limitation the rights
10 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 # copies of the Software, and to permit persons to whom the Software is
12 # furnished to do so, subject to the following conditions:
14 # The above copyright notice and this permission notice shall be included in
15 # all copies or substantial portions of the Software.
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 ##########################################################################/
41 # See http://www.pythonware.com/library/pil/handbook/imagemath.htm
42 mask = ImageMath.eval("min(abs(a - b), 1)", a=im, b=ref)
43 gray = ref.convert('L')
47 def surface(html, image):
49 html.write(' <td><a href="%s"><img src="%s"/></a></td>\n' % (image, image))
51 name, ext = os.path.splitext(image)
52 thumb = name + '_thumb' + ext
53 if not os.path.exists(thumb) and os.path.exists(image):
54 im = Image.open(image)
55 im.thumbnail(thumb_size)
57 html.write(' <td><a href="%s"><img src="%s"/></a></td>\n' % (image, thumb))
61 optparser = optparse.OptionParser(
62 usage="\n\t%prog [options] [file] ...",
65 '-o', '--output', metavar='FILE',
66 type="string", dest="output",
67 help="output filename [stdout]")
69 '--start', metavar='FRAME',
70 type="int", dest="start", default=1,
71 help="start frame [default: %default]")
73 '--stop', metavar='FRAME',
74 type="int", dest="stop", default=9999,
75 help="stop frame [default: %default]")
78 type="string", dest="fuzz", default='5%',
79 help="fuzz [default: %default]")
81 (options, args) = optparser.parse_args(sys.argv[1:])
84 optparser.error('incorrect number of arguments')
86 ref_prefix = sys.argv[1]
87 src_prefix = sys.argv[2]
90 html = open(options.output, 'wt')
93 html.write('<html>\n')
94 html.write(' <body>\n')
95 html.write(' <table border="1">\n')
96 html.write(' <tr><th><th>ref</th><th>src</th><th>Δ</th></tr>\n')
97 for frame_no in range(options.start, options.stop + 1):
98 ref_image = "%s%04u.png" % (ref_prefix, frame_no)
99 src_image = "%s%04u.png" % (src_prefix, frame_no)
100 delta_image = "%s%04u_diff.png" % (src_prefix, frame_no)
101 if os.path.exists(ref_image) and os.path.exists(src_image):
102 html.write(' <tr>\n')
103 subprocess.call(["compare", '-metric', 'AE', '-fuzz', options.fuzz, ref_image, src_image, delta_image])
104 surface(html, ref_image)
105 surface(html, src_image)
106 surface(html, delta_image)
107 html.write(' </tr>\n')
109 html.write(' </table>\n')
110 html.write(' </body>\n')
111 html.write('</html>\n')
114 if __name__ == '__main__':