diff --git a/PVRTCEncoder/src/Block.cpp b/PVRTCEncoder/src/Block.cpp index 5b49b3f..ebbf06f 100644 --- a/PVRTCEncoder/src/Block.cpp +++ b/PVRTCEncoder/src/Block.cpp @@ -73,7 +73,7 @@ namespace PVRTCC { const uint8 opaqueBitDepths[4] = { 0, 5, 5, 5 }; const uint8 transBitDepths[4] = { 3, 4, 4, 4 }; - m_ColorA = Pixel(m_ByteData, isOpaque? opaqueBitDepths : transBitDepths); + m_ColorA = Pixel(m_ByteData, isOpaque? opaqueBitDepths : transBitDepths, 1); m_ColorACached = true; return m_ColorA; } diff --git a/PVRTCEncoder/src/Pixel.cpp b/PVRTCEncoder/src/Pixel.cpp index 0d669ab..2b01800 100644 --- a/PVRTCEncoder/src/Pixel.cpp +++ b/PVRTCEncoder/src/Pixel.cpp @@ -73,18 +73,14 @@ namespace PVRTCC { nBits += m_BitDepth[i]; } - const uint32 nBytes = (nBits >> 3) + ((nBits & 0x7) > 0); - assert(nBytes > 0); - - int32 byteIdx = nBytes - 1; + int32 byteIdx = 0; uint32 bitIdx = bitOffset; while(bitIdx >= 8) { bitIdx -= 8; - byteIdx--; - assert(byteIdx >= 0); + byteIdx++; } - for(int32 i = 3; i >= 0; i--) { + for(int32 i = 0; i < 4; i++) { uint8 &channel = m_Component[i]; uint32 depth = m_BitDepth[i]; @@ -94,17 +90,18 @@ namespace PVRTCC { if(0 == depth) { channel = 0xFF; } else if(depth + bitIdx < 8) { - channel = (bits[byteIdx] >> bitIdx) & ((1 << depth) - 1); bitIdx += depth; + channel = (bits[byteIdx] >> (8 - bitIdx)) & ((1 << depth) - 1); } else { const uint32 numLowBits = 8 - bitIdx; uint32 bitsLeft = depth - numLowBits; - channel |= (bits[byteIdx] >> bitIdx) & ((1 << numLowBits) - 1); - byteIdx--; - assert(byteIdx >= 0 || (i == 0 && bitsLeft == 0)); + channel |= bits[byteIdx] & ((1 << numLowBits) - 1); + byteIdx++; - uint8 highBits = bits[byteIdx] & ((1 << bitsLeft) - 1); - channel |= highBits << numLowBits; + const uint8 highBitsMask = ((1 << bitsLeft) - 1); + const uint8 highBits = (bits[byteIdx] >> (8 - bitsLeft)) & highBitsMask; + channel <<= bitsLeft; + channel |= highBits; bitIdx = bitsLeft; } }