[Scummvm-git-logs] scummvm master -> 50c01c749574045750fe1d433c8f56a4def41f42

OMGPizzaGuy noreply at scummvm.org
Thu Mar 28 02:23:37 UTC 2024


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:
74e0a8ad98 ULTIMA8: Use palette entries for mini stats.
e53d58d970 ULTIMA8: Use palette entries for crusader health and energy.
39e448d542 ULTIMA8: Use palette colors for minimap gump.
50c01c7495 ULTIMA8: Convert minimap to clut8 format


Commit: 74e0a8ad989a570c7cef0a21bba6a2711b91d998
    https://github.com/scummvm/scummvm/commit/74e0a8ad989a570c7cef0a21bba6a2711b91d998
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2024-03-27T21:23:00-05:00

Commit Message:
ULTIMA8: Use palette entries for mini stats.
This allows for palette transformations and is a partial fix for issue #14851

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


diff --git a/engines/ultima/ultima8/graphics/render_surface.cpp b/engines/ultima/ultima8/graphics/render_surface.cpp
index 36d833b3b51..5c86858dc8f 100644
--- a/engines/ultima/ultima8/graphics/render_surface.cpp
+++ b/engines/ultima/ultima8/graphics/render_surface.cpp
@@ -195,6 +195,13 @@ bool RenderSurface::IsFlipped() const {
 	return _flipped;
 }
 
