support reversed remapping for d2k

This commit is contained in:
Matthias Mailänder
2012-07-17 17:01:37 +02:00
parent 6204bfcabf
commit 44b8630c71
3 changed files with 11 additions and 10 deletions

View File

@@ -19,12 +19,6 @@ namespace OpenRA.FileFormats
{
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];
@@ -33,11 +27,18 @@ namespace OpenRA.FileFormats
public PlayerColorRemap(int[] Ramp, ColorRamp c)
{
var c1 = c.GetColor(0);
var c2 = c.GetColor(1); /* temptemp: this can be expressed better */
var c2 = c.GetColor(1); // temptemp: this can be expressed better
var baseIndex = Ramp[0];
var RemapRamp = GetRemapRamp(Ramp);
var RemapRamp = Ramp.Select(r => r - Ramp[0]).ToArray();
if (Ramp[0] > Ramp[15]) // reversed remapping
{
baseIndex = Ramp[15];
for (int i=15; i>0; i--)
RemapRamp = Ramp.Select(r => r - Ramp[15]).ToArray();
}
remapColors = RemapRamp.Select((x, i) => Pair.New(baseIndex + i, Exts.ColorLerp(x / 16f, c1, c2)))
.ToDictionary(u => u.First, u => u.Second);
}