[Scummvm-cvs-logs] SF.net SVN: scummvm:[44494] scummvm/trunk/engines/sci/gfx

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Wed Sep 30 18:06:05 CEST 2009


Revision: 44494
          http://scummvm.svn.sourceforge.net/scummvm/?rev=44494&view=rev
Author:   fingolfin
Date:     2009-09-30 16:06:04 +0000 (Wed, 30 Sep 2009)

Log Message:
-----------
SCI: Some palette code cleanup

Modified Paths:
--------------
    scummvm/trunk/engines/sci/gfx/gfx_driver.cpp
    scummvm/trunk/engines/sci/gfx/gfx_pixmap_scale.cpp
    scummvm/trunk/engines/sci/gfx/operations.cpp
    scummvm/trunk/engines/sci/gfx/palette.cpp
    scummvm/trunk/engines/sci/gfx/palette.h

Modified: scummvm/trunk/engines/sci/gfx/gfx_driver.cpp
===================================================================
--- scummvm/trunk/engines/sci/gfx/gfx_driver.cpp	2009-09-30 16:04:21 UTC (rev 44493)
+++ scummvm/trunk/engines/sci/gfx/gfx_driver.cpp	2009-09-30 16:06:04 UTC (rev 44494)
@@ -86,9 +86,9 @@
 	memcpy(p + (y * 320* drv->getMode()->scaleFactor + x), &col, 1);
 }
 
-void GfxDriver::drawLine(Common::Point start, Common::Point end, gfx_color_t color, 
+void GfxDriver::drawLine(Common::Point start, Common::Point end, gfx_color_t color,
 						gfx_line_mode_t line_mode, gfx_line_style_t line_style) {
-	uint32 scolor = color.visual.parent_index;
+	uint32 scolor = color.visual.getParentIndex();
 	int scaleFactor = (line_mode == GFX_LINE_MODE_FINE)? 1: _mode->scaleFactor;
 	int xsize = _mode->xsize;
 	int ysize = _mode->ysize;
@@ -119,7 +119,7 @@
 	if (color1.mask & GFX_MASK_VISUAL) {
 		for (int i = rect.y; i < rect.y + rect.height; i++) {
 			memset(_visual[0] + (i * _mode->xsize + rect.x),
-			       color1.visual.parent_index, rect.width);
+			       color1.visual.getParentIndex(), rect.width);
 		}
 	}
 
@@ -228,7 +228,7 @@
 			// FIXME: The palette size check is a workaround for cursors using non-palette colour GFX_CURSOR_TRANSPARENT
 			// Note that some cursors don't have a palette in SQ5
 			if (pointer->palette && color < pointer->palette->size())
-				color = pointer->palette->getColor(color).parent_index;
+				color = pointer->palette->getColor(color).getParentIndex();
 			memset(&linebase[xc], color, _mode->scaleFactor);
 		}
 
@@ -241,7 +241,7 @@
 	// Note that some cursors don't have a palette (e.g. in SQ5 and QFG3)
 	byte color_key = pointer->color_key;
 	if ((pointer->color_key != GFX_PIXMAP_COLOR_KEY_NONE) && (pointer->palette && (uint)pointer->color_key < pointer->palette->size()))
-		color_key = pointer->palette->getColor(pointer->color_key).parent_index;
+		color_key = pointer->palette->getColor(pointer->color_key).getParentIndex();
 
 	CursorMan.replaceCursor(cursorData, pointer->width, pointer->height, hotspot->x, hotspot->y, color_key);
 	CursorMan.showMouse(true);

Modified: scummvm/trunk/engines/sci/gfx/gfx_pixmap_scale.cpp
===================================================================
--- scummvm/trunk/engines/sci/gfx/gfx_pixmap_scale.cpp	2009-09-30 16:04:21 UTC (rev 44493)
+++ scummvm/trunk/engines/sci/gfx/gfx_pixmap_scale.cpp	2009-09-30 16:06:04 UTC (rev 44494)
@@ -58,7 +58,7 @@
 
 	// Calculate all colors
 	for (i = 0; i < pxm->colors_nr(); i++)
-		result_colors[i] = pxm->palette->getColor(i).parent_index;
+		result_colors[i] = pxm->palette->getColor(i).getParentIndex();
 
 	if (!separate_alpha_map && pxm->color_key != GFX_PIXMAP_COLOR_KEY_NONE)
 		result_colors[pxm->color_key] = 0;

