From 7184d49ccde832ae8449099f574ed038546eb2d4 Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Thu, 12 Sep 2013 14:41:00 -0400 Subject: [PATCH] Add unpack RGBA for our pixels --- PVRTCEncoder/src/Pixel.cpp | 7 +++++++ PVRTCEncoder/src/Pixel.h | 1 + PVRTCEncoder/test/PixelTest.cpp | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/PVRTCEncoder/src/Pixel.cpp b/PVRTCEncoder/src/Pixel.cpp index d64b9c1..aa3d3a1 100644 --- a/PVRTCEncoder/src/Pixel.cpp +++ b/PVRTCEncoder/src/Pixel.cpp @@ -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); diff --git a/PVRTCEncoder/src/Pixel.h b/PVRTCEncoder/src/Pixel.h index 692eed3..1953e09 100644 --- a/PVRTCEncoder/src/Pixel.h +++ b/PVRTCEncoder/src/Pixel.h @@ -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; diff --git a/PVRTCEncoder/test/PixelTest.cpp b/PVRTCEncoder/test/PixelTest.cpp index afc380f..b8b4d2a 100644 --- a/PVRTCEncoder/test/PixelTest.cpp +++ b/PVRTCEncoder/test/PixelTest.cpp @@ -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); +}