- Fixed missing alpha clamp in Color.cs/FromNonPremultiplied
- Added TestCase for Random Color generation using Random.
This commit is contained in:
parent
9f4369c05d
commit
82b717c008
@ -404,6 +404,20 @@ namespace ANX.Framework.TestCenter.Strukturen
|
|||||||
AssertHelper.ConvertEquals(xna, anx, "FromNonPremultipliedIntStatic2");
|
AssertHelper.ConvertEquals(xna, anx, "FromNonPremultipliedIntStatic2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void FromNonPremultipliedIntRandom()
|
||||||
|
{
|
||||||
|
Random rand = new Random();
|
||||||
|
int r = rand.Next(255);
|
||||||
|
int g = rand.Next(255);
|
||||||
|
int b = rand.Next(255);
|
||||||
|
int a = 255;
|
||||||
|
XNAColor xna = XNAColor.FromNonPremultiplied(r, g, b, a);
|
||||||
|
ANXColor anx = ANXColor.FromNonPremultiplied(r, g, b, a);
|
||||||
|
|
||||||
|
AssertHelper.ConvertEquals(xna, anx, "FromNonPremultipliedIntStatic2");
|
||||||
|
}
|
||||||
|
|
||||||
[Test, TestCaseSource("fourfloats")]
|
[Test, TestCaseSource("fourfloats")]
|
||||||
public void FromNonPremultipliedVector4Static(float r, float g, float b, float a)
|
public void FromNonPremultipliedVector4Static(float r, float g, float b, float a)
|
||||||
{
|
{
|
||||||
|
@ -811,9 +811,10 @@ namespace ANX.Framework
|
|||||||
{
|
{
|
||||||
Color color;
|
Color color;
|
||||||
|
|
||||||
r = ClampValue((long)r * a / 255L);
|
r = ClampValue64((long)r * a / 255L);
|
||||||
g = ClampValue((long)g * a / 255L);
|
g = ClampValue64((long)g * a / 255L);
|
||||||
b = ClampValue((long)b * a / 255L);
|
b = ClampValue64((long)b * a / 255L);
|
||||||
|
a = ClampValue32(a);
|
||||||
|
|
||||||
/* //What the heck is this? Anyway it does not work!
|
/* //What the heck is this? Anyway it does not work!
|
||||||
if (((((r | g) | b) | a) & -256) != 0)
|
if (((((r | g) | b) | a) & -256) != 0)
|
||||||
@ -829,7 +830,7 @@ namespace ANX.Framework
|
|||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int ClampValue(long value)
|
private static int ClampValue64(long value)
|
||||||
{
|
{
|
||||||
if (value < 0L)
|
if (value < 0L)
|
||||||
return 0;
|
return 0;
|
||||||
@ -838,6 +839,15 @@ namespace ANX.Framework
|
|||||||
return (int) value;
|
return (int) value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int ClampValue32(int value)
|
||||||
|
{
|
||||||
|
if (value < 0)
|
||||||
|
return 0;
|
||||||
|
if (value > 255)
|
||||||
|
return 255;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
public static Color FromNonPremultiplied(Vector4 vector)
|
public static Color FromNonPremultiplied(Vector4 vector)
|
||||||
{
|
{
|
||||||
Color color;
|
Color color;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user