Browse Source

Complete Rgb conversion

pull/2739/head
James Jackson-South 2 years ago
parent
commit
cb71ae2436
  1. 2
      src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieLabCieXyz.cs
  2. 2
      src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieXyzCieLab.cs
  3. 14
      src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieXyzCieXyz.cs
  4. 19
      src/ImageSharp/ColorProfiles/Companding/CompandingUtilities.cs
  5. 10
      src/ImageSharp/ColorProfiles/Companding/GammaCompanding.cs
  6. 10
      src/ImageSharp/ColorProfiles/Companding/LCompanding.cs
  7. 10
      src/ImageSharp/ColorProfiles/Companding/Rec2020Companding.cs
  8. 10
      src/ImageSharp/ColorProfiles/Companding/Rec709Companding.cs
  9. 10
      src/ImageSharp/ColorProfiles/Companding/SRgbCompanding.cs
  10. 7
      tests/ImageSharp.Tests/ColorProfiles/ApproximateColorProfileComparer.cs
  11. 151
      tests/ImageSharp.Tests/ColorProfiles/RgbAndCieXyzConversionTest.cs

2
src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieLabCieXyz.cs

@ -21,7 +21,7 @@ internal static class ColorProfileConverterExtensionsCieLabCieXyz
CieXyz pcsTo = pcsFrom.ToProfileConnectingSpace(options);
// Adapt to target white point
VonKriesChromaticAdaptation.Transform<TFrom, TTo>(options, in pcsTo);
pcsTo = VonKriesChromaticAdaptation.Transform<TFrom, TTo>(options, in pcsTo);
// Convert to output from PCS
return TTo.FromProfileConnectingSpace(options, pcsTo);

2
src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieXyzCieLab.cs

@ -18,7 +18,7 @@ internal static class ColorProfileConverterExtensionsCieXyzCieLab
CieXyz pcsFrom = source.ToProfileConnectingSpace(options);
// Adapt to target white point
VonKriesChromaticAdaptation.Transform<TFrom, TTo>(options, in pcsFrom);
pcsFrom = VonKriesChromaticAdaptation.Transform<TFrom, TTo>(options, in pcsFrom);
// Convert between PCS
CieLab pcsTo = CieLab.FromProfileConnectingSpace(options, in pcsFrom);

14
src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieXyzCieXyz.cs

@ -18,13 +18,10 @@ internal static class ColorProfileConverterExtensionsCieXyzCieXyz
CieXyz pcsFrom = source.ToProfileConnectingSpace(options);
// Adapt to target white point
VonKriesChromaticAdaptation.Transform<TFrom, TTo>(options, in pcsFrom);
// Convert between PCS
CieXyz pcsTo = CieXyz.FromProfileConnectingSpace(options, in pcsFrom);
pcsFrom = VonKriesChromaticAdaptation.Transform<TFrom, TTo>(options, in pcsFrom);
// Convert to output from PCS
return TTo.FromProfileConnectingSpace(options, pcsTo);
return TTo.FromProfileConnectingSpace(options, pcsFrom);
}
public static void Convert<TFrom, TTo>(this ColorProfileConverter converter, ReadOnlySpan<TFrom> source, Span<TTo> destination)
@ -41,12 +38,7 @@ internal static class ColorProfileConverterExtensionsCieXyzCieXyz
// Adapt to target white point
VonKriesChromaticAdaptation.Transform<TFrom, TTo>(options, pcsFrom, pcsFrom);
// Convert between PCS.
using IMemoryOwner<CieXyz> pcsToOwner = options.MemoryAllocator.Allocate<CieXyz>(source.Length);
Span<CieXyz> pcsTo = pcsToOwner.GetSpan();
CieXyz.FromProfileConnectionSpace(options, pcsFrom, pcsTo);
// Convert to output from PCS
TTo.FromProfileConnectionSpace(options, pcsTo, destination);
TTo.FromProfileConnectionSpace(options, pcsFrom, destination);
}
}

19
src/ImageSharp/ColorProfiles/Companding/CompandingUtilities.cs

