]> git.donarmstrong.com Git - lilypond.git/blob - scripts/auxiliar/make-regtest-pngs.sh
Add '-dcrop' option to ps and svg backends
[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                     -dAutoRotatePages=/None \
74                     -dTextAlphaBits=1 -dGraphicsAlphaBits=1 \
75                     -sOutputFile="${2%.pdf}-%d.png" "$2" -c quit
76             };;
77         p)
78             use_parallel=y;;
79         d)
80             gsdevice=$OPTARG;;
81     esac
82 done
83
84 shift $((OPTIND-1))
85
86 if [ -z "$file_loc" ]; then
87     echo "Must specify old (-o) or new (-n) regtest PNG creation on command line"
88     exit 1
89 fi
90
91 rm -rf $LILYPOND_BUILD_DIR/out-png-check/$file_loc
92 mkdir -p $LILYPOND_BUILD_DIR/out-png-check/$file_loc
93 OLDPWD="$PWD"
94 cd $LILYPOND_BUILD_DIR/out-png-check/$file_loc
95 if [ "$*" = "" ]
96 then
97     ls $LILYPOND_GIT/input/regression/*.ly > dir.txt
98 else
99     : > dir.txt
100     for i
101     do
102         case "$i" in /*)
103                 echo "$i" >> dir.txt;;
104             *)
105                 echo "$OLDPWD/$i" >> dir.txt
106         esac
107     done
108 fi
109
110 $LILYPOND_BUILD_DIR/out/bin/lilypond $(eval echo $backend_opt) --relocate \
111     -dinclude-settings=$LILYPOND_GIT/scripts/auxiliar/NoTagline.ly \
112     -djob-count=$cpu_count -dread-file-list "dir.txt"
113 if [ "$backend_opt" = "--pdf" ]
114 then
115     if [ $use_parallel = y ]
116     then
117         for i in *.pdf
118         do
119             png_generate echo $i
120         done | parallel -j $cpu_count
121         rm *.pdf
122     else
123         for i in *.pdf
124         do
125             png_generate "" $i && rm "$i"
126         done
127     fi
128 fi
129 rm -rf dir.txt
130 rm -rf *.log
131
132 if [ -n "$do_compare" ]; then
133     cd ..
134     rm -rf regtest-diffs
135     mkdir -p regtest-diffs
136     diff_count=0
137     for filename in new-regtest-results/*.png; do
138         trimFile=$(basename $filename)
139         if [ -e "old-regtest-results/$trimFile" ]; then
140             convert new-regtest-results/$trimFile -level 50%  NewTest.png
141             convert old-regtest-results/$trimFile -level 50%  OldTest.png
142             difference=$(compare -metric AE NewTest.png OldTest.png null: 2>&1 )
143             if [ $? -gt 0 ];then
144                 difference=9999
145             fi
146             if [ $difference -gt 1 ];then
147                 echo $trimFile": "$difference" differences"
148                 compare -dissimilarity-threshold 1 \
149                     new-regtest-results/$trimFile \
150                     old-regtest-results/$trimFile  regtest-diffs/$trimFile
151                 convert regtest-diffs/$trimFile -trim regtest-diffs/$trimFile
152                 diff_count=$(($diff_count+1))
153             fi
154         else
155             echo "old-regtest-results/"$trimFile" does not exist"
156         fi
157     done
158     rm -rf NewTest.png
159     rm -rf OldTest.png
160     echo $diff_count "differences found."
161 fi