[Scummvm-git-logs] scummvm master -> 4b594af6821ae16842e8f51cd4a3850804d0a55f

OMGPizzaGuy noreply at scummvm.org
Sat Dec 17 00:32:56 UTC 2022


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

Summary:
1d0593874b ULTIMA8: Remove PACK_RGB16 macro
3e601d842d ULTIMA8: Replace PACK_RGB8 macro with RGBToColor from the pixel format
da5bc30090 ULTIMA8: Replace UNPACK_RGB8 macro with ColorToRGB from the pixel format
4b594af682 ULTIMA8: Replace U8PixelFormat with Graphics::PixelFormat


Commit: 1d0593874bb17285863e557d40a4836a202d407c
    https://github.com/scummvm/scummvm/commit/1d0593874bb17285863e557d40a4836a202d407c
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2022-12-16T17:58:24-06:00

Commit Message:
ULTIMA8: Remove PACK_RGB16 macro
Shifting values by 8 before calling PACK_RGB8 accomplishes the same goal

Changed paths:
    engines/ultima/ultima8/graphics/render_surface.cpp
    engines/ultima/ultima8/graphics/render_surface.h
    engines/ultima/ultima8/graphics/soft_render_surface.cpp
    engines/ultima/ultima8/graphics/xform_blend.h


diff --git a/engines/ultima/ultima8/graphics/render_surface.cpp b/engines/ultima/ultima8/graphics/render_surface.cpp
index e7433d940e7..0f60867d0ab 100644
--- a/engines/ultima/ultima8/graphics/render_surface.cpp
+++ b/engines/ultima/ultima8/graphics/render_surface.cpp
@@ -51,10 +51,6 @@ RenderSurface::RenderSurface(Graphics::ManagedSurface *s) : _pixels(nullptr), _p
 		RenderSurface::_format->gLoss = _surface->format.gLoss;
 		RenderSurface::_format->bLoss = _surface->format.bLoss;
 		RenderSurface::_format->aLoss = _surface->format.aLoss;
-		RenderSurface::_format->rLoss16 = _format->rLoss + 8;
-		RenderSurface::_format->gLoss16 = _format->gLoss + 8;
-		RenderSurface::_format->bLoss16 = _format->bLoss + 8;
-		RenderSurface::_format->aLoss16 = _format->aLoss + 8;
 		RenderSurface::_format->rShift = _surface->format.rShift;
 		RenderSurface::_format->gShift = _surface->format.gShift;
 		RenderSurface::_format->bShift = _surface->format.bShift;
@@ -102,7 +98,6 @@ RenderSurface::RenderSurface(Graphics::ManagedSurface *s) : _pixels(nullptr), _p
 		// Set it
 		_format->aShift = first;
 		_format->aLoss = 8 - (last + 1 - first);
-		_format->aLoss16 = _format->aLoss + 8;
 		_format->aMask = mask;
 	}
 }
diff --git a/engines/ultima/ultima8/graphics/render_surface.h b/engines/ultima/ultima8/graphics/render_surface.h
index 8a9ea9d1a97..8a71ea63599 100644
--- a/engines/ultima/ultima8/graphics/render_surface.h
+++ b/engines/ultima/ultima8/graphics/render_surface.h
@@ -40,19 +40,15 @@ class Scaler;
 
 #define UNPACK_RGB8(pix,r,g,b) { r = (((pix)&RenderSurface::_format->rMask)>>RenderSurface::_format->rShift)<<RenderSurface::_format->rLoss; g = (((pix)&RenderSurface::_format->gMask)>>RenderSurface::_format->gShift)<<RenderSurface::_format->gLoss; b = (((pix)&RenderSurface::_format->bMask)>>RenderSurface::_format->bShift)<<RenderSurface::_format->bLoss; }
 #define PACK_RGB8(r,g,b) ((((r)>>RenderSurface::_format->rLoss)<<RenderSurface::_format->rShift) | (((g)>>RenderSurface::_format->gLoss)<<RenderSurface::_format->gShift) | (((b)>>RenderSurface::_format->bLoss)<<RenderSurface::_format->bShift))
-#define PACK_RGB16(r,g,b) ((((r)>>RenderSurface::_format->rLoss16)<<RenderSurface::_format->rShift) | (((g)>>RenderSurface::_format->gLoss16)<<RenderSurface::_format->gShift) | (((b)>>RenderSurface::_format->bLoss16)<<RenderSurface::_format->bShift))
 
 #define UNPACK_RGBA8(pix,r,g,b,a) { r = (((pix)&RenderSurface::_format->rMask)>>RenderSurface::_format->rShift)<<RenderSurface::_format->rLoss; g = (((pix)&RenderSurface::_format->gMask)>>RenderSurface::_format->gShift)<<RenderSurface::_format->gLoss; b = (((pix)&RenderSurface::_format->bMask)>>RenderSurface::_format->bShift)<<RenderSurface::_format->bLoss; ; a = (((pix)&RenderSurface::_format->aMask)>>RenderSurface::_format->aShift)<<RenderSurface::_format->aLoss; }
 #define PACK_RGBA8(r,g,b,a) ((((r)>>RenderSurface::_format->rLoss)<<RenderSurface::_format->rShift) | (((g)>>RenderSurface::_format->gLoss)<<RenderSurface::_format->gShift) | (((b)>>RenderSurface::_format->bLoss)<<RenderSurface::_format->bShift) | (((a)>>RenderSurface::_format->aLoss)<<RenderSurface::_format->aShift))
