From bff595c13f2e6bc98857d6f5d02ec79eefb751cc Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 10 Jun 2011 01:08:32 +0300 Subject: Improve image loading speed in Software mode. --- src/resources/image.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/resources/image.cpp b/src/resources/image.cpp index 4a89ae636..e9260071f 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -555,35 +555,38 @@ Image *Image::_SDLload(SDL_Surface *tmpImage) converted = true; } + const int sz = tmpImage->w * tmpImage->h; // Figure out whether the image uses its alpha layer if (tmpImage->format->palette == NULL) { const SDL_PixelFormat * const fmt = tmpImage->format; - for (int i = 0; i < tmpImage->w * tmpImage->h; ++ i) + if (fmt->Amask) { - Uint8 a; - if (fmt->Amask) + for (int i = 0; i < sz; ++ i) { 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; - } + Uint8 a = (v << fmt->Aloss) + (v >> (8 - (fmt->Aloss << 1))); - 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 < sz; ++ i) + alphaChannel[i] = SDL_ALPHA_OPAQUE; } } else { if (SDL_ALPHA_OPAQUE != 255) hasAlpha = true; - for (int i = 0; i < tmpImage->w * tmpImage->h; ++ i) + for (int i = 0; i < sz; ++ i) alphaChannel[i] = SDL_ALPHA_OPAQUE; } -- cgit v1.2.3-60-g2f50