mirror of https://github.com/SixLabors/ImageSharp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
3.4 KiB
95 lines
3.4 KiB
// Copyright (c) Six Labors and contributors.
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
|
using System;
|
|
using SixLabors.ImageSharp.ColorSpaces;
|
|
using SixLabors.ImageSharp.ColorSpaces.Conversion;
|
|
using Xunit;
|
|
|
|
namespace SixLabors.ImageSharp.Tests.Colorspaces
|
|
{
|
|
/// <summary>
|
|
/// Tests <see cref="CieLab"/>-<see cref="CieLch"/> conversions.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Test data generated using:
|
|
/// <see href="http://www.brucelindbloom.com/index.html?ColorCalculator.html"/>
|
|
/// </remarks>
|
|
public class CieLabAndCieLchConversionTests
|
|
{
|
|
private static readonly ApproximateColorSpaceComparer ColorSpaceComparer = new ApproximateColorSpaceComparer(.0001F);
|
|
private static readonly ColorSpaceConverter Converter = new ColorSpaceConverter();
|
|
|
|
/// <summary>
|
|
/// Tests conversion from <see cref="CieLch"/> to <see cref="CieLab"/>.
|
|
/// </summary>
|
|
[Theory]
|
|
[InlineData(0, 0, 0, 0, 0, 0)]
|
|
[InlineData(54.2917, 106.8391, 40.8526, 54.2917, 80.8125, 69.8851)]
|
|
[InlineData(100, 0, 0, 100, 0, 0)]
|
|
[InlineData(100, 50, 180, 100, -50, 0)]
|
|
[InlineData(10, 36.0555, 56.3099, 10, 20, 30)]
|
|
[InlineData(10, 36.0555, 123.6901, 10, -20, 30)]
|
|
[InlineData(10, 36.0555, 303.6901, 10, 20, -30)]
|
|
[InlineData(10, 36.0555, 236.3099, 10, -20, -30)]
|
|
public void Convert_Lch_to_Lab(float l, float c, float h, float l2, float a, float b)
|
|
{
|
|
// Arrange
|
|
var input = new CieLch(l, c, h);
|
|
var expected = new CieLab(l2, a, b);
|
|
|
|
Span<CieLch> inputSpan = new CieLch[5];
|
|
inputSpan.Fill(input);
|
|
|
|
Span<CieLab> actualSpan = new CieLab[5];
|
|
|
|
// Act
|
|
var actual = Converter.ToCieLab(input);
|
|
Converter.Convert(inputSpan, actualSpan, actualSpan.Length);
|
|
|
|
// Assert
|
|
Assert.Equal(expected, actual, ColorSpaceComparer);
|
|
|
|
for (int i = 0; i < actualSpan.Length; i++)
|
|
{
|
|
Assert.Equal(expected, actualSpan[i], ColorSpaceComparer);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests conversion from <see cref="CieLab"/> to <see cref="CieLch"/>.
|
|
/// </summary>
|
|
[Theory]
|
|
[InlineData(0, 0, 0, 0, 0, 0)]
|
|
[InlineData(54.2917, 80.8125, 69.8851, 54.2917, 106.8391, 40.8526)]
|
|
[InlineData(100, 0, 0, 100, 0, 0)]
|
|
[InlineData(100, -50, 0, 100, 50, 180)]
|
|
[InlineData(10, 20, 30, 10, 36.0555, 56.3099)]
|
|
[InlineData(10, -20, 30, 10, 36.0555, 123.6901)]
|
|
[InlineData(10, 20, -30, 10, 36.0555, 303.6901)]
|
|
[InlineData(10, -20, -30, 10, 36.0555, 236.3099)]
|
|
public void Convert_Lab_to_LCHab(float l, float a, float b, float l2, float c, float h)
|
|
{
|
|
// Arrange
|
|
var input = new CieLab(l, a, b);
|
|
var expected = new CieLch(l2, c, h);
|
|
|
|
Span<CieLab> inputSpan = new CieLab[5];
|
|
inputSpan.Fill(input);
|
|
|
|
Span<CieLch> actualSpan = new CieLch[5];
|
|
|
|
// Act
|
|
var actual = Converter.ToCieLch(input);
|
|
Converter.Convert(inputSpan, actualSpan, actualSpan.Length);
|
|
|
|
// Assert
|
|
Assert.Equal(expected, actual, ColorSpaceComparer);
|
|
|
|
for (int i = 0; i < actualSpan.Length; i++)
|
|
{
|
|
Assert.Equal(expected, actualSpan[i], ColorSpaceComparer);
|
|
}
|
|
}
|
|
}
|
|
}
|