[Scummvm-git-logs] scummvm master -> acac282f6f142ef87c9ba46dbd81e9addb99cbcb

mgerhardy noreply at scummvm.org
Thu Oct 10 09:31:59 UTC 2024


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

Summary:
059f0ca1d2 BACKENDS: added imgui window for showing a Graphics::Palette instance
1a219466b1 TWINE: palette code was moved into ImGuiEx
4daa450779 TWINE: added helper functions for loading palettes from hqr
9ea3637f4e TWINE: started to use Graphics::Palette
2e5e3e3b7c TWINE: renamed method to match original sources
e846600f51 TWINE: allow to set a Graphics::Palette instance directly
acac282f6f TWINE: use Graphics::Palette for fadePalToPal


Commit: 059f0ca1d28fe3b09d0d1f72aa27ae62acbdb722
    https://github.com/scummvm/scummvm/commit/059f0ca1d28fe3b09d0d1f72aa27ae62acbdb722
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2024-10-10T11:31:39+02:00

Commit Message:
BACKENDS: added imgui window for showing a Graphics::Palette instance

Changed paths:
  A backends/imgui/imgui_utils.cpp
    backends/imgui/imgui_utils.h
    backends/module.mk


diff --git a/backends/imgui/imgui_utils.cpp b/backends/imgui/imgui_utils.cpp
new file mode 100644
index 00000000000..5de529b5829
--- /dev/null
+++ b/backends/imgui/imgui_utils.cpp
@@ -0,0 +1,69 @@
+/* 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/>.
+ *
+ */
+
+#include "backends/imgui/imgui_utils.h"
+
+namespace ImGuiEx {
+
+void Boolean(bool val) {
+	if (val) {
+		ImGui::Text(ICON_MS_CHECK_BOX);
+	} else {
+		ImGui::Text(ICON_MS_CHECK_BOX_OUTLINE_BLANK);
+	}
+}
+
+void Palette(const Graphics::Palette &palette) {
+	ImDrawList *drawList = ImGui::GetWindowDrawList();
+	const ImDrawListFlags backupFlags = drawList->Flags;
+	drawList->Flags &= ~ImDrawListFlags_AntiAliasedLines;
+	const ImVec2 &pos = ImGui::GetCursorScreenPos();
+	for (uint palettePanelIdx = 0; palettePanelIdx < palette.size(); ++palettePanelIdx) {
+		uint8 r, g, b;
+		palette.get(palettePanelIdx, r, g, b);
+		const float borderWidth = 1.0f;
+		const ImVec2 availableInner = ImGui::GetContentRegionAvail();
+		const float contentRegionWidth = availableInner.x + ImGui::GetCursorPosX();
+		const ImVec2 colorButtonSize(ImGui::GetFrameHeight(), ImGui::GetFrameHeight());
+		ImVec2 globalCursorPos = ImGui::GetCursorScreenPos();
+		const ImVec2 &windowPos = ImGui::GetWindowPos();
+		const ImVec2 v1(globalCursorPos.x + borderWidth, globalCursorPos.y + borderWidth);
+		const ImVec2 v2(globalCursorPos.x + colorButtonSize.x, globalCursorPos.y + colorButtonSize.y);
+		drawList->AddRectFilled(v1, v2, IM_COL32(r, g, b, 255));
+
+		ImGui::PushID((int)palettePanelIdx);
+		if (ImGui::InvisibleButton("", colorButtonSize)) {
+		}
+		ImGui::SetItemTooltip("Index: %i, R(%d), G(%d), B(%d)", (int)palettePanelIdx, (int)r, (int)g, (int)b);
+		ImGui::PopID();
+
+		globalCursorPos.x += colorButtonSize.x;
+		if (globalCursorPos.x > windowPos.x + contentRegionWidth - colorButtonSize.x) {
+			globalCursorPos.x = pos.x;
+			globalCursorPos.y += colorButtonSize.y;
+		}
+		ImGui::SetCursorScreenPos(globalCursorPos);
+	}
+	// restore the draw list flags from above
+	drawList->Flags = backupFlags;
+}
+
+} // namespace ImGuiEx
diff --git a/backends/imgui/imgui_utils.h b/backends/imgui/imgui_utils.h
index af605841b24..417449fce53 100644
--- a/backends/imgui/imgui_utils.h
+++ b/backends/imgui/imgui_utils.h
@@ -22,6 +22,7 @@
 #include "backends/imgui/IconsMaterialSymbols.h"
 
 #include "backends/imgui/imgui.h"
+#include "graphics/palette.h"
 
 namespace ImGuiEx {
 
@@ -35,12 +36,7 @@ bool InputInt(const char *label, INT *v, int step = 1, int step_fast = 100, ImGu
 	return false;
 }
 
-void Boolean(bool val) {
-	if (val) {
-		ImGui::Text(ICON_MS_CHECK_BOX);
-	} else {
-		ImGui::Text(ICON_MS_CHECK_BOX_OUTLINE_BLANK);
-	}
-}
+void Boolean(bool val);
+void Palette(const Graphics::Palette &palette);
 
 } // namespace ImGuiEx