Modified: scummvm/trunk/engines/sci/gfx/operations.cpp
===================================================================
--- scummvm/trunk/engines/sci/gfx/operations.cpp	2009-09-30 16:04:21 UTC (rev 44493)
+++ scummvm/trunk/engines/sci/gfx/operations.cpp	2009-09-30 16:06:04 UTC (rev 44494)
@@ -405,7 +405,7 @@
 	state->driver = new GfxDriver(xfact, yfact, mode);
 
 	state->gfxResMan = new GfxResManager(state->options, state->driver, resMan);
-	
+
 	gfxop_set_clip_zone(state, gfx_rect(0, 0, 320, 200));
 	state->pointerZone = Common::Rect(0, 0, 320, 200);
 
@@ -536,7 +536,7 @@
 		color->alpha = a;
 
 		if (PALETTE_MODE) {
-			color->visual.parent_index = state->driver->getMode()->palette->findNearbyColor(r,g,b,true);
+			color->visual._parentIndex = PALETTE_MODE->findNearbyColor(r,g,b,true);
 		}
 	}
 }
@@ -556,11 +556,11 @@
 	if (!PALETTE_MODE)
 		return;
 
-	if (index >= state->driver->getMode()->palette->size()) {
-		error("Attempt to set invalid color index %02x as system color", color->visual.parent_index);
+	if (index >= PALETTE_MODE->size()) {
+		error("Attempt to set invalid color index %02x as system color", color->visual.getParentIndex());
 	}
 
-	state->driver->getMode()->palette->makeSystemColor(index, color->visual);
+	PALETTE_MODE->makeSystemColor(index, color->visual);
 }
 
 void gfxop_free_color(GfxState *state, gfx_color_t *color) {
@@ -776,7 +776,7 @@
 		end.y += yfact >> 1;
 	}
 
-	if (color.visual.parent_index == -1)
+	if (color.visual.getParentIndex() == -1)
 		gfxop_set_color(state, &color, color);
 	_gfxop_draw_line_clipped(state, start, end, color, line_mode, line_style);
 }
