diff options
-rw-r--r-- | engines/scumm/he/wiz_he.cpp | 8 | ||||
-rw-r--r-- | engines/scumm/palette.cpp | 13 | ||||
-rw-r--r-- | engines/scumm/scumm.cpp | 5 | ||||
-rw-r--r-- | engines/scumm/scumm.h | 2 |
4 files changed, 24 insertions, 4 deletions
diff --git a/engines/scumm/he/wiz_he.cpp b/engines/scumm/he/wiz_he.cpp index fb1eb28765..3f4967efea 100644 --- a/engines/scumm/he/wiz_he.cpp +++ b/engines/scumm/he/wiz_he.cpp @@ -574,10 +574,10 @@ void Wiz::copyRaw16BitWizImage(uint8 *dst, const uint8 *src, int dstw, int dsth, uint8 r = ((col >> 10) & 0x1F) << 3; uint8 g = ((col >> 5) & 0x1F) << 3; uint8 b = ((col >> 0) & 0x1F) << 3; - col = _vm->remapPaletteColor(r, g, b, -1); + uint8 color = _vm->convert16BitColor(col, r, g, b); if (transColor == -1 || transColor != col) { - dst[i] = palPtr[col]; + dst[i] = palPtr[color]; } } src += srcw * 2; @@ -662,7 +662,7 @@ void Wiz::decompress16BitWizImage(uint8 *dst, int dstPitch, const uint8 *src, co uint8 r = ((col >> 10) & 0x1F) << 3; uint8 g = ((col >> 5) & 0x1F) << 3; uint8 b = ((col >> 0) & 0x1F) << 3; - col = _vm->remapPaletteColor(r, g, b, -1); + col = _vm->convert16BitColor(col, r, g, b); if (type == kWizXMap) { *dstPtr = xmapPtr[col * 256 + *dstPtr]; @@ -696,7 +696,7 @@ void Wiz::decompress16BitWizImage(uint8 *dst, int dstPitch, const uint8 *src, co uint8 r = ((col >> 10) & 0x1F) << 3; uint8 g = ((col >> 5) & 0x1F) << 3; uint8 b = ((col >> 0) & 0x1F) << 3; - col = _vm->remapPaletteColor(r, g, b, -1); + col = _vm->convert16BitColor(col, r, g, b); if (type == kWizXMap) { *dstPtr = xmapPtr[col * 256 + *dstPtr]; diff --git a/engines/scumm/palette.cpp b/engines/scumm/palette.cpp index 4214ab2330..a4ba9b25c4 100644 --- a/engines/scumm/palette.cpp +++ b/engines/scumm/palette.cpp @@ -310,6 +310,9 @@ void ScummEngine::setDirtyColors(int min, int max) { _palDirtyMin = min; if (_palDirtyMax < max) _palDirtyMax = max; + + if (_hePaletteCache) + memset(_hePaletteCache, -1, 65536); } void ScummEngine::initCycl(const byte *ptr) { @@ -810,6 +813,16 @@ void ScummEngine_v8::desaturatePalette(int hueScale, int satScale, int lightScal #endif +int ScummEngine::convert16BitColor(uint16 color, uint8 r, uint8 g, uint8 b) { + // HACK: Find the closest matching color, and store in + // cache for faster access. + if (_hePaletteCache[color] == -1) { + _hePaletteCache[color] = remapPaletteColor(r, g, b, -1); + } + + return _hePaletteCache[color]; +} + int ScummEngine::remapPaletteColor(int r, int g, int b, int threshold) { byte *pal; int ar, ag, ab, i; diff --git a/engines/scumm/scumm.cpp b/engines/scumm/scumm.cpp index aeb1269865..5fe4031de0 100644 --- a/engines/scumm/scumm.cpp +++ b/engines/scumm/scumm.cpp @@ -264,6 +264,7 @@ ScummEngine::ScummEngine(OSystem *syst, const DetectorResult &dr) _palManipPalette = NULL; _palManipIntermediatePal = NULL; memset(gfxUsageBits, 0, sizeof(gfxUsageBits)); + _hePaletteCache = NULL; _hePalettes = NULL; _shadowPalette = NULL; _shadowPaletteSize = 0; @@ -805,6 +806,7 @@ ScummEngine_v90he::~ScummEngine_v90he() { delete _logicHE; } if (_game.heversion >= 99) { + free(_hePaletteCache); free(_hePalettes); } } @@ -1521,6 +1523,9 @@ void ScummEngine_v99he::resetScumm() { ScummEngine_v90he::resetScumm(); + _hePaletteCache = (int16 *)malloc(65536); + memset(_hePaletteCache, -1, 65536); + _hePalettes = (uint8 *)malloc((_numPalettes + 1) * 1024); memset(_hePalettes, 0, (_numPalettes + 1) * 1024); diff --git a/engines/scumm/scumm.h b/engines/scumm/scumm.h index e040cb1593..065b941165 100644 --- a/engines/scumm/scumm.h +++ b/engines/scumm/scumm.h @@ -1027,6 +1027,7 @@ protected: virtual void palManipulateInit(int resID, int start, int end, int time); void palManipulate(); public: + int convert16BitColor(uint16 color, uint8 r, uint8 g, uint8 b); int remapPaletteColor(int r, int g, int b, int threshold); // Used by Actor::remapActorPalette protected: void moveMemInPalRes(int start, int end, byte direction); @@ -1102,6 +1103,7 @@ public: // HE specific byte _HEV7ActorPalette[256]; uint8 *_hePalettes; + int16 *_hePaletteCache; protected: int _shadowPaletteSize; |