From: José Fonseca Date: Tue, 12 Apr 2011 08:17:02 +0000 (+0100) Subject: Move scripts into a sepearate dir, to distinguish for code generation ones. X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=ce36d7be730246190bcc37ea2acc112d9acbfcb2;p=apitrace Move scripts into a sepearate dir, to distinguish for code generation ones. --- diff --git a/scripts/snapdiff.py b/scripts/snapdiff.py new file mode 100755 index 0000000..4eb60a0 --- /dev/null +++ b/scripts/snapdiff.py @@ -0,0 +1,115 @@ +#!/usr/bin/env python +########################################################################## +# +# Copyright 2008-2009 VMware, Inc. +# All Rights Reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +##########################################################################/ + + +import sys +import os.path +import subprocess +import optparse + +import Image + + +thumb_size = 320, 320 + + +def compare(im, ref): + import ImageMath + # See http://www.pythonware.com/library/pil/handbook/imagemath.htm + mask = ImageMath.eval("min(abs(a - b), 1)", a=im, b=ref) + gray = ref.convert('L') + # TODO + + +def surface(html, image): + if False: + html.write(' \n' % (image, image)) + else: + name, ext = os.path.splitext(image) + thumb = name + '_thumb' + ext + if not os.path.exists(thumb) and os.path.exists(image): + im = Image.open(image) + im.thumbnail(thumb_size) + im.save(thumb) + html.write(' \n' % (image, thumb)) + + +def main(): + optparser = optparse.OptionParser( + usage="\n\t%prog [options] [file] ...", + version="%%prog") + optparser.add_option( + '-o', '--output', metavar='FILE', + type="string", dest="output", + help="output filename [stdout]") + optparser.add_option( + '--start', metavar='FRAME', + type="int", dest="start", default=1, + help="start frame [default: %default]") + optparser.add_option( + '--stop', metavar='FRAME', + type="int", dest="stop", default=9999, + help="stop frame [default: %default]") + optparser.add_option( + '-f', '--fuzz', + type="string", dest="fuzz", default='5%', + help="fuzz [default: %default]") + + (options, args) = optparser.parse_args(sys.argv[1:]) + + if len(args) != 2: + optparser.error('incorrect number of arguments') + + ref_prefix = sys.argv[1] + src_prefix = sys.argv[2] + + if options.output: + html = open(options.output, 'wt') + else: + html = sys.stdout + html.write('\n') + html.write(' \n') + html.write(' \n') + html.write(' \n') + for frame_no in range(options.start, options.stop + 1): + ref_image = "%s%04u.png" % (ref_prefix, frame_no) + src_image = "%s%04u.png" % (src_prefix, frame_no) + delta_image = "%s%04u_diff.png" % (src_prefix, frame_no) + if os.path.exists(ref_image) and os.path.exists(src_image): + html.write(' \n') + subprocess.call(["compare", '-metric', 'AE', '-fuzz', options.fuzz, ref_image, src_image, delta_image]) + surface(html, ref_image) + surface(html, src_image) + surface(html, delta_image) + html.write(' \n') + html.flush() + html.write('
refsrcΔ
\n') + html.write(' \n') + html.write('\n') + + +if __name__ == '__main__': + main() diff --git a/snapdiff.py b/snapdiff.py deleted file mode 100755 index 4eb60a0..0000000 --- a/snapdiff.py +++ /dev/null @@ -1,115 +0,0 @@ -#!/usr/bin/env python -########################################################################## -# -# Copyright 2008-2009 VMware, Inc. -# All Rights Reserved. -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -# -##########################################################################/ - - -import sys -import os.path -import subprocess -import optparse - -import Image - - -thumb_size = 320, 320 - - -def compare(im, ref): - import ImageMath - # See http://www.pythonware.com/library/pil/handbook/imagemath.htm - mask = ImageMath.eval("min(abs(a - b), 1)", a=im, b=ref) - gray = ref.convert('L') - # TODO - - -def surface(html, image): - if False: - html.write(' \n' % (image, image)) - else: - name, ext = os.path.splitext(image) - thumb = name + '_thumb' + ext - if not os.path.exists(thumb) and os.path.exists(image): - im = Image.open(image) - im.thumbnail(thumb_size) - im.save(thumb) - html.write(' \n' % (image, thumb)) - - -def main(): - optparser = optparse.OptionParser( - usage="\n\t%prog [options] [file] ...", - version="%%prog") - optparser.add_option( - '-o', '--output', metavar='FILE', - type="string", dest="output", - help="output filename [stdout]") - optparser.add_option( - '--start', metavar='FRAME', - type="int", dest="start", default=1, - help="start frame [default: %default]") - optparser.add_option( - '--stop', metavar='FRAME', - type="int", dest="stop", default=9999, - help="stop frame [default: %default]") - optparser.add_option( - '-f', '--fuzz', - type="string", dest="fuzz", default='5%', - help="fuzz [default: %default]") - - (options, args) = optparser.parse_args(sys.argv[1:]) - - if len(args) != 2: - optparser.error('incorrect number of arguments') - - ref_prefix = sys.argv[1] - src_prefix = sys.argv[2] - - if options.output: - html = open(options.output, 'wt') - else: - html = sys.stdout - html.write('\n') - html.write(' \n') - html.write(' \n') - html.write(' \n') - for frame_no in range(options.start, options.stop + 1): - ref_image = "%s%04u.png" % (ref_prefix, frame_no) - src_image = "%s%04u.png" % (src_prefix, frame_no) - delta_image = "%s%04u_diff.png" % (src_prefix, frame_no) - if os.path.exists(ref_image) and os.path.exists(src_image): - html.write(' \n') - subprocess.call(["compare", '-metric', 'AE', '-fuzz', options.fuzz, ref_image, src_image, delta_image]) - surface(html, ref_image) - surface(html, src_image) - surface(html, delta_image) - html.write(' \n') - html.flush() - html.write('
refsrcΔ
\n') - html.write(' \n') - html.write('\n') - - -if __name__ == '__main__': - main()