[Scummvm-cvs-logs] scummvm master -> bd281928cb6e87cfb7175189cafd2b25991f3e01

bluegr md5 at scummvm.org
Tue Jul 24 02:55:28 CEST 2012


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:
bd281928cb SCI: Initial implementation of kRemapColors(kRemapByPercent)


Commit: bd281928cb6e87cfb7175189cafd2b25991f3e01
    https://github.com/scummvm/scummvm/commit/bd281928cb6e87cfb7175189cafd2b25991f3e01
Author: Filippos Karapetis (md5 at scummvm.org)
Date: 2012-07-23T17:53:44-07:00

Commit Message:
SCI: Initial implementation of kRemapColors(kRemapByPercent)

Fixes some graphics glitches in the QFG4 demo and the menus of QFG4, by
implementing one of the transparency effects used mainly in SCI32.
Many thanks to fuzzie for her debugging info on QFG4 demo and to wjp for
his great help on the dissassembly

Changed paths:
    engines/sci/engine/kgraphics.cpp
    engines/sci/engine/kgraphics32.cpp
    engines/sci/graphics/palette.cpp
    engines/sci/graphics/palette.h
    engines/sci/graphics/view.cpp



diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp
index 2ce44db..bd78c56 100644
--- a/engines/sci/engine/kgraphics.cpp
+++ b/engines/sci/engine/kgraphics.cpp
@@ -1221,17 +1221,18 @@ reg_t kShow(EngineState *s, int argc, reg_t *argv) {
 	return s->r_acc;
 }
 
