]> git.donarmstrong.com Git - lilypond.git/blob - scripts/auxiliar/make-regtest-pngs.sh
01610e8ac34d5376155b49abeeeb8735969195d9
[lilypond.git] / scripts / auxiliar / make-regtest-pngs.sh
1 #!/bin/sh
2
3 #  Make PNG files from regtests
4 #
5 #  Usage:  ./make-regtest-pngs.sh -j CPUs -o/-n
6 #
7 #    where -j specifies the number of parallel processes to run
8 #    (normally CPUs+1).  e.g.:
9 #
10 #    ./make-regtest-pngs.sh -j9
11 #
12 #   -p uses GNU parallel with the given job count in order to also
13 #   parallelize the conversion of PDF files to bitmaps when using -g
14 #   or -d.  No attempt is made to parallelize the bitmap comparisons
15 #   since their memory requirements may be prohibitive.
16 #
17 #   -o means build an old regtest set - the PNGs go in the old-regtest-results
18 #   directory
19 #
20 #   -n means build a new regtest set - the PNGs go in the new-regtest-results
21 #   directory
22 #
23 #   -c uses PDF and the poppler library via pdftocairo for generating
24 #   bitmaps, simulating the output for Evince and other previewers
25 #   using poppler.  pdftocairo may be contained in the poppler-utils
26 #   package.
27 #
28 #   -r can be used for specifying a rendering resolution.  This
29 #   defaults to 101 for poppler and 300 for Ghostscript from PDF.
30 #
31 #   -g uses Ghostscript for rendering a bitmap version from the PDF,
32 #   simulating the output from printing PDF files on a GNU system, so
33 #   use a resolution appropriate for print.  Antialiasing is not enabled.
34 #
35 #   -d changes the Ghostscript device used for creating PNG files
36 #   (usually png16m for direct PNG creation and pngmono for printer simulation)
37 #
38 #   if any filenames follow, those are the tests to run.  In absence
39 #   of any filenames, the contents of input/regression are used.
40
41 cpu_count=${CPU_COUNT:-1}
42 backend_opt='--png ${resolution:+=-dresolution=$resolution} ${gsdevice:+=-dpixmap-format=$gsdevice}'
43 resolution=
44 gsdevice=
45 use_parallel=n
46
47 while getopts "j:oncr:gpd:" opts; do
48     case $opts in j)
49             cpu_count=$OPTARG;;
50         
51         o)
52             file_loc="old-regtest-results";;
53
54         c)
55             backend_opt="--pdf"
56             png_generate()
57             {
58                 $1 pdftocairo -png -r ${resolution:-101} -q "$2"
59             };;
60
61         n)
62             file_loc="new-regtest-results"
63             do_compare="y";;
64
65         r)
66             resolution=$OPTARG;;
67         g)
68             backend_opt="--pdf"
69             png_generate()
70             {
71                 $1 gs -sDEVICE=${gsdevice:-pngmono} -q -dNOPAUSE \
72                     -r${resolution:-300} -dNOPLATFONTS \
73                     -dTextAlphaBits=1 -dGraphicsAlphaBits=1 \
74                     -sOutputFile="${2%.pdf}-%d.png" "$2" -c quit
75             };;
76         p)
77             use_parallel=y;;
78         d)
79             gsdevice=$OPTARG;;
80     esac
81 done
82
83 shift $((OPTIND-1))
84
85 if [ -z "$file_loc" ]; then
86     echo "Must specify old (-o) or new (-n) regtest PNG creation on command line"
87     exit 1
88 fi
89
90 rm -rf $LILYPOND_BUILD_DIR/out-png-check/$file_loc
91 mkdir -p $LILYPOND_BUILD_DIR/out-png-check/$file_loc
92 OLDPWD="$PWD"
93 cd $LILYPOND_BUILD_DIR/out-png-check/$file_loc
94 if [ "$*" = "" ]
95 then
96     ls $LILYPOND_GIT/input/regression/*.ly > dir.txt
97 else
98     : > dir.txt
99     for i
100     do
101         case "$i" in /*)
102                 echo "$i" >> dir.txt;;
103             *)
104                 echo "$OLDPWD/$i" >> dir.txt
105         esac
106     done
107 fi
108
109 $LILYPOND_BUILD_DIR/out/bin/lilypond $(eval echo $backend_opt) --relocate \
110     -dinclude-settings=$LILYPOND_GIT/scripts/auxiliar/NoTagline.ly \
111     -djob-count=$cpu_count -dread-file-list "dir.txt"
112 if [ "$backend_opt" = "--pdf" ]
113 then
114     if [ $use_parallel = y ]
115     then
116         for i in *.pdf
117         do
118             png_generate echo $i
119         done | parallel -j $cpu_count
120         rm *.pdf
121     else
122         for i in *.pdf
123         do
124             png_generate "" $i && rm "$i"
125         done
126     fi
127 fi
128 rm -rf dir.txt
129 rm -rf *.log
130
131 if [ -n "$do_compare" ]; then
132     cd ..
133     rm -rf regtest-diffs
134     mkdir -p regtest-diffs
135     diff_count=0
136     for filename in new-regtest-results/*.png; do
137         trimFile=$(basename $filename)
138         if [ -e "old-regtest-results/$trimFile" ]; then
139             convert new-regtest-results/$trimFile -level 50%  NewTest.png
140             convert old-regtest-results/$trimFile -level 50%  OldTest.png
141             difference=$(compare -metric AE NewTest.png OldTest.png null: 2>&1 )
142             if [ $? -gt 0 ];then
143                 difference=9999
144             fi
145             if [ $difference -gt 1 ];then
146                 echo $trimFile": "$difference" differences"
147                 compare -dissimilarity-threshold 1 \
148                     new-regtest-results/$trimFile \
149                     old-regtest-results/$trimFile  regtest-diffs/$trimFile
150                 convert regtest-diffs/$trimFile -trim regtest-diffs/$trimFile
151                 diff_count=$(($diff_count+1))
152             fi
153         else
154             echo "old-regtest-results/"$trimFile" does not exist"
155         fi
156     done
157     rm -rf NewTest.png
158     rm -rf OldTest.png
159     echo $diff_count "differences found."
160 fi