Add unpack RGBA for our pixels

This commit is contained in:
Pavel Krajcevski 2013-09-12 14:41:00 -04:00
parent 9f6e6e7233
commit 7184d49ccd
3 changed files with 27 additions and 0 deletions

View file

@ -165,6 +165,13 @@ namespace PVRTCC {
return r;
}
void Pixel::UnpackRGBA(uint32 rgba) {
A() = ChangeBitDepth((rgba >> 24) & 0xFF, 8, m_BitDepth[0]);
R() = ChangeBitDepth(rgba & 0xFF, 8, m_BitDepth[1]);
G() = ChangeBitDepth((rgba >> 8) & 0xFF, 8, m_BitDepth[2]);
B() = ChangeBitDepth((rgba >> 16) & 0xFF, 8, m_BitDepth[3]);
}
bool Pixel::operator==(const Pixel &other) const {
uint8 depths[4];
other.GetBitDepth(depths);

View file

@ -110,6 +110,7 @@ class Pixel {
// that the architecture is little-endian, so the alpha channel will end
// up in the most-significant byte.
uint32 PackRGBA() const;
void UnpackRGBA(uint32 rgba);
// Tests for equality by comparing the values and the bit depths.
bool operator==(const Pixel &) const;

View file

@ -195,3 +195,22 @@ TEST(Pixel, PackRGBA) {
uint32 val = p.PackRGBA();
EXPECT_EQ(val, 0x87FFFF6D);
}
TEST(Pixel, UnpackRGBA) {
uint32 rgba = 0x4619B3FE;
PVRTCC::Pixel p;
p.UnpackRGBA(rgba);
EXPECT_EQ(p.A(), 0x46);
EXPECT_EQ(p.B(), 0x19);
EXPECT_EQ(p.G(), 0xB3);
EXPECT_EQ(p.R(), 0xFE);
uint8 newBitDepth[4] = { 3, 5, 2, 1 }; // A R G B
p.ChangeBitDepth(newBitDepth);
EXPECT_EQ(p.A(), 0x2);
EXPECT_EQ(p.B(), 0x0);
EXPECT_EQ(p.G(), 0x2);
EXPECT_EQ(p.R(), 0x1f);
}