diff options
author | Filippos Karapetis | 2012-07-25 00:58:16 +0300 |
---|---|---|
committer | Filippos Karapetis | 2012-07-25 00:58:16 +0300 |
commit | 537b1969bf896ee4e72e9d042e4b7f41c921d38c (patch) | |
tree | 28b98f9a149458bd7f7aa348737bccf52d237198 /engines/sci/graphics | |
parent | 37b209dac14bea6b8f08c3ee3f66e3d5772652bb (diff) | |
download | scummvm-rg350-537b1969bf896ee4e72e9d042e4b7f41c921d38c.tar.gz scummvm-rg350-537b1969bf896ee4e72e9d042e4b7f41c921d38c.tar.bz2 scummvm-rg350-537b1969bf896ee4e72e9d042e4b7f41c921d38c.zip |
SCI: Rewrite the color remapping code to support simultaneous effects
Fixes the torch in the full version of QFG4
Diffstat (limited to 'engines/sci/graphics')
-rw-r--r-- | engines/sci/graphics/palette.cpp | 43 | ||||
-rw-r--r-- | engines/sci/graphics/palette.h | 17 | ||||
-rw-r--r-- | engines/sci/graphics/view.cpp | 8 |
3 files changed, 38 insertions, 30 deletions
diff --git a/engines/sci/graphics/palette.cpp b/engines/sci/graphics/palette.cpp index cb5c0fe614..9b8618c0ef 100644 --- a/engines/sci/graphics/palette.cpp +++ b/engines/sci/graphics/palette.cpp @@ -143,8 +143,9 @@ void GfxPalette::createFromData(byte *data, int bytesLeft, Palette *paletteOut) memset(paletteOut, 0, sizeof(Palette)); // Setup 1:1 mapping - for (colorNo = 0; colorNo < 256; colorNo++) + for (colorNo = 0; colorNo < 256; colorNo++) { paletteOut->mapping[colorNo] = colorNo; + } if (bytesLeft < 37) { // This happens when loading palette of picture 0 in sq5 - the resource is broken and doesn't contain a full @@ -332,18 +333,26 @@ void GfxPalette::set(Palette *newPalette, bool force, bool forceRealMerge) { } } -bool GfxPalette::isRemapMask(byte color) { - return (_remapOn && (color >= _remappingMaskFrom && color <= _remappingMaskTo)); +byte GfxPalette::remapColor(byte remappedColor, byte screenColor) { + assert(_remapOn); + if (_remappingType[remappedColor] == kRemappingByRange) + return _remappingByRange[screenColor]; + else if (_remappingType[remappedColor] == kRemappingByPercent) + return _remappingByPercent[screenColor]; + else + error("remapColor(): Color %d isn't remapped", remappedColor); + + return 0; // should never reach here } void GfxPalette::resetRemapping() { _remapOn = false; - _remappingMaskFrom = 0; - _remappingMaskTo = 0; _remappingPercentToSet = 0; for (int i = 0; i < 256; i++) { - _remappingTable[i] = i; + _remappingType[i] = kRemappingNone; + _remappingByPercent[i] = i; + _remappingByRange[i] = i; } } @@ -356,28 +365,17 @@ void GfxPalette::setRemappingPercent(byte color, byte percent) { // copySysPaletteToScreen(). _remappingPercentToSet = percent; - if (_remappingMaskFrom > color || _remappingMaskFrom == 0) - _remappingMaskFrom = color; - if (_remappingMaskTo < color) - _remappingMaskTo = color; + _remappingType[color] = kRemappingByPercent; } void GfxPalette::setRemappingRange(byte color, byte from, byte to, byte base) { _remapOn = true; for (int i = from; i <= to; i++) { - _remappingTable[i] = i + base; + _remappingByRange[i] = i + base; } - if (_remappingMaskFrom > color || _remappingMaskFrom == 0) - _remappingMaskFrom = color; - if (_remappingMaskTo < color) - _remappingMaskTo = color; -} - -byte GfxPalette::remapColor(byte color) { - assert(_remapOn); - return _remappingTable[color]; + _remappingType[color] = kRemappingByRange; } bool GfxPalette::insert(Palette *newPalette, Palette *destPalette) { @@ -548,7 +546,7 @@ void GfxPalette::copySysPaletteToScreen() { 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); + _remappingByPercent[i] = kernelFindColor(r, g, b); } } @@ -1060,8 +1058,9 @@ bool GfxPalette::loadClut(uint16 clutId) { memset(&pal, 0, sizeof(Palette)); // Setup 1:1 mapping - for (int i = 0; i < 256; i++) + for (int i = 0; i < 256; i++) { pal.mapping[i] = i; + } // Now load in the palette for (int i = 1; i <= 236; i++) { diff --git a/engines/sci/graphics/palette.h b/engines/sci/graphics/palette.h index 134ade5e36..9898315897 100644 --- a/engines/sci/graphics/palette.h +++ b/engines/sci/graphics/palette.h @@ -31,6 +31,12 @@ namespace Sci { class ResourceManager; class GfxScreen; +enum ColorRemappingType { + kRemappingNone = 0, + kRemappingByRange = 1, + kRemappingByPercent = 2 +}; + /** * Palette class, handles palette operations like changing intensity, setting up the palette, merging different palettes */ @@ -56,8 +62,10 @@ public: void resetRemapping(); void setRemappingPercent(byte color, byte percent); void setRemappingRange(byte color, byte from, byte to, byte base); - bool isRemapMask(byte color); - byte remapColor(byte color); + bool isRemapped(byte color) const { + return _remapOn && (_remappingType[color] != kRemappingNone); + } + byte remapColor(byte remappedColor, byte screenColor); void setOnScreen(); void copySysPaletteToScreen(); @@ -130,8 +138,9 @@ private: uint16 _totalScreenColors; bool _remapOn; - byte _remappingTable[256]; - uint16 _remappingMaskFrom, _remappingMaskTo; + ColorRemappingType _remappingType[256]; + byte _remappingByPercent[256]; + byte _remappingByRange[256]; uint16 _remappingPercentToSet; void loadMacIconBarPalette(); diff --git a/engines/sci/graphics/view.cpp b/engines/sci/graphics/view.cpp index f68ed1443a..36aaae9232 100644 --- a/engines/sci/graphics/view.cpp +++ b/engines/sci/graphics/view.cpp @@ -742,10 +742,10 @@ void GfxView::draw(const Common::Rect &rect, const Common::Rect &clipRect, const const int y2 = clipRectTranslated.top + y; if (!upscaledHires) { if (priority >= _screen->getPriority(x2, y2)) { - if (!_palette->isRemapMask(palette->mapping[color])) { + if (!_palette->isRemapped(palette->mapping[color])) { _screen->putPixel(x2, y2, drawMask, palette->mapping[color], priority, 0); } else { - byte remappedColor = _palette->remapColor(_screen->getVisual(x2, y2)); + byte remappedColor = _palette->remapColor(palette->mapping[color], _screen->getVisual(x2, y2)); _screen->putPixel(x2, y2, drawMask, remappedColor, priority, 0); } } @@ -857,10 +857,10 @@ void GfxView::drawScaled(const Common::Rect &rect, const Common::Rect &clipRect, const int x2 = clipRectTranslated.left + x; const int y2 = clipRectTranslated.top + y; if (color != clearKey && priority >= _screen->getPriority(x2, y2)) { - if (!_palette->isRemapMask(palette->mapping[color])) { + if (!_palette->isRemapped(palette->mapping[color])) { _screen->putPixel(x2, y2, drawMask, palette->mapping[color], priority, 0); } else { - byte remappedColor = _palette->remapColor(_screen->getVisual(x2, y2)); + byte remappedColor = _palette->remapColor(palette->mapping[color], _screen->getVisual(x2, y2)); _screen->putPixel(x2, y2, drawMask, remappedColor, priority, 0); } } |