mirror of https://github.com/SixLabors/ImageSharp
20 changed files with 745 additions and 49 deletions
@ -0,0 +1,57 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using System.Buffers; |
|||
using SixLabors.ImageSharp.Memory; |
|||
|
|||
namespace SixLabors.ImageSharp.ColorProfiles; |
|||
|
|||
internal static class ColorProfileConverterExtensionsCieLabRgb |
|||
{ |
|||
public static TTo Convert<TFrom, TTo>(this ColorProfileConverter converter, TFrom source) |
|||
where TFrom : struct, IColorProfile<TFrom, CieLab> |
|||
where TTo : struct, IColorProfile<TTo, Rgb> |
|||
{ |
|||
ColorConversionOptions options = converter.Options; |
|||
|
|||
// Convert to input PCS
|
|||
CieLab pcsFromA = source.ToProfileConnectingSpace(options); |
|||
CieXyz pcsFromB = pcsFromA.ToProfileConnectingSpace(options); |
|||
|
|||
// Adapt to target white point
|
|||
pcsFromB = VonKriesChromaticAdaptation.Transform<TFrom, TTo>(options, in pcsFromB); |
|||
|
|||
// Convert between PCS
|
|||
Rgb pcsTo = Rgb.FromProfileConnectingSpace(options, in pcsFromB); |
|||
|
|||
// Convert to output from PCS
|
|||
return TTo.FromProfileConnectingSpace(options, pcsTo); |
|||
} |
|||
|
|||
public static void Convert<TFrom, TTo>(this ColorProfileConverter converter, ReadOnlySpan<TFrom> source, Span<TTo> destination) |
|||
where TFrom : struct, IColorProfile<TFrom, CieLab> |
|||
where TTo : struct, IColorProfile<TTo, Rgb> |
|||
{ |
|||
ColorConversionOptions options = converter.Options; |
|||
|
|||
// Convert to input PCS.
|
|||
using IMemoryOwner<CieLab> pcsFromAOwner = options.MemoryAllocator.Allocate<CieLab>(source.Length); |
|||
Span<CieLab> pcsFromA = pcsFromAOwner.GetSpan(); |
|||
TFrom.ToProfileConnectionSpace(options, source, pcsFromA); |
|||
|
|||
using IMemoryOwner<CieXyz> pcsFromBOwner = options.MemoryAllocator.Allocate<CieXyz>(source.Length); |
|||
Span<CieXyz> pcsFromB = pcsFromBOwner.GetSpan(); |
|||
CieLab.ToProfileConnectionSpace(options, pcsFromA, pcsFromB); |
|||
|
|||
// Adapt to target white point
|
|||
VonKriesChromaticAdaptation.Transform<TFrom, TTo>(options, pcsFromB, pcsFromB); |
|||
|
|||
// Convert between PCS.
|
|||
using IMemoryOwner<Rgb> pcsToOwner = options.MemoryAllocator.Allocate<Rgb>(source.Length); |
|||
Span<Rgb> pcsTo = pcsToOwner.GetSpan(); |
|||
Rgb.FromProfileConnectionSpace(options, pcsFromB, pcsTo); |
|||
|
|||
// Convert to output from PCS
|
|||
TTo.FromProfileConnectionSpace(options, pcsTo, destination); |
|||
} |
|||
} |
|||
@ -0,0 +1,57 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using System.Buffers; |
|||
using SixLabors.ImageSharp.Memory; |
|||
|
|||
namespace SixLabors.ImageSharp.ColorProfiles; |
|||
|
|||
internal static class ColorProfileConverterExtensionsRgbCieLab |
|||
{ |
|||
public static TTo Convert<TFrom, TTo>(this ColorProfileConverter converter, TFrom source) |
|||
where TFrom : struct, IColorProfile<TFrom, Rgb> |
|||
where TTo : struct, IColorProfile<TTo, CieLab> |
|||
{ |
|||
ColorConversionOptions options = converter.Options; |
|||
|
|||
// Convert to input PCS
|
|||
Rgb pcsFromA = source.ToProfileConnectingSpace(options); |
|||
CieXyz pcsFromB = pcsFromA.ToProfileConnectingSpace(options); |
|||
|
|||
// Adapt to target white point
|
|||
pcsFromB = VonKriesChromaticAdaptation.Transform<TFrom, TTo>(options, in pcsFromB); |
|||
|
|||
// Convert between PCS
|
|||
CieLab pcsTo = CieLab.FromProfileConnectingSpace(options, in pcsFromB); |
|||
|
|||
// Convert to output from PCS
|
|||
return TTo.FromProfileConnectingSpace(options, pcsTo); |
|||
} |
|||
|
|||
public static void Convert<TFrom, TTo>(this ColorProfileConverter converter, ReadOnlySpan<TFrom> source, Span<TTo> destination) |
|||
where TFrom : struct, IColorProfile<TFrom, Rgb> |
|||
where TTo : struct, IColorProfile<TTo, CieLab> |
|||
{ |
|||
ColorConversionOptions options = converter.Options; |
|||
|
|||
// Convert to input PCS.
|
|||
using IMemoryOwner<Rgb> pcsFromAOwner = options.MemoryAllocator.Allocate<Rgb>(source.Length); |
|||
Span<Rgb> pcsFromA = pcsFromAOwner.GetSpan(); |
|||
TFrom.ToProfileConnectionSpace(options, source, pcsFromA); |
|||
|
|||
using IMemoryOwner<CieXyz> pcsFromBOwner = options.MemoryAllocator.Allocate<CieXyz>(source.Length); |
|||
Span<CieXyz> pcsFromB = pcsFromBOwner.GetSpan(); |
|||
Rgb.ToProfileConnectionSpace(options, pcsFromA, pcsFromB); |
|||
|
|||
// Adapt to target white point
|
|||
VonKriesChromaticAdaptation.Transform<TFrom, TTo>(options, pcsFromB, pcsFromB); |
|||
|
|||
// Convert between PCS.
|
|||
using IMemoryOwner<CieLab> pcsToOwner = options.MemoryAllocator.Allocate<CieLab>(source.Length); |
|||
Span<CieLab> pcsTo = pcsToOwner.GetSpan(); |
|||
CieLab.FromProfileConnectionSpace(options, pcsFromB, pcsTo); |
|||
|
|||
// Convert to output from PCS
|
|||
TTo.FromProfileConnectionSpace(options, pcsTo, destination); |
|||
} |
|||
} |
|||
@ -0,0 +1,70 @@ |
|||
// 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="Hsl"/> conversions.
|
|||
/// </summary>
|
|||
public class CieXyzAndHslConversionTests |
|||
{ |
|||
private static readonly ApproximateColorProfileComparer Comparer = new(.0002F); |
|||
|
|||
[Theory] |
|||
[InlineData(0, 0, 0, 0, 0, 0)] |
|||
[InlineData(0.360555, 0.936901, 0.1001514, 120, 1, 0.5)] |
|||
public void Convert_CieXyz_to_Hsl(float x, float y, float yl, float h, float s, float l) |
|||
{ |
|||
// Arrange
|
|||
CieXyz input = new(x, y, yl); |
|||
Hsl expected = new(h, s, l); |
|||
ColorProfileConverter converter = new(); |
|||
|
|||
Span<CieXyz> inputSpan = new CieXyz[5]; |
|||
inputSpan.Fill(input); |
|||
|
|||
Span<Hsl> actualSpan = new Hsl[5]; |
|||
|
|||
// Act
|
|||
Hsl actual = converter.Convert<CieXyz, Hsl>(input); |
|||
converter.Convert<CieXyz, Hsl>(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(120, 1, 0.5, 0.38506496, 0.716878653, 0.09710451)] |
|||
public void Convert_Hsl_to_CieXyz(float h, float s, float l, float x, float y, float yl) |
|||
{ |
|||
// Arrange
|
|||
Hsl input = new(h, s, l); |
|||
CieXyz expected = new(x, y, yl); |
|||
ColorProfileConverter converter = new(); |
|||
|
|||
Span<Hsl> inputSpan = new Hsl[5]; |
|||
inputSpan.Fill(input); |
|||
|
|||
Span<CieXyz> actualSpan = new CieXyz[5]; |
|||
|
|||
// Act
|
|||
CieXyz actual = converter.Convert<Hsl, CieXyz>(input); |
|||
converter.Convert<Hsl, 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,70 @@ |
|||
// 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="Hsv"/> conversions.
|
|||
/// </summary>
|
|||
public class CieXyzAndHsvConversionTests |
|||
{ |
|||
private static readonly ApproximateColorProfileComparer Comparer = new(.0002F); |
|||
|
|||
[Theory] |
|||
[InlineData(0, 0, 0, 0, 0, 0)] |
|||
[InlineData(0.360555, 0.936901, 0.1001514, 120, 1, 0.9999999)] |
|||
public void Convert_CieXyz_to_Hsv(float x, float y, float yl, float h, float s, float v) |
|||
{ |
|||
// Arrange
|
|||
CieXyz input = new(x, y, yl); |
|||
Hsv expected = new(h, s, v); |
|||
ColorProfileConverter converter = new(); |
|||
|
|||
Span<CieXyz> inputSpan = new CieXyz[5]; |
|||
inputSpan.Fill(input); |
|||
|
|||
Span<Hsv> actualSpan = new Hsv[5]; |
|||
|
|||
// Act
|
|||
Hsv actual = converter.Convert<CieXyz, Hsv>(input); |
|||
converter.Convert<CieXyz, Hsv>(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(120, 1, 0.9999999, 0.3850648, 0.7168785, 0.09710446)] |
|||
public void Convert_Hsv_to_CieXyz(float h, float s, float v, float x, float y, float yl) |
|||
{ |
|||
// Arrange
|
|||
Hsv input = new(h, s, v); |
|||
CieXyz expected = new(x, y, yl); |
|||
ColorProfileConverter converter = new(); |
|||
|
|||
Span<Hsv> inputSpan = new Hsv[5]; |
|||
inputSpan.Fill(input); |
|||
|
|||
Span<CieXyz> actualSpan = new CieXyz[5]; |
|||
|
|||
// Act
|
|||
CieXyz actual = converter.Convert<Hsv, CieXyz>(input); |
|||
converter.Convert<Hsv, 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,74 @@ |
|||
// 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="HunterLab"/> conversions.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// Test data generated using:
|
|||
/// <see href="http://www.brucelindbloom.com/index.html?ColorCalculator.html"/>
|
|||
/// </remarks>
|
|||
public class CieXyzAndHunterLabConversionTest |
|||
{ |
|||
private static readonly ApproximateColorProfileComparer Comparer = new(.0002f); |
|||
|
|||
[Theory] |
|||
[InlineData(0, 0, 0, 0, 0, 0)] |
|||
[InlineData(0.360555, 0.936901, 0.1001514, 96.79365, -100.951096, 49.35507)] |
|||
public void Convert_Xyz_To_HunterLab(float x, float y, float z, float l, float a, float b) |
|||
{ |
|||
// Arrange
|
|||
CieXyz input = new(x, y, z); |
|||
HunterLab expected = new(l, a, b); |
|||
ColorProfileConverter converter = new(); |
|||
|
|||
Span<CieXyz> inputSpan = new CieXyz[5]; |
|||
inputSpan.Fill(input); |
|||
|
|||
Span<HunterLab> actualSpan = new HunterLab[5]; |
|||
|
|||
// Act
|
|||
HunterLab actual = converter.Convert<CieXyz, HunterLab>(input); |
|||
converter.Convert<CieXyz, HunterLab>(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(31.6467056, -33.00599, 25.67032, 0.0385420471, 0.10015139, -0.0317969956)] |
|||
public void Convert_HunterLab_To_Xyz(float l, float a, float b, float x, float y, float z) |
|||
{ |
|||
// Arrange
|
|||
HunterLab input = new(l, a, b); |
|||
CieXyz expected = new(x, y, z); |
|||
ColorProfileConverter converter = new(); |
|||
|
|||
Span<HunterLab> inputSpan = new HunterLab[5]; |
|||
inputSpan.Fill(input); |
|||
|
|||
Span<CieXyz> actualSpan = new CieXyz[5]; |
|||
|
|||
// Act
|
|||
CieXyz actual = converter.Convert<HunterLab, CieXyz>(input); |
|||
converter.Convert<HunterLab, 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,70 @@ |
|||
// 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="YCbCr"/> conversions.
|
|||
/// </summary>
|
|||
public class CieXyzAndYCbCrConversionTests |
|||
{ |
|||
private static readonly ApproximateColorProfileComparer Comparer = new(.0002f); |
|||
|
|||
[Theory] |
|||
[InlineData(0, 0, 0, 0, 128, 128)] |
|||
[InlineData(0.360555, 0.936901, 0.1001514, 149.685, 43.52769, 21.23457)] |
|||
public void Convert_CieXyz_to_YCbCr(float x, float y, float z, float y2, float cb, float cr) |
|||
{ |
|||
// Arrange
|
|||
CieXyz input = new(x, y, z); |
|||
YCbCr expected = new(y2, cb, cr); |
|||
ColorProfileConverter converter = new(); |
|||
|
|||
Span<CieXyz> inputSpan = new CieXyz[5]; |
|||
inputSpan.Fill(input); |
|||
|
|||
Span<YCbCr> actualSpan = new YCbCr[5]; |
|||
|
|||
// Act
|
|||
YCbCr actual = converter.Convert<CieXyz, YCbCr>(input); |
|||
converter.Convert<CieXyz, YCbCr>(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, 128, 128, 0, 0, 0)] |
|||
[InlineData(149.685, 43.52769, 21.23457, 0.38506496, 0.716878653, 0.0971045)] |
|||
public void Convert_YCbCr_to_CieXyz(float y2, float cb, float cr, float x, float y, float z) |
|||
{ |
|||
// Arrange
|
|||
YCbCr input = new(y2, cb, cr); |
|||
CieXyz expected = new(x, y, z); |
|||
ColorProfileConverter converter = new(); |
|||
|
|||
Span<YCbCr> inputSpan = new YCbCr[5]; |
|||
inputSpan.Fill(input); |
|||
|
|||
Span<CieXyz> actualSpan = new CieXyz[5]; |
|||
|
|||
// Act
|
|||
CieXyz actual = converter.Convert<YCbCr, CieXyz>(input); |
|||
converter.Convert<YCbCr, 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,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="Cmyk"/>-<see cref="CieLch"/> conversions.
|
|||
/// </summary>
|
|||
public class CmykAndCieLchConversionTests |
|||
{ |
|||
private static readonly ApproximateColorProfileComparer Comparer = new(.0002f); |
|||
|
|||
[Theory] |
|||
[InlineData(0.360555, 0.1036901, 0.818514, 0.274615, 62.85025, 64.77041, 118.2425)] |
|||
public void Convert_Cmyk_To_CieLch(float c, float m, float y, float k, float l, float c2, float h) |
|||
{ |
|||
// Arrange
|
|||
Cmyk input = new(c, m, y, k); |
|||
CieLch expected = new(l, c2, h); |
|||
ColorProfileConverter converter = new(); |
|||
|
|||
Span<Cmyk> inputSpan = new Cmyk[5]; |
|||
inputSpan.Fill(input); |
|||
|
|||
Span<CieLch> actualSpan = new CieLch[5]; |
|||
|
|||
// Act
|
|||
CieLch actual = converter.Convert<Cmyk, CieLch>(input); |
|||
converter.Convert<Cmyk, CieLch>(inputSpan, actualSpan); |
|||
|
|||
// Assert
|
|||
Assert.Equal(expected, actual, Comparer); |
|||
|
|||
for (int i = 0; i < actualSpan.Length; i++) |
|||
{ |
|||
Assert.Equal(expected, actualSpan[i], Comparer); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[InlineData(100, 3.81656E-05, 218.6598, 0, 1.192093E-07, 0, 5.960464E-08)] |
|||
[InlineData(62.85025, 64.77041, 118.2425, 0.286581, 0, 0.7975187, 0.34983)] |
|||
public void Convert_CieLch_To_Cmyk(float l, float c2, float h, float c, float m, float y, float k) |
|||
{ |
|||
// Arrange
|
|||
CieLch input = new(l, c2, h); |
|||
Cmyk expected = new(c, m, y, k); |
|||
ColorProfileConverter converter = new(); |
|||
|
|||
Span<CieLch> inputSpan = new CieLch[5]; |
|||
inputSpan.Fill(input); |
|||
|
|||
Span<Cmyk> actualSpan = new Cmyk[5]; |
|||
|
|||
// Act
|
|||
Cmyk actual = converter.Convert<CieLch, Cmyk>(input); |
|||
converter.Convert<CieLch, Cmyk>(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,70 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using SixLabors.ImageSharp.ColorProfiles; |
|||
|
|||
namespace SixLabors.ImageSharp.Tests.ColorProfiles; |
|||
|
|||
/// <summary>
|
|||
/// Tests <see cref="Cmyk"/>-<see cref="CieLuv"/> conversions.
|
|||
/// </summary>
|
|||
public class CmykAndCieLuvConversionTests |
|||
{ |
|||
private static readonly ApproximateColorProfileComparer Comparer = new(.0002f); |
|||
|
|||
[Theory] |
|||
[InlineData(0, 0, 0, 0, 100, -1.937151E-05, -3.874302E-05)] |
|||
[InlineData(0.360555, 0.1036901, 0.818514, 0.274615, 62.85024, -24.4844189, 54.8588524)] |
|||
public void Convert_Cmyk_To_CieLuv(float c, float m, float y, float k, float l, float u, float v) |
|||
{ |
|||
// Arrange
|
|||
Cmyk input = new(c, m, y, k); |
|||
CieLuv expected = new(l, u, v); |
|||
ColorProfileConverter converter = new(); |
|||
|
|||
Span<Cmyk> inputSpan = new Cmyk[5]; |
|||
inputSpan.Fill(input); |
|||
|
|||
Span<CieLuv> actualSpan = new CieLuv[5]; |
|||
|
|||
// Act
|
|||
CieLuv actual = converter.Convert<Cmyk, CieLuv>(input); |
|||
converter.Convert<Cmyk, CieLuv>(inputSpan, actualSpan); |
|||
|
|||
// Assert
|
|||
Assert.Equal(expected, actual, Comparer); |
|||
|
|||
for (int i = 0; i < actualSpan.Length; i++) |
|||
{ |
|||
Assert.Equal(expected, actualSpan[i], Comparer); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[InlineData(100, -1.937151E-05, -3.874302E-05, 0, 5.96046448E-08, 0, 0)] |
|||
[InlineData(62.85024, -24.4844189, 54.8588524, 0.2865809, 0, 0.797518551, 0.3498301)] |
|||
public void Convert_CieLuv_To_Cmyk(float l, float u, float v, float c, float m, float y, float k) |
|||
{ |
|||
// Arrange
|
|||
CieLuv input = new(l, u, v); |
|||
Cmyk expected = new(c, m, y, k); |
|||
ColorProfileConverter converter = new(); |
|||
|
|||
Span<CieLuv> inputSpan = new CieLuv[5]; |
|||
inputSpan.Fill(input); |
|||
|
|||
Span<Cmyk> actualSpan = new Cmyk[5]; |
|||
|
|||
// Act
|
|||
Cmyk actual = converter.Convert<CieLuv, Cmyk>(input); |
|||
converter.Convert<CieLuv, Cmyk>(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,83 @@ |
|||
// 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="Rgb"/>-<see cref="Hsl"/> conversions.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// Test data generated using:
|
|||
/// <see href="http://www.colorhexa.com"/>
|
|||
/// <see href="http://www.rapidtables.com/convert/color/hsl-to-rgb"/>
|
|||
/// </remarks>
|
|||
public class RgbAndHslConversionTest |
|||
{ |
|||
private static readonly ApproximateColorProfileComparer Comparer = new(.0001f); |
|||
|
|||
[Theory] |
|||
[InlineData(0, 0, 0, 0, 0, 0)] |
|||
[InlineData(0, 1, 1, 1, 1, 1)] |
|||
[InlineData(360, 1, 1, 1, 1, 1)] |
|||
[InlineData(0, 1, .5F, 1, 0, 0)] |
|||
[InlineData(120, 1, .5F, 0, 1, 0)] |
|||
[InlineData(240, 1, .5F, 0, 0, 1)] |
|||
public void Convert_Hsl_To_Rgb(float h, float s, float l, float r, float g, float b) |
|||
{ |
|||
// Arrange
|
|||
Hsl input = new(h, s, l); |
|||
Rgb expected = new(r, g, b); |
|||
ColorProfileConverter converter = new(); |
|||
|
|||
Span<Hsl> inputSpan = new Hsl[5]; |
|||
inputSpan.Fill(input); |
|||
|
|||
Span<Rgb> actualSpan = new Rgb[5]; |
|||
|
|||
// Act
|
|||
Rgb actual = converter.Convert<Hsl, Rgb>(input); |
|||
converter.Convert<Hsl, Rgb>(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(1, 1, 1, 0, 0, 1)] |
|||
[InlineData(1, 0, 0, 0, 1, .5F)] |
|||
[InlineData(0, 1, 0, 120, 1, .5F)] |
|||
[InlineData(0, 0, 1, 240, 1, .5F)] |
|||
[InlineData(0.7, 0.8, 0.6, 90, 0.3333, 0.7F)] |
|||
public void Convert_Rgb_To_Hsl(float r, float g, float b, float h, float s, float l) |
|||
{ |
|||
// Arrange
|
|||
Rgb input = new(r, g, b); |
|||
Hsl expected = new(h, s, l); |
|||
ColorProfileConverter converter = new(); |
|||
|
|||
Span<Rgb> inputSpan = new Rgb[5]; |
|||
inputSpan.Fill(input); |
|||
|
|||
Span<Hsl> actualSpan = new Hsl[5]; |
|||
|
|||
// Act
|
|||
Hsl actual = converter.Convert<Rgb, Hsl>(input); |
|||
converter.Convert<Rgb, Hsl>(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,81 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using SixLabors.ImageSharp.ColorProfiles; |
|||
|
|||
namespace SixLabors.ImageSharp.Tests.ColorProfiles; |
|||
|
|||
/// <summary>
|
|||
/// Tests <see cref="Rgb"/>-<see cref="Hsv"/> conversions.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// Test data generated using:
|
|||
/// <see href="http://www.colorhexa.com"/>
|
|||
/// </remarks>
|
|||
public class RgbAndHsvConversionTest |
|||
{ |
|||
private static readonly ApproximateColorProfileComparer Comparer = new(.0001f); |
|||
|
|||
[Theory] |
|||
[InlineData(0, 0, 0, 0, 0, 0)] |
|||
[InlineData(0, 0, 1, 1, 1, 1)] |
|||
[InlineData(360, 1, 1, 1, 0, 0)] |
|||
[InlineData(0, 1, 1, 1, 0, 0)] |
|||
[InlineData(120, 1, 1, 0, 1, 0)] |
|||
[InlineData(240, 1, 1, 0, 0, 1)] |
|||
public void Convert_Hsv_To_Rgb(float h, float s, float v, float r, float g, float b) |
|||
{ |
|||
// Arrange
|
|||
Hsv input = new(h, s, v); |
|||
Rgb expected = new(r, g, b); |
|||
ColorProfileConverter converter = new(); |
|||
|
|||
Span<Hsv> inputSpan = new Hsv[5]; |
|||
inputSpan.Fill(input); |
|||
|
|||
Span<Rgb> actualSpan = new Rgb[5]; |
|||
|
|||
// Act
|
|||
Rgb actual = converter.Convert<Hsv, Rgb>(input); |
|||
converter.Convert<Hsv, Rgb>(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(1, 1, 1, 0, 0, 1)] |
|||
[InlineData(1, 0, 0, 0, 1, 1)] |
|||
[InlineData(0, 1, 0, 120, 1, 1)] |
|||
[InlineData(0, 0, 1, 240, 1, 1)] |
|||
public void Convert_Rgb_To_Hsv(float r, float g, float b, float h, float s, float v) |
|||
{ |
|||
// Arrange
|
|||
Rgb input = new(r, g, b); |
|||
Hsv expected = new(h, s, v); |
|||
ColorProfileConverter converter = new(); |
|||
|
|||
Span<Rgb> inputSpan = new Rgb[5]; |
|||
inputSpan.Fill(input); |
|||
|
|||
Span<Hsv> actualSpan = new Hsv[5]; |
|||
|
|||
// Act
|
|||
Hsv actual = converter.Convert<Rgb, Hsv>(input); |
|||
converter.Convert<Rgb, Hsv>(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