aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schickel2013-08-01 23:53:18 +0200
committerJohannes Schickel2013-08-01 23:57:10 +0200
commit9db17152c1ca47a851aed685c0515f3aebb6c390 (patch)
treeebf2f75a034add19dc1bf7de2a12eeb8d9d8533d
parent9fb15a909c964c607110d29b15074c4a0269baae (diff)
downloadscummvm-rg350-9db17152c1ca47a851aed685c0515f3aebb6c390.tar.gz
scummvm-rg350-9db17152c1ca47a851aed685c0515f3aebb6c390.tar.bz2
scummvm-rg350-9db17152c1ca47a851aed685c0515f3aebb6c390.zip
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.)
-rw-r--r--graphics/surface.cpp12
1 files changed, 11 insertions, 1 deletions
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) {