diff --git a/BPTCEncoder/src/RGBAEndpoints.cpp b/BPTCEncoder/src/RGBAEndpoints.cpp index c792051..ca365af 100755 --- a/BPTCEncoder/src/RGBAEndpoints.cpp +++ b/BPTCEncoder/src/RGBAEndpoints.cpp @@ -217,16 +217,16 @@ uint32 RGBAVector::ToPixel(const uint32 channelMask, const int pBit) const { // /////////////////////////////////////////////////////////////////////////////// +template double RGBACluster::QuantizedError( const RGBAVector &p1, const RGBAVector &p2, - uint8 nBuckets, uint32 bitMask, const RGBAVector &errorMetricVec, + uint32 bitMask, const RGBAVector &errorMetricVec, const int pbits[2], uint8 *indices ) const { // nBuckets should be a power of two. - assert(nBuckets == 3 || !(nBuckets & (nBuckets - 1))); - - const uint8 indexPrec = (nBuckets == 3)? 3 : 8-CountBitsInMask(~(nBuckets - 1)); + assert(!(nBuckets & (nBuckets - 1))); + const uint8 indexPrec = 8-CountBitsInMask(~(nBuckets - 1)); typedef uint32 tInterpPair[2]; typedef tInterpPair tInterpLevel[16]; @@ -295,6 +295,21 @@ double RGBACluster::QuantizedError( return totalError; } +template double RGBACluster::QuantizedError<4>( + const RGBAVector &p1, const RGBAVector &p2, + uint32 bitMask, const RGBAVector &errorMetricVec, + const int pbits[2], uint8 *indices) const; + +template double RGBACluster::QuantizedError<8>( + const RGBAVector &p1, const RGBAVector &p2, + uint32 bitMask, const RGBAVector &errorMetricVec, + const int pbits[2], uint8 *indices) const; + +template double RGBACluster::QuantizedError<16>( + const RGBAVector &p1, const RGBAVector &p2, + uint32 bitMask, const RGBAVector &errorMetricVec, + const int pbits[2], uint8 *indices) const; + uint32 RGBACluster::GetPrincipalAxis(RGBADir &axis, float *eigOne, float *eigTwo) const { // We use these vectors for calculating the covariance matrix... diff --git a/BPTCEncoder/src/RGBAEndpoints.h b/BPTCEncoder/src/RGBAEndpoints.h index cce0d01..eca39f0 100755 --- a/BPTCEncoder/src/RGBAEndpoints.h +++ b/BPTCEncoder/src/RGBAEndpoints.h @@ -71,6 +71,7 @@ #include "Matrix4x4.h" #include +#include #include #include #include @@ -164,11 +165,25 @@ public: // Returns the error if we were to quantize the colors right now with the // given number of buckets and bit mask. + template double QuantizedError( const RGBAVector &p1, const RGBAVector &p2, - uint8 nBuckets, uint32 bitMask, const RGBAVector &errorMetricVec, + uint32 bitMask, const RGBAVector &errorMetricVec, const int pbits[2] = NULL, uint8 *indices = NULL) const; + double QuantizedError( + const RGBAVector &p1, const RGBAVector &p2, + uint32 nBuckets, uint32 bitMask, const RGBAVector &errorMetricVec, + const int pbits[2] = NULL, uint8 *indices = NULL) const { + switch(nBuckets) { + case 4: return QuantizedError<4>(p1, p2, bitMask, errorMetricVec, pbits, indices); + case 8: return QuantizedError<8>(p1, p2, bitMask, errorMetricVec, pbits, indices); + case 16: return QuantizedError<16>(p1, p2, bitMask, errorMetricVec, pbits, indices); + } + assert(!"Unsupported num buckets"); + return std::numeric_limits::max(); + } + bool AllSamePoint() const { return m_Max == m_Min; } // Returns the principal axis for this point cluster.