aboutsummaryrefslogtreecommitdiff
path: root/engines/mohawk
diff options
context:
space:
mode:
Diffstat (limited to 'engines/mohawk')
-rw-r--r--engines/mohawk/bitmap.cpp101
-rw-r--r--engines/mohawk/bitmap.h24
-rw-r--r--engines/mohawk/graphics.cpp17
-rw-r--r--engines/mohawk/myst_graphics.cpp41
-rw-r--r--engines/mohawk/myst_graphics.h7
-rw-r--r--engines/mohawk/video.cpp20
6 files changed, 46 insertions, 164 deletions
diff --git a/engines/mohawk/bitmap.cpp b/engines/mohawk/bitmap.cpp
index 4edde31236..952b6daec2 100644
--- a/engines/mohawk/bitmap.cpp
+++ b/engines/mohawk/bitmap.cpp
@@ -29,6 +29,7 @@
#include "common/substream.h"
#include "common/system.h"
#include "common/textconsole.h"
+#include "graphics/decoders/bmp.h"
namespace Mohawk {
@@ -631,97 +632,37 @@ void MohawkBitmap::drawRLE8(Graphics::Surface *surface, bool isLE) {
MohawkSurface *MystBitmap::decodeImage(Common::SeekableReadStream* stream) {
uint32 uncompressedSize = stream->readUint32LE();
- Common::SeekableReadStream* bmpStream = decompressLZ(stream, uncompressedSize);
+ Common::SeekableReadStream *bmpStream = decompressLZ(stream, uncompressedSize);
delete stream;
- _header.type = bmpStream->readUint16BE();
+ Graphics::BitmapDecoder bitmapDecoder;
+ if (!bitmapDecoder.loadStream(*bmpStream))
+ error("Could not decode Myst bitmap");
- if (_header.type != 'BM')
- error("BMP header not detected");
+ const Graphics::Surface *bmpSurface = bitmapDecoder.getSurface();
+ Graphics::Surface *newSurface = 0;
- _header.size = bmpStream->readUint32LE();
- assert (_header.size > 0);
- _header.res1 = bmpStream->readUint16LE();
- _header.res2 = bmpStream->readUint16LE();
- _header.imageOffset = bmpStream->readUint32LE();
-
- _info.size = bmpStream->readUint32LE();
-
- if (_info.size != 40)
- error("Only Windows v3 BMP's are supported");
-
- _info.width = bmpStream->readUint32LE();
- _info.height = bmpStream->readUint32LE();
- _info.planes = bmpStream->readUint16LE();
- _info.bitsPerPixel = bmpStream->readUint16LE();
- _info.compression = bmpStream->readUint32LE();
- _info.imageSize = bmpStream->readUint32LE();
- _info.pixelsPerMeterX = bmpStream->readUint32LE();
- _info.pixelsPerMeterY = bmpStream->readUint32LE();
- _info.colorsUsed = bmpStream->readUint32LE();
- _info.colorsImportant = bmpStream->readUint32LE();
-
- if (_info.compression != 0)
- error("Unhandled BMP compression %d", _info.compression);
-
- if (_info.colorsUsed == 0)
- _info.colorsUsed = 256;
-
- if (_info.bitsPerPixel != 8 && _info.bitsPerPixel != 24)
- error("%dbpp Bitmaps not supported", _info.bitsPerPixel);
-
- byte *palData = NULL;
-
- if (_info.bitsPerPixel == 8) {
- palData = (byte *)malloc(256 * 3);
- for (uint16 i = 0; i < _info.colorsUsed; i++) {
- palData[i * 3 + 2] = bmpStream->readByte();
- palData[i * 3 + 1] = bmpStream->readByte();
- palData[i * 3 + 0] = bmpStream->readByte();
- bmpStream->readByte();
- }
- }
-
- bmpStream->seek(_header.imageOffset);
-
- Graphics::Surface *surface = createSurface(_info.width, _info.height);
- int srcPitch = _info.width * (_info.bitsPerPixel >> 3);
- const int extraDataLength = (srcPitch % 4) ? 4 - (srcPitch % 4) : 0;
-
- if (_info.bitsPerPixel == 8) {
- byte *dst = (byte *)surface->pixels;
-
- for (uint32 i = 0; i < _info.height; i++) {
- bmpStream->read(dst + (_info.height - i - 1) * _info.width, _info.width);
- bmpStream->skip(extraDataLength);
- }
+ if (bmpSurface->format.bytesPerPixel == 1) {
+ _bitsPerPixel = 8;
+ newSurface = new Graphics::Surface();
+ newSurface->copyFrom(*bmpSurface);
} else {
- Graphics::PixelFormat pixelFormat = g_system->getScreenFormat();
-
- byte *dst = (byte *)surface->pixels + (surface->h - 1) * surface->pitch;
-
- for (uint32 i = 0; i < _info.height; i++) {
- for (uint32 j = 0; j < _info.width; j++) {
- byte b = bmpStream->readByte();
- byte g = bmpStream->readByte();
- byte r = bmpStream->readByte();
+ _bitsPerPixel = 24;
+ newSurface = bmpSurface->convertTo(g_system->getScreenFormat());
+ }
- if (pixelFormat.bytesPerPixel == 2)
- *((uint16 *)dst) = pixelFormat.RGBToColor(r, g, b);
- else
- *((uint32 *)dst) = pixelFormat.RGBToColor(r, g, b);
+ // Copy the palette to one of our own
+ const byte *palette = bitmapDecoder.getPalette();
+ byte *newPal = 0;
- dst += pixelFormat.bytesPerPixel;
- }
-
- bmpStream->skip(extraDataLength);
- dst -= surface->pitch * 2;
- }
+ if (palette) {
+ newPal = (byte *)malloc(256 * 3);
+ memcpy(newPal, palette, 256 * 3);
}
delete bmpStream;
- return new MohawkSurface(surface, palData);
+ return new MohawkSurface(newSurface, newPal);
}
#endif
diff --git a/engines/mohawk/bitmap.h b/engines/mohawk/bitmap.h
index 74218882e8..73c117b5c7 100644
--- a/engines/mohawk/bitmap.h
+++ b/engines/mohawk/bitmap.h
@@ -154,30 +154,10 @@ public:
MohawkSurface *decodeImage(Common::SeekableReadStream *stream);
protected:
- byte getBitsPerPixel() { return _info.bitsPerPixel; }
+ byte getBitsPerPixel() { return _bitsPerPixel; }
private:
- struct BitmapHeader {
- uint16 type;
- uint32 size;
- uint16 res1;
- uint16 res2;
- uint32 imageOffset;
- } _header;
-
- struct InfoHeader {
- uint32 size;
- uint32 width;
- uint32 height;
- uint16 planes;
- uint16 bitsPerPixel;
- uint32 compression;
- uint32 imageSize;
- uint32 pixelsPerMeterX;
- uint32 pixelsPerMeterY;
- uint32 colorsUsed;
- uint32 colorsImportant;
- } _info;
+ uint16 _bitsPerPixel;
};
#endif
diff --git a/engines/mohawk/graphics.cpp b/engines/mohawk/graphics.cpp
index a08d034ef7..0f9a62c891 100644
--- a/engines/mohawk/graphics.cpp
+++ b/engines/mohawk/graphics.cpp
@@ -58,22 +58,7 @@ void MohawkSurface::convertToTrueColor() {
assert(_palette);
- Graphics::PixelFormat pixelFormat = g_system->getScreenFormat();
- Graphics::Surface *surface = new Graphics::Surface();
- surface->create(_surface->w, _surface->h, pixelFormat);
-
- for (uint16 i = 0; i < _surface->h; i++) {
- for (uint16 j = 0; j < _surface->w; j++) {
- byte palIndex = *((byte *)_surface->pixels + i * _surface->pitch + j);
- byte r = _palette[palIndex * 3 + 0];
- byte g = _palette[palIndex * 3 + 1];
- byte b = _palette[palIndex * 3 + 2];
- if (pixelFormat.bytesPerPixel == 2)
- *((uint16 *)surface->getBasePtr(j, i)) = pixelFormat.RGBToColor(r, g, b);
- else
- *((uint32 *)surface->getBasePtr(j, i)) = pixelFormat.RGBToColor(r, g, b);
- }
- }
+ Graphics::Surface *surface = _surface->convertTo(g_system->getScreenFormat(), _palette);
// Free everything and set the new surface as the converted surface
_surface->free();
diff --git a/engines/mohawk/myst_graphics.cpp b/engines/mohawk/myst_graphics.cpp
index 151390580f..484e49d529 100644
--- a/engines/mohawk/myst_graphics.cpp
+++ b/engines/mohawk/myst_graphics.cpp
@@ -28,8 +28,8 @@
#include "common/system.h"
#include "common/textconsole.h"
#include "engines/util.h"
-#include "graphics/jpeg.h"
-#include "graphics/pict.h"
+#include "graphics/decoders/jpeg.h"
+#include "graphics/decoders/pict.h"
namespace Mohawk {
@@ -49,14 +49,6 @@ MystGraphics::MystGraphics(MohawkEngine_Myst* vm) : GraphicsManager(), _vm(vm) {
if (_pixelFormat.bytesPerPixel == 1)
error("Myst requires greater than 256 colors to run");
- if (_vm->getFeatures() & GF_ME) {
- _jpegDecoder = new Graphics::JPEG();
- _pictDecoder = new Graphics::PictDecoder(_pixelFormat);
- } else {
- _jpegDecoder = NULL;
- _pictDecoder = NULL;
- }
-
_pictureFile.entries = NULL;
// Initialize our buffer
@@ -69,8 +61,6 @@ MystGraphics::MystGraphics(MohawkEngine_Myst* vm) : GraphicsManager(), _vm(vm) {
MystGraphics::~MystGraphics() {
delete _bmpDecoder;
- delete _jpegDecoder;
- delete _pictDecoder;
delete[] _pictureFile.entries;
_backBuffer->free();
@@ -130,15 +120,21 @@ MohawkSurface *MystGraphics::decodeImage(uint16 id) {
for (uint32 i = 0; i < _pictureFile.pictureCount; i++)
if (_pictureFile.entries[i].id == id) {
if (_pictureFile.entries[i].type == 0) {
- Common::SeekableReadStream *stream = new Common::SeekableSubReadStream(&_pictureFile.picFile, _pictureFile.entries[i].offset, _pictureFile.entries[i].offset + _pictureFile.entries[i].size);
+ Graphics::JPEGDecoder jpeg;
+ Common::SeekableSubReadStream subStream(&_pictureFile.picFile, _pictureFile.entries[i].offset, _pictureFile.entries[i].offset + _pictureFile.entries[i].size);
- if (!_jpegDecoder->read(stream))
+ if (!jpeg.loadStream(subStream))
error("Could not decode Myst ME Mac JPEG");
- mhkSurface = new MohawkSurface(_jpegDecoder->getSurface(_pixelFormat));
- delete stream;
+ mhkSurface = new MohawkSurface(jpeg.getSurface()->convertTo(_pixelFormat));
} else if (_pictureFile.entries[i].type == 1) {
- mhkSurface = new MohawkSurface(_pictDecoder->decodeImage(new Common::SeekableSubReadStream(&_pictureFile.picFile, _pictureFile.entries[i].offset, _pictureFile.entries[i].offset + _pictureFile.entries[i].size)));
+ Graphics::PICTDecoder pict;
+ Common::SeekableSubReadStream subStream(&_pictureFile.picFile, _pictureFile.entries[i].offset, _pictureFile.entries[i].offset + _pictureFile.entries[i].size);
+
+ if (!pict.loadStream(subStream))
+ error("Could not decode Myst ME Mac PICT");
+
+ mhkSurface = new MohawkSurface(pict.getSurface()->convertTo(_pixelFormat));
} else
error ("Unknown Picture File type %d", _pictureFile.entries[i].type);
break;
@@ -170,9 +166,14 @@ MohawkSurface *MystGraphics::decodeImage(uint16 id) {
dataStream->seek(0);
}
- if (isPict)
- mhkSurface = new MohawkSurface(_pictDecoder->decodeImage(dataStream));
- else {
+ if (isPict) {
+ Graphics::PICTDecoder pict;
+
+ if (!pict.loadStream(*dataStream))
+ error("Could not decode Myst ME PICT");
+
+ mhkSurface = new MohawkSurface(pict.getSurface()->convertTo(_pixelFormat));
+ } else {
mhkSurface = _bmpDecoder->decodeImage(dataStream);
mhkSurface->convertToTrueColor();
}
diff --git a/engines/mohawk/myst_graphics.h b/engines/mohawk/myst_graphics.h
index e2b02db5fc..20fd46c5b9 100644
--- a/engines/mohawk/myst_graphics.h
+++ b/engines/mohawk/myst_graphics.h
@@ -27,11 +27,6 @@
#include "common/file.h"
-namespace Graphics {
-class JPEG;
-class PictDecoder;
-}
-
namespace Mohawk {
class MystBitmap;
@@ -70,8 +65,6 @@ protected:
private:
MohawkEngine_Myst *_vm;
MystBitmap *_bmpDecoder;
- Graphics::PictDecoder *_pictDecoder;
- Graphics::JPEG *_jpegDecoder;
struct PictureFile {
uint32 pictureCount;
diff --git a/engines/mohawk/video.cpp b/engines/mohawk/video.cpp
index 8d72fa3f72..80fa4bf9a0 100644
--- a/engines/mohawk/video.cpp
+++ b/engines/mohawk/video.cpp
@@ -235,25 +235,7 @@ bool VideoManager::updateMovies() {
if (_videoStreams[i]->hasDirtyPalette())
_videoStreams[i]->setSystemPalette();
} else {
- convertedFrame = new Graphics::Surface();
- const byte *palette = _videoStreams[i]->getPalette();
- assert(palette);
-
- convertedFrame->create(frame->w, frame->h, pixelFormat);
-
- for (uint16 j = 0; j < frame->h; j++) {
- for (uint16 k = 0; k < frame->w; k++) {
- byte palIndex = *((const byte *)frame->getBasePtr(k, j));
- byte r = palette[palIndex * 3];
- byte g = palette[palIndex * 3 + 1];
- byte b = palette[palIndex * 3 + 2];
- if (pixelFormat.bytesPerPixel == 2)
- *((uint16 *)convertedFrame->getBasePtr(k, j)) = pixelFormat.RGBToColor(r, g, b);
- else
- *((uint32 *)convertedFrame->getBasePtr(k, j)) = pixelFormat.RGBToColor(r, g, b);
- }
- }
-
+ convertedFrame = frame->convertTo(pixelFormat, _videoStreams[i]->getPalette());
frame = convertedFrame;
}
}