diff options
Diffstat (limited to 'video')
-rw-r--r-- | video/codecs/qtrle.cpp | 135 | ||||
-rw-r--r-- | video/codecs/qtrle.h | 3 | ||||
-rw-r--r-- | video/codecs/rpza.cpp | 22 | ||||
-rw-r--r-- | video/codecs/rpza.h | 3 | ||||
-rw-r--r-- | video/coktel_decoder.cpp | 45 | ||||
-rw-r--r-- | video/coktel_decoder.h | 9 |
6 files changed, 134 insertions, 83 deletions
diff --git a/video/codecs/qtrle.cpp b/video/codecs/qtrle.cpp index f01720ec86..d2cdea27de 100644 --- a/video/codecs/qtrle.cpp +++ b/video/codecs/qtrle.cpp @@ -37,28 +37,25 @@ namespace Video { QTRLEDecoder::QTRLEDecoder(uint16 width, uint16 height, byte bitsPerPixel) : Codec() { _bitsPerPixel = bitsPerPixel; - _pixelFormat = g_system->getScreenFormat(); - // We need to increase the surface size to a multiple of 4 + // We need to ensure the width is a multiple of 4 uint16 wMod = width % 4; - if(wMod != 0) + if (wMod != 0) width += 4 - wMod; - debug(2, "QTRLE corrected width: %d", width); - _surface = new Graphics::Surface(); - _surface->create(width, height, _bitsPerPixel <= 8 ? Graphics::PixelFormat::createFormatCLUT8() : _pixelFormat); + _surface->create(width, height, getPixelFormat()); } #define CHECK_STREAM_PTR(n) \ if ((stream->pos() + n) > stream->size()) { \ - warning ("Problem: stream out of bounds (%d >= %d)", stream->pos() + n, stream->size()); \ + warning("QTRLE Problem: stream out of bounds (%d > %d)", stream->pos() + n, stream->size()); \ return; \ } #define CHECK_PIXEL_PTR(n) \ if ((int32)pixelPtr + n > _surface->w * _surface->h) { \ - warning ("Problem: pixel ptr = %d, pixel limit = %d", pixelPtr + n, _surface->w * _surface->h); \ + warning("QTRLE Problem: pixel ptr = %d, pixel limit = %d", pixelPtr + n, _surface->w * _surface->h); \ return; \ } \ @@ -132,8 +129,6 @@ void QTRLEDecoder::decode2_4(Common::SeekableReadStream *stream, uint32 rowPtr, for (int8 i = numPixels - 1; i >= 0; i--) { pi[numPixels - 1 - i] = (stream->readByte() >> ((i * bpp) & 0x07)) & ((1 << bpp) - 1); - // FIXME: Is this right? - //stream_ptr += ((i & ((num_pixels>>2)-1)) == 0); if ((i & ((numPixels >> 2) - 1)) == 0) stream->readByte(); } @@ -215,7 +210,7 @@ void QTRLEDecoder::decode8(Common::SeekableReadStream *stream, uint32 rowPtr, ui void QTRLEDecoder::decode16(Common::SeekableReadStream *stream, uint32 rowPtr, uint32 linesToChange) { uint32 pixelPtr = 0; - OverlayColor *rgb = (OverlayColor *)_surface->pixels; + uint16 *rgb = (uint16 *)_surface->pixels; while (linesToChange--) { CHECK_STREAM_PTR(2); @@ -235,25 +230,15 @@ void QTRLEDecoder::decode16(Common::SeekableReadStream *stream, uint32 rowPtr, u CHECK_PIXEL_PTR(rleCode); - while (rleCode--) { - // Convert from RGB555 to the format specified by the Overlay - byte r = 0, g = 0, b = 0; - Graphics::colorToRGB<Graphics::ColorMasks<555> >(rgb16, r, g, b); - rgb[pixelPtr++] = _pixelFormat.RGBToColor(r, g, b); - } + while (rleCode--) + rgb[pixelPtr++] = rgb16; } else { CHECK_STREAM_PTR(rleCode * 2); CHECK_PIXEL_PTR(rleCode); // copy pixels directly to output - while (rleCode--) { - uint16 rgb16 = stream->readUint16BE(); - - // Convert from RGB555 to the format specified by the Overlay - byte r = 0, g = 0, b = 0; - Graphics::colorToRGB<Graphics::ColorMasks<555> >(rgb16, r, g, b); - rgb[pixelPtr++] = _pixelFormat.RGBToColor(r, g, b); - } + while (rleCode--) + rgb[pixelPtr++] = stream->readUint16BE(); } } @@ -263,7 +248,7 @@ void QTRLEDecoder::decode16(Common::SeekableReadStream *stream, uint32 rowPtr, u void QTRLEDecoder::decode24(Common::SeekableReadStream *stream, uint32 rowPtr, uint32 linesToChange) { uint32 pixelPtr = 0; - OverlayColor *rgb = (OverlayColor *)_surface->pixels; + uint32 *rgb = (uint32 *)_surface->pixels; while (linesToChange--) { CHECK_STREAM_PTR(2); @@ -283,11 +268,12 @@ void QTRLEDecoder::decode24(Common::SeekableReadStream *stream, uint32 rowPtr, u byte r = stream->readByte(); byte g = stream->readByte(); byte b = stream->readByte(); + uint32 color = _surface->format.RGBToColor(r, g, b); CHECK_PIXEL_PTR(rleCode); while (rleCode--) - rgb[pixelPtr++] = _pixelFormat.RGBToColor(r, g, b); + rgb[pixelPtr++] = color; } else { CHECK_STREAM_PTR(rleCode * 3); CHECK_PIXEL_PTR(rleCode); @@ -297,7 +283,7 @@ void QTRLEDecoder::decode24(Common::SeekableReadStream *stream, uint32 rowPtr, u byte r = stream->readByte(); byte g = stream->readByte(); byte b = stream->readByte(); - rgb[pixelPtr++] = _pixelFormat.RGBToColor(r, g, b); + rgb[pixelPtr++] = _surface->format.RGBToColor(r, g, b); } } } @@ -308,7 +294,7 @@ void QTRLEDecoder::decode24(Common::SeekableReadStream *stream, uint32 rowPtr, u void QTRLEDecoder::decode32(Common::SeekableReadStream *stream, uint32 rowPtr, uint32 linesToChange) { uint32 pixelPtr = 0; - OverlayColor *rgb = (OverlayColor *)_surface->pixels; + uint32 *rgb = (uint32 *)_surface->pixels; while (linesToChange--) { CHECK_STREAM_PTR(2); @@ -329,11 +315,12 @@ void QTRLEDecoder::decode32(Common::SeekableReadStream *stream, uint32 rowPtr, u byte r = stream->readByte(); byte g = stream->readByte(); byte b = stream->readByte(); + uint32 color = _surface->format.ARGBToColor(a, r, g, b); CHECK_PIXEL_PTR(rleCode); while (rleCode--) - rgb[pixelPtr++] = _pixelFormat.ARGBToColor(a, r, g, b); + rgb[pixelPtr++] = color; } else { CHECK_STREAM_PTR(rleCode * 4); CHECK_PIXEL_PTR(rleCode); @@ -344,7 +331,7 @@ void QTRLEDecoder::decode32(Common::SeekableReadStream *stream, uint32 rowPtr, u byte r = stream->readByte(); byte g = stream->readByte(); byte b = stream->readByte(); - rgb[pixelPtr++] = _pixelFormat.ARGBToColor(a, r, g, b); + rgb[pixelPtr++] = _surface->format.ARGBToColor(a, r, g, b); } } } @@ -354,7 +341,7 @@ void QTRLEDecoder::decode32(Common::SeekableReadStream *stream, uint32 rowPtr, u } const Graphics::Surface *QTRLEDecoder::decodeImage(Common::SeekableReadStream *stream) { - uint16 start_line = 0; + uint16 startLine = 0; uint16 height = _surface->h; // check if this frame is even supposed to change @@ -369,44 +356,45 @@ const Graphics::Surface *QTRLEDecoder::decodeImage(Common::SeekableReadStream *s // if a header is present, fetch additional decoding parameters if (header & 8) { - if(stream->size() < 14) + if (stream->size() < 14) return _surface; - start_line = stream->readUint16BE(); + + startLine = stream->readUint16BE(); stream->readUint16BE(); // Unknown height = stream->readUint16BE(); stream->readUint16BE(); // Unknown } - uint32 row_ptr = _surface->w * start_line; + uint32 rowPtr = _surface->w * startLine; switch (_bitsPerPixel) { - case 1: - case 33: - decode1(stream, row_ptr, height); - break; - case 2: - case 34: - decode2_4(stream, row_ptr, height, 2); - break; - case 4: - case 36: - decode2_4(stream, row_ptr, height, 4); - break; - case 8: - case 40: - decode8(stream, row_ptr, height); - break; - case 16: - decode16(stream, row_ptr, height); - break; - case 24: - decode24(stream, row_ptr, height); - break; - case 32: - decode32(stream, row_ptr, height); - break; - default: - error ("Unsupported bits per pixel %d", _bitsPerPixel); + case 1: + case 33: + decode1(stream, rowPtr, height); + break; + case 2: + case 34: + decode2_4(stream, rowPtr, height, 2); + break; + case 4: + case 36: + decode2_4(stream, rowPtr, height, 4); + break; + case 8: + case 40: + decode8(stream, rowPtr, height); + break; + case 16: + decode16(stream, rowPtr, height); + break; + case 24: + decode24(stream, rowPtr, height); + break; + case 32: + decode32(stream, rowPtr, height); + break; + default: + error("Unsupported QTRLE bits per pixel %d", _bitsPerPixel); } return _surface; @@ -417,4 +405,27 @@ QTRLEDecoder::~QTRLEDecoder() { delete _surface; } +Graphics::PixelFormat QTRLEDecoder::getPixelFormat() const { + switch (_bitsPerPixel) { + case 1: + case 33: + case 2: + case 34: + case 4: + case 36: + case 8: + case 40: + return Graphics::PixelFormat::createFormatCLUT8(); + case 16: + return Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0); + case 24: + case 32: + return Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24); + default: + error("Unsupported QTRLE bits per pixel %d", _bitsPerPixel); + } + + return Graphics::PixelFormat(); +} + } // End of namespace Video diff --git a/video/codecs/qtrle.h b/video/codecs/qtrle.h index 6f8e113ca5..d9db58ab23 100644 --- a/video/codecs/qtrle.h +++ b/video/codecs/qtrle.h @@ -34,13 +34,12 @@ public: ~QTRLEDecoder(); const Graphics::Surface *decodeImage(Common::SeekableReadStream *stream); - Graphics::PixelFormat getPixelFormat() const { return _pixelFormat; } + Graphics::PixelFormat getPixelFormat() const; private: byte _bitsPerPixel; Graphics::Surface *_surface; - Graphics::PixelFormat _pixelFormat; void decode1(Common::SeekableReadStream *stream, uint32 rowPtr, uint32 linesToChange); void decode2_4(Common::SeekableReadStream *stream, uint32 rowPtr, uint32 linesToChange, byte bpp); diff --git a/video/codecs/rpza.cpp b/video/codecs/rpza.cpp index df5738202e..acc1b7f358 100644 --- a/video/codecs/rpza.cpp +++ b/video/codecs/rpza.cpp @@ -28,22 +28,17 @@ #include "common/system.h" #include "common/stream.h" #include "common/textconsole.h" -#include "graphics/colormasks.h" namespace Video { RPZADecoder::RPZADecoder(uint16 width, uint16 height) : Codec() { - _pixelFormat = g_system->getScreenFormat(); - // We need to increase the surface size to a multiple of 4 uint16 wMod = width % 4; - if(wMod != 0) + if (wMod != 0) width += 4 - wMod; - debug(2, "RPZA corrected width: %d", width); - _surface = new Graphics::Surface(); - _surface->create(width, height, _pixelFormat); + _surface->create(width, height, getPixelFormat()); } RPZADecoder::~RPZADecoder() { @@ -59,18 +54,11 @@ RPZADecoder::~RPZADecoder() { } \ totalBlocks--; \ if (totalBlocks < 0) \ - error("block counter just went negative (this should not happen)") \ + error("rpza block counter just went negative (this should not happen)") \ -// Convert from RGB555 to the format specified by the screen #define PUT_PIXEL(color) \ - if ((int32)blockPtr < _surface->w * _surface->h) { \ - byte r = 0, g = 0, b = 0; \ - Graphics::colorToRGB<Graphics::ColorMasks<555> >(color, r, g, b); \ - if (_pixelFormat.bytesPerPixel == 2) \ - *((uint16 *)_surface->pixels + blockPtr) = _pixelFormat.RGBToColor(r, g, b); \ - else \ - *((uint32 *)_surface->pixels + blockPtr) = _pixelFormat.RGBToColor(r, g, b); \ - } \ + if ((int32)blockPtr < _surface->w * _surface->h) \ + WRITE_UINT16((uint16 *)_surface->pixels + blockPtr, color); \ blockPtr++ const Graphics::Surface *RPZADecoder::decodeImage(Common::SeekableReadStream *stream) { diff --git a/video/codecs/rpza.h b/video/codecs/rpza.h index 809a69f444..f082d25549 100644 --- a/video/codecs/rpza.h +++ b/video/codecs/rpza.h @@ -34,11 +34,10 @@ public: ~RPZADecoder(); const Graphics::Surface *decodeImage(Common::SeekableReadStream *stream); - Graphics::PixelFormat getPixelFormat() const { return _pixelFormat; } + Graphics::PixelFormat getPixelFormat() const { return Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0); } private: Graphics::Surface *_surface; - Graphics::PixelFormat _pixelFormat; }; } // End of namespace Video diff --git a/video/coktel_decoder.cpp b/video/coktel_decoder.cpp index be36874db4..0c7ade1b8a 100644 --- a/video/coktel_decoder.cpp +++ b/video/coktel_decoder.cpp @@ -646,6 +646,21 @@ PreIMDDecoder::~PreIMDDecoder() { close(); } +bool PreIMDDecoder::reloadStream(Common::SeekableReadStream *stream) { + if (!_stream) + return false; + + if (!stream->seek(_stream->pos())) { + close(); + return false; + } + + delete _stream; + _stream = stream; + + return true; +} + bool PreIMDDecoder::seek(int32 frame, int whence, bool restart) { if (!evaluateSeekFrame(frame, whence)) return false; @@ -840,6 +855,21 @@ IMDDecoder::~IMDDecoder() { close(); } +bool IMDDecoder::reloadStream(Common::SeekableReadStream *stream) { + if (!_stream) + return false; + + if (!stream->seek(_stream->pos())) { + close(); + return false; + } + + delete _stream; + _stream = stream; + + return true; +} + bool IMDDecoder::seek(int32 frame, int whence, bool restart) { if (!evaluateSeekFrame(frame, whence)) return false; @@ -1536,6 +1566,21 @@ VMDDecoder::~VMDDecoder() { close(); } +bool VMDDecoder::reloadStream(Common::SeekableReadStream *stream) { + if (!_stream) + return false; + + if (!stream->seek(_stream->pos())) { + close(); + return false; + } + + delete _stream; + _stream = stream; + + return true; +} + bool VMDDecoder::seek(int32 frame, int whence, bool restart) { if (!evaluateSeekFrame(frame, whence)) return false; diff --git a/video/coktel_decoder.h b/video/coktel_decoder.h index 68696d5ff3..c88d982191 100644 --- a/video/coktel_decoder.h +++ b/video/coktel_decoder.h @@ -79,6 +79,9 @@ public: Audio::Mixer::SoundType soundType = Audio::Mixer::kPlainSoundType); ~CoktelDecoder(); + /** Replace the current video stream with this identical one. */ + virtual bool reloadStream(Common::SeekableReadStream *stream) = 0; + virtual bool seek(int32 frame, int whence = SEEK_SET, bool restart = false) = 0; /** Draw directly onto the specified video memory. */ @@ -237,6 +240,8 @@ public: Audio::Mixer::SoundType soundType = Audio::Mixer::kPlainSoundType); ~PreIMDDecoder(); + bool reloadStream(Common::SeekableReadStream *stream); + bool seek(int32 frame, int whence = SEEK_SET, bool restart = false); @@ -268,6 +273,8 @@ public: IMDDecoder(Audio::Mixer *mixer, Audio::Mixer::SoundType soundType = Audio::Mixer::kPlainSoundType); ~IMDDecoder(); + bool reloadStream(Common::SeekableReadStream *stream); + bool seek(int32 frame, int whence = SEEK_SET, bool restart = false); void setXY(uint16 x, uint16 y); @@ -364,6 +371,8 @@ public: VMDDecoder(Audio::Mixer *mixer, Audio::Mixer::SoundType soundType = Audio::Mixer::kPlainSoundType); ~VMDDecoder(); + bool reloadStream(Common::SeekableReadStream *stream); + bool seek(int32 frame, int whence = SEEK_SET, bool restart = false); void setXY(uint16 x, uint16 y); |