[Scummvm-git-logs] scummvm master -> 0561e5dcc4b9825f0de196cdd8234f35a400cc12

bluegr noreply at scummvm.org
Sat Jun 21 19:47:19 UTC 2025


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .

Summary:
0561e5dcc4 WINTERMUTE: Combine detecting alpha transparency with applying the colour key


Commit: 0561e5dcc4b9825f0de196cdd8234f35a400cc12
    https://github.com/scummvm/scummvm/commit/0561e5dcc4b9825f0de196cdd8234f35a400cc12
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2025-06-21T22:47:15+03:00

Commit Message:
WINTERMUTE: Combine detecting alpha transparency with applying the colour key

Changed paths:
    engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp
    graphics/blit/blit-alpha.cpp
    graphics/surface.h


diff --git a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp
index 87b335fc4b0..f0b63e6549a 100644
--- a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp
+++ b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp
@@ -169,10 +169,16 @@ bool BaseSurfaceOSystem::finishLoad() {
 	if (needsColorKey) {
 		// We set the pixel color to transparent black,
 		// like D3DX, if it matches the color key.
-		_surface->applyColorKey(_ckRed, _ckGreen, _ckBlue, replaceAlpha, 0, 0, 0);
+		bool applied = _surface->applyColorKey(_ckRed, _ckGreen, _ckBlue, replaceAlpha, 0, 0, 0);
+
+		if (replaceAlpha || image->getSurface()->format.aBits() == 0 || image->getSurface()->format.isCLUT8())
+			_alphaType = applied ? Graphics::ALPHA_BINARY : Graphics::ALPHA_OPAQUE;
+		else
+			_alphaType = _surface->detectAlpha();
+	} else {
+		_alphaType = image->getSurface()->detectAlpha();
 	}
 
-	_alphaType = _surface->detectAlpha();
 	_valid = true;
 
 	delete image;
diff --git a/graphics/blit/blit-alpha.cpp b/graphics/blit/blit-alpha.cpp
index dc4c23ea24e..b37edd2e712 100644
--- a/graphics/blit/blit-alpha.cpp
+++ b/graphics/blit/blit-alpha.cpp
@@ -28,7 +28,7 @@ namespace Graphics {
 namespace {
 
 template<typename Size, bool overwriteAlpha>
-inline void applyColorKeyLogic(byte *dst, const byte *src, const uint w, const uint h,
+inline bool applyColorKeyLogic(byte *dst, const byte *src, const uint w, const uint h,
 							   const uint srcDelta, const uint dstDelta,
 							   const Graphics::PixelFormat &format,
 							   const uint8 rKey, const uint8 gKey, const uint8 bKey,
@@ -38,6 +38,7 @@ inline void applyColorKeyLogic(byte *dst, const byte *src, const uint w, const u
 	const uint32 newPix    = format.ARGBToColor(0,   rNew, gNew, bNew);
 	const uint32 rgbMask   = format.ARGBToColor(0,   255,  255,  255);
 	const uint32 alphaMask = format.ARGBToColor(255, 0,    0,    0);
+	bool applied = false;
 
 	for (uint y = 0; y < h; ++y) {
 		for (uint x = 0; x < w; ++x) {
@@ -45,6 +46,7 @@ inline void applyColorKeyLogic(byte *dst, const byte *src, const uint w, const u
 
 			if ((pix & rgbMask) == keyPix) {
 				*(Size *)dst = newPix;
+				applied = true;
 			} else if (overwriteAlpha) {
 				*(Size *)dst = pix | alphaMask;
 			}
@@ -56,6 +58,8 @@ inline void applyColorKeyLogic(byte *dst, const byte *src, const uint w, const u
 		src += srcDelta;
 		dst += dstDelta;
 	}
+
+	return applied;
 }
 
 template<typename Size, bool skipTransparent>
@@ -105,27 +109,25 @@ bool applyColorKey(byte *dst, const byte *src,
 
 	if (overwriteAlpha) {
 		if (format.bytesPerPixel == 1) {
-			applyColorKeyLogic<uint8, true>(dst, src, w, h, srcDelta, dstDelta, format, rKey, gKey, bKey, rNew, gNew, bNew);
+			return applyColorKeyLogic<uint8, true>(dst, src, w, h, srcDelta, dstDelta, format, rKey, gKey, bKey, rNew, gNew, bNew);
 		} else if (format.bytesPerPixel == 2) {
-			applyColorKeyLogic<uint16, true>(dst, src, w, h, srcDelta, dstDelta, format, rKey, gKey, bKey, rNew, gNew, bNew);
+			return applyColorKeyLogic<uint16, true>(dst, src, w, h, srcDelta, dstDelta, format, rKey, gKey, bKey, rNew, gNew, bNew);
 		} else if (format.bytesPerPixel == 4) {
-			applyColorKeyLogic<uint32, true>(dst, src, w, h, srcDelta, dstDelta, format, rKey, gKey, bKey, rNew, gNew, bNew);
+			return applyColorKeyLogic<uint32, true>(dst, src, w, h, srcDelta, dstDelta, format, rKey, gKey, bKey, rNew, gNew, bNew);
 		} else {
 			return false;
 		}
 	} else {
 		if (format.bytesPerPixel == 1) {
-			applyColorKeyLogic<uint8, false>(dst, src, w, h, srcDelta, dstDelta, format, rKey, gKey, bKey, rNew, gNew, bNew);
+			return applyColorKeyLogic<uint8, false>(dst, src, w, h, srcDelta, dstDelta, format, rKey, gKey, bKey, rNew, gNew, bNew);
 		} else if (format.bytesPerPixel == 2) {
-			applyColorKeyLogic<uint16, false>(dst, src, w, h, srcDelta, dstDelta, format, rKey, gKey, bKey, rNew, gNew, bNew);
+			return applyColorKeyLogic<uint16, false>(dst, src, w, h, srcDelta, dstDelta, format, rKey, gKey, bKey, rNew, gNew, bNew);
 		} else if (format.bytesPerPixel == 4) {
-			applyColorKeyLogic<uint32, false>(dst, src, w, h, srcDelta, dstDelta, format, rKey, gKey, bKey, rNew, gNew, bNew);
+			return applyColorKeyLogic<uint32, false>(dst, src, w, h, srcDelta, dstDelta, format, rKey, gKey, bKey, rNew, gNew, bNew);
 		} else {
 			return false;
 		}
 	}
-
-	return true;
 }
 
 // Function to set the alpha channel for all pixels to the specified value
diff --git a/graphics/surface.h b/graphics/surface.h
index 5d204836dbf..58d726d711e 100644
--- a/graphics/surface.h
+++ b/graphics/surface.h
@@ -529,6 +529,7 @@ public:
 	 * @param gKey  the green component of the color key
 	 * @param bKey  the blue component of the color key
 	 * @param overwriteAlpha if true, all other alpha will be set fully opaque
+	 * @return true if a color key was applied, otherwise false.
 	 */
 	bool applyColorKey(uint8 rKey, uint8 gKey, uint8 bKey, bool overwriteAlpha = false);
 
@@ -541,6 +542,7 @@ public:
 	 * @param rNew  the red component to replace the color key with
 	 * @param gNew  the green component to replace the color key with
 	 * @param bNew  the blue component to replace the color key with
+	 * @return true if a color key was applied, otherwise false.
 	 */
 	bool applyColorKey(uint8 rKey, uint8 gKey, uint8 bKey, bool overwriteAlpha,
 	                   uint8 rNew, uint8 gNew, uint8 bNew);




More information about the Scummvm-git-logs mailing list