Skip to content

Commit 9d1cb16

Browse files
Add CIeLuv tests
1 parent b983cd3 commit 9d1cb16

File tree

3 files changed

+216
-0
lines changed

3 files changed

+216
-0
lines changed
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="CieLuv"/>-<see cref="Lms"/> conversions.
10+
/// </summary>
11+
public class CieLuvAndLmsConversionTests
12+
{
13+
private static readonly ApproximateColorProfileComparer Comparer = new(.0002F);
14+
15+
[Theory]
16+
[InlineData(0, 0, 0, 0, 0, 0)]
17+
[InlineData(36.0555, 93.6901, 10.01514, 0.164352, 0.03267485, 0.0483408)]
18+
public void Convert_CieLuv_to_Lms(float l, float u, float v, float l2, float m, float s)
19+
{
20+
// Arrange
21+
CieLuv input = new(l, u, v);
22+
Lms expected = new(l2, m, s);
23+
ColorConversionOptions options = new() { WhitePoint = Illuminants.D65, TargetWhitePoint = Illuminants.D65 };
24+
ColorProfileConverter converter = new(options);
25+
26+
Span<CieLuv> inputSpan = new CieLuv[5];
27+
inputSpan.Fill(input);
28+
29+
Span<Lms> actualSpan = new Lms[5];
30+
31+
// Act
32+
Lms actual = converter.Convert<CieLuv, Lms>(input);
33+
converter.Convert<CieLuv, Lms>(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)]
46+
[InlineData(0.164352, 0.03267485, 0.0483408, 36.0555, 93.69009, 10.01514)]
47+
public void Convert_Lms_to_CieLuv(float l2, float m, float s, float l, float u, float v)
48+
{
49+
// Arrange
50+
Lms input = new(l2, m, s);
51+
CieLuv expected = new(l, u, v);
52+
ColorConversionOptions options = new() { WhitePoint = Illuminants.D65, TargetWhitePoint = Illuminants.D65 };
53+
ColorProfileConverter converter = new(options);
54+
55+
Span<Lms> inputSpan = new Lms[5];
56+
inputSpan.Fill(input);
57+
58+
Span<CieLuv> actualSpan = new CieLuv[5];
59+
60+
// Act
61+
CieLuv actual = converter.Convert<Lms, CieLuv>(input);
62+
converter.Convert<Lms, CieLuv>(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+
}
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="CieLuv"/>-<see cref="Rgb"/> conversions.
10+
/// </summary>
11+
public class CieLuvAndRgbConversionTests
12+
{
13+
private static readonly ApproximateColorProfileComparer Comparer = new(.0002F);
14+
15+
[Theory]
16+
[InlineData(0, 0, 0, 0, 0, 0)]
17+
[InlineData(36.0555, 93.6901, 10.01514, 0.6444615, 0.1086071, 0.2213444)]
18+
public void Convert_CieLuv_to_Rgb(float l, float u, float v, float r, float g, float b)
19+
{
20+
// Arrange
21+
CieLuv input = new(l, u, v);
22+
Rgb expected = new(r, g, b);
23+
ColorConversionOptions options = new() { WhitePoint = Illuminants.D65, TargetWhitePoint = Illuminants.D65 };
24+
ColorProfileConverter converter = new(options);
25+
26+
Span<CieLuv> inputSpan = new CieLuv[5];
27+
inputSpan.Fill(input);
28+
29+
Span<Rgb> actualSpan = new Rgb[5];
30+
31+
// Act
32+
Rgb actual = converter.Convert<CieLuv, Rgb>(input);
33+
converter.Convert<CieLuv, Rgb>(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)]
46+
[InlineData(0.6444615, 0.1086071, 0.2213444, 36.0555, 93.69012, 10.01514)]
47+
public void Convert_Rgb_to_CieLuv(float r, float g, float b, float l, float u, float v)
48+
{
49+
// Arrange
50+
Rgb input = new(r, g, b);
51+
CieLuv expected = new(l, u, v);
52+
ColorConversionOptions options = new() { WhitePoint = Illuminants.D65, TargetWhitePoint = Illuminants.D65 };
53+
ColorProfileConverter converter = new(options);
54+
55+
Span<Rgb> inputSpan = new Rgb[5];
56+
inputSpan.Fill(input);
57+
58+
Span<CieLuv> actualSpan = new CieLuv[5];
59+
60+
// Act
61+
CieLuv actual = converter.Convert<Rgb, CieLuv>(input);
62+
converter.Convert<Rgb, CieLuv>(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+
}
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="CieLuv"/>-<see cref="YCbCr"/> conversions.
10+
/// </summary>
11+
public class CieLuvAndYCbCrConversionTests
12+
{
13+
private static readonly ApproximateColorProfileComparer Comparer = new(.0002F);
14+
15+
[Theory]
16+
[InlineData(0, 0, 0, 0, 128, 128)]
17+
[InlineData(36.0555, 93.6901, 10.01514, 71.8283, 119.3174, 193.9839)]
18+
public void Convert_CieLuv_to_YCbCr(float l, float u, float v, float y, float cb, float cr)
19+
{
20+
// Arrange
21+
CieLuv input = new(l, u, v);
22+
YCbCr expected = new(y, cb, cr);
23+
ColorConversionOptions options = new() { WhitePoint = Illuminants.D65, TargetWhitePoint = Illuminants.D65 };
24+
ColorProfileConverter converter = new(options);
25+
26+
Span<CieLuv> inputSpan = new CieLuv[5];
27+
inputSpan.Fill(input);
28+
29+
Span<YCbCr> actualSpan = new YCbCr[5];
30+
31+
// Act
32+
YCbCr actual = converter.Convert<CieLuv, YCbCr>(input);
33+
converter.Convert<CieLuv, YCbCr>(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, 128, 128, 0, 0, 0)]
46+
[InlineData(71.8283, 119.3174, 193.9839, 36.00565, 93.44593, 10.2234)]
47+
public void Convert_YCbCr_to_CieLuv(float y, float cb, float cr, float l, float u, float v)
48+
{
49+
// Arrange
50+
YCbCr input = new(y, cb, cr);
51+
CieLuv expected = new(l, u, v);
52+
ColorConversionOptions options = new() { WhitePoint = Illuminants.D65, TargetWhitePoint = Illuminants.D65 };
53+
ColorProfileConverter converter = new(options);
54+
55+
Span<YCbCr> inputSpan = new YCbCr[5];
56+
inputSpan.Fill(input);
57+
58+
Span<CieLuv> actualSpan = new CieLuv[5];
59+
60+
// Act
61+
CieLuv actual = converter.Convert<YCbCr, CieLuv>(input);
62+
converter.Convert<YCbCr, CieLuv>(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)