From 07498687bdae9c05b9ef59470522078c0187c533 Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Sun, 5 Jun 2022 15:28:28 +0100 Subject: [PATCH] GRAPHICS: Add Surface::copyRectToSurfaceWithKey() --- graphics/managed_surface.h | 18 ++++++++++++++++++ graphics/surface.cpp | 20 ++++++++++++++++++++ graphics/surface.h | 28 ++++++++++++++++++++++++++++ gui/about.cpp | 3 +-- 4 files changed, 67 insertions(+), 2 deletions(-) diff --git a/graphics/managed_surface.h b/graphics/managed_surface.h index 3b8d169ec28..0d5b60891d6 100644 --- a/graphics/managed_surface.h +++ b/graphics/managed_surface.h @@ -533,6 +533,24 @@ public: _innerSurface.copyRectToSurface(srcSurface, destX, destY, subRect); } + /** + * Copy a bitmap to the internal buffer of the surface. + * + * The pixel format of the buffer must match the pixel format of the surface. + */ + void copyRectToSurfaceWithKey(const void *buffer, int srcPitch, int destX, int destY, int width, int height, uint32 key) { + _innerSurface.copyRectToSurfaceWithKey(buffer, srcPitch, destX, destY, width, height, key); + } + + /** + * Copy a bitmap to the internal buffer of the surface. + * + * The pixel format of the buffer must match the pixel format of the surface. + */ + void copyRectToSurfaceWithKey(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect subRect, uint32 key) { + _innerSurface.copyRectToSurfaceWithKey(srcSurface, destX, destY, subRect, key); + } + /** * Copy the data from another surface, reinitializing the * surface to match the dimensions of the passed surface. diff --git a/graphics/surface.cpp b/graphics/surface.cpp index 102f84a73a6..66bc3f17f86 100644 --- a/graphics/surface.cpp +++ b/graphics/surface.cpp @@ -188,6 +188,26 @@ void Surface::copyRectToSurface(const Graphics::Surface &srcSurface, int destX, copyRectToSurface(srcSurface.getBasePtr(subRect.left, subRect.top), srcSurface.pitch, destX, destY, subRect.width(), subRect.height()); } +void Surface::copyRectToSurfaceWithKey(const void *buffer, int srcPitch, int destX, int destY, int width, int height, uint32 key) { + assert(buffer); + + assert(destX >= 0 && destX < w); + assert(destY >= 0 && destY < h); + assert(height > 0 && destY + height <= h); + assert(width > 0 && destX + width <= w); + + // Copy buffer data to internal buffer + const byte *src = (const byte *)buffer; + byte *dst = (byte *)getBasePtr(destX, destY); + Graphics::keyBlit(dst, src, pitch, srcPitch, width, height, format.bytesPerPixel, key); +} + +void Surface::copyRectToSurfaceWithKey(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect subRect, uint32 key) { + assert(srcSurface.format == format); + + copyRectToSurfaceWithKey(srcSurface.getBasePtr(subRect.left, subRect.top), srcSurface.pitch, destX, destY, subRect.width(), subRect.height(), key); +} + void Surface::hLine(int x, int y, int x2, uint32 color) { // Clipping if (y < 0 || y >= h) diff --git a/graphics/surface.h b/graphics/surface.h index cccb766f7be..5d2e2a9480b 100644 --- a/graphics/surface.h +++ b/graphics/surface.h @@ -289,6 +289,34 @@ public: */ void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect subRect); + /** + * Copy a bitmap to the internal buffer of the surface. + * + * The pixel format of the buffer must match the pixel format of the surface. + * + * @param buffer Buffer containing the graphics data source. + * @param srcPitch Pitch of the buffer (number of bytes in a scanline). + * @param destX The x coordinate of the destination rectangle. + * @param destY The y coordinate of the destination rectangle. + * @param width Width of the destination rectangle. + * @param height Height of the destination rectangle. + * @param key + */ + void copyRectToSurfaceWithKey(const void *buffer, int srcPitch, int destX, int destY, int width, int height, uint32 key); + + /** + * Copy a bitmap to the internal buffer of the surface. + * + * The pixel format of the buffer must match the pixel format of the surface. + * + * @param srcSurface Source of the bitmap data. + * @param destX The x coordinate of the destination rectangle. + * @param destY The y coordinate of the destination rectangle. + * @param subRect The subRect of the surface to be blitted. + * @param key + */ + void copyRectToSurfaceWithKey(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect subRect, uint32 key); + /** * Convert the data to another pixel format. * diff --git a/gui/about.cpp b/gui/about.cpp index b47b912b6c6..94ec8d52c37 100644 --- a/gui/about.cpp +++ b/gui/about.cpp @@ -26,7 +26,6 @@ #include "common/system.h" #include "common/translation.h" #include "common/util.h" -#include "graphics/conversion.h" #include "graphics/surface.h" #include "graphics/fonts/amigafont.h" #include "gui/about.h" @@ -1099,7 +1098,7 @@ void EE::draw(int sn, int x1, int y1) { int x = x1 * _scale; int y = y1 * _scale; - Graphics::keyBlit((byte *)_back.getBasePtr(x, y), (const byte *)_sp[sn].getPixels(), _back.pitch, _sp[sn].pitch, _sp[sn].w, _sp[sn].h, _back.format.bytesPerPixel, _colorKey); + _back.copyRectToSurfaceWithKey(_sp[sn].getPixels(), _sp[sn].pitch, x, y, _sp[sn].w, _sp[sn].h, _colorKey); g_system->copyRectToOverlay(_back.getBasePtr(x, y), _back.pitch, _windowX + x, _windowY + y, _sp[sn].w, _sp[sn].h); }