copy.c: Remove "Dest" variable to CopyElementLowLevel() function
[geda-pcb/pcjc2.git] / lib / png_diff.sh
blobee557fdcac72bf7f278341a58d2d13959aa98f25
1 #!/bin/sh
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.
23 usage() {
24 cat <<EOF
26 $0 -- Recursively compare all .png files between two directories.
28 $0 -h|--help
29 $0 [-o | --out <outdir>] dir1 dir2
31 OVERVIEW
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
38 results.
40 The results are placed in <outdir> which defaults to "mismatch".
42 EXAMPLES
44 $0 pcblib-newlib.orig pcblib-newlib.new
47 EOF
50 show_sep() {
51 echo "----------------------------------------------------------------------"
54 all_tests=""
55 while test -n "$1"
57 case "$1" in
59 -h|--help)
60 usage
61 exit 0
64 -o|--out)
65 ERRDIR="$2"
66 shift 2
69 -*)
70 echo "unknown option: $1"
71 exit 1
75 break
78 esac
79 done
81 if test $# -ne 2 ; then
82 usage
83 exit 1
86 dir1="$1"
87 dir2="$2"
89 if test ! -d $dir1 ; then
90 echo "$dir1 does not exist or is not a directory"
91 usage
92 exit 1
95 if test ! -d $dir2 ; then
96 echo "$dir2 does not exist or is not a directory"
97 usage
98 exit 1
101 # Source directory
102 srcdir=${srcdir:-.}
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}
112 # golden directories
113 ERRDIR=${ERRDIR:-mismatch}
115 # some system tools
116 AWK=${AWK:-awk}
118 # create output directory
119 if test ! -d $ERRDIR ; then
120 mkdir -p $ERRDIR
121 if test $? -ne 0 ; then
122 echo "Failed to create output directory ${ERRDIR}"
123 exit 1
128 # fail/pass/total counts
129 fail=0
130 pass=0
131 skip=0
132 tot=0
134 cat << EOF
136 srcdir ${srcdir}
137 top_srcdir ${top_srcdir}
139 AWK ${AWK}
140 ERRDIR ${ERRDIR}
142 ImageMagick Tools:
144 ANIMATE ${ANIMATE}
145 COMPARE ${COMPARE}
146 COMPOSITE ${COMPOSITE}
147 CONVERT ${CONVERT}
148 DISPLAY ${DISPLAY}
149 MONTAGE ${MONTAGE}
153 find $dir1 -name \*.png -print | while read -r t ; do
154 show_sep
156 f1="$t"
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'`
160 echo "Test: $tnm"
161 echo "t: $t"
162 echo "File1: $f1"
163 echo "File2: $f2"
165 errdir=${ERRDIR}/${tnm}
167 tot=`expr $tot + 1`
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
179 echo "PASS"
180 pass=`expr $pass + 1`
181 else
182 echo "FAILED: See ${errdir}"
183 mkdir -p ${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
188 #!/bin/sh
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`
196 else
197 echo "Missing file ${f2}. Skipping test"
198 skip=`expr $skip + 1`
201 done
203 show_sep
204 echo "Passed $pass, failed $fail, skipped $skip out of $tot tests."
206 rc=0
207 if test $pass -ne $tot ; then
208 rc=1
211 exit $rc