: ${do_jpeg_if_not_dds:=false}
: ${jpeg_qual_rgb:=95}
: ${jpeg_qual_a:=99}
+: ${do_webp:=false}
+: ${do_webp_if_not_dds:=false}
+: ${webp_flags_lq:=-lossless -q 100}
+: ${webp_flags_hq:=-lossless -q 100}
+: ${webp_flags_alq:=-lossless -q 100 -q_alpha 100}
+: ${webp_flags_ahq:=-lossless -q 100 -q_alpha 100}
: ${do_dds:=true}
-: ${dds_tool:=compressonator-dxtc}
+: ${dds_tool:=s2tc}
: ${do_ogg:=false}
-: ${ogg_qual:=1}
+: ${ogg_ogg:=true}
+: ${ogg_qual:=2}
: ${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
{
i=$1; shift
ia=$1; shift
- o=$1; shift; shift
- convert "$i" "$ia" -compose CopyOpacity -composite "$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
}
{
i=$1; shift
ia=$1; shift
- o=$1; shift; shift
- convert "$i" "$ia" -compose CopyOpacity -composite "$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
}
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
fi
}
+reduce_jpeg2_webp()
+{
+ i=$1; shift
+ ia=$1; shift
+ o=$1; shift; shift
+ # this one MUST run
+ convert "$i" "$ia" -auto-orient -compose CopyOpacity -composite -type TrueColorMatte "$tmpdir/x.png" && \
+ cwebp $1 "$tmpdir/x.png" -o "$o"
+}
+
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
{
i=$1; shift; shift
o=$1; shift; shift
- convert "$i" "$tmpdir/x.tga" && \
+ convert "$i" -auto-orient -type TrueColorMatte "$tmpdir/x.tga" && \
pickdxta "$dds_tool" "$dds_sepalpha" "$tmpdir/x.tga" "$o" $1
}
{
i=$1; shift; shift
o=$1; shift; shift
- convert "$i" "$tmpdir/x.tga" && \
+ convert "$i" -auto-orient -type TrueColorMatte "$tmpdir/x.tga" && \
pickdxta "$dds_tool" "$dds_prealpha" "$tmpdir/x.tga" "$o" $1
}
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
{
i=$1; shift; shift
o=$1; shift; shift
- convert "$i" "$tmpdir/x.tga" && \
+ convert "$i" -auto-orient -type TrueColor "$tmpdir/x.tga" && \
"$meprefix"compress-texture "$dds_tool" "$dds_noalpha" "$tmpdir/x.tga" "$o" $1
}
{
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
fi
}
+reduce_rgba_webp()
+{
+ i=$1; shift; shift
+ o=$1; shift; shift
+ convert "$i" -auto-orient "$tmpdir/x.png" && \
+ cwebp $1 "$tmpdir/x.png" -o "$o"
+}
+
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
keep=false
jqual_rgb=$jpeg_qual_rgb
jqual_a=$jpeg_qual_a
+ webp_mode=lq
will_jpeg=$do_jpeg
+ will_webp=$do_webp
will_dds=$do_dds
will_ogg=$do_ogg
- case "$f" in
- ./sounds/misc/talk*.wav) will_ogg=false ;; # engine "feature"
- *_bump) will_dds=false ;;
+ if ! $ogg_ogg; then
+ case "$F" in
+ *.ogg) will_ogg=false ;;
+ esac
+ fi
+ 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/*) ;;
./textures/*) ;;
./models/*) ;;
./particles/*) ;;
;;
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
case "$f" in
./maps/*/lm_[0-9][0-9][0-9][13579]) # deluxemap
jqual_rgb=$jqual_a
+ webp_mode=hq
;;
./maps/*/lm_[0-9][0-9][0-9][02468]) # lightmap
jqual_rgb=$jqual_a
+ webp_mode=hq
;;
*_norm) # normalmap
jqual_rgb=$jqual_a
+ webp_mode=hq
;;
esac
fi
will_jpeg=true
fi
fi
+ if $do_webp_if_not_dds; then
+ if $will_dds; then
+ will_webp=false
+ else
+ will_webp=true
+ fi
+ fi
selfprofile startconvert
case "$F" in
*_alpha.jpg)
# handle in *.jpg case
# they always got converted, I assume
- if $will_dds || $will_jpeg; then
+ if $will_dds || $will_jpeg || $will_webp; then
conv=true
fi
keep=$will_jpeg
if [ -f "${f}_alpha.jpg" ]; then
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
+ #eval wflags=\$webp_flags_${webp_mode}a
+ #cached "$will_webp" reduce_jpeg2_webp "$F" "${f}_alpha.jpg" "${f}.webp" "" "$wflags"
+ else
cached "$will_dds" reduce_rgb_dds "$F" "" "dds/${f}.dds" "" "$dds_flags"
cached "$will_jpeg" reduce_jpeg_jpeg "$F" "" "$F" "" "$jqual_rgb"
+ #eval wflags=\$webp_flags_${webp_mode}
+ #cached "$will_webp" reduce_rgba_webp "$F" "" "${f}.webp" "" "$wflags"
fi
;;
- *.png|*.tga)
+ *.png|*.tga|*.webp)
cached true has_alpha "$F" "" "$F.hasalpha" ""
conv=false
if [ -s "$F.hasalpha" ]; then
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
+ eval wflags=\$webp_flags_${webp_mode}a
+ cached "$will_webp" reduce_rgba_webp "$F" "" "${f}.webp" "" "$wflags"
+ else
cached "$will_dds" reduce_rgb_dds "$F" "" "dds/${f}.dds" "" "$dds_flags"
cached "$will_jpeg" reduce_rgb_jpeg "$F" "" "${f}.jpg" "" "$jqual_rgb"
+ eval wflags=\$webp_flags_${webp_mode}
+ cached "$will_webp" reduce_rgba_webp "$F" "" "${f}.webp" "" "$wflags"
fi
rm -f "$F.hasalpha"
;;