From 1c4d0d87ecde1fdea1cf1473da3665605d956657 Mon Sep 17 00:00:00 2001 From: Le Philousophe Date: Mon, 20 May 2019 20:49:01 +0200 Subject: CRYOMNI3D: Use existing palette to init video one This is useful when there will be hooks on video plays which use a palette entry not defined in video --- engines/cryomni3d/cryomni3d.cpp | 6 +++++- engines/cryomni3d/video/hnm_decoder.cpp | 18 +++++++++++++----- engines/cryomni3d/video/hnm_decoder.h | 5 +++-- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/engines/cryomni3d/cryomni3d.cpp b/engines/cryomni3d/cryomni3d.cpp index ae05778681..473fc7cce6 100644 --- a/engines/cryomni3d/cryomni3d.cpp +++ b/engines/cryomni3d/cryomni3d.cpp @@ -118,7 +118,11 @@ void CryOmni3DEngine::playHNM(const Common::String &filename, Audio::Mixer::Soun const char *const extensions[] = { "hns", "hnm", nullptr }; Common::String fname(prepareFileName(filename, extensions)); - Video::VideoDecoder *videoDecoder = new Video::HNMDecoder(); + byte *currentPalette = new byte[256 * 3]; + g_system->getPaletteManager()->grabPalette(currentPalette, 0, 256); + + // Pass the ownership of currentPalette to HNMDecoder + Video::VideoDecoder *videoDecoder = new Video::HNMDecoder(false, currentPalette); videoDecoder->setSoundType(soundType); if (!videoDecoder->loadFile(fname)) { diff --git a/engines/cryomni3d/video/hnm_decoder.cpp b/engines/cryomni3d/video/hnm_decoder.cpp index 355345beaa..0451828f0c 100644 --- a/engines/cryomni3d/video/hnm_decoder.cpp +++ b/engines/cryomni3d/video/hnm_decoder.cpp @@ -35,13 +35,16 @@ namespace Video { // When no sound display a frame every 80ms -HNMDecoder::HNMDecoder(bool loop) : _regularFrameDelay(80), _videoTrack(nullptr), - _audioTrack(nullptr), _stream(nullptr), _loop(loop) { +HNMDecoder::HNMDecoder(bool loop, byte *initialPalette) : _regularFrameDelay(80), + _videoTrack(nullptr), _audioTrack(nullptr), _stream(nullptr), + _loop(loop), _initialPalette(initialPalette) { } HNMDecoder::~HNMDecoder() { close(); + delete[] _initialPalette; + // We don't deallocate _videoTrack and _audioTrack as they are owned by base class } @@ -79,7 +82,7 @@ bool HNMDecoder::loadStream(Common::SeekableReadStream *stream) { frameCount = 0; } - _videoTrack = new HNM4VideoTrack(width, height, frameSize, frameCount, _regularFrameDelay); + _videoTrack = new HNM4VideoTrack(width, height, frameSize, frameCount, _regularFrameDelay, _initialPalette); if (soundBits != 0 && soundChannels != 0) { // HNM4 is 22050Hz _audioTrack = new DPCMAudioTrack(soundChannels, soundBits, 22050, getSoundType()); @@ -149,13 +152,18 @@ void HNMDecoder::readNextPacket() { } HNMDecoder::HNM4VideoTrack::HNM4VideoTrack(uint32 width, uint32 height, uint32 frameSize, - uint32 frameCount, uint32 regularFrameDelay) : + uint32 frameCount, uint32 regularFrameDelay, const byte *initialPalette) : _frameCount(frameCount), _regularFrameDelay(regularFrameDelay), _nextFrameStartTime(0) { restart(); _curFrame = -1; - memset(_palette, 0, 256 * 3); + // Get the currently loaded palette for undefined colors + if (initialPalette) { + memcpy(_palette, initialPalette, 256 * 3); + } else { + memset(_palette, 0, 256 * 3); + } if (width * height != frameSize) { error("Invalid frameSize"); diff --git a/engines/cryomni3d/video/hnm_decoder.h b/engines/cryomni3d/video/hnm_decoder.h index b09026b674..c5d9307bb7 100644 --- a/engines/cryomni3d/video/hnm_decoder.h +++ b/engines/cryomni3d/video/hnm_decoder.h @@ -43,7 +43,7 @@ namespace Video { */ class HNMDecoder : public VideoDecoder { public: - HNMDecoder(bool loop = false); + HNMDecoder(bool loop = false, byte *initialPalette = nullptr); virtual ~HNMDecoder(); bool loadStream(Common::SeekableReadStream *stream); void readNextPacket(); @@ -55,7 +55,7 @@ private: class HNM4VideoTrack : public VideoTrack { public: HNM4VideoTrack(uint32 width, uint32 height, uint32 frameSize, uint32 frameCount, - uint32 regularFrameDelay); + uint32 regularFrameDelay, const byte *initialPalette = nullptr); ~HNM4VideoTrack(); // When _frameCount is 0, it means we are looping @@ -113,6 +113,7 @@ private: }; bool _loop; + byte *_initialPalette; uint32 _regularFrameDelay; // These two pointer are owned by VideoDecoder -- cgit v1.2.3