diff options
| author | Jody Northup | 2009-08-21 09:37:51 +0000 | 
|---|---|---|
| committer | Jody Northup | 2009-08-21 09:37:51 +0000 | 
| commit | 3084919b32771d43d17fdd5d584505cd31d20b72 (patch) | |
| tree | 3f42b5e0cb69f340ccd30fad96f6ee4e51e260cf /graphics | |
| parent | cba2897cc8f7b70d27fc75ca8b8d55cde4738e4a (diff) | |
| parent | 89d7fea4e619cd44d5ce16eee1e46ad417e26c9c (diff) | |
| download | scummvm-rg350-3084919b32771d43d17fdd5d584505cd31d20b72.tar.gz scummvm-rg350-3084919b32771d43d17fdd5d584505cd31d20b72.tar.bz2 scummvm-rg350-3084919b32771d43d17fdd5d584505cd31d20b72.zip  | |
Merged RGB color API and support in from /scummvm/branches/gsoc2009-16bit/
svn-id: r43577
Diffstat (limited to 'graphics')
| -rw-r--r-- | graphics/cursorman.cpp | 29 | ||||
| -rw-r--r-- | graphics/cursorman.h | 36 | ||||
| -rw-r--r-- | graphics/pixelformat.h | 39 | ||||
| -rw-r--r-- | graphics/scaler.cpp | 9 | 
4 files changed, 91 insertions, 22 deletions
diff --git a/graphics/cursorman.cpp b/graphics/cursorman.cpp index 2e71b548bc..b77aac37cf 100644 --- a/graphics/cursorman.cpp +++ b/graphics/cursorman.cpp @@ -57,14 +57,14 @@ bool CursorManager::showMouse(bool visible) {  	return g_system->showMouse(visible);  } -void CursorManager::pushCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor, int targetScale) { -	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, uint32 keycolor, int targetScale, const Graphics::PixelFormat *format) { +	Cursor *cur = new Cursor(buf, w, h, hotspotX, hotspotY, keycolor, targetScale, format);  	cur->_visible = isVisible();  	_cursorStack.push(cur);  	if (buf) { -		g_system->setMouseCursor(cur->_data, w, h, hotspotX, hotspotY, keycolor, targetScale); +		g_system->setMouseCursor(cur->_data, w, h, hotspotX, hotspotY, keycolor, targetScale, format);  	}  } @@ -77,7 +77,7 @@ void CursorManager::popCursor() {  	if (!_cursorStack.empty()) {  		cur = _cursorStack.top(); -		g_system->setMouseCursor(cur->_data, cur->_width, cur->_height, cur->_hotspotX, cur->_hotspotY, cur->_keycolor, cur->_targetScale); +		g_system->setMouseCursor(cur->_data, cur->_width, cur->_height, cur->_hotspotX, cur->_hotspotY, cur->_keycolor, cur->_targetScale, &cur->_format);  	}  	g_system->showMouse(isVisible()); @@ -100,15 +100,24 @@ void CursorManager::popAllCursors() {  	g_system->showMouse(isVisible());  } +void CursorManager::replaceCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int targetScale, const Graphics::PixelFormat *format) { -void CursorManager::replaceCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor, int targetScale) {  	if (_cursorStack.empty()) { -		pushCursor(buf, w, h, hotspotX, hotspotY, keycolor, targetScale); +		pushCursor(buf, w, h, hotspotX, hotspotY, keycolor, targetScale, format);  		return;  	}  	Cursor *cur = _cursorStack.top(); + +#ifdef ENABLE_RGB_COLOR +	uint size; +	if (!format) +		size = w * h; +	else +		size = w * h * format->bytesPerPixel; +#else  	uint size = w * h; +#endif  	if (cur->_size < size) {  		delete[] cur->_data; @@ -125,8 +134,14 @@ void CursorManager::replaceCursor(const byte *buf, uint w, uint h, int hotspotX,  	cur->_hotspotY = hotspotY;  	cur->_keycolor = keycolor;  	cur->_targetScale = targetScale; +#ifdef ENABLE_RGB_COLOR +	if (format) +		cur->_format = *format; +	else +		cur->_format = Graphics::PixelFormat::createFormatCLUT8(); +#endif -	g_system->setMouseCursor(cur->_data, w, h, hotspotX, hotspotY, keycolor, targetScale); +	g_system->setMouseCursor(cur->_data, w, h, hotspotX, hotspotY, keycolor, targetScale, format);  }  bool CursorManager::supportsCursorPalettes() { diff --git a/graphics/cursorman.h b/graphics/cursorman.h index f019e37b04..ae7008f54c 100644 --- a/graphics/cursorman.h +++ b/graphics/cursorman.h @@ -28,6 +28,10 @@  #include "common/scummsys.h"  #include "common/stack.h"  #include "common/singleton.h" +#include "graphics/pixelformat.h" +#ifdef ENABLE_RGB_COLOR +#include "common/system.h" +#endif  namespace Graphics { @@ -59,18 +63,19 @@ public:  	 * safely freed afterwards.  	 *  	 * @param buf		the new cursor data -	 * @param w		the width -	 * @param h		the height +	 * @param w			the width +	 * @param h			the height  	 * @param hotspotX	the hotspot X coordinate  	 * @param hotspotY	the hotspot Y coordinate  	 * @param keycolor	the index for the transparent color  	 * @param targetScale	the scale for which the cursor is designed -	 * +	 * @param format	a pointer to the pixel format which the cursor graphic uses,  +	 *					CLUT8 will be used if this is NULL or not specified.  	 * @note It is ok for the buffer to be a NULL pointer. It is sometimes  	 *       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); +	void pushCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor = 0xFFFFFFFF, int targetScale = 1, const Graphics::PixelFormat *format = NULL);  	/**  	 * Pop a cursor from the stack, and restore the previous one to the @@ -90,8 +95,10 @@ public:  	 * @param hotspotY	the hotspot Y coordinate  	 * @param keycolor	the index for the transparent color  	 * @param targetScale	the scale for which the cursor is designed +	 * @param format	a pointer to the pixel format which the cursor graphic uses, +	 *					CLUT8 will be used if this is NULL or not specified.  	 */ -	void replaceCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor = 255, int targetScale = 1); +	void replaceCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor = 0xFFFFFFFF, int targetScale = 1, const Graphics::PixelFormat *format = NULL);  	/**  	 * Pop all of the cursors and cursor palettes from their respective stacks. @@ -166,13 +173,24 @@ private:  		uint _height;  		int _hotspotX;  		int _hotspotY; -		byte _keycolor; +		uint32 _keycolor; +		Graphics::PixelFormat _format;  		byte _targetScale;  		uint _size; - -		Cursor(const byte *data, uint w, uint h, int hotspotX, int hotspotY, byte keycolor = 255, int targetScale = 1) { +		Cursor(const byte *data, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor = 0xFFFFFFFF, int targetScale = 1, const Graphics::PixelFormat *format = NULL) { +#ifdef ENABLE_RGB_COLOR +			if (!format) +				_format = Graphics::PixelFormat::createFormatCLUT8(); +			 else  +				_format = *format; +			_size = w * h * _format.bytesPerPixel; +			_keycolor &= ((1 << (_format.bytesPerPixel << 3)) - 1); +#else +			_format = Graphics::PixelFormat::createFormatCLUT8();  			_size = w * h; +			_keycolor &= 0xFF; +#endif  			_data = new byte[_size];  			if (data && _data)  				memcpy(_data, data, _size); @@ -180,7 +198,6 @@ private:  			_height = h;  			_hotspotX = hotspotX;  			_hotspotY = hotspotY; -			_keycolor = keycolor;  			_targetScale = targetScale;  		} @@ -216,7 +233,6 @@ private:  			delete[] _data;  		}  	}; -  	Common::Stack<Cursor *> _cursorStack;  	Common::Stack<Palette *> _cursorPaletteStack;  }; diff --git a/graphics/pixelformat.h b/graphics/pixelformat.h index f59650e5cc..d16de51ea7 100644 --- a/graphics/pixelformat.h +++ b/graphics/pixelformat.h @@ -27,6 +27,7 @@  #define GRAPHICS_PIXELFORMAT_H  #include "common/scummsys.h" +#include "common/list.h"  namespace Graphics { @@ -50,6 +51,24 @@ struct PixelFormat {  	byte rLoss, gLoss, bLoss, aLoss; /**< Precision loss of each color component. */  	byte rShift, gShift, bShift, aShift; /**< Binary left shift of each color component in the pixel value. */ +	inline PixelFormat() { +		bytesPerPixel =  +		rLoss = gLoss = bLoss = aLoss =  +		rShift = gShift = bShift = aShift = 0; +	} + +	inline PixelFormat(byte BytesPerPixel,  +						byte RBits, byte GBits, byte BBits, byte ABits,  +						byte RShift, byte GShift, byte BShift, byte AShift) { +		bytesPerPixel = BytesPerPixel; +		rLoss = 8 - RBits, gLoss = 8 - GBits, bLoss = 8 - BBits, aLoss = 8 - ABits; +		rShift = RShift, gShift = GShift, bShift = BShift, aShift = AShift; +	} + +	static inline PixelFormat createFormatCLUT8() { +		return PixelFormat(1, 0, 0, 0, 0, 0, 0, 0, 0); +	} +  	inline bool operator==(const PixelFormat &fmt) const {  		// TODO: If aLoss==8, then the value of aShift is irrelevant, and should be ignored.  		return 0 == memcmp(this, &fmt, sizeof(PixelFormat)); @@ -129,6 +148,26 @@ struct PixelFormat {  	}  }; +/** + * Determines the first matching format between two lists. + * + * @param backend	The higher priority list, meant to be a list of formats supported by the backend + * @param frontend	The lower priority list, meant to be a list of formats supported by the engine + * @return			The first item on the backend list that also occurs on the frontend list + *					or PixelFormat::createFormatCLUT8() if no matching formats were found. + */ +inline PixelFormat findCompatibleFormat(Common::List<PixelFormat> backend, Common::List<PixelFormat> frontend) { +#ifdef ENABLE_RGB_COLOR +	for (Common::List<PixelFormat>::iterator i = backend.begin(); i != backend.end(); ++i) { +		for (Common::List<PixelFormat>::iterator j = frontend.begin(); j != frontend.end(); ++j) { +			if (*i == *j) +				return *i; +		} +	} +#endif +	return PixelFormat::createFormatCLUT8(); +} +  } // end of namespace Graphics  #endif diff --git a/graphics/scaler.cpp b/graphics/scaler.cpp index a3aaaa121d..8c677cc083 100644 --- a/graphics/scaler.cpp +++ b/graphics/scaler.cpp @@ -30,18 +30,17 @@  int gBitFormat = 565; -static const Graphics::PixelFormat gPixelFormat555 = { +static const Graphics::PixelFormat gPixelFormat555(  	2,  	3, 3, 3, 8,  	10, 5, 0, 0 -	}; +	); -static const Graphics::PixelFormat gPixelFormat565 = { +static const Graphics::PixelFormat gPixelFormat565(  	2,  	3, 2, 3, 8,  	11, 5, 0, 0 -	}; - +	);  #ifndef DISABLE_HQ_SCALERS  | 
