Icon alpha channel

SDL_WM_SetIcon will derive ‘mask’ using the color key if SDL_SRCCOLORKEY is
set on the source surface and mask is NULL. I need to do conversion
on my source (making sure it’s 32x32), which leaves me with an alpha
channel surface, not a color keyed one, and SDL_WM_SetIcon doesn’t
support SDL_SRCALPHA.

The attached patch makes it set the mask based on the source alpha
channel if SDL_SRCALPHA is set; zero alpha values are transparent,
nonzero values are opaque.–
Glenn Maynard
-------------- next part --------------
— /home/glenn/SDL12/src/video/SDL_video.c 2002-10-05 12:50:56.000000000 -0400
+++ SDL_video.c 2002-11-17 01:41:52.000000000 -0500
@@ -125,6 +125,14 @@

SDL_VideoDevice *current_video = NULL;

+/* SM: Default refresh rate of 0 uses the default. */
+int refresh_rate = 0;
+
+void SDL_SM_SetRefreshRate(unsigned rate)
+{

  • refresh_rate = rate;
    +}

/* Various local functions */
int SDL_VideoInit(const char *driver_name, Uint32 flags);
void SDL_VideoQuit(void);
@@ -1640,8 +1648,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 +1676,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 +1692,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 +1717,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);

SDL_WM_SetIcon will derive ‘mask’ using the color key if SDL_SRCCOLORKEY is
set on the source surface and mask is NULL. I need to do conversion
on my source (making sure it’s 32x32), which leaves me with an alpha
channel surface, not a color keyed one, and SDL_WM_SetIcon doesn’t
support SDL_SRCALPHA.

The attached patch makes it set the mask based on the source alpha
channel if SDL_SRCALPHA is set; zero alpha values are transparent,
nonzero values are opaque.

Nice! I’ve added your patch to CVS.

Thanks!
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Are you sure this patch maintains ABI??? It didn’t look like it to
me…

-LorenOn Sun, 2002-11-17 at 09:56, Sam Lantinga wrote:

SDL_WM_SetIcon will derive ‘mask’ using the color key if SDL_SRCCOLORKEY is
set on the source surface and mask is NULL. I need to do conversion
on my source (making sure it’s 32x32), which leaves me with an alpha
channel surface, not a color keyed one, and SDL_WM_SetIcon doesn’t
support SDL_SRCALPHA.

The attached patch makes it set the mask based on the source alpha
channel if SDL_SRCALPHA is set; zero alpha values are transparent,
nonzero values are opaque.

Nice! I’ve added your patch to CVS.

Thanks!
-Sam Lantinga, Software Engineer, Blizzard Entertainment

It only changes a static function; how could that change the ABI?On Mon, Nov 18, 2002 at 02:20:55AM -0800, Loren Osborn wrote:

Are you sure this patch maintains ABI??? It didn’t look like it to
me…


Glenn Maynard

Nope… You’re right… I misread that it was changing the arguments
list of SDL_WM_SetIcon() itself… I guess I should refrain from
commenting on such things unless I’m awake enough to digest them
properly…

Nonetheless, I do think SDL_SM_SetRefreshRate() might be better off
being explicitly static for the same reason.

-Loren “Suffering From Foot-In-Mouth Disease” OsbornOn Mon, 2002-11-18 at 02:32, Glenn Maynard wrote:

On Mon, Nov 18, 2002 at 02:20:55AM -0800, Loren Osborn wrote:

Are you sure this patch maintains ABI??? It didn’t look like it to
me…

It only changes a static function; how could that change the ABI?

Huh. Oops. I didn’t mean to include that; that’s a separate hack I
added to let StepMania tell SDL which refresh rate to use (so it doesn’t
always use 60Hz). That’s what _SM means. The code that actually uses
this is elsewhere.

Luckily, Sam removed that.

(Actually, I’d expect that adding new functions to the ABI should be OK,
since it shouldn’t break backwards-compatibility–but it’s not needed
here.)On Mon, Nov 18, 2002 at 02:46:55AM -0800, Loren Osborn wrote:

Nope… You’re right… I misread that it was changing the arguments
list of SDL_WM_SetIcon() itself… I guess I should refrain from
commenting on such things unless I’m awake enough to digest them
properly…

Nonetheless, I do think SDL_SM_SetRefreshRate() might be better off
being explicitly static for the same reason.


Glenn Maynard