Last active
June 15, 2019 03:28
-
-
Save drewcassidy/1f3d583f7ef6086e5fb2baf87525c56a to your computer and use it in GitHub Desktop.
Convert all input to DDS and replace using nvcompress or Crunch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
mkdir -p /tmp/dds > /dev/null | |
tool="nvcompress" | |
for file in "$@" | |
do | |
echo "$file" | |
dirname=$(dirname "$file") | |
basename=$(basename "$file") | |
extname="${file#${file%.*}}" | |
filename=$(basename "$basename" "$extname") | |
convert -flip "$file" "/tmp/dds/$basename" | |
alpha=$(convert "$file" -resize 1x1 -format "%[fx:int(255*a+.5)]" info:-) | |
if [ "$tool" == "crunch" ] | |
then | |
if [ $alpha -lt 255 ] | |
then | |
format="-dxt5" | |
else | |
format="-dxt1" | |
fi | |
crunch -quiet -file "/tmp/dds/$basename" -fileformat dds $format && rm $file | |
else | |
if [ $alpha -lt 255 ] | |
then | |
format="-bc3" | |
else | |
format="-bc1" | |
fi | |
nvcompress $format "/tmp/dds/$basename" "$dirname/$filename.dds" && rm $file | |
fi | |
done⏎ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment