Skip to content

Commit 611c78d

Browse files
More tests
1 parent 51c3094 commit 611c78d

2 files changed

Lines changed: 142 additions & 0 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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="Rgb"/> conversions.
10+
/// </summary>
11+
public class CieLabAndRgbConversionTests
12+
{
13+
private static readonly ApproximateColorProfileComparer Comparer = new(.0002F);
14+
private static readonly ColorProfileConverter Converter = new();
15+
16+
[Theory]
17+
[InlineData(0, 0, 0, 0, 0, 0)]
18+
[InlineData(0.9999999, 0, 0.384345, 55.063, 82.54871, 23.16505)]
19+
public void Convert_Rgb_to_CieLab(float r, float g, float b2, float l, float a, float b)
20+
{
21+
// Arrange
22+
Rgb input = new(r, g, b2);
23+
CieLab expected = new(l, a, b);
24+
ColorProfileConverter converter = new();
25+
26+
Span<Rgb> inputSpan = new Rgb[5];
27+
inputSpan.Fill(input);
28+
29+
Span<CieLab> actualSpan = new CieLab[5];
30+
31+
// Act
32+
CieLab actual = converter.Convert<Rgb, CieLab>(input);
33+
converter.Convert<Rgb, CieLab>(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(55.063, 82.54871, 23.16505, 0.9999999, 0, 0.384345)]
47+
public void Convert_CieLab_to_Rgb(float l, float a, float b, float r, float g, float b2)
48+
{
49+
// Arrange
50+
CieLab input = new(l, a, b);
51+
Rgb expected = new(r, g, b2);
52+
ColorProfileConverter converter = new();
53+
54+
Span<CieLab> inputSpan = new CieLab[5];
55+
inputSpan.Fill(input);
56+
57+
Span<Rgb> actualSpan = new Rgb[5];
58+
59+
// Act
60+
Rgb actual = converter.Convert<CieLab, Rgb>(input);
61+
converter.Convert<CieLab, Rgb>(inputSpan, actualSpan);
62+
63+
// Assert
64+
Assert.Equal(expected, actual, Comparer);
65+
66+
for (int i = 0; i < actualSpan.Length; i++)
67+
{
68+
Assert.Equal(expected, actualSpan[i], Comparer);
69+
}
70+
}
71+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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="CieLchuv"/>-<see cref="CieLch"/> conversions.
10+
/// </summary>
11+
public class CieLchuvAndCieLchConversionTests
12+
{
13+
private static readonly ApproximateColorProfileComparer Comparer = new(.0002F);
14+
15+
[Theory]
16+
[InlineData(0, 0, 0, 0, 0, 0)]
17+
[InlineData(36.73742, 64.79149, 30.1786, 36.0555, 103.6901, 10.01513)]
18+
public void Convert_CieLch_To_CieLchuv(float l2, float c2, float h2, float l, float c, float h)
19+
{
20+
// Arrange
21+
CieLch input = new(l2, c2, h2);
22+
CieLchuv expected = new(l, c, h);
23+
ColorConversionOptions options = new() { WhitePoint = Illuminants.D50, TargetWhitePoint = Illuminants.D65 };
24+
ColorProfileConverter converter = new(options);
25+
26+
Span<CieLch> inputSpan = new CieLch[5];
27+
inputSpan.Fill(input);
28+
29+
Span<CieLchuv> actualSpan = new CieLchuv[5];
30+
31+
// Act
32+
CieLchuv actual = converter.Convert<CieLch, CieLchuv>(input);
33+
converter.Convert<CieLch, 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(36.0555, 103.6901, 10.01514, 36.73742, 64.79149, 30.1786)]
46+
public void Convert_CieLchuv_To_CieLch(float l, float c, float h, float l2, float c2, float h2)
47+
{
48+
// Arrange
49+
CieLchuv input = new(l, c, h);
50+
CieLch expected = new(l2, c2, h2);
51+
ColorConversionOptions options = new() { WhitePoint = Illuminants.D65, TargetWhitePoint = Illuminants.D50 };
52+
ColorProfileConverter converter = new(options);
53+
54+
Span<CieLchuv> inputSpan = new CieLchuv[5];
55+
inputSpan.Fill(input);
56+
57+
Span<CieLch> actualSpan = new CieLch[5];
58+
59+
// Act
60+
CieLch actual = converter.Convert<CieLchuv, CieLch>(input);
61+
converter.Convert<CieLchuv, CieLch>(inputSpan, actualSpan);
62+
63+
// Assert
64+
Assert.Equal(expected, actual, Comparer);
65+
66+
for (int i = 0; i < actualSpan.Length; i++)
67+
{
68+
Assert.Equal(expected, actualSpan[i], Comparer);
69+
}
70+
}
71+
}

0 commit comments

Comments
 (0)