3 # Copyright (c) 2003, 2004, 2005, 2006, 2007 Dan McMahill
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of version 2 of the GNU General Public License as
7 # published by the Free Software Foundation
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
17 # All rights reserved.
19 # This code was derived from code written by Dan McMahill as part of the
20 # latex-mk testsuite. The original code was covered by a BSD license
21 # but the copyright holder is releasing the version for gerbv under the GPL.
26 $0 -- Recursively compare all .png files between two directories.
29 $0 [-o | --out <outdir>] dir1 dir2
33 The $0 script is used to compare all png files which exist in both
34 <dir1> and <dir2>. The comparison indicates if the files differ
35 graphically as well as providing a visual difference output.
36 This script is used to help verify changes made to the m4 libraries
37 since a simple change in a macro may have far reaching and unintended
40 The results are placed in <outdir> which defaults to "mismatch".
44 $0 pcblib-newlib.orig pcblib-newlib.new
51 echo "----------------------------------------------------------------------"
70 echo "unknown option: $1"
81 if test $# -ne 2 ; then
89 if test ! -d $dir1 ; then
90 echo "$dir1 does not exist or is not a directory"
95 if test ! -d $dir2 ; then
96 echo "$dir2 does not exist or is not a directory"
104 # various ImageMagick tools
105 ANIMATE
=${ANIMATE:-animate}
106 COMPARE
=${COMPARE:-compare}
107 COMPOSITE
=${COMPOSITE:-composite}
108 CONVERT
=${CONVERT:-convert}
109 DISPLAY
=${DISPLAY:-display}
110 MONTAGE
=${MONTAGE:-montage}
113 ERRDIR
=${ERRDIR:-mismatch}
118 # create output directory
119 if test ! -d $ERRDIR ; then
121 if test $?
-ne 0 ; then
122 echo "Failed to create output directory ${ERRDIR}"
128 # fail/pass/total counts
137 top_srcdir ${top_srcdir}
146 COMPOSITE ${COMPOSITE}
153 find $dir1 -name \
*.png
-print |
while read -r t
; do
157 f2
=`echo "$t" | sed "s;^${dir1}/;${dir2}/;g"`
159 tnm
=`echo "$t" | sed -e "s;^${dir1}/;;g" -e 's;/;_;g' -e 's;.png$;;g' -e 's; ;_;g'`
165 errdir
=${ERRDIR}/${tnm}
170 ######################################################################
172 # compare the png files
175 if test -f "${f2}" ; then
176 same
=`${COMPARE} -metric MAE "$f1" "$f2" null: 2>&1 | \
177 ${AWK} '{if($1 == 0){print "yes"} else {print "no"}}'`
178 if test "$same" = yes ; then
180 pass
=`expr $pass + 1`
182 echo "FAILED: See ${errdir}"
184 ${COMPARE} "${f1}" "${f2}" ${errdir}/compare.png
185 ${COMPOSITE} "${f1}" "${f2}" -compose difference ${errdir}/composite.png
186 ${CONVERT} "${f1}" "${f2}" -compose difference -composite -colorspace gray ${errdir}/gray.png
187 cat > ${errdir}/animate.sh
<< EOF
189 ${CONVERT} -label "%f" "${f1}" "${f2}" miff:- | \
190 ${MONTAGE} - -geometry +0+0 -tile 1x1 miff:- | \
191 ${ANIMATE} -delay 0.5 -loop 0 -
193 chmod a
+x
${errdir}/animate.sh
194 fail
=`expr $fail + 1`
197 echo "Missing file ${f2}. Skipping test"
198 skip
=`expr $skip + 1`
204 echo "Passed $pass, failed $fail, skipped $skip out of $tot tests."
207 if test $pass -ne $tot ; then