aboutsummaryrefslogtreecommitdiff
path: root/graphics/surface.cpp
diff options
context:
space:
mode:
authorYotam Barnoy2010-10-31 11:08:43 +0000
committerYotam Barnoy2010-10-31 11:08:43 +0000
commit94c8d0a14df429a1b25bd9f5c5d75497fd0ddbd1 (patch)
tree3df2a4ae7967c56d464729669fc06ce4e93dff36 /graphics/surface.cpp
parent8df4278ba8cfbf71228e1927f9db635a9a30a57f (diff)
parentdca3c8d8bfc6c4db38cf8e8291818dd472041d4e (diff)
downloadscummvm-rg350-94c8d0a14df429a1b25bd9f5c5d75497fd0ddbd1.tar.gz
scummvm-rg350-94c8d0a14df429a1b25bd9f5c5d75497fd0ddbd1.tar.bz2
scummvm-rg350-94c8d0a14df429a1b25bd9f5c5d75497fd0ddbd1.zip
Updated with latest from trunk
svn-id: r53976
Diffstat (limited to 'graphics/surface.cpp')
-rw-r--r--graphics/surface.cpp60
1 files changed, 34 insertions, 26 deletions
diff --git a/graphics/surface.cpp b/graphics/surface.cpp
index 137ef29a4e..f06c24c2cd 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"
@@ -179,65 +180,72 @@ void Surface::frameRect(const Common::Rect &r, uint32 color) {
vLine(r.right-1, r.top, r.bottom-1, color);
}
-// FIXME: LordHoto asks why is this in Surface, since this
-// just supports 8bpp surfaces. Looks like someone wants
-// to subclass Surface to add this or it should be extended
-// 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;
+ if (bytesPerPixel != 1 && bytesPerPixel != 2)
+ error("Surface::move: bytesPerPixel must be 1 or 2");
+
byte *src, *dst;
int x, y;
// 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) {
+ *(uint16 *)dst = *(const 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) {
+ *(uint16 *)dst = *(const uint16 *)src;
+ src += 2;
+ dst += 2;
+ }
}
- src += w - (w + dx);
- dst += w - (w + dx);
+ src += pitch - (pitch + dx * bytesPerPixel);
+ dst += pitch - (pitch + dx * bytesPerPixel);
}
}
}