Skip to content

Commit f37ac8e

Browse files
Add LMS and Lch tests
1 parent 2fbabe8 commit f37ac8e

3 files changed

Lines changed: 143 additions & 7 deletions

File tree

src/ImageSharp/ColorProfiles/CieLch.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ namespace SixLabors.ImageSharp.ColorProfiles;
1212
/// </summary>
1313
public readonly struct CieLch : IColorProfile<CieLch, CieLab>
1414
{
15-
/// <summary>
16-
/// D50 standard illuminant.
17-
/// Used when reference white is not specified explicitly.
18-
/// </summary>
19-
public static readonly CieXyz DefaultWhitePoint = Illuminants.D50;
20-
2115
private static readonly Vector3 Min = new(0, -200, 0);
2216
private static readonly Vector3 Max = new(100, 200, 360);
2317

@@ -165,5 +159,6 @@ public static void ToProfileConnectionSpace(ColorConversionOptions options, Read
165159
}
166160

167161
/// <inheritdoc/>
168-
public static ChromaticAdaptionWhitePointSource GetChromaticAdaptionWhitePointSource() => ChromaticAdaptionWhitePointSource.WhitePoint;
162+
public static ChromaticAdaptionWhitePointSource GetChromaticAdaptionWhitePointSource()
163+
=> ChromaticAdaptionWhitePointSource.WhitePoint;
169164
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Six Labors Split License.
3+
4+
using SixLabors.ImageSharp.ColorProfiles;
5+
6+
namespace SixLabors.ImageSharp.Tests.ColorProfiles;
7+
8+
/// <summary>
9+
/// Tests <see cref="CieLab"/>-<see cref="Lms"/> conversions.
10+
/// </summary>
11+
public class CieLabAndLmsConversionTests
12+
{
13+
private static readonly ApproximateColorProfileComparer Comparer = new(.0002f);
14+
15+
[Theory]
16+
[InlineData(0, 0, 0, 0, 0, 0)]
17+
[InlineData(0.8303261, -0.5776886, 0.1133359, 30.66193, 291.57209, -11.25262)]
18+
public void Convert_Lms_to_CieLab(float l2, float m, float s, float l, float a, float b)
19+
{
20+
// Arrange
21+
Lms input = new(l2, m, s);
22+
CieLab expected = new(l, a, b);
23+
ColorProfileConverter converter = new();
24+
25+
Span<Lms> inputSpan = new Lms[5];
26+
inputSpan.Fill(input);
27+
28+
Span<CieLab> actualSpan = new CieLab[5];
29+
30+
// Act
31+
CieLab actual = converter.Convert<Lms, CieLab>(input);
32+
converter.Convert<Lms, CieLab>(inputSpan, actualSpan);
33+
34+
// Assert
35+
Assert.Equal(expected, actual, Comparer);
36+
37+
for (int i = 0; i < actualSpan.Length; i++)
38+
{
39+
Assert.Equal(expected, actualSpan[i], Comparer);
40+
}
41+
}
42+
43+
[Theory]
44+
[InlineData(0, 0, 0, 0, 0, 0)]
45+
[InlineData(30.66193, 291.57209, -11.25262, 0.8303261, -0.5776886, 0.1133359)]
46+
public void Convert_CieLab_to_Lms(float l, float a, float b, float l2, float m, float s)
47+
{
48+
// Arrange
49+
CieLab input = new(l, a, b);
50+
Lms expected = new(l2, m, s);
51+
ColorProfileConverter converter = new();
52+
53+
Span<CieLab> inputSpan = new CieLab[5];
54+
inputSpan.Fill(input);
55+
56+
Span<Lms> actualSpan = new Lms[5];
57+
58+
// Act
59+
Lms actual = converter.Convert<CieLab, Lms>(input);
60+
converter.Convert<CieLab, Lms>(inputSpan, actualSpan);
61+
62+
// Assert
63+
Assert.Equal(expected, actual, Comparer);
64+
65+
for (int i = 0; i < actualSpan.Length; i++)
66+
{
67+
Assert.Equal(expected, actualSpan[i], Comparer);
68+
}
69+
}
70+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Six Labors Split License.
3+
4+
using SixLabors.ImageSharp.ColorProfiles;
5+
6+
namespace SixLabors.ImageSharp.Tests.ColorProfiles;
7+
8+
/// <summary>
9+
/// Tests <see cref="CieLch"/>-<see cref="CieLuv"/> conversions.
10+
/// </summary>
11+
public class CieLchAndCieLuvConversionTests
12+
{
13+
private static readonly ApproximateColorProfileComparer Comparer = new(.0002f);
14+
15+
[Theory]
16+
[InlineData(0, 0, 0, 0, 0, 0)]
17+
[InlineData(36.0555, 103.6901, 10.01514, 34.89777, 187.6642, -7.181467)]
18+
public void Convert_CieLch_to_CieLuv(float l, float c, float h, float l2, float u, float v)
19+
{
20+
// Arrange
21+
CieLch input = new(l, c, h);
22+
CieLuv expected = new(l2, u, v);
23+
ColorConversionOptions options = new() { WhitePoint = Illuminants.D50, TargetWhitePoint = Illuminants.D65 };
24+
ColorProfileConverter converter = new(options);
25+
26+
Span<CieLch> inputSpan = new CieLch[5];
27+
inputSpan.Fill(input);
28+
29+
Span<CieLuv> actualSpan = new CieLuv[5];
30+
31+
// Act
32+
CieLuv actual = converter.Convert<CieLch, CieLuv>(input);
33+
converter.Convert<CieLch, CieLuv>(inputSpan, actualSpan);
34+
35+
// Assert
36+
Assert.Equal(expected, actual, Comparer);
37+
38+
for (int i = 0; i < actualSpan.Length; i++)
39+
{
40+
Assert.Equal(expected, actualSpan[i], Comparer);
41+
}
42+
}
43+
44+
[Theory]
45+
[InlineData(34.89777, 187.6642, -7.181467, 36.0555, 103.6901, 10.01514)]
46+
public void Convert_CieLuv_to_CieLch(float l2, float u, float v, float l, float c, float h)
47+
{
48+
// Arrange
49+
CieLuv input = new(l2, u, v);
50+
CieLch expected = new(l, c, h);
51+
ColorConversionOptions options = new() { WhitePoint = Illuminants.D65, TargetWhitePoint = Illuminants.D50 };
52+
ColorProfileConverter converter = new(options);
53+
54+
Span<CieLuv> inputSpan = new CieLuv[5];
55+
inputSpan.Fill(input);
56+
57+
Span<CieLch> actualSpan = new CieLch[5];
58+
59+
// Act
60+
CieLch actual = converter.Convert<CieLuv, CieLch>(input);
61+
converter.Convert<CieLuv, CieLch>(inputSpan, actualSpan);
62+
63+
// Assert
64+
Assert.Equal(expected, actual, Comparer);
65+
66+
for (int i = 0; i < actualSpan.Length; i++)
67+
{
68+
Assert.Equal(expected, actualSpan[i], Comparer);
69+
}
70+
}
71+
}

0 commit comments

Comments
 (0)