mirror of https://github.com/SixLabors/ImageSharp
2 changed files with 152 additions and 0 deletions
@ -0,0 +1,76 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using SixLabors.ImageSharp.ColorProfiles; |
|||
|
|||
namespace SixLabors.ImageSharp.Tests.ColorProfiles.Conversion; |
|||
|
|||
/// <summary>
|
|||
/// Tests <see cref="CieLab"/>-<see cref="CieLchuv"/> conversions.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// Test data generated using:
|
|||
/// <see href="http://www.brucelindbloom.com/index.html?ColorCalculator.html"/>
|
|||
/// </remarks>
|
|||
public class CieLabAndCieLchuvConversionTests |
|||
{ |
|||
private static readonly ApproximateColorProfileComparer Comparer = new(.0002F); |
|||
|
|||
[Theory] |
|||
[InlineData(0, 0, 0, 0, 0, 0)] |
|||
[InlineData(30.66194, 200, 352.7564, 31.95653, 116.8745, 2.388602)] |
|||
public void Convert_Lchuv_to_Lab(float l, float c, float h, float l2, float a, float b) |
|||
{ |
|||
// Arrange
|
|||
CieLchuv input = new(l, c, h); |
|||
CieLab expected = new(l2, a, b); |
|||
ColorConversionOptions options = new() { WhitePoint = Illuminants.D65, TargetWhitePoint = Illuminants.D50 }; |
|||
ColorProfileConverter converter = new(options); |
|||
|
|||
Span<CieLchuv> inputSpan = new CieLchuv[5]; |
|||
inputSpan.Fill(input); |
|||
|
|||
Span<CieLab> actualSpan = new CieLab[5]; |
|||
|
|||
// Act
|
|||
CieLab actual = converter.Convert<CieLchuv, CieLab>(input); |
|||
converter.Convert<CieLchuv, CieLab>(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(36.0555, 303.6901, 10.01514, 29.4713573, 200, 352.6346)] |
|||
public void Convert_Lab_to_Lchuv(float l, float a, float b, float l2, float c, float h) |
|||
{ |
|||
// Arrange
|
|||
CieLab input = new(l, a, b); |
|||
CieLchuv expected = new(l2, c, h); |
|||
ColorConversionOptions options = new() { WhitePoint = Illuminants.D50, TargetWhitePoint = Illuminants.D65 }; |
|||
ColorProfileConverter converter = new(options); |
|||
|
|||
Span<CieLab> inputSpan = new CieLab[5]; |
|||
inputSpan.Fill(input); |
|||
|
|||
Span<CieLchuv> actualSpan = new CieLchuv[5]; |
|||
|
|||
// Act
|
|||
CieLchuv actual = converter.Convert<CieLab, CieLchuv>(input); |
|||
converter.Convert<CieLab, CieLchuv>(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,76 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using SixLabors.ImageSharp.ColorProfiles; |
|||
|
|||
namespace SixLabors.ImageSharp.Tests.ColorProfiles.Conversion; |
|||
|
|||
/// <summary>
|
|||
/// Tests <see cref="CieLab"/>-<see cref="CieLuv"/> conversions.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// Test data generated using:
|
|||
/// <see href="http://www.brucelindbloom.com/index.html?ColorCalculator.html"/>
|
|||
/// </remarks>
|
|||
public class CieLabAndCieLuvConversionTests |
|||
{ |
|||
private static readonly ApproximateColorProfileComparer Comparer = new(.0002F); |
|||
|
|||
[Theory] |
|||
[InlineData(0, 0, 0, 0, 0, 0)] |
|||
[InlineData(10, 36.0555, 303.6901, 10.6006718, -17.24077, 82.8835)] |
|||
public void Convert_CieLuv_to_CieLab(float l, float u, float v, float l2, float a, float b) |
|||
{ |
|||
// Arrange
|
|||
CieLuv input = new(l, u, v); |
|||
CieLab expected = new(l2, a, b); |
|||
ColorConversionOptions options = new() { WhitePoint = Illuminants.D65, TargetWhitePoint = Illuminants.D50 }; |
|||
ColorProfileConverter converter = new(options); |
|||
|
|||
Span<CieLuv> inputSpan = new CieLuv[5]; |
|||
inputSpan.Fill(input); |
|||
|
|||
Span<CieLab> actualSpan = new CieLab[5]; |
|||
|
|||
// Act
|
|||
CieLab actual = converter.Convert<CieLuv, CieLab>(input); |
|||
converter.Convert<CieLuv, CieLab>(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(10.0151367, -23.9644356, 17.0226, 10.0000038, -12.830183, 15.1829338)] |
|||
public void Convert_CieLab_to_CieLuv(float l, float a, float b, float l2, float u, float v) |
|||
{ |
|||
// Arrange
|
|||
CieLab input = new(l, a, b); |
|||
CieLuv expected = new(l2, u, v); |
|||
ColorConversionOptions options = new() { WhitePoint = Illuminants.D50, TargetWhitePoint = Illuminants.D65 }; |
|||
ColorProfileConverter converter = new(options); |
|||
|
|||
Span<CieLab> inputSpan = new CieLab[5]; |
|||
inputSpan.Fill(input); |
|||
|
|||
Span<CieLuv> actualSpan = new CieLuv[5]; |
|||
|
|||
// Act
|
|||
CieLuv actual = converter.Convert<CieLab, CieLuv>(input); |
|||
converter.Convert<CieLab, CieLuv>(inputSpan, actualSpan); |
|||
|
|||
// 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