5 # Copyright (c) 2003, 2004, 2005, 2006, 2007 Dan McMahill
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of version 2 of the GNU General Public License as
9 # published by the Free Software Foundation
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
19 # All rights reserved.
21 # This code was derived from code written by Dan McMahill as part of the
22 # latex-mk testsuite. The original code was covered by a BSD license
23 # but the copyright holder is releasing the version for gerbv under the GPL.
28 $0 -- Recursively compare all .png files between two directories.
31 $0 [-o | --out <outdir>] dir1 dir2
35 The $0 script is used to compare all png files which exist in both
36 <dir1> and <dir2>. The comparison indicates if the files differ
37 graphically as well as providing a visual difference output.
38 This script is used to help verify changes made to the m4 libraries
39 since a simple change in a macro may have far reaching and unintended
42 The results are placed in <outdir> which defaults to "mismatch".
46 $0 pcblib-newlib.orig pcblib-newlib.new
53 echo "----------------------------------------------------------------------"
72 echo "unknown option: $1"
83 if test $# -ne 2 ; then
91 if test ! -d $dir1 ; then
92 echo "$dir1 does not exist or is not a directory"
97 if test ! -d $dir2 ; then
98 echo "$dir2 does not exist or is not a directory"
106 # various ImageMagick tools
107 ANIMATE
=${ANIMATE:-animate}
108 COMPARE
=${COMPARE:-compare}
109 COMPOSITE
=${COMPOSITE:-composite}
110 CONVERT
=${CONVERT:-convert}
111 DISPLAY
=${DISPLAY:-display}
112 MONTAGE
=${MONTAGE:-montage}
115 ERRDIR
=${ERRDIR:-mismatch}
120 # create output directory
121 if test ! -d $ERRDIR ; then
123 if test $?
-ne 0 ; then
124 echo "Failed to create output directory ${ERRDIR}"
130 # fail/pass/total counts
139 top_srcdir ${top_srcdir}
148 COMPOSITE ${COMPOSITE}
155 find $dir1 -name \
*.png
-print |
while read -r t
; do
159 f2
=`echo "$t" | sed "s;^${dir1}/;${dir2}/;g"`
161 tnm
=`echo "$t" | sed -e "s;^${dir1}/;;g" -e 's;/;_;g' -e 's;.png$;;g' -e 's; ;_;g'`
167 errdir
=${ERRDIR}/${tnm}
172 ######################################################################
174 # compare the png files
177 if test -f "${f2}" ; then
178 same
=`${COMPARE} -metric MAE "$f1" "$f2" null: 2>&1 | \
179 ${AWK} '{if($1 == 0){print "yes"} else {print "no"}}'`
180 if test "$same" = yes ; then
182 pass
=`expr $pass + 1`
184 echo "FAILED: See ${errdir}"
186 ${COMPARE} "${f1}" "${f2}" ${errdir}/compare.png
187 ${COMPOSITE} "${f1}" "${f2}" -compose difference ${errdir}/composite.png
188 ${CONVERT} "${f1}" "${f2}" -compose difference -composite -colorspace gray ${errdir}/gray.png
189 cat > ${errdir}/animate.sh
<< EOF
191 ${CONVERT} -label "%f" "${f1}" "${f2}" miff:- | \
192 ${MONTAGE} - -geometry +0+0 -tile 1x1 miff:- | \
193 ${ANIMATE} -delay 0.5 -loop 0 -
195 chmod a
+x
${errdir}/animate.sh
196 fail
=`expr $fail + 1`
199 echo "Missing file ${f2}. Skipping test"
200 skip
=`expr $skip + 1`
206 echo "Passed $pass, failed $fail, skipped $skip out of $tot tests."
209 if test $pass -ne $tot ; then