From 1db1974435a6c9dff4908fefb6fe4fd093fc431f Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 18 Mar 2007 22:16:51 +0000 Subject: Added man page by Patrick Matthäi and restored alpha layer check. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/resources/image.cpp | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/resources/image.cpp b/src/resources/image.cpp index fed26851..a7c81574 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -99,6 +99,28 @@ Image* Image::load(void *buffer, unsigned int bufferSize, amask = 0xff000000; #endif + bool hasAlpha = false; + + // Figure out whether the image uses its alpha layer + for (int i = 0; i < tmpImage->w * tmpImage->h; ++i) + { + Uint8 r, g, b, a; + SDL_GetRGBA( + ((Uint32*) tmpImage->pixels)[i], + tmpImage->format, + &r, &g, &b, &a); + + if (a != 255) + { + hasAlpha = true; + break; + } + } + + if (hasAlpha) { + SDL_SetAlpha(tmpImage, SDL_SRCALPHA, SDL_ALPHA_OPAQUE); + } + #ifdef USE_OPENGL if (mUseOpenGL) { @@ -186,10 +208,15 @@ Image* Image::load(void *buffer, unsigned int bufferSize, } #endif - SDL_SetAlpha(tmpImage, SDL_SRCALPHA, SDL_ALPHA_OPAQUE); - - SDL_Surface *image = SDL_DisplayFormatAlpha(tmpImage); + SDL_Surface *image; + // Convert the surface to the current display format + if (hasAlpha) { + image = SDL_DisplayFormatAlpha(tmpImage); + } + else { + image = SDL_DisplayFormat(tmpImage); + } SDL_FreeSurface(tmpImage); if (image == NULL) { -- cgit v1.2.3-70-g09d2