diff options
author | Filippos Karapetis | 2013-01-02 15:04:48 +0200 |
---|---|---|
committer | Filippos Karapetis | 2013-01-02 15:04:48 +0200 |
commit | 765578effe1e83b0bf853144d9e7edfb29dc9f49 (patch) | |
tree | 8dd6ab421e50568c8d5d7b49f27275936556e0dc /engines/toltecs/palette.cpp | |
parent | 3eae0e61e77bd2fe51934465c14bc71d8bec6773 (diff) | |
download | scummvm-rg350-765578effe1e83b0bf853144d9e7edfb29dc9f49.tar.gz scummvm-rg350-765578effe1e83b0bf853144d9e7edfb29dc9f49.tar.bz2 scummvm-rg350-765578effe1e83b0bf853144d9e7edfb29dc9f49.zip |
TOLTECS: Cleanup
Diffstat (limited to 'engines/toltecs/palette.cpp')
-rw-r--r-- | engines/toltecs/palette.cpp | 66 |
1 files changed, 31 insertions, 35 deletions
diff --git a/engines/toltecs/palette.cpp b/engines/toltecs/palette.cpp index 74683c6d7a..c88d80e627 100644 --- a/engines/toltecs/palette.cpp +++ b/engines/toltecs/palette.cpp @@ -138,52 +138,48 @@ void Palette::clearFragments() { _fragments.clear(); } +byte Palette::getMatchingColor(byte r, byte g, byte b) { + int bestIndex = 0; + uint16 bestMatch = 0xFFFF; + + for (int j = 0; j < 256; j++) { + byte distance = ABS(_mainPalette[j * 3 + 0] - r) + ABS(_mainPalette[j * 3 + 1] - g) + ABS(_mainPalette[j * 3 + 2] - b); + byte maxColor = MAX(_mainPalette[j * 3 + 0], MAX(_mainPalette[j * 3 + 1], _mainPalette[j * 3 + 2])); + uint16 match = (distance << 8) | maxColor; + if (match < bestMatch) { + bestMatch = match; + bestIndex = j; + } + } + + return bestIndex; +} + void Palette::buildColorTransTable(byte limit, int8 deltaValue, byte mask) { byte r = 0, g = 0, b = 0; mask &= 7; - for (int i = 0; i < 256; i++) { - - if (deltaValue < 0) { - // TODO (probably unused) - warning("Palette::buildColorTransTable(%d, %d, %02X) not yet implemented!", limit, deltaValue, mask); - } else { - r = _mainPalette[i * 3 + 0]; - g = _mainPalette[i * 3 + 1]; - b = _mainPalette[i * 3 + 2]; - if (MAX(r, MAX(b, g)) >= limit) { - if ((mask & 1) && r >= deltaValue) - r -= deltaValue; - if ((mask & 2) && g >= deltaValue) - g -= deltaValue; - if ((mask & 4) && b >= deltaValue) - b -= deltaValue; - } - } + if (deltaValue < 0) // unused + error("buildColorTransTable called with a negative delta value(limit %d, delta %d, mask %02X)", limit, deltaValue, mask); - int bestIndex = 0; - uint16 bestMatch = 0xFFFF; - - for (int j = 0; j < 256; j++) { - byte distance = ABS(_mainPalette[j * 3 + 0] - r) + ABS(_mainPalette[j * 3 + 1] - g) + ABS(_mainPalette[j * 3 + 2] - b); - byte maxColor = MAX(_mainPalette[j * 3 + 0], MAX(_mainPalette[j * 3 + 1], _mainPalette[j * 3 + 2])); - uint16 match = (distance << 8) | maxColor; - if (match < bestMatch) { - bestMatch = match; - bestIndex = j; - } + for (int i = 0; i < 256; i++) { + r = _mainPalette[i * 3 + 0]; + g = _mainPalette[i * 3 + 1]; + b = _mainPalette[i * 3 + 2]; + if (MAX(r, MAX(b, g)) >= limit) { + if ((mask & 1) && r >= deltaValue) + r -= deltaValue; + if ((mask & 2) && g >= deltaValue) + g -= deltaValue; + if ((mask & 4) && b >= deltaValue) + b -= deltaValue; } - _colorTransTable[i] = bestIndex; - + _colorTransTable[i] = getMatchingColor(r, g, b); } } -void Palette::buildColorTransTable2(byte limit, int8 deltaValue, byte mask) { - // TODO -} - void Palette::saveState(Common::WriteStream *out) { // Save currently active palette byte palette[768]; |