From 422a228ceab691314e64c72c1fa46d28f1061b40 Mon Sep 17 00:00:00 2001 From: Gustas <37534529+PunkPun@users.noreply.github.com> Date: Mon, 27 Feb 2023 20:22:06 +0200 Subject: [PATCH] Fix PlayerColorRemap expecting colors in linear space PlayerColorRemap expected colors in linear space yet we provided them in gamma. We fix this by instead expecting gamma space colors and then converting them into linear space ourselves. --- OpenRA.Game/Graphics/PlayerColorRemap.cs | 7 ++++--- OpenRA.Mods.Common/Traits/Palettes/ColorPickerPalette.cs | 6 ++---- OpenRA.Mods.Common/Traits/Palettes/FixedColorPalette.cs | 4 +--- OpenRA.Mods.Common/Traits/Palettes/PlayerColorPalette.cs | 4 +--- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/OpenRA.Game/Graphics/PlayerColorRemap.cs b/OpenRA.Game/Graphics/PlayerColorRemap.cs index 0e96103939..edf9613aec 100644 --- a/OpenRA.Game/Graphics/PlayerColorRemap.cs +++ b/OpenRA.Game/Graphics/PlayerColorRemap.cs @@ -21,11 +21,12 @@ namespace OpenRA.Graphics readonly float hue; readonly float saturation; - public PlayerColorRemap(int[] remapIndices, float hue, float saturation) + public PlayerColorRemap(int[] remapIndices, Color color) { this.remapIndices = remapIndices; - this.hue = hue; - this.saturation = saturation; + + var (r, g, b) = color.ToLinear(); + (hue, saturation, _) = Color.RgbToHsv(r, g, b); } public Color GetRemappedColor(Color original, int index) diff --git a/OpenRA.Mods.Common/Traits/Palettes/ColorPickerPalette.cs b/OpenRA.Mods.Common/Traits/Palettes/ColorPickerPalette.cs index 0653c7b49a..384906ad1e 100644 --- a/OpenRA.Mods.Common/Traits/Palettes/ColorPickerPalette.cs +++ b/OpenRA.Mods.Common/Traits/Palettes/ColorPickerPalette.cs @@ -57,8 +57,7 @@ namespace OpenRA.Mods.Common.Traits void ILoadsPalettes.LoadPalettes(WorldRenderer wr) { color = colorManager.Color; - var (_, h, s, _) = color.ToAhsv(); - var remap = new PlayerColorRemap(info.RemapIndex.Length == 0 ? Enumerable.Range(0, 256).ToArray() : info.RemapIndex, h, s); + var remap = new PlayerColorRemap(info.RemapIndex.Length == 0 ? Enumerable.Range(0, 256).ToArray() : info.RemapIndex, color); wr.AddPalette(info.Name, new ImmutablePalette(wr.Palette(info.BasePalette).Palette, remap), info.AllowModifiers); } @@ -70,8 +69,7 @@ namespace OpenRA.Mods.Common.Traits return; color = colorManager.Color; - var (_, h, s, _) = color.ToAhsv(); - var remap = new PlayerColorRemap(info.RemapIndex.Length == 0 ? Enumerable.Range(0, 256).ToArray() : info.RemapIndex, h, s); + var remap = new PlayerColorRemap(info.RemapIndex.Length == 0 ? Enumerable.Range(0, 256).ToArray() : info.RemapIndex, color); wr.ReplacePalette(info.Name, new ImmutablePalette(wr.Palette(info.BasePalette).Palette, remap)); } } diff --git a/OpenRA.Mods.Common/Traits/Palettes/FixedColorPalette.cs b/OpenRA.Mods.Common/Traits/Palettes/FixedColorPalette.cs index d4f29c1b1f..43642a53dd 100644 --- a/OpenRA.Mods.Common/Traits/Palettes/FixedColorPalette.cs +++ b/OpenRA.Mods.Common/Traits/Palettes/FixedColorPalette.cs @@ -52,9 +52,7 @@ namespace OpenRA.Mods.Common.Traits public void LoadPalettes(WorldRenderer wr) { - var (_, h, s, _) = info.Color.ToAhsv(); - - var remap = new PlayerColorRemap(info.RemapIndex.Length == 0 ? Enumerable.Range(0, 256).ToArray() : info.RemapIndex, h, s); + var remap = new PlayerColorRemap(info.RemapIndex.Length == 0 ? Enumerable.Range(0, 256).ToArray() : info.RemapIndex, info.Color); wr.AddPalette(info.Name, new ImmutablePalette(wr.Palette(info.Base).Palette, remap), info.AllowModifiers); } } diff --git a/OpenRA.Mods.Common/Traits/Palettes/PlayerColorPalette.cs b/OpenRA.Mods.Common/Traits/Palettes/PlayerColorPalette.cs index 9c33f1553c..b2712c7ab9 100644 --- a/OpenRA.Mods.Common/Traits/Palettes/PlayerColorPalette.cs +++ b/OpenRA.Mods.Common/Traits/Palettes/PlayerColorPalette.cs @@ -49,9 +49,7 @@ namespace OpenRA.Mods.Common.Traits public void LoadPlayerPalettes(WorldRenderer wr, string playerName, Color color, bool replaceExisting) { - var (_, h, s, _) = color.ToAhsv(); - - var remap = new PlayerColorRemap(info.RemapIndex.Length == 0 ? Enumerable.Range(0, 256).ToArray() : info.RemapIndex, h, s); + var remap = new PlayerColorRemap(info.RemapIndex.Length == 0 ? Enumerable.Range(0, 256).ToArray() : info.RemapIndex, color); var pal = new ImmutablePalette(wr.Palette(info.BasePalette).Palette, remap); wr.AddPalette(info.BaseName + playerName, pal, info.AllowModifiers, replaceExisting); }