]> git.xonotic.org Git - xonotic/xonotic.git/blob - misc/tools/compress-texture
fix some text
[xonotic/xonotic.git] / misc / tools / compress-texture
1 #!/bin/sh
2
3 # usage: compress-texture tool compression in.png out.dds
4 # example: compress-texture compressonator dxt1 foo.jpg foo.dds
5
6 echo >&2 "$0 $*"
7
8 tool=$1; shift
9 format=$1; shift
10 src=$1; shift
11 dst=$1; shift
12
13 c=
14 f=
15
16 fourcchack=
17 case "$tool" in
18         compressonator-dxtc)
19                 # we still have to preprocess the image to premultiply alpha, as it seems
20                 case "$format" in
21                         dxt2)
22                                 fourcchack=DXT2
23                                 format=dxt2
24                                 ;;
25                         dxt4)
26                                 fourcchack=DXT4
27                                 format=dxt4
28                                 ;;
29                 esac
30                 ;;
31         *)
32                 case "$format" in
33                         dxt2)
34                                 fourcchack=DXT2
35                                 format=dxt3
36                                 ;;
37                         dxt4)
38                                 fourcchack=DXT4
39                                 format=dxt5
40                                 ;;
41                 esac
42                 ;;
43 esac
44
45 if [ -n "$fourcchack" ]; then
46         fourcchack_dir=`mktemp -d`
47         convert "$src" -fx "u*u.a" "$fourcchack_dir/src.$ext"
48         src="$fourcchack_dir/src.$ext"
49 fi
50
51 case "$tool" in
52         compressonator-dxtc|compressonator-atic)
53                 case "$tool" in
54                         *-dxtc) c="-codec DXTC.dll" ;;
55                         *-atic) c="-codec ATICompressor.dll" ;;
56                 esac
57                 case "$format" in
58                         dxt1) f="+fourCC DXT1" ;;
59                         dxt2) f="+fourCC DXT2" ;;
60                         dxt3) f="+fourCC DXT3" ;;
61                         dxt4) f="+fourCC DXT4" ;;
62                         dxt5) f="+fourCC DXT5" ;;
63                 esac
64                 dir=`mktemp -d "$HOME/.wine/drive_c/compressonator.XXXXXX"`
65                 dir_dos="C:/${dir##*/}"
66                 ext=${src##*.}
67                 cp "$src" "$dir/src.$ext"
68
69                 # compressonator and wine suck, so we sometimes have to retry :(
70                 for retry in 1 2 3 4 5; do
71                         wine "c:/Program Files/AMD/The Compressonator 1.50/TheCompressonator.exe" -convert -mipmaps "$dir_dos/src.$ext" "$dir_dos/dst.dds" $c $f "$@" -mipper BoxFilter.dll
72                         if mv "$dir/dst.dds" "$dst"; then
73                                 break
74                         fi
75                 done
76                 rm -rf "$dir"
77                 [ -f "$dst" ]
78                 ;;
79         nvcompress)
80                 case "$format" in
81                         dxt1) f="-bc1" ;;
82                         dxt3) f="-alpha -bc3" ;;
83                         dxt5) f="-alpha -bc5" ;;
84                 esac
85                 nvcompress $f "$@" "$src" "$dst"
86                 ;;
87 esac
88
89 if [ -n "$fourcchack" ]; then
90         # use dd to hack in the right FOURCC
91         echo -n "$fourcchack" | dd of="$dst" bs=1 count=4 seek=84
92         rm -rf "$fourcchack_dir"
93 fi