]> git.donarmstrong.com Git - lilypond.git/blob - scripts/auxiliar/make-regtest-pngs.sh
Merge branch 'master' into translation
[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 #   -o means build an old regtest set - the PNGs go in the old-regtest-results
13 #   directory
14 #
15 #   -n means build a new regtest set - the PNGs go in the new-regtest-results
16 #   directory
17 #
18 #   -p uses PDF and the poppler library via pdftocairo for generating bitmaps,
19 #   simulating the output for Evince and other previewers using poppler.
20 #   pdftocairo may be contained in the poppler-utils package.
21 #
22 #   -r can be used for specifying a rendering resolution.  This
23 #   defaults to 101 for poppler and 300 for Ghostscript from PDF.
24 #
25 #   -g uses Ghostscript for rendering a bitmap version from the PDF,
26 #   simulating the output from printing PDF files on a GNU system, so
27 #   use a resolution appropriate for print.  Antialiasing is not enabled.
28 #
29 #   -d changes the Ghostscript device used for creating PNG files
30 #   (usually png16m, but with -g you might prefer fewer colors for size
31 #   reasons, like png16).
32
33 cpu_count=${CPU_COUNT:-1}
34 backend_opt='--png ${resolution:+=-dresolution=$resolution} ${gsdevice:+=-dpixmap-format=$gsdevice}'
35 resolution=
36 gsdevice=
37
38 png_generate()
39 {
40     :
41 }
42
43 while getopts "j:onpr:g" opts; do
44     case $opts in j)
45             cpu_count=$OPTARG;;
46         
47         o)
48             file_loc="old-regtest-results";;
49
50         p)
51             backend_opt="--pdf"
52             png_generate()
53             {
54                 for i
55                 do pdftocairo -png -r ${resolution:-101} -q "$i" &&
56                     rm "$i"
57                 done
58             };;
59
60         n)
61             file_loc="new-regtest-results"
62             do_compare="y";;
63
64         r)
65             resolution=$OPTARG;;
66         g)
67             backend_opt="--pdf"
68             png_generate()
69             {
70                 for i
71                 do
72                     gs -sDEVICE=${gsdevice:-png16m} -q -dNOPAUSE \
73                         -r${resolution:-300} -dNOPLATFONTS \
74                         -dTextAlphaBits=1 -dGraphicsAlphaBits=1 \
75                         -sOutputFile="${i%.pdf}-%d.png" "$i" -c quit &&
76                     rm "$i"
77                 done
78             };;
79     esac
80 done
81
82 if [ -z "$file_loc" ]; then
83     echo "Must specify old (-o) or new (-n) regtest PNG creation on command line"
84     exit 1
85 fi
86
87 rm -rf $LILYPOND_BUILD_DIR/out-png-check/$file_loc
88 mkdir -p $LILYPOND_BUILD_DIR/out-png-check/$file_loc
89 cd $LILYPOND_BUILD_DIR/out-png-check/$file_loc
90 ls $LILYPOND_GIT/input/regression/*.ly > dir.txt
91 $LILYPOND_BUILD_DIR/out/bin/lilypond $(eval echo $backend_opt) --relocate \
92     -dinclude-settings=$LILYPOND_GIT/scripts/auxiliar/NoTagline.ly \
93     -djob-count=$cpu_count -dread-file-list "dir.txt"
94 png_generate *.pdf
95 rm -rf dir.txt
96 rm -rf *.log
97
98 if [ -n "$do_compare" ]; then
99     cd ..
100     rm -rf regtest-diffs
101     mkdir -p regtest-diffs
102     diff_count=0
103     for filename in new-regtest-results/*.png; do
104         trimFile=$(basename $filename)
105         if [ -e old-regtest-results/$trimFile ]; then
106             convert new-regtest-results/$trimFile -level 50%  NewTest.png
107             convert old-regtest-results/$trimFile -level 50%  OldTest.png
108             difference=$(compare -metric AE NewTest.png OldTest.png null: 2>&1 )
109             if [ $? -gt 0 ];then
110                 difference=9999
111             fi
112             if [ $difference -gt 1 ];then
113                 echo $trimFile": "$difference" differences"
114                 compare -dissimilarity-threshold 1 \
115                     new-regtest-results/$trimFile \
116                     old-regtest-results/$trimFile  regtest-diffs/$trimFile
117                 convert regtest-diffs/$trimFile -trim regtest-diffs/$trimFile
118                 diff_count=$(($diff_count+1))
119             fi
120         else
121             echo "old-regtest-results/"$trimFile" does not exist"
122         fi
123     done
124     rm -rf NewTest.png
125     rm -rf OldTest.png
126     echo $diff_count "differences found."
127 fi