diff options
author | Matthew Hoops | 2011-02-13 17:22:07 -0500 |
---|---|---|
committer | Matthew Hoops | 2011-02-13 17:29:15 -0500 |
commit | dbc6910eae6a174fbab08a39a7e5e0fcfb135793 (patch) | |
tree | 135a0f772665db024d96cf2b29c748afe29e8750 | |
parent | a5b198b23337e3b4f44dabefccb9f097b37b3198 (diff) | |
download | scummvm-rg350-dbc6910eae6a174fbab08a39a7e5e0fcfb135793.tar.gz scummvm-rg350-dbc6910eae6a174fbab08a39a7e5e0fcfb135793.tar.bz2 scummvm-rg350-dbc6910eae6a174fbab08a39a7e5e0fcfb135793.zip |
SCI: Add support for Phantasmagoria 2 CLUT resources
My test of ising the clut associated with the intro video produced a decent quality color conversion. This is not yet hooked up to the video player.
-rw-r--r-- | engines/sci/graphics/palette.cpp | 61 | ||||
-rw-r--r-- | engines/sci/graphics/palette.h | 10 |
2 files changed, 71 insertions, 0 deletions
diff --git a/engines/sci/graphics/palette.cpp b/engines/sci/graphics/palette.cpp index 616ee841c1..b27b5f35a7 100644 --- a/engines/sci/graphics/palette.cpp +++ b/engines/sci/graphics/palette.cpp @@ -69,11 +69,19 @@ GfxPalette::GfxPalette(ResourceManager *resMan, GfxScreen *screen, bool useMergi _useMerging = useMerging; palVaryInit(); + +#ifdef ENABLE_SCI32 + _clutTable = 0; +#endif } GfxPalette::~GfxPalette() { if (_palVaryResourceId != -1) palVaryRemoveTimer(); + +#ifdef ENABLE_SCI32 + unloadClut(); +#endif } bool GfxPalette::isMerging() { @@ -787,4 +795,57 @@ void GfxPalette::palVaryProcess(int signal, bool setPalette) { } } +#ifdef ENABLE_SCI32 + +bool GfxPalette::loadClut(uint16 clutId) { + // loadClut() will load a color lookup table from a clu file and set + // the palette found in the file. This is to be used with Phantasmagoria 2. + + unloadClut(); + + Common::String filename = Common::String::format("%d.clu", clutId); + Common::File clut; + + if (!clut.open(filename) || clut.size() != 0x10000 + 236 * 3) + return false; + + // Read in the lookup table + // It maps each RGB565 color to a palette index + _clutTable = new byte[0x10000]; + clut.read(_clutTable, 0x10000); + + Palette pal; + memset(&pal, 0, sizeof(Palette)); + + // Setup 1:1 mapping + for (int i = 0; i < 256; i++) + pal.mapping[i] = i; + + // Now load in the palette + for (int i = 1; i <= 236; i++) { + pal.colors[i].used = 1; + pal.colors[i].r = clut.readByte(); + pal.colors[i].g = clut.readByte(); + pal.colors[i].b = clut.readByte(); + } + + set(&pal, true); + setOnScreen(); + return true; +} + +byte GfxPalette::matchClutColor(uint16 color) { + // Match a color in RGB565 format to a palette index based on the loaded CLUT + assert(_clutTable); + return _clutTable[color]; +} + +void GfxPalette::unloadClut() { + // This will only unload the actual table, but not reset any palette + delete[] _clutTable; + _clutTable = 0; +} + +#endif + } // End of namespace Sci diff --git a/engines/sci/graphics/palette.h b/engines/sci/graphics/palette.h index 879bbcfd9c..84334a4a61 100644 --- a/engines/sci/graphics/palette.h +++ b/engines/sci/graphics/palette.h @@ -88,6 +88,12 @@ public: virtual void saveLoadWithSerializer(Common::Serializer &s); void palVarySaveLoadPalette(Common::Serializer &s, Palette *palette); +#ifdef ENABLE_SCI32 + bool loadClut(uint16 clutId); + byte matchClutColor(uint16 color); + void unloadClut(); +#endif + private: void palVaryInit(); void palVaryInstallTimer(); @@ -113,6 +119,10 @@ private: uint16 _palVaryTicks; int _palVaryPaused; int _palVarySignal; + +#ifdef ENABLE_SCI32 + byte *_clutTable; +#endif }; } // End of namespace Sci |