-#define PACK_RGBA16(r,g,b,a) ((((r)>>RenderSurface::_format->rLoss16)<<RenderSurface::_format->rShift) | (((g)>>RenderSurface::_format->gLoss16)<<RenderSurface::_format->gShift) | (((b)>>RenderSurface::_format->bLoss16)<<RenderSurface::_format->bShift) | (((a)>>RenderSurface::_format->aLoss16)<<RenderSurface::_format->aShift))
 
 struct U8PixelFormat : Graphics::PixelFormat {
 	// Extend with some extra attributes
-	byte  rLoss16, gLoss16, bLoss16, aLoss16;
 	uint32  rMask, gMask, bMask, aMask;
 
 	inline U8PixelFormat() : Graphics::PixelFormat(),
-		rLoss16(0), gLoss16(0), bLoss16(0), aLoss16(0),
 		rMask(0), gMask(0), bMask(0), aMask(0) {
 	}
 };
diff --git a/engines/ultima/ultima8/graphics/soft_render_surface.cpp b/engines/ultima/ultima8/graphics/soft_render_surface.cpp
index 38cd1eaf9e4..e3de61d5dfe 100644
--- a/engines/ultima/ultima8/graphics/soft_render_surface.cpp
+++ b/engines/ultima/ultima8/graphics/soft_render_surface.cpp
@@ -336,7 +336,7 @@ template<class uintX> void SoftRenderSurface<uintX>::FadedBlit(const Graphics::M
 						dg += TEX32_G(Tsrc) * ia + ((g * TEX32_A(Tsrc)) >> 8);
 						db += TEX32_B(Tsrc) * ia + ((b * TEX32_A(Tsrc)) >> 8);
 
-						*dest = PACK_RGB16(dr, dg, db);
+						*dest = PACK_RGB8(dr >> 8, dg >> 8, db >> 8);
 					}
 					pixel += sizeof(uintX);
 					texel++;
@@ -471,7 +471,7 @@ template<class uintX> void SoftRenderSurface<uintX>::MaskedBlit(const Graphics::
 							dg += TEX32_G(Tsrc) * ia + ((g * TEX32_A(Tsrc)) >> 8);
 							db += TEX32_B(Tsrc) * ia + ((b * TEX32_A(Tsrc)) >> 8);
 
-							*dest = PACK_RGB16(dr, dg, db);
+							*dest = PACK_RGB8(dr >> 8, dg >> 8, db >> 8);
 						}
 					}
 					pixel += sizeof(uintX);
diff --git a/engines/ultima/ultima8/graphics/xform_blend.h b/engines/ultima/ultima8/graphics/xform_blend.h
index d64a88df176..8e5406264ed 100644
--- a/engines/ultima/ultima8/graphics/xform_blend.h
+++ b/engines/ultima/ultima8/graphics/xform_blend.h
@@ -50,7 +50,10 @@ inline uint32 P_FASTCALL BlendPreModulated(uint32 src, uint32 dst) {
 	r += 256 * TEX32_R(src);
 	g += 256 * TEX32_G(src);
 	b += 256 * TEX32_B(src);
-	return PACK_RGB16(r > 65535 ? 65535 : r, g > 65535 ? 65535 : g, b > 65535 ? 65535 : b);
+	r >>= 8;
+	g >>= 8;
+	b >>= 8;
+	return PACK_RGB8(r > 0xFF ? 0xFF : r, g > 0xFF ? 0xFF : g, b > 0xFF ? 0xFF : b);
 }
 
 inline uint32 P_FASTCALL BlendPreModFast(uint32 src, uint32 dst) {
@@ -62,14 +65,16 @@ inline uint32 P_FASTCALL BlendPreModFast(uint32 src, uint32 dst) {
 	r += 256 * TEX32_R(src);
 	g += 256 * TEX32_G(src);
 	b += 256 * TEX32_B(src);
-	return PACK_RGB16(r, g, b);
+	return PACK_RGB8(r >> 8, g >> 8, b >> 8);
 }
 
 // This does the red highlight blending.
 inline uint32 P_FASTCALL BlendHighlight(uint32 src, uint32 cr, uint32 cg, uint32 cb, uint32 ca, uint32 ica) {
 	uint32 sr, sg, sb;
 	UNPACK_RGB8(src, sr, sg, sb);
-	return PACK_RGB16(sr * ica + cr * ca, sg * ica + cg * ca, sb * ica + cb * ca);
+	return PACK_RGB8((sr * ica + cr * ca) >> 8,
+					 (sg * ica + cg * ca) >> 8,
+					 (sb * ica + cb * ca) >> 8);
 }
 
 // This does the invisible blending. I've set it to about 40%
@@ -78,9 +83,9 @@ inline uint32 P_FASTCALL BlendInvisible(uint32 src, uint32 dst) {
 	uint32 dr, dg, db;
 	UNPACK_RGB8(src, sr, sg, sb);
 	UNPACK_RGB8(dst, dr, dg, db);
-	return PACK_RGB16(sr * 100 + dr * 156,
-	                  sg * 100 + dg * 156,
-	                  sb * 100 + db * 156);
+	return PACK_RGB8((sr * 100 + dr * 156) >> 8,
+					 (sg * 100 + dg * 156) >> 8,
+					 (sb * 100 + db * 156) >> 8);
 }
 
 // This does the translucent highlight blending. (50%)
@@ -89,9 +94,9 @@ inline uint32 P_FASTCALL BlendHighlightInvis(uint32 src, uint32 dst, uint32 cr,
 	uint32 dr, dg, db;
 	UNPACK_RGB8(src, sr, sg, sb);
 	UNPACK_RGB8(dst, dr, dg, db);
-	return PACK_RGB16(((sr * ica + cr * ca) >> 1) + (dr << 7),
-	                  ((sg * ica + cg * ca) >> 1) + (dg << 7),
-	                  ((sb * ica + cb * ca) >> 1) + (db << 7));
+	return PACK_RGB8((((sr * ica + cr * ca) >> 1) + (dr << 7)) >> 8,
+					 (((sg * ica + cg * ca) >> 1) + (dg << 7)) >> 8,
+					 (((sb * ica + cb * ca) >> 1) + (db << 7)) >> 8);
 }
 
 } // End of namespace Ultima8


