Scripts for non-power-of 2 textures

dev-ui
Piotr Dziwinski 2013-05-11 21:43:16 +02:00
parent 23b3b01d92
commit b88f1b716b
2 changed files with 35 additions and 0 deletions

15
tools/convert-npow2.sh Executable file
View File

@ -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

20
tools/find-npow2.sh Executable file
View File

@ -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