blob: d99a4acf81b0aaeb7791d2027ec368dd6d0c9578 [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',
Michel Dänzere4246252011-02-24 09:20:52 -080070 type="int", dest="start", default=0,
José Fonsecaf87d8c62011-02-15 12:19:11 +000071 help="start frame [default: %default]")
72 optparser.add_option(
73 '--stop', metavar='FRAME',
Michel Dänzere4246252011-02-24 09:20:52 -080074 type="int", dest="stop", default=0xffffffff,
José Fonsecaf87d8c62011-02-15 12:19:11 +000075 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')
José Fonseca448d4232011-04-13 17:39:04 +010096 html.write(' <tr><th>ref</th><th>src</th><th>&Delta;</th></tr>\n')
Michel Dänzere4246252011-02-24 09:20:52 -080097 frame_no = options.start
98 while frame_no <= options.stop:
99 ref_image = "%s%010u.png" % (ref_prefix, frame_no)
100 src_image = "%s%010u.png" % (src_prefix, frame_no)
101 delta_image = "%s%010u_diff.png" % (src_prefix, frame_no)
José Fonsecaf87d8c62011-02-15 12:19:11 +0000102 if os.path.exists(ref_image) and os.path.exists(src_image):
103 html.write(' <tr>\n')
104 subprocess.call(["compare", '-metric', 'AE', '-fuzz', options.fuzz, ref_image, src_image, delta_image])
105 surface(html, ref_image)
106 surface(html, src_image)
107 surface(html, delta_image)
108 html.write(' </tr>\n')
109 html.flush()
Michel Dänzere4246252011-02-24 09:20:52 -0800110 frame_no += 1
José Fonsecaf87d8c62011-02-15 12:19:11 +0000111 html.write(' </table>\n')
112 html.write(' </body>\n')
113 html.write('</html>\n')
114
115
116if __name__ == '__main__':
117 main()