Use memmove when source and destination sprite areas overlap in drawSprite()

svn-id: r32305
This commit is contained in:
Sven Hesse 2008-05-26 21:07:49 +00:00
parent c13fda76d6
commit 9eed36cc4f

View File

@ -109,10 +109,16 @@ void VGAVideoDriver::drawSprite(SurfaceDesc *source, SurfaceDesc *dest,
int16 width = MIN((right - left) + 1, (int) dest->getWidth());
int16 height = MIN((bottom - top) + 1, (int) dest->getHeight());
if ((width < 1) || (height < 1))
return;
byte *srcPos = source->getVidMem() + (top * source->getWidth()) + left;
byte *destPos = dest->getVidMem() + (y * dest->getWidth()) + x;
uint32 size = width * height;
if (transp) {
while (height--) {
for (int16 i = 0; i < width; ++i) {
if (srcPos[i])
@ -122,13 +128,26 @@ void VGAVideoDriver::drawSprite(SurfaceDesc *source, SurfaceDesc *dest,
srcPos += source->getWidth();
destPos += dest->getWidth();
}
} else if (((srcPos >= destPos) && (srcPos <= (destPos + size))) ||
((destPos >= srcPos) && (destPos <= (srcPos + size)))) {
while (height--) {
memmove(destPos, srcPos, width);
srcPos += source->getWidth();
destPos += dest->getWidth();
}
} else {
while (height--) {
memcpy(destPos, srcPos, width);
srcPos += source->getWidth();
destPos += dest->getWidth();
}
}
}