Make Color use uint for ARGB.
This is a more natural representation than int that allows removal of casts in many places that require uint. Additionally, we can change the internal representation from long to uint, making the Color struct smaller. Since arrays of colors are common, this can save on memory.
This commit is contained in:
@@ -30,7 +30,7 @@ namespace OpenRA.Graphics
|
||||
|
||||
public static Color GetColor(this IPalette palette, int index)
|
||||
{
|
||||
return Color.FromArgb((int)palette[index]);
|
||||
return Color.FromArgb(palette[index]);
|
||||
}
|
||||
|
||||
public static IPalette AsReadOnly(this IPalette palette)
|
||||
@@ -103,7 +103,7 @@ namespace OpenRA.Graphics
|
||||
: this(p)
|
||||
{
|
||||
for (var i = 0; i < Palette.Size; i++)
|
||||
colors[i] = (uint)r.GetRemappedColor(this.GetColor(i), i).ToArgb();
|
||||
colors[i] = r.GetRemappedColor(this.GetColor(i), i).ToArgb();
|
||||
}
|
||||
|
||||
public ImmutablePalette(IPalette p)
|
||||
@@ -142,7 +142,7 @@ namespace OpenRA.Graphics
|
||||
|
||||
public void SetColor(int index, Color color)
|
||||
{
|
||||
colors[index] = (uint)color.ToArgb();
|
||||
colors[index] = color.ToArgb();
|
||||
}
|
||||
|
||||
public void SetFromPalette(IPalette p)
|
||||
@@ -153,7 +153,7 @@ namespace OpenRA.Graphics
|
||||
public void ApplyRemap(IPaletteRemap r)
|
||||
{
|
||||
for (var i = 0; i < Palette.Size; i++)
|
||||
colors[i] = (uint)r.GetRemappedColor(this.GetColor(i), i).ToArgb();
|
||||
colors[i] = r.GetRemappedColor(this.GetColor(i), i).ToArgb();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ namespace OpenRA.Graphics
|
||||
// Cast the data to an int array so we can copy the src data directly
|
||||
fixed (byte* bd = &destData[0])
|
||||
{
|
||||
var data = (int*)bd;
|
||||
var data = (uint*)bd;
|
||||
var x = dest.Bounds.Left;
|
||||
var y = dest.Bounds.Top;
|
||||
|
||||
@@ -195,7 +195,7 @@ namespace OpenRA.Graphics
|
||||
// Cast the data to an int array so we can copy the src data directly
|
||||
fixed (byte* bd = &destData[0])
|
||||
{
|
||||
var data = (int*)bd;
|
||||
var data = (uint*)bd;
|
||||
var x = dest.Bounds.Left;
|
||||
var y = dest.Bounds.Top;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace OpenRA.Primitives
|
||||
{
|
||||
public readonly struct Color : IEquatable<Color>, IScriptBindable
|
||||
{
|
||||
readonly long argb;
|
||||
readonly uint argb;
|
||||
|
||||
public static Color FromArgb(int red, int green, int blue)
|
||||
{
|
||||
@@ -26,7 +26,7 @@ namespace OpenRA.Primitives
|
||||
|
||||
public static Color FromArgb(int alpha, int red, int green, int blue)
|
||||
{
|
||||
return new Color(((byte)alpha << 24) + ((byte)red << 16) + ((byte)green << 8) + (byte)blue);
|
||||
return new Color((uint)(((byte)alpha << 24) + ((byte)red << 16) + ((byte)green << 8) + (byte)blue));
|
||||
}
|
||||
|
||||
public static Color FromAhsl(int alpha, float h, float s, float l)
|
||||
@@ -55,14 +55,14 @@ namespace OpenRA.Primitives
|
||||
return (A, h, s, v);
|
||||
}
|
||||
|
||||
Color(long argb)
|
||||
Color(uint argb)
|
||||
{
|
||||
this.argb = argb;
|
||||
}
|
||||
|
||||
public int ToArgb()
|
||||
public uint ToArgb()
|
||||
{
|
||||
return (int)argb;
|
||||
return argb;
|
||||
}
|
||||
|
||||
public static Color FromArgb(int alpha, Color baseColor)
|
||||
@@ -70,14 +70,9 @@ namespace OpenRA.Primitives
|
||||
return FromArgb(alpha, baseColor.R, baseColor.G, baseColor.B);
|
||||
}
|
||||
|
||||
public static Color FromArgb(int argb)
|
||||
{
|
||||
return FromArgb((byte)(argb >> 24), (byte)(argb >> 16), (byte)(argb >> 8), (byte)argb);
|
||||
}
|
||||
|
||||
public static Color FromArgb(uint argb)
|
||||
{
|
||||
return FromArgb((byte)(argb >> 24), (byte)(argb >> 16), (byte)(argb >> 8), (byte)argb);
|
||||
return new Color(argb);
|
||||
}
|
||||
|
||||
static float SrgbToLinear(float c)
|
||||
|
||||
Reference in New Issue
Block a user