diff options
Diffstat (limited to 'graphics/surface.cpp')
-rw-r--r-- | graphics/surface.cpp | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/graphics/surface.cpp b/graphics/surface.cpp index 137ef29a4e..73fff26dbd 100644 --- a/graphics/surface.cpp +++ b/graphics/surface.cpp @@ -24,6 +24,7 @@ #include "common/algorithm.h" #include "common/util.h" +#include "common/endian.h" #include "graphics/primitives.h" #include "graphics/surface.h" @@ -185,9 +186,6 @@ void Surface::frameRect(const Common::Rect &r, uint32 color) { // to support 16bpp (or marked as just working for 8bpp // surfaces). void Surface::move(int dx, int dy, int height) { - // This function currently just works with 8bpp surfaces - assert(bytesPerPixel == 1); - // Short circuit check - do we have to do anything anyway? if ((dx == 0 && dy == 0) || height <= 0) return; @@ -198,46 +196,58 @@ void Surface::move(int dx, int dy, int height) { // vertical movement if (dy > 0) { // move down - copy from bottom to top - dst = (byte *)pixels + (height - 1) * w; - src = dst - dy * w; + dst = (byte *)pixels + (height - 1) * pitch; + src = dst - dy * pitch; for (y = dy; y < height; y++) { - memcpy(dst, src, w); - src -= w; - dst -= w; + memcpy(dst, src, pitch); + src -= pitch; + dst -= pitch; } } else if (dy < 0) { // move up - copy from top to bottom dst = (byte *)pixels; - src = dst - dy * w; + src = dst - dy * pitch; for (y = -dy; y < height; y++) { - memcpy(dst, src, w); - src += w; - dst += w; + memcpy(dst, src, pitch); + src += pitch; + dst += pitch; } } // horizontal movement if (dx > 0) { // move right - copy from right to left - dst = (byte *)pixels + (w - 1); - src = dst - dx; + dst = (byte *)pixels + (pitch - bytesPerPixel); + src = dst - (dx * bytesPerPixel); for (y = 0; y < height; y++) { for (x = dx; x < w; x++) { - *dst-- = *src--; + if (bytesPerPixel == 1) { + *dst-- = *src--; + } else if (bytesPerPixel == 2) { + WRITE_LE_UINT16(dst, READ_LE_UINT16(src)); + src -= 2; + dst -= 2; + } } - src += w + (w - dx); - dst += w + (w - dx); + src += pitch + (pitch - dx * bytesPerPixel); + dst += pitch + (pitch - dx * bytesPerPixel); } } else if (dx < 0) { // move left - copy from left to right dst = (byte *)pixels; - src = dst - dx; + src = dst - (dx * bytesPerPixel); for (y = 0; y < height; y++) { for (x = -dx; x < w; x++) { - *dst++ = *src++; + if (bytesPerPixel == 1) { + *dst++ = *src++; + } else if (bytesPerPixel == 2) { + WRITE_LE_UINT16(dst, READ_LE_UINT16(src)); + src += 2; + dst += 2; + } } - src += w - (w + dx); - dst += w - (w + dx); + src += pitch - (pitch + dx * bytesPerPixel); + dst += pitch - (pitch + dx * bytesPerPixel); } } } |