Skip to content

Commit ec14dc2

Browse files
Create CieLchuvAndCmykConversionTests.cs
1 parent 00162b6 commit ec14dc2

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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="CieLchuv"/>-<see cref="Cmyk"/> conversions.
10+
/// </summary>
11+
public class CieLchuvAndCmykConversionTests
12+
{
13+
private static readonly ApproximateColorProfileComparer Comparer = new(.0001F);
14+
15+
[Theory]
16+
[InlineData(0, 0, 0, 1, 0, 0, 0)]
17+
[InlineData(0, 0.8576171, 0.7693201, 0.3440427, 36.0555, 103.6901, 10.01514)]
18+
public void Convert_Cmyk_to_CieLchuv(float c2, float m, float y, float k, float l, float c, float h)
19+
{
20+
// Arrange
21+
Cmyk input = new(c2, m, y, k);
22+
CieLchuv expected = new(l, c, h);
23+
ColorConversionOptions options = new() { WhitePoint = Illuminants.D65, TargetWhitePoint = Illuminants.D65 };
24+
ColorProfileConverter converter = new(options);
25+
26+
Span<Cmyk> inputSpan = new Cmyk[5];
27+
inputSpan.Fill(input);
28+
29+
Span<CieLchuv> actualSpan = new CieLchuv[5];
30+
31+
// Act
32+
CieLchuv actual = converter.Convert<Cmyk, CieLchuv>(input);
33+
converter.Convert<Cmyk, CieLchuv>(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(0, 0, 0, 0, 0, 0, 1)]
46+
[InlineData(36.0555, 103.6901, 10.01514, 0, 0.8576171, 0.7693201, 0.3440427)]
47+
public void Convert_CieLchuv_to_Cmyk(float l, float c, float h, float c2, float m, float y, float k)
48+
{
49+
// Arrange
50+
CieLchuv input = new(l, c, h);
51+
Cmyk expected = new(c2, m, y, k);
52+
ColorConversionOptions options = new() { WhitePoint = Illuminants.D65, TargetWhitePoint = Illuminants.D65 };
53+
ColorProfileConverter converter = new(options);
54+
55+
Span<CieLchuv> inputSpan = new CieLchuv[5];
56+
inputSpan.Fill(input);
57+
58+
Span<Cmyk> actualSpan = new Cmyk[5];
59+
60+
// Act
61+
Cmyk actual = converter.Convert<CieLchuv, Cmyk>(input);
62+
converter.Convert<CieLchuv, Cmyk>(inputSpan, actualSpan);
63+
64+
// Assert
65+
Assert.Equal(expected, actual, Comparer);
66+
67+
for (int i = 0; i < actualSpan.Length; i++)
68+
{
69+
Assert.Equal(expected, actualSpan[i], Comparer);
70+
}
71+
}
72+
}

0 commit comments

Comments
 (0)