summaryrefslogtreecommitdiff
path: root/src/resources/image.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-04-22 17:05:08 +0300
committerAndrei Karas <akaras@inbox.ru>2011-04-22 17:05:08 +0300
commit55c25d526f76c3e41e232d765721eb8ee722e908 (patch)
tree40caef8e6db7467ab4de779692827b8fe2d9c7f9 /src/resources/image.cpp
parentc5808ea0d60620d3c9768b2ca63398f5f62309e3 (diff)
downloadplus-55c25d526f76c3e41e232d765721eb8ee722e908.tar.gz
plus-55c25d526f76c3e41e232d765721eb8ee722e908.tar.bz2
plus-55c25d526f76c3e41e232d765721eb8ee722e908.tar.xz
plus-55c25d526f76c3e41e232d765721eb8ee722e908.zip
Improve speed in _SDLLoad function.
Diffstat (limited to 'src/resources/image.cpp')
-rw-r--r--src/resources/image.cpp33
1 files changed, 26 insertions, 7 deletions
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<Uint32*>(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<Uint32*>(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;