Browse Source

Add clamping and more struct tests

af/merge-core
James Jackson-South 7 years ago
parent
commit
02f7339ee6
  1. 12
      src/ImageSharp/ColorSpaces/CieLab.cs
  2. 11
      src/ImageSharp/ColorSpaces/CieLch.cs
  3. 13
      src/ImageSharp/ColorSpaces/CieLchuv.cs
  4. 9
      src/ImageSharp/ColorSpaces/CieLuv.cs
  5. 4
      src/ImageSharp/ColorSpaces/CieXyz.cs
  6. 5
      src/ImageSharp/ColorSpaces/Cmyk.cs
  7. 8
      src/ImageSharp/ColorSpaces/Hsl.cs
  8. 8
      src/ImageSharp/ColorSpaces/Hsv.cs
  9. 5
      src/ImageSharp/ColorSpaces/HunterLab.cs
  10. 5
      src/ImageSharp/ColorSpaces/LinearRgb.cs
  11. 4
      src/ImageSharp/ColorSpaces/Lms.cs
  12. 12
      src/ImageSharp/ColorSpaces/Rgb.cs
  13. 8
      src/ImageSharp/ColorSpaces/YCbCr.cs
  14. 34
      src/ImageSharp/Common/Extensions/ComparableExtensions.cs
  15. 43
      tests/ImageSharp.Tests/Colorspaces/CieLabTests.cs
  16. 39
      tests/ImageSharp.Tests/Colorspaces/CieLchTests.cs
  17. 39
      tests/ImageSharp.Tests/Colorspaces/CieLchuvTests.cs
  18. 39
      tests/ImageSharp.Tests/Colorspaces/CieLuvTests.cs
  19. 39
      tests/ImageSharp.Tests/Colorspaces/CieXyyTests.cs
  20. 39
      tests/ImageSharp.Tests/Colorspaces/CieXyzTests.cs
  21. 41
      tests/ImageSharp.Tests/Colorspaces/CmykTests.cs
  22. 162
      tests/ImageSharp.Tests/Colorspaces/ColorSpaceEqualityTests.cs
  23. 11
      tests/ImageSharp.Tests/Colorspaces/Conversion/CieXyzAndLmsConversionTest.cs
  24. 39
      tests/ImageSharp.Tests/Colorspaces/HslTests.cs
  25. 39
      tests/ImageSharp.Tests/Colorspaces/HsvTests.cs
  26. 43
      tests/ImageSharp.Tests/Colorspaces/HunterLabTests.cs
  27. 42
      tests/ImageSharp.Tests/Colorspaces/LinearRgbTests.cs
  28. 43
      tests/ImageSharp.Tests/Colorspaces/LmsTests.cs
  29. 42
      tests/ImageSharp.Tests/Colorspaces/YCbCrTests.cs

12
src/ImageSharp/ColorSpaces/CieLab.cs

