From 8fdc27efb01089180b7cda9a54eeb69f6a3b960e Mon Sep 17 00:00:00 2001 From: Iliyas Jorio Date: Thu, 19 Nov 2020 09:02:27 +0100 Subject: [PATCH] icl8: get mask from matching ICN# resource --- src/Graphics/Graphics.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Graphics/Graphics.cpp b/src/Graphics/Graphics.cpp index ecb8d13..0efeaab 100644 --- a/src/Graphics/Graphics.cpp +++ b/src/Graphics/Graphics.cpp @@ -650,12 +650,22 @@ void DrawChar(char c) void Pomme::Graphics::SetWindowIconFromIcl8Resource(short icl8ID) { - Handle macIcon = GetResource('icl8', icl8ID); - if (1024 != GetHandleSize(macIcon)) + Handle colorIcon = GetResource('icl8', icl8ID); + if (1024 != GetHandleSize(colorIcon)) { + DisposeHandle(colorIcon); throw std::invalid_argument("icl8 resource has incorrect size"); } + Handle bwIcon = GetResource('ICN#', icl8ID); + if (256 != GetHandleSize(bwIcon)) + { + DisposeHandle(bwIcon); + throw std::invalid_argument("ICN# resource has incorrect size"); + } + uint32_t* maskScanlines = (uint32_t*)(*bwIcon + 128); // mask starts 128 bytes into ICN# resource + ByteswapInts(4, 32, maskScanlines); + const int width = 32; const int height = 32; @@ -665,11 +675,18 @@ void Pomme::Graphics::SetWindowIconFromIcl8Resource(short icl8ID) uint32_t* out = (uint32_t*) ((char*) icon->pixels + icon->pitch * y); for (int x = 0; x < width; x++) { - unsigned char pixel = (*macIcon)[y * width + x]; - *out++ = pixel == 0 ? 0 : Pomme::Graphics::clut8[pixel]; + uint8_t paletteEntry = (*colorIcon)[y * width + x]; + uint32_t argb = Pomme::Graphics::clut8[paletteEntry]; + bool masked = maskScanlines[y] & (1 << (width - 1 - x)); + if (!masked) + { + argb &= 0x00FFFFFF; + } + *out++ = argb; } } SDL_SetWindowIcon(gSDLWindow, icon); SDL_FreeSurface(icon); - DisposeHandle(macIcon); + DisposeHandle(colorIcon); + DisposeHandle(bwIcon); }