aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--graphics/transparent_surface.cpp17
-rw-r--r--graphics/transparent_surface.h1
2 files changed, 18 insertions, 0 deletions
diff --git a/graphics/transparent_surface.cpp b/graphics/transparent_surface.cpp
index b4d73d1078..a24f7198aa 100644
--- a/graphics/transparent_surface.cpp
+++ b/graphics/transparent_surface.cpp
@@ -716,6 +716,23 @@ void TransparentSurface::applyColorKey(uint8 rKey, uint8 gKey, uint8 bKey, bool
}
}
+/**
+ * Sets alpha channel for all pixels to specified value
+ * @param alpha value of the alpha channel to set
+ */
+void TransparentSurface::setAlpha(uint8 alpha) {
+ assert(format.bytesPerPixel == 4);
+ for (int i = 0; i < h; i++) {
+ for (int j = 0; j < w; j++) {
+ uint32 pix = ((uint32 *)pixels)[i * w + j];
+ uint8 r, g, b, a;
+ format.colorToARGB(pix, a, r, g, b);
+ a = alpha;
+ ((uint32 *)pixels)[i * w + j] = format.ARGBToColor(a, r, g, b);
+ }
+ }
+}
+
AlphaType TransparentSurface::getAlphaMode() const {
return _alphaMode;
}
diff --git a/graphics/transparent_surface.h b/graphics/transparent_surface.h
index 22fe04551e..0738c90f90 100644
--- a/graphics/transparent_surface.h
+++ b/graphics/transparent_surface.h
@@ -137,6 +137,7 @@ struct TransparentSurface : public Graphics::Surface {
TSpriteBlendMode blend = BLEND_NORMAL);
void applyColorKey(uint8 r, uint8 g, uint8 b, bool overwriteAlpha = false);
+ void setAlpha(uint8 alpha);
/**
* @brief Scale function; this returns a transformed version of this surface after rotation and