-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpng_diff.sh
executable file
·214 lines (166 loc) · 4.26 KB
/
png_diff.sh
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/bin/sh
#
# $Id$
#
# Copyright (c) 2003, 2004, 2005, 2006, 2007 Dan McMahill
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
# All rights reserved.
#
# This code was derived from code written by Dan McMahill as part of the
# latex-mk testsuite. The original code was covered by a BSD license
# but the copyright holder is releasing the version for gerbv under the GPL.
usage() {
cat <<EOF
$0 -- Recursively compare all .png files between two directories.
$0 -h|--help
$0 [-o | --out <outdir>] dir1 dir2
OVERVIEW
The $0 script is used to compare all png files which exist in both
<dir1> and <dir2>. The comparison indicates if the files differ
graphically as well as providing a visual difference output.
This script is used to help verify changes made to the m4 libraries
since a simple change in a macro may have far reaching and unintended
results.
The results are placed in <outdir> which defaults to "mismatch".
EXAMPLES
$0 pcblib-newlib.orig pcblib-newlib.new
EOF
}
show_sep() {
echo "----------------------------------------------------------------------"
}
all_tests=""
while test -n "$1"
do
case "$1" in
-h|--help)
usage
exit 0
;;
-o|--out)
ERRDIR="$2"
shift 2
;;
-*)
echo "unknown option: $1"
exit 1
;;
*)
break
;;
esac
done
if test $# -ne 2 ; then
usage
exit 1
fi
dir1="$1"
dir2="$2"
if test ! -d $dir1 ; then
echo "$dir1 does not exist or is not a directory"
usage
exit 1
fi
if test ! -d $dir2 ; then
echo "$dir2 does not exist or is not a directory"
usage
exit 1
fi
# Source directory
srcdir=${srcdir:-.}
# various ImageMagick tools
ANIMATE=${ANIMATE:-animate}
COMPARE=${COMPARE:-compare}
COMPOSITE=${COMPOSITE:-composite}
CONVERT=${CONVERT:-convert}
DISPLAY=${DISPLAY:-display}
MONTAGE=${MONTAGE:-montage}
# golden directories
ERRDIR=${ERRDIR:-mismatch}
# some system tools
AWK=${AWK:-awk}
# create output directory
if test ! -d $ERRDIR ; then
mkdir -p $ERRDIR
if test $? -ne 0 ; then
echo "Failed to create output directory ${ERRDIR}"
exit 1
fi
fi
# fail/pass/total counts
fail=0
pass=0
skip=0
tot=0
cat << EOF
srcdir ${srcdir}
top_srcdir ${top_srcdir}
AWK ${AWK}
ERRDIR ${ERRDIR}
ImageMagick Tools:
ANIMATE ${ANIMATE}
COMPARE ${COMPARE}
COMPOSITE ${COMPOSITE}
CONVERT ${CONVERT}
DISPLAY ${DISPLAY}
MONTAGE ${MONTAGE}
EOF
find $dir1 -name \*.png -print | while read -r t ; do
show_sep
f1="$t"
f2=`echo "$t" | sed "s;^${dir1}/;${dir2}/;g"`
tnm=`echo "$t" | sed -e "s;^${dir1}/;;g" -e 's;/;_;g' -e 's;.png$;;g' -e 's; ;_;g'`
echo "Test: $tnm"
echo "t: $t"
echo "File1: $f1"
echo "File2: $f2"
errdir=${ERRDIR}/${tnm}
tot=`expr $tot + 1`
######################################################################
#
# compare the png files
#
if test -f "${f2}" ; then
same=`${COMPARE} -metric MAE "$f1" "$f2" null: 2>&1 | \
${AWK} '{if($1 == 0){print "yes"} else {print "no"}}'`
if test "$same" = yes ; then
echo "PASS"
pass=`expr $pass + 1`
else
echo "FAILED: See ${errdir}"
mkdir -p ${errdir}
${COMPARE} "${f1}" "${f2}" ${errdir}/compare.png
${COMPOSITE} "${f1}" "${f2}" -compose difference ${errdir}/composite.png
${CONVERT} "${f1}" "${f2}" -compose difference -composite -colorspace gray ${errdir}/gray.png
cat > ${errdir}/animate.sh << EOF
#!/bin/sh
${CONVERT} -label "%f" "${f1}" "${f2}" miff:- | \
${MONTAGE} - -geometry +0+0 -tile 1x1 miff:- | \
${ANIMATE} -delay 0.5 -loop 0 -
EOF
chmod a+x ${errdir}/animate.sh
fail=`expr $fail + 1`
fi
else
echo "Missing file ${f2}. Skipping test"
skip=`expr $skip + 1`
fi
done
show_sep
echo "Passed $pass, failed $fail, skipped $skip out of $tot tests."
rc=0
if test $pass -ne $tot ; then
rc=1
fi
exit $rc