Browse Source

Add LMS and Lch tests

pull/2739/head
James Jackson-South 2 years ago
parent
commit
f37ac8e704
  1. 9
      src/ImageSharp/ColorProfiles/CieLch.cs
  2. 70
      tests/ImageSharp.Tests/ColorProfiles/CieLabAndLmsConversionTests.cs
  3. 71
      tests/ImageSharp.Tests/ColorProfiles/CieLchAndCieLuvConversionTests.cs

9
src/ImageSharp/ColorProfiles/CieLch.cs

@ -12,12 +12,6 @@ namespace SixLabors.ImageSharp.ColorProfiles;
/// </summary>
public readonly struct CieLch : IColorProfile<CieLch, CieLab>
{
/// <summary>
/// D50 standard illuminant.
/// Used when reference white is not specified explicitly.
/// </summary>
public static readonly CieXyz DefaultWhitePoint = Illuminants.D50;
private static readonly Vector3 Min = new(0, -200, 0);
private static readonly Vector3 Max = new(100, 200, 360);
@ -165,5 +159,6 @@ public readonly struct CieLch : IColorProfile<CieLch, CieLab>
}
/// <inheritdoc/>
public static ChromaticAdaptionWhitePointSource GetChromaticAdaptionWhitePointSource() => ChromaticAdaptionWhitePointSource.WhitePoint;
public static ChromaticAdaptionWhitePointSource GetChromaticAdaptionWhitePointSource()
=> ChromaticAdaptionWhitePointSource.WhitePoint;
}

70
tests/ImageSharp.Tests/ColorProfiles/CieLabAndLmsConversionTests.cs

@ -0,0 +1,70 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.ColorProfiles;
namespace SixLabors.ImageSharp.Tests.ColorProfiles;
/// <summary>
/// Tests <see cref="CieLab"/>-<see cref="Lms"/> conversions.
/// </summary>
public class CieLabAndLmsConversionTests
{
private static readonly ApproximateColorProfileComparer Comparer = new(.0002f);
[Theory]
[InlineData(0, 0, 0, 0, 0, 0)]
[InlineData(0.8303261, -0.5776886, 0.1133359, 30.66193, 291.57209, -11.25262)]
public void Convert_Lms_to_CieLab(float l2, float m, float s, float l, float a, float b)
{
// Arrange
Lms input = new(l2, m, s);
CieLab expected = new(l, a, b);
ColorProfileConverter converter = new();
Span<Lms> inputSpan = new Lms[5];
inputSpan.Fill(input);
Span<CieLab> actualSpan = new CieLab[5];
// Act
CieLab actual = converter.Convert<Lms, CieLab>(input);
converter.Convert<Lms, CieLab>(inputSpan, actualSpan);
// Assert
Assert.Equal(expected, actual, Comparer);
for (int i = 0; i < actualSpan.Length; i++)
{
Assert.Equal(expected, actualSpan[i], Comparer);
}
}
[Theory]
[InlineData(0, 0, 0, 0, 0, 0)]
[InlineData(30.66193, 291.57209, -11.25262, 0.8303261, -0.5776886, 0.1133359)]
public void Convert_CieLab_to_Lms(float l, float a, float b, float l2, float m, float s)
{
// Arrange
CieLab input = new(l, a, b);
Lms expected = new(l2, m, s);
ColorProfileConverter converter = new();
Span<CieLab> inputSpan = new CieLab[5];
inputSpan.Fill(input);
Span<Lms> actualSpan = new Lms[5];
// Act
Lms actual = converter.Convert<CieLab, Lms>(input);
converter.Convert<CieLab, Lms>(inputSpan, actualSpan);
// Assert
Assert.Equal(expected, actual, Comparer);
for (int i = 0; i < actualSpan.Length; i++)
{
Assert.Equal(expected, actualSpan[i], Comparer);
}
}
}

71
tests/ImageSharp.Tests/ColorProfiles/CieLchAndCieLuvConversionTests.cs

@ -0,0 +1,71 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.ColorProfiles;
namespace SixLabors.ImageSharp.Tests.ColorProfiles;
/// <summary>
/// Tests <see cref="CieLch"/>-<see cref="CieLuv"/> conversions.
/// </summary>
public class CieLchAndCieLuvConversionTests
{
private static readonly ApproximateColorProfileComparer Comparer = new(.0002f);
[Theory]
[InlineData(0, 0, 0, 0, 0, 0)]
[InlineData(36.0555, 103.6901, 10.01514, 34.89777, 187.6642, -7.181467)]
public void Convert_CieLch_to_CieLuv(float l, float c, float h, float l2, float u, float v)
{
// Arrange
CieLch input = new(l, c, h);
CieLuv expected = new(l2, u, v);
ColorConversionOptions options = new() { WhitePoint = Illuminants.D50, TargetWhitePoint = Illuminants.D65 };
ColorProfileConverter converter = new(options);
Span<CieLch> inputSpan = new CieLch[5];
inputSpan.Fill(input);
Span<CieLuv> actualSpan = new CieLuv[5];
// Act
CieLuv actual = converter.Convert<CieLch, CieLuv>(input);
converter.Convert<CieLch, CieLuv>(inputSpan, actualSpan);
// Assert
Assert.Equal(expected, actual, Comparer);
for (int i = 0; i < actualSpan.Length; i++)
{
Assert.Equal(expected, actualSpan[i], Comparer);
}
}
[Theory]
[InlineData(34.89777, 187.6642, -7.181467, 36.0555, 103.6901, 10.01514)]
public void Convert_CieLuv_to_CieLch(float l2, float u, float v, float l, float c, float h)
{
// Arrange
CieLuv input = new(l2, u, v);
CieLch expected = new(l, c, h);
ColorConversionOptions options = new() { WhitePoint = Illuminants.D65, TargetWhitePoint = Illuminants.D50 };
ColorProfileConverter converter = new(options);
Span<CieLuv> inputSpan = new CieLuv[5];
inputSpan.Fill(input);
Span<CieLch> actualSpan = new CieLch[5];
// Act
CieLch actual = converter.Convert<CieLuv, CieLch>(input);
converter.Convert<CieLuv, CieLch>(inputSpan, actualSpan);
// Assert
Assert.Equal(expected, actual, Comparer);
for (int i = 0; i < actualSpan.Length; i++)
{
Assert.Equal(expected, actualSpan[i], Comparer);
}
}
}
Loading…
Cancel
Save