diff options
author | David Turner | 2010-12-20 04:29:53 +0000 |
---|---|---|
committer | David Turner | 2010-12-20 04:29:53 +0000 |
commit | 3cc456bf2afa73d65f01d493594d19ef2f0efdbf (patch) | |
tree | ee49743d13b6a0a67790516fb4cf65aaf287c1c5 | |
parent | 9fd43ba6cca192cd7a1ca202e2f2db5b20eff981 (diff) | |
download | scummvm-rg350-3cc456bf2afa73d65f01d493594d19ef2f0efdbf.tar.gz scummvm-rg350-3cc456bf2afa73d65f01d493594d19ef2f0efdbf.tar.bz2 scummvm-rg350-3cc456bf2afa73d65f01d493594d19ef2f0efdbf.zip |
MOHAWK: Fixed Valgrind Error in Myst When Selecting 0 in Imager Code (Myst Card 4709)
Reworked MystGraphics::copyImageSectionToScreen() :
Added clipping of width and height within src surface dimensions.
Improved function readability.
svn-id: r54972
-rw-r--r-- | engines/mohawk/graphics.cpp | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/engines/mohawk/graphics.cpp b/engines/mohawk/graphics.cpp index 29d8802a8a..47808e4c69 100644 --- a/engines/mohawk/graphics.cpp +++ b/engines/mohawk/graphics.cpp @@ -350,10 +350,6 @@ MohawkSurface *MystGraphics::decodeImage(uint16 id) { } void MystGraphics::copyImageSectionToScreen(uint16 image, Common::Rect src, Common::Rect dest) { - // Clip the destination rect to the screen - if (dest.right > _vm->_system->getWidth() || dest.bottom > _vm->_system->getHeight()) - dest.debugPrint(4, "Clipping destination rect to the screen:"); - Graphics::Surface *surface = findImage(image)->getSurface(); // Make sure the image is bottom aligned in the dest rect @@ -367,20 +363,30 @@ void MystGraphics::copyImageSectionToScreen(uint16 image, Common::Rect src, Comm top += dest.height() - _viewport.height(); } + // Clip the destination rect to the screen + if (dest.right > _vm->_system->getWidth() || dest.bottom > _vm->_system->getHeight()) + dest.debugPrint(4, "Clipping destination rect to the screen"); dest.right = CLIP<int>(dest.right, 0, _vm->_system->getWidth()); dest.bottom = CLIP<int>(dest.bottom, 0, _vm->_system->getHeight()); - debug(3, "Image Blit:"); - debug(3, "src.x: %d", src.left); - debug(3, "src.y: %d", src.top); - debug(3, "dest.x: %d", dest.left); - debug(3, "dest.y: %d", dest.top); - debug(3, "width: %d", src.width()); - debug(3, "height: %d", src.height()); - uint16 width = MIN<int>(surface->w, dest.width()); uint16 height = MIN<int>(surface->h, dest.height()); + // Clamp Width and Height to within src surface dimensions + if (src.left + width > surface->w) + width = surface->w - src.left; + if (src.top + height > surface->h) + height = surface->h - src.top; + + debug(3, "MystGraphics::copyImageSectionToScreen()"); + debug(3, "\tImage: %d", image); + debug(3, "\tsrc.left: %d", src.left); + debug(3, "\tsrc.top: %d", src.top); + debug(3, "\tdest.left: %d", dest.left); + debug(3, "\tdest.top: %d", dest.top); + debug(3, "\twidth: %d", width); + debug(3, "\theight: %d", height); + _vm->_system->copyRectToScreen((byte *)surface->getBasePtr(src.left, top), surface->pitch, dest.left, dest.top, width, height); } |