polygon1.c: #ifdef DEBUG_ALL_LABELS build print_labels()
[geda-pcb/gde.git] / lib / png_diff.sh
blob478c19cea28e8118594cb695c7b3bc8ba57b1047
1 #!/bin/sh
3 # $Id$
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.
25 usage() {
26 cat <<EOF
28 $0 -- Recursively compare all .png files between two directories.
30 $0 -h|--help
31 $0 [-o | --out <outdir>] dir1 dir2
33 OVERVIEW
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
40 results.
42 The results are placed in <outdir> which defaults to "mismatch".
44 EXAMPLES
46 $0 pcblib-newlib.orig pcblib-newlib.new
49 EOF
52 show_sep() {
53 echo "----------------------------------------------------------------------"
56 all_tests=""
57 while test -n "$1"
59 case "$1" in
61 -h|--help)
62 usage
63 exit 0
66 -o|--out)
67 ERRDIR="$2"
68 shift 2
71 -*)
72 echo "unknown option: $1"
73 exit 1
77 break
80 esac
81 done
83 if test $# -ne 2 ; then
84 usage
85 exit 1
88 dir1="$1"
89 dir2="$2"
91 if test ! -d $dir1 ; then
92 echo "$dir1 does not exist or is not a directory"
93 usage
94 exit 1
97 if test ! -d $dir2 ; then
98 echo "$dir2 does not exist or is not a directory"
99 usage
100 exit 1
103 # Source directory
104 srcdir=${srcdir:-.}
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}
114 # golden directories
115 ERRDIR=${ERRDIR:-mismatch}
117 # some system tools
118 AWK=${AWK:-awk}
120 # create output directory
121 if test ! -d $ERRDIR ; then
122 mkdir -p $ERRDIR
123 if test $? -ne 0 ; then
124 echo "Failed to create output directory ${ERRDIR}"
125 exit 1
130 # fail/pass/total counts
131 fail=0
132 pass=0
133 skip=0
134 tot=0
136 cat << EOF
138 srcdir ${srcdir}
139 top_srcdir ${top_srcdir}
141 AWK ${AWK}
142 ERRDIR ${ERRDIR}
144 ImageMagick Tools:
146 ANIMATE ${ANIMATE}
147 COMPARE ${COMPARE}
148 COMPOSITE ${COMPOSITE}
149 CONVERT ${CONVERT}
150 DISPLAY ${DISPLAY}
151 MONTAGE ${MONTAGE}
155 find $dir1 -name \*.png -print | while read -r t ; do
156 show_sep
158 f1="$t"
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'`
162 echo "Test: $tnm"
163 echo "t: $t"
164 echo "File1: $f1"
165 echo "File2: $f2"
167 errdir=${ERRDIR}/${tnm}
169 tot=`expr $tot + 1`
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
181 echo "PASS"
182 pass=`expr $pass + 1`
183 else
184 echo "FAILED: See ${errdir}"
185 mkdir -p ${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
190 #!/bin/sh
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`
198 else
199 echo "Missing file ${f2}. Skipping test"
200 skip=`expr $skip + 1`
203 done
205 show_sep
206 echo "Passed $pass, failed $fail, skipped $skip out of $tot tests."
208 rc=0
209 if test $pass -ne $tot ; then
210 rc=1
213 exit $rc