diff options
Diffstat (limited to 'engines/titanic/support')
-rw-r--r-- | engines/titanic/support/font.cpp | 5 | ||||
-rw-r--r-- | engines/titanic/support/video_surface.cpp | 83 | ||||
-rw-r--r-- | engines/titanic/support/video_surface.h | 14 |
3 files changed, 73 insertions, 29 deletions
diff --git a/engines/titanic/support/font.cpp b/engines/titanic/support/font.cpp index e519237c3b..39a0b777a1 100644 --- a/engines/titanic/support/font.cpp +++ b/engines/titanic/support/font.cpp @@ -292,12 +292,13 @@ void STFont::copyRect(CVideoSurface *surface, const Point &pt, Rect &rect) { if (surface->lock()) { uint16 *lineP = surface->getBasePtr(pt.x, pt.y); uint16 color = getColor(); + bool is16Bit = surface->getPixelDepth() == 2; for (int yp = rect.top; yp < rect.bottom; ++yp, lineP += surface->getWidth()) { uint16 *destP = lineP; for (int xp = rect.left; xp < rect.right; ++xp, ++destP) { - const byte *srcP = _dataPtr + yp * _dataWidth + xp; - surface->changePixel(destP, &color, *srcP >> 3, true); + const byte *transP = _dataPtr + yp * _dataWidth + xp; + surface->copyPixel(destP, &color, *transP >> 3, is16Bit, true); } } diff --git a/engines/titanic/support/video_surface.cpp b/engines/titanic/support/video_surface.cpp index 166a954dc1..20b1bb4fbe 100644 --- a/engines/titanic/support/video_surface.cpp +++ b/engines/titanic/support/video_surface.cpp @@ -140,9 +140,9 @@ void CVideoSurface::blitRect1(const Rect &srcRect, const Rect &destRect, CVideoS if (src->_fastBlitFlag) { _rawSurface->blitFrom(*src->_rawSurface, srcRect, Point(destRect.left, destRect.top)); } else if (getTransparencySurface()) { - transBlitRect(srcRect, destRect, src); + transBlitRect(srcRect, destRect, src, false); } else { - _rawSurface->transBlitFrom(*src->_rawSurface, srcRect, destRect, src->getTransparencyColor()); + _rawSurface->transBlitFrom(*src->_rawSurface, srcRect, destRect, src->getTransparencyColor(), 1); } src->unlock(); @@ -151,7 +151,7 @@ void CVideoSurface::blitRect1(const Rect &srcRect, const Rect &destRect, CVideoS void CVideoSurface::blitRect2(const Rect &srcRect, const Rect &destRect, CVideoSurface *src) { if (getTransparencySurface()) { - transBlitRect(srcRect, destRect, src); + transBlitRect(srcRect, destRect, src, true); } else { src->lock(); lock(); @@ -163,14 +163,52 @@ void CVideoSurface::blitRect2(const Rect &srcRect, const Rect &destRect, CVideoS } } -void CVideoSurface::transBlitRect(const Rect &srcRect, const Rect &destRect, CVideoSurface *src) { +void CVideoSurface::transBlitRect(const Rect &srcRect, const Rect &destRect, CVideoSurface *src, bool flag) { if (lock()) { if (src->lock()) { Graphics::ManagedSurface *srcSurface = src->_rawSurface; Graphics::ManagedSurface *destSurface = _rawSurface; - - // TODO: Handle the transparency mode correctly - destSurface->blitFrom(*srcSurface, srcRect, Point(srcRect.left, srcRect.top)); + Graphics::Surface destArea = destSurface->getSubArea(destRect); + + const uint16 *srcPtr = flag ? + (const uint16 *)srcSurface->getBasePtr(srcRect.left, srcRect.top) : + (const uint16 *)srcSurface->getBasePtr(srcRect.left, srcRect.bottom); + uint16 *destPtr = (uint16 *)destSurface->getBasePtr(destArea.w, destArea.h - 1); + bool is16Bit = src->getPixelDepth() == 2; + bool isAlpha = src->_transparencyMode == TRANS_ALPHA0 || + src->_transparencyMode == TRANS_ALPHA255; + + CRawSurface rawSurface(src->getTransparencySurface(), src->_transparencyMode); + if (flag) + rawSurface.setRow(srcRect.top); + else + rawSurface.setRow(src->getHeight() - srcRect.bottom); + + for (int srcY = srcRect.top; srcY < srcRect.bottom; ++srcY) { + // Prepare for copying the line + const uint16 *lineSrcP = srcPtr; + uint16 *lineDestP = destPtr; + rawSurface.resetPitch(); + rawSurface.setCol(srcRect.left); + + for (int srcX = 0; srcX < srcRect.width(); ++srcX) { + int move = rawSurface.moveX(0); + + if (move <= 1) { + if (!rawSurface.isPixelTransparent2()) { + copyPixel(lineDestP, lineSrcP, rawSurface.getPixel() >> 3, + is16Bit, isAlpha); + } + } else { + // TODO + } + } + + // Move to next line + rawSurface.skipPitch(); + srcPtr = flag ? srcPtr + getWidth() : srcPtr - getWidth(); + destPtr -= destArea.w; + } src->unlock(); } @@ -435,27 +473,30 @@ void OSVideoSurface::setPixel(const Point &pt, uint pixel) { *pixelP = pixel; } -void OSVideoSurface::changePixel(uint16 *pixelP, uint16 *color, byte srcVal, bool remapFlag) { - assert(getPixelDepth() == 2); - const Graphics::PixelFormat &destFormat = _ddSurface->getFormat(); - const Graphics::PixelFormat srcFormat(2, 5, 5, 5, 0, 10, 5, 0, 0); +void OSVideoSurface::copyPixel(uint16 *destP, const uint16 *srcP, byte transVal, bool is16Bit, bool isAlpha) { + const Graphics::PixelFormat srcFormat = is16Bit ? + Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0) : + Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0); + const Graphics::PixelFormat destFormat = _ddSurface->getFormat(); + transVal &= 0xff; + assert(transVal < 32); // Get the color byte r, g, b; - srcFormat.colorToRGB(*color, r, g, b); - if (remapFlag) { - r = _palette1[31 - srcVal][r >> 3]; - g = _palette1[31 - srcVal][g >> 3]; - b = _palette1[31 - srcVal][b >> 3]; + srcFormat.colorToRGB(*srcP, r, g, b); + if (isAlpha) { + r = _palette1[31 - transVal][r >> 3]; + g = _palette1[31 - transVal][g >> 3]; + b = _palette1[31 - transVal][b >> 3]; } byte r2, g2, b2; - destFormat.colorToRGB(*pixelP, r2, g2, b2); - r2 = _palette1[srcVal][r2 >> 3]; - g2 = _palette1[srcVal][g2 >> 3]; - b2 = _palette1[srcVal][b2 >> 3]; + destFormat.colorToRGB(*destP, r2, g2, b2); + r2 = _palette1[transVal][r2 >> 3]; + g2 = _palette1[transVal][g2 >> 3]; + b2 = _palette1[transVal][b2 >> 3]; - *pixelP = destFormat.RGBToColor(r + r2, g + g2, b + b2); + *destP = destFormat.RGBToColor(r + r2, g + g2, b + b2); } void OSVideoSurface::shiftColors() { diff --git a/engines/titanic/support/video_surface.h b/engines/titanic/support/video_surface.h index ad868d87ba..cd87f61292 100644 --- a/engines/titanic/support/video_surface.h +++ b/engines/titanic/support/video_surface.h @@ -53,7 +53,7 @@ private: void blitRect1(const Rect &srcRect, const Rect &destRect, CVideoSurface *src); void blitRect2(const Rect &srcRect, const Rect &destRect, CVideoSurface *src); - void transBlitRect(const Rect &srcRect, const Rect &destRect, CVideoSurface *src); + void transBlitRect(const Rect &srcRect, const Rect &destRect, CVideoSurface *src, bool flag); protected: static int _videoSurfaceCounter; protected: @@ -182,9 +182,9 @@ public: virtual void setPixel(const Point &pt, uint pixel) = 0; /** - * Change a pixel + * Copies a pixel, handling transparency */ - virtual void changePixel(uint16 *pixelP, uint16 *color, byte srcVal, bool remapFlag = true) = 0; + virtual void copyPixel(uint16 *destP, const uint16 *srcP, byte transVal, bool is16Bit, bool isAlpha) = 0; /** * Shifts the colors of the surface.. maybe greys it out? @@ -298,7 +298,9 @@ public: /** * Get the previously set transparency mask surface */ - Graphics::ManagedSurface *getTransparencySurface() const { return _transparencySurface; } + const Graphics::Surface *getTransparencySurface() const { + return _transparencySurface ? &_transparencySurface->rawSurface() : nullptr; + } /** * Get the pixels associated with the surface. Only valid when the @@ -433,9 +435,9 @@ public: virtual void setPixel(const Point &pt, uint pixel); /** - * Change a pixel + * Copies a pixel, handling transparency */ - virtual void changePixel(uint16 *pixelP, uint16 *color, byte srcVal, bool remapFlag = true); + virtual void copyPixel(uint16 *destP, const uint16 *srcP, byte transVal, bool is16Bit, bool isAlpha); /** * Shifts the colors of the surface.. maybe greys it out? |