diff options
| author | Cameron Cawley | 2019-11-16 15:27:55 +0000 | 
|---|---|---|
| committer | Filippos Karapetis | 2020-01-02 20:53:29 +0200 | 
| commit | ba035ac532a65457d55ec77b06273642d5191909 (patch) | |
| tree | 95740d8d8571685ddfdd183643bb4a645ea1ca70 | |
| parent | 7b3d50957d441189c90f2471d9ebc625226dda53 (diff) | |
| download | scummvm-rg350-ba035ac532a65457d55ec77b06273642d5191909.tar.gz scummvm-rg350-ba035ac532a65457d55ec77b06273642d5191909.tar.bz2 scummvm-rg350-ba035ac532a65457d55ec77b06273642d5191909.zip | |
GRAPHICS: Add a function to vertically flip surfaces
| -rw-r--r-- | graphics/surface.cpp | 14 | ||||
| -rw-r--r-- | graphics/surface.h | 7 | 
2 files changed, 21 insertions, 0 deletions
| 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);  };  /** | 
