forked from avian2/eagle-automation
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheaglediff
executable file
·92 lines (72 loc) · 2.18 KB
/
eaglediff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/python
import os
from eagle_automation.config import *
from eagle_automation.export import BadExtension, EaglePNGExport
import sys
import tempfile
from PIL import Image, ImageOps, ImageChops
def to_png(in_path):
workdir = tempfile.mkdtemp()
extension = in_path.split('.')[-1].lower()
if extension == 'brd':
layers = LAYERS.values()
out_paths = [ os.path.join(workdir, layer + '.png')
for layer in LAYERS.iterkeys() ]
elif extension == 'sch':
layers = [{'layers': ['ALL']}]
out_paths = [os.path.join(workdir, 'all.png')]
else:
os.rmdir(workdir)
raise BadExtension
export = EaglePNGExport(workdir=workdir)
export.export(in_path, layers, out_paths)
oim = None
for i, out_path in enumerate(out_paths):
im = Image.open(out_path).convert("L")
if oim is None:
oim = im
else:
oim = Image.blend(oim, im, 1.0/(1.0+i))
os.unlink(out_path)
os.rmdir(workdir)
return oim
def usage():
print """eaglediff, visually compare CadSoft Eagle files
Copyright (C) 2012 Tomaz Solc <[email protected]>
USAGE: eaglediff from-file to-file"""
sys.exit(1)
def main():
if len(sys.argv) != 3:
usage()
try:
a_im = to_png(sys.argv[1])
except BadExtension:
print "%s: skipping, not a board or schematic" % sys.argv[1]
return
try:
b_im = to_png(sys.argv[2])
except BadExtension:
print "%s: skipping, not a board or schematic" % sys.argv[2]
return
# make the sizes equal
# if a sheet contains the filename, it is updated with the temporary name
# and may thus change the size of the image
width = max( (a_im.size[0], b_im.size[0]) )
height = max( (a_im.size[1], b_im.size[1]) )
a_im2 = Image.new( "L", (width,height) )
a_im2.paste( a_im, (0,0) )
a_im = a_im2
a_im2 = None
b_im2 = Image.new( "L", (width,height) )
b_im2.paste( b_im, (0,0) )
b_im = b_im2
b_im2 = None
added = ImageOps.autocontrast(ImageChops.subtract(b_im, a_im), 0)
deled = ImageOps.autocontrast(ImageChops.subtract(a_im, b_im), 0)
same = Image.blend(a_im, b_im, 0.5)
deled = ImageOps.colorize(deled, "#000", "#f00")
added = ImageOps.colorize(added, "#000", "#00f")
same = ImageOps.colorize(same, "#000", "#777")
im = ImageChops.add(ImageChops.add(added, deled), same)
im.show()
main()