18
18
* along with this program; if not, write to the Free Software
19
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
* $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/tags/release-1-2-1/graphics/surface.cpp $
22
* $Id: surface.cpp 52268 2010-08-21 20:14:46Z sev $
25
25
#include "common/algorithm.h"
26
26
#include "common/util.h"
27
#include "common/rect.h"
28
#include "common/textconsole.h"
27
29
#include "graphics/primitives.h"
28
30
#include "graphics/surface.h"
179
181
vLine(r.right-1, r.top, r.bottom-1, color);
182
// FIXME: LordHoto asks why is this in Surface, since this
183
// just supports 8bpp surfaces. Looks like someone wants
184
// to subclass Surface to add this or it should be extended
185
// to support 16bpp (or marked as just working for 8bpp
187
184
void Surface::move(int dx, int dy, int height) {
188
// This function currently just works with 8bpp surfaces
189
assert(bytesPerPixel == 1);
191
185
// Short circuit check - do we have to do anything anyway?
192
186
if ((dx == 0 && dy == 0) || height <= 0)
189
if (bytesPerPixel != 1 && bytesPerPixel != 2)
190
error("Surface::move: bytesPerPixel must be 1 or 2");
198
195
// vertical movement
200
197
// move down - copy from bottom to top
201
dst = (byte *)pixels + (height - 1) * w;
198
dst = (byte *)pixels + (height - 1) * pitch;
199
src = dst - dy * pitch;
203
200
for (y = dy; y < height; y++) {
201
memcpy(dst, src, pitch);
208
205
} else if (dy < 0) {
209
206
// move up - copy from top to bottom
210
207
dst = (byte *)pixels;
208
src = dst - dy * pitch;
212
209
for (y = -dy; y < height; y++) {
210
memcpy(dst, src, pitch);
219
216
// horizontal movement
221
218
// move right - copy from right to left
222
dst = (byte *)pixels + (w - 1);
219
dst = (byte *)pixels + (pitch - bytesPerPixel);
220
src = dst - (dx * bytesPerPixel);
224
221
for (y = 0; y < height; y++) {
225
222
for (x = dx; x < w; x++) {
223
if (bytesPerPixel == 1) {
225
} else if (bytesPerPixel == 2) {
226
*(uint16 *)dst = *(const uint16 *)src;
231
src += pitch + (pitch - dx * bytesPerPixel);
232
dst += pitch + (pitch - dx * bytesPerPixel);
231
234
} else if (dx < 0) {
232
235
// move left - copy from left to right
233
236
dst = (byte *)pixels;
237
src = dst - (dx * bytesPerPixel);
235
238
for (y = 0; y < height; y++) {
236
239
for (x = -dx; x < w; x++) {
240
if (bytesPerPixel == 1) {
242
} else if (bytesPerPixel == 2) {
243
*(uint16 *)dst = *(const uint16 *)src;
248
src += pitch - (pitch + dx * bytesPerPixel);
249
dst += pitch - (pitch + dx * bytesPerPixel);