-// Early variant of the SCI32 remapcolors kernel function, used in the demo of QFG4
+// Early variant of the SCI32 kRemapColors kernel function, used in the demo of QFG4
 reg_t kRemapColors(EngineState *s, int argc, reg_t *argv) {
 	uint16 operation = argv[0].toUint16();
 
 	switch (operation) {
 	case 0: { // remap by percent
 		uint16 percent = argv[1].toUint16();
-		warning("RemapColors(RemapByPercent) %d", percent);
+		g_sci->_gfxPalette->toggleRemap(true);
+		g_sci->_gfxPalette->setRemappingPercent(percent);
 		}
 		break;
-	case 1:	{ // unknown
+	case 1:	{ // set remapping base
 		//int16 unk1 = argv[1].toSint16();
 		//int16 unk2 = argv[2].toSint16();
 		//int16 unk3 = argv[3].toSint16();
diff --git a/engines/sci/engine/kgraphics32.cpp b/engines/sci/engine/kgraphics32.cpp
index 245c265..1b7b628 100644
--- a/engines/sci/engine/kgraphics32.cpp
+++ b/engines/sci/engine/kgraphics32.cpp
@@ -742,8 +742,11 @@ reg_t kRemapColors32(EngineState *s, int argc, reg_t *argv) {
 		if (base != 0)	// 0 is the default behavior when changing rooms in GK1, thus silencing the warning
 			warning("kRemapColors: Set remapping to base %d", base);
 		}
+		// TODO: Don't turn remapping off always
+		g_sci->_gfxPalette->toggleRemap(false);
+		g_sci->_gfxPalette->setRemappingPercent(0);
 		break;
-	case 1:	{ // unknown
+	case 1:	{ // set remapping base
 		//int16 unk1 = argv[1].toSint16();
 		//int16 unk2 = argv[2].toSint16();
 		//int16 unk3 = argv[3].toSint16();
@@ -753,21 +756,15 @@ reg_t kRemapColors32(EngineState *s, int argc, reg_t *argv) {
 		}
 		break;
 	case 2:	{ // remap by percent
-		// This adjusts the alpha value of a specific color, and it operates on
-		// an RGBA palette. Since we're operating on an RGB palette, we just
-		// modify the color intensity instead
-		// TODO: From what I understand, palette remapping should be placed
-		// separately, so that it can be reset by case 0 above. Thus, we
-		// should adjust the functionality of the Palette class accordingly.
-		int16 color = argv[1].toSint16();
+		// TODO: Use the color index. The -10 offset is wrong.
+		/*int16 color = argv[1].toSint16();
 		if (color >= 10)
-			color -= 10;
+			color -= 10;*/
 		uint16 percent = argv[2].toUint16(); // 0 - 100
 		if (argc >= 4)
 			warning("RemapByPercent called with 4 parameters, unknown parameter is %d", argv[3].toUint16());
-		warning("kRemapColors: RemapByPercent color %d by %d percent", color, percent);
-		// TODO: It's not correct to set intensity here
-		//g_sci->_gfxPalette->kernelSetIntensity(color, 255, percent, false);
+		g_sci->_gfxPalette->toggleRemap(true);
+		g_sci->_gfxPalette->setRemappingPercent(percent);
 		}
 		break;
 	case 3:	{ // remap to gray
diff --git a/engines/sci/graphics/palette.cpp b/engines/sci/graphics/palette.cpp
index ea154c5..f16d607 100644
--- a/engines/sci/graphics/palette.cpp
+++ b/engines/sci/graphics/palette.cpp
@@ -100,6 +100,9 @@ GfxPalette::GfxPalette(ResourceManager *resMan, GfxScreen *screen)
 	default:
 		error("GfxPalette: Unknown view type");
 	}
+
+	_remapOn = false;
+	_remappingPercent = 0;
 }
 
 GfxPalette::~GfxPalette() {
@@ -329,6 +332,26 @@ void GfxPalette::set(Palette *newPalette, bool force, bool forceRealMerge) {
 	}
 }
 
+bool GfxPalette::isRemapColor(byte color) {
+	// TODO: Expand this for SCI32 (more than one remap color can be set).
+	// Now, it is assumed that colors 253 and 254 are the remap colors.
+	return _remapOn && (color == 253 || color == 254);
+}
+
+byte GfxPalette::remapColor(byte color) {
+	assert(_remapOn);
+
+	// TODO: Change this to use a table instead, like the original.
+	if (_remappingPercent) {
+		byte r = _sysPalette.colors[color].r * _remappingPercent / 100;
+		byte g = _sysPalette.colors[color].g * _remappingPercent / 100;
+		byte b = _sysPalette.colors[color].b * _remappingPercent / 100;
+		return kernelFindColor(r, g, b);
+	} else {
+		return color;
+	}
+}
+
 bool GfxPalette::insert(Palette *newPalette, Palette *destPalette) {
 	bool paletteChanged = false;
 
diff --git a/engines/sci/graphics/palette.h b/engines/sci/graphics/palette.h
index a9ea1c3..5b9ae9e 100644
--- a/engines/sci/graphics/palette.h
+++ b/engines/sci/graphics/palette.h
@@ -53,6 +53,11 @@ public:
 	void getSys(Palette *pal);
 	uint16 getTotalColorCount() const { return _totalScreenColors; }
 
+	void toggleRemap(bool remap) { _remapOn = remap; }
+	void setRemappingPercent(uint16 percent) { _remappingPercent = percent;	}
+	bool isRemapColor(byte color);
+	byte remapColor(byte color);
+
 	void setOnScreen();
 	void copySysPaletteToScreen();
 
@@ -123,6 +128,10 @@ private:
 	int _palVarySignal;
 	uint16 _totalScreenColors;
 
+	bool _remapOn;
+	uint16 _remappingBaseR, _remappingBaseG, _remappingBaseB;
+	uint16 _remappingPercent;
+
 	void loadMacIconBarPalette();
 	byte *_macClut;
 
diff --git a/engines/sci/graphics/view.cpp b/engines/sci/graphics/view.cpp
index 4e5c4da..ae135d1 100644
--- a/engines/sci/graphics/view.cpp
+++ b/engines/sci/graphics/view.cpp
@@ -741,8 +741,14 @@ void GfxView::draw(const Common::Rect &rect, const Common::Rect &clipRect, const
 					const int x2 = clipRectTranslated.left + x;
 					const int y2 = clipRectTranslated.top + y;
 					if (!upscaledHires) {
-						if (priority >= _screen->getPriority(x2, y2))
-							_screen->putPixel(x2, y2, drawMask, palette->mapping[color], priority, 0);
+						if (priority >= _screen->getPriority(x2, y2)) {
+							if (!_palette->isRemapColor(palette->mapping[color])) {
+								_screen->putPixel(x2, y2, drawMask, palette->mapping[color], priority, 0);
+							} else {
+								byte remappedColor = _palette->remapColor(_screen->getVisual(x2, y2));
+								_screen->putPixel(x2, y2, drawMask, remappedColor, priority, 0);
+							}
+						}
 					} else {
 						// UpscaledHires means view is hires and is supposed to
 						// get drawn onto lowres screen.






More information about the Scummvm-git-logs mailing list