From f5e0aa4f9fb77216ebe326f3371e49831c6bb089 Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Tue, 10 Sep 2013 13:21:48 -0400 Subject: [PATCH] Make sure to clear the MSBs of channels that have zero depth that get converted to higher depth values --- PVRTCEncoder/src/Pixel.cpp | 4 +++- PVRTCEncoder/test/PixelTest.cpp | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) 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};