blob: fda5570e181963e2d841c5b72f58d276e9132bc8 [file] [log] [blame]
José Fonsecaf87d8c62011-02-15 12:19:11 +00001#!/usr/bin/env python
2##########################################################################
3#
4# Copyright 2008-2009 VMware, Inc.
5# All Rights Reserved.
6#
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:
13#
14# The above copyright notice and this permission notice shall be included in
15# all copies or substantial portions of the Software.
16#
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
23# THE SOFTWARE.
24#
25##########################################################################/
26
27
28import sys
29import os.path
30import subprocess
31import optparse
32
33import Image
34
35
36thumb_size = 320, 320
37
38
39def compare(im, ref):
40 import ImageMath
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')
44 # TODO
45
46
47def surface(html, image):
48 if False:
49 html.write(' <td><a href="%s"><img src="%s"/></a></td>\n' % (image, image))
50 else:
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)
56 im.save(thumb)
57 html.write(' <td><a href="%s"><img src="%s"/></a></td>\n' % (image, thumb))
58
59
60def main():
61 optparser = optparse.OptionParser(
62 usage="\n\t%prog [options] [file] ...",
63 version="%%prog")
64 optparser.add_option(
65 '-o', '--output', metavar='FILE',
66 type="string", dest="output",
67 help="output filename [stdout]")
68 optparser.add_option(
69 '--start', metavar='FRAME',
70 type="int", dest="start", default=1,
71 help="start frame [default: %default]")
72 optparser.add_option(
73 '--stop', metavar='FRAME',
74 type="int", dest="stop", default=9999,
75 help="stop frame [default: %default]")
76 optparser.add_option(
77 '-f', '--fuzz',
78 type="string", dest="fuzz", default='5%',
79 help="fuzz [default: %default]")
80
81 (options, args) = optparser.parse_args(sys.argv[1:])
82
83 if len(args) != 2:
84 optparser.error('incorrect number of arguments')
85
José Fonseca2f6720e2011-04-13 15:57:15 +010086 ref_prefix = args[0]
87 src_prefix = args[1]
José Fonsecaf87d8c62011-02-15 12:19:11 +000088
89 if options.output:
90 html = open(options.output, 'wt')
91 else:
92 html = sys.stdout
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>&Delta;</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')
108 html.flush()
109 html.write(' </table>\n')
110 html.write(' </body>\n')
111 html.write('</html>\n')
112
113
114if __name__ == '__main__':
115 main()