mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-12-14 12:09:36 +00:00
Fix incorrect fast AA calculations
This commit is contained in:
@@ -90,15 +90,21 @@ namespace PortabilityLayer
|
|||||||
rgbScaleTree[i] = (rgbScaleLinear[i] + rgbScaleLinear[i + 1]) / 2;
|
rgbScaleTree[i] = (rgbScaleLinear[i] + rgbScaleLinear[i + 1]) / 2;
|
||||||
|
|
||||||
uint32_t toneScaleLinear[16];
|
uint32_t toneScaleLinear[16];
|
||||||
|
uint32_t grayScaleLinear[16];
|
||||||
for (unsigned int i = 0; i < 16; i++)
|
for (unsigned int i = 0; i < 16; i++)
|
||||||
{
|
{
|
||||||
unsigned int upscaled = i * 17;
|
unsigned int upscaled = i * 17;
|
||||||
toneScaleLinear[i] = upscaled * upscaled * (kDivisions - 1);
|
toneScaleLinear[i] = upscaled * upscaled * (kDivisions - 1);
|
||||||
|
grayScaleLinear[i] = toneScaleLinear[i] * 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t toneScaleTree[15];
|
uint32_t toneScaleTree[15];
|
||||||
|
uint32_t grayScaleTree[15];
|
||||||
for (unsigned int i = 0; i < 15; i++)
|
for (unsigned int i = 0; i < 15; i++)
|
||||||
|
{
|
||||||
toneScaleTree[i] = (toneScaleLinear[i] + toneScaleLinear[i + 1]) / 2;
|
toneScaleTree[i] = (toneScaleLinear[i] + toneScaleLinear[i + 1]) / 2;
|
||||||
|
grayScaleTree[i] = (grayScaleLinear[i] + grayScaleLinear[i + 1]) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
baseChLinear[i] = baseCh[i] * baseCh[i];
|
baseChLinear[i] = baseCh[i] * baseCh[i];
|
||||||
@@ -126,15 +132,18 @@ namespace PortabilityLayer
|
|||||||
|
|
||||||
unsigned int toneIndexes[3];
|
unsigned int toneIndexes[3];
|
||||||
unsigned int rgbIndexes[3];
|
unsigned int rgbIndexes[3];
|
||||||
|
unsigned int grayScaleIndex;
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
toneIndexes[i] = BinTreeQuantize(toneScaleTree, toneScaleLinear, newChLinear[i]);
|
toneIndexes[i] = BinTreeQuantize(toneScaleTree, toneScaleLinear, newChLinear[i]);
|
||||||
rgbIndexes[i] = BinTreeQuantize(rgbScaleTree, rgbScaleLinear, 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 toneZeroError[3];
|
||||||
uint64_t toneQuantizedError[3];
|
uint64_t toneQuantizedError[3];
|
||||||
|
uint64_t grayError = 0;
|
||||||
uint64_t rgbError = 0;
|
uint64_t rgbError = 0;
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
@@ -144,15 +153,18 @@ namespace PortabilityLayer
|
|||||||
int32_t toneDelta = static_cast<int32_t>(toneScaleLinear[toneIndexes[i]]) - static_cast<int32_t>(newChLinear[i]);
|
int32_t toneDelta = static_cast<int32_t>(toneScaleLinear[toneIndexes[i]]) - static_cast<int32_t>(newChLinear[i]);
|
||||||
toneQuantizedError[i] = static_cast<uint64_t>(static_cast<int64_t>(toneDelta) * static_cast<int64_t>(toneDelta));
|
toneQuantizedError[i] = static_cast<uint64_t>(static_cast<int64_t>(toneDelta) * static_cast<int64_t>(toneDelta));
|
||||||
|
|
||||||
int32_t rgbDelta = static_cast<int32_t>(rgbScaleLinear[toneIndexes[i]]) - static_cast<int32_t>(newChLinear[i]);
|
int32_t rgbDelta = static_cast<int32_t>(rgbScaleLinear[rgbIndexes[i]]) - static_cast<int32_t>(newChLinear[i]);
|
||||||
rgbError += static_cast<uint64_t>(static_cast<int64_t>(toneDelta) * static_cast<int64_t>(toneDelta));
|
rgbError += static_cast<uint64_t>(static_cast<int64_t>(rgbDelta) * static_cast<int64_t>(rgbDelta));
|
||||||
|
|
||||||
|
int32_t grayDelta = static_cast<int32_t>(toneScaleLinear[grayScaleIndex]) - static_cast<int32_t>(newChLinear[i]);
|
||||||
|
grayError += static_cast<uint64_t>(static_cast<int64_t>(grayDelta) * static_cast<int64_t>(grayDelta));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t possibleErrors[5];
|
uint64_t possibleErrors[5];
|
||||||
possibleErrors[0] = toneQuantizedError[0] + toneZeroError[1] + toneZeroError[2];
|
possibleErrors[0] = toneQuantizedError[0] + toneZeroError[1] + toneZeroError[2];
|
||||||
possibleErrors[1] = toneZeroError[0] + toneQuantizedError[1] + toneZeroError[2];
|
possibleErrors[1] = toneZeroError[0] + toneQuantizedError[1] + toneZeroError[2];
|
||||||
possibleErrors[2] = toneZeroError[0] + toneZeroError[1] + toneQuantizedError[2];
|
possibleErrors[2] = toneZeroError[0] + toneZeroError[1] + toneQuantizedError[2];
|
||||||
possibleErrors[3] = toneQuantizedError[0] + toneQuantizedError[1] + toneQuantizedError[2];
|
possibleErrors[3] = grayError;
|
||||||
possibleErrors[4] = rgbError;
|
possibleErrors[4] = rgbError;
|
||||||
|
|
||||||
int bestErrorIndex = 0;
|
int bestErrorIndex = 0;
|
||||||
@@ -170,7 +182,7 @@ namespace PortabilityLayer
|
|||||||
else if (bestErrorIndex == 2)
|
else if (bestErrorIndex == 2)
|
||||||
bestColor = StandardPalette::GetInstance()->MapColorAnalyticTruncated(0, 0, toneIndexes[2]);
|
bestColor = StandardPalette::GetInstance()->MapColorAnalyticTruncated(0, 0, toneIndexes[2]);
|
||||||
else if (bestErrorIndex == 3)
|
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)
|
else //if (bestErrorIndex == 4)
|
||||||
bestColor = StandardPalette::GetInstance()->MapColorAnalyticTruncated(rgbIndexes[0] * 3, rgbIndexes[1] * 3, rgbIndexes[2] * 3);
|
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)
|
void AntiAliasTable::GenerateForPalette(const RGBAColor &baseColorRef, const RGBAColor *colors, size_t numColors, bool cacheable)
|
||||||
{
|
{
|
||||||
char cacheFileName[256];
|
char cacheFileName[256];
|
||||||
@@ -252,7 +263,6 @@ namespace PortabilityLayer
|
|||||||
if (cacheable)
|
if (cacheable)
|
||||||
SaveToCache(cacheFileName);
|
SaveToCache(cacheFileName);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void AntiAliasTable::GenerateForSimpleScale(uint8_t colorChannel, bool cacheable)
|
void AntiAliasTable::GenerateForSimpleScale(uint8_t colorChannel, bool cacheable)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,9 +12,7 @@ namespace PortabilityLayer
|
|||||||
// Striped 256x16 because constant background color is more likely than constant sample
|
// Striped 256x16 because constant background color is more likely than constant sample
|
||||||
uint8_t m_aaTranslate[256][16];
|
uint8_t m_aaTranslate[256][16];
|
||||||
|
|
||||||
#if 0
|
|
||||||
void GenerateForPalette(const RGBAColor &baseColor, const RGBAColor *colors, size_t numColors, bool cacheable);
|
void GenerateForPalette(const RGBAColor &baseColor, const RGBAColor *colors, size_t numColors, bool cacheable);
|
||||||
#endif
|
|
||||||
void GenerateForPaletteFast(const RGBAColor &baseColor);
|
void GenerateForPaletteFast(const RGBAColor &baseColor);
|
||||||
void GenerateForSimpleScale(uint8_t colorChannel, bool cacheable);
|
void GenerateForSimpleScale(uint8_t colorChannel, bool cacheable);
|
||||||
|
|
||||||
|
|||||||
@@ -262,6 +262,7 @@ namespace PortabilityLayer
|
|||||||
if (mutex)
|
if (mutex)
|
||||||
mutex->Unlock();
|
mutex->Unlock();
|
||||||
|
|
||||||
|
//entry.m_aaTable.GenerateForPalette(color, m_colors, 256, true);
|
||||||
entry.m_aaTable.GenerateForPaletteFast(color);
|
entry.m_aaTable.GenerateForPaletteFast(color);
|
||||||
|
|
||||||
return entry.m_aaTable;
|
return entry.m_aaTable;
|
||||||
|
|||||||
Reference in New Issue
Block a user