Make sure to clear the MSBs of channels that have zero depth that get converted to higher depth values

This commit is contained in:
Pavel Krajcevski 2013-09-10 13:21:48 -04:00
parent 77bb7488cc
commit f5e0aa4f9f
2 changed files with 16 additions and 1 deletions

View File

@ -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;

View File

@ -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};