From 19b5d478a0c8de556b1dff6d1e5782914ec8ae7a Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Tue, 4 Nov 2014 18:22:05 -0500 Subject: [PATCH] Fix small bug: Set the bits that aren't being used in the texel data to zero so that the integer decoding sequence recreates the proper texel values for trits and quints that don't have as many bits as there are expected values. --- ASTCEncoder/src/Decompressor.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/ASTCEncoder/src/Decompressor.cpp b/ASTCEncoder/src/Decompressor.cpp index b7dd85a..71e2279 100644 --- a/ASTCEncoder/src/Decompressor.cpp +++ b/ASTCEncoder/src/Decompressor.cpp @@ -912,6 +912,18 @@ namespace ASTCC { } assert(strm.GetBitsRead() + weightParams.GetPackedBitSize() == 128); + // Decode both color data and texel weight data + uint32 colorValues[32]; // Four values, two endpoints, four maximum paritions + DecodeColorValues(colorValues, colorEndpointData, colorEndpointMode, + nPartitions, colorDataBits); + + FasTC::Pixel endpoints[4][2]; + const uint32 *colorValuesPtr = colorValues; + for(uint32 i = 0; i < nPartitions; i++) { + ComputeEndpoints(endpoints[i][0], endpoints[i][1], + colorValuesPtr, colorEndpointMode[i]); + } + // Read the texel weight data.. uint8 texelWeightData[16]; memcpy(texelWeightData, inBuf, sizeof(texelWeightData)); @@ -928,10 +940,10 @@ namespace ASTCC { texelWeightData[15-i] = a; } - // Decode both color data and texel weight data - uint32 colorValues[32]; // Four values, two endpoints, four maximum paritions - DecodeColorValues(colorValues, colorEndpointData, colorEndpointMode, - nPartitions, colorDataBits); + // Make sure that higher non-texel bits are set to zero + const uint32 clearByteStart = (weightParams.GetPackedBitSize() >> 3) + 1; + texelWeightData[clearByteStart - 1] &= (1 << (weightParams.GetPackedBitSize() % 8)) - 1; + memset(texelWeightData + clearByteStart, 0, 16 - clearByteStart); std::vector texelWeightValues; FasTC::BitStreamReadOnly weightStream (texelWeightData); @@ -941,13 +953,6 @@ namespace ASTCC { weightParams.m_MaxWeight, weightParams.GetNumWeightValues()); - FasTC::Pixel endpoints[4][2]; - const uint32 *colorValuesPtr = colorValues; - for(uint32 i = 0; i < nPartitions; i++) { - ComputeEndpoints(endpoints[i][0], endpoints[i][1], - colorValuesPtr, colorEndpointMode[i]); - } - // Blocks can be at most 12x12, so we can have as many as 144 weights uint32 weights[2][144]; UnquantizeTexelWeights(weights, texelWeightValues, weightParams, blockWidth, blockHeight);