JPEG and DDS generator scripts (untested)
authorRudolf Polzer <divverent@alientrap.org>
Mon, 21 Jun 2010 07:45:07 +0000 (09:45 +0200)
committerRudolf Polzer <divverent@alientrap.org>
Mon, 21 Jun 2010 07:45:07 +0000 (09:45 +0200)
misc/tools/generate-dds.sh [new file with mode: 0755]
misc/tools/generate-jpeg.sh [new file with mode: 0755]
misc/tools/jpeg-if-not-alpha.sh [deleted file]

diff --git a/misc/tools/generate-dds.sh b/misc/tools/generate-dds.sh
new file mode 100755 (executable)
index 0000000..7e407b0
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+set -e
+
+for X in "$@"; do
+       case "$X" in
+               *.jpg)
+                       if [ -n "$scaledown" ]; then
+                               mogrify -geometry "$scaledown" -quality 100 "$X"
+                       fi
+                       echo "$X has no alpha, converting"
+                       nvcompress -bc1 "$X" "${X%.*}.dds"
+                       rm -f "$X"
+                       ;;
+               *.png|*.tga)
+                       if [ -n "$scaledown" ]; then
+                               mogrify -geometry "$scaledown" -quality 100 "$X"
+                       fi
+                       if convert "$X" -depth 16 RGBA:- | perl -e 'while(read STDIN, $_, 8) { substr($_, 6, 2) eq "\xFF\xFF" or exit 1; ++$pix; } exit not $pix;'; then
+                               echo "$X has no alpha, converting"
+                               nvcompress -bc1 "$X" "${X%.*}.dds"
+                               rm -f "$X"
+                       else
+                               echo "$X has alpha, converting"
+                               nvcompress -alpha -bc3 "$X" "${X%.*}.dds"
+                               rm -f "$X"
+                       fi
+                       ;;
+       esac
+done
diff --git a/misc/tools/generate-jpeg.sh b/misc/tools/generate-jpeg.sh
new file mode 100755 (executable)
index 0000000..f9ba64a
--- /dev/null
@@ -0,0 +1,33 @@
+#!/bin/sh
+
+set -e
+
+: ${qual:=95}
+
+for X in "$@"; do
+       case "$X" in
+               *.jpg)
+                       if [ -n "$scaledown" ]; then
+                               mogrify -geometry "$scaledown" -quality 100 "$X"
+                       fi
+                       jpegoptim --strip-all -m$qual "$X"
+                       ;;
+               *.png|*.tga)
+                       if [ -n "$scaledown" ]; then
+                               mogrify -geometry "$scaledown" -quality 100 "$X"
+                       fi
+                       if convert "$X" -depth 16 RGBA:- | perl -e 'while(read STDIN, $_, 8) { substr($_, 6, 2) eq "\xFF\xFF" or exit 1; ++$pix; } exit not $pix;'; then
+                               echo "$X has no alpha, converting"
+                               convert "$X" -quality 100 "${X%.*}.jpg"
+                               jpegoptim --strip-all -m$qual "${X%.*}.jpg"
+                               rm -f "$X"
+                       else
+                               echo "$X has alpha, converting twice"
+                               convert "$X" -alpha extract -quality 100 "${X%.*}.jpg"
+                               convert "$X" -alpha off     -quality 100 "${X%.*}_alpha.jpg"
+                               jpegoptim --strip-all -m$qual "${X%.*}_alpha.jpg"
+                               rm -f "$X"
+                       fi
+                       ;;
+       esac
+done
diff --git a/misc/tools/jpeg-if-not-alpha.sh b/misc/tools/jpeg-if-not-alpha.sh
deleted file mode 100755 (executable)
index f6e4597..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/bin/sh
-
-set -e
-
-: ${qual:=95}
-
-for X in "$@"; do
-       case "$X" in
-               *.jpg)
-                       if [ -n "$scaledown" ]; then
-                               mogrify -geometry "$scaledown>" -quality 100 "$X"
-                       fi
-                       jpegoptim --strip-all -m$qual "$X"
-                       ;;
-               *.png|*.tga)
-                       if [ -n "$scaledown" ]; then
-                               mogrify -geometry "$scaledown>" -quality 100 "$X"
-                       fi
-                       if convert "$X" -depth 16 RGBA:- | perl -e 'while(read STDIN, $_, 8) { substr($_, 6, 2) eq "\xFF\xFF" or exit 1; ++$pix; } exit not $pix;'; then
-                               echo "$X has no alpha, converting"
-                               convert "$X" -quality 100 "${X%.*}.jpg"
-                               jpegoptim --strip-all -m$qual "${X%.*}.jpg"
-                               rm -f "$X"
-                       else
-                               echo "$X has alpha, not converting"
-                       fi
-                       ;;
-       esac
-done