Commit: 3e601d842d47b76b9678c03a0682a63aff7c8329
    https://github.com/scummvm/scummvm/commit/3e601d842d47b76b9678c03a0682a63aff7c8329
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2022-12-16T17:58:24-06:00

Commit Message:
ULTIMA8: Replace PACK_RGB8 macro with RGBToColor from the pixel format

Changed paths:
    engines/ultima/ultima8/graphics/render_surface.cpp
    engines/ultima/ultima8/graphics/render_surface.h
    engines/ultima/ultima8/graphics/soft_render_surface.cpp
    engines/ultima/ultima8/graphics/xform_blend.h


diff --git a/engines/ultima/ultima8/graphics/render_surface.cpp b/engines/ultima/ultima8/graphics/render_surface.cpp
index 0f60867d0ab..690b07f8227 100644
--- a/engines/ultima/ultima8/graphics/render_surface.cpp
+++ b/engines/ultima/ultima8/graphics/render_surface.cpp
@@ -201,9 +201,9 @@ void RenderSurface::CreateNativePalette(Palette *palette, int maxindex) {
 		int32 r, g, b;
 
 		// Normal palette
-		palette->_native_untransformed[i] = PACK_RGB8(palette->_palette[i * 3 + 0],
-													  palette->_palette[i * 3 + 1],
-													  palette->_palette[i * 3 + 2]);
+		palette->_native_untransformed[i] = _format->RGBToColor(palette->_palette[i * 3 + 0],
+																palette->_palette[i * 3 + 1],
+																palette->_palette[i * 3 + 2]);
 
 		r = palette->_matrix[0] * palette->_palette[i * 3 + 0] +
 			palette->_matrix[1] * palette->_palette[i * 3 + 1] +
@@ -234,9 +234,9 @@ void RenderSurface::CreateNativePalette(Palette *palette, int maxindex) {
 
 		// Transformed normal palette
 		// FIXME - Wont work on non SDL SRS Implementations
-		palette->_native[i] = PACK_RGB8(static_cast<uint8>(r >> 11),
-										static_cast<uint8>(g >> 11),
-										static_cast<uint8>(b >> 11));
+		palette->_native[i] = _format->RGBToColor(static_cast<uint8>(r >> 11),
+												  static_cast<uint8>(g >> 11),
+												  static_cast<uint8>(b >> 11));
 
 		// Transformed XFORM palette (Uses the TEX32 format)
 		if (TEX32_A(palette->_xform_untransformed[i])) {
diff --git a/engines/ultima/ultima8/graphics/render_surface.h b/engines/ultima/ultima8/graphics/render_surface.h
index 8a71ea63599..c11d3a6a1cc 100644
--- a/engines/ultima/ultima8/graphics/render_surface.h
+++ b/engines/ultima/ultima8/graphics/render_surface.h
@@ -39,10 +39,8 @@ struct Rect;
 class Scaler;
 
 #define UNPACK_RGB8(pix,r,g,b) { r = (((pix)&RenderSurface::_format->rMask)>>RenderSurface::_format->rShift)<<RenderSurface::_format->rLoss; g = (((pix)&RenderSurface::_format->gMask)>>RenderSurface::_format->gShift)<<RenderSurface::_format->gLoss; b = (((pix)&RenderSurface::_format->bMask)>>RenderSurface::_format->bShift)<<RenderSurface::_format->bLoss; }
-#define PACK_RGB8(r,g,b) ((((r)>>RenderSurface::_format->rLoss)<<RenderSurface::_format->rShift) | (((g)>>RenderSurface::_format->gLoss)<<RenderSurface::_format->gShift) | (((b)>>RenderSurface::_format->bLoss)<<RenderSurface::_format->bShift))
 
 #define UNPACK_RGBA8(pix,r,g,b,a) { r = (((pix)&RenderSurface::_format->rMask)>>RenderSurface::_format->rShift)<<RenderSurface::_format->rLoss; g = (((pix)&RenderSurface::_format->gMask)>>RenderSurface::_format->gShift)<<RenderSurface::_format->gLoss; b = (((pix)&RenderSurface::_format->bMask)>>RenderSurface::_format->bShift)<<RenderSurface::_format->bLoss; ; a = (((pix)&RenderSurface::_format->aMask)>>RenderSurface::_format->aShift)<<RenderSurface::_format->aLoss; }
-#define PACK_RGBA8(r,g,b,a) ((((r)>>RenderSurface::_format->rLoss)<<RenderSurface::_format->rShift) | (((g)>>RenderSurface::_format->gLoss)<<RenderSurface::_format->gShift) | (((b)>>RenderSurface::_format->bLoss)<<RenderSurface::_format->bShift) | (((a)>>RenderSurface::_format->aLoss)<<RenderSurface::_format->aShift))
 
 struct U8PixelFormat : Graphics::PixelFormat {
 	// Extend with some extra attributes
diff --git a/engines/ultima/ultima8/graphics/soft_render_surface.cpp b/engines/ultima/ultima8/graphics/soft_render_surface.cpp
index e3de61d5dfe..3eb49c2c795 100644
--- a/engines/ultima/ultima8/graphics/soft_render_surface.cpp
+++ b/engines/ultima/ultima8/graphics/soft_render_surface.cpp
@@ -55,7 +55,7 @@ template<class uintX> SoftRenderSurface<uintX>::SoftRenderSurface(Graphics::Mana
 template<class uintX> void SoftRenderSurface<uintX>::Fill32(uint32 rgb, int32 sx, int32 sy, int32 w, int32 h) {
 	Rect rect(sx, sy, sx + w, sy + h);
 	rect.clip(_clipWindow);
-	rgb = PACK_RGB8((rgb >> 16) & 0xFF , (rgb >> 8) & 0xFF , rgb & 0xFF);
+	rgb = _format->RGBToColor((rgb >> 16) & 0xFF , (rgb >> 8) & 0xFF , rgb & 0xFF);
 	_surface->fillRect(Common::Rect(rect.left + _ox, rect.top + _oy, rect.right + _ox, rect.bottom + _oy), rgb);
 }
 
@@ -302,12 +302,10 @@ template<class uintX> void SoftRenderSurface<uintX>::FadedBlit(const Graphics::M
 			if (!alpha_blend) while (pixel != line_end) {
 					if (*texel & TEX32_A_MASK) {
 						*(reinterpret_cast<uintX *>(pixel)) = static_cast<uintX>(
-						        PACK_RGB8(
-						            (TEX32_R(*texel) * ia + r) >> 8,
-						            (TEX32_G(*texel) * ia + g) >> 8,
-						            (TEX32_B(*texel) * ia + b) >> 8
-						        )
-						                                      );
+							_format->RGBToColor(
+								(TEX32_R(*texel) * ia + r) >> 8,
+								(TEX32_G(*texel) * ia + g) >> 8,
+								(TEX32_B(*texel) * ia + b) >> 8));
 					}
 					pixel += sizeof(uintX);
 					texel++;
@@ -316,12 +314,10 @@ template<class uintX> void SoftRenderSurface<uintX>::FadedBlit(const Graphics::M
 					uint32 alpha = *texel & TEX32_A_MASK;
 					if (alpha == 0xFF) {
 						*(reinterpret_cast<uintX *>(pixel)) = static_cast<uintX>(
-						        PACK_RGB8(
-						            (TEX32_R(*texel) * ia + r) >> 8,
-						            (TEX32_G(*texel) * ia + g) >> 8,
-						            (TEX32_B(*texel) * ia + b) >> 8
-						        )
-						                                      );
+							_format->RGBToColor(
+								(TEX32_R(*texel) * ia + r) >> 8,
+								(TEX32_G(*texel) * ia + g) >> 8,
+								(TEX32_B(*texel) * ia + b) >> 8));
 					} else if (alpha) {
 						uintX *dest = reinterpret_cast<uintX *>(pixel);
 
@@ -336,7 +332,7 @@ template<class uintX> void SoftRenderSurface<uintX>::FadedBlit(const Graphics::M
 						dg += TEX32_G(Tsrc) * ia + ((g * TEX32_A(Tsrc)) >> 8);
 						db += TEX32_B(Tsrc) * ia + ((b * TEX32_A(Tsrc)) >> 8);
 
-						*dest = PACK_RGB8(dr >> 8, dg >> 8, db >> 8);
+						*dest = _format->RGBToColor(dr >> 8, dg >> 8, db >> 8);
 					}
 					pixel += sizeof(uintX);
 					texel++;
@@ -434,12 +430,10 @@ template<class uintX> void SoftRenderSurface<uintX>::MaskedBlit(const Graphics::
 					if (*texel & TEX32_A_MASK) {
 						if (!RenderSurface::_format->aMask || (*dest & RenderSurface::_format->aMask)) {
 							*dest = static_cast<uintX>(
-								PACK_RGB8(
+								_format->RGBToColor(
 									(TEX32_R(*texel) * ia + r) >> 8,
 									(TEX32_G(*texel) * ia + g) >> 8,
-									(TEX32_B(*texel) * ia + b) >> 8
-								)
-							);
+									(TEX32_B(*texel) * ia + b) >> 8));
 						}
 					}
 					pixel += sizeof(uintX);
@@ -453,12 +447,10 @@ template<class uintX> void SoftRenderSurface<uintX>::MaskedBlit(const Graphics::
 						uint32 alpha = *texel & TEX32_A_MASK;
 						if (alpha == 0xFF) {
 							*dest = static_cast<uintX>(
-							    PACK_RGB8(
-							        (TEX32_R(*texel) * ia + r) >> 8,
-							        (TEX32_G(*texel) * ia + g) >> 8,
-							        (TEX32_B(*texel) * ia + b) >> 8
-							    )
-							);
+								_format->RGBToColor(
+									(TEX32_R(*texel) * ia + r) >> 8,
+									(TEX32_G(*texel) * ia + g) >> 8,
+									(TEX32_B(*texel) * ia + b) >> 8));
 						} else if (alpha) {
 							uint32 Tsrc = *texel;
 							uint32 dr, dg, db;
@@ -471,7 +463,7 @@ template<class uintX> void SoftRenderSurface<uintX>::MaskedBlit(const Graphics::
 							dg += TEX32_G(Tsrc) * ia + ((g * TEX32_A(Tsrc)) >> 8);
 							db += TEX32_B(Tsrc) * ia + ((b * TEX32_A(Tsrc)) >> 8);
 
-							*dest = PACK_RGB8(dr >> 8, dg >> 8, db >> 8);
+							*dest = _format->RGBToColor(dr >> 8, dg >> 8, db >> 8);
 						}
 					}
 					pixel += sizeof(uintX);
diff --git a/engines/ultima/ultima8/graphics/xform_blend.h b/engines/ultima/ultima8/graphics/xform_blend.h
index 8e5406264ed..e466c850ddf 100644
--- a/engines/ultima/ultima8/graphics/xform_blend.h
+++ b/engines/ultima/ultima8/graphics/xform_blend.h
@@ -53,7 +53,7 @@ inline uint32 P_FASTCALL BlendPreModulated(uint32 src, uint32 dst) {
 	r >>= 8;
 	g >>= 8;
 	b >>= 8;
-	return PACK_RGB8(r > 0xFF ? 0xFF : r, g > 0xFF ? 0xFF : g, b > 0xFF ? 0xFF : b);
+	return RenderSurface::_format->RGBToColor(r > 0xFF ? 0xFF : r, g > 0xFF ? 0xFF : g, b > 0xFF ? 0xFF : b);
 }
 
 inline uint32 P_FASTCALL BlendPreModFast(uint32 src, uint32 dst) {
@@ -65,16 +65,16 @@ inline uint32 P_FASTCALL BlendPreModFast(uint32 src, uint32 dst) {
 	r += 256 * TEX32_R(src);
 	g += 256 * TEX32_G(src);
 	b += 256 * TEX32_B(src);
-	return PACK_RGB8(r >> 8, g >> 8, b >> 8);
+	return RenderSurface::_format->RGBToColor(r >> 8, g >> 8, b >> 8);
 }
 
 // This does the red highlight blending.
 inline uint32 P_FASTCALL BlendHighlight(uint32 src, uint32 cr, uint32 cg, uint32 cb, uint32 ca, uint32 ica) {
 	uint32 sr, sg, sb;
 	UNPACK_RGB8(src, sr, sg, sb);
-	return PACK_RGB8((sr * ica + cr * ca) >> 8,
-					 (sg * ica + cg * ca) >> 8,
-					 (sb * ica + cb * ca) >> 8);
+	return RenderSurface::_format->RGBToColor((sr * ica + cr * ca) >> 8,
+											  (sg * ica + cg * ca) >> 8,
+											  (sb * ica + cb * ca) >> 8);
 }
 
 // This does the invisible blending. I've set it to about 40%
@@ -83,9 +83,9 @@ inline uint32 P_FASTCALL BlendInvisible(uint32 src, uint32 dst) {
 	uint32 dr, dg, db;
 	UNPACK_RGB8(src, sr, sg, sb);
 	UNPACK_RGB8(dst, dr, dg, db);
-	return PACK_RGB8((sr * 100 + dr * 156) >> 8,
-					 (sg * 100 + dg * 156) >> 8,
-					 (sb * 100 + db * 156) >> 8);
+	return RenderSurface::_format->RGBToColor((sr * 100 + dr * 156) >> 8,
+											  (sg * 100 + dg * 156) >> 8,
+											  (sb * 100 + db * 156) >> 8);
 }
 
 // This does the translucent highlight blending. (50%)
@@ -94,9 +94,9 @@ inline uint32 P_FASTCALL BlendHighlightInvis(uint32 src, uint32 dst, uint32 cr,
 	uint32 dr, dg, db;
 	UNPACK_RGB8(src, sr, sg, sb);
 	UNPACK_RGB8(dst, dr, dg, db);
-	return PACK_RGB8((((sr * ica + cr * ca) >> 1) + (dr << 7)) >> 8,
-					 (((sg * ica + cg * ca) >> 1) + (dg << 7)) >> 8,
-					 (((sb * ica + cb * ca) >> 1) + (db << 7)) >> 8);
+	return RenderSurface::_format->RGBToColor((((sr * ica + cr * ca) >> 1) + (dr << 7)) >> 8,
+											  (((sg * ica + cg * ca) >> 1) + (dg << 7)) >> 8,
+											  (((sb * ica + cb * ca) >> 1) + (db << 7)) >> 8);
 }
 
 } // End of namespace Ultima8


Commit: da5bc300901d5ca55c9d56a006861bbc075d8e00
    https://github.com/scummvm/scummvm/commit/da5bc300901d5ca55c9d56a006861bbc075d8e00
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2022-12-16T17:58:24-06:00

Commit Message:
ULTIMA8: Replace UNPACK_RGB8 macro with ColorToRGB from the pixel format

Changed paths:
    engines/ultima/ultima8/graphics/render_surface.h
    engines/ultima/ultima8/graphics/soft_render_surface.cpp
    engines/ultima/ultima8/graphics/xform_blend.h


diff --git a/engines/ultima/ultima8/graphics/render_surface.h b/engines/ultima/ultima8/graphics/render_surface.h
index c11d3a6a1cc..91181af7bc6 100644
--- a/engines/ultima/ultima8/graphics/render_surface.h
+++ b/engines/ultima/ultima8/graphics/render_surface.h
@@ -38,10 +38,6 @@ struct Palette;
 struct Rect;
 class Scaler;
 
-#define UNPACK_RGB8(pix,r,g,b) { r = (((pix)&RenderSurface::_format->rMask)>>RenderSurface::_format->rShift)<<RenderSurface::_format->rLoss; g = (((pix)&RenderSurface::_format->gMask)>>RenderSurface::_format->gShift)<<RenderSurface::_format->gLoss; b = (((pix)&RenderSurface::_format->bMask)>>RenderSurface::_format->bShift)<<RenderSurface::_format->bLoss; }
-
-#define UNPACK_RGBA8(pix,r,g,b,a) { r = (((pix)&RenderSurface::_format->rMask)>>RenderSurface::_format->rShift)<<RenderSurface::_format->rLoss; g = (((pix)&RenderSurface::_format->gMask)>>RenderSurface::_format->gShift)<<RenderSurface::_format->gLoss; b = (((pix)&RenderSurface::_format->bMask)>>RenderSurface::_format->bShift)<<RenderSurface::_format->bLoss; ; a = (((pix)&RenderSurface::_format->aMask)>>RenderSurface::_format->aShift)<<RenderSurface::_format->aLoss; }
-
 struct U8PixelFormat : Graphics::PixelFormat {
 	// Extend with some extra attributes
 	uint32  rMask, gMask, bMask, aMask;
diff --git a/engines/ultima/ultima8/graphics/soft_render_surface.cpp b/engines/ultima/ultima8/graphics/soft_render_surface.cpp
index 3eb49c2c795..d5a0f496eca 100644
--- a/engines/ultima/ultima8/graphics/soft_render_surface.cpp
+++ b/engines/ultima/ultima8/graphics/soft_render_surface.cpp
@@ -322,12 +322,12 @@ template<class uintX> void SoftRenderSurface<uintX>::FadedBlit(const Graphics::M
 						uintX *dest = reinterpret_cast<uintX *>(pixel);
 
 						uint32 Tsrc = *texel;
-						uint32 dr, dg, db;
-						UNPACK_RGB8(*dest, dr, dg, db);
+						uint8 r2, g2, b2;
+						_format->colorToRGB(*dest, r2, g2, b2);
 
-						dr *= 256 - TEX32_A(Tsrc);
-						dg *= 256 - TEX32_A(Tsrc);
-						db *= 256 - TEX32_A(Tsrc);
+						uint32 dr = r2 * (256 - TEX32_A(Tsrc));
+						uint32 dg = g2 * (256 - TEX32_A(Tsrc));
+						uint32 db = b2 * (256 - TEX32_A(Tsrc));
 						dr += TEX32_R(Tsrc) * ia + ((r * TEX32_A(Tsrc)) >> 8);
 						dg += TEX32_G(Tsrc) * ia + ((g * TEX32_A(Tsrc)) >> 8);
 						db += TEX32_B(Tsrc) * ia + ((b * TEX32_A(Tsrc)) >> 8);
@@ -453,12 +453,12 @@ template<class uintX> void SoftRenderSurface<uintX>::MaskedBlit(const Graphics::
 									(TEX32_B(*texel) * ia + b) >> 8));
 						} else if (alpha) {
 							uint32 Tsrc = *texel;
-							uint32 dr, dg, db;
-							UNPACK_RGB8(*dest, dr, dg, db);
+							uint8 r2, g2, b2;
+							_format->colorToRGB(*dest, r2, g2, b2);
 
-							dr *= 256 - TEX32_A(Tsrc);
-							dg *= 256 - TEX32_A(Tsrc);
-							db *= 256 - TEX32_A(Tsrc);
+							uint32 dr = r2 * (256 - TEX32_A(Tsrc));
+							uint32 dg = g2 * (256 - TEX32_A(Tsrc));
+							uint32 db = b2 * (256 - TEX32_A(Tsrc));
 							dr += TEX32_R(Tsrc) * ia + ((r * TEX32_A(Tsrc)) >> 8);
 							dg += TEX32_G(Tsrc) * ia + ((g * TEX32_A(Tsrc)) >> 8);
 							db += TEX32_B(Tsrc) * ia + ((b * TEX32_A(Tsrc)) >> 8);
diff --git a/engines/ultima/ultima8/graphics/xform_blend.h b/engines/ultima/ultima8/graphics/xform_blend.h
index e466c850ddf..72fd89f1b9b 100644
--- a/engines/ultima/ultima8/graphics/xform_blend.h
+++ b/engines/ultima/ultima8/graphics/xform_blend.h
@@ -42,11 +42,12 @@ extern const uint8 U8XFormPal[1024];
 extern const uint8 CruXFormPal[1024];
 
 inline uint32 P_FASTCALL BlendPreModulated(uint32 src, uint32 dst) {
-	uint32 r, g, b;
-	UNPACK_RGB8(dst, r, g, b);
-	r *= 256 - TEX32_A(src);
-	g *= 256 - TEX32_A(src);
-	b *= 256 - TEX32_A(src);
+	uint8 sr, sg, sb;
+	RenderSurface::_format->colorToRGB(dst, sr, sg, sb);
+
+	uint32 r = sr * (256 - TEX32_A(src));
+	uint32 g = sg * (256 - TEX32_A(src));
+	uint32 b = sb * (256 - TEX32_A(src));
 	r += 256 * TEX32_R(src);
 	g += 256 * TEX32_G(src);
 	b += 256 * TEX32_B(src);
@@ -57,11 +58,12 @@ inline uint32 P_FASTCALL BlendPreModulated(uint32 src, uint32 dst) {
 }
 
 inline uint32 P_FASTCALL BlendPreModFast(uint32 src, uint32 dst) {
-	uint32 r, g, b;
-	UNPACK_RGB8(dst, r, g, b);
-	r *= 256 - TEX32_A(src);
-	g *= 256 - TEX32_A(src);
-	b *= 256 - TEX32_A(src);
+	uint8 sr, sg, sb;
+	RenderSurface::_format->colorToRGB(dst, sr, sg, sb);
+
+	uint32 r = sr * (256 - TEX32_A(src));
+	uint32 g = sg * (256 - TEX32_A(src));
+	uint32 b = sb * (256 - TEX32_A(src));
 	r += 256 * TEX32_R(src);
 	g += 256 * TEX32_G(src);
 	b += 256 * TEX32_B(src);
@@ -70,8 +72,8 @@ inline uint32 P_FASTCALL BlendPreModFast(uint32 src, uint32 dst) {
 
 // This does the red highlight blending.
 inline uint32 P_FASTCALL BlendHighlight(uint32 src, uint32 cr, uint32 cg, uint32 cb, uint32 ca, uint32 ica) {
-	uint32 sr, sg, sb;
-	UNPACK_RGB8(src, sr, sg, sb);
+	uint8 sr, sg, sb;
+	RenderSurface::_format->colorToRGB(src, sr, sg, sb);
 	return RenderSurface::_format->RGBToColor((sr * ica + cr * ca) >> 8,
 											  (sg * ica + cg * ca) >> 8,
 											  (sb * ica + cb * ca) >> 8);
@@ -79,10 +81,10 @@ inline uint32 P_FASTCALL BlendHighlight(uint32 src, uint32 cr, uint32 cg, uint32
 
 // This does the invisible blending. I've set it to about 40%
 inline uint32 P_FASTCALL BlendInvisible(uint32 src, uint32 dst) {
-	uint32 sr, sg, sb;
-	uint32 dr, dg, db;
-	UNPACK_RGB8(src, sr, sg, sb);
-	UNPACK_RGB8(dst, dr, dg, db);
+	uint8 sr, sg, sb;
+	uint8 dr, dg, db;
+	RenderSurface::_format->colorToRGB(src, sr, sg, sb);
+	RenderSurface::_format->colorToRGB(dst, dr, dg, db);
 	return RenderSurface::_format->RGBToColor((sr * 100 + dr * 156) >> 8,
 											  (sg * 100 + dg * 156) >> 8,
 											  (sb * 100 + db * 156) >> 8);
@@ -90,10 +92,10 @@ inline uint32 P_FASTCALL BlendInvisible(uint32 src, uint32 dst) {
 
 // This does the translucent highlight blending. (50%)
 inline uint32 P_FASTCALL BlendHighlightInvis(uint32 src, uint32 dst, uint32 cr, uint32 cg, uint32 cb, uint32 ca, uint32 ica) {
-	uint32 sr, sg, sb;
-	uint32 dr, dg, db;
-	UNPACK_RGB8(src, sr, sg, sb);
-	UNPACK_RGB8(dst, dr, dg, db);
+	uint8 sr, sg, sb;
+	uint8 dr, dg, db;
+	RenderSurface::_format->colorToRGB(src, sr, sg, sb);
+	RenderSurface::_format->colorToRGB(dst, dr, dg, db);
 	return RenderSurface::_format->RGBToColor((((sr * ica + cr * ca) >> 1) + (dr << 7)) >> 8,
 											  (((sg * ica + cg * ca) >> 1) + (dg << 7)) >> 8,
 											  (((sb * ica + cb * ca) >> 1) + (db << 7)) >> 8);


Commit: 4b594af6821ae16842e8f51cd4a3850804d0a55f
    https://github.com/scummvm/scummvm/commit/4b594af6821ae16842e8f51cd4a3850804d0a55f
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2022-12-16T17:58:24-06:00

Commit Message:
ULTIMA8: Replace U8PixelFormat with Graphics::PixelFormat

Changed paths:
    engines/ultima/ultima8/graphics/render_surface.cpp
    engines/ultima/ultima8/graphics/render_surface.h
    engines/ultima/ultima8/graphics/soft_render_surface.cpp
    engines/ultima/ultima8/ultima8.h


diff --git a/engines/ultima/ultima8/graphics/render_surface.cpp b/engines/ultima/ultima8/graphics/render_surface.cpp
index 690b07f8227..3cfa8ebe569 100644
--- a/engines/ultima/ultima8/graphics/render_surface.cpp
+++ b/engines/ultima/ultima8/graphics/render_surface.cpp
@@ -31,7 +31,7 @@
 namespace Ultima {
 namespace Ultima8 {
 
-U8PixelFormat *RenderSurface::_format = nullptr;
+Graphics::PixelFormat *RenderSurface::_format = nullptr;
 
 uint8 RenderSurface::_gamma10toGamma22[256];
 uint8 RenderSurface::_gamma22toGamma10[256];
@@ -55,51 +55,9 @@ RenderSurface::RenderSurface(Graphics::ManagedSurface *s) : _pixels(nullptr), _p
 		RenderSurface::_format->gShift = _surface->format.gShift;
 		RenderSurface::_format->bShift = _surface->format.bShift;
 		RenderSurface::_format->aShift = _surface->format.aShift;
-		RenderSurface::_format->rMask = _surface->format.rMax() << _surface->format.rShift;
-		RenderSurface::_format->gMask = _surface->format.gMax() << _surface->format.gShift;
-		RenderSurface::_format->bMask = _surface->format.bMax() << _surface->format.bShift;
-		RenderSurface::_format->aMask = _surface->format.aMax() << _surface->format.aShift;
 	}
 
 	SetPixelsPointer();
-
-	// Trickery to get the alpha channel
-	if (_format->aMask == 0 && _surface->format.bytesPerPixel == 4) {
-		uint32 mask = ~(_format->rMask | _format->gMask | _format->bMask);
-
-		// Using all bits????
-		if (!mask)
-			return;
-
-		// Check the mask to make sure that it's 'sane'
-		int i;
-		int last = 0;
-		int first = 0;
-		int zero = 32;
-
-		for (i = 0; i < 32; i++) {
-			if ((1 << i) & mask) {
-				last = first = i;
-				break;
-			}
-		}
-
-		for (; i < 32; i++) {
-			if ((1 << i) & mask)
-				last = i;
-			else if (i < zero)
-				zero = i;
-		}
-
-		// something screwy going on
-		if (zero < last)
-			return;
-
-		// Set it
-		_format->aShift = first;
-		_format->aLoss = 8 - (last + 1 - first);
-		_format->aMask = mask;
-	}
 }
 
 //
diff --git a/engines/ultima/ultima8/graphics/render_surface.h b/engines/ultima/ultima8/graphics/render_surface.h
index 91181af7bc6..c26f823962b 100644
--- a/engines/ultima/ultima8/graphics/render_surface.h
+++ b/engines/ultima/ultima8/graphics/render_surface.h
@@ -38,15 +38,6 @@ struct Palette;
 struct Rect;
 class Scaler;
 
-struct U8PixelFormat : Graphics::PixelFormat {
-	// Extend with some extra attributes
-	uint32  rMask, gMask, bMask, aMask;
-
-	inline U8PixelFormat() : Graphics::PixelFormat(),
-		rMask(0), gMask(0), bMask(0), aMask(0) {
-	}
-};
-
 //
 // RenderSurface
 //
@@ -79,7 +70,7 @@ protected:
 	void SetPixelsPointer();
 
 public:
-	static U8PixelFormat *_format;
+	static Graphics::PixelFormat *_format;
 
 	static uint8 _gamma10toGamma22[256];
 	static uint8 _gamma22toGamma10[256];
diff --git a/engines/ultima/ultima8/graphics/soft_render_surface.cpp b/engines/ultima/ultima8/graphics/soft_render_surface.cpp
index d5a0f496eca..a9ba6316276 100644
--- a/engines/ultima/ultima8/graphics/soft_render_surface.cpp
+++ b/engines/ultima/ultima8/graphics/soft_render_surface.cpp
@@ -68,6 +68,7 @@ template<class uintX> void SoftRenderSurface<uintX>::Fill32(uint32 rgb, int32 sx
 //#define CHECK_ALPHA_FILLS
 
 template<class uintX> void SoftRenderSurface<uintX>::FillAlpha(uint8 alpha, int32 sx, int32 sy, int32 w, int32 h) {
+	uint32 aMask = _format->aMax() << _format->aShift;
 	Rect rect(sx, sy, sx + w, sy + h);
 	rect.clip(_clipWindow);
 	sx = rect.left;
@@ -75,7 +76,8 @@ template<class uintX> void SoftRenderSurface<uintX>::FillAlpha(uint8 alpha, int3
 	w = rect.width();
 	h = rect.height();
 
-	if (!w || !h || !RenderSurface::_format->aMask) return;
+	if (!w || !h || !aMask)
+		return;
 
 	// An optimization.
 	if ((int)(w * sizeof(uintX)) == _pitch) {
@@ -89,7 +91,7 @@ template<class uintX> void SoftRenderSurface<uintX>::FillAlpha(uint8 alpha, int3
 	uint8 *line_end = pixel + w * sizeof(uintX);
 	int diff = _pitch - w * sizeof(uintX);
 
-	uintX a = (((uintX)alpha) << RenderSurface::_format->aShift)&RenderSurface::_format->aMask;
+	uintX a = (((uintX)alpha) << RenderSurface::_format->aShift) & aMask;
 
 #ifdef CHECK_ALPHA_FILLS
 	uintX c;
@@ -106,7 +108,7 @@ template<class uintX> void SoftRenderSurface<uintX>::FillAlpha(uint8 alpha, int3
 	while (pixel != end) {
 		while (pixel != line_end) {
 			uintX *dest = reinterpret_cast<uintX *>(pixel);
-			*dest = (*dest & ~RenderSurface::_format->aMask) | a;
+			*dest = (*dest & ~aMask) | a;
 #ifdef CHECK_ALPHA_FILLS
 			*dest = (*dest & ~m) | (c + (((*dest & m) >> 1)&m));
 #endif
@@ -147,6 +149,7 @@ template<class uintX> void SoftRenderSurface<uintX>::FillBlended(uint32 rgba, in
 	uint8 *line_end = pixel + w * sizeof(uintX);
 	int diff = _pitch - w * sizeof(uintX);
 
+	uint32 aMask = _format->aMax() << _format->aShift;
 	int alpha = TEX32_A(rgba) + 1;
 	rgba = TEX32_PACK_RGBA16(TEX32_R(rgba) * alpha, TEX32_G(rgba) * alpha, TEX32_B(rgba) * alpha, 255 * alpha);
 
@@ -154,7 +157,7 @@ template<class uintX> void SoftRenderSurface<uintX>::FillBlended(uint32 rgba, in
 		while (pixel != line_end) {
 			uintX *dest = reinterpret_cast<uintX *>(pixel);
 			uintX d = *dest;
-			*dest = (d & RenderSurface::_format->aMask) | BlendPreModFast(rgba, d);
+			*dest = (d & aMask) | BlendPreModFast(rgba, d);
 			pixel += sizeof(uintX);
 		}
 
@@ -416,6 +419,7 @@ template<class uintX> void SoftRenderSurface<uintX>::MaskedBlit(const Graphics::
 	uint32 g = (TEX32_G(col32) * a);
 	uint32 b = (TEX32_B(col32) * a);
 
+	uint32 aMask = _format->aMax() << _format->aShift;
 	int texbpp = src.rawSurface().format.bpp();
 
 	if (texbpp == 32) {
@@ -428,7 +432,7 @@ template<class uintX> void SoftRenderSurface<uintX>::MaskedBlit(const Graphics::
 					uintX *dest = reinterpret_cast<uintX *>(pixel);
 
 					if (*texel & TEX32_A_MASK) {
-						if (!RenderSurface::_format->aMask || (*dest & RenderSurface::_format->aMask)) {
+						if (!aMask || (*dest & aMask)) {
 							*dest = static_cast<uintX>(
 								_format->RGBToColor(
 									(TEX32_R(*texel) * ia + r) >> 8,
@@ -443,7 +447,7 @@ template<class uintX> void SoftRenderSurface<uintX>::MaskedBlit(const Graphics::
 				while (pixel != line_end) {
 					uintX *dest = reinterpret_cast<uintX *>(pixel);
 
-					if (!RenderSurface::_format->aMask || (*dest & RenderSurface::_format->aMask)) {
+					if (!aMask || (*dest & aMask)) {
 						uint32 alpha = *texel & TEX32_A_MASK;
 						if (alpha == 0xFF) {
 							*dest = static_cast<uintX>(
@@ -485,7 +489,7 @@ template<class uintX> void SoftRenderSurface<uintX>::MaskedBlit(const Graphics::
 
 				// Uh, not completely supported right now
 				//if ((*texel & RenderSurface::_format->a_mask) && (*dest & RenderSurface::_format->a_mask))
-				if (*dest & RenderSurface::_format->aMask) {
+				if (*dest & aMask) {
 					*dest = BlendHighlight(*texel, r, g, b, 1, ia);
 				}
 				pixel += sizeof(uintX);
diff --git a/engines/ultima/ultima8/ultima8.h b/engines/ultima/ultima8/ultima8.h
index 6bc5e047d90..0fe4f435c64 100644
--- a/engines/ultima/ultima8/ultima8.h
+++ b/engines/ultima/ultima8/ultima8.h
@@ -375,7 +375,7 @@ public:
 		return _interpolate;
 	}
 public:
-	U8PixelFormat _renderFormat;
+	Graphics::PixelFormat _renderFormat;
 };
 
 } // End of namespace Ultima8




More information about the Scummvm-git-logs mailing list