@ -17,17 +17,28 @@ public static class CompandingUtilities
{
private const int Length = Scale + 2; // 256kb @ 16bit precision.
private const int Scale = (1 << 16) - 1;
private static readonly ConcurrentDictionary<(Type, double), Lazy<float[]>> LookupTables = new();
private static readonly ConcurrentDictionary<(Type, double), float[]> CompressLookupTables = new();
private static readonly ConcurrentDictionary<(Type, double), float[]> ExpandLookupTables = new();
/// <summary>
/// Lazily creates and stores a companding lookup table using the given function and modifier.
/// Lazily creates and stores a companding compression lookup table using the given function and modifier.
/// </summary>
/// <typeparam name="T">The type of companding function.</typeparam>
/// <param name="compandingFunction">The companding function.</param>
/// <param name="modifier">A modifier to pass to the function.</param>
/// <returns>The <see cref="float"/> array.</returns>
public static Lazy<float[]> GetLookupTable<T>(Func<double, double, double> compandingFunction, double modifier = 0)
=> LookupTables.GetOrAdd((typeof(T), modifier), args => new(() => CreateLookupTableImpl(compandingFunction, args.Item2), true));
public static float[] GetCompressLookupTable<T>(Func<double, double, double> compandingFunction, double modifier = 0)
=> CompressLookupTables.GetOrAdd((typeof(T), modifier), args => CreateLookupTableImpl(compandingFunction, args.Item2));
/// <summary>
/// Lazily creates and stores a companding expanding lookup table using the given function and modifier.
/// </summary>
/// <typeparam name="T">The type of companding function.</typeparam>
/// <param name="compandingFunction">The companding function.</param>
/// <param name="modifier">A modifier to pass to the function.</param>
/// <returns>The <see cref="float"/> array.</returns>
public static float[] GetExpandLookupTable<T>(Func<double, double, double> compandingFunction, double modifier = 0)
=> ExpandLookupTables.GetOrAdd((typeof(T), modifier), args => CreateLookupTableImpl(compandingFunction, args.Item2));
/// <summary>
/// Creates a companding lookup table using the given function.

10
src/ImageSharp/ColorProfiles/Companding/GammaCompanding.cs

@ -24,7 +24,7 @@ public static class GammaCompanding
/// <param name="vectors">The span of vectors.</param>
/// <param name="gamma">The gamma value.</param>
public static void Compress(Span<Vector4> vectors, double gamma)
=> CompandingUtilities.Compand(vectors, CompandingUtilities.GetLookupTable<GammaCompandingKey>(CompressFunction, gamma).Value);
=> CompandingUtilities.Compand(vectors, CompandingUtilities.GetCompressLookupTable<GammaCompandingKey>(CompressFunction, gamma));
/// <summary>
/// Expands the nonlinear vectors to their linear equivalents with respect to the energy.
@ -32,7 +32,7 @@ public static class GammaCompanding
/// <param name="vectors">The span of vectors.</param>
/// <param name="gamma">The gamma value.</param>
public static void Expand(Span<Vector4> vectors, double gamma)
=> CompandingUtilities.Compand(vectors, CompandingUtilities.GetLookupTable<GammaCompandingKey>(ExpandFunction, gamma).Value);
=> CompandingUtilities.Compand(vectors, CompandingUtilities.GetExpandLookupTable<GammaCompandingKey>(ExpandFunction, gamma));
/// <summary>
/// Compresses the linear vector to its nonlinear equivalent with respect to the energy.
@ -41,16 +41,16 @@ public static class GammaCompanding
/// <param name="gamma">The gamma value.</param>
/// <returns>The <see cref="Vector4"/>.</returns>
public static Vector4 Compress(Vector4 vector, double gamma)
=> CompandingUtilities.Compand(vector, CompandingUtilities.GetLookupTable<GammaCompandingKey>(CompressFunction, gamma).Value);
=> CompandingUtilities.Compand(vector, CompandingUtilities.GetCompressLookupTable<GammaCompandingKey>(CompressFunction, gamma));
/// <summary>
/// Compresses the linear vector to its nonlinear equivalent with respect to the energy.
/// Expands the nonlinear vector to its linear equivalent with respect to the energy.
/// </summary>
/// <param name="vector">The vector.</param>
/// <param name="gamma">The gamma value.</param>
/// <returns>The <see cref="Vector4"/>.</returns>
public static Vector4 Expand(Vector4 vector, double gamma)
=> CompandingUtilities.Compand(vector, CompandingUtilities.GetLookupTable<GammaCompandingKey>(ExpandFunction, gamma).Value);
=> CompandingUtilities.Compand(vector, CompandingUtilities.GetExpandLookupTable<GammaCompandingKey>(ExpandFunction, gamma));
private class GammaCompandingKey;
}

