Skip to content

Commit

Permalink
PEGASUS: Add ability to draw masked surfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Hoops committed Nov 1, 2011
1 parent 74d08a1 commit 0d6dbfa
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
31 changes: 31 additions & 0 deletions engines/pegasus/surface.cpp
Expand Up @@ -205,6 +205,37 @@ void Surface::copyToCurrentPortTransparent(const Common::Rect &srcRect, const Co
}
}

void Surface::copyToCurrentPortMasked(const Common::Rect &srcRect, const Common::Rect &dstRect, const Surface *mask) const {
Graphics::Surface *screen = ((PegasusEngine *)g_engine)->_gfx->getCurSurface();
byte *src = (byte *)_surface->getBasePtr(srcRect.left, srcRect.top);
byte *dst = (byte *)screen->getBasePtr(dstRect.left, dstRect.top);

int lineSize = srcRect.width() * _surface->format.bytesPerPixel;

for (int y = 0; y < srcRect.height(); y++) {
byte *maskSrc = (byte *)mask->getSurface()->getBasePtr(0, y);

for (int x = 0; x < srcRect.width(); x++) {
if (g_system->getScreenFormat().bytesPerPixel == 2) {
uint16 color = READ_UINT16(maskSrc);
if (!isTransparent(color))
memcpy(dst, src, 2);
} else if (g_system->getScreenFormat().bytesPerPixel == 4) {
uint32 color = READ_UINT32(maskSrc);
if (!isTransparent(color))
memcpy(dst, src, 4);
}

src += g_system->getScreenFormat().bytesPerPixel;
maskSrc += g_system->getScreenFormat().bytesPerPixel;
dst += g_system->getScreenFormat().bytesPerPixel;
}

src += _surface->pitch - lineSize;
dst += screen->pitch - lineSize;
}
}

void Surface::copyToCurrentPortTransparentGlow(const Common::Rect &srcRect, const Common::Rect &dstRect) const {
// This is the same as copyToCurrentPortTransparent(), but turns the red value of each
// pixel all the way up.
Expand Down
1 change: 1 addition & 0 deletions engines/pegasus/surface.h
Expand Up @@ -70,6 +70,7 @@ class Surface {
void copyToCurrentPortTransparent(const Common::Rect &) const;
void copyToCurrentPort(const Common::Rect &, const Common::Rect &) const;
void copyToCurrentPortTransparent(const Common::Rect &, const Common::Rect &) const;
void copyToCurrentPortMasked(const Common::Rect &, const Common::Rect &, const Surface *) const;
void copyToCurrentPortTransparentGlow(const Common::Rect &, const Common::Rect &) const;
void scaleTransparentCopy(const Common::Rect &, const Common::Rect &) const;
void scaleTransparentCopyGlow(const Common::Rect &, const Common::Rect &) const;
Expand Down

0 comments on commit 0d6dbfa

Please sign in to comment.