Skip to content
Permalink
Browse files

[Mathematics] Fixes for Color/ColorRGBA float/byte mismatches (#258) (f…

…ixes #251)
  • Loading branch information
SleepyMode authored and xen2 committed Jan 19, 2019
1 parent 993704f commit 81331463843bfaf6975a0e418047a208a23a7fe7
Showing with 20 additions and 20 deletions.
  1. +10 −10 sources/core/Xenko.Core.Mathematics/Color.cs
  2. +10 −10 sources/core/Xenko.Core.Mathematics/ColorBGRA.cs
@@ -475,7 +475,7 @@ public static void Add(ref Color left, ref Color right, out Color result)
/// <returns>The sum of the two colors.</returns>
public static Color Add(Color left, Color right)
{
return new Color(left.R + right.R, left.G + right.G, left.B + right.B, left.A + right.A);
return new Color((byte)(left.R + right.R), (byte)(left.G + right.G), (byte)(left.B + right.B), (byte)(left.A + right.A));
}

/// <summary>
@@ -500,7 +500,7 @@ public static void Subtract(ref Color left, ref Color right, out Color result)
/// <returns>The difference of the two colors.</returns>
public static Color Subtract(Color left, Color right)
{
return new Color(left.R - right.R, left.G - right.G, left.B - right.B, left.A - right.A);
return new Color((byte)(left.R - right.R), (byte)(left.G - right.G), (byte)(left.B - right.B), (byte)(left.A - right.A));
}

/// <summary>
@@ -511,10 +511,10 @@ public static Color Subtract(Color left, Color right)
/// <param name="result">When the method completes, contains the modulated color.</param>
public static void Modulate(ref Color left, ref Color right, out Color result)
{
result.A = (byte)(left.A * right.A / 255.0f);
result.R = (byte)(left.R * right.R / 255.0f);
result.G = (byte)(left.G * right.G / 255.0f);
result.B = (byte)(left.B * right.B / 255.0f);
result.A = (byte)(left.A * right.A / 255);
result.R = (byte)(left.R * right.R / 255);
result.G = (byte)(left.G * right.G / 255);
result.B = (byte)(left.B * right.B / 255);
}

/// <summary>
@@ -525,7 +525,7 @@ public static void Modulate(ref Color left, ref Color right, out Color result)
/// <returns>The modulated color.</returns>
public static Color Modulate(Color left, Color right)
{
return new Color(left.R * right.R, left.G * right.G, left.B * right.B, left.A * right.A);
return new Color((byte)(left.R * right.R / 255), (byte)(left.G * right.G / 255), (byte)(left.B * right.B / 255), (byte)(left.A * right.A / 255));
}

/// <summary>
@@ -573,7 +573,7 @@ public static void Negate(ref Color value, out Color result)
/// <returns>The negated color.</returns>
public static Color Negate(Color value)
{
return new Color(255 - value.R, 255 - value.G, 255 - value.B, 255 - value.A);
return new Color((byte)(255 - value.R), (byte)(255 - value.G), (byte)(255 - value.B), (byte)(255 - value.A));
}

/// <summary>
@@ -864,7 +864,7 @@ public static Color AdjustSaturation(Color value, float saturation)
/// <returns>The sum of the two colors.</returns>
public static Color operator +(Color left, Color right)
{
return new Color(left.R + right.R, left.G + right.G, left.B + right.B, left.A + right.A);
return new Color((byte)(left.R + right.R), (byte)(left.G + right.G), (byte)(left.B + right.B), (byte)(left.A + right.A));
}

/// <summary>
@@ -885,7 +885,7 @@ public static Color AdjustSaturation(Color value, float saturation)
/// <returns>The difference of the two colors.</returns>
public static Color operator -(Color left, Color right)
{
return new Color(left.R - right.R, left.G - right.G, left.B - right.B, left.A - right.A);
return new Color((byte)(left.R - right.R), (byte)(left.G - right.G), (byte)(left.B - right.B), (byte)(left.A - right.A));
}

/// <summary>
@@ -449,7 +449,7 @@ public static void Add(ref ColorBGRA left, ref ColorBGRA right, out ColorBGRA re
/// <returns>The sum of the two colors.</returns>
public static ColorBGRA Add(ColorBGRA left, ColorBGRA right)
{
return new ColorBGRA(left.R + right.R, left.G + right.G, left.B + right.B, left.A + right.A);
return new ColorBGRA((byte)(left.R + right.R), (byte)(left.G + right.G), (byte)(left.B + right.B), (byte)(left.A + right.A));
}

/// <summary>
@@ -474,7 +474,7 @@ public static void Subtract(ref ColorBGRA left, ref ColorBGRA right, out ColorBG
/// <returns>The difference of the two colors.</returns>
public static ColorBGRA Subtract(ColorBGRA left, ColorBGRA right)
{
return new ColorBGRA(left.R - right.R, left.G - right.G, left.B - right.B, left.A - right.A);
return new ColorBGRA((byte)(left.R - right.R), (byte)(left.G - right.G), (byte)(left.B - right.B), (byte)(left.A - right.A));
}

/// <summary>
@@ -485,10 +485,10 @@ public static ColorBGRA Subtract(ColorBGRA left, ColorBGRA right)
/// <param name="result">When the method completes, contains the modulated color.</param>
public static void Modulate(ref ColorBGRA left, ref ColorBGRA right, out ColorBGRA result)
{
result.A = (byte)(left.A * right.A / 255.0f);
result.R = (byte)(left.R * right.R / 255.0f);
result.G = (byte)(left.G * right.G / 255.0f);
result.B = (byte)(left.B * right.B / 255.0f);
result.A = (byte)(left.A * right.A / 255);
result.R = (byte)(left.R * right.R / 255);
result.G = (byte)(left.G * right.G / 255);
result.B = (byte)(left.B * right.B / 255);
}

/// <summary>
@@ -499,7 +499,7 @@ public static void Modulate(ref ColorBGRA left, ref ColorBGRA right, out ColorBG
/// <returns>The modulated color.</returns>
public static ColorBGRA Modulate(ColorBGRA left, ColorBGRA right)
{
return new ColorBGRA((left.R * right.R) >> 8, (left.G * right.G) >> 8, (left.B * right.B) >> 8, (left.A * right.A) >> 8);
return new ColorBGRA((byte)((left.R * right.R) / 255), (byte)((left.G * right.G) / 255), (byte)((left.B * right.B) / 255), (byte)((left.A * right.A) / 255));
}

/// <summary>
@@ -547,7 +547,7 @@ public static void Negate(ref ColorBGRA value, out ColorBGRA result)
/// <returns>The negated color.</returns>
public static ColorBGRA Negate(ColorBGRA value)
{
return new ColorBGRA(255 - value.R, 255 - value.G, 255 - value.B, 255 - value.A);
return new ColorBGRA((byte)(255 - value.R), (byte)(255 - value.G), (byte)(255 - value.B), (byte)(255 - value.A));
}

/// <summary>
@@ -778,7 +778,7 @@ public static ColorBGRA AdjustSaturation(ColorBGRA value, float saturation)
/// <returns>The sum of the two colors.</returns>
public static ColorBGRA operator +(ColorBGRA left, ColorBGRA right)
{
return new ColorBGRA(left.R + right.R, left.G + right.G, left.B + right.B, left.A + right.A);
return new ColorBGRA((byte)(left.R + right.R), (byte)(left.G + right.G), (byte)(left.B + right.B), (byte)(left.A + right.A));
}

/// <summary>
@@ -799,7 +799,7 @@ public static ColorBGRA AdjustSaturation(ColorBGRA value, float saturation)
/// <returns>The difference of the two colors.</returns>
public static ColorBGRA operator -(ColorBGRA left, ColorBGRA right)
{
return new ColorBGRA(left.R - right.R, left.G - right.G, left.B - right.B, left.A - right.A);
return new ColorBGRA((byte)(left.R - right.R), (byte)(left.G - right.G), (byte)(left.B - right.B), (byte)(left.A - right.A));
}

/// <summary>

0 comments on commit 8133146

Please sign in to comment.
You can’t perform that action at this time.