SDL app icon transparency - fix #308

This commit is contained in:
Vadim Lopatin 2016-10-18 09:03:52 +03:00
parent 84040a277c
commit 691ba3411f
2 changed files with 18 additions and 2 deletions

View File

@ -1013,6 +1013,22 @@ class ColorDrawBuf : ColorDrawBufBase {
drawRescaled(Rect(0, 0, dx, dy), v, Rect(0, 0, v.width, v.height));
}
void invertAndPreMultiplyAlpha() {
foreach(ref pixel; _buf) {
uint a = (pixel >> 24) & 0xFF;
uint r = (pixel >> 16) & 0xFF;
uint g = (pixel >> 8) & 0xFF;
uint b = (pixel >> 0) & 0xFF;
a ^= 0xFF;
if (a > 0xFC) {
r = ((r * a) >> 8) & 0xFF;
g = ((g * a) >> 8) & 0xFF;
b = ((b * a) >> 8) & 0xFF;
}
pixel = (a << 24) | (r << 16) | (g << 8) | (b << 0);
}
}
void invertAlpha() {
foreach(ref pixel; _buf)
pixel ^= 0xFF000000;

View File

@ -287,9 +287,9 @@ class SDLWindow : Window {
int iconw = 32;
int iconh = 32;
ColorDrawBuf iconDraw = new ColorDrawBuf(iconw, iconh);
iconDraw.fill(0xE0E0E0);
iconDraw.fill(0xFF000000);
iconDraw.drawRescaled(Rect(0, 0, iconw, iconh), icon, Rect(0, 0, icon.width, icon.height));
iconDraw.invertAlpha();
iconDraw.invertAndPreMultiplyAlpha();
SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(iconDraw.scanLine(0), iconDraw.width, iconDraw.height, 32, iconDraw.width * 4, 0x00ff0000,0x0000ff00,0x000000ff,0xff000000);
if (surface) {
// The icon is attached to the window pointer