From d23125e14c91ca28703df08c6e82023792ba5c3d Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Mon, 8 Apr 2013 16:44:15 -0400 Subject: [PATCH] Another bug fix. In the previous commit, we simply accomodated for alpha errors when compressing single color partitions. In fact, the issue was a bit more greivous: we weren't computing the proper error term at all! This fixed that function so that we emphasize the error metrics induced by *squaring* the error in each channel and then returning that as a measurement of the acceptability of using a single color compression for that partition. --- BPTCEncoder/src/BC7Compressor.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/BPTCEncoder/src/BC7Compressor.cpp b/BPTCEncoder/src/BC7Compressor.cpp index e6a0c2e..3fd1655 100755 --- a/BPTCEncoder/src/BC7Compressor.cpp +++ b/BPTCEncoder/src/BC7Compressor.cpp @@ -346,14 +346,14 @@ double BC7CompressionMode::CompressSingleColor(const RGBAVector &p, RGBAVector & const uint32 pixel = p.ToPixel(); - uint32 bestDist = 0xFF; + float bestError = FLT_MAX; bestPbitCombo = -1; for(int pbi = 0; pbi < GetNumPbitCombos(); pbi++) { const int *pbitCombo = GetPBitCombo(pbi); - uint32 dist = 0x0; + uint32 dist[4] = { 0x0, 0x0, 0x0, 0x0 }; uint32 bestValI[kNumColorChannels] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF }; uint32 bestValJ[kNumColorChannels] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF }; @@ -365,7 +365,7 @@ double BC7CompressionMode::CompressSingleColor(const RGBAVector &p, RGBAVector & // If we don't handle this channel, then it must be the full value (alpha) if(nBits == 0) { bestValI[ci] = bestValJ[ci] = 0xFF; - dist = std::max(dist, (uint32)((uint8)0xFF - val)); + dist[ci] = std::max(dist[ci], (uint32)((uint8)0xFF - val)); continue; } @@ -417,11 +417,18 @@ double BC7CompressionMode::CompressSingleColor(const RGBAVector &p, RGBAVector & } } - dist = std::max(bestChannelDist, dist); + dist[ci] = std::max(bestChannelDist, dist[ci]); } - if(dist < bestDist) { - bestDist = dist; + const float *errorWeights = BC7C::GetErrorMetric(); + float error = 0.0; + for(int i = 0; i < kNumColorChannels; i++) { + float e = float(dist[i]) * errorWeights[i]; + error += e * e; + } + + if(error < bestError) { + bestError = error; bestPbitCombo = pbi; for(uint32 ci = 0; ci < kNumColorChannels; ci++) { @@ -431,7 +438,7 @@ double BC7CompressionMode::CompressSingleColor(const RGBAVector &p, RGBAVector & } } - return bestDist; + return bestError; } // Fast random number generator. See more information at