From b88f1b716ba5a4452671d6045ce0662660a4acc6 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sat, 11 May 2013 21:43:16 +0200 Subject: [PATCH] Scripts for non-power-of 2 textures --- tools/convert-npow2.sh | 15 +++++++++++++++ tools/find-npow2.sh | 20 ++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100755 tools/convert-npow2.sh create mode 100755 tools/find-npow2.sh diff --git a/tools/convert-npow2.sh b/tools/convert-npow2.sh new file mode 100755 index 00000000..130c0306 --- /dev/null +++ b/tools/convert-npow2.sh @@ -0,0 +1,15 @@ +function nearest_pow2 { + python -c "import math; print(2 ** int(math.ceil(math.log($1) / math.log(2.0))))" +} + +mkdir -p new + +for file in $@ do + size=$(identify $file | cut -d' ' -f 3) + w=$(echo $size | cut -d'x' -f 1) + h=$(echo $size | cut -d'x' -f 2) + n_w=$(nearest_pow2 $w) + n_h=$(nearest_pow2 $h) + echo "$file: ${w}x${h} -> ${n_w}x${n_h}" + convert $file -resize ${n_w}x${n_h}\! new/$file +done diff --git a/tools/find-npow2.sh b/tools/find-npow2.sh new file mode 100755 index 00000000..08c2cd63 --- /dev/null +++ b/tools/find-npow2.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +function check_npow2 { + ans=`python -c "import math; l = math.log($1) / math.log(2.0); print(2**int(l) != $1)"` + if [ "$ans" == "True" ]; then + echo "1" + else + echo "0" + fi +} + +for file in textures/*; do + x_res=`identify $file | sed -E -n 's/.* ([0-9]+)x[0-9]+\+[0-9]+\+[0-9]+ .*/\1/p'` + y_res=`identify $file | sed -E -n 's/.* [0-9]+x([0-9]+)\+[0-9]+\+[0-9]+ .*/\1/p'` + npow_x=`check_npow2 $x_res` + npow_y=`check_npow2 $y_res` + if [ "$npow_x" == "1" -o "$npow_y" == "1" ]; then + echo "`basename $file`: non-pow2 dimensions: ${x_res}x${y_res}" + fi +done