+void RenderSurface::fillRect(const Rect &r, uint32 color) {
+	Common::Rect rect(r.left, r.top, r.right, r.bottom);
+	rect.clip(_clipWindow);
+	rect.translate(_ox, _oy);
+	_surface->fillRect(rect, color);
+}
+
 void RenderSurface::fill32(uint32 rgb, const Rect &r) {
 	Common::Rect rect(r.left, r.top, r.right, r.bottom);
 	rect.clip(_clipWindow);
diff --git a/engines/ultima/ultima8/graphics/render_surface.h b/engines/ultima/ultima8/graphics/render_surface.h
index 8bf108280fe..ee6490acdbd 100644
--- a/engines/ultima/ultima8/graphics/render_surface.h
+++ b/engines/ultima/ultima8/graphics/render_surface.h
@@ -122,6 +122,9 @@ public:
 	// Surface Filling
 	//
 
+	//! Fill the region with a color in the pixel format
+	void fillRect(const Rect &r, uint32 color);
+
 	//! Fill the region with a color in the TEX32_PACK_RGB format
 	void fill32(uint32 rgb, int32 sx, int32 sy, int32 w, int32 h) {
 		fill32(rgb, Rect(sx, sy, sx + w, sy + h));
@@ -136,7 +139,7 @@ public:
 	//! Fill the region with a color in the TEX32_PACK_RGB format
 	void frameRect32(uint32 rgb, const Rect &r);
 
-		//
+	//
 	// The rule for painting methods:
 	//
 	// First arg are the source object to 'draw' with
diff --git a/engines/ultima/ultima8/gumps/mini_stats_gump.cpp b/engines/ultima/ultima8/gumps/mini_stats_gump.cpp
index cfa25fdb427..a69810d49c9 100644
--- a/engines/ultima/ultima8/gumps/mini_stats_gump.cpp
+++ b/engines/ultima/ultima8/gumps/mini_stats_gump.cpp
@@ -23,6 +23,8 @@
 
 #include "ultima/ultima8/games/game_data.h"
 #include "ultima/ultima8/graphics/gump_shape_archive.h"
+#include "ultima/ultima8/graphics/palette.h"
+#include "ultima/ultima8/graphics/palette_manager.h"
 #include "ultima/ultima8/world/actors/main_actor.h"
 #include "ultima/ultima8/graphics/render_surface.h"
 #include "ultima/ultima8/graphics/texture.h"
@@ -40,18 +42,10 @@ static const int manax = 13;
 static const int bary = 19;
 static const int barheight = 14;
 
-static const uint32 hpcolour[] = {
-	TEX32_PACK_RGB(0x98, 0x04, 0x04),
-	TEX32_PACK_RGB(0xBC, 0x0C, 0x0C),
-	TEX32_PACK_RGB(0xD4, 0x30, 0x30)
-};
-
-static const uint32 manacolour[] = {
-	TEX32_PACK_RGB(0x40, 0x50, 0xFC),
-	TEX32_PACK_RGB(0x1C, 0x28, 0xFC),
-	TEX32_PACK_RGB(0x0C, 0x0C, 0xCC)
-};
-
+// TODO: Confirm palette colors for use on mini stats gump
+// These values were closest to previously defined RGB values
+static const uint hpcolour[3] = {41, 39, 37};
+static const uint manacolour[3] = {138, 139, 141};
 
 MiniStatsGump::MiniStatsGump() : Gump() {
 
@@ -96,9 +90,12 @@ void MiniStatsGump::PaintThis(RenderSurface *surf, int32 lerp_factor, bool scale
 	else
 		hpheight = (hp * barheight) / maxhp;
 
+	Palette *pal = PaletteManager::get_instance()->getPalette(PaletteManager::Pal_Game);
 	for (int i = 0; i < 3; ++i) {
-		surf->fill32(hpcolour[i], hpx + i, bary - hpheight + 1, 1, hpheight);
-		surf->fill32(manacolour[i], manax + i, bary - manaheight + 1, 1, manaheight);
+		Rect hprect(hpx + i, bary - hpheight + 1, hpx + i + 1, bary + 1);
+		Rect manarect(manax + i, bary - manaheight + 1, manax + i + 1, bary + 1);
+		surf->fillRect(hprect, pal->_native[hpcolour[i]]);
+		surf->fillRect(manarect, pal->_native[manacolour[i]]);
 	}
 }
 


Commit: e53d58d9709920f77c4bb4d0ad7f9e05d5d10572
    https://github.com/scummvm/scummvm/commit/e53d58d9709920f77c4bb4d0ad7f9e05d5d10572
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2024-03-27T21:23:01-05:00

Commit Message:
ULTIMA8: Use palette entries for crusader health and energy.
These were using calculated transformations on each paint before.

Changed paths:
    engines/ultima/ultima8/gumps/cru_energy_gump.cpp
    engines/ultima/ultima8/gumps/cru_health_gump.cpp


diff --git a/engines/ultima/ultima8/gumps/cru_energy_gump.cpp b/engines/ultima/ultima8/gumps/cru_energy_gump.cpp
index a1ab27fb9fb..7ae18d1bf59 100644
--- a/engines/ultima/ultima8/gumps/cru_energy_gump.cpp
+++ b/engines/ultima/ultima8/gumps/cru_energy_gump.cpp
@@ -31,9 +31,7 @@
 namespace Ultima {
 namespace Ultima8 {
 
-static const uint32 ENERGY_BAR_R = 154;
-static const uint32 ENERGY_BAR_G = 4;
-static const uint32 ENERGY_BAR_B = 4;
+static const uint ENERGY_BAR_COLOR = 245;
 
 DEFINE_RUNTIME_CLASSTYPE_CODE(CruEnergyGump)
 
@@ -74,12 +72,8 @@ void CruEnergyGump::PaintThis(RenderSurface *surf, int32 lerp_factor, bool scale
 	if (!gamepal)
 		return;
 
-	int r = ENERGY_BAR_R;
-	int g = ENERGY_BAR_G;
-	int b = ENERGY_BAR_B;
-	gamepal->transformRGB(r, g, b);
-	uint32 color = TEX32_PACK_RGB(r, g, b);
-	surf->fill32(color, 34, 7, width, 14);
+	Rect rect(34, 7, 34 + width, 21);
+	surf->fillRect(rect, gamepal->_native[ENERGY_BAR_COLOR]);
 }
 
 void CruEnergyGump::saveData(Common::WriteStream *ws) {
diff --git a/engines/ultima/ultima8/gumps/cru_health_gump.cpp b/engines/ultima/ultima8/gumps/cru_health_gump.cpp
index daa1e536ef7..f35690ae1d1 100644
--- a/engines/ultima/ultima8/gumps/cru_health_gump.cpp
+++ b/engines/ultima/ultima8/gumps/cru_health_gump.cpp
@@ -31,9 +31,7 @@
 namespace Ultima {
 namespace Ultima8 {
 
-static const uint32 HEALTH_BAR_R = 0;
-static const uint32 HEALTH_BAR_G = 48;
-static const uint32 HEALTH_BAR_B = 113;
+static const uint HEALTH_BAR_COLOR = 65;
 
 DEFINE_RUNTIME_CLASSTYPE_CODE(CruHealthGump)
 
@@ -66,12 +64,8 @@ void CruHealthGump::PaintThis(RenderSurface *surf, int32 lerp_factor, bool scale
 	if (!gamepal)
 		return;
 
-	int r = HEALTH_BAR_R;
-	int g = HEALTH_BAR_G;
-	int b = HEALTH_BAR_B;
-	gamepal->transformRGB(r, g, b);
-	uint32 color = TEX32_PACK_RGB(r, g, b);
-	surf->fill32(color, 34, 7, width, 14);
+	Rect rect(34, 7, 34 + width, 21);
+	surf->fillRect(rect, gamepal->_native[HEALTH_BAR_COLOR]);
 }
 
 void CruHealthGump::saveData(Common::WriteStream *ws) {


Commit: 39e448d5424665ad8d8e4ba211dc3ae5c7d088bf
    https://github.com/scummvm/scummvm/commit/39e448d5424665ad8d8e4ba211dc3ae5c7d088bf
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2024-03-27T21:23:02-05:00

Commit Message:
ULTIMA8: Use palette colors for minimap gump.
The untransformed palette is used for now as the minimap sufaces do not use the game palette yet.

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


diff --git a/engines/ultima/ultima8/graphics/render_surface.cpp b/engines/ultima/ultima8/graphics/render_surface.cpp
index 5c86858dc8f..6b89dde1a77 100644
--- a/engines/ultima/ultima8/graphics/render_surface.cpp
+++ b/engines/ultima/ultima8/graphics/render_surface.cpp
@@ -202,6 +202,17 @@ void RenderSurface::fillRect(const Rect &r, uint32 color) {
 	_surface->fillRect(rect, color);
 }
 
+void RenderSurface::frameRect(const Rect& r, uint32 color) {
+	Common::Rect rect(r.left, r.top, r.right, r.bottom);
+	rect.clip(_clipWindow);
+	rect.translate(_ox, _oy);
+	_surface->frameRect(rect, color);
+}
+
+void RenderSurface::drawLine(int32 sx, int32 sy, int32 ex, int32 ey, uint32 color) {
+	_surface->drawLine(sx + _ox, sy + _oy, ex + _ox, ey + _oy, color);
+}
+
 void RenderSurface::fill32(uint32 rgb, const Rect &r) {
 	Common::Rect rect(r.left, r.top, r.right, r.bottom);
 	rect.clip(_clipWindow);
diff --git a/engines/ultima/ultima8/graphics/render_surface.h b/engines/ultima/ultima8/graphics/render_surface.h
index ee6490acdbd..fd3c52b92eb 100644
--- a/engines/ultima/ultima8/graphics/render_surface.h
+++ b/engines/ultima/ultima8/graphics/render_surface.h
@@ -118,13 +118,15 @@ public:
 		return _surface;
 	};
 
-	//
-	// Surface Filling
-	//
-
 	//! Fill the region with a color in the pixel format
 	void fillRect(const Rect &r, uint32 color);
 
+	//! Fill the region with a color in the pixel format
+	void frameRect(const Rect &r, uint32 color);
+
+	// Draw a line with a color in the pixel format
+	void drawLine(int32 sx, int32 sy, int32 ex, int32 ey, uint32 color);
+
 	//! Fill the region with a color in the TEX32_PACK_RGB format
 	void fill32(uint32 rgb, int32 sx, int32 sy, int32 w, int32 h) {
 		fill32(rgb, Rect(sx, sy, sx + w, sy + h));
@@ -139,6 +141,9 @@ public:
 	//! Fill the region with a color in the TEX32_PACK_RGB format
 	void frameRect32(uint32 rgb, const Rect &r);
 
+	// Draw a line with a color in the TEX32_PACK_RGB format
+	void drawLine32(uint32 rgb, int32 sx, int32 sy, int32 ex, int32 ey);
+
 	//
 	// The rule for painting methods:
 	//
@@ -166,14 +171,6 @@ public:
 	//! Paint a Invisible Highlighted Shape of using the 32 Bit Colour col32 (0xAARRGGBB Alpha is blend level)
 	void PaintHighlightInvis(const Shape *s, uint32 frame, int32 x, int32 y, bool trans, bool mirrored, uint32 col32);
 
-	//
-	// Basic Line Drawing
-	//
-
-	// Draw a line with a color in the TEX32_PACK_RGB format
-	void drawLine32(uint32 rgb, int32 sx, int32 sy, int32 ex, int32 ey);
-
-
 	//
 	// Basic Texture Blitting
 	//
diff --git a/engines/ultima/ultima8/gumps/minimap_gump.cpp b/engines/ultima/ultima8/gumps/minimap_gump.cpp
index 25c68a3df1d..3a386ab7598 100644
--- a/engines/ultima/ultima8/gumps/minimap_gump.cpp
+++ b/engines/ultima/ultima8/gumps/minimap_gump.cpp
@@ -24,6 +24,8 @@
 #include "ultima/ultima8/world/current_map.h"
 #include "ultima/ultima8/world/world.h"
 #include "ultima/ultima8/world/actors/main_actor.h"
+#include "ultima/ultima8/graphics/palette.h"
+#include "ultima/ultima8/graphics/palette_manager.h"
 #include "ultima/ultima8/graphics/render_surface.h"
 #include "ultima/ultima8/graphics/texture.h"
 #include "ultima/ultima8/world/get_object.h"
@@ -34,8 +36,9 @@ namespace Ultima8 {
 
 DEFINE_RUNTIME_CLASSTYPE_CODE(MiniMapGump)
 
-static const uint32 NORMAL_COLOR = TEX32_PACK_RGB(0xFF, 0xAF, 0x00);
-static const uint32 HIGHLIGHT_COLOR = TEX32_PACK_RGB(0xFF, 0xCF, 0x00);
+static const uint BACKGROUND_COLOR = 0;
+static const uint NORMAL_COLOR = 53;
+static const uint HIGHLIGHT_COLOR = 52;
 
 MiniMapGump::MiniMapGump(int x, int y) : ResizableGump(x, y, 120, 120), _minimaps(), _ax(0), _ay(0) {
 	setMinSize(60, 60);
@@ -106,19 +109,22 @@ void MiniMapGump::clear() {
 }
 
 void MiniMapGump::PaintThis(RenderSurface *surf, int32 lerp_factor, bool scaled) {
-	uint32 color = NORMAL_COLOR;
+	Palette *pal = PaletteManager::get_instance()->getPalette(PaletteManager::Pal_Game);
+	uint32 *map = pal->_native_untransformed;
+
+	uint32 color = map[NORMAL_COLOR];
 	if (_dragPosition != Gump::CENTER || _mousePosition != Gump::CENTER)
-		color = HIGHLIGHT_COLOR;
+		color = map[HIGHLIGHT_COLOR];
 
 	// Draw the border
-	surf->frameRect32(color, _dims);
+	surf->frameRect(_dims, color);
 
 	// Dimensions minus border
 	Rect dims = _dims;
 	dims.grow(-1);
 
 	// Fill the background
-	surf->fill32(TEX32_PACK_RGB(0, 0, 0), dims);
+	surf->fillRect(dims, map[BACKGROUND_COLOR]);
 
 	// Center on avatar
 	int sx = _ax - dims.width() / 2;
@@ -163,10 +169,10 @@ void MiniMapGump::PaintThis(RenderSurface *surf, int32 lerp_factor, bool scaled)
 	int32 ay = _ay - sy;
 
 	// Paint the avatar position marker
-	surf->drawLine32(color, ax - 1, ay + 1, ax, ay + 1);
-	surf->drawLine32(color, ax + 1, ay - 1, ax + 1, ay);
-	surf->drawLine32(color, ax + 2, ay + 1, ax + 3, ay + 1);
-	surf->drawLine32(color, ax + 1, ay + 2, ax + 1, ay + 3);
+	surf->drawLine(ax - 1, ay + 1, ax, ay + 1, color);
+	surf->drawLine(ax + 1, ay - 1, ax + 1, ay, color);
+	surf->drawLine(ax + 2, ay + 1, ax + 3, ay + 1, color);
+	surf->drawLine(ax + 1, ay + 2, ax + 1, ay + 3, color);
 }
 
 Gump *MiniMapGump::onMouseDown(int button, int32 mx, int32 my) {


Commit: 50c01c749574045750fe1d433c8f56a4def41f42
    https://github.com/scummvm/scummvm/commit/50c01c749574045750fe1d433c8f56a4def41f42
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2024-03-27T21:23:02-05:00

Commit Message:
ULTIMA8: Convert minimap to clut8 format
This reduces savefile size, allows for faster blit, and palette transformations work on the minimap gump. Fixes issue #14851

Changed paths:
    engines/ultima/ultima8/graphics/render_surface.cpp
    engines/ultima/ultima8/graphics/render_surface.h
    engines/ultima/ultima8/gumps/minimap_gump.cpp
    engines/ultima/ultima8/world/minimap.cpp


diff --git a/engines/ultima/ultima8/graphics/render_surface.cpp b/engines/ultima/ultima8/graphics/render_surface.cpp
index 6b89dde1a77..f23a471a7d8 100644
--- a/engines/ultima/ultima8/graphics/render_surface.cpp
+++ b/engines/ultima/ultima8/graphics/render_surface.cpp
@@ -27,6 +27,7 @@
 #include "ultima/ultima8/ultima8.h"
 #include "common/system.h"
 #include "engines/util.h"
+#include "graphics/blit.h"
 #include "graphics/screen.h"
 
 namespace Ultima {
@@ -307,6 +308,12 @@ void RenderSurface::Blit(const Graphics::ManagedSurface &src, const Common::Rect
 	}
 }
 
+void RenderSurface::CrossKeyBlitMap(const Graphics::Surface& src, const Common::Rect& srcRect, int32 dx, int32 dy, const uint32* map, const uint32 key) {
+	byte *dstPixels = reinterpret_cast<byte *>(_surface->getBasePtr(_ox + dx, _oy + dy));
+	const byte *srcPixels = reinterpret_cast<const byte *>(src.getBasePtr(srcRect.left, srcRect.top));
+	Graphics::crossKeyBlitMap(dstPixels, srcPixels, _surface->pitch, src.pitch, srcRect.width(), srcRect.height(), _surface->format.bytesPerPixel, map, key);
+}
+
 namespace {
 
 template<typename uintDst, typename uintSrc>
diff --git a/engines/ultima/ultima8/graphics/render_surface.h b/engines/ultima/ultima8/graphics/render_surface.h
index fd3c52b92eb..19107d0eefb 100644
--- a/engines/ultima/ultima8/graphics/render_surface.h
+++ b/engines/ultima/ultima8/graphics/render_surface.h
@@ -178,6 +178,8 @@ public:
 	//! Blit a region from a Texture (Alpha == 0 -> skipped)
 	void Blit(const Graphics::ManagedSurface &src, const Common::Rect &srcRect, int32 dx, int32 dy, bool alpha_blend = false);
 
+	void CrossKeyBlitMap(const Graphics::Surface &src, const Common::Rect &srcRect, int32 dx, int32 dy, const uint32 *map, const uint32 key);
+
 	//! Blit a region from a Texture with a Colour blend (AlphaTex == 0 -> skipped. AlphaCol32 -> Blend Factors)
 	void FadedBlit(const Graphics::ManagedSurface &src, const Common::Rect &srcRect, int32 dx, int32 dy, uint32 col32, bool alpha_blend = false);
 
diff --git a/engines/ultima/ultima8/gumps/minimap_gump.cpp b/engines/ultima/ultima8/gumps/minimap_gump.cpp
index 3a386ab7598..76f9b2f4f0b 100644
--- a/engines/ultima/ultima8/gumps/minimap_gump.cpp
+++ b/engines/ultima/ultima8/gumps/minimap_gump.cpp
@@ -39,6 +39,7 @@ DEFINE_RUNTIME_CLASSTYPE_CODE(MiniMapGump)
 static const uint BACKGROUND_COLOR = 0;
 static const uint NORMAL_COLOR = 53;
 static const uint HIGHLIGHT_COLOR = 52;
+static const uint KEY_COLOR = 255;
 
 MiniMapGump::MiniMapGump(int x, int y) : ResizableGump(x, y, 120, 120), _minimaps(), _ax(0), _ay(0) {
 	setMinSize(60, 60);
@@ -110,7 +111,7 @@ void MiniMapGump::clear() {
 
 void MiniMapGump::PaintThis(RenderSurface *surf, int32 lerp_factor, bool scaled) {
 	Palette *pal = PaletteManager::get_instance()->getPalette(PaletteManager::Pal_Game);
-	uint32 *map = pal->_native_untransformed;
+	uint32 *map = pal->_native;
 
 	uint32 color = map[NORMAL_COLOR];
 	if (_dragPosition != Gump::CENTER || _mousePosition != Gump::CENTER)
@@ -162,7 +163,7 @@ void MiniMapGump::PaintThis(RenderSurface *surf, int32 lerp_factor, bool scaled)
 	}
 
 	if (!r.isEmpty()) {
-		surf->Blit(ms, r, dx, dy);
+		surf->CrossKeyBlitMap(ms, r, dx, dy, map, KEY_COLOR);
 	}
 
 	int32 ax = _ax - sx;
diff --git a/engines/ultima/ultima8/world/minimap.cpp b/engines/ultima/ultima8/world/minimap.cpp
index c3d1c9ab82d..ce6f28cb633 100644
--- a/engines/ultima/ultima8/world/minimap.cpp
+++ b/engines/ultima/ultima8/world/minimap.cpp
@@ -29,13 +29,19 @@
 #include "ultima/ultima8/graphics/shape.h"
 #include "ultima/ultima8/graphics/shape_frame.h"
 #include "ultima/ultima8/graphics/palette.h"
+#include "ultima/ultima8/graphics/palette_manager.h"
 
 namespace Ultima {
 namespace Ultima8 {
 
+static const uint BLACK_COLOR = 0;
+static const uint KEY_COLOR = 255;
+
 MiniMap::MiniMap(uint32 mapNum) : _mapNum(mapNum), _surface() {
-	_surface.create((MAP_NUM_CHUNKS * MINMAPGUMP_SCALE), (MAP_NUM_CHUNKS * MINMAPGUMP_SCALE),
-					Graphics::PixelFormat(2, 5, 5, 5, 1, 11, 6, 1, 0));
+	uint16 w = MAP_NUM_CHUNKS * MINMAPGUMP_SCALE;
+	uint16 h = MAP_NUM_CHUNKS * MINMAPGUMP_SCALE;
+	_surface.create(w, h, Graphics::PixelFormat::createFormatCLUT8());
+	_surface.fillRect(Common::Rect(w, h), KEY_COLOR);
 }
 
 MiniMap::~MiniMap() {
@@ -49,7 +55,7 @@ void MiniMap::update(const CurrentMap &map) {
 	for (int x = 0; x < _surface.w; x++) {
 		for (int y = 0; y < _surface.h; y++) {
 			uint32 val = _surface.getPixel(x, y);
-			if (val == 0) {
+			if (val == KEY_COLOR) {
 				int cx = x / MINMAPGUMP_SCALE;
 				int cy = y / MINMAPGUMP_SCALE;
 				if (map.isChunkFast(cx, cy)) {
@@ -95,13 +101,13 @@ uint32 MiniMap::sampleAtPoint(const CurrentMap &map, int x, int y) {
 				continue;
 
 			uint32 val = sampleAtPoint(*item, x, y);
-			if (val != 0)
+			if (val != KEY_COLOR)
 				return val;
 		}
 	}
 
 	// set to avoid reprocessing
-	return _surface.format.RGBToColor(0x00, 0x00, 0x00);
+	return BLACK_COLOR;
 }
 
 uint32 MiniMap::sampleAtPoint(const Item &item, int x, int y) {
@@ -132,8 +138,8 @@ uint32 MiniMap::sampleAtPoint(const Item &item, int x, int y) {
 	// Screenspace bounding box bottom extent  (RNB y_ coord)
 	int sy = (ix + iy) / 8 + idz;
 
-	int w = 2;
-	int h = 2;
+	int w = 3;
+	int h = 3;
 
 	// Ensure sample is in bounds of frame
 	if (frame->_xoff - sx < 0)
@@ -156,29 +162,28 @@ uint32 MiniMap::sampleAtPoint(const Item &item, int x, int y) {
 			uint8 p = frame->getPixel(i - sx, j - sy);
 			byte r2, g2, b2;
 			pal->get(p, r2, g2, b2);
-			r += RenderSurface::_gamma22toGamma10[r2];
-			g += RenderSurface::_gamma22toGamma10[g2];
-			b += RenderSurface::_gamma22toGamma10[b2];
+			r += r2;
+			g += g2;
+			b += b2;
 			c++;
 		}
 	}
 
 	if (c > 0) {
-		return _surface.format.RGBToColor(RenderSurface::_gamma10toGamma22[r / c], RenderSurface::_gamma10toGamma22[g / c], RenderSurface::_gamma10toGamma22[b / c]);
+		return pal->findBestColor(r / c, g / c, b / c);
 	}
 
-	return 0;
+	return KEY_COLOR;
 }
 
 const Common::Rect MiniMap::getCropBounds() const {
 	Common::Rect bounds(_surface.w, _surface.h);
-	uint32 mask = _surface.format.ARGBToColor(0x00, 0xFF, 0xFF, 0xFF);
 
 	// Get left
 	for (int x = bounds.left; x < bounds.right; x++) {
 		for (int y = bounds.top; y < bounds.bottom; y++) {
 			uint32 val = _surface.getPixel(x, y);
-			if ((val & mask) != 0) {
+			if (val != KEY_COLOR) {
 				bounds.left = x;
 
 				// end loops
@@ -192,7 +197,7 @@ const Common::Rect MiniMap::getCropBounds() const {
 	for (int y = bounds.top; y < bounds.bottom; y++) {
 		for (int x = bounds.left; x < bounds.right; x++) {
 			uint32 val = _surface.getPixel(x, y);
-			if ((val & mask) != 0) {
+			if (val != KEY_COLOR) {
 				bounds.top = y;
 
 				// end loops
@@ -206,7 +211,7 @@ const Common::Rect MiniMap::getCropBounds() const {
 	for (int x = bounds.right - 1; x > bounds.left; x--) {
 		for (int y = bounds.bottom - 1; y > bounds.top; y--) {
 			uint32 val = _surface.getPixel(x, y);
-			if ((val & mask) != 0) {
+			if (val != KEY_COLOR) {
 				bounds.right = x + 1;
 
 				// end loops
@@ -220,7 +225,7 @@ const Common::Rect MiniMap::getCropBounds() const {
 	for (int y = bounds.bottom - 1; y > bounds.top; y--) {
 		for (int x = bounds.right - 1; x > bounds.left; x--) {
 			uint32 val = _surface.getPixel(x, y);
-			if ((val & mask) != 0) {
+			if (val != KEY_COLOR) {
 				bounds.bottom = y + 1;
 
 				// end loops
@@ -253,20 +258,40 @@ bool MiniMap::load(Common::ReadStream *rs, uint32 version) {
 	format.bShift = rs->readByte();
 	format.aShift = rs->readByte();
 
-	if (format.bytesPerPixel != 2) {
-		error("unsupported minimap texture format %d bpp", format.bytesPerPixel);
-		return false;
-	}
-
 	uint16 w = _surface.w;
 	uint16 h = _surface.h;
-	_surface.create(w, h, format);
-	for (int y = bounds.top; y < bounds.bottom; ++y) {
-		uint16 *pixels = (uint16 *)_surface.getBasePtr(bounds.left, y);
-		for (int x = bounds.left; x < bounds.right; ++x) {
-			*pixels++ = rs->readUint16LE();
+	_surface.create(w, h, Graphics::PixelFormat::createFormatCLUT8());
+	_surface.fillRect(Common::Rect(w, h), KEY_COLOR);
+
+	if (format.bytesPerPixel == 1) {
+		for (int y = bounds.top; y < bounds.bottom; ++y) {
+			uint8 *pixels = (uint8 *)_surface.getBasePtr(bounds.left, y);
+			for (int x = bounds.left; x < bounds.right; ++x) {
+				*pixels++ = rs->readByte();
+			}
+		}
+	} else if (format.bytesPerPixel == 2) {
+		// Convert format to palette
+		Palette *p = PaletteManager::get_instance()->getPalette(PaletteManager::Pal_Game);
+		Graphics::PaletteLookup pl(p->data(), p->size());
+		for (int y = bounds.top; y < bounds.bottom; ++y) {
+			uint8 *pixels = (uint8 *)_surface.getBasePtr(bounds.left, y);
+			for (int x = bounds.left; x < bounds.right; ++x) {
+				uint16 color = rs->readUint16LE();
+				if (color) {
+					byte r, g, b;
+					format.colorToRGB(color, r, g, b);
+					*pixels++ = pl.findBestColor(r, g, b);
+				} else {
+					*pixels++ = KEY_COLOR;
+				}
+			}
 		}
+	} else {
+		error("unsupported minimap texture format %d bpp", format.bytesPerPixel);
+		return false;
 	}
+
 	return true;
 }
 
@@ -292,9 +317,9 @@ void MiniMap::save(Common::WriteStream *ws) const {
 
 	// Serialize the pixel data
 	for (int y = bounds.top; y < bounds.bottom; ++y) {
-		const uint16 *pixels = (const uint16 *)_surface.getBasePtr(bounds.left, y);
+		const uint8 *pixels = (const uint8 *)_surface.getBasePtr(bounds.left, y);
 		for (int x = bounds.left; x < bounds.right; ++x) {
-			ws->writeUint16LE(*pixels++);
+			ws->writeByte(*pixels++);
 		}
 	}
 }




More information about the Scummvm-git-logs mailing list