]> git.xonotic.org Git - xonotic/xonotic.git/blobdiff - misc/tools/cached-converter.sh
Fix macOS SDL2 framework permissions
[xonotic/xonotic.git] / misc / tools / cached-converter.sh
index 191e208660af9c9fef55f3b9c2fa8b7ba3fe82dd..1e8f7e9c114aef13a34ba2cd58714989ff26ca54 100755 (executable)
@@ -21,8 +21,8 @@ set -e
 : ${del_src:=false}
 : ${git_src_repo:=}
 : ${dds_noalpha:=dxt1}
-: ${dds_prealpha:=dxt2 dxt4}
-: ${dds_sepalpha:=dxt3 dxt5}
+: ${dds_prealpha:=dxt1 dxt2 dxt4}
+: ${dds_sepalpha:=dxt1 dxt3 dxt5}
 
 selfprofile_t0=`date +%s`
 selfprofile_step=init
@@ -209,8 +209,8 @@ reduce_jpeg2_dds()
 {
        i=$1; shift
        ia=$1; shift
-       o=$1; shift; shift 
-       convert "$i" "$ia" -compose CopyOpacity -composite -type TrueColorMatte "$tmpdir/x.tga" && \
+       o=$1; shift; shift
+       convert "$i" "$ia" -auto-orient -compose CopyOpacity -composite -type TrueColorMatte "$tmpdir/x.tga" && \
        pickdxta "$dds_tool" "$dds_sepalpha" "$tmpdir/x.tga" "$o" $1
 }
 
@@ -218,8 +218,8 @@ reduce_jpeg2_dds_premul()
 {
        i=$1; shift
        ia=$1; shift
-       o=$1; shift; shift 
-       convert "$i" "$ia" -compose CopyOpacity -composite -type TrueColorMatte "$tmpdir/x.tga" && \
+       o=$1; shift; shift
+       convert "$i" "$ia" -auto-orient -compose CopyOpacity -composite -type TrueColorMatte "$tmpdir/x.tga" && \
        pickdxta "$dds_tool" "$dds_prealpha" "$tmpdir/x.tga" "$o" $1
 }
 
@@ -229,14 +229,14 @@ reduce_jpeg2_jpeg2()
        ia=$1; shift
        o=$1; shift
        oa=$1; shift
-       if convert "$i" TGA:- | cjpeg -targa -quality "$1" -optimize -sample 1x1,1x1,1x1 > "$o"; then
+       if convert "$i" -auto-orient TGA:- | cjpeg -targa -quality "$1" -optimize -sample 1x1,1x1,1x1 > "$o"; then
                if [ "`stat -c %s "$i"`" -lt "`stat -c %s "$o"`" ]; then
                        cp "$i" "$o"
                fi
        else
                return 1
        fi
-       if convert "$ia" TGA:- | cjpeg -targa -quality "$2" -optimize -sample 1x1,1x1,1x1 > "$oa"; then
+       if convert "$ia" -auto-orient TGA:- | cjpeg -targa -quality "$2" -optimize -sample 1x1,1x1,1x1 > "$oa"; then
                if [ "`stat -c %s "$ia"`" -lt "`stat -c %s "$oa"`" ]; then
                        cp "$ia" "$oa"
                fi
@@ -251,7 +251,7 @@ reduce_jpeg2_webp()
        ia=$1; shift
        o=$1; shift; shift
        # this one MUST run
-       convert "$i" "$ia" -compose CopyOpacity -composite -type TrueColorMatte "$tmpdir/x.png" && \
+       convert "$i" "$ia" -auto-orient -compose CopyOpacity -composite -type TrueColorMatte "$tmpdir/x.png" && \
        cwebp $1 "$tmpdir/x.png" -o "$o"
 }
 
