diff --git a/LEGO1/legobackgroundcolor.cpp b/LEGO1/legobackgroundcolor.cpp index eec569c2..db4e743e 100644 --- a/LEGO1/legobackgroundcolor.cpp +++ b/LEGO1/legobackgroundcolor.cpp @@ -20,9 +20,9 @@ void LegoBackgroundColor::SetColorString(const char *colorString) m_colorString.operator=(colorString); m_colorString.ToLowerCase(); + float converted_r; float converted_b; float converted_g; - float converted_r; LegoVideoManager *videomanager = VideoManager(); if (videomanager && colorString) @@ -33,9 +33,7 @@ void LegoBackgroundColor::SetColorString(const char *colorString) char *colorStringSplit = strtok(colorStringCopy, Delimiter); if (!strcmp(colorStringSplit, set)) { - // set it - - //TODO: I think this is in BGR because of the order of local variables + //TODO: the names of these variables are incorrect as I can't figure out what color format ConvertColor() uses char *blue = strtok(0, Delimiter); if (blue) b = atoi(blue) * 0.01; @@ -50,8 +48,8 @@ void LegoBackgroundColor::SetColorString(const char *colorString) { // reset it - ConvertColor(this->b, this->g, this->r, &converted_b, &converted_g, &converted_r); - videomanager->SetSkyColor(converted_b, converted_g, converted_r); + ConvertColor(this->b, this->g, this->r, &converted_r, &converted_g, &converted_b); + videomanager->SetSkyColor(converted_r, converted_g, converted_b); } free(colorStringCopy); } diff --git a/LEGO1/legobackgroundcolor.h b/LEGO1/legobackgroundcolor.h index 15efb3e4..14030746 100644 --- a/LEGO1/legobackgroundcolor.h +++ b/LEGO1/legobackgroundcolor.h @@ -8,11 +8,6 @@ class LegoBackgroundColor : public MxBackgroundColor public: __declspec(dllexport) LegoBackgroundColor(const char *, const char *); void SetColorString(const char *colorString); - -protected: - float b; - float g; - float r; }; #endif // LEGOBACKGROUNDCOLOR_H diff --git a/LEGO1/legoutil.cpp b/LEGO1/legoutil.cpp index 8012ebc8..b7f45c7c 100644 --- a/LEGO1/legoutil.cpp +++ b/LEGO1/legoutil.cpp @@ -1,7 +1,63 @@ #include "legoutil.h" // OFFSET: LEGO1 0x1003eae0 -void ConvertColor(float r, float g, float b, float* out_r, float* out_g, float* out_b) +void ConvertColor(float h, float s, float v, float *r_out, float *b_out, float *g_out) { - // todo + double calc; // st7 + if (s <= 0.5) + calc = (v + 1.0) * s; + else + calc = (1.0 - v) * s + v; + if (calc < 0.0) + { + *g_out = 0.0; + *b_out = 0.0; + *r_out = 0.0; + return; + } + double v11 = s * 2.0 - calc; + int hue_index = h * 6.0; + double v9 = (calc - v11) / calc * (hue_index - hue_index) * calc; + double v12 = v11 + v9; + double v13 = calc - v9; + switch (hue_index) + { + case 0: + *r_out = calc; + *b_out = v12; + *g_out = v11; + break; + case 1: + *r_out = v13; + *b_out = calc; + *g_out = v11; + break; + case 2: + *r_out = v11; + *b_out = calc; + *g_out = v12; + break; + case 3: + *r_out = v11; + *b_out = v13; + *g_out = calc; + break; + case 4: + *r_out = v12; + *b_out = v11; + *g_out = calc; + break; + case 5: + *r_out = calc; + *b_out = v11; + *g_out = v13; + break; + case 6: + *r_out = calc; + *b_out = v11; + *g_out = v13; + break; + default: + return; + } } \ No newline at end of file diff --git a/LEGO1/legovideomanager.cpp b/LEGO1/legovideomanager.cpp index d27f00cb..20b42aa8 100644 --- a/LEGO1/legovideomanager.cpp +++ b/LEGO1/legovideomanager.cpp @@ -1,7 +1,13 @@ #include "legovideomanager.h" - +#include // OFFSET: LEGO1 0x1007c440 -void LegoVideoManager::SetSkyColor(float r, float g, float b) +void LegoVideoManager::SetSkyColor(float red, float green, float blue) { - //TODO + PALETTEENTRY colorStrucure; // [esp+0h] [ebp-4h] BYREF + + colorStrucure.peRed = (red* 255.0); + colorStrucure.peGreen = (green * 255.0); + colorStrucure.peBlue = (blue * 255.0); + colorStrucure.peFlags = -124; + // TODO } \ No newline at end of file diff --git a/LEGO1/mxbackgroundcolor.h b/LEGO1/mxbackgroundcolor.h index 3038ef24..fae1741b 100644 --- a/LEGO1/mxbackgroundcolor.h +++ b/LEGO1/mxbackgroundcolor.h @@ -6,13 +6,17 @@ class MxBackgroundColor { public: __declspec(dllexport) MxBackgroundColor(const char *, const char *); - MxBackgroundColor(){} - virtual MxString* GetColorString(); - virtual void SetColorString(const char* colorString); + MxBackgroundColor() {} + virtual MxString *GetColorString(); + virtual void SetColorString(const char *colorString); virtual ~MxBackgroundColor(); + protected: MxString m_name; MxString m_colorString; + float b; + float g; + float r; }; #endif // MXBACKGROUNDCOLOR_H