aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Snover2016-06-25 21:19:47 +0200
committerWillem Jan Palenstijn2016-07-01 00:18:32 +0200
commit0c799e1bd910231ba05c8ed7f182577314ac967b (patch)
tree729ea5efd7cc5bb8fbf158ea50780f051edacf53
parent0aed08681eff9589dd7747b0285b07ef5a7cc155 (diff)
downloadscummvm-rg350-0c799e1bd910231ba05c8ed7f182577314ac967b.tar.gz
scummvm-rg350-0c799e1bd910231ba05c8ed7f182577314ac967b.tar.bz2
scummvm-rg350-0c799e1bd910231ba05c8ed7f182577314ac967b.zip
SCI32: Move matchColor to GfxRemap32
-rw-r--r--engines/sci/graphics/palette32.cpp48
-rw-r--r--engines/sci/graphics/palette32.h2
-rw-r--r--engines/sci/graphics/remap32.cpp46
-rw-r--r--engines/sci/graphics/remap32.h1
4 files changed, 52 insertions, 45 deletions
diff --git a/engines/sci/graphics/palette32.cpp b/engines/sci/graphics/palette32.cpp
index 6c6234d10d..5c9bfd66e9 100644
--- a/engines/sci/graphics/palette32.cpp
+++ b/engines/sci/graphics/palette32.cpp
@@ -82,6 +82,11 @@ const Palette *GfxPalette32::getNextPalette() const {
return &_nextPalette;
}
+const Palette *GfxPalette32::getCurrentPalette() const {
+ return &_sysPalette;
+}
+
+
void GfxPalette32::submit(Palette &palette) {
// TODO: The resource manager in SCI32 retains raw data of palettes from
// the ResourceManager (ResourceMgr) through SegManager (MemoryMgr), and
@@ -178,49 +183,6 @@ void GfxPalette32::set(Palette *newPalette, bool force, bool forceRealMerge) {
submit(*newPalette);
}
-// In SCI32 engine this method is SOLPalette::Match(Rgb24 *, int, int *, int *)
-// and is used by Remap
-// TODO: Anything that calls GfxPalette::matchColor(int, int, int) is going to
-// match using an algorithm from SCI16 engine right now. This needs to be
-// corrected in the future so either nothing calls
-// GfxPalette::matchColor(int, int, int), or it is fixed to match the other
-// SCI32 algorithms.
-int16 GfxPalette32::matchColor(const byte r, const byte g, const byte b, const int defaultDifference, int &lastCalculatedDifference, const bool *const matchTable) {
- int16 bestIndex = -1;
- int bestDifference = 0xFFFFF;
- int difference = defaultDifference;
-
- // SQ6 DOS really does check only the first 236 entries
- for (int i = 0, channelDifference; i < 236; ++i) {
- if (matchTable[i] == 0) {
- continue;
- }
-
- difference = _sysPalette.colors[i].r - r;
- difference *= difference;
- if (bestDifference <= difference) {
- continue;
- }
- channelDifference = _sysPalette.colors[i].g - g;
- difference += channelDifference * channelDifference;
- if (bestDifference <= difference) {
- continue;
- }
- channelDifference = _sysPalette.colors[i].b - b;
- difference += channelDifference * channelDifference;
- if (bestDifference <= difference) {
- continue;
- }
- bestDifference = difference;
- bestIndex = i;
- }
-
- // NOTE: This value is only valid if the last index to
- // perform a difference calculation was the best index
- lastCalculatedDifference = difference;
- return bestIndex;
-}
-
bool GfxPalette32::updateForFrame() {
applyAll();
_versionUpdated = false;
diff --git a/engines/sci/graphics/palette32.h b/engines/sci/graphics/palette32.h
index 1902d00ed7..ec75b58dd5 100644
--- a/engines/sci/graphics/palette32.h
+++ b/engines/sci/graphics/palette32.h
@@ -114,11 +114,11 @@ private:
public:
virtual void saveLoadWithSerializer(Common::Serializer &s) override;
const Palette *getNextPalette() const;
+ const Palette *getCurrentPalette() const;
bool kernelSetFromResource(GuiResourceId resourceId, bool force) override;
int16 kernelFindColor(uint16 r, uint16 g, uint16 b) override;
void set(Palette *newPalette, bool force, bool forceRealMerge = false) override;
- int16 matchColor(const byte matchRed, const byte matchGreen, const byte matchBlue, const int defaultDifference, int &lastCalculatedDifference, const bool *const matchTable);
/**
* Submits a palette to display. Entries marked as “used” in the
diff --git a/engines/sci/graphics/remap32.cpp b/engines/sci/graphics/remap32.cpp
index 774c4ca6f8..ef27c8491d 100644
--- a/engines/sci/graphics/remap32.cpp
+++ b/engines/sci/graphics/remap32.cpp
@@ -269,7 +269,7 @@ bool GfxRemap32::applyRemap(byte index) {
continue;
int diff = 0;
- int16 result = _palette->matchColor(targetColor.r, targetColor.g, targetColor.b, curRemap->distance[i], diff, unmappedColors);
+ int16 result = matchColor(targetColor.r, targetColor.g, targetColor.b, curRemap->distance[i], diff, unmappedColors);
if (result != -1 && curRemap->remap[i] != result) {
changed = true;
curRemap->remap[i] = result;
@@ -291,4 +291,48 @@ bool GfxRemap32::remapAllTables(bool palChanged) {
return changed;
}
+// In SCI32 engine this method is SOLPalette::Match(Rgb24 *, int, int *, int *)
+// and is used by Remap
+// TODO: Anything that calls GfxPalette::matchColor(int, int, int) is going to
+// match using an algorithm from SCI16 engine right now. This needs to be
+// corrected in the future so either nothing calls
+// GfxPalette::matchColor(int, int, int), or it is fixed to match the other
+// SCI32 algorithms.
+int16 GfxRemap32::matchColor(const byte r, const byte g, const byte b, const int defaultDifference, int &lastCalculatedDifference, const bool *const matchTable) const {
+ int16 bestIndex = -1;
+ int bestDifference = 0xFFFFF;
+ int difference = defaultDifference;
+ const Palette &_sysPalette = *g_sci->_gfxPalette32->getCurrentPalette();
+
+ // SQ6 DOS really does check only the first 236 entries
+ for (int i = 0, channelDifference; i < 236; ++i) {
+ if (matchTable[i] == 0) {
+ continue;
+ }
+
+ difference = _sysPalette.colors[i].r - r;
+ difference *= difference;
+ if (bestDifference <= difference) {
+ continue;
+ }
+ channelDifference = _sysPalette.colors[i].g - g;
+ difference += channelDifference * channelDifference;
+ if (bestDifference <= difference) {
+ continue;
+ }
+ channelDifference = _sysPalette.colors[i].b - b;
+ difference += channelDifference * channelDifference;
+ if (bestDifference <= difference) {
+ continue;
+ }
+ bestDifference = difference;
+ bestIndex = i;
+ }
+
+ // NOTE: This value is only valid if the last index to
+ // perform a difference calculation was the best index
+ lastCalculatedDifference = difference;
+ return bestIndex;
+}
+
} // End of namespace Sci
diff --git a/engines/sci/graphics/remap32.h b/engines/sci/graphics/remap32.h
index 3d5b67da37..52736f59d6 100644
--- a/engines/sci/graphics/remap32.h
+++ b/engines/sci/graphics/remap32.h
@@ -113,6 +113,7 @@ private:
void initColorArrays(byte index);
bool applyRemap(byte index);
bool updateRemap(byte index, bool palChanged);
+ int16 matchColor(const byte r, const byte g, const byte b, const int defaultDifference, int &lastCalculatedDifference, const bool *const matchTable) const;
};
} // End of namespace Sci