Commit a9c0bef8 authored by Sam Lantinga's avatar Sam Lantinga

Fixed SDL_DisplayFormatAlpha() on RGB surfaces with alpha

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40432
parent 86138853
...@@ -16,6 +16,7 @@ be found at the <A HREF="http://www.libsdl.org/"> main SDL page</A>. ...@@ -16,6 +16,7 @@ be found at the <A HREF="http://www.libsdl.org/"> main SDL page</A>.
Major changes since SDL 1.0.0: Major changes since SDL 1.0.0:
</H2> </H2>
<UL> <UL>
<LI> 1.2.5: Fixed SDL_DisplayFormatAlpha() on RGB surfaces with alpha
<LI> 1.2.5: Fixed setting OpenGL mode multiple times on Windows <LI> 1.2.5: Fixed setting OpenGL mode multiple times on Windows
<LI> 1.2.5: Added support for Qtopia on embedded systems (thanks David!) <LI> 1.2.5: Added support for Qtopia on embedded systems (thanks David!)
<LI> 1.2.4: Added initial support for Atari (thanks Patrice!) <LI> 1.2.4: Added initial support for Atari (thanks Patrice!)
......
...@@ -645,7 +645,7 @@ extern DECLSPEC SDL_Surface * SDLCALL SDL_ConvertSurface ...@@ -645,7 +645,7 @@ extern DECLSPEC SDL_Surface * SDLCALL SDL_ConvertSurface
* alpha-blend (using the source per-surface alpha value); * alpha-blend (using the source per-surface alpha value);
* set destination alpha to opaque. * set destination alpha to opaque.
* SDL_SRCALPHA not set: * SDL_SRCALPHA not set:
* copy RGB, set destination alpha to opaque. * copy RGB, set destination alpha to source per-surface alpha value.
* both: * both:
* if SDL_SRCCOLORKEY set, only copy the pixels matching the * if SDL_SRCCOLORKEY set, only copy the pixels matching the
* source colour key. * source colour key.
......
...@@ -1202,7 +1202,7 @@ static void BlitNtoN(SDL_BlitInfo *info) ...@@ -1202,7 +1202,7 @@ static void BlitNtoN(SDL_BlitInfo *info)
int srcbpp = srcfmt->BytesPerPixel; int srcbpp = srcfmt->BytesPerPixel;
SDL_PixelFormat *dstfmt = info->dst; SDL_PixelFormat *dstfmt = info->dst;
int dstbpp = dstfmt->BytesPerPixel; int dstbpp = dstfmt->BytesPerPixel;
unsigned alpha = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0; unsigned alpha = dstfmt->Amask ? srcfmt->alpha : 0;
while ( height-- ) { while ( height-- ) {
DUFFS_LOOP( DUFFS_LOOP(
...@@ -1358,7 +1358,7 @@ static void BlitNtoNKey(SDL_BlitInfo *info) ...@@ -1358,7 +1358,7 @@ static void BlitNtoNKey(SDL_BlitInfo *info)
SDL_PixelFormat *dstfmt = info->dst; SDL_PixelFormat *dstfmt = info->dst;
int srcbpp = srcfmt->BytesPerPixel; int srcbpp = srcfmt->BytesPerPixel;
int dstbpp = dstfmt->BytesPerPixel; int dstbpp = dstfmt->BytesPerPixel;
unsigned alpha = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0; unsigned alpha = dstfmt->Amask ? srcfmt->alpha : 0;
while ( height-- ) { while ( height-- ) {
DUFFS_LOOP( DUFFS_LOOP(
......
...@@ -211,6 +211,7 @@ int SDL_SetColorKey (SDL_Surface *surface, Uint32 flag, Uint32 key) ...@@ -211,6 +211,7 @@ int SDL_SetColorKey (SDL_Surface *surface, Uint32 flag, Uint32 key)
SDL_InvalidateMap(surface->map); SDL_InvalidateMap(surface->map);
return(0); return(0);
} }
/* This function sets the alpha channel of a surface */
int SDL_SetAlpha (SDL_Surface *surface, Uint32 flag, Uint8 value) int SDL_SetAlpha (SDL_Surface *surface, Uint32 flag, Uint8 value)
{ {
Uint32 oldflags = surface->flags; Uint32 oldflags = surface->flags;
...@@ -269,6 +270,52 @@ int SDL_SetAlpha (SDL_Surface *surface, Uint32 flag, Uint8 value) ...@@ -269,6 +270,52 @@ int SDL_SetAlpha (SDL_Surface *surface, Uint32 flag, Uint8 value)
SDL_InvalidateMap(surface->map); SDL_InvalidateMap(surface->map);
return(0); return(0);
} }
int SDL_SetAlphaChannel(SDL_Surface *surface, Uint8 value)
{
int row, col;
int offset;
Uint8 *buf;
if ( (surface->format->Amask != 0xFF000000) &&
(surface->format->Amask != 0x000000FF) ) {
SDL_SetError("Unsupported surface alpha mask format");
return -1;
}
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
if ( surface->format->Amask == 0xFF000000 ) {
offset = 3;
} else {
offset = 0;
}
#else
if ( surface->format->Amask == 0xFF000000 ) {
offset = 0;
} else {
offset = 3;
}
#endif /* Byte ordering */
/* Quickly set the alpha channel of an RGBA or ARGB surface */
if ( SDL_MUSTLOCK(surface) ) {
if ( SDL_LockSurface(surface) < 0 ) {
return -1;
}
}
row = surface->h;
while (row--) {
col = surface->w;
buf = (Uint8 *)surface->pixels + row * surface->pitch + offset;
while(col--) {
*buf = value;
buf += 4;
}
}
if ( SDL_MUSTLOCK(surface) ) {
SDL_UnlockSurface(surface);
}
return 0;
}
/* /*
* A function to calculate the intersection of two rectangles: * A function to calculate the intersection of two rectangles:
...@@ -748,8 +795,13 @@ SDL_Surface * SDL_ConvertSurface (SDL_Surface *surface, ...@@ -748,8 +795,13 @@ SDL_Surface * SDL_ConvertSurface (SDL_Surface *surface,
} }
} }
if ( (surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) { if ( (surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
alpha = surface->format->alpha; /* Copy over the alpha channel to RGBA if requested */
SDL_SetAlpha(surface, 0, 0); if ( format->Amask ) {
surface->flags &= ~SDL_SRCALPHA;
} else {
alpha = surface->format->alpha;
SDL_SetAlpha(surface, 0, 0);
}
} }
/* Copy over the image data */ /* Copy over the image data */
...@@ -780,7 +832,11 @@ SDL_Surface * SDL_ConvertSurface (SDL_Surface *surface, ...@@ -780,7 +832,11 @@ SDL_Surface * SDL_ConvertSurface (SDL_Surface *surface,
SDL_SetAlpha(convert, aflags|(flags&SDL_RLEACCELOK), SDL_SetAlpha(convert, aflags|(flags&SDL_RLEACCELOK),
alpha); alpha);
} }
SDL_SetAlpha(surface, aflags, alpha); if ( format->Amask ) {
surface->flags |= SDL_SRCALPHA;
} else {
SDL_SetAlpha(surface, aflags, alpha);
}
} }
/* We're ready to go! */ /* We're ready to go! */
......
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