aboutsummaryrefslogtreecommitdiff
path: root/engines/toltecs/palette.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/toltecs/palette.cpp')
-rw-r--r--engines/toltecs/palette.cpp68
1 files changed, 33 insertions, 35 deletions
diff --git a/engines/toltecs/palette.cpp b/engines/toltecs/palette.cpp
index 74683c6d7a..b93bb8b510 100644
--- a/engines/toltecs/palette.cpp
+++ b/engines/toltecs/palette.cpp
@@ -32,6 +32,8 @@ namespace Toltecs {
Palette::Palette(ToltecsEngine *vm) : _vm(vm) {
clearFragments();
+ memset(_mainPalette, 0, sizeof(_mainPalette));
+ memset(_animPalette, 0, sizeof(_animPalette));
memset(_colorTransTable, 0, sizeof(_colorTransTable));
}
@@ -138,52 +140,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];