summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-07-20 04:12:29 +0300
committerAndrei Karas <akaras@inbox.ru>2011-07-20 04:26:56 +0300
commit0ba6ef14054e096b1d94604310e445fb4e78bb82 (patch)
tree94d8ba011abbf7e822817c38c7eae986a90ff366
parente645959d2dc85ee6a50d9927df3d9f6e374c8317 (diff)
downloadmanaplus-0ba6ef14054e096b1d94604310e445fb4e78bb82.tar.gz
manaplus-0ba6ef14054e096b1d94604310e445fb4e78bb82.tar.bz2
manaplus-0ba6ef14054e096b1d94604310e445fb4e78bb82.tar.xz
manaplus-0ba6ef14054e096b1d94604310e445fb4e78bb82.zip
Improve setAlpha speed in software mode.
-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);
}
}