@@ -894,7 +894,7 @@
 	if (shade_type == GFX_BOX_SHADE_FLAT) {
 		color1.priority = 0;
 		color1.control = 0;
-		if (color1.visual.parent_index == -1)
+		if (color1.visual.getParentIndex() == -1)
 			gfxop_set_color(state, &color1, color1);
 		drv->drawFilledRect(new_box, color1, color1, GFX_SHADE_FLAT);
 		return;
@@ -1052,9 +1052,9 @@
 	// may change when a new PIC is loaded. The cursor has to be regenerated
 	// from this pxm at that point. (An alternative might be to ensure the
 	// cursor only uses colours in the static part of the palette?)
-	if (pxm && state->driver->getMode()->palette) {
+	if (pxm && PALETTE_MODE) {
 		assert(pxm->palette);
-		pxm->palette->mergeInto(state->driver->getMode()->palette);
+		pxm->palette->mergeInto(PALETTE_MODE);
 	}
 	state->driver->setPointer(pxm, hotspot);
 }
@@ -1306,7 +1306,7 @@
 			input.character = ev.kbd.ascii;
 
 			// Debug console
-			if (ev.kbd.flags == Common::KBD_CTRL && ev.kbd.keycode == Common::KEYCODE_d) {	
+			if (ev.kbd.flags == Common::KBD_CTRL && ev.kbd.keycode == Common::KEYCODE_d) {
 				// Open debug console
 				Console *con = ((Sci::SciEngine*)g_engine)->getSciDebugger();
 				con->attach();
@@ -1625,8 +1625,8 @@
 	// FIXME: The _gfxop_install_pixmap call below updates the OSystem palette.
 	// This is too soon, since it causes brief palette corruption until the
 	// screen is updated too. (Possibly related: EngineState::pic_not_valid .)
-	if (state->pic->visual_map->palette && state->driver->getMode()->palette) {
-		state->pic->visual_map->palette->forceInto(state->driver->getMode()->palette);
+	if (state->pic->visual_map->palette && PALETTE_MODE) {
+		state->pic->visual_map->palette->forceInto(PALETTE_MODE);
 		_gfxop_install_pixmap(state->driver, state->pic->visual_map);
 	}
 

Modified: scummvm/trunk/engines/sci/gfx/palette.cpp
===================================================================
--- scummvm/trunk/engines/sci/gfx/palette.cpp	2009-09-30 16:04:21 UTC (rev 44493)
+++ scummvm/trunk/engines/sci/gfx/palette.cpp	2009-09-30 16:06:04 UTC (rev 44494)
@@ -52,7 +52,7 @@
 		_colors[i].g = colors[i].g;
 		_colors[i].b = colors[i].b;
 		_colors[i].refcount = 0;
-		_colors[i].parent_index = -1;
+		_colors[i]._parentIndex = -1;
 	}
 }
 
@@ -108,22 +108,22 @@
 
 	int count = 0;
 	for (uint i = 0; i < _size; ++i) {
-		if (_colors[i].refcount == PALENTRY_FREE) {
-			assert(_colors[i].parent_index == 0);
+		if (_colors[i].refcount == PaletteEntry::FREE) {
+			assert(_colors[i]._parentIndex == 0);
 		}
 
-		int pi = _colors[i].parent_index;
+		int pi = _colors[i]._parentIndex;
 		assert(pi >= 0);
 		assert(pi < (int)_parent->_size);
 		assert(_parent->_colors[pi].refcount != 0);
-		assert(_parent->_colors[pi].refcount != PALENTRY_FREE);
-		if (_parent->_colors[pi].refcount != PALENTRY_LOCKED)
+		assert(_parent->_colors[pi].refcount != PaletteEntry::FREE);
+		if (_parent->_colors[pi].refcount != PaletteEntry::LOCKED)
 			_parent->_colors[pi].refcount--;
 		if (_parent->_colors[pi].refcount == 0) {
-			_parent->_colors[pi].refcount = PALENTRY_FREE;
+			_parent->_colors[pi].refcount = PaletteEntry::FREE;
 			count++;
 		}
-		_colors[i].parent_index = -1;
+		_colors[i]._parentIndex = -1;
 	}
 #ifdef DEBUG_MERGE
 	fprintf(stderr, "Unmerge free %d colors\n", count);
@@ -142,12 +142,12 @@
 
 	PaletteEntry& entry = _colors[index];
 
-	assert(entry.refcount == PALENTRY_FREE || entry.refcount == 0);
+	assert(entry.refcount == PaletteEntry::FREE || entry.refcount == 0);
 	entry.refcount = 0;
 	entry.r = r;
 	entry.g = g;
 	entry.b = b;
-	entry.parent_index = parentIndex;
+	entry._parentIndex = parentIndex;
 
 	_dirty = true;
 }
@@ -158,7 +158,7 @@
 	entry.r = color.r;
 	entry.g = color.g;
 	entry.b = color.b;
-	entry.refcount = PALENTRY_LOCKED;
+	entry.refcount = PaletteEntry::LOCKED;
 }
 
 uint Palette::findNearbyColor(byte r, byte g, byte b, bool lock) {
@@ -171,7 +171,7 @@
 	for (uint i = 0; i < _size; ++i) {
 		PaletteEntry& entry = _colors[i];
 
-		if (entry.refcount != PALENTRY_FREE) {
+		if (entry.refcount != PaletteEntry::FREE) {
 			int dr = abs(entry.r - r);
 			int dg = abs(entry.g - g);
 			int db = abs(entry.b - b);
@@ -179,7 +179,7 @@
 			if (dr == 0 && dg == 0 && db == 0) {
 				// Exact match
 				//exact = true;
-				if (lock && entry.refcount != PALENTRY_LOCKED)
+				if (lock && entry.refcount != PaletteEntry::LOCKED)
 					entry.refcount++;
 				return i;
 			}
@@ -205,7 +205,7 @@
 	}
 
 	//exact = false;
-	if (lock && _colors[bestcolor].refcount != PALENTRY_LOCKED) {
+	if (lock && _colors[bestcolor].refcount != PaletteEntry::LOCKED) {
 #if 0
 			_colors[bestcolor].r = r;
 			_colors[bestcolor].g = g;
@@ -244,10 +244,10 @@
 
 	for (uint i = 0; i < _size; ++i) {
 		PaletteEntry& entry = _colors[i];
-		if (entry.refcount == PALENTRY_FREE) {
+		if (entry.refcount == PaletteEntry::FREE) {
 			// Force all unused colours to index 0
-			entry.parent_index = 0;
-			if (_parent->_colors[0].refcount != PALENTRY_LOCKED)
+			entry._parentIndex = 0;
+			if (_parent->_colors[0].refcount != PaletteEntry::LOCKED)
 				_parent->_colors[0].refcount++;
 			if (_colors[i].r || _colors[i].g || _colors[i].b)
 				warning("Non-black unused colour in pic: index %d, %02X %02X %02X", i, _colors[i].r, _colors[i].g, _colors[i].b);
@@ -261,8 +261,8 @@
 		if (pi > used_max) used_max = pi;
 		if (pi < used_min) used_min = pi;
 #endif
-		entry.parent_index = pi;
-		if (_parent->_colors[pi].refcount != PALENTRY_LOCKED)
+		entry._parentIndex = pi;
+		if (_parent->_colors[pi].refcount != PaletteEntry::LOCKED)
 			_parent->_colors[pi].refcount++;
 	}
 #ifdef DEBUG_MERGE
@@ -284,18 +284,18 @@
 	_revision = parent->_revision;
 
 	for (unsigned int i = 0; i < _size; ++i) {
-		// FIXME: PALENTRY_LOCKED doesn't work well with forceInto...
-		if (_colors[i].refcount != PALENTRY_FREE) {
+		// FIXME: PaletteEntry::LOCKED doesn't work well with forceInto...
+		if (_colors[i].refcount != PaletteEntry::FREE) {
 			_parent->_colors[i] = _colors[i];
-			_parent->_colors[i].parent_index = -1;
-			_colors[i].parent_index = i;
-			if (_parent->_colors[i].refcount != PALENTRY_LOCKED)
+			_parent->_colors[i]._parentIndex = -1;
+			_colors[i]._parentIndex = i;
+			if (_parent->_colors[i].refcount != PaletteEntry::LOCKED)
 				_parent->_colors[i].refcount = 1;
 		} else {
 			_parent->_colors[i].refcount = 0;
 			// Force all unused colours to index 0
-			_colors[i].parent_index = 0;
-			if (_parent->_colors[0].refcount != PALENTRY_LOCKED) {
+			_colors[i]._parentIndex = 0;
+			if (_parent->_colors[0].refcount != PaletteEntry::LOCKED) {
 				if (i == 0)
 					_parent->_colors[0].refcount = 1;
 				else

Modified: scummvm/trunk/engines/sci/gfx/palette.h
===================================================================
--- scummvm/trunk/engines/sci/gfx/palette.h	2009-09-30 16:04:21 UTC (rev 44493)
+++ scummvm/trunk/engines/sci/gfx/palette.h	2009-09-30 16:06:04 UTC (rev 44494)
@@ -31,15 +31,21 @@
 
 namespace Sci {
 
-const int PALENTRY_LOCKED = -42;
-const int PALENTRY_FREE = -41;
+class PaletteEntry {
 
-struct PaletteEntry {
+	friend class Palette;
+
+	enum {
+		LOCKED = -42,
+		FREE = -41
+	};
+
+public:
 	PaletteEntry()
-		: r(0), g(0), b(0), parent_index(-1), refcount(PALENTRY_FREE)
+		: r(0), g(0), b(0), _parentIndex(-1), refcount(FREE)
 	{ }
 	PaletteEntry(byte R, byte G, byte B)
-		: r(R), g(G), b(B), parent_index(-1), refcount(PALENTRY_FREE)
+		: r(R), g(G), b(B), _parentIndex(-1), refcount(LOCKED)
 	{ }
 
 	/** @name Color data */
@@ -47,9 +53,12 @@
 	byte r, g, b;
 	/** @} */
 
+	inline int getParentIndex() const { return _parentIndex; }
+
 	/** Index in parent palette, or -1 */
-	int parent_index;
+	int _parentIndex;
 
+protected:
 	/**
 	 * Number of references from child palettes. (This includes palettes
 	 * of pixmaps.)
@@ -99,9 +108,14 @@
 
 	Palette *_parent;
 
-	bool _dirty; /**< Palette has changed */
-	int _refcount; /**< Number of pixmaps (or other objects) using this palette */
-	int _revision; /**< When this is incremented, all child references are invalidated */
+	/** Palette has changed */
+	bool _dirty;
+
+	/** Number of pixmaps (or other objects) using this palette */
+	int _refcount;
+
+	/** When this is incremented, all child references are invalidated */
+	int _revision;
 };
 
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list