From 6a1e5bd43a2a3b12b820a9b82c48761cb54a620a Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Thu, 6 Oct 2016 22:01:43 -0400 Subject: TITANIC: Cleanup usages of CTransparencySurface --- engines/titanic/support/mouse_cursor.cpp | 11 ++++++--- engines/titanic/support/transparency_surface.cpp | 12 +--------- engines/titanic/support/transparency_surface.h | 29 ++++++++++++++++++++---- engines/titanic/support/video_surface.cpp | 13 ++++------- 4 files changed, 39 insertions(+), 26 deletions(-) diff --git a/engines/titanic/support/mouse_cursor.cpp b/engines/titanic/support/mouse_cursor.cpp index 3983e9fe60..665ead3056 100644 --- a/engines/titanic/support/mouse_cursor.cpp +++ b/engines/titanic/support/mouse_cursor.cpp @@ -22,6 +22,7 @@ #include "graphics/cursorman.h" #include "titanic/support/mouse_cursor.h" +#include "titanic/support/transparency_surface.h" #include "titanic/support/video_surface.h" #include "titanic/titanic.h" @@ -107,12 +108,16 @@ void CMouseCursor::setCursor(CursorId cursorId) { Graphics::ManagedSurface surface(CURSOR_SIZE, CURSOR_SIZE, g_system->getScreenFormat()); const uint16 *srcP = srcSurface.getPixels(); - const byte *maskP = (const byte *)ce._transSurface->getPixels(); + CTransparencySurface transSurface(&ce._transSurface->rawSurface(), TRANS_DEFAULT); uint16 *destP = (uint16 *)surface.getPixels(); for (int y = 0; y < CURSOR_SIZE; ++y) { - for (int x = 0; x < CURSOR_SIZE; ++x, ++srcP, ++maskP, ++destP) { - *destP = ((*maskP >> 4) == 0) ? srcSurface.getTransparencyColor() : *srcP; + transSurface.setRow(y); + transSurface.setCol(0); + + for (int x = 0; x < CURSOR_SIZE; ++x, ++srcP, ++destP) { + *destP = transSurface.isPixelTransparent() ? srcSurface.getTransparencyColor() : *srcP; + transSurface.moveX(); } } diff --git a/engines/titanic/support/transparency_surface.cpp b/engines/titanic/support/transparency_surface.cpp index f917dfb48b..5ffa8b99b1 100644 --- a/engines/titanic/support/transparency_surface.cpp +++ b/engines/titanic/support/transparency_surface.cpp @@ -67,17 +67,7 @@ int CTransparencySurface::moveX() { uint CTransparencySurface::getPixel() const { const byte *pixelP = (const byte *)_surface->getBasePtr(_pos.x, _pos.y); - return _flag1 ? 0xFF - *pixelP : *pixelP; -} - -bool CTransparencySurface::isPixelTransparent1() const { - const byte *pixelP = (const byte *)_surface->getBasePtr(_pos.x, _pos.y); - return _flag1 ? *pixelP == 0xF0 : *pixelP == 0x10; -} - -bool CTransparencySurface::isPixelTransparent2() const { - const byte *pixelP = (const byte *)_surface->getBasePtr(_pos.x, _pos.y); - return _flag2 ? *pixelP == 0xF0 : *pixelP == 0x10; + return *pixelP; } } // End of namespace Titanic diff --git a/engines/titanic/support/transparency_surface.h b/engines/titanic/support/transparency_surface.h index 5593dfa66d..06861b609b 100644 --- a/engines/titanic/support/transparency_surface.h +++ b/engines/titanic/support/transparency_surface.h @@ -43,19 +43,40 @@ private: bool _flag1; bool _flag2; public: + /** + * Constructor + */ CTransparencySurface(const Graphics::Surface *surface, TransparencyMode transMode); + /** + * Sets the row to get transparencies from + */ void setRow(int yp) { _pos.y = yp; } + /** + * Sets the column to get transparencies from + */ void setCol(int xp) { _pos.x = xp; } - uint getPixel() const; + /** + * Moves reading position horizontally by a single pixel + */ + int moveX(); - bool isPixelTransparent1() const; + /** + * Returns a byte from the transparency surface + */ + uint getPixel() const; - bool isPixelTransparent2() const; + /** + * Returns the alpha value for the pixel (0-31) + */ + uint getAlpha() const { return getPixel() >> 3; } - int moveX(); + /** + * Returns true if the pixel is completely transparent + */ + bool isPixelTransparent() const { return getAlpha() == 0; } }; } // End of namespace Titanic diff --git a/engines/titanic/support/video_surface.cpp b/engines/titanic/support/video_surface.cpp index 1991d7423f..79d1f075c2 100644 --- a/engines/titanic/support/video_surface.cpp +++ b/engines/titanic/support/video_surface.cpp @@ -52,8 +52,7 @@ CVideoSurface::~CVideoSurface() { void CVideoSurface::setupPalette(byte palette[32][32], byte val) { for (uint idx1 = 0; idx1 < 32; ++idx1) { for (uint idx2 = 0, base = 0; idx2 < 32; ++idx2, base += idx1) { - int64 v = 0x84210843; - v *= base; + uint v = base / 31; uint v2 = (v >> 36); v = ((v2 >> 31) + v2) & 0xff; palette[idx1][idx2] = v << 3; @@ -252,15 +251,13 @@ void CVideoSurface::transBlitRect(const Rect &srcRect, const Rect &destRect, CVi transSurface.setCol(srcRect.left); for (int srcX = srcRect.left; srcX < srcRect.right; ++srcX) { - transSurface.moveX(); - - if (!transSurface.isPixelTransparent2()) { - copyPixel(lineDestP, lineSrcP, transSurface.getPixel() >> 3, - is16Bit, isAlpha); + if (!transSurface.isPixelTransparent()) { + copyPixel(lineDestP, lineSrcP, transSurface.getAlpha(), is16Bit, isAlpha); } ++lineSrcP; ++lineDestP; + transSurface.moveX(); } // Move to next line @@ -517,7 +514,7 @@ uint16 OSVideoSurface::getPixel(const Common::Point &pt) { transSurface.setRow(_flipVertically ? getHeight() - pt.y - 1 : pt.y); transSurface.setCol(pt.x); - if (transSurface.isPixelTransparent2()) + if (transSurface.isPixelTransparent()) return getTransparencyColor(); } -- cgit v1.2.3