From 7e8e9bf3d1e718758298b8fb5ccc6a0f296d5b9c Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 14 Aug 2013 19:42:56 -0500 Subject: GRAPHICS: Create copyRectToSurface member function --- graphics/surface.cpp | 18 ++++++++++++++++++ graphics/surface.h | 13 +++++++++++++ 2 files changed, 31 insertions(+) (limited to 'graphics') diff --git a/graphics/surface.cpp b/graphics/surface.cpp index 929157203e..d808121c87 100644 --- a/graphics/surface.cpp +++ b/graphics/surface.cpp @@ -133,6 +133,24 @@ const Surface Surface::getSubArea(const Common::Rect &area) const { return subSurface; } +void Surface::copyRectToSurface(const void *buffer, int pitch, int x, int y, int width, int height) { + assert(buffer); + + assert(x >= 0 && x < w); + assert(y >= 0 && y < h); + assert(height > 0 && y + height <= h); + assert(width > 0 && x + width <= w); + + // Copy buffer data to internal buffer + const byte *src = (const byte *)buffer; + byte *dst = (byte *)getBasePtr(x, y); + for (int i = 0; i < height; i++) { + memcpy(dst, src, width * format.bytesPerPixel); + src += pitch; + dst += this->pitch; + } +} + 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 b08d4a5cb7..ad52ed8238 100644 --- a/graphics/surface.h +++ b/graphics/surface.h @@ -208,6 +208,19 @@ public: */ const Surface getSubArea(const Common::Rect &area) const; + /** + * Copies a bitmap to the Surface internal buffer. The pixel format + * of buffer must match the pixel format of the Surface. + * + * @param buffer The buffer containing the graphics data source + * @param pitch The pitch of the buffer (number of bytes in a scanline) + * @param x The x coordinate of the destination rectangle + * @param y The y coordinate of the destination rectangle + * @param width The width of the destination rectangle + * @param height The height of the destination rectangle + */ + void copyRectToSurface(const void *buffer, int pitch, int x, int y, int width, int height); + /** * Convert the data to another pixel format. * -- cgit v1.2.3 From 6f4e80e36e7729bd2137a1a2bde712521861b0b3 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Thu, 12 Sep 2013 09:30:28 -0500 Subject: ZVISION: Add wrapper function for copyRectToSurface Also rename some arguments to make them more clear --- graphics/surface.cpp | 18 ++++++++++++------ graphics/surface.h | 17 ++++++++++++++--- 2 files changed, 26 insertions(+), 9 deletions(-) (limited to 'graphics') diff --git a/graphics/surface.cpp b/graphics/surface.cpp index d808121c87..a8173f0e9c 100644 --- a/graphics/surface.cpp +++ b/graphics/surface.cpp @@ -133,17 +133,17 @@ const Surface Surface::getSubArea(const Common::Rect &area) const { return subSurface; } -void Surface::copyRectToSurface(const void *buffer, int pitch, int x, int y, int width, int height) { +void Surface::copyRectToSurface(const void *buffer, int pitch, int destX, int destY, int width, int height) { assert(buffer); - assert(x >= 0 && x < w); - assert(y >= 0 && y < h); - assert(height > 0 && y + height <= h); - assert(width > 0 && x + width <= w); + 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(x, y); + byte *dst = (byte *)getBasePtr(destX, destY); for (int i = 0; i < height; i++) { memcpy(dst, src, width * format.bytesPerPixel); src += pitch; @@ -151,6 +151,12 @@ void Surface::copyRectToSurface(const void *buffer, int pitch, int x, int y, int } } +void Surface::copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect subRect) { + assert(srcSurface.format == format); + + copyRectToSurface(srcSurface.getBasePtr(subRect.left, subRect.top), srcSurface.pitch, destX, destY, subRect.width(), subRect.height()); +} + 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 ad52ed8238..1492e71e68 100644 --- a/graphics/surface.h +++ b/graphics/surface.h @@ -214,12 +214,23 @@ public: * * @param buffer The buffer containing the graphics data source * @param pitch The pitch of the buffer (number of bytes in a scanline) - * @param x The x coordinate of the destination rectangle - * @param y The y coordinate of the destination rectangle + * @param destX The x coordinate of the destination rectangle + * @param destY The y coordinate of the destination rectangle * @param width The width of the destination rectangle * @param height The height of the destination rectangle */ - void copyRectToSurface(const void *buffer, int pitch, int x, int y, int width, int height); + void copyRectToSurface(const void *buffer, int pitch, int destX, int destY, int width, int height); + /** + * Copies a bitmap to the Surface internal buffer. The pixel format + * of buffer must match the pixel format of the Surface. + * + * @param srcSurface The 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 surface to be blitted + * @return + */ + void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect subRect); /** * Convert the data to another pixel format. -- cgit v1.2.3 From 701250efb57ef94e35d2b7b6f0d6d045b713e6f5 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 22 Sep 2013 15:53:15 -0500 Subject: GRAPHICS: Remove variable shadowing --- graphics/surface.cpp | 6 +++--- graphics/surface.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'graphics') diff --git a/graphics/surface.cpp b/graphics/surface.cpp index a8173f0e9c..777c1058fb 100644 --- a/graphics/surface.cpp +++ b/graphics/surface.cpp @@ -133,7 +133,7 @@ const Surface Surface::getSubArea(const Common::Rect &area) const { return subSurface; } -void Surface::copyRectToSurface(const void *buffer, int pitch, int destX, int destY, int width, int height) { +void Surface::copyRectToSurface(const void *buffer, int srcPitch, int destX, int destY, int width, int height) { assert(buffer); assert(destX >= 0 && destX < w); @@ -146,8 +146,8 @@ void Surface::copyRectToSurface(const void *buffer, int pitch, int destX, int de byte *dst = (byte *)getBasePtr(destX, destY); for (int i = 0; i < height; i++) { memcpy(dst, src, width * format.bytesPerPixel); - src += pitch; - dst += this->pitch; + src += srcPitch; + dst += pitch; } } diff --git a/graphics/surface.h b/graphics/surface.h index 1492e71e68..07e289b0bb 100644 --- a/graphics/surface.h +++ b/graphics/surface.h @@ -219,7 +219,7 @@ public: * @param width The width of the destination rectangle * @param height The height of the destination rectangle */ - void copyRectToSurface(const void *buffer, int pitch, int destX, int destY, int width, int height); + void copyRectToSurface(const void *buffer, int srcPitch, int destX, int destY, int width, int height); /** * Copies a bitmap to the Surface internal buffer. The pixel format * of buffer must match the pixel format of the Surface. -- cgit v1.2.3