diff options
author | Colin Snover | 2017-02-24 12:15:57 -0600 |
---|---|---|
committer | Colin Snover | 2017-04-22 13:01:37 -0500 |
commit | e504efe4da62b3d2e32ffb895b935080be02aed4 (patch) | |
tree | eb8b452309c90ad667039599d743a80bd50cd2fd /engines/sci | |
parent | 399551af09420e0b97ce4ee82d0bf368964e1333 (diff) | |
download | scummvm-rg350-e504efe4da62b3d2e32ffb895b935080be02aed4.tar.gz scummvm-rg350-e504efe4da62b3d2e32ffb895b935080be02aed4.tar.bz2 scummvm-rg350-e504efe4da62b3d2e32ffb895b935080be02aed4.zip |
SCI32: Add palette code for late SCI2.1mid+ games
Sometime during SCI2.1mid, the palette manager was changed to
save and restore the source palette, and to add in-game gamma
correction. Previously, only the vary start and target palettes
were saved, and gamma correction was only configurable in SSCI by
editing RESOURCE.CFG.
Diffstat (limited to 'engines/sci')
-rw-r--r-- | engines/sci/engine/features.h | 12 | ||||
-rw-r--r-- | engines/sci/engine/kgraphics32.cpp | 12 | ||||
-rw-r--r-- | engines/sci/engine/savegame.cpp | 12 | ||||
-rw-r--r-- | engines/sci/engine/savegame.h | 3 | ||||
-rw-r--r-- | engines/sci/graphics/palette32.cpp | 236 | ||||
-rw-r--r-- | engines/sci/graphics/palette32.h | 31 | ||||
-rw-r--r-- | engines/sci/graphics/remap32.cpp | 2 |
7 files changed, 280 insertions, 28 deletions
diff --git a/engines/sci/engine/features.h b/engines/sci/engine/features.h index 044111a43e..6d9460d61e 100644 --- a/engines/sci/engine/features.h +++ b/engines/sci/engine/features.h @@ -124,10 +124,20 @@ public: gid != GID_MOTHERGOOSEHIRES; } - inline bool hasNewPaletteCode() const { + inline bool hasMidPaletteCode() const { return getSciVersion() >= SCI_VERSION_2_1_MIDDLE || g_sci->getGameId() == GID_KQ7; } + inline bool hasLatePaletteCode() const { + return getSciVersion() > SCI_VERSION_2_1_MIDDLE || + g_sci->getGameId() == GID_GK2 || + g_sci->getGameId() == GID_PQSWAT || + // Guessing that Shivers has the late palette code because it has a + // brightness slider + g_sci->getGameId() == GID_SHIVERS || + g_sci->getGameId() == GID_TORIN; + } + inline bool VMDOpenStopsAudio() const { // Of the games that use VMDs: // Yes: Phant1, Shivers, Torin diff --git a/engines/sci/engine/kgraphics32.cpp b/engines/sci/engine/kgraphics32.cpp index 07a63c73d9..ae84e6b8a5 100644 --- a/engines/sci/engine/kgraphics32.cpp +++ b/engines/sci/engine/kgraphics32.cpp @@ -934,16 +934,8 @@ reg_t kPaletteFindColor32(EngineState *s, int argc, reg_t *argv) { return make_reg(0, g_sci->_gfxPalette32->matchColor(r, g, b)); } -/* - * Used starting in Shivers 1. SCI3 contains 6 gamma look-up tables, with the - * first table (gamma = 0) being the default one. - */ reg_t kPaletteSetGamma(EngineState *s, int argc, reg_t *argv) { - const uint8 gamma = argv[0].toUint16(); - assert(gamma <= 6); - - warning("TODO: kPaletteSetGamma(%d)", gamma); - + g_sci->_gfxPalette32->setGamma(argv[0].toSint16()); return s->r_acc; } @@ -962,7 +954,7 @@ reg_t kPalVarySetVary(EngineState *s, int argc, reg_t *argv) { int16 fromColor; int16 toColor; - if (g_sci->_features->hasNewPaletteCode() && argc > 4) { + if (g_sci->_features->hasMidPaletteCode() && argc > 4) { fromColor = argv[3].toSint16(); toColor = argv[4].toSint16(); } else { diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index e6a6af7d17..04715d6034 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -865,10 +865,18 @@ void GfxPalette32::saveLoadWithSerializer(Common::Serializer &s) { s.syncAsByte(_cycleMap[i]); } + if (g_sci->_features->hasLatePaletteCode() && s.getVersion() >= 41) { + s.syncAsSint16LE(_gammaLevel); + saveLoadPalette32(s, &_sourcePalette); + ++_version; + _needsUpdate = true; + _gammaChanged = true; + } + saveLoadOptionalPalette32(s, &_varyTargetPalette); saveLoadOptionalPalette32(s, &_varyStartPalette); - // NOTE: _sourcePalette and _nextPalette are not saved - // by SCI engine + + // _nextPalette is not saved by SSCI for (int i = 0; i < ARRAYSIZE(_cyclers); ++i) { PalCycler *cycler = nullptr; diff --git a/engines/sci/engine/savegame.h b/engines/sci/engine/savegame.h index 274df25dc2..72982469e0 100644 --- a/engines/sci/engine/savegame.h +++ b/engines/sci/engine/savegame.h @@ -37,6 +37,7 @@ struct EngineState; * * Version - new/changed feature * ============================= + * 41 - palette support for newer SCI2.1 games * 40 - always store palvary variables * 39 - Accurate SCI32 arrays/strings, score metadata, avatar metadata * 38 - SCI32 cursor @@ -65,7 +66,7 @@ struct EngineState; */ enum { - CURRENT_SAVEGAME_VERSION = 40, + CURRENT_SAVEGAME_VERSION = 41, MINIMUM_SAVEGAME_VERSION = 14 }; diff --git a/engines/sci/graphics/palette32.cpp b/engines/sci/graphics/palette32.cpp index febb6820d0..d13ae2c097 100644 --- a/engines/sci/graphics/palette32.cpp +++ b/engines/sci/graphics/palette32.cpp @@ -122,9 +122,212 @@ const Palette HunkPalette::toPalette() const { } #pragma mark - +#pragma mark Gamma correction tables + +static const uint8 gammaTables[GfxPalette32::numGammaTables][256] = { + { 0, 2, 3, 5, 6, 7, 9, 10, + 11, 13, 14, 15, 16, 18, 19, 20, + 21, 22, 23, 25, 26, 27, 28, 29, + 30, 32, 33, 34, 35, 36, 37, 38, + 39, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 54, 55, 56, + 57, 58, 59, 60, 61, 62, 63, 64, + 65, 66, 67, 68, 69, 70, 71, 72, + 74, 75, 76, 77, 78, 79, 80, 81, + 82, 83, 84, 85, 86, 87, 88, 89, + 90, 91, 92, 93, 94, 95, 96, 97, + 98, 99, 100, 101, 102, 103, 104, 105, + 106, 107, 108, 109, 110, 111, 112, 113, + 114, 115, 116, 117, 118, 119, 120, 121, + 122, 123, 124, 125, 126, 127, 128, 128, + 129, 130, 131, 132, 133, 134, 135, 136, + 137, 138, 139, 140, 141, 142, 143, 144, + 145, 146, 147, 148, 149, 150, 151, 152, + 153, 153, 154, 155, 156, 157, 158, 159, + 160, 161, 162, 163, 164, 165, 166, 167, + 168, 169, 170, 171, 171, 172, 173, 174, + 175, 176, 177, 178, 179, 180, 181, 182, + 183, 184, 185, 186, 186, 187, 188, 189, + 190, 191, 192, 193, 194, 195, 196, 197, + 198, 199, 199, 200, 201, 202, 203, 204, + 205, 206, 207, 208, 209, 210, 211, 211, + 212, 213, 214, 215, 216, 217, 218, 219, + 220, 221, 222, 222, 223, 224, 225, 226, + 227, 228, 229, 230, 231, 232, 232, 233, + 234, 235, 236, 237, 238, 239, 240, 241, + 242, 242, 243, 244, 245, 246, 247, 248, + 249, 250, 251, 251, 252, 253, 254, 255 }, + + { 0, 3, 5, 6, 8, 10, 11, 13, + 14, 16, 17, 19, 20, 22, 23, 24, + 26, 27, 28, 30, 31, 32, 33, 35, + 36, 37, 38, 40, 41, 42, 43, 44, + 46, 47, 48, 49, 50, 51, 53, 54, + 55, 56, 57, 58, 59, 60, 62, 63, + 64, 65, 66, 67, 68, 69, 70, 71, + 73, 74, 75, 76, 77, 78, 79, 80, + 81, 82, 83, 84, 85, 86, 87, 88, + 89, 90, 91, 92, 93, 94, 95, 96, + 97, 99, 100, 101, 102, 103, 104, 105, + 106, 107, 108, 108, 109, 110, 111, 112, + 113, 114, 115, 116, 117, 118, 119, 120, + 121, 122, 123, 124, 125, 126, 127, 128, + 129, 130, 131, 132, 133, 134, 135, 136, + 136, 137, 138, 139, 140, 141, 142, 143, + 144, 145, 146, 147, 148, 149, 150, 151, + 151, 152, 153, 154, 155, 156, 157, 158, + 159, 160, 161, 162, 162, 163, 164, 165, + 166, 167, 168, 169, 170, 171, 172, 172, + 173, 174, 175, 176, 177, 178, 179, 180, + 180, 181, 182, 183, 184, 185, 186, 187, + 188, 188, 189, 190, 191, 192, 193, 194, + 195, 196, 196, 197, 198, 199, 200, 201, + 202, 202, 203, 204, 205, 206, 207, 208, + 209, 209, 210, 211, 212, 213, 214, 215, + 215, 216, 217, 218, 219, 220, 221, 221, + 222, 223, 224, 225, 226, 227, 227, 228, + 229, 230, 231, 232, 233, 233, 234, 235, + 236, 237, 238, 238, 239, 240, 241, 242, + 243, 243, 244, 245, 246, 247, 248, 249, + 249, 250, 251, 252, 253, 254, 254, 255 }, + + { 0, 4, 6, 8, 10, 12, 14, 16, + 18, 19, 21, 23, 24, 26, 27, 29, + 30, 32, 33, 35, 36, 37, 39, 40, + 41, 43, 44, 45, 47, 48, 49, 50, + 52, 53, 54, 55, 57, 58, 59, 60, + 61, 62, 64, 65, 66, 67, 68, 69, + 71, 72, 73, 74, 75, 76, 77, 78, + 79, 81, 82, 83, 84, 85, 86, 87, + 88, 89, 90, 91, 92, 93, 94, 95, + 96, 97, 98, 99, 100, 102, 103, 104, + 105, 106, 107, 108, 109, 110, 111, 112, + 112, 113, 114, 115, 116, 117, 118, 119, + 120, 121, 122, 123, 124, 125, 126, 127, + 128, 129, 130, 131, 132, 133, 134, 135, + 135, 136, 137, 138, 139, 140, 141, 142, + 143, 144, 145, 146, 146, 147, 148, 149, + 150, 151, 152, 153, 154, 155, 156, 156, + 157, 158, 159, 160, 161, 162, 163, 163, + 164, 165, 166, 167, 168, 169, 170, 170, + 171, 172, 173, 174, 175, 176, 177, 177, + 178, 179, 180, 181, 182, 183, 183, 184, + 185, 186, 187, 188, 188, 189, 190, 191, + 192, 193, 194, 194, 195, 196, 197, 198, + 199, 199, 200, 201, 202, 203, 203, 204, + 205, 206, 207, 208, 208, 209, 210, 211, + 212, 212, 213, 214, 215, 216, 217, 217, + 218, 219, 220, 221, 221, 222, 223, 224, + 225, 225, 226, 227, 228, 229, 229, 230, + 231, 232, 233, 233, 234, 235, 236, 237, + 237, 238, 239, 240, 240, 241, 242, 243, + 244, 244, 245, 246, 247, 247, 248, 249, + 250, 251, 251, 252, 253, 254, 254, 255 }, + + { 0, 5, 9, 11, 14, 16, 19, 21, + 23, 25, 26, 28, 30, 32, 33, 35, + 37, 38, 40, 41, 43, 44, 46, 47, + 49, 50, 52, 53, 54, 56, 57, 58, + 60, 61, 62, 64, 65, 66, 67, 69, + 70, 71, 72, 73, 75, 76, 77, 78, + 79, 80, 82, 83, 84, 85, 86, 87, + 88, 89, 91, 92, 93, 94, 95, 96, + 97, 98, 99, 100, 101, 102, 103, 104, + 105, 106, 107, 108, 109, 110, 111, 112, + 113, 114, 115, 116, 117, 118, 119, 120, + 121, 122, 123, 124, 125, 126, 127, 128, + 129, 130, 131, 132, 133, 134, 134, 135, + 136, 137, 138, 139, 140, 141, 142, 143, + 144, 144, 145, 146, 147, 148, 149, 150, + 151, 152, 152, 153, 154, 155, 156, 157, + 158, 158, 159, 160, 161, 162, 163, 164, + 164, 165, 166, 167, 168, 169, 169, 170, + 171, 172, 173, 174, 174, 175, 176, 177, + 178, 179, 179, 180, 181, 182, 183, 183, + 184, 185, 186, 187, 187, 188, 189, 190, + 191, 191, 192, 193, 194, 195, 195, 196, + 197, 198, 199, 199, 200, 201, 202, 202, + 203, 204, 205, 205, 206, 207, 208, 209, + 209, 210, 211, 212, 212, 213, 214, 215, + 215, 216, 217, 218, 218, 219, 220, 221, + 221, 222, 223, 224, 224, 225, 226, 227, + 227, 228, 229, 230, 230, 231, 232, 232, + 233, 234, 235, 235, 236, 237, 238, 238, + 239, 240, 240, 241, 242, 243, 243, 244, + 245, 245, 246, 247, 248, 248, 249, 250, + 250, 251, 252, 252, 253, 254, 255, 255 }, + + { 0, 9, 14, 18, 21, 24, 27, 29, + 32, 34, 37, 39, 41, 43, 45, 47, + 48, 50, 52, 54, 55, 57, 59, 60, + 62, 63, 65, 66, 68, 69, 71, 72, + 73, 75, 76, 77, 79, 80, 81, 83, + 84, 85, 86, 88, 89, 90, 91, 92, + 94, 95, 96, 97, 98, 99, 100, 102, + 103, 104, 105, 106, 107, 108, 109, 110, + 111, 112, 113, 114, 115, 116, 117, 118, + 119, 120, 121, 122, 123, 124, 125, 126, + 127, 128, 129, 130, 131, 132, 133, 134, + 135, 136, 137, 137, 138, 139, 140, 141, + 142, 143, 144, 145, 145, 146, 147, 148, + 149, 150, 151, 151, 152, 153, 154, 155, + 156, 156, 157, 158, 159, 160, 161, 161, + 162, 163, 164, 165, 165, 166, 167, 168, + 169, 169, 170, 171, 172, 173, 173, 174, + 175, 176, 176, 177, 178, 179, 179, 180, + 181, 182, 182, 183, 184, 185, 185, 186, + 187, 188, 188, 189, 190, 191, 191, 192, + 193, 194, 194, 195, 196, 196, 197, 198, + 199, 199, 200, 201, 201, 202, 203, 203, + 204, 205, 206, 206, 207, 208, 208, 209, + 210, 210, 211, 212, 212, 213, 214, 214, + 215, 216, 216, 217, 218, 218, 219, 220, + 220, 221, 222, 222, 223, 224, 224, 225, + 226, 226, 227, 228, 228, 229, 230, 230, + 231, 231, 232, 233, 233, 234, 235, 235, + 236, 237, 237, 238, 238, 239, 240, 240, + 241, 242, 242, 243, 243, 244, 245, 245, + 246, 247, 247, 248, 248, 249, 250, 250, + 251, 251, 252, 253, 253, 254, 254, 255 }, + + { 0, 16, 23, 28, 32, 36, 39, 42, + 45, 48, 50, 53, 55, 58, 60, 62, + 64, 66, 68, 70, 71, 73, 75, 77, + 78, 80, 81, 83, 84, 86, 87, 89, + 90, 92, 93, 94, 96, 97, 98, 100, + 101, 102, 103, 105, 106, 107, 108, 109, + 111, 112, 113, 114, 115, 116, 117, 118, + 119, 121, 122, 123, 124, 125, 126, 127, + 128, 129, 130, 131, 132, 133, 134, 135, + 135, 136, 137, 138, 139, 140, 141, 142, + 143, 144, 145, 145, 146, 147, 148, 149, + 150, 151, 151, 152, 153, 154, 155, 156, + 156, 157, 158, 159, 160, 160, 161, 162, + 163, 164, 164, 165, 166, 167, 167, 168, + 169, 170, 170, 171, 172, 173, 173, 174, + 175, 176, 176, 177, 178, 179, 179, 180, + 181, 181, 182, 183, 183, 184, 185, 186, + 186, 187, 188, 188, 189, 190, 190, 191, + 192, 192, 193, 194, 194, 195, 196, 196, + 197, 198, 198, 199, 199, 200, 201, 201, + 202, 203, 203, 204, 204, 205, 206, 206, + 207, 208, 208, 209, 209, 210, 211, 211, + 212, 212, 213, 214, 214, 215, 215, 216, + 217, 217, 218, 218, 219, 220, 220, 221, + 221, 222, 222, 223, 224, 224, 225, 225, + 226, 226, 227, 228, 228, 229, 229, 230, + 230, 231, 231, 232, 233, 233, 234, 234, + 235, 235, 236, 236, 237, 237, 238, 238, + 239, 240, 240, 241, 241, 242, 242, 243, + 243, 244, 244, 245, 245, 246, 246, 247, + 247, 248, 248, 249, 249, 250, 250, 251, + 251, 252, 252, 253, 253, 254, 254, 255 } +}; + +#pragma mark - #pragma mark GfxPalette32 -GfxPalette32::GfxPalette32(ResourceManager *resMan) + GfxPalette32::GfxPalette32(ResourceManager *resMan) : _resMan(resMan), // Palette versioning @@ -147,7 +350,12 @@ GfxPalette32::GfxPalette32(ResourceManager *resMan) // Palette cycling _cyclers(), - _cycleMap() { + _cycleMap(), + + // Gamma correction + _gammaLevel(-1), + _gammaChanged(false) { + _varyPercent = _varyTargetPercent; for (int i = 0, len = ARRAYSIZE(_fadeTable); i < len; ++i) { _fadeTable[i] = 100; @@ -248,7 +456,7 @@ void GfxPalette32::updateFFrame() { } void GfxPalette32::updateHardware(const bool updateScreen) { - if (_currentPalette == _nextPalette) { + if (_currentPalette == _nextPalette && !_gammaChanged) { return; } @@ -257,21 +465,21 @@ void GfxPalette32::updateHardware(const bool updateScreen) { for (int i = 0; i < ARRAYSIZE(_currentPalette.colors) - 1; ++i) { _currentPalette.colors[i] = _nextPalette.colors[i]; - // NOTE: If the brightness option in the user configuration file is set, - // SCI engine adjusts palette brightnesses here by mapping RGB values to - // values in some hard-coded brightness tables. There is no reason on - // modern hardware to implement this, unless it is discovered that some - // game uses a non-standard brightness setting by default - // All color entries MUST be copied, not just "used" entries, otherwise // uninitialised memory from bpal makes its way into the system palette. // This would not normally be a problem, except that games sometimes use // unused palette entries. e.g. Phant1 title screen references palette // entries outside its own palette, so will render garbage colors where // the game expects them to be black - bpal[i * 3 ] = _currentPalette.colors[i].r; - bpal[i * 3 + 1] = _currentPalette.colors[i].g; - bpal[i * 3 + 2] = _currentPalette.colors[i].b; + if (_gammaLevel == -1) { + bpal[i * 3 ] = _currentPalette.colors[i].r; + bpal[i * 3 + 1] = _currentPalette.colors[i].g; + bpal[i * 3 + 2] = _currentPalette.colors[i].b; + } else { + bpal[i * 3 ] = gammaTables[_gammaLevel][_currentPalette.colors[i].r]; + bpal[i * 3 + 1] = gammaTables[_gammaLevel][_currentPalette.colors[i].g]; + bpal[i * 3 + 2] = gammaTables[_gammaLevel][_currentPalette.colors[i].b]; + } } if (g_sci->getPlatform() != Common::kPlatformMacintosh) { @@ -289,6 +497,8 @@ void GfxPalette32::updateHardware(const bool updateScreen) { if (updateScreen) { g_system->updateScreen(); } + + _gammaChanged = false; } Palette GfxPalette32::getPaletteFromResource(const GuiResourceId resourceId) const { @@ -560,7 +770,7 @@ void GfxPalette32::setCycle(const uint8 fromColor, const uint8 toColor, const in } uint16 numColorsToCycle = toColor - fromColor; - if (g_sci->_features->hasNewPaletteCode()) { + if (g_sci->_features->hasMidPaletteCode()) { numColorsToCycle += 1; } cycler->fromColor = fromColor; diff --git a/engines/sci/graphics/palette32.h b/engines/sci/graphics/palette32.h index d6d7d0dbd1..267ec39d96 100644 --- a/engines/sci/graphics/palette32.h +++ b/engines/sci/graphics/palette32.h @@ -572,6 +572,37 @@ private: * The intensity levels of each palette entry, in percent. Defaults to 100. */ uint16 _fadeTable[256]; + +#pragma mark - +#pragma mark Gamma correction +public: + enum { + /** + * The number of available gamma corrections. + */ + numGammaTables = 6 + }; + + /** + * Sets the gamma correction level, from 0 (off) to `numGammaTables`, + * inclusive. + */ + void setGamma(const int16 level) { + _gammaLevel = CLIP<int16>(level, 0, numGammaTables) - 1; + _gammaChanged = true; + } + +private: + /** + * The current gamma correction level. -1 means no correction. + */ + int8 _gammaLevel; + + /** + * Whether the gamma correction has changed since the last call to update + * the hardware palette. + */ + bool _gammaChanged; }; } // End of namespace Sci diff --git a/engines/sci/graphics/remap32.cpp b/engines/sci/graphics/remap32.cpp index 768594f974..9b5ffcd2f7 100644 --- a/engines/sci/graphics/remap32.cpp +++ b/engines/sci/graphics/remap32.cpp @@ -301,7 +301,7 @@ GfxRemap32::GfxRemap32() : // match the highest possible value of `_remapStartColor` assert(_remapStartColor == 236); - if (g_sci->_features->hasNewPaletteCode()) { + if (g_sci->_features->hasMidPaletteCode()) { _remaps.resize(9); } else { _remaps.resize(19); |