summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-07-20 23:03:30 +0300
committerAndrei Karas <akaras@inbox.ru>2011-07-20 23:03:30 +0300
commit8fdaa55cfc951459b0ee079839cdf40e88baa2af (patch)
treec0742a94803dc34dfb146c16f82d019c7a6459f6
parentf1f3fd2696500bf569ea0543a2161d4c0e1fcc91 (diff)
downloadmv-8fdaa55cfc951459b0ee079839cdf40e88baa2af.tar.gz
mv-8fdaa55cfc951459b0ee079839cdf40e88baa2af.tar.bz2
mv-8fdaa55cfc951459b0ee079839cdf40e88baa2af.tar.xz
mv-8fdaa55cfc951459b0ee079839cdf40e88baa2af.zip
Small optimisations.
-rw-r--r--src/gui/outfitwindow.h12
-rw-r--r--src/resources/image.cpp30
2 files changed, 25 insertions, 17 deletions
diff --git a/src/gui/outfitwindow.h b/src/gui/outfitwindow.h
index 2d2f6271b..60634dbdd 100644
--- a/src/gui/outfitwindow.h
+++ b/src/gui/outfitwindow.h
@@ -28,6 +28,12 @@
#include <guichan/actionlistener.hpp>
#include <guichan/mouselistener.hpp>
+#ifdef __GNUC__
+#define A_PURE __attribute__ ((pure))
+#else
+#define A_PURE
+#endif
+
#define OUTFITS_COUNT 100
#define OUTFIT_ITEM_COUNT 12
@@ -82,9 +88,9 @@ class OutfitWindow : public Window, gcn::ActionListener
void unequipNotInOutfit(int outfit);
- int keyToNumber(SDLKey key) const;
+ int keyToNumber(SDLKey key) const A_PURE;
- SDLKey numberToKey(int number) const;
+ SDLKey numberToKey(int number) const A_PURE;
void next();
@@ -100,7 +106,7 @@ class OutfitWindow : public Window, gcn::ActionListener
void showCurrentOutfit();
- std::string keyName(int number);
+ std::string keyName(int number) A_PURE;
private:
Button *mPreviousButton;
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;
}
}