From 55c25d526f76c3e41e232d765721eb8ee722e908 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 22 Apr 2011 17:05:08 +0300 Subject: Improve speed in _SDLLoad function. --- src/resources/image.cpp | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/resources/image.cpp b/src/resources/image.cpp index ea32e6601..4b07556cf 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -549,16 +549,35 @@ Image *Image::_SDLload(SDL_Surface *tmpImage) } // Figure out whether the image uses its alpha layer - for (int i = 0; i < tmpImage->w * tmpImage->h; ++i) + if (tmpImage->format->palette == NULL) { - Uint8 r, g, b, a; - SDL_GetRGBA((static_cast(tmpImage->pixels))[i], - tmpImage->format, &r, &g, &b, &a); + const SDL_PixelFormat * const fmt = tmpImage->format; + for (int i = 0; i < tmpImage->w * tmpImage->h; ++ i) + { + Uint8 a; + if(fmt->Amask) + { + unsigned v = ((static_cast(tmpImage->pixels))[i] + & fmt->Amask) >> fmt->Ashift; + a = (v << fmt->Aloss) + (v >> (8 - (fmt->Aloss << 1))); + } + else + { + a = SDL_ALPHA_OPAQUE; + } - if (a != 255) - hasAlpha = true; + if (a != 255) + hasAlpha = true; - alphaChannel[i] = a; + alphaChannel[i] = a; + } + } + else + { + if (SDL_ALPHA_OPAQUE != 255) + hasAlpha = true; + for (int i = 0; i < tmpImage->w * tmpImage->h; ++ i) + alphaChannel[i] = SDL_ALPHA_OPAQUE; } SDL_Surface *image; -- cgit v1.2.3-60-g2f50