@ -21,19 +21,19 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// <summary>
/// Gets the lightness dimension.
/// <remarks>A value ranging between 0 (black), 100 (diffuse white) or higher (specular white).</remarks>
/// <remarks>A value usually ranging between 0 (black), 100 (diffuse white) or higher (specular white).</remarks>
/// </summary>
public readonly float L;
/// <summary>
/// Gets the a color component.
/// <remarks>A value ranging from -100 to 100. Negative is green, positive magenta.</remarks>
/// <remarks>A value usually ranging from -100 to 100. Negative is green, positive magenta.</remarks>
/// </summary>
public readonly float A;
/// <summary>
/// Gets the b color component.
/// <remarks>A value ranging from -100 to 100. Negative is blue, positive is yellow</remarks>
/// <remarks>A value usually ranging from -100 to 100. Negative is blue, positive is yellow</remarks>
/// </summary>
public readonly float B;
@ -64,11 +64,8 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// <param name="whitePoint">The reference white point. <see cref="Illuminants"/></param>
[MethodImpl(InliningOptions.ShortMethod)]
public CieLab(float l, float a, float b, CieXyz whitePoint)
: this(new Vector3(l, a, b), whitePoint)
{
this.L = l;
this.A = a;
this.B = b;
this.WhitePoint = whitePoint;
}
/// <summary>
@ -91,6 +88,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
public CieLab(Vector3 vector, CieXyz whitePoint)
: this()
{
// Not clamping as documentation about this space seems to indicate "usual" ranges
this.L = vector.X;
this.A = vector.Y;
this.B = vector.Z;

11
src/ImageSharp/ColorSpaces/CieLch.cs

@ -13,6 +13,9 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// </summary>
public readonly struct CieLch : IEquatable<CieLch>
{
private static readonly Vector3 Min = Vector3.Zero;
private static readonly Vector3 Max = new Vector3(100, 200, 360);
/// <summary>
/// D50 standard illuminant.
/// Used when reference white is not specified explicitly.
@ -27,7 +30,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// <summary>
/// Gets the a chroma component.
/// <remarks>A value ranging from 0 to 100.</remarks>
/// <remarks>A value ranging from 0 to 200.</remarks>
/// </summary>
public readonly float C;
@ -64,11 +67,8 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// <param name="whitePoint">The reference white point. <see cref="Illuminants"/></param>
[MethodImpl(InliningOptions.ShortMethod)]
public CieLch(float l, float c, float h, CieXyz whitePoint)
: this(new Vector3(l, c, h), whitePoint)
{
this.L = l;
this.C = c;
this.H = h;
this.WhitePoint = whitePoint;
}
/// <summary>
@ -90,6 +90,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
[MethodImpl(InliningOptions.ShortMethod)]
public CieLch(Vector3 vector, CieXyz whitePoint)
{
vector = Vector3.Clamp(vector, Min, Max);
this.L = vector.X;
this.C = vector.Y;
this.H = vector.Z;

13
src/ImageSharp/ColorSpaces/CieLchuv.cs

@ -9,10 +9,13 @@ namespace SixLabors.ImageSharp.ColorSpaces
{
/// <summary>
/// Represents the CIE L*C*h°, cylindrical form of the CIE L*u*v* 1976 color.
/// <see href="https://en.wikipedia.org/wiki/Lab_color_space#Cylindrical_representation:_CieLchuv_or_CIEHLC"/>
/// <see href="https://en.wikipedia.org/wiki/CIELAB_color_space#Cylindrical_representation:_CIELCh_or_CIEHLC"/>
/// </summary>
public readonly struct CieLchuv : IEquatable<CieLchuv>
{
private static readonly Vector3 Min = Vector3.Zero;
private static readonly Vector3 Max = new Vector3(100, 200, 360);
/// <summary>
/// D50 standard illuminant.
/// Used when reference white is not specified explicitly.
@ -27,7 +30,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// <summary>
/// Gets the a chroma component.
/// <remarks>A value ranging from 0 to 100.</remarks>
/// <remarks>A value ranging from 0 to 200.</remarks>
/// </summary>
public readonly float C;
@ -64,11 +67,8 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// <param name="whitePoint">The reference white point. <see cref="Illuminants"/></param>
[MethodImpl(InliningOptions.ShortMethod)]
public CieLchuv(float l, float c, float h, CieXyz whitePoint)
: this(new Vector3(l, c, h), whitePoint)
{
this.L = l;
this.C = c;
this.H = h;
this.WhitePoint = whitePoint;
}
/// <summary>
@ -91,6 +91,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
public CieLchuv(Vector3 vector, CieXyz whitePoint)
: this()
{
vector = Vector3.Clamp(vector, Min, Max);
this.L = vector.X;
this.C = vector.Y;
this.H = vector.Z;

9
src/ImageSharp/ColorSpaces/CieLuv.cs

@ -15,6 +15,9 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// </summary>
public readonly struct CieLuv : IEquatable<CieLuv>
{
private static readonly Vector3 Min = new Vector3(0, -100, -100);
private static readonly Vector3 Max = new Vector3(100, 100, 100);
/// <summary>
/// D65 standard illuminant.
/// Used when reference white is not specified explicitly.
@ -66,11 +69,8 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// <param name="whitePoint">The reference white point. <see cref="Illuminants"/></param>
[MethodImpl(InliningOptions.ShortMethod)]
public CieLuv(float l, float u, float v, CieXyz whitePoint)
: this(new Vector3(l, u, v), whitePoint)
{
this.L = l;
this.U = u;
this.V = v;
this.WhitePoint = whitePoint;
}
/// <summary>
@ -92,6 +92,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
[MethodImpl(InliningOptions.ShortMethod)]
public CieLuv(Vector3 vector, CieXyz whitePoint)
{
vector = Vector3.Clamp(vector, Min, Max);
this.L = vector.X;
this.U = vector.Y;
this.V = vector.Z;

4
src/ImageSharp/ColorSpaces/CieXyz.cs

@ -41,10 +41,6 @@ namespace SixLabors.ImageSharp.ColorSpaces
public CieXyz(float x, float y, float z)
: this(new Vector3(x, y, z))
{
// Not clamping as documentation about this space seems to indicate "usual" ranges
this.X = x;
this.Y = y;
this.Z = z;
}
/// <summary>

5
src/ImageSharp/ColorSpaces/Cmyk.cs

@ -12,6 +12,9 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// </summary>
public readonly struct Cmyk : IEquatable<Cmyk>
{
private static readonly Vector4 Min = Vector4.Zero;
private static readonly Vector4 Max = Vector4.One;
/// <summary>
/// Gets the cyan color component.
/// <remarks>A value ranging between 0 and 1.</remarks>
@ -56,7 +59,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
[MethodImpl(InliningOptions.ShortMethod)]
public Cmyk(Vector4 vector)
{
vector = Vector4.Clamp(vector, Vector4.Zero, Vector4.One);
vector = Vector4.Clamp(vector, Min, Max);
this.C = vector.X;
this.M = vector.Y;
this.Y = vector.Z;

8
src/ImageSharp/ColorSpaces/Hsl.cs

@ -12,10 +12,8 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// </summary>
public readonly struct Hsl : IEquatable<Hsl>
{
/// <summary>
/// Max range used for clamping.
/// </summary>
private static readonly Vector3 VectorMax = new Vector3(360, 1, 1);
private static readonly Vector3 Min = Vector3.Zero;
private static readonly Vector3 Max = new Vector3(360, 1, 1);
/// <summary>
/// Gets the hue component.
@ -54,7 +52,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
[MethodImpl(InliningOptions.ShortMethod)]
public Hsl(Vector3 vector)
{
vector = Vector3.Clamp(vector, Vector3.Zero, VectorMax);
vector = Vector3.Clamp(vector, Min, Max);
this.H = vector.X;
this.S = vector.Y;
this.L = vector.Z;

8
src/ImageSharp/ColorSpaces/Hsv.cs

@ -12,10 +12,8 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// </summary>
public readonly struct Hsv : IEquatable<Hsv>
{
/// <summary>
/// Max range used for clamping.
/// </summary>
private static readonly Vector3 VectorMax = new Vector3(360, 1, 1);
private static readonly Vector3 Min = Vector3.Zero;
private static readonly Vector3 Max = new Vector3(360, 1, 1);
/// <summary>
/// Gets the hue component.
@ -54,7 +52,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
[MethodImpl(InliningOptions.ShortMethod)]
public Hsv(Vector3 vector)
{
vector = Vector3.Clamp(vector, Vector3.Zero, VectorMax);
vector = Vector3.Clamp(vector, Min, Max);
this.H = vector.X;
this.S = vector.Y;
this.V = vector.Z;

5
src/ImageSharp/ColorSpaces/HunterLab.cs

@ -13,6 +13,9 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// </summary>
public readonly struct HunterLab : IEquatable<HunterLab>
{
private static readonly Vector3 Min = new Vector3(0, -100, -100);
private static readonly Vector3 Max = new Vector3(100, 100, 100);
/// <summary>
/// D50 standard illuminant.
/// Used when reference white is not specified explicitly.
@ -87,7 +90,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
[MethodImpl(InliningOptions.ShortMethod)]
public HunterLab(Vector3 vector, CieXyz whitePoint)
{
// TODO: Clamp?
vector = Vector3.Clamp(vector, Min, Max);
this.L = vector.X;
this.A = vector.Y;
this.B = vector.Z;

5
src/ImageSharp/ColorSpaces/LinearRgb.cs

@ -13,6 +13,9 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// </summary>
public readonly struct LinearRgb : IEquatable<LinearRgb>
{
private static readonly Vector3 Min = Vector3.Zero;
private static readonly Vector3 Max = Vector3.One;
/// <summary>
/// The default LinearRgb working space.
/// </summary>
@ -85,7 +88,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
public LinearRgb(Vector3 vector, RgbWorkingSpace workingSpace)
{
// Clamp to 0-1 range.
vector = Vector3.Clamp(vector, Vector3.Zero, Vector3.One);
vector = Vector3.Clamp(vector, Min, Max);
this.R = vector.X;
this.G = vector.Y;
this.B = vector.Z;

4
src/ImageSharp/ColorSpaces/Lms.cs

@ -40,10 +40,8 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// <param name="s">S represents the responsivity at short wavelengths.</param>
[MethodImpl(InliningOptions.ShortMethod)]
public Lms(float l, float m, float s)
: this(new Vector3(l, m, s))
{
this.L = l;
this.M = m;
this.S = s;
}
/// <summary>

12
src/ImageSharp/ColorSpaces/Rgb.cs

@ -14,6 +14,9 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// </summary>
public readonly struct Rgb : IEquatable<Rgb>
{
private static readonly Vector3 Min = Vector3.Zero;
private static readonly Vector3 Max = Vector3.One;
/// <summary>
/// The default rgb working space
/// </summary>
@ -63,12 +66,8 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// <param name="workingSpace">The rgb working space.</param>
[MethodImpl(InliningOptions.ShortMethod)]
public Rgb(float r, float g, float b, RgbWorkingSpace workingSpace)
: this(new Vector3(r, g, b), workingSpace)
{
// Clamp to 0-1 range.
this.R = r.Clamp(0, 1F);
this.G = g.Clamp(0, 1F);
this.B = b.Clamp(0, 1F);
this.WorkingSpace = workingSpace;
}
/// <summary>
@ -89,8 +88,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
[MethodImpl(InliningOptions.ShortMethod)]
public Rgb(Vector3 vector, RgbWorkingSpace workingSpace)
{
// Clamp to 0-1 range.
vector = Vector3.Clamp(vector, Vector3.Zero, Vector3.One);
vector = Vector3.Clamp(vector, Min, Max);
this.R = vector.X;
this.G = vector.Y;
this.B = vector.Z;

8
src/ImageSharp/ColorSpaces/YCbCr.cs

@ -14,10 +14,8 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// </summary>
public readonly struct YCbCr : IEquatable<YCbCr>
{
/// <summary>
/// Vector which is used in clamping to the max value.
/// </summary>
private static readonly Vector3 VectorMax = new Vector3(255F);
private static readonly Vector3 Min = Vector3.Zero;
private static readonly Vector3 Max = new Vector3(255);
/// <summary>
/// Gets the Y luminance component.
@ -56,7 +54,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
[MethodImpl(InliningOptions.ShortMethod)]
public YCbCr(Vector3 vector)
{
vector = Vector3.Clamp(vector, Vector3.Zero, VectorMax);
vector = Vector3.Clamp(vector, Min, Max);
this.Y = vector.X;
this.Cb = vector.Y;
this.Cr = vector.Z;

34
src/ImageSharp/Common/Extensions/ComparableExtensions.cs

@ -20,7 +20,7 @@ namespace SixLabors.ImageSharp
/// <returns>
/// The <see cref="byte"/> representing the clamped value.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[MethodImpl(InliningOptions.ShortMethod)]
public static byte Clamp(this byte value, byte min, byte max)
{
// Order is important here as someone might set min to higher than max.
@ -46,7 +46,7 @@ namespace SixLabors.ImageSharp
/// <returns>
/// The <see cref="int"/> representing the clamped value.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[MethodImpl(InliningOptions.ShortMethod)]
public static uint Clamp(this uint value, uint min, uint max)
{
if (value >= max)
@ -71,7 +71,7 @@ namespace SixLabors.ImageSharp
/// <returns>
/// The <see cref="int"/> representing the clamped value.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[MethodImpl(InliningOptions.ShortMethod)]
public static int Clamp(this int value, int min, int max)
{
if (value >= max)
@ -96,7 +96,7 @@ namespace SixLabors.ImageSharp
/// <returns>
/// The <see cref="float"/> representing the clamped value.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[MethodImpl(InliningOptions.ShortMethod)]
public static float Clamp(this float value, float min, float max)
{
if (value >= max)
@ -121,7 +121,7 @@ namespace SixLabors.ImageSharp
/// <returns>
/// The <see cref="double"/> representing the clamped value.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[MethodImpl(InliningOptions.ShortMethod)]
public static double Clamp(this double value, double min, double max)
{
if (value >= max)
@ -136,27 +136,5 @@ namespace SixLabors.ImageSharp
return value;
}
/// <summary>
/// Converts an <see cref="float"/> to a <see cref="byte"/> first restricting the value between the
/// minimum and maximum allowable ranges.
/// </summary>
/// <param name="value">The <see cref="float"/> this method extends.</param>
/// <returns>The <see cref="byte"/></returns>
public static byte ToByte(this float value)
{
return (byte)value.Clamp(0, 255);
}
/// <summary>
/// Converts an <see cref="double"/> to a <see cref="byte"/> first restricting the value between the
/// minimum and maximum allowable ranges.
/// </summary>
/// <param name="value">The <see cref="double"/> this method extends.</param>
/// <returns>The <see cref="byte"/></returns>
public static byte ToByte(this double value)
{
return (byte)value.Clamp(0, 255);
}
}
}
}

43
tests/ImageSharp.Tests/Colorspaces/CieLabTests.cs

@ -0,0 +1,43 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.ImageSharp.ColorSpaces;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Colorspaces
{
/// <summary>
/// Tests the <see cref="CieLab"/> struct.
/// </summary>
public class CieLabTests
{
[Fact]
public void CieLabConstructorAssignsFields()
{
const float l = 75F;
const float a = -64F;
const float b = 87F;
var cieLab = new CieLab(l, a, b);
Assert.Equal(l, cieLab.L);
Assert.Equal(a, cieLab.A);
Assert.Equal(b, cieLab.B);
}
[Fact]
public void CieLabEquality()
{
var x = default(CieLab);
var y = new CieLab(Vector3.One);
Assert.True(default(CieLab) == default(CieLab));
Assert.True(default(CieLab) != new CieLab(1, 0, 1));
Assert.False(default(CieLab) == new CieLab(1, 0, 1));
Assert.Equal(default(CieLab), default(CieLab));
Assert.Equal(new CieLab(1, 0, 1), new CieLab(1, 0, 1));
Assert.Equal(new CieLab(Vector3.One), new CieLab(Vector3.One));
Assert.False(x.Equals(y));
}
}
}

39
tests/ImageSharp.Tests/Colorspaces/CieLchTests.cs

@ -0,0 +1,39 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.ImageSharp.ColorSpaces;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Colorspaces
{
/// <summary>
/// Tests the <see cref="CieLch"/> struct.
/// </summary>
public class CieLchTests
{
[Fact]
public void CieLchConstructorAssignsFields()
{
const float l = 75F;
const float c = 64F;
const float h = 287F;
var cieLch = new CieLch(l, c, h);
Assert.Equal(l, cieLch.L);
Assert.Equal(c, cieLch.C);
Assert.Equal(h, cieLch.H);
}
[Fact]
public void CieLchEquality()
{
var x = default(CieLch);
var y = new CieLch(Vector3.One);
Assert.Equal(default(CieLch), default(CieLch));
Assert.Equal(new CieLch(1, 0, 1), new CieLch(1, 0, 1));
Assert.Equal(new CieLch(Vector3.One), new CieLch(Vector3.One));
Assert.False(x.Equals(y));
}
}
}

39
tests/ImageSharp.Tests/Colorspaces/CieLchuvTests.cs

@ -0,0 +1,39 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.ImageSharp.ColorSpaces;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Colorspaces
{
/// <summary>
/// Tests the <see cref="CieLchuv"/> struct.
/// </summary>
public class CieLchuvTests
{
[Fact]
public void CieLchuvConstructorAssignsFields()
{
const float l = 75F;
const float c = 64F;
const float h = 287F;
var cieLchuv = new CieLchuv(l, c, h);
Assert.Equal(l, cieLchuv.L);
Assert.Equal(c, cieLchuv.C);
Assert.Equal(h, cieLchuv.H);
}
[Fact]
public void CieLchuvEquality()
{
var x = default(CieLchuv);
var y = new CieLchuv(Vector3.One);
Assert.Equal(default(CieLchuv), default(CieLchuv));
Assert.Equal(new CieLchuv(1, 0, 1), new CieLchuv(1, 0, 1));
Assert.Equal(new CieLchuv(Vector3.One), new CieLchuv(Vector3.One));
Assert.False(x.Equals(y));
}
}
}

39
tests/ImageSharp.Tests/Colorspaces/CieLuvTests.cs

@ -0,0 +1,39 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.ImageSharp.ColorSpaces;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Colorspaces
{
/// <summary>
/// Tests the <see cref="CieLuv"/> struct.
/// </summary>
public class CieLuvTests
{
[Fact]
public void CieLuvConstructorAssignsFields()
{
const float l = 75F;
const float c = -64F;
const float h = 87F;
var cieLuv = new CieLuv(l, c, h);
Assert.Equal(l, cieLuv.L);
Assert.Equal(c, cieLuv.U);
Assert.Equal(h, cieLuv.V);
}
[Fact]
public void CieLuvEquality()
{
var x = default(CieLuv);
var y = new CieLuv(Vector3.One);
Assert.Equal(default(CieLuv), default(CieLuv));
Assert.Equal(new CieLuv(1, 0, 1), new CieLuv(1, 0, 1));
Assert.Equal(new CieLuv(Vector3.One), new CieLuv(Vector3.One));
Assert.False(x.Equals(y));
}
}
}

39
tests/ImageSharp.Tests/Colorspaces/CieXyyTests.cs

@ -0,0 +1,39 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.ImageSharp.ColorSpaces;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Colorspaces
{
/// <summary>
/// Tests the <see cref="CieXyy"/> struct.
/// </summary>
public class CieXyyTests
{
[Fact]
public void CieXyyConstructorAssignsFields()
{
const float x = 75F;
const float y = 64F;
const float yl = 287F;
var cieXyy = new CieXyy(x, y, yl);
Assert.Equal(x, cieXyy.X);
Assert.Equal(y, cieXyy.Y);
Assert.Equal(y, cieXyy.Y);
}
[Fact]
public void CieXyyEquality()
{
var x = default(CieXyy);
var y = new CieXyy(Vector3.One);
Assert.Equal(default(CieXyy), default(CieXyy));
Assert.Equal(new CieXyy(1, 0, 1), new CieXyy(1, 0, 1));
Assert.Equal(new CieXyy(Vector3.One), new CieXyy(Vector3.One));
Assert.False(x.Equals(y));
}
}
}

39
tests/ImageSharp.Tests/Colorspaces/CieXyzTests.cs

@ -0,0 +1,39 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.ImageSharp.ColorSpaces;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Colorspaces
{
/// <summary>
/// Tests the <see cref="CieXyz"/> struct.
/// </summary>
public class CieXyzTests
{
[Fact]
public void CieXyzConstructorAssignsFields()
{
const float x = 75F;
const float y = 64F;
const float z = 287F;
var cieXyz = new CieXyz(x, y, z);
Assert.Equal(x, cieXyz.X);
Assert.Equal(y, cieXyz.Y);
Assert.Equal(z, cieXyz.Z);
}
[Fact]
public void CieXyzEquality()
{
var x = default(CieXyz);
var y = new CieXyz(Vector3.One);
Assert.Equal(default(CieXyz), default(CieXyz));
Assert.Equal(new CieXyz(1, 0, 1), new CieXyz(1, 0, 1));
Assert.Equal(new CieXyz(Vector3.One), new CieXyz(Vector3.One));
Assert.False(x.Equals(y));
}
}
}

41
tests/ImageSharp.Tests/Colorspaces/CmykTests.cs

@ -0,0 +1,41 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.ImageSharp.ColorSpaces;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Colorspaces
{
/// <summary>
/// Tests the <see cref="Cmyk"/> struct.
/// </summary>
public class CmykTests
{
[Fact]
public void CmykConstructorAssignsFields()
{
const float c = .75F;
const float m = .64F;
const float y = .87F;
const float k = .334F;
var cmyk = new Cmyk(c, m, y, k);
Assert.Equal(c, cmyk.C);
Assert.Equal(m, cmyk.M);
Assert.Equal(y, cmyk.Y);
Assert.Equal(k, cmyk.K);
}
[Fact]
public void CmykEquality()
{
var x = default(Cmyk);
var y = new Cmyk(Vector4.One);
Assert.Equal(default(Cmyk), default(Cmyk));
Assert.Equal(new Cmyk(1, 0, 1, 0), new Cmyk(1, 0, 1, 0));
Assert.Equal(new Cmyk(Vector4.One), new Cmyk(Vector4.One));
Assert.False(x.Equals(y));
}
}
}

162
tests/ImageSharp.Tests/Colorspaces/ColorSpaceEqualityTests.cs

@ -1,162 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.ImageSharp.ColorSpaces;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Colorspaces
{
/// <summary>
/// Test implementations of IEquatable and IAlmostEquatable in our colorspaces
/// </summary>
public class ColorSpaceEqualityTests
{
[Fact]
public void CieLabEquality()
{
var x = default(CieLab);
var y = new CieLab(Vector3.One);
Assert.True(default(CieLab) == default(CieLab));
Assert.True(default(CieLab) != new CieLab(1, 0, 1));
Assert.False(default(CieLab) == new CieLab(1, 0, 1));
Assert.Equal(default(CieLab), default(CieLab));
Assert.Equal(new CieLab(1, 0, 1), new CieLab(1, 0, 1));
Assert.Equal(new CieLab(Vector3.One), new CieLab(Vector3.One));
Assert.False(x.Equals(y));
}
[Fact]
public void CieLchEquality()
{
var x = default(CieLch);
var y = new CieLch(Vector3.One);
Assert.Equal(default(CieLch), default(CieLch));
Assert.Equal(new CieLch(1, 0, 1), new CieLch(1, 0, 1));
Assert.Equal(new CieLch(Vector3.One), new CieLch(Vector3.One));
Assert.False(x.Equals(y));
}
[Fact]
public void CieLchuvEquality()
{
var x = default(CieLchuv);
var y = new CieLchuv(Vector3.One);
Assert.Equal(default(CieLchuv), default(CieLchuv));
Assert.Equal(new CieLchuv(1, 0, 1), new CieLchuv(1, 0, 1));
Assert.Equal(new CieLchuv(Vector3.One), new CieLchuv(Vector3.One));
Assert.False(x.Equals(y));
}
[Fact]
public void CieLuvEquality()
{
var x = default(CieLuv);
var y = new CieLuv(Vector3.One);
Assert.Equal(default(CieLuv), default(CieLuv));
Assert.Equal(new CieLuv(1, 0, 1), new CieLuv(1, 0, 1));
Assert.Equal(new CieLuv(Vector3.One), new CieLuv(Vector3.One));
Assert.False(x.Equals(y));
}
[Fact]
public void CieXyzEquality()
{
var x = default(CieXyz);
var y = new CieXyz(Vector3.One);
Assert.Equal(default(CieXyz), default(CieXyz));
Assert.Equal(new CieXyz(1, 0, 1), new CieXyz(1, 0, 1));
Assert.Equal(new CieXyz(Vector3.One), new CieXyz(Vector3.One));
Assert.False(x.Equals(y));
}
[Fact]
public void CieXyyEquality()
{
var x = default(CieXyy);
var y = new CieXyy(Vector3.One);
Assert.Equal(default(CieXyy), default(CieXyy));
Assert.Equal(new CieXyy(1, 0, 1), new CieXyy(1, 0, 1));
Assert.Equal(new CieXyy(Vector3.One), new CieXyy(Vector3.One));
Assert.False(x.Equals(y));
}
[Fact]
public void HslEquality()
{
var x = default(Hsl);
var y = new Hsl(Vector3.One);
Assert.Equal(default(Hsl), default(Hsl));
Assert.Equal(new Hsl(1, 0, 1), new Hsl(1, 0, 1));
Assert.Equal(new Hsl(Vector3.One), new Hsl(Vector3.One));
Assert.False(x.Equals(y));
}
[Fact]
public void HsvEquality()
{
var x = default(Hsv);
var y = new Hsv(Vector3.One);
Assert.Equal(default(Hsv), default(Hsv));
Assert.Equal(new Hsv(1, 0, 1), new Hsv(1, 0, 1));
Assert.Equal(new Hsv(Vector3.One), new Hsv(Vector3.One));
Assert.False(x.Equals(y));
}
[Fact]
public void HunterLabEquality()
{
var x = default(HunterLab);
var y = new HunterLab(Vector3.One);
Assert.Equal(default(HunterLab), default(HunterLab));
Assert.Equal(new HunterLab(1, 0, 1), new HunterLab(1, 0, 1));
Assert.Equal(new HunterLab(Vector3.One), new HunterLab(Vector3.One));
Assert.False(x.Equals(y));
}
[Fact]
public void LmsEquality()
{
var x = default(Lms);
var y = new Lms(Vector3.One);
Assert.Equal(default(Lms), default(Lms));
Assert.Equal(new Lms(1, 0, 1), new Lms(1, 0, 1));
Assert.Equal(new Lms(Vector3.One), new Lms(Vector3.One));
Assert.False(x.Equals(y));
}
[Fact]
public void LinearRgbEquality()
{
var x = default(LinearRgb);
var y = new LinearRgb(Vector3.One);
Assert.Equal(default(LinearRgb), default(LinearRgb));
Assert.Equal(new LinearRgb(1, 0, 1), new LinearRgb(1, 0, 1));
Assert.Equal(new LinearRgb(Vector3.One), new LinearRgb(Vector3.One));
Assert.False(x.Equals(y));
}
[Fact]
public void YCbCrEquality()
{
var x = default(YCbCr);
var y = new YCbCr(Vector3.One);
Assert.Equal(default(YCbCr), default(YCbCr));
Assert.Equal(new YCbCr(1, 0, 1), new YCbCr(1, 0, 1));
Assert.Equal(new YCbCr(Vector3.One), new YCbCr(Vector3.One));
Assert.False(x.Equals(y));
}
[Fact]
public void CmykEquality()
{
var x = default(Cmyk);
var y = new Cmyk(Vector4.One);
Assert.Equal(default(Cmyk), default(Cmyk));
Assert.Equal(new Cmyk(1, 0, 1, 0), new Cmyk(1, 0, 1, 0));
Assert.Equal(new Cmyk(Vector4.One), new Cmyk(Vector4.One));
Assert.False(x.Equals(y));
}
}
}

11
tests/ImageSharp.Tests/Colorspaces/Conversion/CieXyzAndLmsConversionTest.cs

@ -70,11 +70,22 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces.Conversion
var converter = new ColorSpaceConverter();
var expected = new Lms(l, m, s);
Span<CieXyz> inputSpan = new CieXyz[5];
inputSpan.Fill(input);
Span<Lms> actualSpan = new Lms[5];
// Act
var actual = converter.ToLms(input);
converter.Convert(inputSpan, actualSpan, actualSpan.Length);
// Assert
Assert.Equal(expected, actual, ColorSpaceComparer);
for (int i = 0; i < actualSpan.Length; i++)
{
Assert.Equal(expected, actualSpan[i], ColorSpaceComparer);
}
}
}
}

39
tests/ImageSharp.Tests/Colorspaces/HslTests.cs

@ -0,0 +1,39 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.ImageSharp.ColorSpaces;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Colorspaces
{
/// <summary>
/// Tests the <see cref="Hsl"/> struct.
/// </summary>
public class HslTests
{
[Fact]
public void HslConstructorAssignsFields()
{
const float h = 275F;
const float s = .64F;
const float l = .87F;
var hsl = new Hsl(h, s, l);
Assert.Equal(h, hsl.H);
Assert.Equal(s, hsl.S);
Assert.Equal(l, hsl.L);
}
[Fact]
public void HslEquality()
{
var x = default(Hsl);
var y = new Hsl(Vector3.One);
Assert.Equal(default(Hsl), default(Hsl));
Assert.Equal(new Hsl(1, 0, 1), new Hsl(1, 0, 1));
Assert.Equal(new Hsl(Vector3.One), new Hsl(Vector3.One));
Assert.False(x.Equals(y));
}
}
}

39
tests/ImageSharp.Tests/Colorspaces/HsvTests.cs

@ -0,0 +1,39 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.ImageSharp.ColorSpaces;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Colorspaces
{
/// <summary>
/// Tests the <see cref="Hsv"/> struct.
/// </summary>
public class HsvTests
{
[Fact]
public void HsvConstructorAssignsFields()
{
const float h = 275F;
const float s = .64F;
const float v = .87F;
var hsv = new Hsv(h, s, v);
Assert.Equal(h, hsv.H);
Assert.Equal(s, hsv.S);
Assert.Equal(v, hsv.V);
}
[Fact]
public void HsvEquality()
{
var x = default(Hsv);
var y = new Hsv(Vector3.One);
Assert.Equal(default(Hsv), default(Hsv));
Assert.Equal(new Hsv(1, 0, 1), new Hsv(1, 0, 1));
Assert.Equal(new Hsv(Vector3.One), new Hsv(Vector3.One));
Assert.False(x.Equals(y));
}
}
}

43
tests/ImageSharp.Tests/Colorspaces/HunterLabTests.cs

@ -0,0 +1,43 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.ImageSharp.ColorSpaces;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Colorspaces
{
/// <summary>
/// Tests the <see cref="HunterLab"/> struct.
/// </summary>
public class HunterLabTests
{
[Fact]
public void HunterLabConstructorAssignsFields()
{
const float l = 75F;
const float a = -64F;
const float b = 87F;
var hunterLab = new HunterLab(l, a, b);
Assert.Equal(l, hunterLab.L);
Assert.Equal(a, hunterLab.A);
Assert.Equal(b, hunterLab.B);
}
[Fact]
public void HunterLabEquality()
{
var x = default(HunterLab);
var y = new HunterLab(Vector3.One);
Assert.True(default(HunterLab) == default(HunterLab));
Assert.True(default(HunterLab) != new HunterLab(1, 0, 1));
Assert.False(default(HunterLab) == new HunterLab(1, 0, 1));
Assert.Equal(default(HunterLab), default(HunterLab));
Assert.Equal(new HunterLab(1, 0, 1), new HunterLab(1, 0, 1));
Assert.Equal(new HunterLab(Vector3.One), new HunterLab(Vector3.One));
Assert.False(x.Equals(y));
}
}
}

42
tests/ImageSharp.Tests/Colorspaces/LinearRgbTests.cs

@ -0,0 +1,42 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.ImageSharp.ColorSpaces;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Colorspaces
{
/// <summary>
/// Tests the <see cref="LinearRgb"/> struct.
/// </summary>
public class LinearRgbTests
{
[Fact]
public void LinearRgbConstructorAssignsFields()
{
const float r = .75F;
const float g = .64F;
const float b = .87F;
var rgb = new LinearRgb(r, g, b);
Assert.Equal(r, rgb.R);
Assert.Equal(g, rgb.G);
Assert.Equal(b, rgb.B);
}
[Fact]
public void LinearRgbEquality()
{
var x = default(LinearRgb);
var y = new LinearRgb(Vector3.One);
Assert.True(default(LinearRgb) == default(LinearRgb));
Assert.False(default(LinearRgb) != default(LinearRgb));
Assert.Equal(default(LinearRgb), default(LinearRgb));
Assert.Equal(new LinearRgb(1, 0, 1), new LinearRgb(1, 0, 1));
Assert.Equal(new LinearRgb(Vector3.One), new LinearRgb(Vector3.One));
Assert.False(x.Equals(y));
}
}
}

43
tests/ImageSharp.Tests/Colorspaces/LmsTests.cs

@ -0,0 +1,43 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.ImageSharp.ColorSpaces;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Colorspaces
{
/// <summary>
/// Tests the <see cref="Lms"/> struct.
/// </summary>
public class LmsTests
{
[Fact]
public void LmsConstructorAssignsFields()
{
const float l = 75F;
const float m = -64F;
const float s = 87F;
var Lms = new Lms(l, m, s);
Assert.Equal(l, Lms.L);
Assert.Equal(m, Lms.M);
Assert.Equal(s, Lms.S);
}
[Fact]
public void LmsEquality()
{
var x = default(Lms);
var y = new Lms(Vector3.One);
Assert.True(default(Lms) == default(Lms));
Assert.True(default(Lms) != new Lms(1, 0, 1));
Assert.False(default(Lms) == new Lms(1, 0, 1));
Assert.Equal(default(Lms), default(Lms));
Assert.Equal(new Lms(1, 0, 1), new Lms(1, 0, 1));
Assert.Equal(new Lms(Vector3.One), new Lms(Vector3.One));
Assert.False(x.Equals(y));
}
}
}

42
tests/ImageSharp.Tests/Colorspaces/YCbCrTests.cs

@ -0,0 +1,42 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.ImageSharp.ColorSpaces;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Colorspaces
{
/// <summary>
/// Tests the <see cref="YCbCr"/> struct.
/// </summary>
public class YCbCrTests
{
[Fact]
public void YCbCrConstructorAssignsFields()
{
const float y = 75F;
const float cb = 64F;
const float cr = 87F;
var yCbCr = new YCbCr(y, cb, cr);
Assert.Equal(y, yCbCr.Y);
Assert.Equal(cb, yCbCr.Cb);
Assert.Equal(cr, yCbCr.Cr);
}
[Fact]
public void YCbCrEquality()
{
var x = default(YCbCr);
var y = new YCbCr(Vector3.One);
Assert.True(default(YCbCr) == default(YCbCr));
Assert.False(default(YCbCr) != default(YCbCr));
Assert.Equal(default(YCbCr), default(YCbCr));
Assert.Equal(new YCbCr(1, 0, 1), new YCbCr(1, 0, 1));
Assert.Equal(new YCbCr(Vector3.One), new YCbCr(Vector3.One));
Assert.False(x.Equals(y));
}
}
}
Loading…
Cancel
Save