From fa37aba7688f9234efffacdc5545f44ba2b59c0b Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Sat, 31 Aug 2013 16:37:58 -0400 Subject: [PATCH] Add comparison operator for pixels --- PVRTCEncoder/src/Pixel.cpp | 14 ++++++++++++++ PVRTCEncoder/src/Pixel.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/PVRTCEncoder/src/Pixel.cpp b/PVRTCEncoder/src/Pixel.cpp index 8db81f6..d8504a3 100644 --- a/PVRTCEncoder/src/Pixel.cpp +++ b/PVRTCEncoder/src/Pixel.cpp @@ -163,5 +163,19 @@ namespace PVRTCC { return r; } + bool Pixel::operator==(const Pixel &other) const { + uint8 depths[4]; + other.GetBitDepth(depths); + + bool ok = true; + for(int i = 0; i < 4; i++) { + ok = ok && m_BitDepth[i] == depths[i]; + + uint8 mask = (1 << depths[i]) - 1; + const uint8 c = other.Component(i) & mask; + ok = ok && (c == (Component(i) & mask)); + } + return ok; + } } // namespace PVRTCC diff --git a/PVRTCEncoder/src/Pixel.h b/PVRTCEncoder/src/Pixel.h index 7c3a488..692eed3 100644 --- a/PVRTCEncoder/src/Pixel.h +++ b/PVRTCEncoder/src/Pixel.h @@ -111,6 +111,9 @@ class Pixel { // up in the most-significant byte. uint32 PackRGBA() const; + // Tests for equality by comparing the values and the bit depths. + bool operator==(const Pixel &) const; + private: union { struct {