diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-07-20 23:03:30 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-07-20 23:03:30 +0300 |
commit | 8fdaa55cfc951459b0ee079839cdf40e88baa2af (patch) | |
tree | c0742a94803dc34dfb146c16f82d019c7a6459f6 /src/resources/image.cpp | |
parent | f1f3fd2696500bf569ea0543a2161d4c0e1fcc91 (diff) | |
download | plus-8fdaa55cfc951459b0ee079839cdf40e88baa2af.tar.gz plus-8fdaa55cfc951459b0ee079839cdf40e88baa2af.tar.bz2 plus-8fdaa55cfc951459b0ee079839cdf40e88baa2af.tar.xz plus-8fdaa55cfc951459b0ee079839cdf40e88baa2af.zip |
Small optimisations.
Diffstat (limited to 'src/resources/image.cpp')
-rw-r--r-- | src/resources/image.cpp | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/src/resources/image.cpp b/src/resources/image.cpp index e39eb1edc..6bb0a9faa 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -165,13 +165,15 @@ Resource *Image::load(void *buffer, unsigned bufferSize, Dye const &dye) Uint32 *pixels = static_cast< Uint32 * >(surf->pixels); for (Uint32 *p_end = pixels + surf->w * surf->h; pixels != p_end; ++pixels) { - int alpha = *pixels & 255; + const Uint32 p = *pixels; + + int alpha = p & 255; if (!alpha) continue; int v[3]; - v[0] = (*pixels >> 24) & 255; - v[1] = (*pixels >> 16) & 255; - v[2] = (*pixels >> 8 ) & 255; + v[0] = (p >> 24) & 255; + v[1] = (p >> 16) & 255; + v[2] = (p >> 8 ) & 255; dye.update(v); *pixels = (v[0] << 24) | (v[1] << 16) | (v[2] << 8) | alpha; } @@ -217,21 +219,21 @@ Image *Image::createTextSurface(SDL_Surface *tmpImage, float alpha) { for (int i = 0; i < sz; ++ i) { - unsigned v = ((static_cast<Uint32*>(tmpImage->pixels))[i] - & fmt->Amask) >> fmt->Ashift; + Uint32 c = (static_cast<Uint32*>(tmpImage->pixels))[i]; + + unsigned v = (c & fmt->Amask) >> fmt->Ashift; Uint8 a = (v << fmt->Aloss) + (v >> (8 - (fmt->Aloss << 1))); Uint8 a2 = static_cast<Uint8>(static_cast<float>(a) * alpha); - (static_cast<Uint32*>(tmpImage->pixels))[i] &= ~fmt->Amask; - (static_cast<Uint32*>(tmpImage->pixels))[i] |= - ((a2 >> fmt->Aloss) << fmt->Ashift & fmt->Amask); + c &= ~fmt->Amask; + c |= ((a2 >> fmt->Aloss) << fmt->Ashift & fmt->Amask); + (static_cast<Uint32*>(tmpImage->pixels))[i] = c; if (a != 255) hasAlpha = true; alphaChannel[i] = a; - } } @@ -429,10 +431,10 @@ void Image::setAlpha(float alpha) 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); + Uint32 c = (static_cast<Uint32*>(mSDLSurface->pixels))[i]; + c &= ~fmt->Amask; + c |= ((a >> fmt->Aloss) << fmt->Ashift & fmt->Amask); + (static_cast<Uint32*>(mSDLSurface->pixels))[i] = c; } } |