diff --git a/engines/kyra/debugger.cpp b/engines/kyra/debugger.cpp index c06c13c9e8c..d71f7b8b256 100644 --- a/engines/kyra/debugger.cpp +++ b/engines/kyra/debugger.cpp @@ -82,7 +82,7 @@ bool Debugger::cmd_loadPalette(int argc, const char **argv) { _vm->screen()->loadBitmap(argv[1], 5, 5, 0); palette.copy(_vm->screen()->getCPagePtr(5), 0, 256); _vm->screen()->copyBlockToPage(5, 0, 0, 320, 200, buffer); - } else if (!_vm->screen()->loadPalette(argv[1], palette.getData())) { + } else if (!_vm->screen()->loadPalette(argv[1], palette)) { DebugPrintf("ERROR: Palette '%s' not found!\n", argv[1]); return true; } diff --git a/engines/kyra/kyra_lok.cpp b/engines/kyra/kyra_lok.cpp index 6d5c95a55c6..4d3b3e75c13 100644 --- a/engines/kyra/kyra_lok.cpp +++ b/engines/kyra/kyra_lok.cpp @@ -358,7 +358,7 @@ void KyraEngine_LoK::startup() { loadButtonShapes(); initMainButtonList(); loadMainScreen(); - _screen->loadPalette("PALETTE.COL", _screen->getPalette(0).getData()); + _screen->loadPalette("PALETTE.COL", _screen->getPalette(0)); // XXX _animator->initAnimStateList(); diff --git a/engines/kyra/screen.cpp b/engines/kyra/screen.cpp index e12ff98d707..e4f7e05dde1 100644 --- a/engines/kyra/screen.cpp +++ b/engines/kyra/screen.cpp @@ -2785,7 +2785,7 @@ void Screen::loadBitmap(const char *filename, int tempPage, int dstPage, Palette uint16 palSize = READ_LE_UINT16(srcData + 8); if (pal && palSize) - loadPalette(srcData + 10, pal->getData(), palSize); + loadPalette(srcData + 10, *pal, palSize); uint8 *srcPtr = srcData + 10 + palSize; uint8 *dstData = getPagePtr(dstPage); @@ -2819,38 +2819,30 @@ void Screen::loadBitmap(const char *filename, int tempPage, int dstPage, Palette delete[] srcData; } -bool Screen::loadPalette(const char *filename, uint8 *palData) { - uint32 fileSize = 0; - uint8 *srcData = _vm->resource()->fileData(filename, &fileSize); - if (!srcData) +bool Screen::loadPalette(const char *filename, Palette &pal) { + Common::SeekableReadStream *stream = _vm->resource()->createReadStream(filename); + + if (!stream) return false; - if (palData && fileSize) { - loadPalette(srcData, palData, fileSize); - } - delete[] srcData; + debugC(3, kDebugLevelScreen, "Screen::loadPalette('%s', %p)", filename, (const void *)&pal); + + if (_vm->gameFlags().platform == Common::kPlatformAmiga) + pal.loadAmigaPalette(*stream, stream->size() / 2); + else + pal.loadVGAPalette(*stream, stream->size() / 3); + + delete stream; return true; } -void Screen::loadPalette(const byte *data, uint8 *palData, int bytes) { - if (_vm->gameFlags().platform == Common::kPlatformAmiga) { - assert(bytes % 2 == 0); - assert(bytes / 2 <= 256); - bytes >>= 1; - const uint16 *src = (const uint16 *)data; - for (int i = 0; i < bytes; ++i) { - uint16 col = READ_BE_UINT16(src); ++src; - palData[2] = (col & 0xF) << 2; col >>= 4; - palData[1] = (col & 0xF) << 2; col >>= 4; - palData[0] = (col & 0xF) << 2; col >>= 4; - palData += 3; - } - } else if (_use16ColorMode) { - for (int i = 0; i < bytes; ++i) - palData[i] = ((data[i] & 0xF) << 4) | (data[i] & 0xF0); - } else { - memcpy(palData, data, bytes); - } +void Screen::loadPalette(const byte *data, Palette &pal, int bytes) { + Common::MemoryReadStream stream(data, bytes, false); + + if (_vm->gameFlags().platform == Common::kPlatformAmiga) + pal.loadAmigaPalette(stream, stream.size() / 2); + else + pal.loadVGAPalette(stream, stream.size() / 3); } // dirty rect handling diff --git a/engines/kyra/screen.h b/engines/kyra/screen.h index 78725dc5f1c..b35b2dd3af6 100644 --- a/engines/kyra/screen.h +++ b/engines/kyra/screen.h @@ -286,8 +286,8 @@ public: // misc void loadBitmap(const char *filename, int tempPage, int dstPage, Palette *pal, bool skip=false); - bool loadPalette(const char *filename, uint8 *palData); - void loadPalette(const byte *data, uint8 *palData, int bytes); + bool loadPalette(const char *filename, Palette &pal); + void loadPalette(const byte *data, Palette &pal, int bytes); void setAnimBlockPtr(int size); diff --git a/engines/kyra/script_hof.cpp b/engines/kyra/script_hof.cpp index 83c414e131d..c8742376671 100644 --- a/engines/kyra/script_hof.cpp +++ b/engines/kyra/script_hof.cpp @@ -147,7 +147,7 @@ int KyraEngine_HoF::o2_meanWhileScene(EMCState *script) { _screen->loadBitmap(cpsfile, 3, 3, 0); _screen->copyPalette(2, 0); - _screen->loadPalette(palfile, _screen->getPalette(2).getData()); + _screen->loadPalette(palfile, _screen->getPalette(2)); _screen->fillRect(0, 0, 319, 199, 207); _screen->setScreenPalette(_screen->getPalette(2)); _screen->copyRegion(0, 0, 0, 0, 320, 200, 2, 0); @@ -1400,7 +1400,7 @@ int KyraEngine_HoF::o2_demoFinale(EMCState *script) { assert(strings); _screen->clearPage(0); - _screen->loadPalette("THANKS.COL", _screen->getPalette(0).getData()); + _screen->loadPalette("THANKS.COL", _screen->getPalette(0)); _screen->loadBitmap("THANKS.CPS", 3, 3, 0); _screen->copyRegion(0, 0, 0, 0, 320, 200, 2, 0); diff --git a/engines/kyra/script_lol.cpp b/engines/kyra/script_lol.cpp index 2f26c14d43d..03cd7f096a1 100644 --- a/engines/kyra/script_lol.cpp +++ b/engines/kyra/script_lol.cpp @@ -2148,12 +2148,12 @@ int LoLEngine::olol_restoreMagicShroud(EMCState *script) { uint8 *tpal2 = tpal1 + 768; uint8 *tpal3 = tpal2 + 768; uint8 *tpal4 = 0; - _screen->loadPalette("LITEPAL1.COL", tpal1); + _res->loadFileToBuf("LITEPAL1.COL", tpal1, 768); tpal2 = _screen->generateFadeTable(tpal3, 0, tpal1, 21); - _screen->loadPalette("LITEPAL2.COL", tpal2); + _res->loadFileToBuf("LITEPAL2.COL", tpal2, 768); tpal4 = tpal2; tpal2 += 768; - _screen->loadPalette("LITEPAL3.COL", tpal1); + _res->loadFileToBuf("LITEPAL3.COL", tpal1, 768); _screen->generateFadeTable(tpal2, tpal4, tpal1, 4); Palette pal(768); @@ -2309,7 +2309,7 @@ int LoLEngine::tlol_setupPaletteFade(const TIM *tim, const uint16 *param) { int LoLEngine::tlol_loadPalette(const TIM *tim, const uint16 *param) { debugC(3, kDebugLevelScriptFuncs, "LoLEngine::tlol_loadPalette(%p, %p) (%d)", (const void *)tim, (const void *)param, param[0]); const char *palFile = (const char *)(tim->text + READ_LE_UINT16(tim->text + (param[0]<<1))); - _screen->loadPalette(palFile, _screen->getPalette(0).getData()); + _screen->loadPalette(palFile, _screen->getPalette(0)); return 1; } diff --git a/engines/kyra/sequences_hof.cpp b/engines/kyra/sequences_hof.cpp index 9a6f43981e3..75c46185a0e 100644 --- a/engines/kyra/sequences_hof.cpp +++ b/engines/kyra/sequences_hof.cpp @@ -92,7 +92,7 @@ void KyraEngine_HoF::seq_playSequences(int startSeq, int endSeq) { } else { _screen->setCurPage(2); _screen->clearPage(2); - _screen->loadPalette("goldfont.col", _screen->getPalette(0).getData()); + _screen->loadPalette("goldfont.col", _screen->getPalette(0)); } if (cb && !(_flags.isDemo && !_flags.isTalkie)) diff --git a/engines/kyra/sequences_lok.cpp b/engines/kyra/sequences_lok.cpp index 935cff8ac53..1bc512adf52 100644 --- a/engines/kyra/sequences_lok.cpp +++ b/engines/kyra/sequences_lok.cpp @@ -141,7 +141,7 @@ void KyraEngine_LoK::seq_introLogos() { _screen->clearPage(0); if (_flags.platform == Common::kPlatformAmiga) { - _screen->loadPalette("INTRO.PAL", _screen->getPalette(0).getData()); + _screen->loadPalette("INTRO.PAL", _screen->getPalette(0)); _screen->loadBitmap("BOTTOM.CPS", 3, 5, 0); _screen->loadBitmap("TOP.CPS", 3, 3, 0); _screen->copyRegion(0, 0, 0, 111, 320, 64, 2, 0); diff --git a/engines/kyra/sequences_lol.cpp b/engines/kyra/sequences_lol.cpp index 9fb573afab7..b5e909f345d 100644 --- a/engines/kyra/sequences_lol.cpp +++ b/engines/kyra/sequences_lol.cpp @@ -304,7 +304,7 @@ int LoLEngine::chooseCharacter() { _screen->_curPage = 0; if (_flags.use16ColorMode) - _screen->loadPalette("LOL.NOL", _screen->getPalette(0).getData()); + _screen->loadPalette("LOL.NOL", _screen->getPalette(0)); _screen->fadePalette(_screen->getPalette(0), 30, 0); @@ -820,8 +820,7 @@ void LoLEngine::showOutro(int character, bool maxDifficulty) { default: _screen->clearPage(3); - memset(_screen->getPalette(0).getData(), 0, 768); - break; + _screen->getPalette(0).clear(); } _screen->copyRegion(0, 0, 0, 0, 320, 200, 2, 0, Screen::CR_NO_P_CHECK); diff --git a/engines/kyra/sprites.cpp b/engines/kyra/sprites.cpp index 4772ad95bbc..3cc632a3919 100644 --- a/engines/kyra/sprites.cpp +++ b/engines/kyra/sprites.cpp @@ -429,7 +429,7 @@ void Sprites::loadDat(const char *filename, SceneExits &exits) { else _screen->copyPalette(1, 0); - _screen->loadPalette(_dat + 0x17, _screen->getPalette(1).getData() + 684, 60); + _screen->getPalette(1).copy(_dat + 0x17, 0, 20, 228); } uint8 *data = _dat + 0x6B; diff --git a/engines/kyra/wsamovie.cpp b/engines/kyra/wsamovie.cpp index 26851e55308..3320b901192 100644 --- a/engines/kyra/wsamovie.cpp +++ b/engines/kyra/wsamovie.cpp @@ -392,7 +392,7 @@ int WSAMovie_v2::open(const char *filename, int unk1, Palette *palBuf) { offsPal = 0x300; _flags |= WF_HAS_PALETTE; if (palBuf) - _screen->loadPalette(wsaData + 8 + ((_numFrames << 2) & 0xFFFF), palBuf->getData(), 0x300); + _screen->loadPalette(wsaData + 8 + ((_numFrames << 2) & 0xFFFF), *palBuf, 0x300); } if (flags & 2) { @@ -400,7 +400,7 @@ int WSAMovie_v2::open(const char *filename, int unk1, Palette *palBuf) { offsPal = 0x30; _flags |= WF_HAS_PALETTE; if (palBuf) - _screen->loadPalette(wsaData + 8 + ((_numFrames << 2) & 0xFFFF), palBuf->getData(), 0x30); + _screen->loadPalette(wsaData + 8 + ((_numFrames << 2) & 0xFFFF), *palBuf, 0x30); } _flags |= WF_XOR;