diff --git a/backends/module.mk b/backends/module.mk
index 6ebd426e024..17888680048 100644
--- a/backends/module.mk
+++ b/backends/module.mk
@@ -492,6 +492,7 @@ MODULE_OBJS += \
 	imgui/imgui_fonts.o \
 	imgui/imgui_tables.o \
 	imgui/imgui_widgets.o \
+	imgui/imgui_utils.o \
 	imgui/misc/freetype/imgui_freetype.o
 endif
 


Commit: 1a219466b1c950c2e27a936932c8c436e59a865a
    https://github.com/scummvm/scummvm/commit/1a219466b1c950c2e27a936932c8c436e59a865a
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2024-10-10T11:31:39+02:00

Commit Message:
TWINE: palette code was moved into ImGuiEx

Changed paths:
    engines/twine/debugger/debugtools.cpp


diff --git a/engines/twine/debugger/debugtools.cpp b/engines/twine/debugger/debugtools.cpp
index ddba9115b2c..73aef6ebf60 100644
--- a/engines/twine/debugger/debugtools.cpp
+++ b/engines/twine/debugger/debugtools.cpp
@@ -167,38 +167,6 @@ static void holomapFlagsWindow(TwinEEngine *engine) {
 	ImGui::End();
 }
 
-static void addColor(float startingPosX, uint index, const Graphics::Palette &palette) {
-	uint8 r, g, b;
-	palette.get(index, r, g, b);
-	const float borderWidth = 1.0f;
-	ImDrawList *drawList = ImGui::GetWindowDrawList();
-	const ImDrawListFlags backupFlags = drawList->Flags;
-	drawList->Flags &= ~ImDrawListFlags_AntiAliasedLines;
-	const ImVec2 available = ImGui::GetContentRegionAvail();
-	const float contentRegionWidth = available.x + ImGui::GetCursorPosX();
-	const ImVec2 colorButtonSize(ImGui::GetFrameHeight(), ImGui::GetFrameHeight());
-	ImVec2 globalCursorPos = ImGui::GetCursorScreenPos();
-	const ImVec2 &windowPos = ImGui::GetWindowPos();
-	const ImVec2 v1(globalCursorPos.x + borderWidth, globalCursorPos.y + borderWidth);
-	const ImVec2 v2(globalCursorPos.x + colorButtonSize.x, globalCursorPos.y + colorButtonSize.y);
-	drawList->AddRectFilled(v1, v2, IM_COL32(r, g, b, 255));
-
-	ImGui::PushID((int)index);
-	if (ImGui::InvisibleButton("", colorButtonSize)) {
-	}
-	ImGui::SetItemTooltip("Index: %i, R(%d), G(%d), B(%d)", (int)index, (int)r, (int)g, (int)b);
-	ImGui::PopID();
-
-	globalCursorPos.x += colorButtonSize.x;
-	if (globalCursorPos.x > windowPos.x + contentRegionWidth - colorButtonSize.x) {
-		globalCursorPos.x = startingPosX;
-		globalCursorPos.y += colorButtonSize.y;
-	}
-	ImGui::SetCursorScreenPos(globalCursorPos);
-	// restore the draw list flags from above
-	drawList->Flags = backupFlags;
-}
-
 static void paletteWindow(TwinEEngine *engine) {
 	if (!engine->_debugState->_paletteWindow) {
 		return;
@@ -209,12 +177,9 @@ static void paletteWindow(TwinEEngine *engine) {
 	const ImVec2 windowSize(10.0f * ImGui::GetFrameHeight(), contentRegionHeight);
 	ImGui::SetNextWindowSize(windowSize, ImGuiCond_FirstUseEver);
 
-	if (ImGui::Begin("Palette", &engine->_debugState->_paletteWindow)) {
+	if (ImGui::Begin("Palettes", &engine->_debugState->_paletteWindow)) {
 		const Graphics::Palette &palette = engine->_frontVideoBuffer.getPalette();
-		const ImVec2 &pos = ImGui::GetCursorScreenPos();
-		for (uint palettePanelIdx = 0; palettePanelIdx < palette.size(); ++palettePanelIdx) {
-			addColor(pos.x, palettePanelIdx, palette);
-		}
+		ImGuiEx::Palette(palette);
 	}
 	ImGui::End();
 }


Commit: 4daa4507797a3e6348482b5795b38d31e142c017
    https://github.com/scummvm/scummvm/commit/4daa4507797a3e6348482b5795b38d31e142c017
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2024-10-10T11:31:39+02:00

Commit Message:
TWINE: added helper functions for loading palettes from hqr

Changed paths:
    engines/twine/resources/hqr.cpp
    engines/twine/resources/hqr.h


diff --git a/engines/twine/resources/hqr.cpp b/engines/twine/resources/hqr.cpp
index c73d1c7ab1a..ffb49fcf7b0 100644
--- a/engines/twine/resources/hqr.cpp
+++ b/engines/twine/resources/hqr.cpp
@@ -337,6 +337,16 @@ int32 getVoxEntry(uint8 *ptr, const char *filename, int32 index, int32 hiddenInd
 	return realSize;
 }
 
+bool getPaletteEntry(Graphics::Palette &palette, const char *filename, int32 index) {
+	byte paletteBuffer[NUMOFCOLORS * 3];
+	int32 size = HQR::getEntry(paletteBuffer, filename, index);
+	if (size <= 0) {
+		return false;
+	}
+	palette = Graphics::Palette(paletteBuffer, size / 3);
+	return true;
+}
+
 int32 getAllocVoxEntry(uint8 **ptr, const char *filename, int32 index, int32 hiddenIndex) {
 	const int32 size = voxEntrySize(filename, index, hiddenIndex);
 	if (size == 0) {
diff --git a/engines/twine/resources/hqr.h b/engines/twine/resources/hqr.h
index bf9163cda45..bba336434b1 100644
--- a/engines/twine/resources/hqr.h
+++ b/engines/twine/resources/hqr.h
@@ -24,6 +24,7 @@
 
 #include "common/scummsys.h"
 #include "common/stream.h"
+#include "graphics/palette.h"
 #include "twine/shared.h"
 
 namespace TwinE {
@@ -107,6 +108,11 @@ int32 getVoxEntry(uint8 *ptr, const char *filename, int32 index, int32 hiddenInd
  */
 int32 getAllocVoxEntry(uint8 **ptr, const char *filename, int32 index, int32 hiddenIndex);
 
+bool getPaletteEntry(Graphics::Palette &palette, const char *filename, int32 index);
+inline bool getPaletteEntry(Graphics::Palette &palette, const TwineResource &resource) {
+	return getPaletteEntry(palette, resource.hqr, resource.index);
+}
+
 Common::SeekableReadStream *makeReadStream(const char *filename, int index);
 inline Common::SeekableReadStream *makeReadStream(const TwineResource &resource) {
 	return makeReadStream(resource.hqr, resource.index);


Commit: 9ea3637f4e67c04b47f3a4a64c8f9bc3ba46f320
    https://github.com/scummvm/scummvm/commit/9ea3637f4e67c04b47f3a4a64c8f9bc3ba46f320
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2024-10-10T11:31:39+02:00

Commit Message:
TWINE: started to use Graphics::Palette

Changed paths:
    engines/twine/debugger/debugtools.cpp
    engines/twine/holomap_v1.cpp
    engines/twine/metaengine.cpp
    engines/twine/movies.cpp
    engines/twine/renderer/screens.cpp
    engines/twine/renderer/screens.h
    engines/twine/resources/resources.cpp
    engines/twine/script/script_life.cpp
    engines/twine/script/script_life_v2.cpp


diff --git a/engines/twine/debugger/debugtools.cpp b/engines/twine/debugger/debugtools.cpp
index 73aef6ebf60..d1647af86fc 100644
--- a/engines/twine/debugger/debugtools.cpp
+++ b/engines/twine/debugger/debugtools.cpp
@@ -180,6 +180,9 @@ static void paletteWindow(TwinEEngine *engine) {
 	if (ImGui::Begin("Palettes", &engine->_debugState->_paletteWindow)) {
 		const Graphics::Palette &palette = engine->_frontVideoBuffer.getPalette();
 		ImGuiEx::Palette(palette);
+
+		ImGui::SeparatorText("Last loaded palette");
+		ImGuiEx::Palette(engine->_screens->_palette);
 	}
 	ImGui::End();
 }
diff --git a/engines/twine/holomap_v1.cpp b/engines/twine/holomap_v1.cpp
index 31e8f54459e..96df55c01de 100644
--- a/engines/twine/holomap_v1.cpp
+++ b/engines/twine/holomap_v1.cpp
@@ -126,19 +126,23 @@ void HolomapV1::initHoloDatas() {
 	constexpr TwineResource resource(Resources::HQR_RESS_FILE, RESSHQR_HOLOPAL);
 	_engine->_screens->loadCustomPalette(resource);
 
-	int32 j = HOLOMAP_PALETTE_INDEX * 3;
+	int32 j = HOLOMAP_PALETTE_INDEX;
 	const int32 n = NUM_HOLOMAPCOLORS * 3;
-	for (int32 i = 0; i < n; i += 3, j += 3) {
-		_paletteHolomap[i + 0] = _engine->_screens->_palette[j + 0];
-		_paletteHolomap[i + 1] = _engine->_screens->_palette[j + 1];
-		_paletteHolomap[i + 2] = _engine->_screens->_palette[j + 2];
+	for (int32 i = 0; i < n; i += 3, j++) {
+		byte r, g, b;
+		_engine->_screens->_palette.get(j, r, g, b);
+		_paletteHolomap[i + 0] = r;
+		_paletteHolomap[i + 1] = g;
+		_paletteHolomap[i + 2] = b;
 	}
 
-	j = HOLOMAP_PALETTE_INDEX * 3;
-	for (int32 i = n; i < 2 * n - 3; i += 3, j += 3) {
-		_paletteHolomap[i + 0] = _engine->_screens->_palette[j + 0];
-		_paletteHolomap[i + 1] = _engine->_screens->_palette[j + 1];
-		_paletteHolomap[i + 2] = _engine->_screens->_palette[j + 2];
+	j = HOLOMAP_PALETTE_INDEX;
+	for (int32 i = n; i < 2 * n - 3; i += 3, j++) {
+		byte r, g, b;
+		_engine->_screens->_palette.get(j, r, g, b);
+		_paletteHolomap[i + 0] = r;
+		_paletteHolomap[i + 1] = g;
+		_paletteHolomap[i + 2] = b;
 	}
 
 	computeCoorMapping();
diff --git a/engines/twine/metaengine.cpp b/engines/twine/metaengine.cpp
index cde7ec4b0f8..5ef79f7f873 100644
--- a/engines/twine/metaengine.cpp
+++ b/engines/twine/metaengine.cpp
@@ -195,7 +195,7 @@ void TwinEMetaEngine::getSavegameThumbnail(Graphics::Surface &thumb) {
 	TwinEEngine *engine = (TwinEEngine *)g_engine;
 	const Graphics::ManagedSurface &managedSurface = engine->_workVideoBuffer;
 	const Graphics::Surface &screenSurface = managedSurface.rawSurface();
-	::createThumbnail(&thumb, (const uint8 *)screenSurface.getPixels(), screenSurface.w, screenSurface.h, engine->_screens->_palette);
+	::createThumbnail(&thumb, (const uint8 *)screenSurface.getPixels(), screenSurface.w, screenSurface.h, engine->_screens->_palette.data());
 }
 
 //
diff --git a/engines/twine/movies.cpp b/engines/twine/movies.cpp
index e7f7b07cbc9..d60d5be6c9d 100644
--- a/engines/twine/movies.cpp
+++ b/engines/twine/movies.cpp
@@ -26,6 +26,7 @@
 #include "common/str.h"
 #include "common/system.h"
 #include "graphics/managed_surface.h"
+#include "graphics/palette.h"
 #include "image/gif.h"
 #include "twine/audio/music.h"
 #include "twine/audio/sound.h"
@@ -187,8 +188,17 @@ void Movies::drawNextFrameFla() {
 		case kLoadPalette: {
 			int16 numOfColor = stream.readSint16LE();
 			int16 startColor = stream.readSint16LE();
-			uint8 *dest = _engine->_screens->_palette + (startColor * 3);
-			stream.read(dest, numOfColor * 3);
+			if (_engine->_screens->_palette.size() < (uint)(numOfColor + startColor)) {
+				Graphics::Palette palette(numOfColor + startColor);
+				palette.set(_engine->_screens->_palette, 0, _engine->_screens->_palette.size());
+				_engine->_screens->_palette = palette;
+			}
+			for (int16 i = 0; i < numOfColor; ++i) {
+				const byte r = stream.readByte();
+				const byte g = stream.readByte();
+				const byte b = stream.readByte();
+				_engine->_screens->_palette.set(i + startColor, r, g, b);
+			}
 			break;
 		}
 		case kInfo: {
@@ -201,7 +211,7 @@ void Movies::drawNextFrameFla() {
 				// FLA movies don't use cross fade
 				// fade out tricky
 				if (_fadeOut != 1) {
-					_engine->_screens->convertPalToRGBA(_engine->_screens->_palette, _engine->_screens->_palettePcx);
+					_engine->_screens->convertPalToRGBA(_engine->_screens->_palette.data(), _engine->_screens->_palettePcx);
 					_engine->_screens->fadeToBlack(_engine->_screens->_palettePcx);
 					_fadeOut = 1;
 				}
@@ -424,7 +434,7 @@ bool Movies::playMovie(const char *name) { // PlayAnimFla
 
 			// Only blit to screen if isn't a fade
 			if (_fadeOut == -1) {
-				_engine->_screens->convertPalToRGBA(_engine->_screens->_palette, _engine->_screens->_palettePcx);
+				_engine->_screens->convertPalToRGBA(_engine->_screens->_palette.data(), _engine->_screens->_palettePcx);
 				if (currentFrame == 0) {
 					// fade in the first frame
 					_engine->_screens->fadeIn(_engine->_screens->_palettePcx);
@@ -435,7 +445,7 @@ bool Movies::playMovie(const char *name) { // PlayAnimFla
 
 			// TRICKY: fade in tricky
 			if (_fadeOutFrames >= 2) {
-				_engine->_screens->convertPalToRGBA(_engine->_screens->_palette, _engine->_screens->_palettePcx);
+				_engine->_screens->convertPalToRGBA(_engine->_screens->_palette.data(), _engine->_screens->_palettePcx);
 				_engine->_screens->fadeToPal(_engine->_screens->_palettePcx);
 				_fadeOut = -1;
 				_fadeOutFrames = 0;
diff --git a/engines/twine/renderer/screens.cpp b/engines/twine/renderer/screens.cpp
index 1c63a0c3a75..87155bf89d6 100644
--- a/engines/twine/renderer/screens.cpp
+++ b/engines/twine/renderer/screens.cpp
@@ -25,6 +25,7 @@
 #include "common/system.h"
 #include "common/util.h"
 #include "graphics/managed_surface.h"
+#include "graphics/palette.h"
 #include "graphics/pixelformat.h"
 #include "graphics/surface.h"
 #include "image/bmp.h"
@@ -33,6 +34,7 @@
 #include "twine/audio/music.h"
 #include "twine/resources/hqr.h"
 #include "twine/resources/resources.h"
+#include "twine/shared.h"
 #include "twine/twine.h"
 
 namespace TwinE {
@@ -62,16 +64,15 @@ void Screens::loadMenuImage(bool fadeIn) {
 }
 
 void Screens::loadCustomPalette(const TwineResource &resource) {
-	const int32 size = HQR::getEntry(_palette, resource.hqr, resource.index);
-	if (size == 0) {
-		warning("Failed to load custom palette %s:%i", resource.hqr, resource.index);
-		return;
+	if (!HQR::getPaletteEntry(_palette, resource)) {
+		error("Failed to get palette entry for custom palette: %s:%d", resource.hqr, resource.index);
 	}
-	if (size != (int32)sizeof(_palette)) {
+
+	if (_palette.size() != NUMOFCOLORS) {
 		warning("Unexpected palette size %s:%i", resource.hqr, resource.index);
 	}
-	debug(3, "palette %s:%i with size %i", resource.hqr, resource.index, size);
-	convertPalToRGBA(_palette, _palettePcx);
+	debug(3, "palette %s:%i with %u colors", resource.hqr, resource.index, _palette.size());
+	convertPalToRGBA(_palette.data(), _palettePcx);
 }
 
 void Screens::convertPalToRGBA(const uint8 *in, uint32 *out) {
@@ -304,8 +305,10 @@ void Screens::blackToWhite() {
 
 void Screens::setDarkPal() {
 	ScopedEngineFreeze scoped(_engine);
-	HQR::getEntry(_palette, Resources::HQR_RESS_FILE, RESSHQR_DARKPAL);
-	convertPalToRGBA(_palette, _ptrPal);
+	if (!HQR::getPaletteEntry(_palette, Resources::HQR_RESS_FILE, RESSHQR_DARKPAL)) {
+		error("Failed to get palette entry for dark palette");
+	}
+	convertPalToRGBA(_palette.data(), _ptrPal);
 	if (!_flagFade) {
 		// set the palette hard if it should not get faded
 		_engine->setPalette(_ptrPal);
@@ -322,7 +325,7 @@ void Screens::setNormalPal() {
 }
 
 void Screens::setBlackPal() {
-	memset(_palette, 0, sizeof(_palette));
+	_palette.clear();
 	memset(_ptrPal, 0, sizeof(_ptrPal));
 
 	_engine->setPalette(_ptrPal);
diff --git a/engines/twine/renderer/screens.h b/engines/twine/renderer/screens.h
index 89c6e53d4a0..17123cdb988 100644
--- a/engines/twine/renderer/screens.h
+++ b/engines/twine/renderer/screens.h
@@ -24,6 +24,7 @@
 
 #include "common/scummsys.h"
 #include "graphics/managed_surface.h"
+#include "graphics/palette.h"
 #include "graphics/surface.h"
 #include "twine/twine.h"
 
@@ -48,7 +49,7 @@ public:
 	Screens(TwinEEngine *engine) : _engine(engine) {}
 
 	/** In-game palette (should not be used, except in special case. otherwise use other images functions instead) */
-	uint8 _palette[NUMOFCOLORS * 3]{0};
+	Graphics::Palette _palette{0};
 
 	int32 mapLba2Palette(int32 palIndex);
 
diff --git a/engines/twine/resources/resources.cpp b/engines/twine/resources/resources.cpp
index 9de9c63b8b2..1f0b203779d 100644
--- a/engines/twine/resources/resources.cpp
+++ b/engines/twine/resources/resources.cpp
@@ -23,6 +23,7 @@
 #include "common/file.h"
 #include "common/tokenizer.h"
 #include "common/util.h"
+#include "graphics/palette.h"
 #include "twine/audio/sound.h"
 #include "twine/parser/anim3ds.h"
 #include "twine/renderer/renderer.h"
@@ -30,6 +31,7 @@
 #include "twine/resources/hqr.h"
 #include "twine/scene/animations.h"
 #include "twine/scene/scene.h"
+#include "twine/shared.h"
 #include "twine/text.h"
 #include "twine/twine.h"
 
@@ -47,18 +49,12 @@ Resources::~Resources() {
 }
 
 void Resources::initPalettes() {
-	uint8 *mainPalette = nullptr;
-	const int32 size = HQR::getAllocEntry(&mainPalette, Resources::HQR_RESS_FILE, RESSHQR_MAINPAL);
-	if (size == 0) {
+	if (!HQR::getPaletteEntry(_engine->_screens->_palette, Resources::HQR_RESS_FILE, RESSHQR_MAINPAL)) {
 		error("Failed to load main palette");
 	}
-	_engine->_screens->convertPalToRGBA(mainPalette, _engine->_screens->_mainPaletteRGBA);
-
-	memcpy(_engine->_screens->_palette, mainPalette, NUMOFCOLORS * 3);
-
-	_engine->_screens->convertPalToRGBA(_engine->_screens->_palette, _engine->_screens->_ptrPal);
+	_engine->_screens->convertPalToRGBA(_engine->_screens->_palette.data(), _engine->_screens->_mainPaletteRGBA);
+	_engine->_screens->convertPalToRGBA(_engine->_screens->_palette.data(), _engine->_screens->_ptrPal);
 	_engine->setPalette(_engine->_screens->_ptrPal);
-	free(mainPalette);
 }
 
 void Resources::preloadAnim3DS() {
diff --git a/engines/twine/script/script_life.cpp b/engines/twine/script/script_life.cpp
index 322939ca282..4474754f68e 100644
--- a/engines/twine/script/script_life.cpp
+++ b/engines/twine/script/script_life.cpp
@@ -1770,8 +1770,8 @@ int32 ScriptLife::lFADE_PAL_RED(TwinEEngine *engine, LifeScriptContext &ctx) {
 int32 ScriptLife::lFADE_ALARM_RED(TwinEEngine *engine, LifeScriptContext &ctx) {
 	debugC(3, kDebugLevels::kDebugScripts, "LIFE::FADE_ALARM_RED()");
 	ScopedEngineFreeze scoped(engine);
-	HQR::getEntry(engine->_screens->_palette, Resources::HQR_RESS_FILE, RESSHQR_ALARMREDPAL);
-	engine->_screens->convertPalToRGBA(engine->_screens->_palette, engine->_screens->_ptrPal);
+	HQR::getPaletteEntry(engine->_screens->_palette, Resources::HQR_RESS_FILE, RESSHQR_ALARMREDPAL);
+	engine->_screens->convertPalToRGBA(engine->_screens->_palette.data(), engine->_screens->_ptrPal);
 	engine->_screens->fadeToRed(engine->_screens->_ptrPal);
 	engine->_screens->_flagPalettePcx = true;
 	return 0;
@@ -1784,8 +1784,8 @@ int32 ScriptLife::lFADE_ALARM_RED(TwinEEngine *engine, LifeScriptContext &ctx) {
 int32 ScriptLife::lFADE_ALARM_PAL(TwinEEngine *engine, LifeScriptContext &ctx) {
 	debugC(3, kDebugLevels::kDebugScripts, "LIFE::FADE_ALARM_PAL()");
 	ScopedEngineFreeze scoped(engine);
-	HQR::getEntry(engine->_screens->_palette, Resources::HQR_RESS_FILE, RESSHQR_ALARMREDPAL);
-	engine->_screens->convertPalToRGBA(engine->_screens->_palette, engine->_screens->_ptrPal);
+	HQR::getPaletteEntry(engine->_screens->_palette, Resources::HQR_RESS_FILE, RESSHQR_ALARMREDPAL);
+	engine->_screens->convertPalToRGBA(engine->_screens->_palette.data(), engine->_screens->_ptrPal);
 	engine->_screens->fadePalToPal(engine->_screens->_ptrPal, engine->_screens->_mainPaletteRGBA);
 	engine->_screens->_flagPalettePcx = false;
 	return 0;
@@ -1810,8 +1810,8 @@ int32 ScriptLife::lFADE_RED_PAL(TwinEEngine *engine, LifeScriptContext &ctx) {
 int32 ScriptLife::lFADE_RED_ALARM(TwinEEngine *engine, LifeScriptContext &ctx) {
 	debugC(3, kDebugLevels::kDebugScripts, "LIFE::FADE_RED_ALARM()");
 	ScopedEngineFreeze scoped(engine);
-	HQR::getEntry(engine->_screens->_palette, Resources::HQR_RESS_FILE, RESSHQR_ALARMREDPAL);
-	engine->_screens->convertPalToRGBA(engine->_screens->_palette, engine->_screens->_ptrPal);
+	HQR::getPaletteEntry(engine->_screens->_palette, Resources::HQR_RESS_FILE, RESSHQR_ALARMREDPAL);
+	engine->_screens->convertPalToRGBA(engine->_screens->_palette.data(), engine->_screens->_ptrPal);
 	engine->_screens->fadeRedToPal(engine->_screens->_ptrPal);
 	engine->_screens->_flagPalettePcx = true;
 	return 0;
@@ -1824,8 +1824,8 @@ int32 ScriptLife::lFADE_RED_ALARM(TwinEEngine *engine, LifeScriptContext &ctx) {
 int32 ScriptLife::lFADE_PAL_ALARM(TwinEEngine *engine, LifeScriptContext &ctx) {
 	debugC(3, kDebugLevels::kDebugScripts, "LIFE::FADE_PAL_ALARM()");
 	ScopedEngineFreeze scoped(engine);
-	HQR::getEntry(engine->_screens->_palette, Resources::HQR_RESS_FILE, RESSHQR_ALARMREDPAL);
-	engine->_screens->convertPalToRGBA(engine->_screens->_palette, engine->_screens->_ptrPal);
+	HQR::getPaletteEntry(engine->_screens->_palette, Resources::HQR_RESS_FILE, RESSHQR_ALARMREDPAL);
+	engine->_screens->convertPalToRGBA(engine->_screens->_palette.data(), engine->_screens->_ptrPal);
 	engine->_screens->fadePalToPal(engine->_screens->_mainPaletteRGBA, engine->_screens->_ptrPal);
 	engine->_screens->_flagPalettePcx = true;
 	return 0;
diff --git a/engines/twine/script/script_life_v2.cpp b/engines/twine/script/script_life_v2.cpp
index 97da5e9da13..1e945c254a5 100644
--- a/engines/twine/script/script_life_v2.cpp
+++ b/engines/twine/script/script_life_v2.cpp
@@ -202,8 +202,8 @@ int32 ScriptLifeV2::lPALETTE(TwinEEngine *engine, LifeScriptContext &ctx) {
 	const int32 palIndex = engine->_screens->mapLba2Palette(ctx.stream.readByte());
 	debugC(3, kDebugLevels::kDebugScripts, "LIFE::PALETTE(%i)", palIndex);
 	ScopedEngineFreeze scoped(engine);
-	HQR::getEntry(engine->_screens->_palette, Resources::HQR_RESS_FILE, palIndex);
-	engine->_screens->convertPalToRGBA(engine->_screens->_palette, engine->_screens->_ptrPal);
+	HQR::getPaletteEntry(engine->_screens->_palette, Resources::HQR_RESS_FILE, palIndex);
+	engine->_screens->convertPalToRGBA(engine->_screens->_palette.data(), engine->_screens->_ptrPal);
 	engine->setPalette(engine->_screens->_ptrPal);
 	engine->_screens->_flagPalettePcx = true;
 	return 0;


Commit: 2e5e3e3b7cd37e2b0f9f1668aa38c11795b73e72
    https://github.com/scummvm/scummvm/commit/2e5e3e3b7cd37e2b0f9f1668aa38c11795b73e72
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2024-10-10T11:31:39+02:00

Commit Message:
TWINE: renamed method to match original sources

Changed paths:
    engines/twine/renderer/screens.cpp
    engines/twine/renderer/screens.h


diff --git a/engines/twine/renderer/screens.cpp b/engines/twine/renderer/screens.cpp
index 87155bf89d6..91a85d259cf 100644
--- a/engines/twine/renderer/screens.cpp
+++ b/engines/twine/renderer/screens.cpp
@@ -111,7 +111,7 @@ void Screens::loadImage(TwineImage image, bool fadeIn) {
 bool Screens::loadImageDelay(TwineImage image, int32 seconds) {
 	loadImage(image);
 	if (_engine->delaySkip(1000 * seconds)) {
-		adjustPalette(0, 0, 0, _palettePcx, 100);
+		fadePal(0, 0, 0, _palettePcx, 100);
 		return true;
 	}
 	fadeOut(_palettePcx);
@@ -200,7 +200,7 @@ int32 Screens::lerp(int32 val1, int32 val2, int32 nbstep, int32 step) {  // Regl
 	return (((val2 - val1) * step) / nbstep) + val1;
 }
 
-void Screens::adjustPalette(uint8 r, uint8 g, uint8 b, const uint32 *rgbaPal, int32 intensity) {
+void Screens::fadePal(uint8 r, uint8 g, uint8 b, const uint32 *rgbaPal, int32 intensity) {
 	uint32 pal[NUMOFCOLORS];
 
 	int32 counter = 0;
@@ -275,7 +275,7 @@ void Screens::fadeToBlack(const uint32 *pal) {
 
 	for (int32 i = 100; i >= 0; i -= 3) {
 		FrameMarker frame(_engine, DEFAULT_HZ);
-		adjustPalette(0, 0, 0, pal, i);
+		fadePal(0, 0, 0, pal, i);
 	}
 
 	_palResetted = true;
@@ -284,7 +284,7 @@ void Screens::fadeToBlack(const uint32 *pal) {
 void Screens::fadeToPal(const uint32 *pal) {
 	for (int32 i = 0; i <= 100; i += 3) {
 		FrameMarker frame(_engine, DEFAULT_HZ);
-		adjustPalette(0, 0, 0, pal, i);
+		fadePal(0, 0, 0, pal, i);
 	}
 
 	_engine->setPalette(pal);
@@ -336,14 +336,14 @@ void Screens::setBlackPal() {
 void Screens::fadeToRed(const uint32 *pal) {
 	for (int32 i = 100; i >= 0; i -= 2) {
 		FrameMarker frame(_engine, DEFAULT_HZ);
-		adjustPalette(0xFF, 0, 0, pal, i);
+		fadePal(0xFF, 0, 0, pal, i);
 	}
 }
 
 void Screens::fadeRedToPal(const uint32 *pal) {
 	for (int32 i = 0; i <= 100; i += 2) {
 		FrameMarker frame(_engine, DEFAULT_HZ);
-		adjustPalette(0xFF, 0, 0, pal, i);
+		fadePal(0xFF, 0, 0, pal, i);
 	}
 }
 
diff --git a/engines/twine/renderer/screens.h b/engines/twine/renderer/screens.h
index 17123cdb988..bf995a177f8 100644
--- a/engines/twine/renderer/screens.h
+++ b/engines/twine/renderer/screens.h
@@ -43,7 +43,7 @@ private:
 	 * @param palette palette to adjust
 	 * @param intensity intensity value to adjust
 	 */
-	void adjustPalette(uint8 r, uint8 g, uint8 b, const uint32 *palette, int32 intensity);
+	void fadePal(uint8 r, uint8 g, uint8 b, const uint32 *palette, int32 intensity);
 
 public:
 	Screens(TwinEEngine *engine) : _engine(engine) {}


Commit: e846600f519127357a0acd44d49ba412ecc84c15
    https://github.com/scummvm/scummvm/commit/e846600f519127357a0acd44d49ba412ecc84c15
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2024-10-10T11:31:39+02:00

Commit Message:
TWINE: allow to set a Graphics::Palette instance directly

Changed paths:
    engines/twine/twine.cpp
    engines/twine/twine.h


diff --git a/engines/twine/twine.cpp b/engines/twine/twine.cpp
index 97a057c6110..eeddcbcf77e 100644
--- a/engines/twine/twine.cpp
+++ b/engines/twine/twine.cpp
@@ -1261,6 +1261,10 @@ void TwinEEngine::setPalette(const uint32 *palette) {
 	setPalette(0, NUMOFCOLORS, pal);
 }
 
+void TwinEEngine::setPalette(const Graphics::Palette &palette, uint startColor) {
+	_frontVideoBuffer.setPalette(palette, startColor);
+}
+
 void TwinEEngine::setPalette(uint startColor, uint numColors, const byte *palette) {
 	if (numColors == 0 || palette == nullptr) {
 		warning("Could not set palette");
diff --git a/engines/twine/twine.h b/engines/twine/twine.h
index 00b8e644703..b5deba539b3 100644
--- a/engines/twine/twine.h
+++ b/engines/twine/twine.h
@@ -378,6 +378,8 @@ public:
 	 * @param palette palette to set in RGBA
 	 */
 	void setPalette(const uint32 *palette);
+	void setPalette(const Graphics::Palette &palette, uint startColor = 0u);
+
 	/**
 	 * @brief Set the Palette object
 	 *


Commit: acac282f6f142ef87c9ba46dbd81e9addb99cbcb
    https://github.com/scummvm/scummvm/commit/acac282f6f142ef87c9ba46dbd81e9addb99cbcb
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2024-10-10T11:31:39+02:00

Commit Message:
TWINE: use Graphics::Palette for fadePalToPal

Changed paths:
    engines/twine/renderer/screens.cpp


diff --git a/engines/twine/renderer/screens.cpp b/engines/twine/renderer/screens.cpp
index 91a85d259cf..5599bbf567d 100644
--- a/engines/twine/renderer/screens.cpp
+++ b/engines/twine/renderer/screens.cpp
@@ -231,33 +231,22 @@ void Screens::fadePal(uint8 r, uint8 g, uint8 b, const uint32 *rgbaPal, int32 in
 }
 
 void Screens::fadePalToPal(const uint32 *ptrpal, const uint32 *ptrpal2) {
-	uint32 workpal[NUMOFCOLORS];
+	Graphics::Palette workpal{NUMOFCOLORS};
 
 	int32 counter = 0;
 	int32 intensity = 0;
 
 	const uint8 *pal1p = (const uint8 *)ptrpal;
 	const uint8 *pal2p = (const uint8 *)ptrpal2;
-	uint8 *paletteOut = (uint8 *)workpal;
 	do {
 		FrameMarker frame(_engine, DEFAULT_HZ);
 		counter = 0;
 
-		uint8 *newR = &paletteOut[counter];
-		uint8 *newG = &paletteOut[counter + 1];
-		uint8 *newB = &paletteOut[counter + 2];
-		uint8 *newA = &paletteOut[counter + 3];
-
 		for (int32 i = 0; i < NUMOFCOLORS; i++) {
-			*newR = lerp(pal1p[counter + 0], pal2p[counter + 0], 100, intensity);
-			*newG = lerp(pal1p[counter + 1], pal2p[counter + 1], 100, intensity);
-			*newB = lerp(pal1p[counter + 2], pal2p[counter + 2], 100, intensity);
-			*newA = 0xFF;
-
-			newR += 4;
-			newG += 4;
-			newB += 4;
-			newA += 4;
+			byte newR = lerp(pal1p[counter + 0], pal2p[counter + 0], 100, intensity);
+			byte newG = lerp(pal1p[counter + 1], pal2p[counter + 1], 100, intensity);
+			byte newB = lerp(pal1p[counter + 2], pal2p[counter + 2], 100, intensity);
+			workpal.set(i, newR, newG, newB);
 
 			counter += 4;
 		}




More information about the Scummvm-git-logs mailing list