mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-12-14 12:09:36 +00:00
Add AA table caching
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
#include "AntiAliasTable.h"
|
||||
#include "RGBAColor.h"
|
||||
#include "HostFileSystem.h"
|
||||
#include "GpIOStream.h"
|
||||
#include "PLBigEndian.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <math.h>
|
||||
@@ -58,8 +61,49 @@ namespace PortabilityLayer
|
||||
}
|
||||
}
|
||||
#else
|
||||
void AntiAliasTable::GenerateForPalette(const RGBAColor &baseColorRef, const RGBAColor *colors, size_t numColors)
|
||||
bool AntiAliasTable::LoadFromCache(const char *cacheFileName)
|
||||
{
|
||||
GpIOStream *stream = PortabilityLayer::HostFileSystem::GetInstance()->OpenFile(PortabilityLayer::VirtualDirectories::kFontCache, cacheFileName, false, GpFileCreationDispositions::kOpenExisting);
|
||||
if (!stream)
|
||||
return false;
|
||||
|
||||
BEUInt32_t cacheVersion;
|
||||
if (stream->Read(&cacheVersion, sizeof(cacheVersion)) != sizeof(cacheVersion) || cacheVersion != kCacheVersion)
|
||||
{
|
||||
stream->Close();
|
||||
return false;
|
||||
}
|
||||
|
||||
const size_t readSize = sizeof(m_aaTranslate);
|
||||
const bool readOK = (stream->Read(m_aaTranslate, readSize) == readSize);
|
||||
stream->Close();
|
||||
|
||||
return readOK;
|
||||
}
|
||||
|
||||
void AntiAliasTable::SaveToCache(const char *cacheFileName)
|
||||
{
|
||||
GpIOStream *stream = PortabilityLayer::HostFileSystem::GetInstance()->OpenFile(PortabilityLayer::VirtualDirectories::kFontCache, cacheFileName, true, GpFileCreationDispositions::kCreateOrOverwrite);
|
||||
if (!stream)
|
||||
return;
|
||||
|
||||
BEUInt32_t cacheVersion(static_cast<uint32_t>(kCacheVersion));
|
||||
stream->Write(&cacheVersion, sizeof(cacheVersion));
|
||||
|
||||
stream->Write(m_aaTranslate, sizeof(m_aaTranslate));
|
||||
stream->Close();
|
||||
}
|
||||
|
||||
void AntiAliasTable::GenerateForPalette(const RGBAColor &baseColorRef, const RGBAColor *colors, size_t numColors, bool cacheable)
|
||||
{
|
||||
char cacheFileName[256];
|
||||
if (cacheable)
|
||||
{
|
||||
sprintf(cacheFileName, "aa_p_%02x%02x%02x%02x.cache", static_cast<int>(baseColorRef.r), static_cast<int>(baseColorRef.g), static_cast<int>(baseColorRef.b), static_cast<int>(baseColorRef.a));
|
||||
if (LoadFromCache(cacheFileName))
|
||||
return;
|
||||
}
|
||||
|
||||
const RGBAColor baseColor = baseColorRef;
|
||||
|
||||
if (numColors > 256)
|
||||
@@ -118,10 +162,21 @@ namespace PortabilityLayer
|
||||
m_aaTranslate[i][b] = static_cast<uint8_t>(bestColor);
|
||||
}
|
||||
}
|
||||
|
||||
if (cacheable)
|
||||
SaveToCache(cacheFileName);
|
||||
}
|
||||
|
||||
void AntiAliasTable::GenerateForSimpleScale(uint8_t colorChannel)
|
||||
void AntiAliasTable::GenerateForSimpleScale(uint8_t colorChannel, bool cacheable)
|
||||
{
|
||||
char cacheFileName[256];
|
||||
if (cacheable)
|
||||
{
|
||||
sprintf(cacheFileName, "aa_t_%02x.cache", static_cast<int>(colorChannel));
|
||||
if (LoadFromCache(cacheFileName))
|
||||
return;
|
||||
}
|
||||
|
||||
const double gamma = 1.8;
|
||||
const double rcpGamma = 1.0 / gamma;
|
||||
const double rcp255 = 1.0 / 255.0;
|
||||
@@ -142,6 +197,9 @@ namespace PortabilityLayer
|
||||
m_aaTranslate[baseColor][opacity] = static_cast<uint8_t>(floor(blendedColorGammaSpace * 255.0 + 0.5));
|
||||
}
|
||||
}
|
||||
|
||||
if (cacheable)
|
||||
SaveToCache(cacheFileName);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user