changeset 541:796f2fe699be

Support 1-bit alpha on surfaces passed to SDL_WM_SetIcon() (thanks Glenn!)
author Sam Lantinga <slouken@libsdl.org>
date Sun, 17 Nov 2002 17:55:45 +0000
parents 4bcfb93e0dfe
children 7a15ee64acc7
files src/video/SDL_video.c
diffstat 1 files changed, 16 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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; 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);
 					}
+					pixels++;
 				}
 			}
 		}
@@ -1680,9 +1684,12 @@
 				pixels = (Uint32 *)icon->pixels +
 				                   y*icon->pitch/4;
 				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);
 					}
+					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);