[Scummvm-cvs-logs] SF.net SVN: scummvm:[34878] scummvm/trunk/gui/ThemeEngine.cpp

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Mon Nov 3 16:15:32 CET 2008


Revision: 34878
          http://scummvm.svn.sourceforge.net/scummvm/?rev=34878&view=rev
Author:   fingolfin
Date:     2008-11-03 15:15:32 +0000 (Mon, 03 Nov 2008)

Log Message:
-----------
Instead of allocating (and leaking, in case of an error) a 64k table with at most 256 entries, use a HashMap

Modified Paths:
--------------
    scummvm/trunk/gui/ThemeEngine.cpp

Modified: scummvm/trunk/gui/ThemeEngine.cpp
===================================================================
--- scummvm/trunk/gui/ThemeEngine.cpp	2008-11-03 14:07:07 UTC (rev 34877)
+++ scummvm/trunk/gui/ThemeEngine.cpp	2008-11-03 15:15:32 UTC (rev 34878)
@@ -1039,9 +1039,7 @@
 	uint colorsFound = 0;
 	const OverlayColor *src = (const OverlayColor*)cursor->pixels;
 
-	byte *table = new byte[65536];
-	assert(table);
-	memset(table, 0, sizeof(byte)*65536);
+	Common::HashMap<int, int>	colorToIndex;
 
 	byte r, g, b;
 
@@ -1051,16 +1049,16 @@
 
 	_cursor = new byte[_cursorWidth * _cursorHeight];
 	assert(_cursor);
-	memset(_cursor, 255, sizeof(byte)*_cursorWidth*_cursorHeight);
+	memset(_cursor, 0xFF, sizeof(byte) * _cursorWidth * _cursorHeight);
 
 	for (uint y = 0; y < _cursorHeight; ++y) {
 		for (uint x = 0; x < _cursorWidth; ++x) {
 			_system->colorToRGB(src[x], r, g, b);
 			uint16 col = RGBToColor<ColorMasks<565> >(r, g, b);
-			if (!table[col] && col != transparency) {
-				table[col] = colorsFound++;
+			if (!colorToIndex.contains(col) && col != transparency) {
+				const int index = colorsFound++;
+				colorToIndex[col] = index;
 
-				uint index = table[col];
 				_cursorPal[index * 4 + 0] = r;
 				_cursorPal[index * 4 + 1] = g;
 				_cursorPal[index * 4 + 2] = b;
@@ -1073,7 +1071,7 @@
 			}
 
 			if (col != transparency) {
-				uint index = table[col];
+				const int index = colorToIndex[col];
 				_cursor[y * _cursorWidth + x] = index;
 			}
 		}
@@ -1081,8 +1079,7 @@
 	}
 
 	_useCursor = true;
-	delete[] table;
-	
+
 	return true;
 }
 


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