aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruruk2014-07-29 13:25:13 +0200
committeruruk2014-07-29 13:25:13 +0200
commitcee669e76325dd9f6dca12262faf61cbe0392828 (patch)
tree75703b083c14f8a7c2dd8506407de6f17bc5ffe5
parent95854c3a5743564aa2ef3e7c1d8ef21156ae7f2e (diff)
downloadscummvm-rg350-cee669e76325dd9f6dca12262faf61cbe0392828.tar.gz
scummvm-rg350-cee669e76325dd9f6dca12262faf61cbe0392828.tar.bz2
scummvm-rg350-cee669e76325dd9f6dca12262faf61cbe0392828.zip
CGE2: Implement setAutoColors().
Add a redefinition of closest() to do so.
-rw-r--r--engines/cge2/talk.cpp11
-rw-r--r--engines/cge2/vga13h.cpp22
-rw-r--r--engines/cge2/vga13h.h1
3 files changed, 33 insertions, 1 deletions
diff --git a/engines/cge2/talk.cpp b/engines/cge2/talk.cpp
index 8e5773c677..f6321d3e59 100644
--- a/engines/cge2/talk.cpp
+++ b/engines/cge2/talk.cpp
@@ -31,7 +31,16 @@
namespace CGE2 {
void CGE2Engine::setAutoColors() {
- warning("STUB: CGE2Engine::setAutoColors()");
+ Dac def[4] = {
+ { 0, 0, 0 },
+ { 220 >> 2, 220 >> 2, 220 >> 2 },
+ { 190 >> 2, 190 >> 2, 190 >> 2 },
+ { 160 >> 2, 160 >> 2, 160 >> 2 },
+ };
+ Dac pal[kPalCount];
+ _vga->getColors(pal);
+ for (int i = 0; i < 4; i++)
+ _font->_colorSet[kCBRel][i] = _vga->closest(pal, def[i]);
}
Font::Font(CGE2Engine *vm) : _vm(vm) {
diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp
index 1cd2c95468..62b070dcac 100644
--- a/engines/cge2/vga13h.cpp
+++ b/engines/cge2/vga13h.cpp
@@ -913,6 +913,28 @@ uint8 Vga::closest(Dac *pal, const uint8 colR, const uint8 colG, const uint8 col
#undef f
}
+uint8 Vga::closest(Dac *pal, Dac x) {
+ int exp = (sizeof(long) * 8 - 1);
+ long D = (1 << exp) - 1; // Maximume value of long.
+ long R = x._r;
+ long G = x._g;
+ long B = x._b;
+ int idx;
+ for (int n = 0; n < 256; n++) {
+ long dR = R - pal[n]._r;
+ long dG = G - pal[n]._g;
+ long dB = B - pal[n]._b,
+ d = dR * dR + dG * dG + dB * dB;
+ if (d < D) {
+ idx = n;
+ D = d;
+ if (!d)
+ break;
+ }
+ }
+ return idx;
+}
+
uint8 *Vga::glass(Dac *pal, const uint8 colR, const uint8 colG, const uint8 colB) {
uint8 *x = (uint8 *)malloc(256);
if (x) {
diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h
index d8fe7156b6..3ed5fd559f 100644
--- a/engines/cge2/vga13h.h
+++ b/engines/cge2/vga13h.h
@@ -336,6 +336,7 @@ public:
void show();
void update();
void rotate();
+ uint8 closest(Dac *pal, Dac x);
void palToDac(const byte *palData, Dac *tab);
void dacToPal(const Dac *tab, byte *palData);