diff options
Diffstat (limited to 'src/resources/image.cpp')
-rw-r--r-- | src/resources/image.cpp | 33 |
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; |