SDL_SetAlpha Bug

i posted this back at the start of february, but between
other people and myself not being around, it never got
resolved. here it comes again :]-----------------------------------------------------------

I’ve got some simple code trying to do a ‘fade from white’ by
blitting an all white image with progressively lower alpha values.

the code as attached works fine, but if you change the starting
alpha level to 255 (instead of the current 254) you’ll find that
changing the alphas doesn’t have any effect.

in fact, it seems once any image has had it’s alpha set to 255
there is no way to set the alpha to any other value. the alpha
values inside the SDL_Surface are being updated correctly, but
the blit is still treating it as 255.

is this a bug on my end? a feature? or some brilliant display
of short-sightedness on my end :]

thanks guys

begin 666 alpha.c
M(VEN8VQU9&4B4T1,+F at B#0H-"@T*:6YT(&UA:6XH0T>PT*“6EN=”!A;’!H
M83L-"@E31$Q?4W5R9F%C92 J<V-R965N+" J9F%D97([#0H)4T1,7U)E8W0@
M:&%L9B ](‘LP+" P+" T,# L(#(P,‘T[#0H-"@E31$Q?26YI=“A31$Q?24Y)
M5%]6241%3WQ31$Q?24Y)5%]424U%4BD[#0H-@ES8W)E96X@/2!31$Q?4V5T
M5FED96]-;V1E*#0P,“P at -# P+” P+" P3L-"@EF861E<B ](%-$3%]#<F5A
M=&521T)3=7)F86-E
# L(#0P,“P at -# P+” S,BP@,‘AF9C P,# L(#!X9F8P
M,“P@,'AF9BP@,“D[#0H)4T1,7T9I;&Q296-T*&9A9&5R+”!.54Q,+” P>&9F
M9F9F9BD[#0H)4T1,7T9L:7 H<V-R965N3L-"@T#0H)9F]R*&%L<&AA(#T@
M,C4T.R!A;’!H82 ^/3 (&%L<&AA("T4T1,7T9I;&Q2
M96-T*’-C<F5E;BP at 3E5,3"P@,"D[#0H)"5-$3%]&:6QL4F5C="AS8W)E96XL
M(“9H86QF+” P>&9F3L-"@T"0E31$Q?4V5T06QP:&$H9F%D97(L(%-$3%]3
M4D-!3%!(02P at 86QP:&$I.PT*"0E31$Q?0FQI=%-U<F9A8V4H9F%D97(L($Y5
M3$PL(’-C<F5E;BP at 3E5,3"D[#0H-"@D)4T1,7T9L:7 H<V-R965N3L-"@D)
M4T1,7T1E;&%Y
#4P3L-"@E]#0H-"@E31$Q?1&5L87DH.# P3L-"@T*“5-$
M3%]&<F5E4W5R9F%C92AF861E<BD[#0H)4T1,7U%U:70H*3L-”@ER971U<FX@
%,3L-"GT
end

Pete Shinners wrote:

i posted this back at the start of february, but between
other people and myself not being around, it never got
resolved. here it comes again :]

I’ve got some simple code trying to do a ‘fade from white’ by
blitting an all white image with progressively lower alpha values.

the code as attached works fine, but if you change the starting
alpha level to 255 (instead of the current 254) you’ll find that
changing the alphas doesn’t have any effect.

in fact, it seems once any image has had it’s alpha set to 255
there is no way to set the alpha to any other value. the alpha
values inside the SDL_Surface are being updated correctly, but
the blit is still treating it as 255.

is this a bug on my end? a feature? or some brilliant display
of short-sightedness on my end :]

Nope.
I have exactly the same problem!

Alex

the code as attached works fine, but if you change the starting
alpha level to 255 (instead of the current 254) you’ll find that
changing the alphas doesn’t have any effect.

thanks, you’ve found a bug. The following patch fixes it for now.
Sam, please apply

(there’s still the problem of RLE:ed surfaces being un-encoded and then
re-encoded when switching between per-surface alpha of 255 and any other
value, but I’ll solve that later)

Index: SDL_surface.c===================================================================
RCS file: /cvs/SDL/src/video/SDL_surface.c,v
retrieving revision 1.8.2.30
diff -u -r1.8.2.30 SDL_surface.c
— SDL_surface.c 2001/02/10 07:20:05 1.8.2.30
+++ SDL_surface.c 2001/03/19 12:46:44
@@ -259,13 +259,16 @@
/*
* The representation for software surfaces is independent of
* per-surface alpha, so no need to invalidate the blit mapping

    • if just the alpha value was changed
    • if just the alpha value was changed. (If either is 255, we still
    • need to invalidate.)
      */
      if((surface->flags & SDL_HWACCEL) == SDL_HWACCEL
  •  || oldflags != surface->flags)
    
  •   SDL_InvalidateMap(surface->map);
    
  •  || oldflags != surface->flags
    
  •  || (((oldalpha + 1) ^ (value + 1)) & 0x100))
    
  •   SDL_InvalidateMap(surface->map);
    
    return(0);
    }

/*

  • A function to calculate the intersection of two rectangles:
  • return true if the rectangles intersect, false otherwise

thanks, you’ve found a bug. The following patch fixes it for now.
Sam, please apply

Hmm, it didn’t even compile. Can you build and test and resubmit? :slight_smile:

Thanks!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

Hmm, it didn’t even compile. Can you build and test and resubmit? :slight_smile:

oops, sorry. wrote it and tested on one machine, and copied over just
part of it to another :confused:

Index: SDL_surface.c===================================================================
RCS file: /cvs/SDL/src/video/SDL_surface.c,v
retrieving revision 1.8.2.31
diff -u -r1.8.2.31 SDL_surface.c
— SDL_surface.c 2001/03/19 17:39:06 1.8.2.31
+++ SDL_surface.c 2001/03/19 18:35:48
@@ -214,6 +214,7 @@
int SDL_SetAlpha (SDL_Surface *surface, Uint32 flag, Uint8 value)
{
Uint32 oldflags = surface->flags;

  • Uint32 oldalpha = surface->format->alpha;

    /* Sanity check the flag as it gets passed in */
    if ( flag & SDL_SRCALPHA ) {
    @@ -228,7 +229,7 @@

    /* Optimize away operations that don’t change anything */
    if ( (flag == (surface->flags & (SDL_SRCALPHA|SDL_RLEACCELOK))) &&

  •    (!flag || (value == surface->format->alpha)) ) {
    
  •    (!flag || value == oldalpha) ) {
      return(0);
    
    }

@@ -259,13 +260,16 @@
/*
* The representation for software surfaces is independent of
* per-surface alpha, so no need to invalidate the blit mapping

    • if just the alpha value was changed
    • if just the alpha value was changed. (If either is 255, we still
    • need to invalidate.)
      */
      if((surface->flags & SDL_HWACCEL) == SDL_HWACCEL
  •  || oldflags != surface->flags)
    
  •   SDL_InvalidateMap(surface->map);
    
  •  || oldflags != surface->flags
    
  •  || (((oldalpha + 1) ^ (value + 1)) & 0x100))
    
  •   SDL_InvalidateMap(surface->map);
    
    return(0);
    }

/*

  • A function to calculate the intersection of two rectangles:
  • return true if the rectangles intersect, false otherwise

Hmm, it didn’t even compile. Can you build and test and resubmit? :slight_smile:

oops, sorry. wrote it and tested on one machine, and copied over just
part of it to another :confused:

No worries. It’s in CVS now, thanks!

-Sam Lantinga, Lead Programmer, Loki Entertainment Software