mirror of https://github.com/SixLabors/ImageSharp
3 changed files with 160 additions and 5 deletions
@ -0,0 +1,69 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using SixLabors.ImageSharp.ColorProfiles; |
|||
|
|||
namespace SixLabors.ImageSharp.Tests.ColorProfiles; |
|||
|
|||
/// <summary>
|
|||
/// Tests <see cref="CieXyz"/>-<see cref="CieLchuv"/> conversions.
|
|||
/// </summary>
|
|||
public class CieXyzAndCieLchuvConversionTests |
|||
{ |
|||
private static readonly ApproximateColorProfileComparer Comparer = new(.0002f); |
|||
|
|||
[Theory] |
|||
[InlineData(0.360555, 0.936901, 0.1001514, 97.50697, 177.345169, 142.601547)] |
|||
public void Convert_CieXyz_to_CieLchuv(float x, float y, float yl, float l, float c, float h) |
|||
{ |
|||
// Arrange
|
|||
CieXyz input = new(x, y, yl); |
|||
CieLchuv expected = new(l, c, h); |
|||
ColorProfileConverter converter = new(); |
|||
|
|||
Span<CieXyz> inputSpan = new CieXyz[5]; |
|||
inputSpan.Fill(input); |
|||
|
|||
Span<CieLchuv> actualSpan = new CieLchuv[5]; |
|||
|
|||
// Act
|
|||
CieLchuv actual = converter.Convert<CieXyz, CieLchuv>(input); |
|||
converter.Convert<CieXyz, CieLchuv>(inputSpan, actualSpan); |
|||
|
|||
// Assert
|
|||
Assert.Equal(expected, actual, Comparer); |
|||
|
|||
for (int i = 0; i < actualSpan.Length; i++) |
|||
{ |
|||
Assert.Equal(expected, actualSpan[i], Comparer); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[InlineData(0, 0, 0, 0, 0, 0)] |
|||
[InlineData(97.50697, 177.345169, 142.601547, 0.360555, 0.936901, 0.1001514)] |
|||
public void Convert_CieLchuv_to_CieXyz(float l, float c, float h, float x, float y, float yl) |
|||
{ |
|||
// Arrange
|
|||
CieLchuv input = new(l, c, h); |
|||
CieXyz expected = new(x, y, yl); |
|||
ColorProfileConverter converter = new(); |
|||
|
|||
Span<CieLchuv> inputSpan = new CieLchuv[5]; |
|||
inputSpan.Fill(input); |
|||
|
|||
Span<CieXyz> actualSpan = new CieXyz[5]; |
|||
|
|||
// Act
|
|||
CieXyz actual = converter.Convert<CieLchuv, CieXyz>(input); |
|||
converter.Convert<CieLchuv, CieXyz>(inputSpan, actualSpan); |
|||
|
|||
// Assert
|
|||
Assert.Equal(expected, actual, Comparer); |
|||
|
|||
for (int i = 0; i < actualSpan.Length; i++) |
|||
{ |
|||
Assert.Equal(expected, actualSpan[i], Comparer); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,86 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using SixLabors.ImageSharp.ColorProfiles; |
|||
|
|||
namespace SixLabors.ImageSharp.Tests.ColorProfiles; |
|||
|
|||
/// <summary>
|
|||
/// Tests <see cref="CieXyz"/>-<see cref="CieLuv"/> conversions.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// Test data generated using:
|
|||
/// <see href="http://www.brucelindbloom.com/index.html?ColorCalculator.html"/>
|
|||
/// </remarks>
|
|||
public class CieXyzAndCieLuvConversionTest |
|||
{ |
|||
private static readonly ApproximateColorProfileComparer Comparer = new(.0002f); |
|||
|
|||
[Theory] |
|||
[InlineData(0, 0, 0, 0, 0, 0)] |
|||
[InlineData(0, 100, 50, 0, 0, 0)] |
|||
[InlineData(0.1, 100, 50, 0.000493, 0.000111, -0.000709)] |
|||
[InlineData(70.0000, 86.3525, 2.8240, 0.569310, 0.407494, 0.365843)] |
|||
[InlineData(10.0000, -1.2345, -10.0000, 0.012191, 0.011260, 0.025939)] |
|||
[InlineData(100, 0, 0, 0.950470, 1.000000, 1.088830)] |
|||
[InlineData(1, 1, 1, 0.001255, 0.001107, 0.000137)] |
|||
public void Convert_Luv_to_Xyz(float l, float u, float v, float x, float y, float z) |
|||
{ |
|||
// Arrange
|
|||
CieLuv input = new(l, u, v); |
|||
CieXyz expected = new(x, y, z); |
|||
|
|||
ColorConversionOptions options = new() { WhitePoint = Illuminants.D65, TargetWhitePoint = Illuminants.D65 }; |
|||
ColorProfileConverter converter = new(options); |
|||
|
|||
Span<CieLuv> inputSpan = new CieLuv[5]; |
|||
inputSpan.Fill(input); |
|||
|
|||
Span<CieXyz> actualSpan = new CieXyz[5]; |
|||
|
|||
// Act
|
|||
CieXyz actual = converter.Convert<CieLuv, CieXyz>(input); |
|||
converter.Convert<CieLuv, CieXyz>(inputSpan, actualSpan); |
|||
|
|||
// Assert
|
|||
Assert.Equal(expected, actual, Comparer); |
|||
|
|||
for (int i = 0; i < actualSpan.Length; i++) |
|||
{ |
|||
Assert.Equal(expected, actualSpan[i], Comparer); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[InlineData(0, 0, 0, 0, 0, 0)] |
|||
[InlineData(0.000493, 0.000111, 0, 0.1003, 0.9332, -0.0070)] |
|||
[InlineData(0.569310, 0.407494, 0.365843, 70.0000, 86.3524, 2.8240)] |
|||
[InlineData(0.012191, 0.011260, 0.025939, 9.9998, -1.2343, -9.9999)] |
|||
[InlineData(0.950470, 1.000000, 1.088830, 100, 0, 0)] |
|||
[InlineData(0.001255, 0.001107, 0.000137, 0.9999, 0.9998, 1.0004)] |
|||
public void Convert_Xyz_to_Luv(float x, float y, float z, float l, float u, float v) |
|||
{ |
|||
// Arrange
|
|||
CieXyz input = new(x, y, z); |
|||
CieLuv expected = new(l, u, v); |
|||
|
|||
ColorConversionOptions options = new() { WhitePoint = Illuminants.D65, TargetWhitePoint = Illuminants.D65 }; |
|||
ColorProfileConverter converter = new(options); |
|||
|
|||
Span<CieXyz> inputSpan = new CieXyz[5]; |
|||
inputSpan.Fill(input); |
|||
|
|||
Span<CieLuv> actualSpan = new CieLuv[5]; |
|||
|
|||
// Act
|
|||
CieLuv actual = converter.Convert<CieXyz, CieLuv>(input); |
|||
|
|||
// Assert
|
|||
Assert.Equal(expected, actual, Comparer); |
|||
|
|||
for (int i = 0; i < actualSpan.Length; i++) |
|||
{ |
|||
Assert.Equal(expected, actualSpan[i], Comparer); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue