From 4c03336a43b382284c9a5f5f9d512637fdaef0cb Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Mon, 3 Nov 2014 15:07:56 -0500 Subject: [PATCH] Fix how we compute compressed size --- Core/src/CompressedImage.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Core/src/CompressedImage.cpp b/Core/src/CompressedImage.cpp index 63dfa3c..097dd94 100644 --- a/Core/src/CompressedImage.cpp +++ b/Core/src/CompressedImage.cpp @@ -167,15 +167,21 @@ void CompressedImage::ComputePixels() { } uint32 CompressedImage::GetCompressedSize(uint32 uncompressedSize, ECompressionFormat format) { + + // Make sure that the uncompressed size is a multiple of the pixel size. + assert(uncompressedSize % sizeof(uint32) == 0); + + // The compressed size is the block size times the number of blocks uint32 blockDim[2]; GetBlockDimensions(format, blockDim); - const uint32 uncompBlockSz = blockDim[0] * blockDim[1] * sizeof(uint32); + const uint32 uncompBlockSize = blockDim[0] * blockDim[1] * sizeof(uint32); + + // The uncompressed block size should be a factor of the uncompressed size. + assert(uncompressedSize % uncompBlockSize == 0); + + const uint32 nBlocks = uncompressedSize / uncompBlockSize; const uint32 blockSz = GetBlockSize(format); - assert(uncompBlockSz % blockSz == 0); - const uint32 scale = uncompBlockSz / blockSz; - - assert(uncompressedSize % blockSz == 0); - return uncompressedSize / scale; + return nBlocks * blockSz; }