aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scumm/gfx.cpp240
-rw-r--r--scumm/script_v1.cpp6
-rw-r--r--scumm/script_v2.cpp32
-rw-r--r--scumm/scumm.h6
4 files changed, 133 insertions, 151 deletions
diff --git a/scumm/gfx.cpp b/scumm/gfx.cpp
index 101b71a21e..1b3e678cb1 100644
--- a/scumm/gfx.cpp
+++ b/scumm/gfx.cpp
@@ -2574,7 +2574,34 @@ void Scumm::palManipulate()
_palManipCounter--;
}
-void Scumm::unkRoomFunc3(int palstart, int palend, int rfact, int gfact, int bfact)
+void Scumm::setupShadowPalette(int slot, int redScale, int greenScale, int blueScale, int startColor, int endColor)
+{
+ byte *table;
+ int i;
+ byte *curpal;
+
+ if (slot < 0 || slot > 7)
+ error("setupShadowPalette: invalid slot %d", slot);
+
+ if (startColor < 0 || startColor > 255 || endColor < 0 || startColor > 255 || endColor < startColor)
+ error("setupShadowPalette: invalid range from %d to %d", startColor, endColor);
+
+ table = _shadowPalette + slot * 256;
+ for (i = 0; i < 256; i++)
+ table[i] = i;
+
+ table += startColor;
+ curpal = _currentPalette + startColor * 3;
+ for (i = startColor; i <= endColor; i++) {
+ *table++ = remapPaletteColor((curpal[0] * redScale) >> 8,
+ curpal[1] * greenScale >> 8,
+ curpal[2] * blueScale >> 8,
+ (uint) - 1);
+ curpal += 3;
+ }
+}
+
+void Scumm::setupShadowPalette(int redScale, int greenScale, int blueScale, int startColor, int endColor)
{
byte *basepal = getPalettePtr();
byte *pal = basepal;
@@ -2601,9 +2628,9 @@ void Scumm::unkRoomFunc3(int palstart, int palend, int rfact, int gfact, int bfa
// and thus doesn't result in any visual differences.
for (i = 0; i <= 255; i++) {
- int r = (int) (*pal++ * rfact) >> 8;
- int g = (int) (*pal++ * gfact) >> 8;
- int b = (int) (*pal++ * bfact) >> 8;
+ int r = (int) (*pal++ * redScale) >> 8;
+ int g = (int) (*pal++ * greenScale) >> 8;
+ int b = (int) (*pal++ * blueScale) >> 8;
// The following functionality is similar to remapPaletteColor, except
// 1) we have to work off the original CLUT rather than the current palette, and
@@ -2613,7 +2640,6 @@ void Scumm::unkRoomFunc3(int palstart, int palend, int rfact, int gfact, int bfa
int j;
int ar, ag, ab;
uint sum, diff, bestsum, bestitem = 0;
- compareptr = basepal + palstart * 3;
if (r > 255)
r = 255;
@@ -2622,13 +2648,14 @@ void Scumm::unkRoomFunc3(int palstart, int palend, int rfact, int gfact, int bfa
if (b > 255)
b = 255;
- bestsum = (uint) - 1;
+ bestsum = (uint)-1;
r &= ~3;
g &= ~3;
b &= ~3;
- for (j = palstart; j <= palend; j++, compareptr += 3) {
+ compareptr = basepal + startColor * 3;
+ for (j = startColor; j <= endColor; j++, compareptr += 3) {
ar = compareptr[0] & ~3;
ag = compareptr[1] & ~3;
ab = compareptr[2] & ~3;
@@ -2653,6 +2680,87 @@ void Scumm::unkRoomFunc3(int palstart, int palend, int rfact, int gfact, int bfa
}
}
+/* Yazoo: This function create the specialPalette used for semi-transparency in SamnMax */
+void Scumm::createSpecialPalette(int16 from, int16 to, int16 redScale, int16 greenScale, int16 blueScale,
+ int16 startColor, int16 endColor)
+{
+ byte *palPtr;
+ byte *curPtr;
+ byte *searchPtr;
+
+ uint bestResult;
+ uint currentResult;
+
+ byte currentIndex;
+
+ int i, j;
+
+ palPtr = getPalettePtr();
+
+ for (i = 0; i < 256; i++)
+ _proc_special_palette[i] = i;
+
+ curPtr = palPtr + startColor * 3;
+
+ for (i = startColor; i < endColor; i++) {
+ int r = (int) (*curPtr++ * redScale) >> 8;
+ int g = (int) (*curPtr++ * greenScale) >> 8;
+ int b = (int) (*curPtr++ * blueScale) >> 8;
+
+ searchPtr = palPtr;
+ bestResult = 32000;
+ currentIndex = 0;
+
+ for (j = from; j < to; j++) {
+ int ar = (*searchPtr++);
+ int ag = (*searchPtr++);
+ int ab = (*searchPtr++);
+
+ // FIXME - shouldn't we use a better distance measure, like the one in remapPaletteColor ?
+ currentResult = abs(ar - r) + abs(ag - g) + abs(ab - b);
+
+ if (currentResult < bestResult) {
+ _proc_special_palette[i] = currentIndex;
+ bestResult = currentResult;
+ }
+ currentIndex++;
+ }
+ }
+}
+
+void Scumm::darkenPalette(int redScale, int greenScale, int blueScale, int startColor, int endColor)
+{
+ if (startColor <= endColor) {
+ byte *cptr, *cur;
+ int j;
+ int color;
+
+ cptr = getPalettePtr() + startColor * 3;
+ cur = _currentPalette + startColor * 3;
+
+ for (j = startColor; j <= endColor; j++) {
+ color = *cptr++;
+ color = color * redScale / 0xFF;
+ if (color > 255)
+ color = 255;
+ *cur++ = color;
+
+ color = *cptr++;
+ color = color * greenScale / 0xFF;
+ if (color > 255)
+ color = 255;
+ *cur++ = color;
+
+ color = *cptr++;
+ color = color * blueScale / 0xFF;
+ if (color > 255)
+ color = 255;
+ *cur++ = color;
+ }
+ setDirtyColors(startColor, endColor);
+ }
+}
+
void Scumm::swapPalColors(int a, int b)
{
byte *ap, *bp;
@@ -2813,43 +2921,6 @@ byte *Scumm::getPalettePtr()
return cptr;
}
-void Scumm::darkenPalette(int startColor, int endColor, int redScale, int greenScale, int blueScale)
-{
- if (startColor <= endColor) {
- byte *cptr, *cur;
- int num;
- int color;
-
- cptr = getPalettePtr() + startColor * 3;
- cur = _currentPalette + startColor * 3;
- num = endColor - startColor + 1;
-
- do {
- color = *cptr++;
- if (redScale != 0xFF)
- color = color * redScale / 0xFF;
- if (color > 255)
- color = 255;
- *cur++ = color;
-
- color = *cptr++;
- if (greenScale != 0xFF)
- color = color * greenScale / 0xFF;
- if (color > 255)
- color = 255;
- *cur++ = color;
-
- color = *cptr++;
- if (blueScale != 0xFF)
- color = color * blueScale / 0xFF;
- if (color > 255)
- color = 255;
- *cur++ = color;
- } while (--num);
- setDirtyColors(startColor, endColor);
- }
-}
-
void Scumm::grabCursor(int x, int y, int w, int h)
{
VirtScreen *vs = findVirtScreen(y);
@@ -3054,7 +3125,7 @@ int Scumm::remapPaletteColor(int r, int g, int b, uint threshold)
{
int i;
int ar, ag, ab;
- uint sum, j, bestsum, bestitem = 0;
+ uint sum, diff, bestsum, bestitem = 0;
byte *pal = _currentPalette;
if (r > 255)
@@ -3077,12 +3148,12 @@ int Scumm::remapPaletteColor(int r, int g, int b, uint threshold)
if (ar == r && ag == g && ab == b)
return i;
- j = ar - r;
- sum = j * j * 3;
- j = ag - g;
- sum += j * j * 6;
- j = ab - b;
- sum += j * j * 2;
+ diff = ar - r;
+ sum = diff * diff * 3;
+ diff = ag - g;
+ sum += diff * diff * 6;
+ diff = ab - b;
+ sum += diff * diff * 2;
if (sum < bestsum) {
bestsum = sum;
@@ -3091,6 +3162,8 @@ int Scumm::remapPaletteColor(int r, int g, int b, uint threshold)
}
if (threshold != (uint) - 1 && bestsum > threshold * threshold * (2 + 3 + 6)) {
+ // Best match exceeded threshold. Try to find an unused palette entry and
+ // use it for our purpose.
pal = _currentPalette + (256 - 2) * 3;
for (i = 254; i > 48; i--, pal -= 3) {
if (pal[0] >= 252 && pal[1] >= 252 && pal[2] >= 252) {
@@ -3392,68 +3465,3 @@ labelBompSkip:
}
}
-/* Yazoo: This function create the specialPalette used for semi-transparency in SamnMax */
-void Scumm::createSpecialPalette(int16 a, int16 b, int16 c, int16 d, int16 e, int16 colorMin,
- int16 colorMax)
-{
- byte *palPtr;
- byte *curPtr;
- byte *searchPtr;
-
- byte readComp1;
- byte readComp2;
- byte readComp3;
-
- int colorComp1;
- int colorComp2;
- int colorComp3;
-
- int searchComp1;
- int searchComp2;
- int searchComp3;
-
- short int bestResult;
- short int currentResult;
-
- byte currentIndex;
-
- int i;
- int j;
-
- palPtr = getPalettePtr();
-
- for (i = 0; i < 256; i++)
- _proc_special_palette[i] = i;
-
- curPtr = palPtr + colorMin * 3;
-
- for (i = colorMin; i < colorMax; i++) {
- readComp1 = *(curPtr++);
- readComp2 = *(curPtr++);
- readComp3 = *(curPtr++);
-
- colorComp1 = ((readComp1) * c) >> 8;
- colorComp2 = ((readComp2) * d) >> 8;
- colorComp3 = ((readComp3) * e) >> 8;
-
- searchPtr = palPtr;
- bestResult = 32000;
- currentIndex = 0;
-
- for (j = a; j < b; j++) {
- searchComp1 = (*searchPtr++);
- searchComp2 = (*searchPtr++);
- searchComp3 = (*searchPtr++);
-
- currentResult =
- abs(searchComp1 - colorComp1) + abs(searchComp2 - colorComp2) + abs(searchComp3 - colorComp3);
-
- if (currentResult < bestResult) {
- _proc_special_palette[i] = currentIndex;
- bestResult = currentResult;
- }
- currentIndex++;
- }
- }
-}
-
diff --git a/scumm/script_v1.cpp b/scumm/script_v1.cpp
index 11be00fb82..a7c39a1250 100644
--- a/scumm/script_v1.cpp
+++ b/scumm/script_v1.cpp
@@ -1756,7 +1756,7 @@ void Scumm::o5_roomOps()
b = getVarOrDirectByte(0x40);
c = getVarOrDirectByte(0x20);
}
- darkenPalette(b, c, a, a, a);
+ darkenPalette(a, a, a, b, c);
break;
case 9: /* ? */
_saveLoadFlag = getVarOrDirectByte(0x80);
@@ -1780,7 +1780,7 @@ void Scumm::o5_roomOps()
_opcode = fetchScriptByte();
d = getVarOrDirectByte(0x80);
e = getVarOrDirectByte(0x40);
- darkenPalette(d, e, a, b, c);
+ darkenPalette(a, b, c, d, e);
break;
case 12: /* ? */
a = getVarOrDirectWord(0x80);
@@ -1789,7 +1789,7 @@ void Scumm::o5_roomOps()
_opcode = fetchScriptByte();
d = getVarOrDirectByte(0x80);
e = getVarOrDirectByte(0x40);
- unkRoomFunc3(d, e, a, b, c);
+ setupShadowPalette(a, b, c, d, e);
break;
case 13:{ /* save-string */
diff --git a/scumm/script_v2.cpp b/scumm/script_v2.cpp
index 62e7711004..484de5170a 100644
--- a/scumm/script_v2.cpp
+++ b/scumm/script_v2.cpp
@@ -1517,7 +1517,7 @@ void Scumm::o6_roomOps()
c = pop();
b = pop();
a = pop();
- darkenPalette(b, c, a, a, a);
+ darkenPalette(a, a, a, b, c);
break;
case 180:
@@ -1543,7 +1543,7 @@ void Scumm::o6_roomOps()
c = pop();
b = pop();
a = pop();
- darkenPalette(d, e, a, b, c);
+ darkenPalette(a, b, c, d, e);
break;
case 183:
@@ -1552,7 +1552,7 @@ void Scumm::o6_roomOps()
c = pop();
b = pop();
a = pop();
- unkRoomFunc3(d, e, a, b, c);
+ setupShadowPalette(a, b, c, d, e);
break;
case 184:
@@ -2975,29 +2975,3 @@ void Scumm::decodeParseString2(int m, int n)
error("decodeParseString: default case");
}
}
-
-void Scumm::setupShadowPalette(int slot, int rfact, int gfact, int bfact, int from, int to)
-{
- byte *table;
- int i, num;
- byte *curpal;
-
- if (slot < 0 || slot > 7)
- error("setupShadowPalette: invalid slot %d", slot);
-
- if (from < 0 || from > 255 || to < 0 || from > 255 || to < from)
- error("setupShadowPalette: invalid range from %d to %d", from, to);
-
- table = _shadowPalette + slot * 256;
- for (i = 0; i < 256; i++)
- table[i] = i;
-
- table += from;
- curpal = _currentPalette + from * 3;
- num = to - from + 1;
- do {
- *table++ = remapPaletteColor((curpal[0] * rfact) >> 8,
- curpal[1] * gfact >> 8, curpal[2] * bfact >> 8, (uint) - 1);
- curpal += 3;
- } while (--num);
-}
diff --git a/scumm/scumm.h b/scumm/scumm.h
index a87a7af212..b75c2c352f 100644
--- a/scumm/scumm.h
+++ b/scumm/scumm.h
@@ -755,11 +755,11 @@ public:
void stopCycle(int i);
void palManipulateInit(int start, int end, int string_id, int time);
void palManipulate();
- void unkRoomFunc3(int a, int b, int c, int d, int e);
int remapPaletteColor(int r, int g, int b, uint threshold);
void moveMemInPalRes(int start, int end, byte direction);
- void setupShadowPalette(int slot, int rfact, int gfact, int bfact, int from, int to);
- void darkenPalette(int a, int b, int c, int d, int e);
+ void setupShadowPalette(int slot, int redScale, int greenScale, int blueScale, int startColor, int endColor);
+ void setupShadowPalette(int redScale, int greenScale, int blueScale, int startColor, int endColor);
+ void darkenPalette(int redScale, int greenScale, int blueScale, int startColor, int endColor);
void setShake(int mode);