Skip to content

Commit 27b6084

Browse files
LAB YCBCR tests
1 parent 611c78d commit 27b6084

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

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="CieLab"/>-<see cref="YCbCr"/> conversions.
10+
/// </summary>
11+
public class CieLabAndYCbCrConversionTests
12+
{
13+
private static readonly ApproximateColorProfileComparer Comparer = new(.0002F);
14+
15+
[Theory]
16+
[InlineData(0, 128, 128, 0, 0, 0)]
17+
[InlineData(87.4179, 133.9763, 247.5308, 55.06287, 82.54838, 23.1697)]
18+
public void Convert_YCbCr_to_CieLab(float y, float cb, float cr, float l, float a, float b)
19+
{
20+
// Arrange
21+
YCbCr input = new(y, cb, cr);
22+
CieLab expected = new(l, a, b);
23+
ColorProfileConverter converter = new();
24+
25+
Span<YCbCr> inputSpan = new YCbCr[5];
26+
inputSpan.Fill(input);
27+
28+
Span<CieLab> actualSpan = new CieLab[5];
29+
30+
// Act
31+
CieLab actual = converter.Convert<YCbCr, CieLab>(input);
32+
converter.Convert<YCbCr, CieLab>(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, 128, 128)]
45+
[InlineData(55.06287, 82.54838, 23.1697, 87.41701, 133.97232, 247.5314)]
46+
public void Convert_CieLab_to_YCbCr(float l, float a, float b, float y, float cb, float cr)
47+
{
48+
// Arrange
49+
CieLab input = new(l, a, b);
50+
YCbCr expected = new(y, cb, cr);
51+
ColorProfileConverter converter = new();
52+
53+
Span<CieLab> inputSpan = new CieLab[5];
54+
inputSpan.Fill(input);
55+
56+
Span<YCbCr> actualSpan = new YCbCr[5];
57+
58+
// Act
59+
YCbCr actual = converter.Convert<CieLab, YCbCr>(input);
60+
converter.Convert<CieLab, YCbCr>(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)