Add shuffle operator to pixels.

This commit is contained in:
Pavel Krajcevski 2014-01-30 13:34:52 -05:00
parent 426d12e5c9
commit 37ffc102d0
2 changed files with 34 additions and 0 deletions

View file

@ -143,6 +143,17 @@ class Pixel : public Vector4<uint16> {
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;
};

View file

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