################################################################
# 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):
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):
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:
</tr>
''' % (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
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.
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)
## 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')
def run_tests ():
- dir = 'output-distance-test'
+ dir = 'test-output-distance'
do_clean = not os.path.exists (dir)