10
src/ImageSharp/ColorProfiles/Companding/LCompanding.cs

@ -42,14 +42,14 @@ public static class LCompanding
/// </summary>
/// <param name="vectors">The span of vectors.</param>
public static void Compress(Span<Vector4> vectors)
=> CompandingUtilities.Compand(vectors, CompandingUtilities.GetLookupTable<LCompandingKey>(CompressFunction).Value);
=> CompandingUtilities.Compand(vectors, CompandingUtilities.GetCompressLookupTable<LCompandingKey>(CompressFunction));
/// <summary>
/// Expands the nonlinear vectors to their linear equivalents with respect to the energy.
/// </summary>
/// <param name="vectors">The span of vectors.</param>
public static void Expand(Span<Vector4> vectors)
=> CompandingUtilities.Compand(vectors, CompandingUtilities.GetLookupTable<LCompandingKey>(ExpandFunction).Value);
=> CompandingUtilities.Compand(vectors, CompandingUtilities.GetExpandLookupTable<LCompandingKey>(ExpandFunction));
/// <summary>
/// Compresses the linear vector to its nonlinear equivalent with respect to the energy.
@ -57,15 +57,15 @@ public static class LCompanding
/// <param name="vector">The vector.</param>
/// <returns>The <see cref="Vector4"/>.</returns>
public static Vector4 Compress(Vector4 vector)
=> CompandingUtilities.Compand(vector, CompandingUtilities.GetLookupTable<LCompandingKey>(CompressFunction).Value);
=> CompandingUtilities.Compand(vector, CompandingUtilities.GetCompressLookupTable<LCompandingKey>(CompressFunction));
/// <summary>
/// Compresses the linear vector to its nonlinear equivalent with respect to the energy.
/// Expands the nonlinear vector to its linear equivalent with respect to the energy.
/// </summary>
/// <param name="vector">The vector.</param>
/// <returns>The <see cref="Vector4"/>.</returns>
public static Vector4 Expand(Vector4 vector)
=> CompandingUtilities.Compand(vector, CompandingUtilities.GetLookupTable<LCompandingKey>(ExpandFunction).Value);
=> CompandingUtilities.Compand(vector, CompandingUtilities.GetExpandLookupTable<LCompandingKey>(ExpandFunction));
private class LCompandingKey;
}

10
src/ImageSharp/ColorProfiles/Companding/Rec2020Companding.cs

@ -46,14 +46,14 @@ public static class Rec2020Companding
/// </summary>
/// <param name="vectors">The span of vectors.</param>
public static void Compress(Span<Vector4> vectors)
=> CompandingUtilities.Compand(vectors, CompandingUtilities.GetLookupTable<Rec2020CompandingKey>(CompressFunction).Value);
=> CompandingUtilities.Compand(vectors, CompandingUtilities.GetCompressLookupTable<Rec2020CompandingKey>(CompressFunction));
/// <summary>
/// Expands the nonlinear vectors to their linear equivalents with respect to the energy.
/// </summary>
/// <param name="vectors">The span of vectors.</param>
public static void Expand(Span<Vector4> vectors)
=> CompandingUtilities.Compand(vectors, CompandingUtilities.GetLookupTable<Rec2020CompandingKey>(ExpandFunction).Value);
=> CompandingUtilities.Compand(vectors, CompandingUtilities.GetExpandLookupTable<Rec2020CompandingKey>(ExpandFunction));
/// <summary>
/// Compresses the linear vector to its nonlinear equivalent with respect to the energy.
@ -61,15 +61,15 @@ public static class Rec2020Companding
/// <param name="vector">The vector.</param>
/// <returns>The <see cref="Vector4"/>.</returns>
public static Vector4 Compress(Vector4 vector)
=> CompandingUtilities.Compand(vector, CompandingUtilities.GetLookupTable<Rec2020CompandingKey>(CompressFunction).Value);
=> CompandingUtilities.Compand(vector, CompandingUtilities.GetCompressLookupTable<Rec2020CompandingKey>(CompressFunction));
/// <summary>
/// Compresses the linear vector to its nonlinear equivalent with respect to the energy.
/// Expands the nonlinear vector to its linear equivalent with respect to the energy.
/// </summary>
/// <param name="vector">The vector.</param>
/// <returns>The <see cref="Vector4"/>.</returns>
public static Vector4 Expand(Vector4 vector)
=> CompandingUtilities.Compand(vector, CompandingUtilities.GetLookupTable<Rec2020CompandingKey>(ExpandFunction).Value);
=> CompandingUtilities.Compand(vector, CompandingUtilities.GetExpandLookupTable<Rec2020CompandingKey>(ExpandFunction));
private class Rec2020CompandingKey;
}

