Icon refactor

This commit is contained in:
elasota
2021-06-06 01:12:21 -04:00
parent 2e9954677d
commit b616c6bf6e
19 changed files with 660 additions and 345 deletions

View File

@@ -44,8 +44,6 @@ namespace PortabilityLayer
{
public:
bool LoadColorIcon(const int16_t id, THandle<PixMapImpl> &outColorImage, THandle<PixMapImpl> &outBWImage, THandle<PixMapImpl> &outMaskImage) override;
THandle<PixMapImpl> LoadSimpleColorIcon(const THandle<void> &hdl) override;
THandle<PixMapImpl> LoadBWIcon(const THandle<void> &hdl) override;
static IconLoaderImpl *GetInstance();
@@ -317,87 +315,6 @@ namespace PortabilityLayer
return true;
}
THandle<PixMapImpl> IconLoaderImpl::LoadSimpleColorIcon(const THandle<void> &hdl)
{
if (hdl == nullptr || hdl.MMBlock()->m_size != 1024)
return THandle<PixMapImpl>();
const Rect rect = Rect::Create(0, 0, 32, 32);
GpPixelFormat_t pixelFormat = DisplayDeviceManager::GetInstance()->GetPixelFormat();
THandle<PixMapImpl> pixMap = PixMapImpl::Create(rect, pixelFormat);
if (!pixMap)
return THandle<PixMapImpl>();
const uint8_t *inData = static_cast<const uint8_t*>(*hdl);
uint8_t *outData = static_cast<uint8_t*>((*pixMap)->GetPixelData());
const size_t outPitch = (*pixMap)->GetPitch();
if (pixelFormat == GpPixelFormats::kRGB32)
{
const PortabilityLayer::RGBAColor *palette = StandardPalette::GetInstance()->GetColors();
for (size_t row = 0; row < 32; row++)
{
uint32_t *outU32 = reinterpret_cast<uint32_t*>(outData);
for (size_t col = 0; col < 32; col++)
outU32[col] = palette[inData[col]].AsUInt32();
inData += 32;
outData += outPitch;
}
}
else if (pixelFormat == GpPixelFormats::k8BitStandard)
{
for (size_t row = 0; row < 32; row++)
{
for (size_t col = 0; col < 32; col++)
outData[col] = inData[col];
inData += 32;
outData += outPitch;
}
}
else
{
PL_NotYetImplemented();
}
return pixMap;
}
THandle<PixMapImpl> IconLoaderImpl::LoadBWIcon(const THandle<void> &hdl)
{
if (hdl == nullptr || hdl.MMBlock()->m_size != 128)
return THandle<PixMapImpl>();
const Rect rect = Rect::Create(0, 0, 32, 32);
THandle<PixMapImpl> pixMap = PixMapImpl::Create(rect, GpPixelFormats::kBW1);
if (!pixMap)
return THandle<PixMapImpl>();
const uint8_t *inData = static_cast<const uint8_t*>(*hdl);
uint8_t *outData = static_cast<uint8_t*>((*pixMap)->GetPixelData());
const size_t outPitch = (*pixMap)->GetPitch();
for (size_t row = 0; row < 32; row++)
{
for (size_t col = 0; col < 32; col++)
{
if (inData[col / 8] & (0x80 >> (col & 7)))
outData[col] = 0xff;
else
outData[col] = 0x00;
}
inData += 4;
outData += outPitch;
}
return pixMap;
}
IconLoaderImpl *IconLoaderImpl::GetInstance()
{
return &ms_instance;