From: Rudolf Polzer Date: Thu, 5 Aug 2010 12:38:34 +0000 (+0200) Subject: also cache whether the images have alpha or not X-Git-Tag: xonotic-v0.1.0preview~329^2~12 X-Git-Url: http://git.xonotic.org/?p=xonotic%2Fxonotic.git;a=commitdiff_plain;h=362f64cb1bfd60b88063ba814cf80d33bb9afed6 also cache whether the images have alpha or not --- diff --git a/misc/tools/cached-converter.sh b/misc/tools/cached-converter.sh index d8a75411..80cdcc34 100755 --- a/misc/tools/cached-converter.sh +++ b/misc/tools/cached-converter.sh @@ -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"