[Scummvm-cvs-logs] SF.net SVN: scummvm:[41443] scummvm/branches/gsoc2009-16bit

upthorn at users.sourceforge.net upthorn at users.sourceforge.net
Thu Jun 11 07:56:00 CEST 2009


Revision: 41443
          http://scummvm.svn.sourceforge.net/scummvm/?rev=41443&view=rev
Author:   upthorn
Date:     2009-06-11 05:56:00 +0000 (Thu, 11 Jun 2009)

Log Message:
-----------
Renamed Graphics::ColorFormat to Graphics::ColorMode, streamlined enum by removing order section and temporarily removing kFormatARGB1555
Converted cursor code to make use of _screenFormat, instead of a parameter passed directly to it by the engine.
Adjusted scumm engine to account for these changes.
This should probably have been two separate commits, but the changes concern the same files...

Modified Paths:
--------------
    scummvm/branches/gsoc2009-16bit/backends/platform/sdl/graphics.cpp
    scummvm/branches/gsoc2009-16bit/backends/platform/sdl/sdl.cpp
    scummvm/branches/gsoc2009-16bit/backends/platform/sdl/sdl.h
    scummvm/branches/gsoc2009-16bit/base/main.cpp
    scummvm/branches/gsoc2009-16bit/common/system.h
    scummvm/branches/gsoc2009-16bit/engines/engine.cpp
    scummvm/branches/gsoc2009-16bit/engines/engine.h
    scummvm/branches/gsoc2009-16bit/engines/scumm/cursor.cpp
    scummvm/branches/gsoc2009-16bit/engines/scumm/scumm.cpp
    scummvm/branches/gsoc2009-16bit/graphics/cursorman.cpp
    scummvm/branches/gsoc2009-16bit/graphics/cursorman.h
    scummvm/branches/gsoc2009-16bit/graphics/pixelformat.h

Modified: scummvm/branches/gsoc2009-16bit/backends/platform/sdl/graphics.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/platform/sdl/graphics.cpp	2009-06-11 01:50:10 UTC (rev 41442)
+++ scummvm/branches/gsoc2009-16bit/backends/platform/sdl/graphics.cpp	2009-06-11 05:56:00 UTC (rev 41443)
@@ -123,6 +123,13 @@
 
 			_videoMode.mode = _oldVideoMode.mode;
 			_videoMode.scaleFactor = _oldVideoMode.scaleFactor;
+#ifdef ENABLE_16BIT
+		} else if (_videoMode.format != _oldVideoMode.format) {
+			errors |= kTransactionPixelFormatNotSupported;
+
+			_videoMode.format = _oldVideoMode.format;
+			_screenFormat = getPixelFormat(_videoMode.format);
+#endif
 		} else if (_videoMode.screenWidth != _oldVideoMode.screenWidth || _videoMode.screenHeight != _oldVideoMode.screenHeight) {
 			errors |= kTransactionSizeChangeFailed;
 
@@ -130,12 +137,6 @@
 			_videoMode.screenHeight = _oldVideoMode.screenHeight;
 			_videoMode.overlayWidth = _oldVideoMode.overlayWidth;
 			_videoMode.overlayHeight = _oldVideoMode.overlayHeight;
-#ifdef ENABLE_16BIT
-		} else if (_videoMode.format != _oldVideoMode.format) {
-			errors |= kTransactionPixelFormatNotSupported;
-
-			_videoMode.format = _oldVideoMode.format;
-#endif
 		}
 
 		if (_videoMode.fullscreen == _oldVideoMode.fullscreen &&
@@ -153,32 +154,8 @@
 	}
 
 #ifdef ENABLE_16BIT
