From 0ba6ef14054e096b1d94604310e445fb4e78bb82 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 20 Jul 2011 04:12:29 +0300 Subject: Improve setAlpha speed in software mode. --- src/resources/image.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'src/resources/image.cpp') 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 - (mSDLSurface->pixels))[i], - mSDLSurface->format, - &r, &g, &b, &a); - - a = static_cast(static_cast( - sourceAlpha) * mAlpha); - - // Here is the pixel we want to set - (static_cast(mSDLSurface->pixels))[i] = - SDL_MapRGBA(mSDLSurface->format, r, g, b, a); + Uint8 a = static_cast( + static_cast(sourceAlpha) * mAlpha); + + (static_cast(mSDLSurface->pixels))[i] + &= ~fmt->Amask; + (static_cast(mSDLSurface->pixels))[i] + |= ((a >> fmt->Aloss) << fmt->Ashift & fmt->Amask); } } -- cgit v1.2.3-70-g09d2