diff --git a/PortabilityLayer/AntiAliasTable.cpp b/PortabilityLayer/AntiAliasTable.cpp index 66fef53..c5e7e9a 100644 --- a/PortabilityLayer/AntiAliasTable.cpp +++ b/PortabilityLayer/AntiAliasTable.cpp @@ -90,15 +90,21 @@ namespace PortabilityLayer rgbScaleTree[i] = (rgbScaleLinear[i] + rgbScaleLinear[i + 1]) / 2; uint32_t toneScaleLinear[16]; + uint32_t grayScaleLinear[16]; for (unsigned int i = 0; i < 16; i++) { unsigned int upscaled = i * 17; toneScaleLinear[i] = upscaled * upscaled * (kDivisions - 1); + grayScaleLinear[i] = toneScaleLinear[i] * 3; } uint32_t toneScaleTree[15]; + uint32_t grayScaleTree[15]; for (unsigned int i = 0; i < 15; i++) + { toneScaleTree[i] = (toneScaleLinear[i] + toneScaleLinear[i + 1]) / 2; + grayScaleTree[i] = (grayScaleLinear[i] + grayScaleLinear[i + 1]) / 2; + } for (int i = 0; i < 3; i++) baseChLinear[i] = baseCh[i] * baseCh[i]; @@ -126,15 +132,18 @@ namespace PortabilityLayer unsigned int toneIndexes[3]; unsigned int rgbIndexes[3]; + unsigned int grayScaleIndex; for (int i = 0; i < 3; i++) { toneIndexes[i] = BinTreeQuantize(toneScaleTree, toneScaleLinear, newChLinear[i]); rgbIndexes[i] = BinTreeQuantize(rgbScaleTree, rgbScaleLinear, newChLinear[i]); } + grayScaleIndex = BinTreeQuantize(grayScaleTree, grayScaleLinear, newChLinear[0] + newChLinear[1] + newChLinear[2]); uint64_t toneZeroError[3]; uint64_t toneQuantizedError[3]; + uint64_t grayError = 0; uint64_t rgbError = 0; for (int i = 0; i < 3; i++) { @@ -144,15 +153,18 @@ namespace PortabilityLayer int32_t toneDelta = static_cast(toneScaleLinear[toneIndexes[i]]) - static_cast(newChLinear[i]); toneQuantizedError[i] = static_cast(static_cast(toneDelta) * static_cast(toneDelta)); - int32_t rgbDelta = static_cast(rgbScaleLinear[toneIndexes[i]]) - static_cast(newChLinear[i]); - rgbError += static_cast(static_cast(toneDelta) * static_cast(toneDelta)); + int32_t rgbDelta = static_cast(rgbScaleLinear[rgbIndexes[i]]) - static_cast(newChLinear[i]); + rgbError += static_cast(static_cast(rgbDelta) * static_cast(rgbDelta)); + + int32_t grayDelta = static_cast(toneScaleLinear[grayScaleIndex]) - static_cast(newChLinear[i]); + grayError += static_cast(static_cast(grayDelta) * static_cast(grayDelta)); } uint64_t possibleErrors[5]; possibleErrors[0] = toneQuantizedError[0] + toneZeroError[1] + toneZeroError[2]; possibleErrors[1] = toneZeroError[0] + toneQuantizedError[1] + toneZeroError[2]; possibleErrors[2] = toneZeroError[0] + toneZeroError[1] + toneQuantizedError[2]; - possibleErrors[3] = toneQuantizedError[0] + toneQuantizedError[1] + toneQuantizedError[2]; + possibleErrors[3] = grayError; possibleErrors[4] = rgbError; int bestErrorIndex = 0; @@ -170,7 +182,7 @@ namespace PortabilityLayer else if (bestErrorIndex == 2) bestColor = StandardPalette::GetInstance()->MapColorAnalyticTruncated(0, 0, toneIndexes[2]); else if (bestErrorIndex == 3) - bestColor = StandardPalette::GetInstance()->MapColorAnalyticTruncated(toneIndexes[0], toneIndexes[1], toneIndexes[2]); + bestColor = StandardPalette::GetInstance()->MapColorAnalyticTruncated(grayScaleIndex, grayScaleIndex, grayScaleIndex); else //if (bestErrorIndex == 4) bestColor = StandardPalette::GetInstance()->MapColorAnalyticTruncated(rgbIndexes[0] * 3, rgbIndexes[1] * 3, rgbIndexes[2] * 3); @@ -179,7 +191,6 @@ namespace PortabilityLayer } } -#if 0 void AntiAliasTable::GenerateForPalette(const RGBAColor &baseColorRef, const RGBAColor *colors, size_t numColors, bool cacheable) { char cacheFileName[256]; @@ -252,7 +263,6 @@ namespace PortabilityLayer if (cacheable) SaveToCache(cacheFileName); } -#endif void AntiAliasTable::GenerateForSimpleScale(uint8_t colorChannel, bool cacheable) { diff --git a/PortabilityLayer/AntiAliasTable.h b/PortabilityLayer/AntiAliasTable.h index ffde3f4..7ee582e 100644 --- a/PortabilityLayer/AntiAliasTable.h +++ b/PortabilityLayer/AntiAliasTable.h @@ -12,9 +12,7 @@ namespace PortabilityLayer // Striped 256x16 because constant background color is more likely than constant sample uint8_t m_aaTranslate[256][16]; -#if 0 void GenerateForPalette(const RGBAColor &baseColor, const RGBAColor *colors, size_t numColors, bool cacheable); -#endif void GenerateForPaletteFast(const RGBAColor &baseColor); void GenerateForSimpleScale(uint8_t colorChannel, bool cacheable); diff --git a/PortabilityLayer/QDStandardPalette.cpp b/PortabilityLayer/QDStandardPalette.cpp index 9add49e..8d25e7a 100644 --- a/PortabilityLayer/QDStandardPalette.cpp +++ b/PortabilityLayer/QDStandardPalette.cpp @@ -262,6 +262,7 @@ namespace PortabilityLayer if (mutex) mutex->Unlock(); + //entry.m_aaTable.GenerateForPalette(color, m_colors, 256, true); entry.m_aaTable.GenerateForPaletteFast(color); return entry.m_aaTable;