From 6505944f577165412080042a67db2e2639af8b5d Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Tue, 25 Mar 2014 16:24:30 -0400 Subject: [PATCH] Cache the pixel computation for the cluster upon creation --- BPTCEncoder/src/RGBAEndpoints.cpp | 2 +- BPTCEncoder/src/RGBAEndpoints.h | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/BPTCEncoder/src/RGBAEndpoints.cpp b/BPTCEncoder/src/RGBAEndpoints.cpp index ca365af..bc8efb5 100755 --- a/BPTCEncoder/src/RGBAEndpoints.cpp +++ b/BPTCEncoder/src/RGBAEndpoints.cpp @@ -254,7 +254,7 @@ double RGBACluster::QuantizedError( float totalError = 0.0; for(uint32 i = 0; i < GetNumPoints(); i++) { - const uint32 pixel = GetPoint(i).ToPixel(); + const uint32 pixel = GetPixel(i); const uint8 *pb = (const uint8 *)(&pixel); float minError = FLT_MAX; diff --git a/BPTCEncoder/src/RGBAEndpoints.h b/BPTCEncoder/src/RGBAEndpoints.h index eca39f0..da07186 100755 --- a/BPTCEncoder/src/RGBAEndpoints.h +++ b/BPTCEncoder/src/RGBAEndpoints.h @@ -141,6 +141,7 @@ public: RGBAVector p = RGBAVector(i, pixels[i]); m_Avg += p; m_PointMap[m_NumPoints] = i; + m_DataPixels[m_NumPoints] = p.ToPixel(); m_DataPoints[m_NumPoints++] = p; for(uint32 i = 0; i < kNumColorChannels; i++) { @@ -156,6 +157,10 @@ public: return m_DataPoints[m_PointMap[idx]]; } + const uint32 &GetPixel(int idx) const { + return m_DataPixels[m_PointMap[idx]]; + } + uint32 GetNumPoints() const { return m_NumPoints; } RGBAVector GetAvg() const { return m_Avg; } @@ -219,6 +224,7 @@ public: // The points in the cluster. RGBAVector m_DataPoints[kMaxNumDataPoints]; + uint32 m_DataPixels[kMaxNumDataPoints]; uint8 m_PointMap[kMaxNumDataPoints]; RGBAVector m_Min, m_Max;