mirror of https://github.com/SixLabors/ImageSharp
2 changed files with 142 additions and 0 deletions
@ -0,0 +1,71 @@ |
|||
// 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="Rgb"/> conversions.
|
|||
/// </summary>
|
|||
public class CieLabAndRgbConversionTests |
|||
{ |
|||
private static readonly ApproximateColorProfileComparer Comparer = new(.0002F); |
|||
private static readonly ColorProfileConverter Converter = new(); |
|||
|
|||
[Theory] |
|||
[InlineData(0, 0, 0, 0, 0, 0)] |
|||
[InlineData(0.9999999, 0, 0.384345, 55.063, 82.54871, 23.16505)] |
|||
public void Convert_Rgb_to_CieLab(float r, float g, float b2, float l, float a, float b) |
|||
{ |
|||
// Arrange
|
|||
Rgb input = new(r, g, b2); |
|||
CieLab expected = new(l, a, b); |
|||
ColorProfileConverter converter = new(); |
|||
|
|||
Span<Rgb> inputSpan = new Rgb[5]; |
|||
inputSpan.Fill(input); |
|||
|
|||
Span<CieLab> actualSpan = new CieLab[5]; |
|||
|
|||
// Act
|
|||
CieLab actual = converter.Convert<Rgb, CieLab>(input); |
|||
converter.Convert<Rgb, 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(55.063, 82.54871, 23.16505, 0.9999999, 0, 0.384345)] |
|||
public void Convert_CieLab_to_Rgb(float l, float a, float b, float r, float g, float b2) |
|||
{ |
|||
// Arrange
|
|||
CieLab input = new(l, a, b); |
|||
Rgb expected = new(r, g, b2); |
|||
ColorProfileConverter converter = new(); |
|||
|
|||
Span<CieLab> inputSpan = new CieLab[5]; |
|||
inputSpan.Fill(input); |
|||
|
|||
Span<Rgb> actualSpan = new Rgb[5]; |
|||
|
|||
// Act
|
|||
Rgb actual = converter.Convert<CieLab, Rgb>(input); |
|||
converter.Convert<CieLab, Rgb>(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,71 @@ |
|||
// 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="CieLchuv"/>-<see cref="CieLch"/> conversions.
|
|||
/// </summary>
|
|||
public class CieLchuvAndCieLchConversionTests |
|||
{ |
|||
private static readonly ApproximateColorProfileComparer Comparer = new(.0002F); |
|||
|
|||
[Theory] |
|||
[InlineData(0, 0, 0, 0, 0, 0)] |
|||
[InlineData(36.73742, 64.79149, 30.1786, 36.0555, 103.6901, 10.01513)] |
|||
public void Convert_CieLch_To_CieLchuv(float l2, float c2, float h2, float l, float c, float h) |
|||
{ |
|||
// Arrange
|
|||
CieLch input = new(l2, c2, h2); |
|||
CieLchuv expected = new(l, c, h); |
|||
ColorConversionOptions options = new() { WhitePoint = Illuminants.D50, TargetWhitePoint = Illuminants.D65 }; |
|||
ColorProfileConverter converter = new(options); |
|||
|
|||
Span<CieLch> inputSpan = new CieLch[5]; |
|||
inputSpan.Fill(input); |
|||
|
|||
Span<CieLchuv> actualSpan = new CieLchuv[5]; |
|||
|
|||
// Act
|
|||
CieLchuv actual = converter.Convert<CieLch, CieLchuv>(input); |
|||
converter.Convert<CieLch, 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(36.0555, 103.6901, 10.01514, 36.73742, 64.79149, 30.1786)] |
|||
public void Convert_CieLchuv_To_CieLch(float l, float c, float h, float l2, float c2, float h2) |
|||
{ |
|||
// Arrange
|
|||
CieLchuv input = new(l, c, h); |
|||
CieLch expected = new(l2, c2, h2); |
|||
ColorConversionOptions options = new() { WhitePoint = Illuminants.D65, TargetWhitePoint = Illuminants.D50 }; |
|||
ColorProfileConverter converter = new(options); |
|||
|
|||
Span<CieLchuv> inputSpan = new CieLchuv[5]; |
|||
inputSpan.Fill(input); |
|||
|
|||
Span<CieLch> actualSpan = new CieLch[5]; |
|||
|
|||
// Act
|
|||
CieLch actual = converter.Convert<CieLchuv, CieLch>(input); |
|||
converter.Convert<CieLchuv, CieLch>(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