SDL: Use the SDL_Surface's pitch in copyRectToScreen.

This fixes messed up graphics, when SDL decides to add padding bytes to the
lines of an SDL_Surface. Formerly the code always calculated the pitch via
w*bpp, which of course does not work in all cases.
This commit is contained in:
Johannes Schickel 2011-02-24 04:24:58 +01:00
parent 9ad4ad1abc
commit e04d983f68

View File

@ -1166,25 +1166,25 @@ void SdlGraphicsManager::copyRectToScreen(const byte *src, int pitch, int x, int
error("SDL_LockSurface failed: %s", SDL_GetError()); error("SDL_LockSurface failed: %s", SDL_GetError());
#ifdef USE_RGB_COLOR #ifdef USE_RGB_COLOR
byte *dst = (byte *)_screen->pixels + y * _videoMode.screenWidth * _screenFormat.bytesPerPixel + x * _screenFormat.bytesPerPixel; byte *dst = (byte *)_screen->pixels + y * _screen->pitch + x * _screenFormat.bytesPerPixel;
if (_videoMode.screenWidth == w && pitch == w * _screenFormat.bytesPerPixel) { if (_videoMode.screenWidth == w && pitch == _screen->pitch) {
memcpy(dst, src, h*w*_screenFormat.bytesPerPixel); memcpy(dst, src, h*pitch);
} else { } else {
do { do {
memcpy(dst, src, w * _screenFormat.bytesPerPixel); memcpy(dst, src, w * _screenFormat.bytesPerPixel);
src += pitch; src += pitch;
dst += _videoMode.screenWidth * _screenFormat.bytesPerPixel; dst += _screen->pitch;
} while (--h); } while (--h);
} }
#else #else
byte *dst = (byte *)_screen->pixels + y * _videoMode.screenWidth + x; byte *dst = (byte *)_screen->pixels + y * _screen->pitch + x;
if (_videoMode.screenWidth == pitch && pitch == w) { if (_screen->pitch == pitch && pitch == w) {
memcpy(dst, src, h*w); memcpy(dst, src, h*w);
} else { } else {
do { do {
memcpy(dst, src, w); memcpy(dst, src, w);
src += pitch; src += pitch;
dst += _videoMode.screenWidth; dst += _screen->pitch;
} while (--h); } while (--h);
} }
#endif #endif