Cache the pixel computation for the cluster upon creation

This commit is contained in:
Pavel Krajcevski 2014-03-25 16:24:30 -04:00
parent 4128bcf073
commit 6505944f57
2 changed files with 7 additions and 1 deletions

View file

@ -254,7 +254,7 @@ double RGBACluster::QuantizedError(
float totalError = 0.0; float totalError = 0.0;
for(uint32 i = 0; i < GetNumPoints(); i++) { for(uint32 i = 0; i < GetNumPoints(); i++) {
const uint32 pixel = GetPoint(i).ToPixel(); const uint32 pixel = GetPixel(i);
const uint8 *pb = (const uint8 *)(&pixel); const uint8 *pb = (const uint8 *)(&pixel);
float minError = FLT_MAX; float minError = FLT_MAX;

View file

@ -141,6 +141,7 @@ public:
RGBAVector p = RGBAVector(i, pixels[i]); RGBAVector p = RGBAVector(i, pixels[i]);
m_Avg += p; m_Avg += p;
m_PointMap[m_NumPoints] = i; m_PointMap[m_NumPoints] = i;
m_DataPixels[m_NumPoints] = p.ToPixel();
m_DataPoints[m_NumPoints++] = p; m_DataPoints[m_NumPoints++] = p;
for(uint32 i = 0; i < kNumColorChannels; i++) { for(uint32 i = 0; i < kNumColorChannels; i++) {
@ -156,6 +157,10 @@ public:
return m_DataPoints[m_PointMap[idx]]; return m_DataPoints[m_PointMap[idx]];
} }
const uint32 &GetPixel(int idx) const {
return m_DataPixels[m_PointMap[idx]];
}
uint32 GetNumPoints() const { return m_NumPoints; } uint32 GetNumPoints() const { return m_NumPoints; }
RGBAVector GetAvg() const { return m_Avg; } RGBAVector GetAvg() const { return m_Avg; }
@ -219,6 +224,7 @@ public:
// The points in the cluster. // The points in the cluster.
RGBAVector m_DataPoints[kMaxNumDataPoints]; RGBAVector m_DataPoints[kMaxNumDataPoints];
uint32 m_DataPixels[kMaxNumDataPoints];
uint8 m_PointMap[kMaxNumDataPoints]; uint8 m_PointMap[kMaxNumDataPoints];
RGBAVector m_Min, m_Max; RGBAVector m_Min, m_Max;