Skip to content

Commit

Permalink
SHERLOCK: Initiial handling of scaling in transBlitFrom
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Jun 6, 2015
1 parent 57017e4 commit 3fda42f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
52 changes: 48 additions & 4 deletions engines/sherlock/surface.cpp
Expand Up @@ -28,6 +28,8 @@

namespace Sherlock {

const int TRANSPARENCY = 0xFF;

Surface::Surface(uint16 width, uint16 height) : _freePixels(true) {
create(width, height);
}
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions engines/sherlock/surface.h
Expand Up @@ -53,6 +53,12 @@ class Surface {
* 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;

Expand Down

0 comments on commit 3fda42f

Please sign in to comment.