Skip to content

Commit 3ac5f70

Browse files
Complete CieXyy tests
1 parent 9b99301 commit 3ac5f70

File tree

4 files changed

+280
-0
lines changed

4 files changed

+280
-0
lines changed
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="HunterLab"/> conversions.
10+
/// </summary>
11+
public class CieXyyAndHunterLabConversionTests
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, 31.6467056, -33.00599, 25.67032)]
18+
public void Convert_CieXyy_to_HunterLab(float x, float y, float yl, float l, float a, float b)
19+
{
20+
// Arrange
21+
CieXyy input = new(x, y, yl);
22+
HunterLab expected = new(l, a, b);
23+
ColorProfileConverter converter = new();
24+
25+
Span<CieXyy> inputSpan = new CieXyy[5];
26+
inputSpan.Fill(input);
27+
28+
Span<HunterLab> actualSpan = new HunterLab[5];
29+
30+
// Act
31+
HunterLab actual = converter.Convert<CieXyy, HunterLab>(input);
32+
converter.Convert<CieXyy, HunterLab>(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(31.6467056, -33.00599, 25.67032, 0.360555, 0.936901, 0.1001514)]
46+
public void Convert_HunterLab_to_CieXyy(float l, float a, float b, float x, float y, float yl)
47+
{
48+
// Arrange
49+
HunterLab input = new(l, a, b);
50+
CieXyy expected = new(x, y, yl);
51+
ColorProfileConverter converter = new();
52+
53+
Span<HunterLab> inputSpan = new HunterLab[5];
54+
inputSpan.Fill(input);
55+
56+
Span<CieXyy> actualSpan = new CieXyy[5];
57+
58+
// Act
59+
CieXyy actual = converter.Convert<HunterLab, CieXyy>(input);
60+
converter.Convert<HunterLab, 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.Conversion;
7+
8+
/// <summary>
9+
/// Tests <see cref="CieXyy"/>-<see cref="Lms"/> conversions.
10+
/// </summary>
11+
public class CieXyyAndLmsConversionTests
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, 0.06631134, 0.1415282, -0.03809926)]
18+
public void Convert_CieXyy_to_Lms(float x, float y, float yl, float l, float m, float s)
19+
{
20+
// Arrange
21+
CieXyy input = new(x, y, yl);
22+
Lms expected = new(l, m, s);
23+
ColorProfileConverter converter = new();
24+
25+
Span<CieXyy> inputSpan = new CieXyy[5];
26+
inputSpan.Fill(input);
27+
28+
Span<Lms> actualSpan = new Lms[5];
29+
30+
// Act
31+
Lms actual = converter.Convert<CieXyy, Lms>(input);
32+
converter.Convert<CieXyy, Lms>(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(0.06631134, 0.1415282, -0.03809926, 0.360555, 0.936901, 0.1001514)]
46+
public void Convert_Lms_to_CieXyy(float l, float m, float s, float x, float y, float yl)
47+
{
48+
// Arrange
49+
Lms input = new(l, m, s);
50+
CieXyy expected = new(x, y, yl);
51+
ColorProfileConverter converter = new();
52+
53+
Span<Lms> inputSpan = new Lms[5];
54+
inputSpan.Fill(input);
55+
56+
Span<CieXyy> actualSpan = new CieXyy[5];
57+
58+
// Act
59+
CieXyy actual = converter.Convert<Lms, CieXyy>(input);
60+
converter.Convert<Lms, 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="Rgb"/> conversions.
10+
/// </summary>
11+
public class CieXyyAndRgbConversionTests
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, 0, 0.4277014, 0)]
18+
public void Convert_CieXyy_to_Rgb(float x, float y, float yl, float r, float g, float b)
19+
{
20+
// Arrange
21+
CieXyy input = new(x, y, yl);
22+
Rgb expected = new(r, g, b);
23+
ColorProfileConverter converter = new();
24+
25+
Span<CieXyy> inputSpan = new CieXyy[5];
26+
inputSpan.Fill(input);
27+
28+
Span<Rgb> actualSpan = new Rgb[5];
29+
30+
// Act
31+
Rgb actual = converter.Convert<CieXyy, Rgb>(input);
32+
converter.Convert<CieXyy, Rgb>(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(0, 0.4277014, 0, 0.32114, 0.59787, 0.10976)]
46+
public void Convert_Rgb_to_CieXyy(float r, float g, float b, float x, float y, float yl)
47+
{
48+
// Arrange
49+
Rgb input = new(r, g, b);
50+
CieXyy expected = new(x, y, yl);
51+
ColorProfileConverter converter = new();
52+
53+
Span<Rgb> inputSpan = new Rgb[5];
54+
inputSpan.Fill(input);
55+
56+
Span<CieXyy> actualSpan = new CieXyy[5];
57+
58+
// Act
59+
CieXyy actual = converter.Convert<Rgb, CieXyy>(input);
60+
converter.Convert<Rgb, 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="YCbCr"/> conversions.
10+
/// </summary>
11+
public class CieXyyAndYCbCrConversionTests
12+
{
13+
private static readonly ApproximateColorProfileComparer Comparer = new(.0002f);
14+
15+
[Theory]
16+
[InlineData(0, 0, 0, 0, 128, 128)]
17+
[InlineData(0.360555, 0.936901, 0.1001514, 64.0204849, 91.87107, 82.33627)]
18+
public void Convert_CieXyy_to_YCbCr(float x, float y, float yl, float y2, float cb, float cr)
19+
{
20+
// Arrange
21+
CieXyy input = new(x, y, yl);
22+
YCbCr expected = new(y2, cb, cr);
23+
ColorProfileConverter converter = new();
24+
25+
Span<CieXyy> inputSpan = new CieXyy[5];
26+
inputSpan.Fill(input);
27+
28+
Span<YCbCr> actualSpan = new YCbCr[5];
29+
30+
// Act
31+
YCbCr actual = converter.Convert<CieXyy, YCbCr>(input);
32+
converter.Convert<CieXyy, YCbCr>(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, 128, 128, 0, 0, 0)]
45+
[InlineData(64.0204849, 91.87107, 82.33627, 0.32114, 0.59787, 0.10976)]
46+
public void Convert_YCbCr_to_CieXyy(float y2, float cb, float cr, float x, float y, float yl)
47+
{
48+
// Arrange
49+
YCbCr input = new(y2, cb, cr);
50+
CieXyy expected = new(x, y, yl);
51+
ColorProfileConverter converter = new();
52+
53+
Span<YCbCr> inputSpan = new YCbCr[5];
54+
inputSpan.Fill(input);
55+
56+
Span<CieXyy> actualSpan = new CieXyy[5];
57+
58+
// Act
59+
CieXyy actual = converter.Convert<YCbCr, CieXyy>(input);
60+
converter.Convert<YCbCr, 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)