From ba035ac532a65457d55ec77b06273642d5191909 Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Sat, 16 Nov 2019 15:27:55 +0000 Subject: GRAPHICS: Add a function to vertically flip surfaces --- graphics/surface.cpp | 14 ++++++++++++++ graphics/surface.h | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/graphics/surface.cpp b/graphics/surface.cpp index 265249e72f..26d40b8922 100644 --- a/graphics/surface.cpp +++ b/graphics/surface.cpp @@ -354,6 +354,20 @@ void Surface::move(int dx, int dy, int height) { } } +void Surface::flipVertical(const Common::Rect &r) { + const int width = r.width() * format.bytesPerPixel; + byte *temp = new byte[width]; + for (int y = r.top; y < r.bottom / 2; y++) { + byte *row1 = (byte *)getBasePtr(r.left, y); + byte *row2 = (byte *)getBasePtr(r.left, r.bottom - y - 1); + + memcpy(temp, row1, width); + memcpy(row1, row2, width); + memcpy(row2, temp, width); + } + delete[] temp; +} + void Surface::convertToInPlace(const PixelFormat &dstFormat, const byte *palette) { // Do not convert to the same format and ignore empty surfaces. if (format == dstFormat || pixels == 0) { diff --git a/graphics/surface.h b/graphics/surface.h index 19107b8bab..8728106273 100644 --- a/graphics/surface.h +++ b/graphics/surface.h @@ -327,6 +327,13 @@ public: // See comment in graphics/surface.cpp about it void move(int dx, int dy, int height); + + /** + * Flip the specified rect vertically. + * + * @param r Rect to flip + */ + void flipVertical(const Common::Rect &r); }; /** -- cgit v1.2.3