-	if (_transactionDetails.formatChanged) {
-		_screenFormat = getPixelFormat(_videoMode.format);
-		if (!_transactionDetails.sizeChanged) {
-			unloadGFXMode();
-			if (!loadGFXMode()) {
-				if (_oldVideoMode.setup) {
-					_transactionMode = kTransactionRollback;
-					errors |= endGFXTransaction();
-				}
-			} else {
-				setGraphicsModeIntern();
-				clearOverlay();
-
-				_videoMode.setup = true;
-				_modeChanged = true;
-				// OSystem_SDL::pollEvent used to update the screen change count,
-				// but actually it gives problems when a video mode was changed
-				// but OSystem_SDL::pollEvent was not called. This for example
-				// caused a crash under certain circumstances when doing an RTL.
-				// To fix this issue we update the screen change count right here.
-				_screenChangeCount++;
-			}	
-		}
-	}
+	if (_transactionDetails.sizeChanged || _transactionDetails.formatChanged) {
 #endif
-	if (_transactionDetails.sizeChanged) {
 		unloadGFXMode();
 		if (!loadGFXMode()) {
 			if (_oldVideoMode.setup) {
@@ -375,11 +352,11 @@
 	return _videoMode.mode;
 }
 #ifdef ENABLE_16BIT
-Graphics::ColorFormat OSystem_SDL::findCompatibleFormat(Common::List<Graphics::ColorFormat> formatList) {
+Graphics::ColorMode OSystem_SDL::findCompatibleFormat(Common::List<Graphics::ColorMode> formatList) {
 	bool typeAccepted = false;
-	Graphics::ColorFormat format;
+	Graphics::ColorMode format;
 	
-	while (!formatList.empty() && !typeAccepted) {
+	while (!formatList.empty()) {
 		typeAccepted = false;
 		format = formatList.front();
 
@@ -389,33 +366,21 @@
 			return format;
 
 		formatList.pop_front();
-		switch (format & Graphics::kFormatTypeMask) {
-		case Graphics::kFormat8Bit:
-			if (format == Graphics::kFormat8Bit)
+		switch (format) {
+		case Graphics::kFormatCLUT8:
+			if (format == Graphics::kFormatCLUT8)
 				return format;
 			break;
 		case Graphics::kFormatRGB555:
-		case Graphics::kFormatARGB1555:
 		case Graphics::kFormatRGB565:
-			typeAccepted = true;
-			break;
-		}
-
-		if (!typeAccepted)
-			continue;
-
-		switch (format & Graphics::kFormatOrderMask) {
-		case Graphics::kFormatRGB:
-		case Graphics::kFormatRGBA:
 			return format;
-		default:
 			break;
 		}
 	}
-	return Graphics::kFormat8Bit;
+	return Graphics::kFormatCLUT8;
 }
 
-void OSystem_SDL::initFormat(Graphics::ColorFormat format) {
+void OSystem_SDL::initFormat(Graphics::ColorMode format) {
 	assert(_transactionMode == kTransactionActive);
 
 	//avoid redundant format changes
@@ -424,17 +389,13 @@
 
 	_videoMode.format = format;
 	_transactionDetails.formatChanged = true;
-
+	_screenFormat = getPixelFormat(format);
 }
 
 //This should only ever be called with a format that is known supported.
-Graphics::PixelFormat OSystem_SDL::getPixelFormat(Graphics::ColorFormat format) {
+Graphics::PixelFormat OSystem_SDL::getPixelFormat(Graphics::ColorMode format) {
 	Graphics::PixelFormat result;
-	switch (format & Graphics::kFormatTypeMask) {
-	case Graphics::kFormatARGB1555:
-		result.aLoss = 7;
-		result.bytesPerPixel = 2;
-		result.rLoss = result.gLoss = result.bLoss = 3;
+	switch (format) {
 	case Graphics::kFormatRGB555:
 		result.aLoss = 8;
 		result.bytesPerPixel = 2;
@@ -446,24 +407,17 @@
 		result.gLoss = 2;
 		result.rLoss = result.bLoss = 3;
 		break;
-	case Graphics::kFormat8Bit:
+	case Graphics::kFormatCLUT8:
 	default:
 		result.bytesPerPixel = 1;
 		result.rShift = result.gShift = result.bShift = result.aShift = 0;
 		result.rLoss = result.gLoss = result.bLoss = result.aLoss = 8;
 		return result;
 	}
-	switch (format & Graphics::kFormatOrderMask) {
-	default:
-	case Graphics::kFormatRGBA:
-		result.aShift = 0;
-		// fall through
-	case Graphics::kFormatRGB:
-		result.bShift = result.aBits();
-		result.gShift = result.bShift + result.bBits();
-		result.rShift = result.gShift + result.gBits();
-		break;
-	}
+	result.aShift = 0;
+	result.bShift = result.aBits();
+	result.gShift = result.bShift + result.bBits();
+	result.rShift = result.gShift + result.gBits();
 	return result;
 }
 #endif
@@ -1473,15 +1427,8 @@
 }
 
 #ifdef ENABLE_16BIT
-void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, uint8 bitDepth) {
-	uint32 colmask = 0xFF;
-	uint8 byteDepth = bitDepth >> 3;
-	for (int i = byteDepth; i > 1; i--) {
-		colmask <<= 8;
-		colmask |= 0xFF;
-	}
-	keycolor &= colmask;
-	_cursorBitDepth = bitDepth;
+void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale) {
+	keycolor &= (1 << (_screenFormat.bytesPerPixel << 3)) - 1;
 #else
 void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale) {
 #endif
@@ -1520,8 +1467,8 @@
 
 	free(_mouseData);
 #ifdef ENABLE_16BIT
-	_mouseData = (byte *)malloc(w * h * byteDepth);
-	memcpy(_mouseData, buf, w * h * byteDepth);
+	_mouseData = (byte *)malloc(w * h * _screenFormat.bytesPerPixel);
+	memcpy(_mouseData, buf, w * h * _screenFormat.bytesPerPixel);
 #else
 	_mouseData = (byte *)malloc(w * h);
 	memcpy(_mouseData, buf, w * h);
@@ -1533,7 +1480,12 @@
 void OSystem_SDL::blitCursor() {
 	byte *dstPtr;
 	const byte *srcPtr = _mouseData;
+#ifdef ENABLE_16BIT
+	uint32 color;
+	uint32 colormask = (1 << (_screenFormat.bytesPerPixel << 3)) - 1;
+#else
 	byte color;
+#endif
 	int w, h, i, j;
 
 	if (!_mouseOrigSurface || !_mouseData)
@@ -1567,20 +1519,20 @@
 
 	for (i = 0; i < h; i++) {
 		for (j = 0; j < w; j++) {
-			color = *srcPtr;
 #ifdef ENABLE_16BIT
-			if (_cursorBitDepth == 16) {
+			if (_screenFormat.bytesPerPixel > 1) {
+				color = (*(uint32 *) srcPtr) & colormask;
 				if (color != _mouseKeyColor) {	// transparent, don't draw
-					int8 r = ((*(uint16 *)srcPtr >> 10) & 0x1F) << 3;
-					int8 g = ((*(uint16 *)srcPtr >> 5) & 0x1F) << 3;
-					int8 b = (*(uint16 *)srcPtr & 0x1F) << 3;
+					uint8 r,g,b;
+					_screenFormat.colorToRGB(color,r,g,b);
 					*(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format,
 						r, g, b);
 				}
 				dstPtr += 2;
-				srcPtr += 2;
+				srcPtr += _screenFormat.bytesPerPixel;
 			} else {
 #endif
+				color = *srcPtr;
 				if (color != _mouseKeyColor) {	// transparent, don't draw
 					*(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format,
 						palette[color].r, palette[color].g, palette[color].b);

Modified: scummvm/branches/gsoc2009-16bit/backends/platform/sdl/sdl.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/platform/sdl/sdl.cpp	2009-06-11 01:50:10 UTC (rev 41442)
+++ scummvm/branches/gsoc2009-16bit/backends/platform/sdl/sdl.cpp	2009-06-11 05:56:00 UTC (rev 41443)
@@ -197,7 +197,7 @@
 #endif
 	_hwscreen(0), _screen(0), _tmpscreen(0),
 #ifdef ENABLE_16BIT
-	_screenFormat(getPixelFormat(Graphics::kFormat8Bit)),
+	_screenFormat(getPixelFormat(Graphics::kFormatCLUT8)),
 	_cursorBitDepth(8),
 #endif
 	_overlayVisible(false),

Modified: scummvm/branches/gsoc2009-16bit/backends/platform/sdl/sdl.h
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/platform/sdl/sdl.h	2009-06-11 01:50:10 UTC (rev 41442)
+++ scummvm/branches/gsoc2009-16bit/backends/platform/sdl/sdl.h	2009-06-11 05:56:00 UTC (rev 41443)
@@ -84,17 +84,17 @@
 #ifdef ENABLE_16BIT
 	// Find a compatible format from the list of formats supported by the engine
 	// Fallback to CLUT8 if none found
-	virtual Graphics::ColorFormat findCompatibleFormat(Common::List<Graphics::ColorFormat> formatList);
+	virtual Graphics::ColorMode findCompatibleFormat(Common::List<Graphics::ColorMode> formatList);
 
 	// Set the depth and format of the video bitmap
 	// Typically, CLUT8
-	virtual void initFormat(Graphics::ColorFormat format);
+	virtual void initFormat(Graphics::ColorMode format);
 
 	// Game screen
 	virtual Graphics::PixelFormat getScreenFormat() const { return _screenFormat; }
 
 	//Create a Graphics::PixelFormat to describe the requested color mode
-	virtual Graphics::PixelFormat getPixelFormat(Graphics::ColorFormat format);
+	virtual Graphics::PixelFormat getPixelFormat(Graphics::ColorMode format);
 #endif
 
 	// Set the size of the video bitmap.
@@ -129,7 +129,7 @@
 
 	// Set the bitmap that's used when drawing the cursor.
 #ifdef ENABLE_16BIT
-	virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, uint8 bitDepth = 8); // overloaded by CE backend (FIXME)
+	virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale); // overloaded by CE backend (FIXME)
 #else
 	virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale); // overloaded by CE backend (FIXME)
 #endif
@@ -302,7 +302,7 @@
 		int screenWidth, screenHeight;
 		int overlayWidth, overlayHeight;
 #ifdef ENABLE_16BIT
-		Graphics::ColorFormat format;
+		Graphics::ColorMode format;
 #endif
 	};
 	VideoState _videoMode, _oldVideoMode;

Modified: scummvm/branches/gsoc2009-16bit/base/main.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/base/main.cpp	2009-06-11 01:50:10 UTC (rev 41442)
+++ scummvm/branches/gsoc2009-16bit/base/main.cpp	2009-06-11 05:56:00 UTC (rev 41443)
@@ -227,7 +227,7 @@
 		system.setGraphicsMode(ConfMan.get("gfx_mode").c_str());
 
 #ifdef ENABLE_16BIT
-		system.initFormat(Graphics::kFormat8Bit);
+		system.initFormat(Graphics::kFormatCLUT8);
 #endif
 		system.initSize(320, 200);
 

Modified: scummvm/branches/gsoc2009-16bit/common/system.h
===================================================================
--- scummvm/branches/gsoc2009-16bit/common/system.h	2009-06-11 01:50:10 UTC (rev 41442)
+++ scummvm/branches/gsoc2009-16bit/common/system.h	2009-06-11 05:56:00 UTC (rev 41443)
@@ -357,9 +357,9 @@
 	 *
 	 * @param formatList	A list of requested pixel formats, ordered by priority
 	 *
-	 * @return a supported ColorFormat from the list, or kFormat8Bit if no supported format was found
+	 * @return a supported ColorMode from the list, or kFormatCLUT8 if no supported format was found
 	 */
-	virtual Graphics::ColorFormat findCompatibleFormat(Common::List<Graphics::ColorFormat> formatList) = 0;
+	virtual Graphics::ColorMode findCompatibleFormat(Common::List<Graphics::ColorMode> formatList) = 0;
 
 	/**
 	 * Set the color format of the virtual screen. Typical formats include:
@@ -374,7 +374,7 @@
 	 *
 	 * @param format	A pixel format that the backend screen will use
 	 */
-	virtual void initFormat(Graphics::ColorFormat format) = 0;
+	virtual void initFormat(Graphics::ColorMode format) = 0;
 
 	/**
 	 * Returns the pixel format description of the screen.
@@ -386,7 +386,7 @@
 	 * Returns the pixel format description of the requested color mode
 	 * @see Graphics::PixelFormat
 	 */
-	virtual Graphics::PixelFormat getPixelFormat(Graphics::ColorFormat format) = 0;
+	virtual Graphics::PixelFormat getPixelFormat(Graphics::ColorMode format) = 0;
 
 #endif
 
@@ -738,7 +738,7 @@
 	 * @param cursorTargetScale	scale factor which cursor is designed for
 	 */
 #ifdef ENABLE_16BIT
-	virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor = 0xFFFFFFFF, int cursorTargetScale = 1, uint8 bitDepth = 8) = 0;
+	virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor = 0xFFFFFFFF, int cursorTargetScale = 1) = 0;
 #else
 	virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor = 255, int cursorTargetScale = 1) = 0;
 #endif

Modified: scummvm/branches/gsoc2009-16bit/engines/engine.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/engine.cpp	2009-06-11 01:50:10 UTC (rev 41442)
+++ scummvm/branches/gsoc2009-16bit/engines/engine.cpp	2009-06-11 05:56:00 UTC (rev 41443)
@@ -126,18 +126,18 @@
 }
 void initGraphics(int width, int height, bool defaultTo1xScaler) {
 #ifdef ENABLE_16BIT
-	Common::List<Graphics::ColorFormat> formatList;
-	formatList.push_back(Graphics::kFormat8Bit);
+	Common::List<Graphics::ColorMode> formatList;
+	formatList.push_back(Graphics::kFormatCLUT8);
 	initGraphics(width,height,defaultTo1xScaler, formatList);
 }
-void initGraphics(int width, int height, bool defaultTo1xScaler, Common::List<Graphics::ColorFormat> formatList) {
+void initGraphics(int width, int height, bool defaultTo1xScaler, Common::List<Graphics::ColorMode> formatList) {
 #endif
 
 	g_system->beginGFXTransaction();
 
 		initCommonGFX(defaultTo1xScaler);
 #ifdef ENABLE_16BIT
-		Graphics::ColorFormat format = g_system->findCompatibleFormat(formatList);
+		Graphics::ColorMode format = g_system->findCompatibleFormat(formatList);
 		debug("%X",format); //TODO: set up the pixelFormat here
 		g_system->initFormat(format);
 #endif
@@ -161,6 +161,15 @@
 		error("%s", message.c_str());
 	}
 
+#ifdef ENABLE_16BIT
+	if (gfxError & OSystem::kTransactionPixelFormatNotSupported) {
+		Common::String message = "Could not initialize color format.";
+
+		GUIErrorMessage(message);
+		error("%s", message.c_str());
+	}
+#endif
+
 	// Just show warnings then these occur:
 	if (gfxError & OSystem::kTransactionModeSwitchFailed) {
 		Common::String message = "Could not switch to video mode: '";

Modified: scummvm/branches/gsoc2009-16bit/engines/engine.h
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/engine.h	2009-06-11 01:50:10 UTC (rev 41442)
+++ scummvm/branches/gsoc2009-16bit/engines/engine.h	2009-06-11 05:56:00 UTC (rev 41443)
@@ -63,7 +63,7 @@
  * mode.
  */
 #ifdef ENABLE_16BIT
-void initGraphics(int width, int height, bool defaultTo1xScaler, Common::List<Graphics::ColorFormat> formatList);
+void initGraphics(int width, int height, bool defaultTo1xScaler, Common::List<Graphics::ColorMode> formatList);
 #endif
 void initGraphics(int width, int height, bool defaultTo1xScaler);
 

Modified: scummvm/branches/gsoc2009-16bit/engines/scumm/cursor.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/scumm/cursor.cpp	2009-06-11 01:50:10 UTC (rev 41442)
+++ scummvm/branches/gsoc2009-16bit/engines/scumm/cursor.cpp	2009-06-11 05:56:00 UTC (rev 41443)
@@ -112,21 +112,10 @@
 
 void ScummEngine::updateCursor() {
 	int transColor = (_game.heversion >= 80) ? 5 : 255;
-	if (_game.features & GF_16BIT_COLOR) {
-		//HACK Had to make a second method to avoid many, many linker errors from other engines
-		//this requires ENABLE_16BIT to be defined in the Scumm project, again, because I #ifdef'ed
-		//the method's definition and declaration in cursorman.h 
-		CursorMan.replaceCursorReal(_grabbedCursor, _cursor.width, _cursor.height,
-								_cursor.hotspotX, _cursor.hotspotY,
-								(_game.platform == Common::kPlatformNES ? _grabbedCursor[63] : transColor),
-								(_game.heversion == 70 ? 2 : 1),
-								16);
-	} else {
-		CursorMan.replaceCursor(_grabbedCursor, _cursor.width, _cursor.height,
-								_cursor.hotspotX, _cursor.hotspotY,
-								(_game.platform == Common::kPlatformNES ? _grabbedCursor[63] : transColor),
-								(_game.heversion == 70 ? 2 : 1));
-	}
+	CursorMan.replaceCursor(_grabbedCursor, _cursor.width, _cursor.height,
+							_cursor.hotspotX, _cursor.hotspotY,
+							(_game.platform == Common::kPlatformNES ? _grabbedCursor[63] : transColor),
+							(_game.heversion == 70 ? 2 : 1));
 }
 
 void ScummEngine_v6::grabCursor(int x, int y, int w, int h) {

Modified: scummvm/branches/gsoc2009-16bit/engines/scumm/scumm.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/scumm/scumm.cpp	2009-06-11 01:50:10 UTC (rev 41442)
+++ scummvm/branches/gsoc2009-16bit/engines/scumm/scumm.cpp	2009-06-11 05:56:00 UTC (rev 41443)
@@ -1083,12 +1083,14 @@
 					// CJK FT and DIG use usual NUT fonts, not FM-TOWNS ROM, so
 					// there is no text surface for them. This takes that into account
 					(_screenWidth * _textSurfaceMultiplier > 320));
+#ifdef ENABLE_16BIT
 	} else if (_game.features & GF_16BIT_COLOR) {
-		int format = Graphics::kFormatRGB555 | Graphics::kFormatRGB;
-		Common::List<Graphics::ColorFormat> formatList;
-		formatList.push_back((Graphics::ColorFormat) format);
-		formatList.push_back(Graphics::kFormat8Bit);
+		int format = Graphics::kFormatRGB555;
+		Common::List<Graphics::ColorMode> formatList;
+		formatList.push_back((Graphics::ColorMode) format);
+		formatList.push_back(Graphics::kFormatCLUT8);
 		initGraphics(_screenWidth, _screenHeight, _screenWidth > 320, formatList);
+#endif
 	} else {
 		initGraphics(_screenWidth, _screenHeight, _screenWidth > 320);
 	}

Modified: scummvm/branches/gsoc2009-16bit/graphics/cursorman.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/graphics/cursorman.cpp	2009-06-11 01:50:10 UTC (rev 41442)
+++ scummvm/branches/gsoc2009-16bit/graphics/cursorman.cpp	2009-06-11 05:56:00 UTC (rev 41443)
@@ -57,33 +57,18 @@
 	return g_system->showMouse(visible);
 }
 
-void CursorManager::pushCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor, int targetScale) {
 #ifdef ENABLE_16BIT
-	pushCursorReal(buf,w,h,hotspotX,hotspotY,keycolor,targetScale,8);
-}
-void CursorManager::pushCursorReal(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int targetScale, uint8 bitDepth) {
-	uint32 colmask = 0xFF;
-	uint8 byteDepth = bitDepth >> 3;
-	for (int i = byteDepth; i > 1; i--) {
-		colmask <<= 8;
-		colmask |= 0xFF;
-	}
-	keycolor &= colmask;
-
-	Cursor *cur = new Cursor(buf, w, h, hotspotX, hotspotY, keycolor, targetScale, bitDepth);
+void CursorManager::pushCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int targetScale) {
 #else
-	Cursor *cur = new Cursor(buf, w, h, hotspotX, hotspotY, keycolor, targetScale);
+void CursorManager::pushCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor, int targetScale) {
 #endif
+	Cursor *cur = new Cursor(buf, w, h, hotspotX, hotspotY, keycolor, targetScale);
 
 	cur->_visible = isVisible();
 	_cursorStack.push(cur);
 
 	if (buf) {
-#ifdef ENABLE_16BIT
-		g_system->setMouseCursor(cur->_data, w, h, hotspotX, hotspotY, keycolor, targetScale, bitDepth);
-#else
 		g_system->setMouseCursor(cur->_data, w, h, hotspotX, hotspotY, keycolor, targetScale);
-#endif
 	}
 }
 
@@ -96,11 +81,7 @@
 
 	if (!_cursorStack.empty()) {
 		cur = _cursorStack.top();
-#ifdef ENABLE_16BIT
-		g_system->setMouseCursor(cur->_data, cur->_width, cur->_height, cur->_hotspotX, cur->_hotspotY, cur->_keycolor, cur->_targetScale, cur->_bitDepth);
-#else
 		g_system->setMouseCursor(cur->_data, cur->_width, cur->_height, cur->_hotspotX, cur->_hotspotY, cur->_keycolor, cur->_targetScale);
-#endif
 	}
 
 	g_system->showMouse(isVisible());
@@ -123,34 +104,25 @@
 	g_system->showMouse(isVisible());
 }
 
-void CursorManager::replaceCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor, int targetScale) {
 #ifdef ENABLE_16BIT
-	replaceCursorReal(buf,w,h,hotspotX,hotspotY,keycolor,targetScale);
-}
-
-void CursorManager::replaceCursorReal(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int targetScale, uint8 bitDepth) {
-	uint32 colmask = 0xFF;
-	uint8 byteDepth = bitDepth >> 3;
-	for (int i = byteDepth; i > 1; i--) {
-		colmask <<= 8;
-		colmask |= 0xFF;
-	}
-	keycolor &= colmask;
-
+void CursorManager::replaceCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int targetScale) {
+#else
+void CursorManager::replaceCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor, int targetScale) {
 #endif
+
 	if (_cursorStack.empty()) {
-#ifdef ENABLE_16BIT
-		pushCursorReal(buf, w, h, hotspotX, hotspotY, keycolor, targetScale, bitDepth);
-#else
 		pushCursor(buf, w, h, hotspotX, hotspotY, keycolor, targetScale);
-#endif
 		return;
 	}
 
 	Cursor *cur = _cursorStack.top();
 
 #ifdef ENABLE_16BIT
-	uint size = w * h * (bitDepth >> 3);
+		uint size;
+		{	//limit the lifespan of the format variable to minimize memory impact
+		Graphics::PixelFormat f = g_system->getScreenFormat();
+		size = w * h * (f.bytesPerPixel);
+	}
 #else
 	uint size = w * h;
 #endif
@@ -171,11 +143,7 @@
 	cur->_keycolor = keycolor;
 	cur->_targetScale = targetScale;
 
-#ifdef ENABLE_16BIT
-	g_system->setMouseCursor(cur->_data, w, h, hotspotX, hotspotY, keycolor, targetScale, bitDepth);
-#else
 	g_system->setMouseCursor(cur->_data, w, h, hotspotX, hotspotY, keycolor, targetScale);
-#endif
 }
 
 void CursorManager::disableCursorPalette(bool disable) {

Modified: scummvm/branches/gsoc2009-16bit/graphics/cursorman.h
===================================================================
--- scummvm/branches/gsoc2009-16bit/graphics/cursorman.h	2009-06-11 01:50:10 UTC (rev 41442)
+++ scummvm/branches/gsoc2009-16bit/graphics/cursorman.h	2009-06-11 05:56:00 UTC (rev 41443)
@@ -28,6 +28,10 @@
 #include "common/scummsys.h"
 #include "common/stack.h"
 #include "common/singleton.h"
+#ifdef ENABLE_16BIT
+#include "graphics/pixelformat.h"
+#include "common/system.h"
+#endif
 
 namespace Graphics {
 
@@ -56,10 +60,11 @@
 	 *       useful to push a "dummy" cursor and modify it later. The
 	 *       cursor will be added to the stack, but not to the backend.
 	 */
-	void pushCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor = 255, int targetScale = 1);
-#ifdef ENABLE_16BIT
-	void pushCursorReal(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor = 0xFFFFFFFF, int targetScale = 1, uint8 bitDepth = 8);
-#endif
+//#ifdef ENABLE_16BIT
+	void pushCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor = 0xFFFFFFFF, int targetScale = 1);
+//#else
+//	void pushCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor = 255, int targetScale = 1);
+//#endif
 
 	/**
 	 * Pop a cursor from the stack, and restore the previous one to the
@@ -80,11 +85,11 @@
 	 * @param keycolor	the index for the transparent color
 	 * @param targetScale	the scale for which the cursor is designed
 	 */
-	void replaceCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor = 255, int targetScale = 1);
-#ifdef ENABLE_16BIT
-	//HACK made a separate method to avoid massive linker errors on every engine.
-	void replaceCursorReal(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor = 0xFFFFFFFF, int targetScale = 1, uint8 bitDepth = 8);
-#endif
+//#ifdef ENABLE_16BIT
+	void replaceCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor = 0xFFFFFFFF, int targetScale = 1);
+//#else
+//	void replaceCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor = 255, int targetScale = 1);
+//#endif
 
 	/**
 	 * Pop all of the cursors and cursor palettes from their respective stacks.
@@ -148,28 +153,22 @@
 		uint _height;
 		int _hotspotX;
 		int _hotspotY;
-#ifdef ENABLE_16BIT
+//#ifdef ENABLE_16BIT
 		uint32 _keycolor;
-		uint8 _bitDepth;
-#else
-		byte _keycolor;
-#endif
+//#else
+//		byte _keycolor;
+//#endif
 		byte _targetScale;
 
 
 		uint _size;
 #ifdef ENABLE_16BIT
 		Cursor(const byte *data, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor = 0xFFFFFFFF, int targetScale = 1, uint8 bitDepth = 8) {
-			uint32 colmask = 0xFF;
-			uint8 byteDepth = bitDepth >> 3;
-			_size = w * h * byteDepth;
-			_bitDepth = bitDepth;
-			for (int i = byteDepth; i > 1; i--) {
-				colmask <<= 8;
-				colmask |= 0xFF;
+			{	//limit the lifespan of the format value to minimize impact on memory usage
+				Graphics::PixelFormat f = g_system->getScreenFormat();
+				_size = w * h * f.bytesPerPixel;
+				_keycolor = keycolor & ((1 << (f.bytesPerPixel << 3)) - 1);
 			}
-			_keycolor = keycolor & colmask;
-
 #else
 		Cursor(const byte *data, uint w, uint h, int hotspotX, int hotspotY, byte keycolor = 255, int targetScale = 1) {
 			_size = w * h;

Modified: scummvm/branches/gsoc2009-16bit/graphics/pixelformat.h
===================================================================
--- scummvm/branches/gsoc2009-16bit/graphics/pixelformat.h	2009-06-11 01:50:10 UTC (rev 41442)
+++ scummvm/branches/gsoc2009-16bit/graphics/pixelformat.h	2009-06-11 05:56:00 UTC (rev 41443)
@@ -43,50 +43,16 @@
  * Use (format & kFormatTypeMask) to get the type, and (format & kFormatOrderMask)
  * to get the applicable color order.
   */
-enum ColorFormat {
-	kFormat8Bit = 0,
+enum ColorMode {
+	kFormatCLUT8 = 0,
 	kFormatRGB555 = 1,
-	kFormatARGB1555 = 2,	// Rare, but I know a guy who knows a guy who's heard of it being used
-	kFormatRGB556 = 3,		// 6 bits for blue, in case this ever happens
-	kFormatRGB565 = 4,
-	kFormatRGB655 = 5,		// 6 bits for red, in case this ever happens
-	kFormatARGB4444 = 6,
-	kFormatRGB888 = 7,
-	kFormatARGB6666 = 8,	// I've never heard of this, but it's theoretically possible
-	kFormatARGB8888 = 9,
-	kFormatTypeMask = 0xFF, // & by this to get the overall bit format
-	kFormatPalette = 0 << 8,
-	kFormatRGB = 1 << 8,
-	kFormatRBG = 2 << 8,
-	kFormatGRB = 3 << 8,
-	kFormatGBR = 4 << 8,
-	kFormatBRG = 5 << 8,
-	kFormatBGR = 6 << 8,
-	kFormatARGB = 7 << 8,
-	kFormatARBG = 8 << 8,
-	kFormatAGRB = 9 << 8,
-	kFormatAGBR = 10 << 8,
-	kFormatABRG = 11 << 8,
-	kFormatABGR = 12 << 8,
-	kFormatRAGB = 13 << 8,
-	kFormatRABG = 14 << 8,
-	kFormatGARB = 15 << 8,
-	kFormatGABR = 16 << 8,
-	kFormatBARG = 17 << 8,
-	kFormatBAGR = 18 << 8,
-	kFormatRGAB = 19 << 8,
-	kFormatRBAG = 20 << 8,
-	kFormatGRAB = 21 << 8,
-	kFormatGBAR = 22 << 8,
-	kFormatBRAG = 23 << 8,
-	kFormatBGAR = 24 << 8,
-	kFormatRGBA = 25 << 8,
-	kFormatRBGA = 26 << 8,
-	kFormatGRBA = 27 << 8,
-	kFormatGBRA = 28 << 8,
-	kFormatBRGA = 29 << 8,
-	kFormatBGRA = 30 << 8,
-	kFormatOrderMask = 0xFF << 8 // & by this to get the order
+	kFormatRGB556 = 2,		// 6 bits for blue, in case this ever happens
+	kFormatRGB565 = 3,
+	kFormatRGB655 = 4,		// 6 bits for red, in case this ever happens
+	kFormatRGBA4444 = 5,
+	kFormatRGB888 = 6,
+	kFormatRGBA6666 = 7,	// I've never heard of this, but it's theoretically possible
+	kFormatRGBA8888 = 8
 };
 #endif
 


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