Skip to content

Commit cc49c7a

Browse files
Add Xyy and HSV/HSL tests
1 parent 9d1cb16 commit cc49c7a

File tree

3 files changed

+141
-1
lines changed

3 files changed

+141
-1
lines changed

src/ImageSharp/ColorProfiles/Hsv.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public static Hsv FromProfileConnectingSpace(ColorConversionOptions options, in
112112
}
113113

114114
h *= 60;
115-
if (h < 0.0)
115+
if (h < 0f)
116116
{
117117
h += 360;
118118
}
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="CieXyy"/>-<see cref="Hsl"/> conversions.
10+
/// </summary>
11+
public class CieXyyAndHslConversionTests
12+
{
13+
private static readonly ApproximateColorProfileComparer Comparer = new(.0002F);
14+
15+
[Theory]
16+
[InlineData(0, 0, 0, 0, 0, 0)]
17+
[InlineData(0.360555, 0.936901, 0.1001514, 120, 1, 0.2138507)]
18+
public void Convert_CieXyy_to_Hsl(float x, float y, float yl, float h, float s, float l)
19+
{
20+
// Arrange
21+
CieXyy input = new(x, y, yl);
22+
Hsl expected = new(h, s, l);
23+
ColorProfileConverter converter = new();
24+
25+
Span<CieXyy> inputSpan = new CieXyy[5];
26+
inputSpan.Fill(input);
27+
28+
Span<Hsl> actualSpan = new Hsl[5];
29+
30+
// Act
31+
Hsl actual = converter.Convert<CieXyy, Hsl>(input);
32+
converter.Convert<CieXyy, Hsl>(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(120, 1, 0.2138507, 0.32114, 0.59787, 0.10976)]
46+
public void Convert_Hsl_to_CieXyy(float h, float s, float l, float x, float y, float yl)
47+
{
48+
// Arrange
49+
Hsl input = new(h, s, l);
50+
CieXyy expected = new(x, y, yl);
51+
ColorProfileConverter converter = new();
52+
53+
Span<Hsl> inputSpan = new Hsl[5];
54+
inputSpan.Fill(input);
55+
56+
Span<CieXyy> actualSpan = new CieXyy[5];
57+
58+
// Act
59+
CieXyy actual = converter.Convert<Hsl, CieXyy>(input);
60+
converter.Convert<Hsl, CieXyy>(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: 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="CieXyy"/>-<see cref="Hsv"/> conversions.
10+
/// </summary>
11+
public class CieXyyAndHsvConversionTests
12+
{
13+
private static readonly ApproximateColorProfileComparer Comparer = new(.0002F);
14+
15+
[Theory]
16+
[InlineData(0, 0, 0, 0, 0, 0)]
17+
[InlineData(0.360555, 0.936901, 0.1001514, 120, 1, 0.42770)]
18+
public void Convert_CieXyy_to_Hsv(float x, float y, float yl, float h, float s, float v)
19+
{
20+
// Arrange
21+
CieXyy input = new(x, y, yl);
22+
Hsv expected = new(h, s, v);
23+
ColorProfileConverter converter = new();
24+
25+
Span<CieXyy> inputSpan = new CieXyy[5];
26+
inputSpan.Fill(input);
27+
28+
Span<Hsv> actualSpan = new Hsv[5];
29+
30+
// Act
31+
Hsv actual = converter.Convert<CieXyy, Hsv>(input);
32+
converter.Convert<CieXyy, Hsv>(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(120, 1, 0.42770, 0.32114, 0.59787, 0.10976)]
46+
public void Convert_Hsv_to_CieXyy(float h, float s, float v, float x, float y, float yl)
47+
{
48+
// Arrange
49+
Hsv input = new(h, s, v);
50+
CieXyy expected = new(x, y, yl);
51+
ColorProfileConverter converter = new();
52+
53+
Span<Hsv> inputSpan = new Hsv[5];
54+
inputSpan.Fill(input);
55+
56+
Span<CieXyy> actualSpan = new CieXyy[5];
57+
58+
// Act
59+
CieXyy actual = converter.Convert<Hsv, CieXyy>(input);
60+
converter.Convert<Hsv, CieXyy>(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+
}

0 commit comments

Comments
 (0)