+ 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
+ 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/*) ;;
+ ./progs/*) ;;
+ *)
+ # we can't DDS compress the 2D textures, sorry
+ # but JPEG is still fine
+ will_dds=false
+ ;;
+ esac
+
+ # 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.
+ export CRUNCH_TEXTYPEFLAGS='-gamma 1.0 -renormalize -rtopmip -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.
+ export CRUNCH_TEXTYPEFLAGS='-gamma 1.0 -renormalize -rtopmip -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
+
+ # for deluxemaps, lightmaps and normalmaps, enforce high jpeg quality (like on alpha channels)
+ if [ "$jqual_a" -gt "$jqual_rgb" ]; then
+ 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
+
+ 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
+ else
+ 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