summaryrefslogtreecommitdiff
path: root/src/resources/image.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/resources/image.cpp')
-rw-r--r--src/resources/image.cpp21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index 583cf7343..876e64af4 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -417,24 +417,21 @@ void Image::setAlpha(float alpha)
const int i1 = mBounds.y * mSDLSurface->w + mBounds.x;
const int i2 = (maxHeight - 1) * mSDLSurface->w + maxWidth - 1;
+ const SDL_PixelFormat * const fmt = mSDLSurface->format;
+
for (int i = i1; i <= i2; i++)
{
// Only change the pixel if it was visible at load time...
Uint8 sourceAlpha = mAlphaChannel[i];
if (sourceAlpha > 0)
{
- Uint8 r, g, b, a;
- SDL_GetRGBA((static_cast<Uint32*>
- (mSDLSurface->pixels))[i],
- mSDLSurface->format,
- &r, &g, &b, &a);
-
- a = static_cast<Uint8>(static_cast<float>(
- sourceAlpha) * mAlpha);
-
- // Here is the pixel we want to set
- (static_cast<Uint32 *>(mSDLSurface->pixels))[i] =
- SDL_MapRGBA(mSDLSurface->format, r, g, b, a);
+ Uint8 a = static_cast<Uint8>(
+ static_cast<float>(sourceAlpha) * mAlpha);
+
+ (static_cast<Uint32*>(mSDLSurface->pixels))[i]
+ &= ~fmt->Amask;
+ (static_cast<Uint32*>(mSDLSurface->pixels))[i]
+ |= ((a >> fmt->Aloss) << fmt->Ashift & fmt->Amask);
}
}