From: Han-Wen Nienhuys Date: Tue, 19 Dec 2006 13:23:58 +0000 (+0100) Subject: Use ImageMagick compare + composite to show difference graphically (+bugfixes). X-Git-Tag: release/2.10.4-1~12 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=353e27d2fc6366da7bccb37f5605a75449d54a9a;p=lilypond.git Use ImageMagick compare + composite to show difference graphically (+bugfixes). --- diff --git a/buildscripts/output-distance.py b/buildscripts/output-distance.py index 92768454dc..511dc657dd 100644 --- a/buildscripts/output-distance.py +++ b/buildscripts/output-distance.py @@ -268,6 +268,43 @@ def read_signature_file (name): ################################################################ # different systems of a .ly file. +def read_pipe (c): + print 'pipe' , c + return os.popen (c).read () + +def system (c): + print 'system' , c + s = os.system (c) + if s : + raise Exception ("failed") + return + +def compare_png_images (old, new, dir): + def png_dims (f): + m = re.search ('([0-9]+) x ([0-9]+)', read_pipe ('file %s' % f)) + + return tuple (map (int, m.groups ())) + + dest = os.path.join (dir, new.replace ('.png', '.compare.jpeg')) + try: + dims1 = png_dims (old) + dims2 = png_dims (new) + except AttributeError: + ## hmmm. what to do? + system ('touch %(dest)s' % locals ()) + return + + dims = (min (dims1[0], dims2[0]), + min (dims1[1], dims2[1])) + + system ('convert -depth 8 -crop %dx%d+0+0 %s crop1.png' % (dims + (old,))) + system ('convert -depth 8 -crop %dx%d+0+0 %s crop2.png' % (dims + (new,))) + + system ('compare -depth 8 crop1.png crop2.png diff.png') + + system ("convert -depth 8 diff.png -blur 0x3 -negate -channel alpha,blue -type TrueColorMatte -fx 'intensity' matte.png") + + system ("composite -quality 65 matte.png %(new)s %(dest)s" % locals ()) class FileLink: def __init__ (self): @@ -341,11 +378,19 @@ class FileLink: self.add_system_link (link, system_index[0]) def link_files_for_html (self, old_dir, new_dir, dest_dir): + png_linked = [[], []] for ext in ('.png', '.ly', '-page*png'): + for oldnew in (0,1): for f in glob.glob (self.base_names[oldnew] + ext): - print f - link_file (f, dest_dir + '/' + f) + dst = dest_dir + '/' + f + link_file (f, dst) + + if f.endswith ('.png'): + png_linked[oldnew].append (f) + + for (old,new) in zip (png_linked[0], png_linked[1]): + compare_png_images (old, new, dest_dir) def html_record_string (self, old_dir, new_dir): def img_cell (ly, img, name): @@ -387,8 +432,9 @@ class FileLink: def cell (base, name): - pages = glob.glob (base + '-page*.png') - + pat = base + '-page*.png' + pages = glob.glob (pat) + if pages: return multi_img_cell (base + '.ly', sorted (pages), name) else: @@ -410,7 +456,7 @@ class FileLink: ''' % (self.distance (), html_2, cell (self.base_names[0], name), - cell (self.base_names[1], name)) + cell (self.base_names[1], name).replace ('.png', '.compare.jpeg')) return html_entry @@ -555,11 +601,11 @@ class ComparisonData: file_link.add_file_compare (f1,f2) def write_text_result_page (self, filename, threshold): - print 'writing "%s"' % filename out = None if filename == '': out = sys.stdout else: + print 'writing "%s"' % filename out = open_write_file (filename) ## todo: support more scores. @@ -598,6 +644,7 @@ class ComparisonData: link.link_files_for_html (dir1, dir2, dest_dir) link.write_html_system_details (dir1, dir2, dest_dir) + html += link.html_record_string (dir1, dir2) @@ -699,7 +746,10 @@ def test_compare_trees (): ## introduce differences system ('cp 19-1.signature dir2/20-1.signature') + system ('cp 19.png dir2/20.png') + system ('cp 19multipage-page1.png dir2/20multipage-page1.png') system ('cp 20-1.signature dir2/subdir/19-sub-1.signature') + system ('cp 20.png dir2/subdir/19-sub.png') ## radical diffs. system ('cp 19-1.signature dir2/20grob-1.signature') @@ -811,7 +861,7 @@ def test_compare_signatures (names, timing=False): def run_tests (): - dir = 'output-distance-test' + dir = 'test-output-distance' do_clean = not os.path.exists (dir)