aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-06-20 10:55:26 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-06-20 10:56:18 -0700
commit67ae1a27f32d1fc6ac6f7262fc3d22cf1003e7e3 (patch)
tree58416e871cd86b130463f772430a9add3907e61c /tools
parent6d34633796954f2edb225c66e62ab5a188d59bb0 (diff)
support for non-square crunch textures with mipmaps
Diffstat (limited to 'tools')
-rw-r--r--tools/crunch-worker.js12
1 files changed, 10 insertions, 2 deletions
diff --git a/tools/crunch-worker.js b/tools/crunch-worker.js
index 7bc63870..5c48d009 100644
--- a/tools/crunch-worker.js
+++ b/tools/crunch-worker.js
@@ -66,7 +66,6 @@
if(format != cCRNFmtDXT1 && format != cCRNFmtDXT3 && format != cCRNFmtDXT5) {
throw "Unsupported image format " + format + " for " + filename;
}
-
width = Module._crn_get_width(src, srcSize);
height = Module._crn_get_height(src, srcSize);
levels = Module._crn_get_levels(src, srcSize);
@@ -74,9 +73,18 @@
dst = Module._malloc(dstSize);
var totalSize = 0;
+ var bytesPerPixel = format == cCRNFmtDXT1 ? 0.5 : 1;
for(i = 0; i < levels; ++i) {
- totalSize += Module._crn_get_uncompressed_size(src, srcSize, i);
+ totalSize += width * height * bytesPerPixel;
+ width *= 0.5;
+ height *= 0.5;
+ width = Math.max(width, 4);
+ height = Math.max(height, 4);
}
+
+ width = Module._crn_get_width(src, srcSize);
+ height = Module._crn_get_height(src, srcSize);
+
var ret = new Uint8Array(totalSize);
var retIndex = 0;