X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=misc%2Ftools%2Fcached-converter.sh;h=2bcaacb2373d153533679e3cb4a98f07e979060e;hb=30a56f6f618f229b60ee23312b3c18587e1ae23e;hp=83a307844b353e5a16674bcb6c2b69c455ad549b;hpb=4dcfd6675f9d5c0cb5a09b2f77f64a4bfb72603e;p=xonotic%2Fxonotic.git diff --git a/misc/tools/cached-converter.sh b/misc/tools/cached-converter.sh index 83a30784..2bcaacb2 100755 --- a/misc/tools/cached-converter.sh +++ b/misc/tools/cached-converter.sh @@ -49,10 +49,18 @@ cached() if [ x"$infile1/../$infile2" = x"$lastinfiles" ]; then sum=$lastinfileshash else - if [ -n "$git_src_repo" ]; then - sum=`( cd "$git_src_repo"; git rev-parse --revs-only HEAD:"${infile1#./}" | grep . ) || git hash-object "$infile1"` + 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=`( cd "$git_src_repo"; git rev-parse --revs-only HEAD:"${infile1#./}" | grep . ) || { echo >&2 "git-rev-parse failed on $infile1"; git hash-object "$infile1"; }` if [ -n "$infile2" ]; then - sum=$sum`( cd "$git_src_repo"; git rev-parse --revs-only HEAD:"${infile2#./}" | grep . ) || git hash-object "$infile2"` + sum=$sum`( cd "$git_src_repo"; git rev-parse --revs-only HEAD:"${infile2#./}" | grep . ) || { echo >&2 "git-rev-parse failed on $infile2"; git hash-object "$infile2"; }` fi else sum=`git hash-object "$infile1"` @@ -68,14 +76,14 @@ cached() tempfile1="${name1%/*}/new-${name1##*/}" [ -z "$outfile2" ] || tempfile2="${name2%/*}/new-${name2##*/}" if [ -f "$name1" ] && { [ -z "$outfile2" ] || [ -f "$name2" ]; }; then - case "$outfile1" in */*) mkdir -p "${outfile1%/*}"; esac && { ln "$name1" "$outfile1" 2>/dev/null || cp "$name1" "$outfile1"; } - [ -z "$outfile2" ] || { case "$outfile2" in */*) mkdir -p "${outfile2%/*}"; esac && { ln "$name2" "$outfile2" 2>/dev/null || cp "$name2" "$outfile2"; }; } + case "$outfile1" in */*) mkdir -p "${outfile1%/*}"; esac && { ln -f "$name1" "$outfile1" 2>/dev/null || { rm -f "$outfile1" && cp "$name1" "$outfile1"; }; } + [ -z "$outfile2" ] || { case "$outfile2" in */*) mkdir -p "${outfile2%/*}"; esac && { ln -f "$name2" "$outfile2" 2>/dev/null || { rm -f "$outfile2" && cp "$name2" "$outfile2"; }; }; } conv=true elif "$method" "$infile1" "$infile2" "$tempfile1" "$tempfile2" "$@"; then mv "$tempfile1" "$name1" [ -z "$outfile2" ] || mv "$tempfile2" "$name2" - case "$outfile1" in */*) mkdir -p "${outfile1%/*}"; esac && { ln "$name1" "$outfile1" 2>/dev/null || cp "$name1" "$outfile1"; } - [ -z "$outfile2" ] || { case "$outfile2" in */*) mkdir -p "${outfile2%/*}"; esac && { ln "$name2" "$outfile2" 2>/dev/null || cp "$name2" "$outfile2"; }; } + case "$outfile1" in */*) mkdir -p "${outfile1%/*}"; esac && { ln -f "$name1" "$outfile1" 2>/dev/null || { rm -f "$outfile1" && cp "$name1" "$outfile1"; }; } + [ -z "$outfile2" ] || { case "$outfile2" in */*) mkdir -p "${outfile2%/*}"; esac && { ln -f "$name2" "$outfile2" 2>/dev/null || { rm -f "$outfile2" && cp "$name2" "$outfile2"; }; }; } conv=true else rm -f "$tempfile1" @@ -93,21 +101,48 @@ reduce_jpeg2_dds() "$meprefix"compress-texture "$dds_tool" dxt5 "$tmpdir/x.tga" "$o" $1 } +reduce_jpeg2_dds_premul() +{ + i=$1; shift + ia=$1; shift + o=$1; shift; shift + convert "$i" "$ia" -compose CopyOpacity -composite "$tmpdir/x.tga" && \ + "$meprefix"compress-texture "$dds_tool" dxt4 "$tmpdir/x.tga" "$o" $1 +} + reduce_jpeg2_jpeg2() { i=$1; shift ia=$1; shift o=$1; shift oa=$1; shift - cp "$i" "$o" && jpegoptim --strip-all -m"$1" "$o" && \ - cp "$ia" "$oa" && jpegoptim --strip-all -m"$2" "$oa" + if convert "$i" 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 [ "`stat -c %s "$ia"`" -lt "`stat -c %s "$oa"`" ]; then + cp "$ia" "$oa" + fi + else + return 1 + fi } reduce_jpeg_jpeg() { i=$1; shift; shift o=$1; shift; shift - cp "$i" "$o" && jpegoptim --strip-all -m"$1" "$o" + if convert "$i" 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 } reduce_ogg_ogg() @@ -135,15 +170,29 @@ reduce_rgba_dds() "$meprefix"compress-texture "$dds_tool" dxt5 "$tmpdir/x.tga" "$o" $1 } +reduce_rgba_dds_premul() +{ + i=$1; shift; shift + o=$1; shift; shift + convert "$i" "$tmpdir/x.tga" && \ + "$meprefix"compress-texture "$dds_tool" dxt4 "$tmpdir/x.tga" "$o" $1 +} + reduce_rgba_jpeg2() { i=$1; shift; shift o=$1; shift oa=$1; shift - convert "$i" -alpha off -quality 100 "$o" && \ - convert "$i" -alpha extract -quality 100 "$oa" && \ - jpegoptim --strip-all -m"$1" "$o" && \ - jpegoptim --strip-all -m"$2" "$oa" + if convert "$i" -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 + : + else + return 1 + fi } reduce_rgb_dds() @@ -158,15 +207,18 @@ reduce_rgb_jpeg() { i=$1; shift; shift o=$1; shift; shift - convert "$i" "$o" && \ - jpegoptim --strip-all -m"$1" "$o" + if convert "$i" TGA:- | cjpeg -targa -quality "$1" -optimize -sample 1x1,1x1,1x1 > "$o"; then + : + else + return 1 + fi } 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 + if convert "$i" -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 @@ -217,6 +269,13 @@ for F in "$@"; do esac fi + pm= + case "$f" in + ./particles/particlefont) # particlefont uses premultiplied alpha + pm=_premul + ;; + esac + if $do_jpeg_if_not_dds; then if $will_dds; then will_jpeg=false @@ -237,30 +296,33 @@ for F in "$@"; do ;; *.jpg) if [ -f "${f}_alpha.jpg" ]; then - cached "$will_dds" reduce_jpeg2_dds "$F" "${f}_alpha.jpg" "dds/${f}.dds" "" "$dds_flags" - cached "$will_jpeg" reduce_jpeg2_jpeg2 "$F" "${f}_alpha.jpg" "$F" "${f}_alpha.jpg" "$jqual_rgb" "$jqual_a" + cached "$will_dds" reduce_jpeg2_dds$pm "$F" "${f}_alpha.jpg" "dds/${f}.dds" "" "$dds_flags" + cached "$will_jpeg" reduce_jpeg2_jpeg2 "$F" "${f}_alpha.jpg" "$F" "${f}_alpha.jpg" "$jqual_rgb" "$jqual_a" else - cached "$will_dds" reduce_rgb_dds "$F" "" "dds/${f}.dds" "" "$dds_flags" - cached "$will_jpeg" reduce_jpeg_jpeg "$F" "" "$F" "" "$jqual_rgb" + cached "$will_dds" reduce_rgb_dds "$F" "" "dds/${f}.dds" "" "$dds_flags" + cached "$will_jpeg" reduce_jpeg_jpeg "$F" "" "$F" "" "$jqual_rgb" fi ;; *.png|*.tga) cached true has_alpha "$F" "" "$F.hasalpha" "" conv=false if [ -s "$F.hasalpha" ]; then - cached "$will_dds" reduce_rgba_dds "$F" "" "dds/${f}.dds" "" "$dds_flags" - cached "$will_jpeg" reduce_rgba_jpeg2 "$F" "" "${f}.jpg" "${f}_alpha.jpg" "$jqual_rgb" "$jqual_a" + cached "$will_dds" reduce_rgba_dds$pm "$F" "" "dds/${f}.dds" "" "$dds_flags" + cached "$will_jpeg" reduce_rgba_jpeg2 "$F" "" "${f}.jpg" "${f}_alpha.jpg" "$jqual_rgb" "$jqual_a" else - cached "$will_dds" reduce_rgb_dds "$F" "" "dds/${f}.dds" "" "$dds_flags" - cached "$will_jpeg" reduce_rgb_jpeg "$F" "" "${f}.jpg" "" "$jqual_rgb" + cached "$will_dds" reduce_rgb_dds "$F" "" "dds/${f}.dds" "" "$dds_flags" + cached "$will_jpeg" reduce_rgb_jpeg "$F" "" "${f}.jpg" "" "$jqual_rgb" fi rm -f "$F.hasalpha" ;; *.ogg) cached "$do_ogg" reduce_ogg_ogg "$F" "" "$F" "" "$ogg_qual" ;; + ./sound/misc/null.wav) + # never convert this one + ;; *.wav) - cached "$do_ogg" reduce_wav_ogg "$F" "" "$F" "" "$ogg_qual" + cached "$do_ogg" reduce_wav_ogg "$F" "" "${f}.ogg" "" "$ogg_qual" ;; esac if $del_src; then