]> git.donarmstrong.com Git - lilypond.git/blob - scripts/auxiliar/make-regtest-pngs.sh
Issue3348: Fix papersize settings in scripts/auxiliar/NoTagLine.ly
[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 cpu_count=${CPU_COUNT:-1}
39 backend_opt='--png ${resolution:+=-dresolution=$resolution} ${gsdevice:+=-dpixmap-format=$gsdevice}'
40 resolution=
41 gsdevice=
42 use_parallel=n
43
44 while getopts "j:oncr:gpd:" opts; do
45     case $opts in j)
46             cpu_count=$OPTARG;;
47         
48         o)
49             file_loc="old-regtest-results";;
50
51         c)
52             backend_opt="--pdf"
53             png_generate()
54             {
55                 $1 pdftocairo -png -r ${resolution:-101} -q "$2"
56             };;
57
58         n)
59             file_loc="new-regtest-results"
60             do_compare="y";;
61
62         r)
63             resolution=$OPTARG;;
64         g)
65             backend_opt="--pdf"
66             png_generate()
67             {
68                 $1 gs -sDEVICE=${gsdevice:-pngmono} -q -dNOPAUSE \
69                     -r${resolution:-300} -dNOPLATFONTS \
70                     -dTextAlphaBits=1 -dGraphicsAlphaBits=1 \
71                     -sOutputFile="${2%.pdf}-%d.png" "$2" -c quit
72             };;
73         p)
74             use_parallel=y;;
75         d)
76             gsdevice=$OPTARG;;
77     esac
78 done
79
80 if [ -z "$file_loc" ]; then
81     echo "Must specify old (-o) or new (-n) regtest PNG creation on command line"
82     exit 1
83 fi
84
85 rm -rf $LILYPOND_BUILD_DIR/out-png-check/$file_loc
86 mkdir -p $LILYPOND_BUILD_DIR/out-png-check/$file_loc
87 cd $LILYPOND_BUILD_DIR/out-png-check/$file_loc
88 ls $LILYPOND_GIT/input/regression/*.ly > dir.txt
89 $LILYPOND_BUILD_DIR/out/bin/lilypond $(eval echo $backend_opt) --relocate \
90     -dinclude-settings=$LILYPOND_GIT/scripts/auxiliar/NoTagline.ly \
91     -djob-count=$cpu_count -dread-file-list "dir.txt"
92 if [ "$backend_opt" = "--pdf" ]
93 then
94     if [ $use_parallel = y ]
95     then
96         for i in *.pdf
97         do
98             png_generate echo $i
99         done | parallel -j $cpu_count
100         rm *.pdf
101     else
102         for i in *.pdf
103         do
104             png_generate "" $i && rm "$i"
105         done
106     fi
107 fi
108 rm -rf dir.txt
109 rm -rf *.log
110
111 if [ -n "$do_compare" ]; then
112     cd ..
113     rm -rf regtest-diffs
114     mkdir -p regtest-diffs
115     diff_count=0
116     for filename in new-regtest-results/*.png; do
117         trimFile=$(basename $filename)
118         if [ -e old-regtest-results/$trimFile ]; then
119             convert new-regtest-results/$trimFile -level 50%  NewTest.png
120             convert old-regtest-results/$trimFile -level 50%  OldTest.png
121             difference=$(compare -metric AE NewTest.png OldTest.png null: 2>&1 )
122             if [ $? -gt 0 ];then
123                 difference=9999
124             fi
125             if [ $difference -gt 1 ];then
126                 echo $trimFile": "$difference" differences"
127                 compare -dissimilarity-threshold 1 \
128                     new-regtest-results/$trimFile \
129                     old-regtest-results/$trimFile  regtest-diffs/$trimFile
130                 convert regtest-diffs/$trimFile -trim regtest-diffs/$trimFile
131                 diff_count=$(($diff_count+1))
132             fi
133         else
134             echo "old-regtest-results/"$trimFile" does not exist"
135         fi
136     done
137     rm -rf NewTest.png
138     rm -rf OldTest.png
139     echo $diff_count "differences found."
140 fi