Replace ColorRamp with HSLColor everywhere.

Fixes:
* Nuclear-purple color exploit.
* #3247.
* Removes a bunch of unnecessary color conversions every frame.

Caveats:
* The ramp range is now defined on the palette, so ramps can no longer be set per-player (may impact maps which define custom colors).
* It's no longer possible to perfectly recreate the original WW color ramps (I doubt we care).
* The old ColorRamp setting isn't migrated, so players will lose their color settings.
This commit is contained in:
Paul Chote
2013-05-10 17:14:22 +12:00
parent abcc30f0b7
commit 656476991f
41 changed files with 112 additions and 168 deletions

View File

@@ -17,17 +17,14 @@ namespace OpenRA.FileFormats
public readonly byte H;
public readonly byte S;
public readonly byte L;
public readonly Color RGB;
public HSLColor(byte h, byte s, byte l)
{
H = h;
S = s;
L = l;
}
public Color ToColor()
{
return RGBFromHSL(H / 255f, S / 255f, L / 255f);
RGB = RGBFromHSL(H / 255f, S / 255f, L / 255f);
}
public void ToHSV(out float h, out float s, out float v)
@@ -47,6 +44,15 @@ namespace OpenRA.FileFormats
return new HSLColor((byte)(255*h), (byte)(255*ss), (byte)(255*ll));
}
public static HSLColor FromRGB(int r, int g, int b)
{
var c = Color.FromArgb(r, g, b);
var h = (byte)((c.GetHue() / 360.0f) * 255);
var s = (byte)(c.GetSaturation() * 255);
var l = (byte)(c.GetBrightness() * 255);
return new HSLColor(h, s, l);
}
public static Color RGBFromHSL(float h, float s, float l)
{
// Convert from HSL to RGB