diff --git a/Base/include/Pixel.h b/Base/include/Pixel.h index 54555c9..1f6afe2 100644 --- a/Base/include/Pixel.h +++ b/Base/include/Pixel.h @@ -143,6 +143,17 @@ class Pixel : public Vector4 { uint32 Pack() const; void Unpack(uint32 rgba); + // Shuffles the pixel values around so that they change their ordering based + // on the passed mask. The values are chosen such that each two bits from the + // least significant bit define a value from 0-3. From LSB to MSB, the values + // are labelled a, b, c, d. From these labels, we store: + // m_Pixels[0] = m_Pixels[a] + // m_Pixels[1] = m_Pixels[b] + // m_Pixels[2] = m_Pixels[c] + // m_Pixels[3] = m_Pixels[d] + // hence, 0xE4 (11 10 01 00) represents a no-op. + void Shuffle(uint8 shuffleMask = 0xE4); + // Tests for equality by comparing the values and the bit depths. bool operator==(const Pixel &) const; }; diff --git a/Base/src/Pixel.cpp b/Base/src/Pixel.cpp index 01582ef..8364dd2 100644 --- a/Base/src/Pixel.cpp +++ b/Base/src/Pixel.cpp @@ -222,6 +222,29 @@ namespace FasTC { B() = ChangeBitDepth((rgba >> 16) & 0xFF, 8, m_BitDepth[3]); } + void Pixel::Shuffle(uint8 shuffleMask) { + Pixel thisPixel(*this); + uint8 a = shuffleMask & 3; + uint8 b = (shuffleMask >> 2) & 3; + uint8 c = (shuffleMask >> 4) & 3; + uint8 d = (shuffleMask >> 6) & 3; + + Pixel tmp; + tmp[0] = thisPixel[a]; + tmp.m_BitDepth[0] = thisPixel.m_BitDepth[a]; + + tmp[1] = thisPixel[b]; + tmp.m_BitDepth[1] = thisPixel.m_BitDepth[b]; + + tmp[2] = thisPixel[c]; + tmp.m_BitDepth[2] = thisPixel.m_BitDepth[c]; + + tmp[3] = thisPixel[d]; + tmp.m_BitDepth[3] = thisPixel.m_BitDepth[d]; + + *this = tmp; + } + bool Pixel::operator==(const Pixel &other) const { uint8 depths[4]; other.GetBitDepth(depths);