@@ -259,7 +259,7 @@ reduce_jpeg_jpeg()
 {
        i=$1; shift; shift
        o=$1; shift; shift
-       if convert "$i" TGA:- | cjpeg -targa -quality "$1" -optimize -sample 1x1,1x1,1x1 > "$o"; then
+       if convert "$i" -auto-orient TGA:- | cjpeg -targa -quality "$1" -optimize -sample 1x1,1x1,1x1 > "$o"; then
                if [ "`stat -c %s "$i"`" -lt "`stat -c %s "$o"`" ]; then
                        cp "$i" "$o"
                fi
@@ -289,7 +289,7 @@ reduce_rgba_dds()
 {
        i=$1; shift; shift
        o=$1; shift; shift
-       convert "$i" -type TrueColorMatte "$tmpdir/x.tga" && \
+       convert "$i" -auto-orient -type TrueColorMatte "$tmpdir/x.tga" && \
        pickdxta "$dds_tool" "$dds_sepalpha" "$tmpdir/x.tga" "$o" $1
 }
 
@@ -297,7 +297,7 @@ reduce_rgba_dds_premul()
 {
        i=$1; shift; shift
        o=$1; shift; shift
-       convert "$i" -type TrueColorMatte "$tmpdir/x.tga" && \
+       convert "$i" -auto-orient -type TrueColorMatte "$tmpdir/x.tga" && \
        pickdxta "$dds_tool" "$dds_prealpha" "$tmpdir/x.tga" "$o" $1
 }
 
@@ -306,12 +306,12 @@ reduce_rgba_jpeg2()
        i=$1; shift; shift
        o=$1; shift
        oa=$1; shift
-       if convert "$i" -alpha off TGA:- | cjpeg -targa -quality "$1" -optimize -sample 1x1,1x1,1x1 > "$o"; then
+       if convert "$i" -auto-orient -alpha off TGA:- | cjpeg -targa -quality "$1" -optimize -sample 1x1,1x1,1x1 > "$o"; then
                :
        else
                return 1
        fi
-       if convert "$i" -alpha extract TGA:- | cjpeg -targa -quality "$2" -optimize -sample 1x1,1x1,1x1 > "$oa"; then
+       if convert "$i" -auto-orient -alpha extract TGA:- | cjpeg -targa -quality "$2" -optimize -sample 1x1,1x1,1x1 > "$oa"; then
                :
        else
                return 1
@@ -322,7 +322,7 @@ reduce_rgb_dds()
 {
        i=$1; shift; shift
        o=$1; shift; shift
-       convert "$i" -type TrueColor "$tmpdir/x.tga" && \
+       convert "$i" -auto-orient -type TrueColor "$tmpdir/x.tga" && \
        "$meprefix"compress-texture "$dds_tool" "$dds_noalpha" "$tmpdir/x.tga" "$o" $1
 }
 
@@ -330,7 +330,7 @@ reduce_rgb_jpeg()
 {
        i=$1; shift; shift
        o=$1; shift; shift
-       if convert "$i" TGA:- | cjpeg -targa -quality "$1" -optimize -sample 1x1,1x1,1x1 > "$o"; then
+       if convert "$i" -auto-orient TGA:- | cjpeg -targa -quality "$1" -optimize -sample 1x1,1x1,1x1 > "$o"; then
                :
        else
                return 1
@@ -341,7 +341,7 @@ reduce_rgba_webp()
 {
        i=$1; shift; shift
        o=$1; shift; shift
-       convert "$i" "$tmpdir/x.png" && \
+       convert "$i" -auto-orient "$tmpdir/x.png" && \
        cwebp $1 "$tmpdir/x.png" -o "$o"
 }
 
@@ -349,7 +349,7 @@ has_alpha()
 {
        i=$1; shift; shift
        o=$1; shift; shift
-       if convert "$i" -depth 16 RGBA:- | perl -e 'while(read STDIN, $_, 8) { substr($_, 6, 2) eq "\xFF\xFF" or exit 1; } exit 0;'; then
+       if convert "$i" -auto-orient -depth 16 RGBA:- | perl -e 'while(read STDIN, $_, 8) { substr($_, 6, 2) eq "\xFF\xFF" or exit 1; } exit 0;'; then
                # no alpha
                : > "$o"
        else
@@ -375,13 +375,13 @@ for F in "$@"; do
        will_dds=$do_dds
        will_ogg=$do_ogg
        if ! $ogg_ogg; then
-               case "$f" in
+               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 ;;
+       case "$F" in
+               ./sound/misc/talk*.wav) will_ogg=false ;; # engine "feature"
+               *_bump.*) will_dds=false ;;
                ./models/player/*) will_dds=false ;;
                ./models/sprites/*) will_dds=false ;;
                ./models/*) ;;
@@ -396,17 +396,36 @@ for F in "$@"; do
                        ;;
        esac
 
-       # configure S2TC
+       # Specific hacks for normalmaps.
        case "$f" in
+               ./maps/*/lm_[0-9][0-9][0-9][13579]) # deluxemap
+                       export S2TC_COLORDIST_MODE=NORMALMAP
+                       export S2TC_RANDOM_COLORS=256
+                       export S2TC_REFINE_COLORS=LOOP
+                       export S2TC_DITHER_MODE=NONE
+                       # Engine ignores alpha channel on these, so we can use the DXT1 black encoding.
+                       # Not that that color should happen very often on a deluxemap, but who knows.
+                       # NOT renormalizing, as DP does its own renormalization anyway in the GLSL shader
+                       # and crunch's renormalizing looks like it can cause banding artifacts.
+                       export CRUNCH_TEXTYPEFLAGS='-gamma 1.0 -uniformMetrics -usetransparentindicesforblack'
+                       ;;
                *_norm)
                        export S2TC_COLORDIST_MODE=NORMALMAP
                        export S2TC_RANDOM_COLORS=256
                        export S2TC_REFINE_COLORS=LOOP
+                       export S2TC_DITHER_MODE=NONE
+                       # Alpha channel here means height.
+                       # NOT renormalizing, as DP does its own renormalization anyway in the GLSL shader
+                       # and crunch's renormalizing looks like it can cause banding artifacts.
+                       export CRUNCH_TEXTYPEFLAGS='-gamma 1.0 -uniformMetrics'
                        ;;
                *)
                        export S2TC_COLORDIST_MODE=SRGB_MIXED
                        export S2TC_RANDOM_COLORS=64
                        export S2TC_REFINE_COLORS=LOOP
+                       export S2TC_DITHER_MODE=FLOYDSTEINBERG
+                       # Color channel-like images - consider as sRGB.
+                       export CRUNCH_TEXTYPEFLAGS='-gamma 2.2'
                        ;;
        esac