[Scummvm-cvs-logs] CVS: scummvm/scumm gfx.cpp,2.33,2.34 script_v8.cpp,2.141,2.142 scumm.h,1.158,1.159
Max Horn
fingolfin at users.sourceforge.net
Wed Mar 12 18:24:16 CET 2003
- Previous message: [Scummvm-cvs-logs] CVS: scummvm/scumm/smush brenderer.h,1.9,1.10 frenderer.cpp,1.17,1.18 frenderer.h,1.12,1.13 scumm_renderer.cpp,1.29,1.30 scumm_renderer.h,1.13,1.14
- Next message: [Scummvm-cvs-logs] CVS: scummvm/scumm/smush chunk_type.h,1.5,1.6
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/scummvm/scummvm/scumm
In directory sc8-pr-cvs1:/tmp/cvs-serv10806
Modified Files:
gfx.cpp script_v8.cpp scumm.h
Log Message:
Patch #686427: SO_ROOM_SATURATION implementation
Index: gfx.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/gfx.cpp,v
retrieving revision 2.33
retrieving revision 2.34
diff -u -d -r2.33 -r2.34
--- gfx.cpp 6 Mar 2003 21:45:56 -0000 2.33
+++ gfx.cpp 13 Mar 2003 02:23:55 -0000 2.34
@@ -2821,6 +2821,118 @@
}
}
+static double value(double n1, double n2, double hue)
+{
+ if (hue > 360.0)
+ hue = hue - 360.0;
+ else if (hue < 0.0)
+ hue = hue + 360.0;
+
+ if (hue < 60.0)
+ return n1 + (n2 - n1) * hue / 60.0;
+ if (hue < 180.0)
+ return n2;
+ if (hue < 240.0)
+ return n1 + (n2 - n1) * (240.0 - hue) / 60.0;
+ return n1;
+}
+
+void Scumm::desaturatePalette(int hueScale, int satScale, int lightScale, int startColor, int endColor)
+{
+ // This function scales the HSL (Hue, Saturation and Lightness)
+ // components of the palette colours. It's used in CMI when Guybrush
+ // walks from the beach towards the swamp.
+ //
+ // I don't know if this function is correct, but the output seems to
+ // match the original fairly closely.
+ //
+ // FIXME: Rewrite using integer arithmetics only?
+
+ if (startColor <= endColor) {
+ byte *cptr, *cur;
+ int j;
+
+ cptr = getPalettePtr() + startColor * 3;
+ cur = _currentPalette + startColor * 3;
+
+ for (j = startColor; j <= endColor; j++) {
+ double R, G, B;
+ double H, S, L;
+ double min, max;
+ int red, green, blue;
+
+ R = ((double) *cptr++) / 255.0;
+ G = ((double) *cptr++) / 255.0;
+ B = ((double) *cptr++) / 255.0;
+
+ // RGB to HLS (Foley and VanDam)
+
+ min = MIN(R, MIN(G, B));
+ max = MAX(R, MAX(G, B));
+
+ L = (max + min) / 2.0;
+
+ if (max != min) {
+ if (L <= 0.5)
+ S = (max - min) / (max + min);
+ else
+ S = (max - min) / (2.0 - max - min);
+
+ if (R == max)
+ H = (G - B) / (max - min);
+ else if (G == max)
+ H = 2.0 + (B - R) / (max - min);
+ else
+ H = 4.0 + (R - G) / (max - min);
+
+ H = H * 60.0;
+ if (H < 0.0)
+ H = H + 360.0;
+ } else {
+ S = 0.0;
+ H = 0.0; // undefined
+ }
+
+ // Scale the result
+
+ H = (H * hueScale) / 255.0;
+ S = (S * satScale) / 255.0;
+ L = (L * lightScale) / 255.0;
+
+ // HLS to RGB (Foley and VanDam)
+
+ double m1, m2;
+
+ if (min != max) {
+ if (L <= 0.5)
+ m2 = L * (1 + S);
+ else
+ m2 = L + S - L * S;
+
+ m1 = 2.0 * L - m2;
+
+ R = value(m1, m2, H + 120);
+ G = value(m1, m2, H);
+ B = value(m1, m2, H - 120);
+ } else {
+ R = L;
+ G = L;
+ B = L;
+ }
+
+ red = (int) (255.0 * R + 0.5);
+ green = (int) (255.0 * G + 0.5);
+ blue = (int) (255.0 * B + 0.5);
+
+ *cur++ = red;
+ *cur++ = green;
+ *cur++ = blue;
+ }
+
+ setDirtyColors(startColor, endColor);
+ }
+}
+
int Scumm::remapPaletteColor(int r, int g, int b, uint threshold) {
int i;
int ar, ag, ab;
Index: script_v8.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/script_v8.cpp,v
retrieving revision 2.141
retrieving revision 2.142
diff -u -d -r2.141 -r2.142
--- script_v8.cpp 8 Mar 2003 02:06:56 -0000 2.141
+++ script_v8.cpp 13 Mar 2003 02:23:55 -0000 2.142
@@ -998,12 +998,7 @@
c = pop();
b = pop();
a = pop();
- // FIXME - this probably has the same format as for darkenPalette:
- // thre values for R, G, B and a start/end palette range to modify.
- // Now, how on earth does on modify the saturation of a single color channel?
- // Change the hue/saturation of a color, no problem, I know how to do that,
- // but for only a channel alone, I don't even know what that should mean... :-/
-// warning("o8_roomOps: SO_ROOM_SATURATION(%d, %d, %d, %d, %d)", a, b, c, d, e);
+ desaturatePalette(a, b, c, d, e);
break;
default:
error("o8_roomOps: default case 0x%x", subOp);
Index: scumm.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/scumm.h,v
retrieving revision 1.158
retrieving revision 1.159
diff -u -d -r1.158 -r1.159
--- scumm.h 8 Mar 2003 17:39:18 -0000 1.158
+++ scumm.h 13 Mar 2003 02:23:55 -0000 1.159
@@ -803,6 +803,7 @@
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 desaturatePalette(int hueScale, int satScale, int lightScale, int startColor, int endColor);
void setCursor(int cursor);
void setCursorImg(uint img, uint room, uint imgindex);
- Previous message: [Scummvm-cvs-logs] CVS: scummvm/scumm/smush brenderer.h,1.9,1.10 frenderer.cpp,1.17,1.18 frenderer.h,1.12,1.13 scumm_renderer.cpp,1.29,1.30 scumm_renderer.h,1.13,1.14
- Next message: [Scummvm-cvs-logs] CVS: scummvm/scumm/smush chunk_type.h,1.5,1.6
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Scummvm-git-logs
mailing list