10
src/ImageSharp/ColorProfiles/Companding/Rec709Companding.cs

@ -42,14 +42,14 @@ public static class Rec709Companding
/// </summary>
/// <param name="vectors">The span of vectors.</param>
public static void Compress(Span<Vector4> vectors)
=> CompandingUtilities.Compand(vectors, CompandingUtilities.GetLookupTable<Rec2020CompandingKey>(CompressFunction).Value);
=> CompandingUtilities.Compand(vectors, CompandingUtilities.GetCompressLookupTable<Rec2020CompandingKey>(CompressFunction));
/// <summary>
/// Expands the nonlinear vectors to their linear equivalents with respect to the energy.
/// </summary>
/// <param name="vectors">The span of vectors.</param>
public static void Expand(Span<Vector4> vectors)
=> CompandingUtilities.Compand(vectors, CompandingUtilities.GetLookupTable<Rec2020CompandingKey>(ExpandFunction).Value);
=> CompandingUtilities.Compand(vectors, CompandingUtilities.GetExpandLookupTable<Rec2020CompandingKey>(ExpandFunction));
/// <summary>
/// Compresses the linear vector to its nonlinear equivalent with respect to the energy.
@ -57,15 +57,15 @@ public static class Rec709Companding
/// <param name="vector">The vector.</param>
/// <returns>The <see cref="Vector4"/>.</returns>
public static Vector4 Compress(Vector4 vector)
=> CompandingUtilities.Compand(vector, CompandingUtilities.GetLookupTable<Rec2020CompandingKey>(CompressFunction).Value);
=> CompandingUtilities.Compand(vector, CompandingUtilities.GetCompressLookupTable<Rec2020CompandingKey>(CompressFunction));
/// <summary>
/// Compresses the linear vector to its nonlinear equivalent with respect to the energy.
/// Expands the nonlinear vector to its linear equivalent with respect to the energy.
/// </summary>
/// <param name="vector">The vector.</param>
/// <returns>The <see cref="Vector4"/>.</returns>
public static Vector4 Expand(Vector4 vector)
=> CompandingUtilities.Compand(vector, CompandingUtilities.GetLookupTable<Rec2020CompandingKey>(ExpandFunction).Value);
=> CompandingUtilities.Compand(vector, CompandingUtilities.GetExpandLookupTable<Rec2020CompandingKey>(ExpandFunction));
private class Rec2020CompandingKey;
}

10
src/ImageSharp/ColorProfiles/Companding/SRgbCompanding.cs

