From c450854165a9c26d6ab982b09e23ac6d53496599 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Tue, 1 Jan 2019 13:24:54 +0100 Subject: GRAPHICS: Added setAlpha() method to TransparentSurface --- graphics/transparent_surface.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'graphics/transparent_surface.cpp') 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; } -- cgit v1.2.3