Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GRAPHICS: Add Surface::copyRectToSurfaceWithKey() #3956

Merged
merged 2 commits into from
Jun 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions graphics/managed_surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,24 @@ class ManagedSurface {
_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.
Expand Down
20 changes: 20 additions & 0 deletions graphics/surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions graphics/surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,33 @@ struct Surface {
*/
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);
/**
bluegr marked this conversation as resolved.
Show resolved Hide resolved
* 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.
*
Expand Down
3 changes: 1 addition & 2 deletions gui/about.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
}

Expand Down