Fixed .ktx parsing.

This commit is contained in:
Branimir Karadžić
2017-07-12 19:12:21 -07:00
parent 09ba52b2fa
commit 55d2962d4a
2 changed files with 10 additions and 7 deletions

View File

@@ -3136,15 +3136,18 @@ namespace bimg
for (uint8_t lod = 0, num = _imageContainer.m_numMips; lod < num; ++lod)
{
uint32_t imageSize = bx::toHostEndian(*(const uint32_t*)&data[offset], _imageContainer.m_ktxLE) / _imageContainer.m_numLayers;
offset += sizeof(uint32_t);
width = bx::uint32_max(blockWidth * minBlockX, ( (width + blockWidth - 1) / blockWidth )*blockWidth);
height = bx::uint32_max(blockHeight * minBlockY, ( (height + blockHeight - 1) / blockHeight)*blockHeight);
depth = bx::uint32_max(1, depth);
uint32_t size = width*height*depth*bpp/8;
const uint32_t mipSize = width*height*depth*bpp/8;
const uint32_t size = mipSize*numSides;
uint32_t imageSize = bx::toHostEndian(*(const uint32_t*)&data[offset], _imageContainer.m_ktxLE);
BX_CHECK(size == imageSize, "KTX: Image size mismatch %d (expected %d).", size, imageSize);
BX_UNUSED(size, imageSize);
offset += sizeof(uint32_t);
for (uint16_t side = 0; side < numSides; ++side)
{
@@ -3154,7 +3157,7 @@ namespace bimg
_mip.m_width = width;
_mip.m_height = height;
_mip.m_blockSize = blockSize;
_mip.m_size = size;
_mip.m_size = mipSize;
_mip.m_data = &data[offset];
_mip.m_bpp = bpp;
_mip.m_format = format;
@@ -3162,7 +3165,7 @@ namespace bimg
return true;
}
offset += imageSize;
offset += mipSize;
BX_CHECK(offset <= _size, "Reading past size of data buffer! (offset %d, size %d)", offset, _size);
BX_UNUSED(_size);

View File

@@ -26,7 +26,7 @@
#include <string>
#define BIMG_TEXTUREC_VERSION_MAJOR 1
#define BIMG_TEXTUREC_VERSION_MINOR 5
#define BIMG_TEXTUREC_VERSION_MINOR 6
struct Options
{