]> git.xonotic.org Git - xonotic/xonotic.git/commitdiff
also cache whether the images have alpha or not
authorRudolf Polzer <divVerent@alientrap.org>
Thu, 5 Aug 2010 12:38:34 +0000 (14:38 +0200)
committerRudolf Polzer <divVerent@alientrap.org>
Thu, 5 Aug 2010 12:38:34 +0000 (14:38 +0200)
misc/tools/cached-converter.sh

index d8a7541100b24baaaf460eb2a6aef9bd500895e5..80cdcc341c26f19a5d38d9cac6980319b97a459b 100755 (executable)
@@ -130,6 +130,18 @@ reduce_rgb_jpeg()
        jpegoptim --strip-all -m"$1" "$o"
 }
 
+has_alpha()
+{
+       i=$1; shift; shift
+       o=$1; shift; shift
+       if convert "$F" -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
+               # has alpha
+               echo yes > "$o"
+       fi
+}
 
 for F in "$@"; do
        echo >&2 "Handling $F..."
@@ -147,15 +159,17 @@ for F in "$@"; do
                fi
                ;;
        *.png|*.tga)
-               if convert "$F" -depth 16 RGBA:- | perl -e 'while(read STDIN, $_, 8) { substr($_, 6, 2) eq "\xFF\xFF" or exit 1; } exit 0;'; then
-                       cached "$do_dds"  reduce_rgb_dds     "$F" ""                  "dds/${F%.*}.dds" ""                  "$dds_flags"
-                       cached "$do_jpeg" reduce_rgb_jpeg    "$F" ""                  "${F%.*}.jpg"     ""                  "$jpeg_qual_rgb"
-                       rm -f "$F"
-               else                                                             
+               cached true has_alpha "$F" "" "$F.hasalpha" ""
+               if [ -s "$F.hasalpha" ]; then
                        cached "$do_dds"  reduce_rgba_dds    "$F" ""                  "dds/${F%.*}.dds" ""                  "$dds_flags"
                        cached "$do_jpeg" reduce_rgba_jpeg2  "$F" ""                  "${F%.*}.jpg"     "${F%.*}_alpha.jpg" "$jpeg_qual_rgb" "$jpeg_qual_a"
                        rm -f "$F"
+               else                                                             
+                       cached "$do_dds"  reduce_rgb_dds     "$F" ""                  "dds/${F%.*}.dds" ""                  "$dds_flags"
+                       cached "$do_jpeg" reduce_rgb_jpeg    "$F" ""                  "${F%.*}.jpg"     ""                  "$jpeg_qual_rgb"
+                       rm -f "$F"
                fi
+               rm -f "$F.hasalpha"
                ;;
        *.ogg)
                cached "$do_ogg" reduce_ogg "$F" "" "$F" "" "$ogg_qual"