Commit 41352931 authored by Sam Lantinga's avatar Sam Lantinga

Support 1-bit alpha on surfaces passed to SDL_WM_SetIcon() (thanks Glenn!)

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40542
parent bb1c6662
...@@ -1640,8 +1640,9 @@ void SDL_WM_GetCaption (char **title, char **icon) ...@@ -1640,8 +1640,9 @@ void SDL_WM_GetCaption (char **title, char **icon)
} }
} }
/* Utility function used by SDL_WM_SetIcon() */ /* Utility function used by SDL_WM_SetIcon();
static void CreateMaskFromColorKey(SDL_Surface *icon, Uint8 *mask) * flags & 1 for color key, flags & 2 for alpha channel. */
static void CreateMaskFromColorKeyOrAlpha(SDL_Surface *icon, Uint8 *mask, int flags)
{ {
int x, y; int x, y;
Uint32 colorkey; Uint32 colorkey;
...@@ -1667,9 +1668,12 @@ static void CreateMaskFromColorKey(SDL_Surface *icon, Uint8 *mask) ...@@ -1667,9 +1668,12 @@ static void CreateMaskFromColorKey(SDL_Surface *icon, Uint8 *mask)
pixels = (Uint16 *)icon->pixels + pixels = (Uint16 *)icon->pixels +
y*icon->pitch/2; y*icon->pitch/2;
for ( x=0; x<icon->w; ++x ) { for ( x=0; x<icon->w; ++x ) {
if ( *pixels++ == colorkey ) { if ( (flags & 1) && *pixels == colorkey ) {
SET_MASKBIT(icon, x, y, mask);
} else if((flags & 2) && (*pixels & icon->format->Amask) == 0) {
SET_MASKBIT(icon, x, y, mask); SET_MASKBIT(icon, x, y, mask);
} }
pixels++;
} }
} }
} }
...@@ -1680,9 +1684,12 @@ static void CreateMaskFromColorKey(SDL_Surface *icon, Uint8 *mask) ...@@ -1680,9 +1684,12 @@ static void CreateMaskFromColorKey(SDL_Surface *icon, Uint8 *mask)
pixels = (Uint32 *)icon->pixels + pixels = (Uint32 *)icon->pixels +
y*icon->pitch/4; y*icon->pitch/4;
for ( x=0; x<icon->w; ++x ) { for ( x=0; x<icon->w; ++x ) {
if ( *pixels++ == colorkey ) { if ( (flags & 1) && *pixels == colorkey ) {
SET_MASKBIT(icon, x, y, mask);
} else if((flags & 2) && (*pixels & icon->format->Amask) == 0) {
SET_MASKBIT(icon, x, y, mask); SET_MASKBIT(icon, x, y, mask);
} }
pixels++;
} }
} }
} }
...@@ -1702,13 +1709,16 @@ void SDL_WM_SetIcon (SDL_Surface *icon, Uint8 *mask) ...@@ -1702,13 +1709,16 @@ void SDL_WM_SetIcon (SDL_Surface *icon, Uint8 *mask)
/* Generate a mask if necessary, and create the icon! */ /* Generate a mask if necessary, and create the icon! */
if ( mask == NULL ) { if ( mask == NULL ) {
int mask_len = icon->h*(icon->w+7)/8; int mask_len = icon->h*(icon->w+7)/8;
int flags = 0;
mask = (Uint8 *)malloc(mask_len); mask = (Uint8 *)malloc(mask_len);
if ( mask == NULL ) { if ( mask == NULL ) {
return; return;
} }
memset(mask, ~0, mask_len); memset(mask, ~0, mask_len);
if ( icon->flags & SDL_SRCCOLORKEY ) { if ( icon->flags & SDL_SRCCOLORKEY ) flags |= 1;
CreateMaskFromColorKey(icon, mask); if ( icon->flags & SDL_SRCALPHA ) flags |= 2;
if( flags ) {
CreateMaskFromColorKeyOrAlpha(icon, mask, flags);
} }
video->SetIcon(video, icon, mask); video->SetIcon(video, icon, mask);
free(mask); free(mask);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment