aboutsummaryrefslogtreecommitdiff
path: root/engines/mohawk/graphics.cpp
diff options
context:
space:
mode:
authorAlyssa Milburn2010-12-02 21:25:15 +0000
committerAlyssa Milburn2010-12-02 21:25:15 +0000
commit27799e354e073cc2db6160fdf25b4da321d343e7 (patch)
treedef5097b0736d9e348fd55efc26fb773756d7c2b /engines/mohawk/graphics.cpp
parenteb729b5f2e5178a652c87fcdc7493eda88c1bddc (diff)
downloadscummvm-rg350-27799e354e073cc2db6160fdf25b4da321d343e7.tar.gz
scummvm-rg350-27799e354e073cc2db6160fdf25b4da321d343e7.tar.bz2
scummvm-rg350-27799e354e073cc2db6160fdf25b4da321d343e7.zip
MOHAWK: move shared setPalette/copyImage routines into GraphicsManager
svn-id: r54743
Diffstat (limited to 'engines/mohawk/graphics.cpp')
-rw-r--r--engines/mohawk/graphics.cpp190
1 files changed, 98 insertions, 92 deletions
diff --git a/engines/mohawk/graphics.cpp b/engines/mohawk/graphics.cpp
index 8ffbe2f81b..8812b2edb2 100644
--- a/engines/mohawk/graphics.cpp
+++ b/engines/mohawk/graphics.cpp
@@ -117,6 +117,99 @@ MohawkSurface *GraphicsManager::findImage(uint16 id) {
return _cache[id];
}
+void GraphicsManager::preloadImage(uint16 image) {
+ findImage(image);
+}
+
+void GraphicsManager::setPalette(uint16 id) {
+ Common::SeekableReadStream *tpalStream = getVM()->getResource(ID_TPAL, id);
+
+ uint16 colorStart = tpalStream->readUint16BE();
+ uint16 colorCount = tpalStream->readUint16BE();
+ byte *palette = new byte[colorCount * 4];
+
+ for (uint16 i = 0; i < colorCount; i++) {
+ palette[i * 4] = tpalStream->readByte();
+ palette[i * 4 + 1] = tpalStream->readByte();
+ palette[i * 4 + 2] = tpalStream->readByte();
+ palette[i * 4 + 3] = tpalStream->readByte();
+ }
+
+ delete tpalStream;
+
+ getVM()->_system->setPalette(palette, colorStart, colorCount);
+ delete[] palette;
+}
+
+void GraphicsManager::copyAnimImageToScreen(uint16 image, int left, int top) {
+ Graphics::Surface *surface = findImage(image)->getSurface();
+
+ Common::Rect srcRect(0, 0, surface->w, surface->h);
+ Common::Rect dstRect(left, top, left + surface->w, top + surface->h);
+ copyAnimImageSectionToScreen(image, srcRect, dstRect);
+}
+
+void GraphicsManager::copyAnimImageSectionToScreen(uint16 image, Common::Rect srcRect, Common::Rect dstRect) {
+ uint16 startX = 0;
+ uint16 startY = 0;
+
+ assert(srcRect.isValidRect() && dstRect.isValidRect());
+ assert(srcRect.left >= 0 && srcRect.top >= 0);
+
+ // TODO: clip rect
+ if (dstRect.left < 0) {
+ startX -= dstRect.left;
+ dstRect.left = 0;
+ }
+
+ if (dstRect.top < 0) {
+ startY -= dstRect.top;
+ dstRect.top = 0;
+ }
+
+ if (dstRect.left >= getVM()->_system->getWidth())
+ return;
+ if (dstRect.top >= getVM()->_system->getHeight())
+ return;
+
+ Graphics::Surface *surface = findImage(image)->getSurface();
+ if (startX >= surface->w)
+ return;
+ if (startY >= surface->h)
+ return;
+
+ if (srcRect.left > surface->w)
+ return;
+ if (srcRect.top > surface->h)
+ return;
+ if (srcRect.right > surface->w)
+ srcRect.right = surface->w;
+ if (srcRect.bottom > surface->h)
+ srcRect.bottom = surface->h;
+
+ uint16 width = MIN<int>(srcRect.right - srcRect.left - startX, getVM()->_system->getWidth() - dstRect.left);
+ uint16 height = MIN<int>(srcRect.bottom - srcRect.top - startY, getVM()->_system->getHeight() - dstRect.top);
+
+ byte *surf = (byte *)surface->getBasePtr(0, srcRect.top + startY);
+ Graphics::Surface *screen = getVM()->_system->lockScreen();
+
+ // image and screen should always be 8bpp
+ for (uint16 y = 0; y < height; y++) {
+ byte *dest = (byte *)screen->getBasePtr(dstRect.left, dstRect.top + y);
+ byte *src = surf + srcRect.left + startX;
+ // blit, with 0 being transparent
+ for (uint16 x = 0; x < width; x++) {
+ if (*src)
+ *dest = *src;
+ src++;
+ dest++;
+ }
+ surf += surface->pitch;
+ }
+
+ getVM()->_system->unlockScreen();
+}
+
MystGraphics::MystGraphics(MohawkEngine_Myst* vm) : GraphicsManager(), _vm(vm) {
_bmpDecoder = new MystBitmap();
@@ -784,85 +877,13 @@ MohawkSurface *LBGraphics::decodeImage(uint16 id) {
return _bmpDecoder->decodeImage(_vm->getResource(ID_TBMP, id));
}
-void LBGraphics::preloadImage(uint16 image) {
- findImage(image);
-}
-
-void LBGraphics::copyImageToScreen(uint16 image, bool useOffsets, int left, int top) {
- MohawkSurface *mhkSurface = findImage(image);
- Graphics::Surface *surface = mhkSurface->getSurface();
-
- if (useOffsets) {
- left -= mhkSurface->getOffsetX();
- top -= mhkSurface->getOffsetY();
- }
-
- Common::Rect srcRect(0, 0, surface->w, surface->h);
- Common::Rect dstRect(left, top, left + surface->w, top + surface->h);
- copyImageSectionToScreen(image, srcRect, dstRect);
-}
-
-void LBGraphics::copyImageSectionToScreen(uint16 image, Common::Rect srcRect, Common::Rect dstRect) {
+void LBGraphics::copyOffsetAnimImageToScreen(uint16 image, int left, int top) {
MohawkSurface *mhkSurface = findImage(image);
- uint16 startX = 0;
- uint16 startY = 0;
-
- assert(srcRect.isValidRect() && dstRect.isValidRect());
- assert(srcRect.left >= 0 && srcRect.top >= 0);
-
- // TODO: clip rect
- if (dstRect.left < 0) {
- startX -= dstRect.left;
- dstRect.left = 0;
- }
-
- if (dstRect.top < 0) {
- startY -= dstRect.top;
- dstRect.top = 0;
- }
-
- if (dstRect.left >= _vm->_system->getWidth())
- return;
- if (dstRect.top >= _vm->_system->getHeight())
- return;
-
- Graphics::Surface *surface = mhkSurface->getSurface();
- if (startX >= surface->w)
- return;
- if (startY >= surface->h)
- return;
-
- if (srcRect.left > surface->w)
- return;
- if (srcRect.top > surface->h)
- return;
- if (srcRect.right > surface->w)
- srcRect.right = surface->w;
- if (srcRect.bottom > surface->h)
- srcRect.bottom = surface->h;
-
- uint16 width = MIN<int>(srcRect.right - srcRect.left - startX, _vm->_system->getWidth() - dstRect.left);
- uint16 height = MIN<int>(srcRect.bottom - srcRect.top - startY, _vm->_system->getHeight() - dstRect.top);
-
- byte *surf = (byte *)surface->getBasePtr(0, srcRect.top + startY);
- Graphics::Surface *screen = _vm->_system->lockScreen();
+ left -= mhkSurface->getOffsetX();
+ top -= mhkSurface->getOffsetY();
- // image and screen are always 8bpp for LB
- for (uint16 y = 0; y < height; y++) {
- byte *dest = (byte *)screen->getBasePtr(dstRect.left, dstRect.top + y);
- byte *src = surf + srcRect.left + startX;
- // blit, with 0 being transparent
- for (uint16 x = 0; x < width; x++) {
- if (*src)
- *dest = *src;
- src++;
- dest++;
- }
- surf += surface->pitch;
- }
-
- _vm->_system->unlockScreen();
+ GraphicsManager::copyAnimImageToScreen(image, left, top);
}
bool LBGraphics::imageIsTransparentAt(uint16 image, bool useOffsets, int x, int y) {
@@ -903,22 +924,7 @@ void LBGraphics::setPalette(uint16 id) {
_vm->_system->setPalette(palette, 0, colorCount);
delete[] palette;
} else {
- Common::SeekableReadStream *tpalStream = _vm->getResource(ID_TPAL, id);
- uint16 colorStart = tpalStream->readUint16BE();
- uint16 colorCount = tpalStream->readUint16BE();
- byte *palette = new byte[colorCount * 4];
-
- for (uint16 i = 0; i < colorCount; i++) {
- palette[i * 4] = tpalStream->readByte();
- palette[i * 4 + 1] = tpalStream->readByte();
- palette[i * 4 + 2] = tpalStream->readByte();
- palette[i * 4 + 3] = tpalStream->readByte();
- }
-
- delete tpalStream;
-
- _vm->_system->setPalette(palette, colorStart, colorCount);
- delete[] palette;
+ GraphicsManager::setPalette(id);
}
}