Skip to content

Commit 55de3cc

Browse files
Add more LAB tests
1 parent b8c73e1 commit 55de3cc

2 files changed

Lines changed: 152 additions & 0 deletions

File tree

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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.Conversion;
7+
8+
/// <summary>
9+
/// Tests <see cref="CieLab"/>-<see cref="CieLchuv"/> conversions.
10+
/// </summary>
11+
/// <remarks>
12+
/// Test data generated using:
13+
/// <see href="http://www.brucelindbloom.com/index.html?ColorCalculator.html"/>
14+
/// </remarks>
15+
public class CieLabAndCieLchuvConversionTests
16+
{
17+
private static readonly ApproximateColorProfileComparer Comparer = new(.0002F);
18+
19+
[Theory]
20+
[InlineData(0, 0, 0, 0, 0, 0)]
21+
[InlineData(30.66194, 200, 352.7564, 31.95653, 116.8745, 2.388602)]
22+
public void Convert_Lchuv_to_Lab(float l, float c, float h, float l2, float a, float b)
23+
{
24+
// Arrange
25+
CieLchuv input = new(l, c, h);
26+
CieLab expected = new(l2, a, b);
27+
ColorConversionOptions options = new() { WhitePoint = Illuminants.D65, TargetWhitePoint = Illuminants.D50 };
28+
ColorProfileConverter converter = new(options);
29+
30+
Span<CieLchuv> inputSpan = new CieLchuv[5];
31+
inputSpan.Fill(input);
32+
33+
Span<CieLab> actualSpan = new CieLab[5];
34+
35+
// Act
36+
CieLab actual = converter.Convert<CieLchuv, CieLab>(input);
37+
converter.Convert<CieLchuv, CieLab>(inputSpan, actualSpan);
38+
39+
// Assert
40+
Assert.Equal(expected, actual, Comparer);
41+
42+
for (int i = 0; i < actualSpan.Length; i++)
43+
{
44+
Assert.Equal(expected, actualSpan[i], Comparer);
45+
}
46+
}
47+
48+
[Theory]
49+
[InlineData(0, 0, 0, 0, 0, 0)]
50+
[InlineData(36.0555, 303.6901, 10.01514, 29.4713573, 200, 352.6346)]
51+
public void Convert_Lab_to_Lchuv(float l, float a, float b, float l2, float c, float h)
52+
{
53+
// Arrange
54+
CieLab input = new(l, a, b);
55+
CieLchuv expected = new(l2, c, h);
56+
ColorConversionOptions options = new() { WhitePoint = Illuminants.D50, TargetWhitePoint = Illuminants.D65 };
57+
ColorProfileConverter converter = new(options);
58+
59+
Span<CieLab> inputSpan = new CieLab[5];
60+
inputSpan.Fill(input);
61+
62+
Span<CieLchuv> actualSpan = new CieLchuv[5];
63+
64+
// Act
65+
CieLchuv actual = converter.Convert<CieLab, CieLchuv>(input);
66+
converter.Convert<CieLab, CieLchuv>(inputSpan, actualSpan);
67+
68+
// Assert
69+
Assert.Equal(expected, actual, Comparer);
70+
71+
for (int i = 0; i < actualSpan.Length; i++)
72+
{
73+
Assert.Equal(expected, actualSpan[i], Comparer);
74+
}
75+
}
76+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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.Conversion;
7+
8+
/// <summary>
9+
/// Tests <see cref="CieLab"/>-<see cref="CieLuv"/> conversions.
10+
/// </summary>
11+
/// <remarks>
12+
/// Test data generated using:
13+
/// <see href="http://www.brucelindbloom.com/index.html?ColorCalculator.html"/>
14+
/// </remarks>
15+
public class CieLabAndCieLuvConversionTests
16+
{
17+
private static readonly ApproximateColorProfileComparer Comparer = new(.0002F);
18+
19+
[Theory]
20+
[InlineData(0, 0, 0, 0, 0, 0)]
21+
[InlineData(10, 36.0555, 303.6901, 10.6006718, -17.24077, 82.8835)]
22+
public void Convert_CieLuv_to_CieLab(float l, float u, float v, float l2, float a, float b)
23+
{
24+
// Arrange
25+
CieLuv input = new(l, u, v);
26+
CieLab expected = new(l2, a, b);
27+
ColorConversionOptions options = new() { WhitePoint = Illuminants.D65, TargetWhitePoint = Illuminants.D50 };
28+
ColorProfileConverter converter = new(options);
29+
30+
Span<CieLuv> inputSpan = new CieLuv[5];
31+
inputSpan.Fill(input);
32+
33+
Span<CieLab> actualSpan = new CieLab[5];
34+
35+
// Act
36+
CieLab actual = converter.Convert<CieLuv, CieLab>(input);
37+
converter.Convert<CieLuv, CieLab>(inputSpan, actualSpan);
38+
39+
// Assert
40+
Assert.Equal(expected, actual, Comparer);
41+
42+
for (int i = 0; i < actualSpan.Length; i++)
43+
{
44+
Assert.Equal(expected, actualSpan[i], Comparer);
45+
}
46+
}
47+
48+
[Theory]
49+
[InlineData(0, 0, 0, 0, 0, 0)]
50+
[InlineData(10.0151367, -23.9644356, 17.0226, 10.0000038, -12.830183, 15.1829338)]
51+
public void Convert_CieLab_to_CieLuv(float l, float a, float b, float l2, float u, float v)
52+
{
53+
// Arrange
54+
CieLab input = new(l, a, b);
55+
CieLuv expected = new(l2, u, v);
56+
ColorConversionOptions options = new() { WhitePoint = Illuminants.D50, TargetWhitePoint = Illuminants.D65 };
57+
ColorProfileConverter converter = new(options);
58+
59+
Span<CieLab> inputSpan = new CieLab[5];
60+
inputSpan.Fill(input);
61+
62+
Span<CieLuv> actualSpan = new CieLuv[5];
63+
64+
// Act
65+
CieLuv actual = converter.Convert<CieLab, CieLuv>(input);
66+
converter.Convert<CieLab, CieLuv>(inputSpan, actualSpan);
67+
68+
// Assert
69+
Assert.Equal(expected, actual, Comparer);
70+
71+
for (int i = 0; i < actualSpan.Length; i++)
72+
{
73+
Assert.Equal(expected, actualSpan[i], Comparer);
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)