From 9db17152c1ca47a851aed685c0515f3aebb6c390 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 1 Aug 2013 23:53:18 +0200 Subject: GRAPHICS: Make Surface::copyFrom work for any src pitch. Formerly we assumed that the newly created surface has the same pitch as the source surface. This is a assumption that might be invalid (for example in case of the Surface returned by OSystem::lockScreen.) --- graphics/surface.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/graphics/surface.cpp b/graphics/surface.cpp index 41ae8dcebb..010389c9fa 100644 --- a/graphics/surface.cpp +++ b/graphics/surface.cpp @@ -84,7 +84,17 @@ void Surface::free() { void Surface::copyFrom(const Surface &surf) { create(surf.w, surf.h, surf.format); - memcpy(pixels, surf.pixels, h * pitch); + if (surf.pitch == pitch) { + memcpy(pixels, surf.pixels, h * pitch); + } else { + const byte *src = (const byte *)surf.pixels; + byte *dst = (byte *)pixels; + for (int y = h; y > 0; --y) { + memcpy(dst, src, w * format.bytesPerPixel); + src += surf.pitch; + dst += pitch; + } + } } void Surface::hLine(int x, int y, int x2, uint32 color) { -- cgit v1.2.3