diff options
author | Matthew Hoops | 2010-02-10 00:20:33 +0000 |
---|---|---|
committer | Matthew Hoops | 2010-02-10 00:20:33 +0000 |
commit | 9fb9c0955df4402d796c2ea02b3da19377e5e480 (patch) | |
tree | 07951bedd7965c9c015f2fbbee95ab60d6dd4ad2 | |
parent | ba1d97211fc20a838571c2821bf653990d5ef3a2 (diff) | |
download | scummvm-rg350-9fb9c0955df4402d796c2ea02b3da19377e5e480.tar.gz scummvm-rg350-9fb9c0955df4402d796c2ea02b3da19377e5e480.tar.bz2 scummvm-rg350-9fb9c0955df4402d796c2ea02b3da19377e5e480.zip |
Add support for the Motion JPEG codec (used in some Myst ME 10th Anniversary videos); minor cleanup.
svn-id: r48028
-rw-r--r-- | engines/mohawk/graphics.cpp | 3 | ||||
-rw-r--r-- | engines/mohawk/graphics.h | 4 | ||||
-rw-r--r-- | engines/mohawk/jpeg.cpp (renamed from engines/mohawk/myst_jpeg.cpp) | 49 | ||||
-rw-r--r-- | engines/mohawk/jpeg.h (renamed from engines/mohawk/myst_jpeg.h) | 20 | ||||
-rw-r--r-- | engines/mohawk/module.mk | 2 | ||||
-rw-r--r-- | engines/mohawk/myst_pict.cpp | 2 | ||||
-rw-r--r-- | engines/mohawk/myst_pict.h | 6 | ||||
-rw-r--r-- | engines/mohawk/video/qt_player.cpp | 5 |
8 files changed, 59 insertions, 32 deletions
diff --git a/engines/mohawk/graphics.cpp b/engines/mohawk/graphics.cpp index fc29c7de83..a634cd1584 100644 --- a/engines/mohawk/graphics.cpp +++ b/engines/mohawk/graphics.cpp @@ -76,7 +76,8 @@ MystGraphics::MystGraphics(MohawkEngine_Myst* vm) : _vm(vm) { error("Myst requires greater than 256 colors to run"); if (_vm->getFeatures() & GF_ME) { - _jpegDecoder = new MystJPEG(); + // We want to delete our own JPEG surfaces, so don't free after use. + _jpegDecoder = new JPEGDecoder(false); _pictDecoder = new MystPICT(_jpegDecoder); } else { _jpegDecoder = NULL; diff --git a/engines/mohawk/graphics.h b/engines/mohawk/graphics.h index 16d515ac08..831e768e41 100644 --- a/engines/mohawk/graphics.h +++ b/engines/mohawk/graphics.h @@ -27,8 +27,8 @@ #define MOHAWK_GRAPHICS_H #include "mohawk/bitmap.h" +#include "mohawk/jpeg.h" #include "mohawk/livingbooks.h" -#include "mohawk/myst_jpeg.h" #include "mohawk/myst_pict.h" #include "common/file.h" @@ -104,7 +104,7 @@ private: MohawkEngine_Myst *_vm; MystBitmap *_bmpDecoder; MystPICT *_pictDecoder; - MystJPEG *_jpegDecoder; + JPEGDecoder *_jpegDecoder; Graphics::PixelFormat _pixelFormat; struct PictureFile { diff --git a/engines/mohawk/myst_jpeg.cpp b/engines/mohawk/jpeg.cpp index e131347a11..07ec54dfea 100644 --- a/engines/mohawk/myst_jpeg.cpp +++ b/engines/mohawk/jpeg.cpp @@ -26,41 +26,62 @@ #include "common/system.h" #include "graphics/conversion.h" // For YUV2RGB -#include "mohawk/myst_jpeg.h" +#include "mohawk/jpeg.h" namespace Mohawk { -MystJPEG::MystJPEG() { +JPEGDecoder::JPEGDecoder(bool freeSurfaceAfterUse) : Graphics::Codec(), _freeSurfaceAfterUse(freeSurfaceAfterUse) { _jpeg = new Graphics::JPEG(); _pixelFormat = g_system->getScreenFormat(); + _surface = NULL; +} + +JPEGDecoder::~JPEGDecoder() { + delete _jpeg; - // We're going to have to dither if we're running in 8bpp. - // We'll take RGBA8888 for best color performance in this case. - if (_pixelFormat.bytesPerPixel == 1) - _pixelFormat = Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0); + if (_surface) { + _surface->free(); + delete _surface; + } } -Graphics::Surface *MystJPEG::decodeImage(Common::SeekableReadStream* stream) { +Graphics::Surface *JPEGDecoder::decodeImage(Common::SeekableReadStream* stream) { _jpeg->read(stream); Graphics::Surface *ySurface = _jpeg->getComponent(1); Graphics::Surface *uSurface = _jpeg->getComponent(2); Graphics::Surface *vSurface = _jpeg->getComponent(3); - Graphics::Surface *finalSurface = new Graphics::Surface(); - finalSurface->create(ySurface->w, ySurface->h, _pixelFormat.bytesPerPixel); + Graphics::Surface *destSurface = NULL; + + // If we should free the surface after use, use the internal _surface storage + // (this should be used when using as a Codec, as the Codecs should free their + // surfaces when deleting the Codec object). Otherwise, create a new Surface + // as the destination. + if (_freeSurfaceAfterUse) { + if (!_surface) { + _surface = new Graphics::Surface(); + _surface->create(ySurface->w, ySurface->h, _pixelFormat.bytesPerPixel); + } + destSurface = _surface; + } else { + destSurface = new Graphics::Surface(); + destSurface->create(ySurface->w, ySurface->h, _pixelFormat.bytesPerPixel); + } + + assert(destSurface); - for (uint16 i = 0; i < finalSurface->h; i++) { - for (uint16 j = 0; j < finalSurface->w; j++) { + for (uint16 i = 0; i < destSurface->h; i++) { + for (uint16 j = 0; j < destSurface->w; j++) { byte r = 0, g = 0, b = 0; Graphics::YUV2RGB(*((byte *)ySurface->getBasePtr(j, i)), *((byte *)uSurface->getBasePtr(j, i)), *((byte *)vSurface->getBasePtr(j, i)), r, g, b); if (_pixelFormat.bytesPerPixel == 2) - *((uint16 *)finalSurface->getBasePtr(j, i)) = _pixelFormat.RGBToColor(r, g, b); + *((uint16 *)destSurface->getBasePtr(j, i)) = _pixelFormat.RGBToColor(r, g, b); else - *((uint32 *)finalSurface->getBasePtr(j, i)) = _pixelFormat.RGBToColor(r, g, b); + *((uint32 *)destSurface->getBasePtr(j, i)) = _pixelFormat.RGBToColor(r, g, b); } } - return finalSurface; + return destSurface; } } // End of namespace Mohawk diff --git a/engines/mohawk/myst_jpeg.h b/engines/mohawk/jpeg.h index ae51dccf7a..086e78332f 100644 --- a/engines/mohawk/myst_jpeg.h +++ b/engines/mohawk/jpeg.h @@ -23,32 +23,36 @@ * */ -#ifndef MYST_JPEG_H -#define MYST_JPEG_H +#ifndef MOHAWK_JPEG_H +#define MOHAWK_JPEG_H #include "common/scummsys.h" #include "common/stream.h" +#include "graphics/video/codecs/codec.h" #include "graphics/jpeg.h" #include "graphics/pixelformat.h" namespace Mohawk { -// Myst JPEG Decoder -// Basically a wrapper around JPEG which converts to RGB +// Mohawk's JPEG Decoder +// Basically a wrapper around JPEG which converts to RGB and also functions +// as a Codec. -class MystJPEG { +class JPEGDecoder : public Graphics::Codec { public: - MystJPEG(); - ~MystJPEG() { delete _jpeg; } + JPEGDecoder(bool freeSurfaceAfterUse); + ~JPEGDecoder(); Graphics::Surface *decodeImage(Common::SeekableReadStream *stream); private: Graphics::PixelFormat _pixelFormat; Graphics::JPEG *_jpeg; + Graphics::Surface *_surface; + bool _freeSurfaceAfterUse; }; -} +} // End of namespace Mohawk #endif diff --git a/engines/mohawk/module.mk b/engines/mohawk/module.mk index 6e72aef0f5..ef1b5f7bb5 100644 --- a/engines/mohawk/module.mk +++ b/engines/mohawk/module.mk @@ -6,10 +6,10 @@ MODULE_OBJS = \ detection.o \ dialogs.o \ graphics.o \ + jpeg.o \ livingbooks.o \ mohawk.o \ myst.o \ - myst_jpeg.o \ myst_pict.o \ myst_vars.o \ myst_saveload.o \ diff --git a/engines/mohawk/myst_pict.cpp b/engines/mohawk/myst_pict.cpp index 765f5b206a..e305937951 100644 --- a/engines/mohawk/myst_pict.cpp +++ b/engines/mohawk/myst_pict.cpp @@ -32,7 +32,7 @@ namespace Mohawk { // The PICT code is based off of the QuickDraw specs: // http://developer.apple.com/documentation/mac/QuickDraw/QuickDraw-461.html -MystPICT::MystPICT(MystJPEG *jpegDecoder) { +MystPICT::MystPICT(JPEGDecoder *jpegDecoder) { _jpegDecoder = jpegDecoder; _pixelFormat = g_system->getScreenFormat(); } diff --git a/engines/mohawk/myst_pict.h b/engines/mohawk/myst_pict.h index 6b56a521b3..087fd301cd 100644 --- a/engines/mohawk/myst_pict.h +++ b/engines/mohawk/myst_pict.h @@ -32,18 +32,18 @@ #include "graphics/pixelformat.h" #include "graphics/surface.h" -#include "mohawk/myst_jpeg.h" +#include "mohawk/jpeg.h" namespace Mohawk { class MystPICT { public: - MystPICT(MystJPEG *jpegDecoder); + MystPICT(JPEGDecoder *jpegDecoder); ~MystPICT() {} Graphics::Surface *decodeImage(Common::SeekableReadStream *stream); private: - MystJPEG *_jpegDecoder; + JPEGDecoder *_jpegDecoder; Common::Rect _imageRect; Graphics::PixelFormat _pixelFormat; diff --git a/engines/mohawk/video/qt_player.cpp b/engines/mohawk/video/qt_player.cpp index 6f868a5418..2423294649 100644 --- a/engines/mohawk/video/qt_player.cpp +++ b/engines/mohawk/video/qt_player.cpp @@ -44,6 +44,7 @@ #include "mohawk/video/qdm2.h" // Video codecs +#include "mohawk/jpeg.h" #include "mohawk/video/cinepak.h" #include "mohawk/video/qtrle.h" #include "mohawk/video/rpza.h" @@ -174,8 +175,8 @@ Graphics::Codec *QTPlayer::createCodec(uint32 codecTag, byte bitsPerPixel) { // Sorenson Video 3: Used by some Myst ME videos. warning ("Sorenson Video 3 not yet supported"); } else if (codecTag == MKID_BE('jpeg')) { - // Motion JPEG: Used by some Myst ME videos. - warning ("Motion JPEG not yet supported"); + // Motion JPEG: Used by some Myst ME 10th Anniversary videos. + return new JPEGDecoder(true); } else if (codecTag == MKID_BE('QkBk')) { // CDToons: Used by most of the Broderbund games. This is an unknown format so far. warning ("CDToons not yet supported"); |