From 4702681be2f5a1e3655f01dfb285e653400b3601 Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Sun, 25 Mar 2018 07:37:49 +0200 Subject: IMAGE: Explicitly initialize CinePak codebooks Starship Titanic produces lots of "uninitialized value" warnings at the very beginning of the game, when turning right. This is because in the very first movie frame it uses codebooks that have not been loaded. Explicitly set their data to 0 to guarantee consistent behavior. --- image/codecs/cinepak.cpp | 20 +++++++++++++++++++- image/codecs/cinepak.h | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'image/codecs') diff --git a/image/codecs/cinepak.cpp b/image/codecs/cinepak.cpp index f356e87971..1c477c82d5 100644 --- a/image/codecs/cinepak.cpp +++ b/image/codecs/cinepak.cpp @@ -405,8 +405,13 @@ const Graphics::Surface *CinepakDecoder::decodeFrame(Common::SeekableReadStream _curFrame.height = stream.readUint16BE(); _curFrame.stripCount = stream.readUint16BE(); - if (!_curFrame.strips) + if (!_curFrame.strips) { _curFrame.strips = new CinepakStrip[_curFrame.stripCount]; + for (uint16 i = 0; i < _curFrame.stripCount; i++) { + initializeCodebook(i, 1); + initializeCodebook(i, 4); + } + } debug(4, "Cinepak Frame: Width = %d, Height = %d, Strip Count = %d", _curFrame.width, _curFrame.height, _curFrame.stripCount); @@ -499,6 +504,19 @@ const Graphics::Surface *CinepakDecoder::decodeFrame(Common::SeekableReadStream return _curFrame.surface; } +void CinepakDecoder::initializeCodebook(uint16 strip, byte codebookType) { + CinepakCodebook *codebook = (codebookType == 1) ? _curFrame.strips[strip].v1_codebook : _curFrame.strips[strip].v4_codebook; + + for (uint16 i = 0; i < 256; i++) { + memset(codebook[i].y, 0, 4); + codebook[i].u = 0; + codebook[i].v = 0; + + if (_ditherType == kDitherTypeQT) + ditherCodebookQT(strip, codebookType, i); + } +} + void CinepakDecoder::loadCodebook(Common::SeekableReadStream &stream, uint16 strip, byte codebookType, byte chunkID, uint32 chunkSize) { CinepakCodebook *codebook = (codebookType == 1) ? _curFrame.strips[strip].v1_codebook : _curFrame.strips[strip].v4_codebook; diff --git a/image/codecs/cinepak.h b/image/codecs/cinepak.h index 4efb1191cc..3b0fe477a6 100644 --- a/image/codecs/cinepak.h +++ b/image/codecs/cinepak.h @@ -94,6 +94,7 @@ private: byte *_colorMap; DitherType _ditherType; + void initializeCodebook(uint16 strip, byte codebookType); void loadCodebook(Common::SeekableReadStream &stream, uint16 strip, byte codebookType, byte chunkID, uint32 chunkSize); void decodeVectors(Common::SeekableReadStream &stream, uint16 strip, byte chunkID, uint32 chunkSize); -- cgit v1.2.3