OSDN Git Service

more fix for test.sh
[android-x86/external-s2tc.git] / tests / test.sh
1 #!/bin/sh
2
3 set -e
4
5 cd ..
6 make clean || true
7 sh autogen.sh
8 ./configure --prefix="`pwd`/tests" CXXFLAGS="-O3"
9 make
10 make install
11 cd tests
12
13 rm -rf html
14 rm *.dds
15 mkdir html
16 exec 3>html/index.html
17
18 html_start()
19 {
20         echo >&3 "<html><title>S2TC</title>"
21         cat <<'EOF' >&3
22 <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
23 <script type="text/javascript">
24 var refsrc = "";
25 function clickfunc()
26 {
27         var me = $(this);
28         if(!me.data("src"))
29                 me.data("src", me.attr("src"));
30         me.attr("src", me.data("src"));
31         if(refsrc == me.data("src"))
32                 refsrc = "";
33         else
34                 refsrc = me.data("src");
35 }
36 function enterfunc()
37 {
38         var me = $(this);
39         if(!me.data("src"))
40                 me.data("src", me.attr("src"));
41         if(refsrc != "")
42                 me.attr("src", refsrc);
43 }
44 function leavefunc()
45 {
46         var me = $(this);
47         if(me.data("src"))
48                 me.attr("src", me.data("src"));
49 }
50 function run()
51 {
52         $('img').click(clickfunc);
53         $('img').mouseenter(enterfunc);
54         $('img').mouseleave(leavefunc);
55 }
56 </script>
57 EOF
58         echo >&3 "<body onLoad=\"run()\"><h1>S2TC</h1>"
59         echo >&3 "<table>"
60         echo >&3 "<tr><th>Picture</th>"
61         echo >&3 "<th>Original</th>"
62
63         if $use_compressonator; then
64                 echo >&3 "<th>Compressonator</th>"
65         fi
66         if $use_nvcompress; then
67                 echo >&3 "<th>nvcompress</th>"
68         fi
69         echo >&3 "<th>rand32-sRGB-mixed</th>"
70         echo >&3 "<th>rand32-wavg</th>"
71         echo >&3 "<th>rand32-avg</th>"
72
73         if $use_libtxc_dxtn; then
74                 echo >&3 "<th>libtxc_dxtn</th>"
75         fi
76         echo >&3 "<th>norand-wavg</th>"
77         echo >&3 "<th>faster-wavg</th>"
78
79         echo >&3 "</tr>"
80 }
81 html_rowstart()
82 {
83         echo >&3 "<tr><th>$1</th>"
84         deltatime=
85         deltatime_raw=0
86         col=0
87 }
88
89 decompress()
90 {
91         case "$1" in
92                 *.dds)
93                         convert "$1" TGA:-
94                         ;;
95                 *)
96                         cat "$1"
97                         ;;
98         esac
99 }
100
101 html()
102 {
103         decompress "$1" | convert TGA:- -crop 256x256+192+128 "html/$1.png"
104         echo >&3 "<td><img src=\"$1.png\" alt=\"$1\" title=\"$1$deltatime\"></td>"
105         eval "prevdeltatime=\$deltatime_$col"
106         prevdeltatime=`echo "($prevdeltatime-0)+$deltatime_raw" | bc`
107         eval "deltatime_$col=\$prevdeltatime"
108         col=$(($col+1))
109 }
110 html2()
111 {
112         bin/s2tc_decompress < "$1" | convert TGA:- -crop 256x256+192+128 "html/$1-s2tc.png"
113         echo >&3 "<td><img src=\"$1-s2tc.png\" alt=\"$1\" title=\"$1$deltatime\"></td>"
114         eval "prevdeltatime=\$deltatime_$col"
115         prevdeltatime=`echo "($prevdeltatime-0)+$deltatime_raw" | bc`
116         eval "deltatime_$col=\$prevdeltatime"
117         col=$(($col+1))
118 }
119 html_rowend()
120 {
121         echo >&3 "</tr>"
122 }
123 html_end()
124 {
125         echo >&3 "<tr><th>Total runtime</th><td>(original)</td>"
126         col=1
127         while :; do
128                 eval "prevdeltatime=\$deltatime_$col"
129                 [ -n "$prevdeltatime" ] || break
130                 deltatime=`echo "scale=3; $prevdeltatime / 1000000000" | bc -l`
131                 echo >&3 "<td>$deltatime seconds</td>"
132                 col=$(($col+1))
133         done
134         echo >&3 "</table></body></html>"
135 }
136
137 timing()
138 {
139         t0=`date +%s%N`
140         "$@"
141         t1=`date +%s%N`
142         deltatime_raw=`echo "$t1 - $t0" | bc`
143         deltatime=`echo "scale=3; $deltatime_raw / 1000000000" | bc -l`
144         deltatime=" ($deltatime seconds)"
145 }
146
147 t()
148 {
149         in=$1; shift
150         out=$1; shift
151         timing "$@" < "$in" > "$out"
152         html "$out"
153 }
154
155 if which nvcompress >/dev/null 2>&1; then
156         use_nvcompress=true
157 else
158         use_nvcompress=false
159 fi
160 if which wine >/dev/null 2>&1 && [ -f "$HOME/.wine/drive_c/Program Files (x86)/AMD/The Compressonator 1.50/TheCompressonator.exe" ]; then
161         use_compressonator=true
162 else
163         use_compressonator=false
164 fi
165 if [ -f /usr/lib/libtxc_dxtn.so ]; then
166         use_libtxc_dxtn=true
167 else
168         use_libtxc_dxtn=false
169 fi
170
171 html_start
172
173 # TODO download test pictures that are not under the same license as this package
174 xon()
175 {
176         # downloads a texture from Xonotic
177         if ! [ -f "$2" ]; then
178                 wget -O- "http://git.xonotic.org/?p=xonotic/xonotic-maps.pk3dir.git;a=blob_plain;f=$1" | convert "${1##*.}":- -geometry 512x512 "$2"
179         fi
180 }
181 # floor_tread01: GPLv2+
182 xon textures/exx/floor/floor_tread01.tga floor_tread01.tga
183 # floor_tread01_norm: GPLv2+
184 xon textures/exx/floor/floor_tread01_norm.tga floor_tread01_norm_dxt3.tga
185 xon textures/exx/floor/floor_tread01_norm.tga floor_tread01_norm_dxt5.tga
186 # base_concrete1a: GPLv2+
187 xon textures/trak4x/base/base_concrete1a.tga base_concrete1a.tga
188 # disabled: GPLv2+
189 xon textures/screens/screen_toggle0.tga disabled.tga
190 # floor_tile3a: GPLv2+
191 xon textures/trak4x/floor/floor_tile3a.tga floor_tile3a.tga
192 # lift02: GPLv2+
193 xon textures/facility114x/misc/lift02.tga lift02.tga
194 # sunset: GPLv2+
195 xon env/distant_sunset/distant_sunset_rt.jpg sunset.tga
196 # amelia: no license
197 if ! [ -f "amelia.tga" ]; then
198         wget -O- "http://www.godoon.com/gallery/media/slayers/amelia-wil-tesla-saillune/49212997-d81e-11df-8228-a8bfc396a36f.jpg" | convert JPG:- amelia.tga
199 fi
200
201 for i in dxtfail floor_tread01 floor_tread01_norm_dxt5 floor_tread01_norm_dxt3 fract001 base_concrete1a disabled floor_tile3a lift02 sunset amelia noise noise_solid supernova; do
202         html_rowstart "$i"
203
204         html "$i".tga
205
206         case "$i" in
207                 *_norm*)
208                         goodmetric=NORMALMAP
209                         ;;
210                 *)
211                         goodmetric=SRGB_MIXED
212                         ;;
213         esac
214         case "$i" in
215                 *_dxt5)
216                         fourcc=DXT5
217                         nvopts="-bc3 -alpha"
218                         ;;
219                 *_dxt3)
220                         fourcc=DXT3
221                         nvopts="-bc2 -alpha"
222                         ;;
223                 *)
224                         fourcc=DXT1
225                         nvopts="-bc1"
226                         ;;
227         esac
228
229         if $use_compressonator; then
230                 timing wine "c:/Program Files (x86)/AMD/The Compressonator 1.50/TheCompressonator.exe" -convert -overwrite -mipmaps "$i".tga "$i"-amdcompress.dds -codec DXTC.dll +fourCC $fourcc -mipper BoxFilter.dll
231                 html "$i"-amdcompress.dds
232         fi
233
234         if $use_nvcompress; then
235                 timing nvcompress $nvopts "$i".tga "$i"-nvcompress.dds
236                 html "$i"-nvcompress.dds
237         fi
238
239         S2TC_COLORDIST_MODE=$goodmetric S2TC_RANDOM_COLORS=32 S2TC_REFINE_COLORS=CHECK  t "$i".tga "$i"-rand32-mrgb-r.dds bin/s2tc -t $fourcc
240         S2TC_COLORDIST_MODE=WAVG        S2TC_RANDOM_COLORS=32 S2TC_REFINE_COLORS=CHECK  t "$i".tga "$i"-rand32-wavg-r.dds bin/s2tc -t $fourcc
241         S2TC_COLORDIST_MODE=AVG         S2TC_RANDOM_COLORS=32 S2TC_REFINE_COLORS=CHECK  t "$i".tga "$i"-rand32-avg-r.dds  bin/s2tc -t $fourcc
242         if $use_libtxc_dxtn; then
243                 LD_PRELOAD=/usr/lib/libtxc_dxtn.so                                      t "$i".tga "$i"-libtxc_dxtn.dds   bin/s2tc -t $fourcc
244                 unset LD_PRELOAD
245         fi
246         S2TC_COLORDIST_MODE=WAVG        S2TC_RANDOM_COLORS=0  S2TC_REFINE_COLORS=ALWAYS t "$i".tga "$i"-norand-wavg-r.dds bin/s2tc -t $fourcc
247         S2TC_COLORDIST_MODE=WAVG        S2TC_RANDOM_COLORS=-1 S2TC_REFINE_COLORS=ALWAYS t "$i".tga "$i"-faster-wavg-r.dds bin/s2tc -t $fourcc
248
249         html_rowend
250 done
251 html_end