Skip to content

Commit

Permalink
SCI: Refresh remapping by percent whenever the screen palette changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bluegr committed Jul 24, 2012
1 parent fe3fb18 commit 37b209d
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions engines/sci/graphics/palette.cpp
Expand Up @@ -350,10 +350,10 @@ void GfxPalette::resetRemapping() {
void GfxPalette::setRemappingPercent(byte color, byte percent) {
_remapOn = true;

// We need to defer the setup of the remapping table until something is
// shown on screen, otherwise kernelFindColor() won't find correct
// We need to defer the setup of the remapping table every time the screen
// palette is changed, so that kernelFindColor() can find the correct
// colors. The actual setup of the remapping table will be performed in
// remapColor().
// copySysPaletteToScreen().
_remappingPercentToSet = percent;

if (_remappingMaskFrom > color || _remappingMaskFrom == 0)
Expand All @@ -377,21 +377,6 @@ void GfxPalette::setRemappingRange(byte color, byte from, byte to, byte base) {

byte GfxPalette::remapColor(byte color) {
assert(_remapOn);

// Check if we need to set remapping by percent. This can only be
// performed when something is shown on screen, so that the screen
// palette is set up and kernelFindColor() can work correctly.
if (_remappingPercentToSet) {
for (int i = 0; i < 256; i++) {
byte r = _sysPalette.colors[i].r * _remappingPercentToSet / 100;
byte g = _sysPalette.colors[i].g * _remappingPercentToSet / 100;
byte b = _sysPalette.colors[i].b * _remappingPercentToSet / 100;
_remappingTable[i] = kernelFindColor(r, g, b);
}

_remappingPercentToSet = 0;
}

return _remappingTable[color];
}

Expand Down Expand Up @@ -557,6 +542,16 @@ void GfxPalette::copySysPaletteToScreen() {
}
}

// Check if we need to reset remapping by percent with the new colors.
if (_remappingPercentToSet) {
for (int i = 0; i < 256; i++) {
byte r = _sysPalette.colors[i].r * _remappingPercentToSet / 100;
byte g = _sysPalette.colors[i].g * _remappingPercentToSet / 100;
byte b = _sysPalette.colors[i].b * _remappingPercentToSet / 100;
_remappingTable[i] = kernelFindColor(r, g, b);
}
}

g_system->getPaletteManager()->setPalette(bpal, 0, 256);
}

Expand Down

0 comments on commit 37b209d

Please sign in to comment.