@ -42,14 +42,14 @@ public static class SRgbCompanding
/// </summary>
/// <param name="vectors">The span of vectors.</param>
public static void Compress(Span<Vector4> vectors)
=> CompandingUtilities.Compand(vectors, CompandingUtilities.GetLookupTable<SRgbCompandingKey>(CompressFunction).Value);
=> CompandingUtilities.Compand(vectors, CompandingUtilities.GetCompressLookupTable<SRgbCompandingKey>(CompressFunction));
/// <summary>
/// Expands the nonlinear vectors to their linear equivalents with respect to the energy.
/// </summary>
/// <param name="vectors">The span of vectors.</param>
public static void Expand(Span<Vector4> vectors)
=> CompandingUtilities.Compand(vectors, CompandingUtilities.GetLookupTable<SRgbCompandingKey>(ExpandFunction).Value);
=> CompandingUtilities.Compand(vectors, CompandingUtilities.GetExpandLookupTable<SRgbCompandingKey>(ExpandFunction));
/// <summary>
/// Compresses the linear vector to its nonlinear equivalent with respect to the energy.
@ -57,15 +57,15 @@ public static class SRgbCompanding
/// <param name="vector">The vector.</param>
/// <returns>The <see cref="Vector4"/>.</returns>
public static Vector4 Compress(Vector4 vector)
=> CompandingUtilities.Compand(vector, CompandingUtilities.GetLookupTable<SRgbCompandingKey>(CompressFunction).Value);
=> CompandingUtilities.Compand(vector, CompandingUtilities.GetCompressLookupTable<SRgbCompandingKey>(CompressFunction));
/// <summary>
/// Compresses the linear vector to its nonlinear equivalent with respect to the energy.
/// Expands the nonlinear vector to its linear equivalent with respect to the energy.
/// </summary>
/// <param name="vector">The vector.</param>
/// <returns>The <see cref="Vector4"/>.</returns>
public static Vector4 Expand(Vector4 vector)
=> CompandingUtilities.Compand(vector, CompandingUtilities.GetLookupTable<SRgbCompandingKey>(ExpandFunction).Value);
=> CompandingUtilities.Compand(vector, CompandingUtilities.GetExpandLookupTable<SRgbCompandingKey>(ExpandFunction));
private class SRgbCompandingKey;
}

7
tests/ImageSharp.Tests/ColorProfiles/ApproximateColorProfileComparer.cs

