diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-07-20 04:12:29 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-07-20 04:26:56 +0300 |
commit | 0ba6ef14054e096b1d94604310e445fb4e78bb82 (patch) | |
tree | 94d8ba011abbf7e822817c38c7eae986a90ff366 /src | |
parent | e645959d2dc85ee6a50d9927df3d9f6e374c8317 (diff) | |
download | mv-0ba6ef14054e096b1d94604310e445fb4e78bb82.tar.gz mv-0ba6ef14054e096b1d94604310e445fb4e78bb82.tar.bz2 mv-0ba6ef14054e096b1d94604310e445fb4e78bb82.tar.xz mv-0ba6ef14054e096b1d94604310e445fb4e78bb82.zip |
Improve setAlpha speed in software mode.
Diffstat (limited to 'src')
-rw-r--r-- | src/resources/image.cpp | 21 |
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); } } |