OSDN Git Service

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