summaryrefslogtreecommitdiff
path: root/src/resources/image.cpp
diff options
context:
space:
mode:
authorBertram <bertram@cegetel.net>2009-08-14 00:19:00 +0200
committerBertram <bertram@cegetel.net>2009-08-14 00:19:00 +0200
commit32e63222acc750fce68048211df3434256802ec4 (patch)
tree608bdf91eb83019dfe0a8a96b721d3eee1bb6d6f /src/resources/image.cpp
parent1f2a31c0a97ee2ff858fe142e778c49011b93f71 (diff)
downloadmana-client-32e63222acc750fce68048211df3434256802ec4.tar.gz
mana-client-32e63222acc750fce68048211df3434256802ec4.tar.bz2
mana-client-32e63222acc750fce68048211df3434256802ec4.tar.xz
mana-client-32e63222acc750fce68048211df3434256802ec4.zip
Added a new function to know if an image is using an alpha channel.
This all will be useful for my next patch: Repair windows opacity break in SDL mode.
Diffstat (limited to 'src/resources/image.cpp')
-rw-r--r--src/resources/image.cpp42
1 files changed, 41 insertions, 1 deletions
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index b3f7140d..0540d543 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -48,6 +48,8 @@ Image::Image(SDL_Surface *image):
{
mBounds.w = mSDLSurface->w;
mBounds.h = mSDLSurface->h;
+
+ mAlphaChannel = hasAlphaChannel();
mLoaded = true;
}
else
@@ -64,7 +66,8 @@ Image::Image(GLuint glimage, int width, int height, int texWidth, int texHeight)
mTexWidth(texWidth),
mTexHeight(texHeight),
mSDLSurface(0),
- mAlpha(1.0)
+ mAlpha(1.0),
+ mAlphaChannel(true)
{
mBounds.x = 0;
mBounds.y = 0;
@@ -189,6 +192,43 @@ bool Image::isAnOpenGLOne() const
#endif
}
+bool Image::hasAlphaChannel()
+{
+ if (mLoaded)
+ return mAlphaChannel;
+
+#ifdef USE_OPENGL
+ if (mUseOpenGL)
+ return true;
+#endif
+
+ if (!mSDLSurface)
+ return false;
+
+ bool hasAlpha = false;
+
+ if (mSDLSurface->format->BitsPerPixel == 32)
+ {
+ // Figure out whether the image uses its alpha layer
+ for (int i = 0; i < mSDLSurface->w * mSDLSurface->h; ++i)
+ {
+ Uint8 r, g, b, a;
+ SDL_GetRGBA(
+ ((Uint32*) mSDLSurface->pixels)[i],
+ mSDLSurface->format,
+ &r, &g, &b, &a);
+
+ if (a != 255)
+ {
+ hasAlpha = true;
+ break;
+ }
+ }
+ }
+
+ return hasAlpha;
+}
+
void Image::setAlpha(float a)
{
if (mAlpha == a)