]> git.rm.cloudns.org Git - xonotic/xonotic.git/commitdiff
when compressing textures, check whether DXT3 or DXT5 is better, and use that (slower...
authorRudolf Polzer <divVerent@xonotic.org>
Sat, 16 Jul 2011 10:15:57 +0000 (12:15 +0200)
committerRudolf Polzer <divVerent@xonotic.org>
Sat, 16 Jul 2011 10:15:57 +0000 (12:15 +0200)
misc/tools/cached-converter.sh

index 642edb108062a356c0986532e48246cd92337b05..f1e535e6bc5d0a96e11efdafa8fae2197f8e410a 100755 (executable)
@@ -14,8 +14,8 @@ set -e
 : ${del_src:=false}
 : ${git_src_repo:=}
 : ${dds_noalpha:=dxt1}
-: ${dds_prealpha:=dxt4}
-: ${dds_sepalpha:=dxt5}
+: ${dds_prealpha:=dxt2 dxt4}
+: ${dds_sepalpha:=dxt3 dxt5}
 
 selfprofile_t0=`date +%s`
 selfprofile_step=init
@@ -143,13 +143,48 @@ cached()
        selfprofile convert_finished
 }
 
+pickdxta()
+{
+       pd_t=$1; shift
+       pd_d=$1; shift
+       pd_i=$1; shift
+       pd_o=$1; shift
+       for pd_dd in $pd_d; do
+               if [ -f "$pd_o".dds ]; then
+                       "$meprefix"compress-texture "$pd_t" "$pd_dd" "$pd_i" "$pd_o".tmp.dds "$@"
+                       pd_psnr_tmp=`compare -channel alpha -metric PSNR "$pd_i" "$pd_o".tmp.dds NULL:`
+                       echo >&2 "$pd_dd: $pd_psnr_tmp dB"
+                       pd_psnr_diff=`echo "($pd_psnr_tmp) - ($pd_psnr)" | bc -l`
+                       case "$pd_psnr_diff" in
+                               -*|0)
+                                       # tmp is smaller or equal
+                                       # smaller PSNR is worse
+                                       # no action
+                                       ;;
+                               *)
+                                       # tmp is larger
+                                       # larger PSNR is better
+                                       pd_psnr=$pd_psnr_tmp
+                                       mv "$pd_o".tmp.dds "$pd_o"
+                                       echo >&2 "PICKED (better)"
+                                       ;;
+                       esac
+               else
+                       "$meprefix"compress-texture "$pd_t" "$pd_dd" "$pd_i" "$pd_o" "$@"
+                       pd_psnr=`compare -channel alpha -metric PSNR "$pd_i" "$pd_o" NULL:`
+                       echo >&2 "$pd_dd: $pd_psnr dB"
+                       echo >&2 "PICKED (first)"
+               fi
+       done
+}
+
 reduce_jpeg2_dds()
 {
        i=$1; shift
        ia=$1; shift
        o=$1; shift; shift 
        convert "$i" "$ia" -compose CopyOpacity -composite "$tmpdir/x.tga" && \
-       "$meprefix"compress-texture "$dds_tool" "$dds_sepalpha" "$tmpdir/x.tga" "$o" $1
+       pickdxta "$dds_tool" "$dds_sepalpha" "$tmpdir/x.tga" "$o" $1
 }
 
 reduce_jpeg2_dds_premul()
@@ -158,7 +193,7 @@ reduce_jpeg2_dds_premul()
        ia=$1; shift
        o=$1; shift; shift 
        convert "$i" "$ia" -compose CopyOpacity -composite "$tmpdir/x.tga" && \
-       "$meprefix"compress-texture "$dds_tool" "$dds_prealpha" "$tmpdir/x.tga" "$o" $1
+       pickdxta "$dds_tool" "$dds_prealpha" "$tmpdir/x.tga" "$o" $1
 }
 
 reduce_jpeg2_jpeg2()
@@ -218,7 +253,7 @@ reduce_rgba_dds()
        i=$1; shift; shift
        o=$1; shift; shift
        convert "$i" "$tmpdir/x.tga" && \
-       "$meprefix"compress-texture "$dds_tool" "$dds_sepalpha" "$tmpdir/x.tga" "$o" $1
+       pickdxta "$dds_tool" "$dds_sepalpha" "$tmpdir/x.tga" "$o" $1
 }
 
 reduce_rgba_dds_premul()
@@ -226,7 +261,7 @@ reduce_rgba_dds_premul()
        i=$1; shift; shift
        o=$1; shift; shift
        convert "$i" "$tmpdir/x.tga" && \
-       "$meprefix"compress-texture "$dds_tool" "$dds_prealpha" "$tmpdir/x.tga" "$o" $1
+       pickdxta "$dds_tool" "$dds_prealpha" "$tmpdir/x.tga" "$o" $1
 }
 
 reduce_rgba_jpeg2()