From cdde70c9b698ed052d4a533742ea9894191694dd Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 3 Apr 2009 13:27:33 +0000 Subject: [PATCH] Added SDL_GetColorKey() --- include/SDL_surface.h | 13 +++++++++++++ src/video/SDL_surface.c | 17 +++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/SDL_surface.h b/include/SDL_surface.h index 3a4abba93..304482911 100644 --- a/include/SDL_surface.h +++ b/include/SDL_surface.h @@ -199,6 +199,19 @@ extern DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface * surface, extern DECLSPEC int SDLCALL SDL_SetColorKey(SDL_Surface * surface, Uint32 flag, Uint32 key); +/* + * \fn int SDL_GetColorKey(SDL_Surface *surface, Uint32 *key) + * + * \brief Sets the color key (transparent pixel) in a blittable surface. + * + * \param surface The surface to update + * \param key A pointer filled in with the transparent pixel in the native surface format + * + * \return 0 on success, or -1 if the surface is not valid or colorkey is not enabled. + */ +extern DECLSPEC int SDLCALL SDL_GetColorKey(SDL_Surface * surface, + Uint32 * key); + /** * \fn int SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b) * diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index ee642dc97..02b2c6993 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -272,6 +272,23 @@ SDL_SetColorKey(SDL_Surface * surface, Uint32 flag, Uint32 key) return 0; } +int +SDL_GetColorKey(SDL_Surface * surface, Uint32 * key) +{ + if (!surface) { + return -1; + } + + if (!(surface->map->info.flags & SDL_COPY_COLORKEY)) { + return -1; + } + + if (key) { + *key = surface->map->info.colorkey; + } + return 0; +} + /* This is a fairly slow function to switch from colorkey to alpha */ static void SDL_ConvertColorkeyToAlpha(SDL_Surface * surface)