Reverse the bits of the ASTC block in order to read the texel weight data...

This commit is contained in:
Pavel Krajcevski 2014-05-08 00:45:23 +02:00
parent 1269ab1314
commit a8514ba9b3

View file

@ -915,18 +915,19 @@ namespace ASTCC {
// Read the texel weight data.. // Read the texel weight data..
uint8 texelWeightData[16]; uint8 texelWeightData[16];
memset(texelWeightData, 0, sizeof(texelWeightData)); memcpy(texelWeightData, inBuf, sizeof(texelWeightData));
FasTC::BitStream texelWeightStream (texelWeightData, 16*8, 0);
int32 texelWeightBits = weightParams.GetPackedBitSize(); // Reverse everything
while(texelWeightBits > 0) { for(uint32 i = 0; i < 8; i++) {
uint32 nb = std::min(texelWeightBits, 8); // Taken from http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith64Bits
uint32 b = strm.ReadBits(nb); #define REVERSE_BYTE(b) (((b) * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32
texelWeightStream.WriteBits(b, nb); unsigned char a = REVERSE_BYTE(texelWeightData[i]);
texelWeightBits -= 8; unsigned char b = REVERSE_BYTE(texelWeightData[15 - i]);
} #undef REVERSE_BYTE
assert(strm.GetBitsRead() == 128); texelWeightData[i] = b;
texelWeightData[15-i] = a;
}
// Decode both color data and texel weight data // Decode both color data and texel weight data
uint32 colorValues[32]; // Four values, two endpoints, four maximum paritions uint32 colorValues[32]; // Four values, two endpoints, four maximum paritions