forked from OpenRA/OpenRA
-
Notifications
You must be signed in to change notification settings - Fork 3
/
PlayerColorRemap.cs
executable file
·52 lines (43 loc) · 1.25 KB
/
PlayerColorRemap.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
namespace OpenRA.FileFormats
{
public class PlayerColorRemap : IPaletteRemap
{
Dictionary<int, Color> remapColors;
static int[] GetRemapRamp(int[] Ramp)
{
var RemapRamp = Ramp.Select(r => r - Ramp[0]).ToArray();
return RemapRamp;
}
public static int GetRemapIndex(int[] Ramp, int i)
{
return Ramp[i];
}
public PlayerColorRemap(int[] Ramp, ColorRamp c)
{
var c1 = c.GetColor(0);
var c2 = c.GetColor(1); /* temptemp: this can be expressed better */
var baseIndex = Ramp[0];
var RemapRamp = GetRemapRamp(Ramp);
remapColors = RemapRamp.Select((x, i) => Pair.New(baseIndex + i, Exts.ColorLerp(x / 16f, c1, c2)))
.ToDictionary(u => u.First, u => u.Second);
}
public Color GetRemappedColor(Color original, int index)
{
Color c;
return remapColors.TryGetValue(index, out c)
? c : original;
}
}
}