[Scummvm-git-logs] scummvm master -> 31172f1684325331e536e827374e7e6ef5f20898

OMGPizzaGuy noreply at scummvm.org
Wed Sep 13 22:39:02 UTC 2023


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

Summary:
31172f1684 ULTIMA8: Merge shape paint blending functions.


Commit: 31172f1684325331e536e827374e7e6ef5f20898
    https://github.com/scummvm/scummvm/commit/31172f1684325331e536e827374e7e6ef5f20898
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2023-09-13T17:37:57-05:00

Commit Message:
ULTIMA8: Merge shape paint blending functions.

Changed paths:
  R engines/ultima/ultima8/graphics/render_surface.inl
    engines/ultima/ultima8/graphics/render_surface.cpp


diff --git a/engines/ultima/ultima8/graphics/render_surface.cpp b/engines/ultima/ultima8/graphics/render_surface.cpp
index 0f1ebbc8de8..6acdaa0665b 100644
--- a/engines/ultima/ultima8/graphics/render_surface.cpp
+++ b/engines/ultima/ultima8/graphics/render_surface.cpp
@@ -611,85 +611,253 @@ RenderSurface *RenderSurface::CreateSecondaryRenderSurface(uint32 width, uint32
 namespace {
 
 template<typename uintX>
-
 void inline paintLogic(uint8 *pixels, int32 pitch,
 					   const Common::Rect &clipWindow,
 					   const Graphics::PixelFormat &format,
 					   const ShapeFrame *frame, int32 x, int32 y, bool mirrored,
 					   const uint32 *map) {
-#include "ultima/ultima8/graphics/render_surface.inl"
-}
+	const Graphics::Surface &src = frame->getSurface();
+	Common::Rect srcRect(0, 0, src.w, src.h);
+	Common::Rect dstRect(x, y, x, y);
 
-template<class uintX>
-void inline paintTranslucentLogic(uint8 *pixels, int32 pitch,
-								  const Common::Rect &clipWindow,
-								  const Graphics::PixelFormat &format,
-								  const ShapeFrame *frame, int32 x, int32 y, bool mirrored,
-								  const uint32 *map, const uint32 *xform_map) {
-#define XFORM_SHAPES
-#include "ultima/ultima8/graphics/render_surface.inl"
-#undef XFORM_SHAPES
-}
+	if (mirrored) {
+		dstRect.right += frame->_xoff + 1;
+		dstRect.left = dstRect.right - srcRect.width();
 
-template<class uintX>
-void inline paintInvisibleLogic(uint8 *pixels, int32 pitch,
-								const Common::Rect &clipWindow,
-								const Graphics::PixelFormat &format,
-								const ShapeFrame *frame, int32 x, int32 y, bool trans, bool mirrored,
-								const uint32 *map, const uint32 *xform_map) {
-#define XFORM_SHAPES
-#define XFORM_CONDITIONAL trans
-#define BLEND_SHAPES(src, dst) BlendInvisible(src, dst, format)
-
-#include "ultima/ultima8/graphics/render_surface.inl"
-
-#undef XFORM_SHAPES
-#undef XFORM_CONDITIONAL
-#undef BLEND_SHAPES
-}
+		if (dstRect.left < clipWindow.left) {
+			srcRect.right += dstRect.left - clipWindow.left;
+			dstRect.left = clipWindow.left;
+		}
+
+		if (dstRect.right > clipWindow.right) {
+			srcRect.left += dstRect.right - clipWindow.right;
+			dstRect.right = clipWindow.right;
+		}
+	} else {
+		dstRect.left -= frame->_xoff;
+		dstRect.right = dstRect.left + srcRect.width();
+
+		if (dstRect.left < clipWindow.left) {
+			srcRect.left -= dstRect.left - clipWindow.left;
+			dstRect.left = clipWindow.left;
+		}
+
+		if (dstRect.right > clipWindow.right) {
+			srcRect.right -= dstRect.right - clipWindow.right;
+			dstRect.right = clipWindow.right;
+		}
+	}
+
+	dstRect.top -= frame->_yoff;
+	dstRect.bottom = dstRect.top + srcRect.height();
+
+	if (dstRect.top < clipWindow.top) {
+		srcRect.top -= dstRect.top - clipWindow.top;
+		dstRect.top = clipWindow.top;
+	}
+
+	if (dstRect.bottom > clipWindow.bottom) {
+		srcRect.bottom -= dstRect.bottom - clipWindow.bottom;
+		dstRect.bottom = clipWindow.bottom;
+	}
 
-template<class uintX>
-void inline paintHighlightLogic(uint8 *pixels, int32 pitch,
-								const Common::Rect &clipWindow,
-								const Graphics::PixelFormat &format,
-								const ShapeFrame *frame, int32 x, int32 y, bool trans, bool mirrored, uint32 col32,
-								const uint32 *map, const uint32 *xform_map) {
-#define XFORM_SHAPES
-#define XFORM_CONDITIONAL trans
-#define BLEND_SHAPES(src, dst) BlendHighlight(src, cr, cg, cb, ca, 255 - ca, format)
-
-	uint32 ca = TEX32_A(col32);
-	uint32 cr = TEX32_R(col32);
-	uint32 cg = TEX32_G(col32);
-	uint32 cb = TEX32_B(col32);
-
-#include "ultima/ultima8/graphics/render_surface.inl"
-
-#undef XFORM_SHAPES
-#undef XFORM_CONDITIONAL
-#undef BLEND_SHAPES
+	const int srcStep = sizeof(uint8);
+	int dstStep = sizeof(uintX);
+
+	if (mirrored) {
+		x = dstRect.right - 1;
+		y = dstRect.top;
+		dstStep = -dstStep;
+	} else {
+		x = dstRect.left;
+		y = dstRect.top;
+	}
+
+	const int w = srcRect.width();
+	const int h = srcRect.height();
+	const int srcDelta = src.pitch - (w * srcStep);
+	const int dstDelta = pitch - (w * dstStep);
+
+	const uint8 keycolor = frame->_keycolor;
+	const uint8 *srcPixels = reinterpret_cast<const uint8 *>(src.getBasePtr(srcRect.left, srcRect.top));
+	uint8 *dstPixels = reinterpret_cast<uint8 *>(pixels + x * sizeof(uintX) + pitch * y);
+
+	for (int i = 0; i < h; i++) {
+		for (int j = 0; j < w; j++) {
+			const uint8 color = *srcPixels;
+			if (color != keycolor) {
+				uintX *dstpix = reinterpret_cast<uintX *>(dstPixels);
+				*dstpix = static_cast<uintX>(map[color]);
+			}
+			srcPixels += srcStep;
+			dstPixels += dstStep;
+		}
+
+		srcPixels += srcDelta;
+		dstPixels += dstDelta;
+	}
 }
 
-template<class uintX>
-void inline paintHighlightInvisLogic(uint8 *pixels, int32 pitch,
-									 const Common::Rect &clipWindow,
-									 const Graphics::PixelFormat &format,
-									 const ShapeFrame *frame, int32 x, int32 y, bool trans, bool mirrored, uint32 col32,
-									 const uint32 *map, const uint32 *xform_map) {
-#define XFORM_SHAPES
-#define XFORM_CONDITIONAL trans
-#define BLEND_SHAPES(src, dst) BlendHighlightInvis(src, dst, cr, cg, cb, ca, 255 - ca, format)
-
-	uint32 ca = TEX32_A(col32);
-	uint32 cr = TEX32_R(col32);
-	uint32 cg = TEX32_G(col32);
-	uint32 cb = TEX32_B(col32);
-
-#include "ultima/ultima8/graphics/render_surface.inl"
-
-#undef XFORM_SHAPES
-#undef XFORM_CONDITIONAL
-#undef BLEND_SHAPES
+template<typename uintX>
+void inline paintBlendedLogic(uint8 *pixels, int32 pitch,
+							  const Common::Rect &clipWindow,
+							  const Graphics::PixelFormat &format,
+							  const ShapeFrame *frame, int32 x, int32 y,
+							  bool mirrored, bool invisible, uint32 highlight,
+							  const uint32 *map, const uint32 *xform_map) {
+	const Graphics::Surface &src = frame->getSurface();
+	Common::Rect srcRect(0, 0, src.w, src.h);
+	Common::Rect dstRect(x, y, x, y);
+
+	if (mirrored) {
+		dstRect.right += frame->_xoff + 1;
+		dstRect.left = dstRect.right - srcRect.width();
+
+		if (dstRect.left < clipWindow.left) {
+			srcRect.right += dstRect.left - clipWindow.left;
+			dstRect.left = clipWindow.left;
+		}
+
+		if (dstRect.right > clipWindow.right) {
+			srcRect.left += dstRect.right - clipWindow.right;
+			dstRect.right = clipWindow.right;
+		}
+	} else {
+		dstRect.left -= frame->_xoff;
+		dstRect.right = dstRect.left + srcRect.width();
+
+		if (dstRect.left < clipWindow.left) {
+			srcRect.left -= dstRect.left - clipWindow.left;
+			dstRect.left = clipWindow.left;
+		}
+
+		if (dstRect.right > clipWindow.right) {
+			srcRect.right -= dstRect.right - clipWindow.right;
+			dstRect.right = clipWindow.right;
+		}
+	}
+
+	dstRect.top -= frame->_yoff;
+	dstRect.bottom = dstRect.top + srcRect.height();
+
+	if (dstRect.top < clipWindow.top) {
+		srcRect.top -= dstRect.top - clipWindow.top;
+		dstRect.top = clipWindow.top;
+	}
+
+	if (dstRect.bottom > clipWindow.bottom) {
+		srcRect.bottom -= dstRect.bottom - clipWindow.bottom;
+		dstRect.bottom = clipWindow.bottom;
+	}
+
+	const int srcStep = sizeof(uint8);
+	int dstStep = sizeof(uintX);
+
+	if (mirrored) {
+		x = dstRect.right - 1;
+		y = dstRect.top;
+		dstStep = -dstStep;
+	} else {
+		x = dstRect.left;
+		y = dstRect.top;
+	}
+
+	const int w = srcRect.width();
+	const int h = srcRect.height();
+	const int srcDelta = src.pitch - (w * srcStep);
+	const int dstDelta = pitch - (w * dstStep);
+
+	const uint8 keycolor = frame->_keycolor;
+	const uint8 *srcPixels = reinterpret_cast<const uint8 *>(src.getBasePtr(srcRect.left, srcRect.top));
+	uint8 *dstPixels = reinterpret_cast<uint8 *>(pixels + x * sizeof(uintX) + pitch * y);
+
+	if (highlight && invisible) {
+		uint32 ca = TEX32_A(highlight);
+		uint32 cr = TEX32_R(highlight);
+		uint32 cg = TEX32_G(highlight);
+		uint32 cb = TEX32_B(highlight);
+
+		for (int i = 0; i < h; i++) {
+			for (int j = 0; j < w; j++) {
+				const uint8 color = *srcPixels;
+				if (color != keycolor) {
+					uintX *dstpix = reinterpret_cast<uintX *>(dstPixels);
+					if (xform_map && xform_map[color]) {
+						*dstpix = static_cast<uintX>(BlendHighlightInvis(BlendPreModulated(xform_map[color], *dstpix, format), *dstpix, cr, cg, cb, ca, 255 - ca, format));
+					} else {
+						*dstpix = static_cast<uintX>(BlendHighlightInvis(map[color], *dstpix, cr, cg, cb, ca, 255 - ca, format));
+					}
+				}
+				srcPixels += srcStep;
+				dstPixels += dstStep;
+			}
+
+			srcPixels += srcDelta;
+			dstPixels += dstDelta;
+		}
+	} else if (highlight) {
+		uint32 ca = TEX32_A(highlight);
+		uint32 cr = TEX32_R(highlight);
+		uint32 cg = TEX32_G(highlight);
+		uint32 cb = TEX32_B(highlight);
+
+		for (int i = 0; i < h; i++) {
+			for (int j = 0; j < w; j++) {
+				const uint8 color = *srcPixels;
+				if (color != keycolor) {
+					uintX *dstpix = reinterpret_cast<uintX *>(dstPixels);
+					if (xform_map && xform_map[color]) {
+						*dstpix = static_cast<uintX>(BlendHighlight(BlendPreModulated(xform_map[color], *dstpix, format), cr, cg, cb, ca, 255 - ca, format));
+					} else {
+						*dstpix = static_cast<uintX>(BlendHighlight(map[color], cr, cg, cb, ca, 255 - ca, format));
+					}
+				}
+				srcPixels += srcStep;
+				dstPixels += dstStep;
+			}
+
+			srcPixels += srcDelta;
+			dstPixels += dstDelta;
+		}
+	} else if (invisible) {
+		for (int i = 0; i < h; i++) {
+			for (int j = 0; j < w; j++) {
+				const uint8 color = *srcPixels;
+				if (color != keycolor) {
+					uintX *dstpix = reinterpret_cast<uintX *>(dstPixels);
+					if (xform_map && xform_map[color]) {
+						*dstpix = static_cast<uintX>(BlendInvisible(BlendPreModulated(xform_map[color], *dstpix, format), *dstpix, format));
+					} else {
+						*dstpix = static_cast<uintX>(BlendInvisible(map[color], *dstpix, format));
+					}
+				}
+				srcPixels += srcStep;
+				dstPixels += dstStep;
+			}
+
+			srcPixels += srcDelta;
+			dstPixels += dstDelta;
+		}
+	} else {
+		for (int i = 0; i < h; i++) {
+			for (int j = 0; j < w; j++) {
+				const uint8 color = *srcPixels;
+				if (color != keycolor) {
+					uintX *dstpix = reinterpret_cast<uintX *>(dstPixels);
+					if (xform_map && xform_map[color]) {
+						*dstpix = static_cast<uintX>(BlendPreModulated(xform_map[color], *dstpix, format));
+					} else {
+						*dstpix = static_cast<uintX>(map[color]);
+					}
+				}
+				srcPixels += srcStep;
+				dstPixels += dstStep;
+			}
+
+			srcPixels += srcDelta;
+			dstPixels += dstDelta;
+		}
+	}
 }
 
 } // End of anonymous namespace
@@ -726,9 +894,9 @@ void RenderSurface::PaintTranslucent(const Shape *s, uint32 framenum, int32 x, i
 	const uint32 *xform_map = s->getPalette()->_xform;
 
 	if (_surface->format.bytesPerPixel == 4)
-		paintTranslucentLogic<uint32>(_pixels, _pitch, _clipWindow, _surface->format, frame, x, y, mirrored, map, xform_map);
+		paintBlendedLogic<uint32>(_pixels, _pitch, _clipWindow, _surface->format, frame, x, y, mirrored, false, 0, map, xform_map);
 	else if (_surface->format.bytesPerPixel == 2)
-		paintTranslucentLogic<uint16>(_pixels, _pitch, _clipWindow, _surface->format, frame, x, y, mirrored, map, xform_map);
+		paintBlendedLogic<uint16>(_pixels, _pitch, _clipWindow, _surface->format, frame, x, y, mirrored, false, 0, map, xform_map);
 }
 
 //
@@ -742,12 +910,12 @@ void RenderSurface::PaintInvisible(const Shape *s, uint32 framenum, int32 x, int
 		return;
 
 	const uint32 *map = s->getPalette()->_native;
-	const uint32 *xform_map = s->getPalette()->_xform;
+	const uint32 *xform_map = trans ? s->getPalette()->_xform : nullptr;
 
 	if (_surface->format.bytesPerPixel == 4)
-		paintInvisibleLogic<uint32>(_pixels, _pitch, _clipWindow, _surface->format, frame, x, y, trans, mirrored, map, xform_map);
+		paintBlendedLogic<uint32>(_pixels, _pitch, _clipWindow, _surface->format, frame, x, y, mirrored, true, 0, map, xform_map);
 	else if (_surface->format.bytesPerPixel == 2)
-		paintInvisibleLogic<uint16>(_pixels, _pitch, _clipWindow, _surface->format, frame, x, y, trans, mirrored, map, xform_map);
+		paintBlendedLogic<uint16>(_pixels, _pitch, _clipWindow, _surface->format, frame, x, y, mirrored, true, 0, map, xform_map);
 }
 
 //
@@ -761,12 +929,12 @@ void RenderSurface::PaintHighlight(const Shape *s, uint32 framenum, int32 x, int
 		return;
 
 	const uint32 *map = s->getPalette()->_native;
-	const uint32 *xform_map = s->getPalette()->_xform;
+	const uint32 *xform_map = trans ? s->getPalette()->_xform : nullptr;
 
 	if (_surface->format.bytesPerPixel == 4)
-		paintHighlightLogic<uint32>(_pixels, _pitch, _clipWindow, _surface->format, frame, x, y, trans, mirrored, col32, map, xform_map);
+		paintBlendedLogic<uint32>(_pixels, _pitch, _clipWindow, _surface->format, frame, x, y, mirrored, false, col32, map, xform_map);
 	else if (_surface->format.bytesPerPixel == 2)
-		paintHighlightLogic<uint16>(_pixels, _pitch, _clipWindow, _surface->format, frame, x, y, trans, mirrored, col32, map, xform_map);
+		paintBlendedLogic<uint16>(_pixels, _pitch, _clipWindow, _surface->format, frame, x, y, mirrored, false, col32, map, xform_map);
 }
 
 //
@@ -780,12 +948,12 @@ void RenderSurface::PaintHighlightInvis(const Shape *s, uint32 framenum, int32 x
 		return;
 
 	const uint32 *map = s->getPalette()->_native;
-	const uint32 *xform_map = s->getPalette()->_xform;
+	const uint32 *xform_map = trans ? s->getPalette()->_xform : nullptr;
 
 	if (_surface->format.bytesPerPixel == 4)
-		paintHighlightInvisLogic<uint32>(_pixels, _pitch, _clipWindow, _surface->format, frame, x, y, trans, mirrored, col32, map, xform_map);
+		paintBlendedLogic<uint32>(_pixels, _pitch, _clipWindow, _surface->format, frame, x, y, mirrored, true, col32, map, xform_map);
 	else if (_surface->format.bytesPerPixel == 2)
-		paintHighlightInvisLogic<uint16>(_pixels, _pitch, _clipWindow, _surface->format, frame, x, y, trans, mirrored, col32, map, xform_map);
+		paintBlendedLogic<uint16>(_pixels, _pitch, _clipWindow, _surface->format, frame, x, y, mirrored, true, col32, map, xform_map);
 }
 
 } // End of namespace Ultima8
diff --git a/engines/ultima/ultima8/graphics/render_surface.inl b/engines/ultima/ultima8/graphics/render_surface.inl
deleted file mode 100644
index 0cac2339ca7..00000000000
--- a/engines/ultima/ultima8/graphics/render_surface.inl
+++ /dev/null
@@ -1,181 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-//
-// Render Surface Shape Display include file
-//
-
-//
-// Macros to define before including this:
-//
-// #define XFORM_SHAPES to enable XFORMing
-//
-// #define XFORM_CONDITIONAL to an argument of the function so XFORM can be
-// enabled/disabled with a bool
-//
-// #define BLEND_SHAPES(src,dst) to an a specified blend function.
-//
-// #define BLEND_CONDITIONAL to an argument of the function so BLEND
-// painting can be enabled/disabled with a bool
-//
-
-//
-// Macros defined by this file:
-//
-// USE_XFORM_FUNC - Checks to see if we want to use XForm Blending for this pixel
-//
-// CUSTOM_BLEND - Final Blend for invisiblity
-//
-
-//
-// XForm = TRUE
-//
-#ifdef XFORM_SHAPES
-
-#ifdef XFORM_CONDITIONAL
-#define USE_XFORM_FUNC ((XFORM_CONDITIONAL) && xform_map[color])
-#else
-#define USE_XFORM_FUNC (xform_map[color])
-#endif
-
-//
-// XForm = FALSE
-//
-#else
-#define USE_XFORM_FUNC 0
-#endif
-
-//
-// Invisilibity = TRUE
-//
-#ifdef BLEND_SHAPES
-
-#ifdef BLEND_CONDITIONAL
-#define CUSTOM_BLEND(src) static_cast<uintX>((BLEND_CONDITIONAL)?BLEND_SHAPES(src,*dstpix):src)
-#else
-#define CUSTOM_BLEND(src) static_cast<uintX>(BLEND_SHAPES(src,*dstpix))
-#endif
-
-//
-// Invisilibity = FALSE
-//
-#else
-
-#define CUSTOM_BLEND(src) static_cast<uintX>(src)
-
-#endif
-
-//
-// The Function
-//
-
-	const Graphics::Surface &src =  frame->getSurface();
-	const uint8 keycolor = frame->_keycolor;
-
-	Common::Rect srcRect(0, 0, src.w, src.h);
-	Common::Rect dstRect(x, y, x, y);
-
-	const int srcStep = sizeof(uint8);
-	int dstStep = sizeof(uintX);
-
-	if (mirrored) {
-		dstRect.right += frame->_xoff + 1;
-		dstRect.left = dstRect.right - srcRect.width();
-
-		if (dstRect.left < clipWindow.left) {
-			srcRect.right += dstRect.left - clipWindow.left;
-			dstRect.left = clipWindow.left;
-		}
-
-		if (dstRect.right > clipWindow.right) {
-			srcRect.left += dstRect.right - clipWindow.right;
-			dstRect.right = clipWindow.right;
-		}
-	} else {
-		dstRect.left -= frame->_xoff;
-		dstRect.right = dstRect.left + srcRect.width();
-
-		if (dstRect.left < clipWindow.left) {
-			srcRect.left -= dstRect.left - clipWindow.left;
-			dstRect.left = clipWindow.left;
-		}
-
-		if (dstRect.right > clipWindow.right) {
-			srcRect.right -= dstRect.right - clipWindow.right;
-			dstRect.right = clipWindow.right;
-		}
-	}
-
-	dstRect.top -= frame->_yoff;
-	dstRect.bottom = dstRect.top + srcRect.height();
-
-	if (dstRect.top < clipWindow.top) {
-		srcRect.top -= dstRect.top - clipWindow.top;
-		dstRect.top = clipWindow.top;
-	}
-
-	if (dstRect.bottom > clipWindow.bottom) {
-		srcRect.bottom -= dstRect.bottom - clipWindow.bottom;
-		dstRect.bottom = clipWindow.bottom;
-	}
-
-	if (mirrored) {
-		x = dstRect.right - 1;
-		y = dstRect.top;
-		dstStep = -dstStep;
-	} else {
-		x = dstRect.left;
-		y = dstRect.top;
-	}
-
-	const int w = srcRect.width();
-	const int h = srcRect.height();
-	const int srcDelta = src.pitch - (w * srcStep);
-	const int dstDelta = pitch - (w * dstStep);
-
-	const uint8 *srcPixels = reinterpret_cast<const uint8 *>(src.getBasePtr(srcRect.left, srcRect.top));
-	uint8 *dstPixels = reinterpret_cast<uint8 *>(pixels + x * sizeof(uintX) + pitch * y);
-
-	for (int i = 0; i < h; i++)  {
-		for (int j = 0; j < w; j++) {
-			const uint8 color = *srcPixels;
-			if (color != keycolor) {
-				uintX *dstpix = reinterpret_cast<uintX *>(dstPixels);
-				#ifdef XFORM_SHAPES
-				if (USE_XFORM_FUNC) {
-					*dstpix = CUSTOM_BLEND(BlendPreModulated(xform_map[color], *dstpix, format));
-				}
-				else
-				#endif
-				{
-					*dstpix = CUSTOM_BLEND(map[color]);
-				}
-			}
-			srcPixels += srcStep;
-			dstPixels += dstStep;
-		}
-
-		srcPixels += srcDelta;
-		dstPixels += dstDelta;
-	}
-
-#undef CUSTOM_BLEND
-#undef USE_XFORM_FUNC




More information about the Scummvm-git-logs mailing list