diff --git a/PVRTCEncoder/src/Pixel.cpp b/PVRTCEncoder/src/Pixel.cpp index d8504a3..d64b9c1 100644 --- a/PVRTCEncoder/src/Pixel.cpp +++ b/PVRTCEncoder/src/Pixel.cpp @@ -112,9 +112,11 @@ namespace PVRTCC { assert(newDepth <= 8); assert(oldDepth <= 8); - if(oldDepth == newDepth || oldDepth == 0) { + if(oldDepth == newDepth) { // Do nothing return val; + } else if(oldDepth == 0 && newDepth != 0) { + return (1 << newDepth) - 1; } else if(newDepth > oldDepth) { uint8 bitsLeft = newDepth; uint8 ret = 0; diff --git a/PVRTCEncoder/test/PixelTest.cpp b/PVRTCEncoder/test/PixelTest.cpp index d1d24f2..afc380f 100644 --- a/PVRTCEncoder/test/PixelTest.cpp +++ b/PVRTCEncoder/test/PixelTest.cpp @@ -153,6 +153,19 @@ TEST(Pixel, ChangeChannelBitDepth) { EXPECT_EQ(PVRTCC::Pixel::ChangeBitDepth(val, depth, 0), 0xFF); } +TEST(Pixel, ChangeChannelBitDepthFromZero) { + uint8 val = 0x43; + uint8 depth = 0; + + EXPECT_EQ(PVRTCC::Pixel::ChangeBitDepth(val, depth, 8), 0xFF); + EXPECT_EQ(PVRTCC::Pixel::ChangeBitDepth(val, depth, 7), 0x7F); + EXPECT_EQ(PVRTCC::Pixel::ChangeBitDepth(val, depth, 6), 0x3F); + EXPECT_EQ(PVRTCC::Pixel::ChangeBitDepth(val, depth, 2), 0x03); + + // Shouldn't change it... + EXPECT_EQ(PVRTCC::Pixel::ChangeBitDepth(val, depth, 0), 0x43); +} + TEST(Pixel, ChangePixelBitDepth) { const uint8 bits[4] = { 0x86, 0xC0, 0x0, 0x0 }; const uint8 depth[4] = {7, 3, 0, 0};