diff options
author | Paul Gilbert | 2015-06-06 14:25:09 -0400 |
---|---|---|
committer | Paul Gilbert | 2015-06-06 14:25:09 -0400 |
commit | 3fda42fbffdc82ec255b4afe3f8296fc9713bc95 (patch) | |
tree | f6ea2bea03fd20582cf77b4faf5e5df0320f25ec | |
parent | 57017e4bc121765c7cd51c6fab4d1210aeace193 (diff) | |
download | scummvm-rg350-3fda42fbffdc82ec255b4afe3f8296fc9713bc95.tar.gz scummvm-rg350-3fda42fbffdc82ec255b4afe3f8296fc9713bc95.tar.bz2 scummvm-rg350-3fda42fbffdc82ec255b4afe3f8296fc9713bc95.zip |
SHERLOCK: Initiial handling of scaling in transBlitFrom
-rw-r--r-- | engines/sherlock/surface.cpp | 52 | ||||
-rw-r--r-- | engines/sherlock/surface.h | 6 |
2 files changed, 54 insertions, 4 deletions
diff --git a/engines/sherlock/surface.cpp b/engines/sherlock/surface.cpp index 8776d9c69f..aba378af65 100644 --- a/engines/sherlock/surface.cpp +++ b/engines/sherlock/surface.cpp @@ -28,6 +28,8 @@ namespace Sherlock { +const int TRANSPARENCY = 0xFF; + Surface::Surface(uint16 width, uint16 height) : _freePixels(true) { create(width, height); } @@ -104,10 +106,53 @@ void Surface::transBlitFrom(const Surface &src, const Common::Point &pt, void Surface::transBlitFrom(const Graphics::Surface &src, const Common::Point &pt, bool flipped, int overrideColor, int scaleVal) { - if (scaleVal != 256) { - error("TODO: scaling for transBlitFrom"); + if (scaleVal == 256) { + transBlitFromUnscaled(src, pt, flipped, overrideColor); + return; } - + + const int SCALE_LIMIT = 0x100; + int scaleX = scaleVal; + int scaleY = scaleVal; + int scaleXCtr = 0, scaleYCtr = 0; + + for (int yCtr = 0, destY = pt.y; yCtr < src.h && destY < this->h(); ++yCtr) { + // Handle skipping lines if Y scaling + scaleYCtr += scaleY; + + while (scaleYCtr >= SCALE_LIMIT && destY < this->h()) { + scaleYCtr -= SCALE_LIMIT; + + if (destY >= 0) { + // Handle drawing the line + const byte *pSrc = (const byte *)src.getBasePtr(0, yCtr); + byte *pDest = (byte *)getBasePtr(pt.x, destY); + scaleXCtr = 0; + + for (int xCtr = 0, destX = pt.x; xCtr < src.w && destX < this->w(); ++xCtr, ++pSrc) { + // Handle horizontal scaling + scaleXCtr += scaleX; + + while (scaleXCtr >= SCALE_LIMIT && destX < this->w()) { + scaleXCtr -= SCALE_LIMIT; + + // Only handle on-screen pixels + if (destX >= 0 && *pSrc != TRANSPARENCY) + *pDest = *pSrc; + + ++pDest; + ++destX; + } + } + } + + ++destY; + } + } +} + +void Surface::transBlitFromUnscaled(const Graphics::Surface &src, const Common::Point &pt, + bool flipped, int overrideColor) { Common::Rect drawRect(0, 0, src.w, src.h); Common::Rect destRect(pt.x, pt.y, pt.x + src.w, pt.y + src.h); @@ -125,7 +170,6 @@ void Surface::transBlitFrom(const Graphics::Surface &src, const Common::Point &p destPt.y + drawRect.height())); // Draw loop - const int TRANSPARENCY = 0xFF; for (int yp = 0; yp < drawRect.height(); ++yp) { const byte *srcP = (const byte *)src.getBasePtr( flipped ? drawRect.right - 1 : drawRect.left, drawRect.top + yp); diff --git a/engines/sherlock/surface.h b/engines/sherlock/surface.h index 506de0b682..32a674fb5b 100644 --- a/engines/sherlock/surface.h +++ b/engines/sherlock/surface.h @@ -53,6 +53,12 @@ private: * Draws a sub-section of a surface at a given position within this surface */ void blitFrom(const Graphics::Surface &src, const Common::Point &pt, const Common::Rect &srcBounds); + + /** + * Draws a surface at a given position within this surface with transparency + */ + void transBlitFromUnscaled(const Graphics::Surface &src, const Common::Point &pt, bool flipped, + int overrideColor); protected: Graphics::Surface _surface; |