@ -13,7 +13,8 @@ internal readonly struct ApproximateColorProfileComparer :
IEqualityComparer<CieLab>,
IEqualityComparer<CieXyz>,
IEqualityComparer<Lms>,
IEqualityComparer<CieLch>
IEqualityComparer<CieLch>,
IEqualityComparer<Rgb>
{
private readonly float epsilon;
@ -31,6 +32,8 @@ internal readonly struct ApproximateColorProfileComparer :
public bool Equals(CieLch x, CieLch y) => this.Equals(x.L, y.L) && this.Equals(x.C, y.C) && this.Equals(x.H, y.H);
public bool Equals(Rgb x, Rgb y) => this.Equals(x.R, y.R) && this.Equals(x.G, y.G) && this.Equals(x.B, y.B);
public int GetHashCode([DisallowNull] CieLab obj) => obj.GetHashCode();
public int GetHashCode([DisallowNull] CieXyz obj) => obj.GetHashCode();
@ -39,6 +42,8 @@ internal readonly struct ApproximateColorProfileComparer :
public int GetHashCode([DisallowNull] CieLch obj) => obj.GetHashCode();
public int GetHashCode([DisallowNull] Rgb obj) => obj.GetHashCode();
private bool Equals(float x, float y)
{
float d = x - y;

151
tests/ImageSharp.Tests/ColorProfiles/RgbAndCieXyzConversionTest.cs

@ -0,0 +1,151 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using SixLabors.ColorProfiles;
using SixLabors.ImageSharp.ColorProfiles;
namespace SixLabors.ImageSharp.Tests.ColorProfiles.Conversion;
/// <summary>
/// Tests <see cref="CieXyz"/>-<see cref="Rgb"/> conversions.
/// </summary>
/// <remarks>
/// Test data generated using:
/// <see href="http://www.brucelindbloom.com/index.html?ColorCalculator.html"/>
/// </remarks>
public class RgbAndCieXyzConversionTest
{
private static readonly ApproximateColorProfileComparer Comparer = new(.0001F);
[Theory]
[InlineData(0.96422, 1.00000, 0.82521, 1, 1, 1)]
[InlineData(0.00000, 1.00000, 0.00000, 0, 1, 0)]
[InlineData(0.96422, 0.00000, 0.00000, 1, 0, 0.292064)]
[InlineData(0.00000, 0.00000, 0.82521, 0, 0.181415, 1)]
[InlineData(0, 0, 0, 0, 0, 0)]
[InlineData(0.297676, 0.267854, 0.045504, 0.720315, 0.509999, 0.168112)]
public void Convert_XYZ_D50_to_SRGB(float x, float y, float z, float r, float g, float b)
{
// Arrange
CieXyz input = new(x, y, z);
ColorConversionOptions options = new() { WhitePoint = Illuminants.D50, TargetRgbWorkingSpace = RgbWorkingSpaces.SRgb };
ColorProfileConverter converter = new(options);
Rgb expected = new(r, g, b);
Span<CieXyz> inputSpan = new CieXyz[5];
inputSpan.Fill(input);
Span<Rgb> actualSpan = new Rgb[5];
// Act
Rgb actual = converter.Convert<CieXyz, Rgb>(input);
converter.Convert<CieXyz, 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.950470, 1.000000, 1.088830, 1, 1, 1)]
[InlineData(0, 1.000000, 0, 0, 1, 0)]
[InlineData(0.950470, 0, 0, 1, 0, 0.254967)]
[InlineData(0, 0, 1.088830, 0, 0.235458, 1)]
[InlineData(0, 0, 0, 0, 0, 0)]
[InlineData(0.297676, 0.267854, 0.045504, 0.754903, 0.501961, 0.099998)]
public void Convert_XYZ_D65_to_SRGB(float x, float y, float z, float r, float g, float b)
{
// Arrange
CieXyz input = new(x, y, z);
ColorConversionOptions options = new() { WhitePoint = Illuminants.D65, TargetRgbWorkingSpace = RgbWorkingSpaces.SRgb };
ColorProfileConverter converter = new(options);
Rgb expected = new(r, g, b);
Span<CieXyz> inputSpan = new CieXyz[5];
inputSpan.Fill(input);
Span<Rgb> actualSpan = new Rgb[5];
// Act
Rgb actual = converter.Convert<CieXyz, Rgb>(input);
converter.Convert<CieXyz, 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(1, 1, 1, 0.964220, 1.000000, 0.825210)]
[InlineData(0, 0, 0, 0, 0, 0)]
[InlineData(1, 0, 0, 0.436075, 0.222504, 0.013932)]
[InlineData(0, 1, 0, 0.385065, 0.716879, 0.0971045)]
[InlineData(0, 0, 1, 0.143080, 0.060617, 0.714173)]
[InlineData(0.754902, 0.501961, 0.100000, 0.315757, 0.273323, 0.035506)]
public void Convert_SRGB_to_XYZ_D50(float r, float g, float b, float x, float y, float z)
{
// Arrange
Rgb input = new(r, g, b);
ColorConversionOptions options = new() { TargetWhitePoint = Illuminants.D50, RgbWorkingSpace = RgbWorkingSpaces.SRgb };
ColorProfileConverter converter = new(options);
CieXyz expected = new(x, y, z);
Span<Rgb> inputSpan = new Rgb[5];
inputSpan.Fill(input);
Span<CieXyz> actualSpan = new CieXyz[5];
// Act
CieXyz actual = converter.Convert<Rgb, CieXyz>(input);
converter.Convert<Rgb, 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(1, 1, 1, 0.950470, 1.000000, 1.088830)]
[InlineData(0, 0, 0, 0, 0, 0)]
[InlineData(1, 0, 0, 0.412456, 0.212673, 0.019334)]
[InlineData(0, 1, 0, 0.357576, 0.715152, 0.119192)]
[InlineData(0, 0, 1, 0.1804375, 0.072175, 0.950304)]
[InlineData(0.754902, 0.501961, 0.100000, 0.297676, 0.267854, 0.045504)]
public void Convert_SRGB_to_XYZ_D65(float r, float g, float b, float x, float y, float z)
{
// Arrange
Rgb input = new(r, g, b);
ColorConversionOptions options = new() { TargetWhitePoint = Illuminants.D65, RgbWorkingSpace = RgbWorkingSpaces.SRgb };
ColorProfileConverter converter = new(options);
CieXyz expected = new(x, y, z);
Span<Rgb> inputSpan = new Rgb[5];
inputSpan.Fill(input);
Span<CieXyz> actualSpan = new CieXyz[5];
// Act
CieXyz actual = converter.Convert<Rgb, CieXyz>(input);
converter.Convert<Rgb, CieXyz>(inputSpan, actualSpan);
// Assert
Assert.Equal(expected, actual, Comparer);
for (int i = 0; i < actualSpan.Length; i++)
{
Assert.Equal(expected, actualSpan[i], Comparer);
}
}
}
Loading…
Cancel
Save