diff options
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/cursorman.cpp | 56 | ||||
-rw-r--r-- | graphics/cursorman.h | 45 | ||||
-rw-r--r-- | graphics/pixelformat.h | 52 |
3 files changed, 43 insertions, 110 deletions
diff --git a/graphics/cursorman.cpp b/graphics/cursorman.cpp index 00932e55b0..850b0044dc 100644 --- a/graphics/cursorman.cpp +++ b/graphics/cursorman.cpp @@ -57,33 +57,18 @@ 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) { #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 @@ void CursorManager::popCursor() { 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 @@ void CursorManager::popAllCursors() { 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 @@ void CursorManager::replaceCursorReal(const byte *buf, uint w, uint h, int hotsp 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) { diff --git a/graphics/cursorman.h b/graphics/cursorman.h index 481567bb09..0c02292818 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" +#ifdef ENABLE_16BIT +#include "graphics/pixelformat.h" +#include "common/system.h" +#endif namespace Graphics { @@ -56,10 +60,11 @@ public: * 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 @@ public: * @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 @@ private: 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; diff --git a/graphics/pixelformat.h b/graphics/pixelformat.h index 2e8c065414..d37a7794f4 100644 --- a/graphics/pixelformat.h +++ b/graphics/pixelformat.h @@ -43,50 +43,16 @@ namespace Graphics { * 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 |