diff --git a/BPTCEncoder/src/BC7Compressor.cpp b/BPTCEncoder/src/BC7Compressor.cpp index e39d5eb..0a8de51 100755 --- a/BPTCEncoder/src/BC7Compressor.cpp +++ b/BPTCEncoder/src/BC7Compressor.cpp @@ -66,23 +66,23 @@ static const char *kBlockStatString[kNumBlockStats] = { "BlockStat_Path", "BlockStat_Mode", - "eBlockStat_ModeZeroEstimate", - "eBlockStat_ModeOneEstimate", - "eBlockStat_ModeTwoEstimate", - "eBlockStat_ModeThreeEstimate", - "eBlockStat_ModeFourEstimate", - "eBlockStat_ModeFiveEstimate", - "eBlockStat_ModeSixEstimate", - "eBlockStat_ModeSevenEstimate", + "BlockStat_ModeZeroEstimate", + "BlockStat_ModeOneEstimate", + "BlockStat_ModeTwoEstimate", + "BlockStat_ModeThreeEstimate", + "BlockStat_ModeFourEstimate", + "BlockStat_ModeFiveEstimate", + "BlockStat_ModeSixEstimate", + "BlockStat_ModeSevenEstimate", - "eBlockStat_ModeZeroError", - "eBlockStat_ModeOneError", - "eBlockStat_ModeTwoError", - "eBlockStat_ModeThreeError", - "eBlockStat_ModeFourError", - "eBlockStat_ModeFiveError", - "eBlockStat_ModeSixError", - "eBlockStat_ModeSevenError", + "BlockStat_ModeZeroError", + "BlockStat_ModeOneError", + "BlockStat_ModeTwoError", + "BlockStat_ModeThreeError", + "BlockStat_ModeFourError", + "BlockStat_ModeFiveError", + "BlockStat_ModeSixError", + "BlockStat_ModeSevenError", }; static const uint32 kNumShapes2 = 64; @@ -1614,8 +1614,15 @@ namespace BC7C BC7CompressionMode compressor0(0, opaque); BC7CompressionMode compressor2(2, opaque); - double error, bestError = (shapeIdx < 16)? compressor0.Compress(tmpStream0, shapeIdx, clusters) : DBL_MAX; - gModeError[0] = bestError; + double error, bestError; + if(shapeIdx < 16) { + bestError = compressor0.Compress(tmpStream0, shapeIdx, clusters); + gModeError[0] = bestError; + } + else { + bestError = DBL_MAX; + gModeError[0] = -1.0; + } gModeChosen = 0; memcpy(outBuf, tempBuf0, 16); if(bestError == 0.0) { @@ -1680,11 +1687,18 @@ namespace BC7C } const float *w = BC7C::GetErrorMetric(); + const double err1 = 0.0001 + c.QuantizedError(Min, Max, 8, 0xFFFCFCFC, RGBAVector(w[0], w[1], w[2], w[3])); - gModeEstimate[1] = min(gModeEstimate[1], err1); + if(err1 >= 0.0) + gModeEstimate[1] = err1; + else + gModeEstimate[1] = min(gModeEstimate[1], err1); const double err3 = 0.0001 + c.QuantizedError(Min, Max, 8, 0xFFFEFEFE, RGBAVector(w[0], w[1], w[2], w[3])); - gModeEstimate[3] = min(gModeEstimate[3], err3); + if(err3 >= 0.0) + gModeEstimate[3] = err3; + else + gModeEstimate[3] = min(gModeEstimate[3], err3); return min(err1, err3); } @@ -1700,10 +1714,16 @@ namespace BC7C const float *w = BC7C::GetErrorMetric(); const double err0 = 0.0001 + c.QuantizedError(Min, Max, 4, 0xFFF0F0F0, RGBAVector(w[0], w[1], w[2], w[3])); - gModeEstimate[0] = min(gModeEstimate[0], err0); + if(err0 >= 0.0) + gModeEstimate[0] = err0; + else + gModeEstimate[0] = min(gModeEstimate[0], err0); const double err2 = 0.0001 + c.QuantizedError(Min, Max, 4, 0xFFF8F8F8, RGBAVector(w[0], w[1], w[2], w[3])); - gModeEstimate[2] = min(gModeEstimate[2], err2); + if(err2 >= 0.0) + gModeEstimate[2] = err2; + else + gModeEstimate[2] = min(gModeEstimate[2], err2); return min(err0, err2); } @@ -1740,7 +1760,7 @@ namespace BC7C // reset global variables... gBestMode = 0; for(int i = 0; i < BC7CompressionMode::kNumModes; i++){ - gModeError[i] = gModeEstimate[i] = DBL_MAX; + gModeError[i] = gModeEstimate[i] = -1.0; } blockIdx = statManager->BeginBlock(); @@ -1833,9 +1853,6 @@ namespace BC7C if(statManager) { BlockStat s = BlockStat(kBlockStatString[eBlockStat_Path], 2); statManager->AddStat(blockIdx, s); - - s = BlockStat(kBlockStatString[eBlockStat_Mode], gBestMode); - statManager->AddStat(blockIdx, s); } return; } diff --git a/Core/include/BlockStats.h b/Core/include/BlockStats.h index 47c6af3..bc04219 100644 --- a/Core/include/BlockStats.h +++ b/Core/include/BlockStats.h @@ -15,6 +15,13 @@ public: BlockStat &operator=(const BlockStat &); private: + const enum Type { + eType_Float, + eType_Int, + + kNumTypes + } m_Type; + static const int kStatNameSz = 32; CHAR m_StatName[kStatNameSz]; union { diff --git a/Core/src/BlockStats.cpp b/Core/src/BlockStats.cpp index bda3d79..a33077d 100644 --- a/Core/src/BlockStats.cpp +++ b/Core/src/BlockStats.cpp @@ -18,17 +18,21 @@ static T max(const T &a, const T &b) { // //////////////////////////////////////////////////////////////////////////////// -BlockStat::BlockStat(const CHAR *statName, int stat) : m_IntStat(stat) +BlockStat::BlockStat(const CHAR *statName, int stat) + : m_IntStat(stat) + , m_Type(eType_Int) { strncpy(m_StatName, statName, kStatNameSz); } -BlockStat::BlockStat(const CHAR *statName, double stat) : m_FloatStat(stat) +BlockStat::BlockStat(const CHAR *statName, double stat) + : m_FloatStat(stat) + , m_Type(eType_Float) { strncpy(m_StatName, statName, kStatNameSz); } -BlockStat::BlockStat(const BlockStat &other) { +BlockStat::BlockStat(const BlockStat &other) : m_Type(other.m_Type) { memcpy(this, &other, sizeof(*this)); } @@ -133,12 +137,24 @@ void BlockStatManager::ToFile(const CHAR *filename) { BlockStat s = head->GetStat(); CHAR statStr[256]; - snprintf(statStr, 256, "%d: %s, %llu, %f\n", i, s.m_StatName, s.m_IntStat, s.m_FloatStat); - + switch(s.m_Type) { + case BlockStat::eType_Float: + snprintf(statStr, 256, "%d,%s,%f\n", i, s.m_StatName, s.m_FloatStat); + break; + + case BlockStat::eType_Int: + snprintf(statStr, 256, "%d,%s,%llu\n", i, s.m_StatName, s.m_IntStat); + break; + + default: + assert(false); + break; + } + int statStrLen = strlen(statStr); if(statStrLen > 255) { statStr[255] = '\n'; - statStrLen = 255; + statStrLen = 256; } fstr.Write((uint8 *)statStr, statStrLen);