# HG changeset patch # User Sam Lantinga # Date 1037555745 0 # Node ID 796f2fe699be0320f0cfc843948d621fd3e1f25d # Parent 4bcfb93e0dfe86d4b982cf927f881f91d285397d Support 1-bit alpha on surfaces passed to SDL_WM_SetIcon() (thanks Glenn!) diff -r 4bcfb93e0dfe -r 796f2fe699be src/video/SDL_video.c --- a/src/video/SDL_video.c Sat Nov 09 06:20:46 2002 +0000 +++ b/src/video/SDL_video.c Sun Nov 17 17:55:45 2002 +0000 @@ -1640,8 +1640,9 @@ } } -/* Utility function used by SDL_WM_SetIcon() */ -static void CreateMaskFromColorKey(SDL_Surface *icon, Uint8 *mask) +/* Utility function used by SDL_WM_SetIcon(); + * flags & 1 for color key, flags & 2 for alpha channel. */ +static void CreateMaskFromColorKeyOrAlpha(SDL_Surface *icon, Uint8 *mask, int flags) { int x, y; Uint32 colorkey; @@ -1667,9 +1668,12 @@ pixels = (Uint16 *)icon->pixels + y*icon->pitch/2; for ( x=0; xw; ++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); } + pixels++; } } } @@ -1680,9 +1684,12 @@ pixels = (Uint32 *)icon->pixels + y*icon->pitch/4; for ( x=0; xw; ++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); } + pixels++; } } } @@ -1702,13 +1709,16 @@ /* Generate a mask if necessary, and create the icon! */ if ( mask == NULL ) { int mask_len = icon->h*(icon->w+7)/8; + int flags = 0; mask = (Uint8 *)malloc(mask_len); if ( mask == NULL ) { return; } memset(mask, ~0, mask_len); - if ( icon->flags & SDL_SRCCOLORKEY ) { - CreateMaskFromColorKey(icon, mask); + if ( icon->flags & SDL_SRCCOLORKEY ) flags |= 1; + if ( icon->flags & SDL_SRCALPHA ) flags |= 2; + if( flags ) { + CreateMaskFromColorKeyOrAlpha(icon, mask, flags); } video->SetIcon(video, icon, mask); free(mask);