]> git.xonotic.org Git - xonotic/xonotic.git/blobdiff - misc/tools/cached-converter.sh
./all update-maps: check for unzip
[xonotic/xonotic.git] / misc / tools / cached-converter.sh
index f1e535e6bc5d0a96e11efdafa8fae2197f8e410a..072d7731955b38ba13bf20565d4289040ab0f919 100755 (executable)
@@ -10,7 +10,8 @@ set -e
 : ${do_dds:=true}
 : ${dds_tool:=compressonator-dxtc}
 : ${do_ogg:=false}
-: ${ogg_qual:=1}
+: ${ogg_ogg:=true}
+: ${ogg_qual:=2}
 : ${del_src:=false}
 : ${git_src_repo:=}
 : ${dds_noalpha:=dxt1}
@@ -66,14 +67,44 @@ use_magnet_to_acquire_checksum_faster()
        if [ -n "$magnet" ]; then
                magnet=${magnet#* }
                magnet=${magnet%% *}
-               sum=$sum$magnet
+               echo "$magnet"
        else
-               sum=$sum`git hash-object "$1"`
+               git hash-object "$1"
        fi
 }
 
 lastinfiles=
 lastinfileshash=
+acquire_checksum()
+{
+       if [ x"$1/../$2" = x"$lastinfiles" ]; then
+               _a_s=$lastinfileshash
+       else
+               _a_e=false
+               for _a_f in "$1" "$2"; do
+                       case "$_a_f" in
+                               */background_l2.tga|*/background_ingame_l2.tga)
+                                       _a_e=true
+                                       ;;
+                       esac
+               done
+               if [ -n "$git_src_repo" ] && ! $_a_e; then
+                       _a_s=`use_magnet_to_acquire_checksum_faster "${1#./}"`
+                       if [ -n "$2" ]; then
+                               _a_s=$_a_s`use_magnet_to_acquire_checksum_faster "${2#./}"`
+                       fi
+               else
+                       _a_s=`git hash-object "$1"`
+                       if [ -n "$2" ]; then
+                               _a_s=$_a_s`git hash-object "$2"`
+                       fi
+               fi
+               lastinfileshash=$_a_s
+               lastinfiles="$1/../$2"
+       fi
+       echo "$_a_s"
+}
+
 cached()
 {
        flag=$1; shift
@@ -91,31 +122,7 @@ cached()
        fi
        options=`echo "$*" | git hash-object --stdin`
        selfprofile convert_findchecksum
-       if [ x"$infile1/../$infile2" = x"$lastinfiles" ]; then
-               sum=$lastinfileshash
-       else
-               evil=false
-               for infile in "$infile1" "$infile2"; do
-                       case "$infile" in
-                               */background_l2.tga|*/background_ingame_l2.tga)
-                                       evil=true
-                                       ;;
-                       esac
-               done
-               if [ -n "$git_src_repo" ] && ! $evil; then
-                       sum=
-                       use_magnet_to_acquire_checksum_faster "${infile1#./}"
-                       if [ -n "$infile2" ]; then
-                               use_magnet_to_acquire_checksum_faster "${infile2#./}"
-                       fi
-               else
-                       sum=`git hash-object "$infile1"`
-                       if [ -n "$infile2" ]; then
-                               sum=$sum`git hash-object "$infile2"`
-                       fi
-               fi
-               lastinfileshash=$sum
-       fi
+       sum=`acquire_checksum "$infile1" "$infile2"`
        selfprofile convert_makecachedir
        mkdir -p "$CACHEDIR/$method-$options"
        name1="$CACHEDIR/$method-$options/$sum-1.${outfile1##*.}"
@@ -150,9 +157,16 @@ pickdxta()
        pd_i=$1; shift
        pd_o=$1; shift
        for pd_dd in $pd_d; do
-               if [ -f "$pd_o".dds ]; then
+               if [ -f "$pd_o" ]; 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:`
+                       pd_psnr_tmp=`compare -channel alpha -metric PSNR "$pd_i" "$pd_o".tmp.dds NULL: 2>&1`
+                       case "$pd_psnr_tmp" in
+                               [0-9.]*)
+                                       ;;
+                               *)
+                                       pd_psnr_tmp=999.9
+                                       ;;
+                       esac
                        echo >&2 "$pd_dd: $pd_psnr_tmp dB"
                        pd_psnr_diff=`echo "($pd_psnr_tmp) - ($pd_psnr)" | bc -l`
                        case "$pd_psnr_diff" in
@@ -171,7 +185,14 @@ pickdxta()
                        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:`
+                       pd_psnr=`compare -channel alpha -metric PSNR "$pd_i" "$pd_o" NULL: 2>&1`
+                       case "$pd_psnr" in
+                               [0-9.]*)
+                                       ;;
+                               *)
+                                       pd_psnr=999.9
+                                       ;;
+                       esac
                        echo >&2 "$pd_dd: $pd_psnr dB"
                        echo >&2 "PICKED (first)"
                fi
@@ -183,7 +204,7 @@ reduce_jpeg2_dds()
        i=$1; shift
        ia=$1; shift
        o=$1; shift; shift 
-       convert "$i" "$ia" -compose CopyOpacity -composite "$tmpdir/x.tga" && \
+       convert "$i" "$ia" -compose CopyOpacity -composite -type TrueColorMatte "$tmpdir/x.tga" && \
        pickdxta "$dds_tool" "$dds_sepalpha" "$tmpdir/x.tga" "$o" $1
 }
 
@@ -192,7 +213,7 @@ reduce_jpeg2_dds_premul()
        i=$1; shift
        ia=$1; shift
        o=$1; shift; shift 
-       convert "$i" "$ia" -compose CopyOpacity -composite "$tmpdir/x.tga" && \
+       convert "$i" "$ia" -compose CopyOpacity -composite -type TrueColorMatte "$tmpdir/x.tga" && \
        pickdxta "$dds_tool" "$dds_prealpha" "$tmpdir/x.tga" "$o" $1
 }
 
@@ -252,7 +273,7 @@ reduce_rgba_dds()
 {
        i=$1; shift; shift
        o=$1; shift; shift
-       convert "$i" "$tmpdir/x.tga" && \
+       convert "$i" -type TrueColorMatte "$tmpdir/x.tga" && \
        pickdxta "$dds_tool" "$dds_sepalpha" "$tmpdir/x.tga" "$o" $1
 }
 
@@ -260,7 +281,7 @@ reduce_rgba_dds_premul()
 {
        i=$1; shift; shift
        o=$1; shift; shift
-       convert "$i" "$tmpdir/x.tga" && \
+       convert "$i" -type TrueColorMatte "$tmpdir/x.tga" && \
        pickdxta "$dds_tool" "$dds_prealpha" "$tmpdir/x.tga" "$o" $1
 }
 
@@ -285,7 +306,7 @@ reduce_rgb_dds()
 {
        i=$1; shift; shift
        o=$1; shift; shift
-       convert "$i" "$tmpdir/x.tga" && \
+       convert "$i" -type TrueColor "$tmpdir/x.tga" && \
        "$meprefix"compress-texture "$dds_tool" "$dds_noalpha" "$tmpdir/x.tga" "$o" $1
 }
 
@@ -327,6 +348,11 @@ for F in "$@"; do
        will_jpeg=$do_jpeg
        will_dds=$do_dds
        will_ogg=$do_ogg
+       if ! $ogg_ogg; then
+               case "$f" in
+                       *.ogg) will_ogg=false ;;
+               esac
+       fi
        case "$f" in
                ./sounds/misc/talk*.wav) will_ogg=false ;; # engine "feature"
                *_bump) will_dds=false ;;