Browse Source

Begin colorspace test cleanup.

af/merge-core
James Jackson-South 8 years ago
parent
commit
28f793d5e8
  1. 1
      src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Lms.cs
  2. 276
      src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs
  3. 255
      src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.YCbCr.cs
  4. 124
      tests/ImageSharp.Tests/Colorspaces/ApproximateColorspaceComparer.cs
  5. 18
      tests/ImageSharp.Tests/Colorspaces/CieLabAndCieLchConversionTests.cs
  6. 18
      tests/ImageSharp.Tests/Colorspaces/CieLuvAndCieLchuvConversionTests.cs
  7. 17
      tests/ImageSharp.Tests/Colorspaces/CieXyzAndCieLabConversionTest.cs
  8. 17
      tests/ImageSharp.Tests/Colorspaces/CieXyzAndCieLuvConversionTest.cs
  9. 17
      tests/ImageSharp.Tests/Colorspaces/CieXyzAndCieXyyConversionTest.cs
  10. 26
      tests/ImageSharp.Tests/Colorspaces/CieXyzAndHunterLabConversionTest.cs
  11. 18
      tests/ImageSharp.Tests/Colorspaces/CieXyzAndLmsConversionTest.cs
  12. 65
      tests/ImageSharp.Tests/Colorspaces/ColorConverterAdaptTest.cs
  13. 445
      tests/ImageSharp.Tests/Colorspaces/ColorSpaceEqualityTests.cs
  14. 2
      tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs

1
src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Lms.cs

@ -1,5 +1,6 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System; using System;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;

276
src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs

@ -1,6 +1,9 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation; using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
namespace SixLabors.ImageSharp.ColorSpaces.Conversion namespace SixLabors.ImageSharp.ColorSpaces.Conversion
@ -23,6 +26,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToRgb(xyzColor); return this.ToRgb(xyzColor);
} }
/// <summary>
/// Performs the bulk conversion from <see cref="CieLab"/> into <see cref="Rgb"/>
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(Span<CieLab> source, Span<Rgb> destination, int count)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
ref CieLab sourceRef = ref MemoryMarshal.GetReference(source);
ref Rgb destRef = ref MemoryMarshal.GetReference(destination);
for (int i = 0; i < count; i++)
{
ref CieLab sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb dp = ref Unsafe.Add(ref destRef, i);
dp = this.ToRgb(sp);
}
}
/// <summary> /// <summary>
/// Converts a <see cref="CieLch"/> into a <see cref="Rgb"/> /// Converts a <see cref="CieLch"/> into a <see cref="Rgb"/>
/// </summary> /// </summary>
@ -34,6 +58,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToRgb(xyzColor); return this.ToRgb(xyzColor);
} }
/// <summary>
/// Performs the bulk conversion from <see cref="CieLch"/> into <see cref="Rgb"/>
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(Span<CieLch> source, Span<Rgb> destination, int count)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
ref CieLch sourceRef = ref MemoryMarshal.GetReference(source);
ref Rgb destRef = ref MemoryMarshal.GetReference(destination);
for (int i = 0; i < count; i++)
{
ref CieLch sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb dp = ref Unsafe.Add(ref destRef, i);
dp = this.ToRgb(sp);
}
}
/// <summary> /// <summary>
/// Converts a <see cref="CieLchuv"/> into a <see cref="Rgb"/> /// Converts a <see cref="CieLchuv"/> into a <see cref="Rgb"/>
/// </summary> /// </summary>
@ -45,6 +90,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToRgb(xyzColor); return this.ToRgb(xyzColor);
} }
/// <summary>
/// Performs the bulk conversion from <see cref="CieLchuv"/> into <see cref="Rgb"/>
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(Span<CieLchuv> source, Span<Rgb> destination, int count)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source);
ref Rgb destRef = ref MemoryMarshal.GetReference(destination);
for (int i = 0; i < count; i++)
{
ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb dp = ref Unsafe.Add(ref destRef, i);
dp = this.ToRgb(sp);
}
}
/// <summary> /// <summary>
/// Converts a <see cref="CieLuv"/> into a <see cref="Rgb"/> /// Converts a <see cref="CieLuv"/> into a <see cref="Rgb"/>
/// </summary> /// </summary>
@ -56,6 +122,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToRgb(xyzColor); return this.ToRgb(xyzColor);
} }
/// <summary>
/// Performs the bulk conversion from <see cref="CieLuv"/> into <see cref="Rgb"/>
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(Span<CieLuv> source, Span<Rgb> destination, int count)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source);
ref Rgb destRef = ref MemoryMarshal.GetReference(destination);
for (int i = 0; i < count; i++)
{
ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb dp = ref Unsafe.Add(ref destRef, i);
dp = this.ToRgb(sp);
}
}
/// <summary> /// <summary>
/// Converts a <see cref="CieXyy"/> into a <see cref="Rgb"/> /// Converts a <see cref="CieXyy"/> into a <see cref="Rgb"/>
/// </summary> /// </summary>
@ -67,6 +154,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToRgb(xyzColor); return this.ToRgb(xyzColor);
} }
/// <summary>
/// Performs the bulk conversion from <see cref="CieXyy"/> into <see cref="Rgb"/>
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(Span<CieXyy> source, Span<Rgb> destination, int count)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source);
ref Rgb destRef = ref MemoryMarshal.GetReference(destination);
for (int i = 0; i < count; i++)
{
ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb dp = ref Unsafe.Add(ref destRef, i);
dp = this.ToRgb(sp);
}
}
/// <summary> /// <summary>
/// Converts a <see cref="CieXyz"/> into a <see cref="Rgb"/> /// Converts a <see cref="CieXyz"/> into a <see cref="Rgb"/>
/// </summary> /// </summary>
@ -81,6 +189,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToRgb(linear); return this.ToRgb(linear);
} }
/// <summary>
/// Performs the bulk conversion from <see cref="CieXyz"/> into <see cref="Rgb"/>
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(Span<CieXyz> source, Span<Rgb> destination, int count)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source);
ref Rgb destRef = ref MemoryMarshal.GetReference(destination);
for (int i = 0; i < count; i++)
{
ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb dp = ref Unsafe.Add(ref destRef, i);
dp = this.ToRgb(sp);
}
}
/// <summary> /// <summary>
/// Converts a <see cref="Cmyk"/> into a <see cref="Rgb"/> /// Converts a <see cref="Cmyk"/> into a <see cref="Rgb"/>
/// </summary> /// </summary>
@ -92,6 +221,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return CmykAndRgbConverter.Convert(color); return CmykAndRgbConverter.Convert(color);
} }
/// <summary>
/// Performs the bulk conversion from <see cref="Cmyk"/> into <see cref="Rgb"/>
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(Span<Cmyk> source, Span<Rgb> destination, int count)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source);
ref Rgb destRef = ref MemoryMarshal.GetReference(destination);
for (int i = 0; i < count; i++)
{
ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb dp = ref Unsafe.Add(ref destRef, i);
dp = this.ToRgb(sp);
}
}
/// <summary> /// <summary>
/// Converts a <see cref="Hsv"/> into a <see cref="Rgb"/> /// Converts a <see cref="Hsv"/> into a <see cref="Rgb"/>
/// </summary> /// </summary>
@ -103,6 +253,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return HsvAndRgbConverter.Convert(color); return HsvAndRgbConverter.Convert(color);
} }
/// <summary>
/// Performs the bulk conversion from <see cref="Hsv"/> into <see cref="Rgb"/>
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(Span<Hsv> source, Span<Rgb> destination, int count)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
ref Hsv sourceRef = ref MemoryMarshal.GetReference(source);
ref Rgb destRef = ref MemoryMarshal.GetReference(destination);
for (int i = 0; i < count; i++)
{
ref Hsv sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb dp = ref Unsafe.Add(ref destRef, i);
dp = this.ToRgb(sp);
}
}
/// <summary> /// <summary>
/// Converts a <see cref="Hsl"/> into a <see cref="Rgb"/> /// Converts a <see cref="Hsl"/> into a <see cref="Rgb"/>
/// </summary> /// </summary>
@ -114,6 +285,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return HslAndRgbConverter.Convert(color); return HslAndRgbConverter.Convert(color);
} }
/// <summary>
/// Performs the bulk conversion from <see cref="Hsl"/> into <see cref="Rgb"/>
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(Span<Hsl> source, Span<Rgb> destination, int count)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
ref Hsl sourceRef = ref MemoryMarshal.GetReference(source);
ref Rgb destRef = ref MemoryMarshal.GetReference(destination);
for (int i = 0; i < count; i++)
{
ref Hsl sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb dp = ref Unsafe.Add(ref destRef, i);
dp = this.ToRgb(sp);
}
}
/// <summary> /// <summary>
/// Converts a <see cref="HunterLab"/> into a <see cref="Rgb"/> /// Converts a <see cref="HunterLab"/> into a <see cref="Rgb"/>
/// </summary> /// </summary>
@ -125,6 +317,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToRgb(xyzColor); return this.ToRgb(xyzColor);
} }
/// <summary>
/// Performs the bulk conversion from <see cref="HunterLab"/> into <see cref="Rgb"/>
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(Span<HunterLab> source, Span<Rgb> destination, int count)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source);
ref Rgb destRef = ref MemoryMarshal.GetReference(destination);
for (int i = 0; i < count; i++)
{
ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb dp = ref Unsafe.Add(ref destRef, i);
dp = this.ToRgb(sp);
}
}
/// <summary> /// <summary>
/// Converts a <see cref="LinearRgb"/> into a <see cref="Rgb"/> /// Converts a <see cref="LinearRgb"/> into a <see cref="Rgb"/>
/// </summary> /// </summary>
@ -136,6 +349,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return LinearRgbToRgbConverter.Convert(color); return LinearRgbToRgbConverter.Convert(color);
} }
/// <summary>
/// Performs the bulk conversion from <see cref="LinearRgb"/> into <see cref="Rgb"/>
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(Span<LinearRgb> source, Span<Rgb> destination, int count)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source);
ref Rgb destRef = ref MemoryMarshal.GetReference(destination);
for (int i = 0; i < count; i++)
{
ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb dp = ref Unsafe.Add(ref destRef, i);
dp = this.ToRgb(sp);
}
}
/// <summary> /// <summary>
/// Converts a <see cref="Lms"/> into a <see cref="Rgb"/> /// Converts a <see cref="Lms"/> into a <see cref="Rgb"/>
/// </summary> /// </summary>
@ -147,6 +381,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToRgb(xyzColor); return this.ToRgb(xyzColor);
} }
/// <summary>
/// Performs the bulk conversion from <see cref="Lms"/> into <see cref="Rgb"/>
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(Span<Lms> source, Span<Rgb> destination, int count)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
ref Lms sourceRef = ref MemoryMarshal.GetReference(source);
ref Rgb destRef = ref MemoryMarshal.GetReference(destination);
for (int i = 0; i < count; i++)
{
ref Lms sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb dp = ref Unsafe.Add(ref destRef, i);
dp = this.ToRgb(sp);
}
}
/// <summary> /// <summary>
/// Converts a <see cref="YCbCr"/> into a <see cref="Rgb"/> /// Converts a <see cref="YCbCr"/> into a <see cref="Rgb"/>
/// </summary> /// </summary>
@ -160,5 +415,26 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
// Adaptation // Adaptation
return this.Adapt(rgb); return this.Adapt(rgb);
} }
/// <summary>
/// Performs the bulk conversion from <see cref="YCbCr"/> into <see cref="Rgb"/>
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(Span<YCbCr> source, Span<Rgb> destination, int count)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source);
ref Rgb destRef = ref MemoryMarshal.GetReference(destination);
for (int i = 0; i < count; i++)
{
ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb dp = ref Unsafe.Add(ref destRef, i);
dp = this.ToRgb(sp);
}
}
} }
} }

255
src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.YCbCr.cs

@ -1,6 +1,9 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation; using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
namespace SixLabors.ImageSharp.ColorSpaces.Conversion namespace SixLabors.ImageSharp.ColorSpaces.Conversion
@ -24,6 +27,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToYCbCr(xyzColor); return this.ToYCbCr(xyzColor);
} }
/// <summary>
/// Performs the bulk conversion from <see cref="CieLab"/> into <see cref="YCbCr"/>
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(Span<CieLab> source, Span<YCbCr> destination, int count)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
ref CieLab sourceRef = ref MemoryMarshal.GetReference(source);
ref YCbCr destRef = ref MemoryMarshal.GetReference(destination);
for (int i = 0; i < count; i++)
{
ref CieLab sp = ref Unsafe.Add(ref sourceRef, i);
ref YCbCr dp = ref Unsafe.Add(ref destRef, i);
dp = this.ToYCbCr(sp);
}
}
/// <summary> /// <summary>
/// Converts a <see cref="CieLch"/> into a <see cref="YCbCr"/> /// Converts a <see cref="CieLch"/> into a <see cref="YCbCr"/>
/// </summary> /// </summary>
@ -37,15 +61,24 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
} }
/// <summary> /// <summary>
/// Converts a <see cref="CieLchuv"/> into a <see cref="YCbCr"/> /// Performs the bulk conversion from <see cref="CieLch"/> into <see cref="YCbCr"/>
/// </summary> /// </summary>
/// <param name="color">The color to convert.</param> /// <param name="source">The span to the source colors</param>
/// <returns>The <see cref="YCbCr"/></returns> /// <param name="destination">The span to the destination colors</param>
public YCbCr ToYCbCr(in CieLchuv color) /// <param name="count">The number of colors to convert.</param>
public void Convert(Span<CieLch> source, Span<YCbCr> destination, int count)
{ {
var xyzColor = this.ToCieXyz(color); Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
return this.ToYCbCr(xyzColor); ref CieLch sourceRef = ref MemoryMarshal.GetReference(source);
ref YCbCr destRef = ref MemoryMarshal.GetReference(destination);
for (int i = 0; i < count; i++)
{
ref CieLch sp = ref Unsafe.Add(ref sourceRef, i);
ref YCbCr dp = ref Unsafe.Add(ref destRef, i);
dp = this.ToYCbCr(sp);
}
} }
/// <summary> /// <summary>
@ -60,6 +93,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToYCbCr(xyzColor); return this.ToYCbCr(xyzColor);
} }
/// <summary>
/// Performs the bulk conversion from <see cref="CieLuv"/> into <see cref="YCbCr"/>
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(Span<CieLuv> source, Span<YCbCr> destination, int count)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source);
ref YCbCr destRef = ref MemoryMarshal.GetReference(destination);
for (int i = 0; i < count; i++)
{
ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i);
ref YCbCr dp = ref Unsafe.Add(ref destRef, i);
dp = this.ToYCbCr(sp);
}
}
/// <summary> /// <summary>
/// Converts a <see cref="CieXyy"/> into a <see cref="YCbCr"/> /// Converts a <see cref="CieXyy"/> into a <see cref="YCbCr"/>
/// </summary> /// </summary>
@ -72,6 +126,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToYCbCr(xyzColor); return this.ToYCbCr(xyzColor);
} }
/// <summary>
/// Performs the bulk conversion from <see cref="CieXyy"/> into <see cref="YCbCr"/>
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(Span<CieXyy> source, Span<YCbCr> destination, int count)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source);
ref YCbCr destRef = ref MemoryMarshal.GetReference(destination);
for (int i = 0; i < count; i++)
{
ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i);
ref YCbCr dp = ref Unsafe.Add(ref destRef, i);
dp = this.ToYCbCr(sp);
}
}
/// <summary> /// <summary>
/// Converts a <see cref="CieXyz"/> into a <see cref="YCbCr"/> /// Converts a <see cref="CieXyz"/> into a <see cref="YCbCr"/>
/// </summary> /// </summary>
@ -84,6 +159,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return YCbCrAndRgbConverter.Convert(rgb); return YCbCrAndRgbConverter.Convert(rgb);
} }
/// <summary>
/// Performs the bulk conversion from <see cref="CieXyz"/> into <see cref="YCbCr"/>
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(Span<CieXyz> source, Span<YCbCr> destination, int count)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source);
ref YCbCr destRef = ref MemoryMarshal.GetReference(destination);
for (int i = 0; i < count; i++)
{
ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i);
ref YCbCr dp = ref Unsafe.Add(ref destRef, i);
dp = this.ToYCbCr(sp);
}
}
/// <summary> /// <summary>
/// Converts a <see cref="Cmyk"/> into a <see cref="YCbCr"/> /// Converts a <see cref="Cmyk"/> into a <see cref="YCbCr"/>
/// </summary> /// </summary>
@ -96,6 +192,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return YCbCrAndRgbConverter.Convert(rgb); return YCbCrAndRgbConverter.Convert(rgb);
} }
/// <summary>
/// Performs the bulk conversion from <see cref="Cmyk"/> into <see cref="YCbCr"/>
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(Span<Cmyk> source, Span<YCbCr> destination, int count)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source);
ref YCbCr destRef = ref MemoryMarshal.GetReference(destination);
for (int i = 0; i < count; i++)
{
ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i);
ref YCbCr dp = ref Unsafe.Add(ref destRef, i);
dp = this.ToYCbCr(sp);
}
}
/// <summary> /// <summary>
/// Converts a <see cref="Hsl"/> into a <see cref="YCbCr"/> /// Converts a <see cref="Hsl"/> into a <see cref="YCbCr"/>
/// </summary> /// </summary>
@ -108,6 +225,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return YCbCrAndRgbConverter.Convert(rgb); return YCbCrAndRgbConverter.Convert(rgb);
} }
/// <summary>
/// Performs the bulk conversion from <see cref="Hsl"/> into <see cref="YCbCr"/>
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(Span<Hsl> source, Span<YCbCr> destination, int count)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
ref Hsl sourceRef = ref MemoryMarshal.GetReference(source);
ref YCbCr destRef = ref MemoryMarshal.GetReference(destination);
for (int i = 0; i < count; i++)
{
ref Hsl sp = ref Unsafe.Add(ref sourceRef, i);
ref YCbCr dp = ref Unsafe.Add(ref destRef, i);
dp = this.ToYCbCr(sp);
}
}
/// <summary> /// <summary>
/// Converts a <see cref="Hsv"/> into a <see cref="YCbCr"/> /// Converts a <see cref="Hsv"/> into a <see cref="YCbCr"/>
/// </summary> /// </summary>
@ -120,6 +258,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return YCbCrAndRgbConverter.Convert(rgb); return YCbCrAndRgbConverter.Convert(rgb);
} }
/// <summary>
/// Performs the bulk conversion from <see cref="Hsv"/> into <see cref="YCbCr"/>
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(Span<Hsv> source, Span<YCbCr> destination, int count)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
ref Hsv sourceRef = ref MemoryMarshal.GetReference(source);
ref YCbCr destRef = ref MemoryMarshal.GetReference(destination);
for (int i = 0; i < count; i++)
{
ref Hsv sp = ref Unsafe.Add(ref sourceRef, i);
ref YCbCr dp = ref Unsafe.Add(ref destRef, i);
dp = this.ToYCbCr(sp);
}
}
/// <summary> /// <summary>
/// Converts a <see cref="HunterLab"/> into a <see cref="YCbCr"/> /// Converts a <see cref="HunterLab"/> into a <see cref="YCbCr"/>
/// </summary> /// </summary>
@ -132,6 +291,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToYCbCr(xyzColor); return this.ToYCbCr(xyzColor);
} }
/// <summary>
/// Performs the bulk conversion from <see cref="HunterLab"/> into <see cref="YCbCr"/>
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(Span<HunterLab> source, Span<YCbCr> destination, int count)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source);
ref YCbCr destRef = ref MemoryMarshal.GetReference(destination);
for (int i = 0; i < count; i++)
{
ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i);
ref YCbCr dp = ref Unsafe.Add(ref destRef, i);
dp = this.ToYCbCr(sp);
}
}
/// <summary> /// <summary>
/// Converts a <see cref="LinearRgb"/> into a <see cref="YCbCr"/> /// Converts a <see cref="LinearRgb"/> into a <see cref="YCbCr"/>
/// </summary> /// </summary>
@ -144,6 +324,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return YCbCrAndRgbConverter.Convert(rgb); return YCbCrAndRgbConverter.Convert(rgb);
} }
/// <summary>
/// Performs the bulk conversion from <see cref="LinearRgb"/> into <see cref="YCbCr"/>
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(Span<LinearRgb> source, Span<YCbCr> destination, int count)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source);
ref YCbCr destRef = ref MemoryMarshal.GetReference(destination);
for (int i = 0; i < count; i++)
{
ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i);
ref YCbCr dp = ref Unsafe.Add(ref destRef, i);
dp = this.ToYCbCr(sp);
}
}
/// <summary> /// <summary>
/// Converts a <see cref="Lms"/> into a <see cref="YCbCr"/> /// Converts a <see cref="Lms"/> into a <see cref="YCbCr"/>
/// </summary> /// </summary>
@ -156,6 +357,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToYCbCr(xyzColor); return this.ToYCbCr(xyzColor);
} }
/// <summary>
/// Performs the bulk conversion from <see cref="Lms"/> into <see cref="YCbCr"/>
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(Span<Lms> source, Span<YCbCr> destination, int count)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
ref Lms sourceRef = ref MemoryMarshal.GetReference(source);
ref YCbCr destRef = ref MemoryMarshal.GetReference(destination);
for (int i = 0; i < count; i++)
{
ref Lms sp = ref Unsafe.Add(ref sourceRef, i);
ref YCbCr dp = ref Unsafe.Add(ref destRef, i);
dp = this.ToYCbCr(sp);
}
}
/// <summary> /// <summary>
/// Converts a <see cref="Rgb"/> into a <see cref="YCbCr"/> /// Converts a <see cref="Rgb"/> into a <see cref="YCbCr"/>
/// </summary> /// </summary>
@ -165,5 +387,26 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{ {
return YCbCrAndRgbConverter.Convert(color); return YCbCrAndRgbConverter.Convert(color);
} }
/// <summary>
/// Performs the bulk conversion from <see cref="Rgb"/> into <see cref="YCbCr"/>
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(Span<Rgb> source, Span<YCbCr> destination, int count)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
ref Rgb sourceRef = ref MemoryMarshal.GetReference(source);
ref YCbCr destRef = ref MemoryMarshal.GetReference(destination);
for (int i = 0; i < count; i++)
{
ref Rgb sp = ref Unsafe.Add(ref sourceRef, i);
ref YCbCr dp = ref Unsafe.Add(ref destRef, i);
dp = this.ToYCbCr(sp);
}
}
} }
} }

124
tests/ImageSharp.Tests/Colorspaces/ApproximateColorspaceComparer.cs

@ -9,7 +9,16 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
/// <summary> /// <summary>
/// Allows the approximate comparison of colorspace component values. /// Allows the approximate comparison of colorspace component values.
/// </summary> /// </summary>
internal class ApproximateColorSpaceComparer : IEqualityComparer<Rgb> internal class ApproximateColorSpaceComparer :
IEqualityComparer<Rgb>,
IEqualityComparer<CieLab>,
IEqualityComparer<CieLch>,
IEqualityComparer<CieLchuv>,
IEqualityComparer<CieLuv>,
IEqualityComparer<CieXyz>,
IEqualityComparer<CieXyy>,
IEqualityComparer<HunterLab>,
IEqualityComparer<Lms>
{ {
private readonly float Epsilon; private readonly float Epsilon;
@ -36,10 +45,121 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
return obj.GetHashCode(); return obj.GetHashCode();
} }
/// <inheritdoc/>
public bool Equals(CieLab x, CieLab y)
{
return this.Equals(x.L, y.L)
&& this.Equals(x.A, y.A)
&& this.Equals(x.B, y.B);
}
/// <inheritdoc/>
public int GetHashCode(CieLab obj)
{
return obj.GetHashCode();
}
/// <inheritdoc/>
public bool Equals(CieLch x, CieLch y)
{
return this.Equals(x.L, y.L)
&& this.Equals(x.C, y.C)
&& this.Equals(x.H, y.H);
}
/// <inheritdoc/>
public int GetHashCode(CieLch obj)
{
return obj.GetHashCode();
}
/// <inheritdoc/>
public bool Equals(CieLchuv x, CieLchuv y)
{
return this.Equals(x.L, y.L)
&& this.Equals(x.C, y.C)
&& this.Equals(x.H, y.H);
}
/// <inheritdoc/>
public int GetHashCode(CieLchuv obj)
{
return obj.GetHashCode();
}
/// <inheritdoc/>
public bool Equals(CieLuv x, CieLuv y)
{
return this.Equals(x.L, y.L)
&& this.Equals(x.U, y.U)
&& this.Equals(x.V, y.V);
}
/// <inheritdoc/>
public int GetHashCode(CieLuv obj)
{
return obj.GetHashCode();
}
/// <inheritdoc/>
public bool Equals(CieXyz x, CieXyz y)
{
return this.Equals(x.X, y.X)
&& this.Equals(x.Y, y.Y)
&& this.Equals(x.Z, y.Z);
}
/// <inheritdoc/>
public int GetHashCode(CieXyz obj)
{
return obj.GetHashCode();
}
/// <inheritdoc/>
public bool Equals(CieXyy x, CieXyy y)
{
return this.Equals(x.X, y.X)
&& this.Equals(x.Y, y.Y)
&& this.Equals(x.Yl, y.Yl);
}
/// <inheritdoc/>
public int GetHashCode(CieXyy obj)
{
return obj.GetHashCode();
}
/// <inheritdoc/>
public bool Equals(HunterLab x, HunterLab y)
{
return this.Equals(x.L, y.L)
&& this.Equals(x.A, y.A)
&& this.Equals(x.B, y.B);
}
/// <inheritdoc/>
public int GetHashCode(HunterLab obj)
{
return obj.GetHashCode();
}
/// <inheritdoc/>
public bool Equals(Lms x, Lms y)
{
return this.Equals(x.L, y.L)
&& this.Equals(x.M, y.M)
&& this.Equals(x.S, y.S);
}
/// <inheritdoc/>
public int GetHashCode(Lms obj)
{
return obj.GetHashCode();
}
private bool Equals(float x, float y) private bool Equals(float x, float y)
{ {
float d = x - y; float d = x - y;
return d >= -this.Epsilon && d <= this.Epsilon; return d >= -this.Epsilon && d <= this.Epsilon;
} }
} }

18
tests/ImageSharp.Tests/Colorspaces/CieLabAndCieLchConversionTests.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System.Collections.Generic;
using SixLabors.ImageSharp.ColorSpaces; using SixLabors.ImageSharp.ColorSpaces;
using SixLabors.ImageSharp.ColorSpaces.Conversion; using SixLabors.ImageSharp.ColorSpaces.Conversion;
using Xunit; using Xunit;
@ -17,8 +16,7 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
/// </remarks> /// </remarks>
public class CieLabAndCieLchConversionTests public class CieLabAndCieLchConversionTests
{ {
private static readonly IEqualityComparer<float> FloatRoundingComparer = new FloatRoundingComparer(4); private static readonly ApproximateColorSpaceComparer ColorSpaceComparer = new ApproximateColorSpaceComparer(.0001F);
private static readonly ColorSpaceConverter Converter = new ColorSpaceConverter(); private static readonly ColorSpaceConverter Converter = new ColorSpaceConverter();
/// <summary> /// <summary>
@ -37,14 +35,13 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
{ {
// Arrange // Arrange
var input = new CieLch(l, c, h); var input = new CieLch(l, c, h);
var expected = new CieLab(l2, a, b);
// Act // Act
var output = Converter.ToCieLab(input); var actual = Converter.ToCieLab(input);
// Assert // Assert
Assert.Equal(l2, output.L, FloatRoundingComparer); Assert.Equal(expected, actual, ColorSpaceComparer);
Assert.Equal(a, output.A, FloatRoundingComparer);
Assert.Equal(b, output.B, FloatRoundingComparer);
} }
/// <summary> /// <summary>
@ -63,14 +60,13 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
{ {
// Arrange // Arrange
var input = new CieLab(l, a, b); var input = new CieLab(l, a, b);
var expected = new CieLch(l2, c, h);
// Act // Act
var output = Converter.ToCieLch(input); var actual = Converter.ToCieLch(input);
// Assert // Assert
Assert.Equal(l2, output.L, FloatRoundingComparer); Assert.Equal(expected, actual, ColorSpaceComparer);
Assert.Equal(c, output.C, FloatRoundingComparer);
Assert.Equal(h, output.H, FloatRoundingComparer);
} }
} }
} }

18
tests/ImageSharp.Tests/Colorspaces/CieLuvAndCieLchuvConversionTests.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System.Collections.Generic;
using SixLabors.ImageSharp.ColorSpaces; using SixLabors.ImageSharp.ColorSpaces;
using SixLabors.ImageSharp.ColorSpaces.Conversion; using SixLabors.ImageSharp.ColorSpaces.Conversion;
using Xunit; using Xunit;
@ -17,8 +16,7 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
/// </remarks> /// </remarks>
public class CieLuvAndCieLchuvuvConversionTests public class CieLuvAndCieLchuvuvConversionTests
{ {
private static readonly IEqualityComparer<float> FloatRoundingComparer = new FloatRoundingComparer(4); private static readonly ApproximateColorSpaceComparer ColorSpaceComparer = new ApproximateColorSpaceComparer(.0001F);
private static readonly ColorSpaceConverter Converter = new ColorSpaceConverter(); private static readonly ColorSpaceConverter Converter = new ColorSpaceConverter();
/// <summary> /// <summary>
@ -37,14 +35,13 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
{ {
// Arrange // Arrange
var input = new CieLchuv(l, c, h); var input = new CieLchuv(l, c, h);
var expected = new CieLuv(l2, u, v);
// Act // Act
CieLuv output = Converter.ToCieLuv(input); var actual = Converter.ToCieLuv(input);
// Assert // Assert
Assert.Equal(l2, output.L, FloatRoundingComparer); Assert.Equal(expected, actual, ColorSpaceComparer);
Assert.Equal(u, output.U, FloatRoundingComparer);
Assert.Equal(v, output.V, FloatRoundingComparer);
} }
/// <summary> /// <summary>
@ -64,14 +61,13 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
{ {
// Arrange // Arrange
var input = new CieLuv(l, u, v); var input = new CieLuv(l, u, v);
var expected = new CieLchuv(l2, c, h);
// Act // Act
CieLchuv output = Converter.ToCieLchuv(input); var actual = Converter.ToCieLchuv(input);
// Assert // Assert
Assert.Equal(l2, output.L, FloatRoundingComparer); Assert.Equal(expected, actual, ColorSpaceComparer);
Assert.Equal(c, output.C, FloatRoundingComparer);
Assert.Equal(h, output.H, FloatRoundingComparer);
} }
} }
} }

17
tests/ImageSharp.Tests/Colorspaces/CieXyzAndCieLabConversionTest.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System.Collections.Generic;
using SixLabors.ImageSharp.ColorSpaces; using SixLabors.ImageSharp.ColorSpaces;
using SixLabors.ImageSharp.ColorSpaces.Conversion; using SixLabors.ImageSharp.ColorSpaces.Conversion;
using Xunit; using Xunit;
@ -17,7 +16,7 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
/// </remarks> /// </remarks>
public class CieXyzAndCieLabConversionTest public class CieXyzAndCieLabConversionTest
{ {
private static readonly IEqualityComparer<float> FloatRoundingComparer = new FloatRoundingComparer(4); private static readonly ApproximateColorSpaceComparer ColorSpaceComparer = new ApproximateColorSpaceComparer(.0001F);
/// <summary> /// <summary>
/// Tests conversion from <see cref="CieLab"/> to <see cref="CieXyz"/> (<see cref="Illuminants.D65"/>). /// Tests conversion from <see cref="CieLab"/> to <see cref="CieXyz"/> (<see cref="Illuminants.D65"/>).
@ -36,14 +35,13 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
// Arrange // Arrange
var input = new CieLab(l, a, b, Illuminants.D65); var input = new CieLab(l, a, b, Illuminants.D65);
var converter = new ColorSpaceConverter { WhitePoint = Illuminants.D65, TargetLabWhitePoint = Illuminants.D65 }; var converter = new ColorSpaceConverter { WhitePoint = Illuminants.D65, TargetLabWhitePoint = Illuminants.D65 };
var expected = new CieXyz(x, y, z);
// Act // Act
var output = converter.ToCieXyz(input); var actual = converter.ToCieXyz(input);
// Assert // Assert
Assert.Equal(x, output.X, FloatRoundingComparer); Assert.Equal(expected, actual, ColorSpaceComparer);
Assert.Equal(y, output.Y, FloatRoundingComparer);
Assert.Equal(z, output.Z, FloatRoundingComparer);
} }
/// <summary> /// <summary>
@ -61,14 +59,13 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
// Arrange // Arrange
var input = new CieXyz(x, y, z); var input = new CieXyz(x, y, z);
var converter = new ColorSpaceConverter { WhitePoint = Illuminants.D65, TargetLabWhitePoint = Illuminants.D65 }; var converter = new ColorSpaceConverter { WhitePoint = Illuminants.D65, TargetLabWhitePoint = Illuminants.D65 };
var expected = new CieLab(l, a, b);
// Act // Act
var output = converter.ToCieLab(input); var actual = converter.ToCieLab(input);
// Assert // Assert
Assert.Equal(l, output.L, FloatRoundingComparer); Assert.Equal(expected, actual, ColorSpaceComparer);
Assert.Equal(a, output.A, FloatRoundingComparer);
Assert.Equal(b, output.B, FloatRoundingComparer);
} }
} }
} }

17
tests/ImageSharp.Tests/Colorspaces/CieXyzAndCieLuvConversionTest.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System.Collections.Generic;
using SixLabors.ImageSharp.ColorSpaces; using SixLabors.ImageSharp.ColorSpaces;
using SixLabors.ImageSharp.ColorSpaces.Conversion; using SixLabors.ImageSharp.ColorSpaces.Conversion;
using Xunit; using Xunit;
@ -17,7 +16,7 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
/// </remarks> /// </remarks>
public class CieXyzAndCieLuvConversionTest public class CieXyzAndCieLuvConversionTest
{ {
private static readonly IEqualityComparer<float> FloatRoundingComparer = new FloatRoundingComparer(4); private static readonly ApproximateColorSpaceComparer ColorSpaceComparer = new ApproximateColorSpaceComparer(.0001F);
/// <summary> /// <summary>
/// Tests conversion from <see cref="CieLuv"/> to <see cref="CieXyz"/> (<see cref="Illuminants.D65"/>). /// Tests conversion from <see cref="CieLuv"/> to <see cref="CieXyz"/> (<see cref="Illuminants.D65"/>).
@ -35,14 +34,13 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
// Arrange // Arrange
var input = new CieLuv(l, u, v, Illuminants.D65); var input = new CieLuv(l, u, v, Illuminants.D65);
var converter = new ColorSpaceConverter { WhitePoint = Illuminants.D65, TargetLabWhitePoint = Illuminants.D65 }; var converter = new ColorSpaceConverter { WhitePoint = Illuminants.D65, TargetLabWhitePoint = Illuminants.D65 };
var expected = new CieXyz(x, y, z);
// Act // Act
CieXyz output = converter.ToCieXyz(input); var actual = converter.ToCieXyz(input);
// Assert // Assert
Assert.Equal(x, output.X, FloatRoundingComparer); Assert.Equal(expected, actual, ColorSpaceComparer);
Assert.Equal(y, output.Y, FloatRoundingComparer);
Assert.Equal(z, output.Z, FloatRoundingComparer);
} }
/// <summary> /// <summary>
@ -60,14 +58,13 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
// Arrange // Arrange
var input = new CieXyz(x, y, z); var input = new CieXyz(x, y, z);
var converter = new ColorSpaceConverter { WhitePoint = Illuminants.D65, TargetLabWhitePoint = Illuminants.D65 }; var converter = new ColorSpaceConverter { WhitePoint = Illuminants.D65, TargetLabWhitePoint = Illuminants.D65 };
var expected = new CieLuv(l, u, v);
// Act // Act
CieLuv output = converter.ToCieLuv(input); var actual = converter.ToCieLuv(input);
// Assert // Assert
Assert.Equal(l, output.L, FloatRoundingComparer); Assert.Equal(expected, actual, ColorSpaceComparer);
Assert.Equal(u, output.U, FloatRoundingComparer);
Assert.Equal(v, output.V, FloatRoundingComparer);
} }
} }
} }

17
tests/ImageSharp.Tests/Colorspaces/CieXyzAndCieXyyConversionTest.cs

@ -17,8 +17,7 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
/// </remarks> /// </remarks>
public class CieXyzAndCieXyyConversionTest public class CieXyzAndCieXyyConversionTest
{ {
private static readonly IEqualityComparer<float> FloatRoundingComparer = new FloatRoundingComparer(4); private static readonly ApproximateColorSpaceComparer ColorSpaceComparer = new ApproximateColorSpaceComparer(.0001F);
private static readonly ColorSpaceConverter Converter = new ColorSpaceConverter(); private static readonly ColorSpaceConverter Converter = new ColorSpaceConverter();
[Theory] [Theory]
@ -29,14 +28,13 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
public void Convert_xyY_to_XYZ(float xyzX, float xyzY, float xyzZ, float x, float y, float yl) public void Convert_xyY_to_XYZ(float xyzX, float xyzY, float xyzZ, float x, float y, float yl)
{ {
var input = new CieXyy(x, y, yl); var input = new CieXyy(x, y, yl);
var expected = new CieXyz(xyzX, xyzY, xyzZ);
// Act // Act
CieXyz output = Converter.ToCieXyz(input); var actual = Converter.ToCieXyz(input);
// Assert // Assert
Assert.Equal(xyzX, output.X, FloatRoundingComparer); Assert.Equal(expected, actual, ColorSpaceComparer);
Assert.Equal(xyzY, output.Y, FloatRoundingComparer);
Assert.Equal(xyzZ, output.Z, FloatRoundingComparer);
} }
[Theory] [Theory]
@ -47,14 +45,13 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
public void Convert_XYZ_to_xyY(float xyzX, float xyzY, float xyzZ, float x, float y, float yl) public void Convert_XYZ_to_xyY(float xyzX, float xyzY, float xyzZ, float x, float y, float yl)
{ {
var input = new CieXyz(xyzX, xyzY, xyzZ); var input = new CieXyz(xyzX, xyzY, xyzZ);
var expected = new CieXyy(x, y, yl);
// Act // Act
CieXyy output = Converter.ToCieXyy(input); var actual = Converter.ToCieXyy(input);
// Assert // Assert
Assert.Equal(x, output.X, FloatRoundingComparer); Assert.Equal(expected, actual, ColorSpaceComparer);
Assert.Equal(y, output.Y, FloatRoundingComparer);
Assert.Equal(yl, output.Yl, FloatRoundingComparer);
} }
} }
} }

26
tests/ImageSharp.Tests/Colorspaces/CieXyzAndHunterLabConversionTest.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System.Collections.Generic;
using SixLabors.ImageSharp.ColorSpaces; using SixLabors.ImageSharp.ColorSpaces;
using SixLabors.ImageSharp.ColorSpaces.Conversion; using SixLabors.ImageSharp.ColorSpaces.Conversion;
using Xunit; using Xunit;
@ -9,7 +8,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Colorspaces namespace SixLabors.ImageSharp.Tests.Colorspaces
{ {
/// <summary> /// <summary>
/// Tests <see cref="CieXyz"/>-<see cref="CieLab"/> conversions. /// Tests <see cref="CieXyz"/>-<see cref="HunterLab"/> conversions.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// Test data generated using: /// Test data generated using:
@ -17,7 +16,7 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
/// </remarks> /// </remarks>
public class CieXyzAndHunterLabConversionTest public class CieXyzAndHunterLabConversionTest
{ {
private static readonly IEqualityComparer<float> FloatRoundingComparer = new FloatRoundingComparer(4); private static readonly ApproximateColorSpaceComparer ColorSpaceComparer = new ApproximateColorSpaceComparer(.0001F);
/// <summary> /// <summary>
/// Tests conversion from <see cref="HunterLab"/> to <see cref="CieXyz"/> (<see cref="Illuminants.C"/>). /// Tests conversion from <see cref="HunterLab"/> to <see cref="CieXyz"/> (<see cref="Illuminants.C"/>).
@ -30,14 +29,13 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
// Arrange // Arrange
var input = new HunterLab(l, a, b); var input = new HunterLab(l, a, b);
var converter = new ColorSpaceConverter { WhitePoint = Illuminants.C }; var converter = new ColorSpaceConverter { WhitePoint = Illuminants.C };
var expected = new CieXyz(x, y, z);
// Act // Act
CieXyz output = converter.ToCieXyz(input); var actual = converter.ToCieXyz(input);
// Assert // Assert
Assert.Equal(x, output.X, FloatRoundingComparer); Assert.Equal(expected, actual, ColorSpaceComparer);
Assert.Equal(y, output.Y, FloatRoundingComparer);
Assert.Equal(z, output.Z, FloatRoundingComparer);
} }
/// <summary> /// <summary>
@ -51,14 +49,13 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
// Arrange // Arrange
var input = new HunterLab(l, a, b); var input = new HunterLab(l, a, b);
var converter = new ColorSpaceConverter { WhitePoint = Illuminants.D65 }; var converter = new ColorSpaceConverter { WhitePoint = Illuminants.D65 };
var expected = new CieXyz(x, y, z);
// Act // Act
CieXyz output = converter.ToCieXyz(input); var actual = converter.ToCieXyz(input);
// Assert // Assert
Assert.Equal(x, output.X, FloatRoundingComparer); Assert.Equal(expected, actual, ColorSpaceComparer);
Assert.Equal(y, output.Y, FloatRoundingComparer);
Assert.Equal(z, output.Z, FloatRoundingComparer);
} }
/// <summary> /// <summary>
@ -72,14 +69,13 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
// Arrange // Arrange
var input = new CieXyz(x, y, z); var input = new CieXyz(x, y, z);
var converter = new ColorSpaceConverter { WhitePoint = Illuminants.D65 }; var converter = new ColorSpaceConverter { WhitePoint = Illuminants.D65 };
var expected = new HunterLab(l, a, b);
// Act // Act
HunterLab output = converter.ToHunterLab(input); var actual = converter.ToHunterLab(input);
// Assert // Assert
Assert.Equal(l, output.L, FloatRoundingComparer); Assert.Equal(expected, actual, ColorSpaceComparer);
Assert.Equal(a, output.A, FloatRoundingComparer);
Assert.Equal(b, output.B, FloatRoundingComparer);
} }
} }
} }

18
tests/ImageSharp.Tests/Colorspaces/CieXyzAndLmsConversionTest.cs

@ -9,14 +9,14 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Colorspaces namespace SixLabors.ImageSharp.Tests.Colorspaces
{ {
/// <summary> /// <summary>
/// Tests <see cref="CieXyz"/>-<see cref="CieLab"/> conversions. /// Tests <see cref="CieXyz"/>-<see cref="Lms"/> conversions.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// Test data generated using original colorful library. /// Test data generated using original colorful library.
/// </remarks> /// </remarks>
public class CieXyzAndLmsConversionTest public class CieXyzAndLmsConversionTest
{ {
private static readonly IEqualityComparer<float> FloatRoundingComparer = new FloatRoundingComparer(5); private static readonly ApproximateColorSpaceComparer ColorSpaceComparer = new ApproximateColorSpaceComparer(.0001F);
/// <summary> /// <summary>
/// Tests conversion from <see cref="CieXyz"/> (<see cref="Illuminants.D65"/>) to <see cref="Lms"/>. /// Tests conversion from <see cref="CieXyz"/> (<see cref="Illuminants.D65"/>) to <see cref="Lms"/>.
@ -33,14 +33,13 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
// Arrange // Arrange
var input = new Lms(l, m, s); var input = new Lms(l, m, s);
var converter = new ColorSpaceConverter(); var converter = new ColorSpaceConverter();
var expected = new CieXyz(x, y, z);
// Act // Act
CieXyz output = converter.ToCieXyz(input); var actual = converter.ToCieXyz(input);
// Assert // Assert
Assert.Equal(x, output.X, FloatRoundingComparer); Assert.Equal(expected, actual, ColorSpaceComparer);
Assert.Equal(y, output.Y, FloatRoundingComparer);
Assert.Equal(z, output.Z, FloatRoundingComparer);
} }
/// <summary> /// <summary>
@ -58,14 +57,13 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
// Arrange // Arrange
var input = new CieXyz(x, y, z); var input = new CieXyz(x, y, z);
var converter = new ColorSpaceConverter(); var converter = new ColorSpaceConverter();
var expected = new Lms(l, m, s);
// Act // Act
Lms output = converter.ToLms(input); var actual = converter.ToLms(input);
// Assert // Assert
Assert.Equal(l, output.L, FloatRoundingComparer); Assert.Equal(expected, actual, ColorSpaceComparer);
Assert.Equal(m, output.M, FloatRoundingComparer);
Assert.Equal(s, output.S, FloatRoundingComparer);
} }
} }
} }

65
tests/ImageSharp.Tests/Colorspaces/ColorConverterAdaptTest.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System.Collections.Generic;
using SixLabors.ImageSharp.ColorSpaces; using SixLabors.ImageSharp.ColorSpaces;
using SixLabors.ImageSharp.ColorSpaces.Conversion; using SixLabors.ImageSharp.ColorSpaces.Conversion;
using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation; using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
@ -17,9 +16,8 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
/// </summary> /// </summary>
public class ColorConverterAdaptTest public class ColorConverterAdaptTest
{ {
private static readonly IEqualityComparer<float> FloatRoundingComparer = new FloatRoundingComparer(3); private static readonly ApproximateFloatComparer ApproximateComparer = new ApproximateFloatComparer(.0001F);
private static readonly ApproximateColorSpaceComparer ColorSpaceComparer = new ApproximateColorSpaceComparer(.0001F);
private static readonly ApproximateFloatComparer ApproximateComparer = new ApproximateFloatComparer(0.0001F);
[Theory] [Theory]
[InlineData(0, 0, 0, 0, 0, 0)] [InlineData(0, 0, 0, 0, 0, 0)]
@ -29,17 +27,15 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
{ {
// Arrange // Arrange
var input = new Rgb(r1, g1, b1, RgbWorkingSpaces.WideGamutRgb); var input = new Rgb(r1, g1, b1, RgbWorkingSpaces.WideGamutRgb);
var expectedOutput = new Rgb(r2, g2, b2, RgbWorkingSpaces.SRgb); var expected = new Rgb(r2, g2, b2, RgbWorkingSpaces.SRgb);
var converter = new ColorSpaceConverter { TargetRgbWorkingSpace = RgbWorkingSpaces.SRgb }; var converter = new ColorSpaceConverter { TargetRgbWorkingSpace = RgbWorkingSpaces.SRgb };
// Action // Action
Rgb output = converter.Adapt(input); Rgb actual = converter.Adapt(input);
// Assert // Assert
Assert.Equal(expectedOutput.WorkingSpace, output.WorkingSpace, ApproximateComparer); Assert.Equal(expected.WorkingSpace, actual.WorkingSpace, ApproximateComparer);
Assert.Equal(expectedOutput.R, output.R, FloatRoundingComparer); Assert.Equal(expected, actual, ColorSpaceComparer);
Assert.Equal(expectedOutput.G, output.G, FloatRoundingComparer);
Assert.Equal(expectedOutput.B, output.B, FloatRoundingComparer);
} }
[Theory] [Theory]
@ -50,17 +46,15 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
{ {
// Arrange // Arrange
var input = new Rgb(r1, g1, b1, RgbWorkingSpaces.SRgb); var input = new Rgb(r1, g1, b1, RgbWorkingSpaces.SRgb);
var expectedOutput = new Rgb(r2, g2, b2, RgbWorkingSpaces.WideGamutRgb); var expected = new Rgb(r2, g2, b2, RgbWorkingSpaces.WideGamutRgb);
var converter = new ColorSpaceConverter { TargetRgbWorkingSpace = RgbWorkingSpaces.WideGamutRgb }; var converter = new ColorSpaceConverter { TargetRgbWorkingSpace = RgbWorkingSpaces.WideGamutRgb };
// Action // Action
Rgb output = converter.Adapt(input); Rgb actual = converter.Adapt(input);
// Assert // Assert
Assert.Equal(expectedOutput.WorkingSpace, output.WorkingSpace, ApproximateComparer); Assert.Equal(expected.WorkingSpace, actual.WorkingSpace, ApproximateComparer);
Assert.Equal(expectedOutput.R, output.R, FloatRoundingComparer); Assert.Equal(expected, actual, ColorSpaceComparer);
Assert.Equal(expectedOutput.G, output.G, FloatRoundingComparer);
Assert.Equal(expectedOutput.B, output.B, FloatRoundingComparer);
} }
[Theory] [Theory]
@ -70,16 +64,14 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
{ {
// Arrange // Arrange
var input = new CieLab(l1, a1, b1, Illuminants.D65); var input = new CieLab(l1, a1, b1, Illuminants.D65);
var expectedOutput = new CieLab(l2, a2, b2); var expected = new CieLab(l2, a2, b2);
var converter = new ColorSpaceConverter { TargetLabWhitePoint = Illuminants.D50 }; var converter = new ColorSpaceConverter { TargetLabWhitePoint = Illuminants.D50 };
// Action // Action
CieLab output = converter.Adapt(input); CieLab actual = converter.Adapt(input);
// Assert // Assert
Assert.Equal(expectedOutput.L, output.L, FloatRoundingComparer); Assert.Equal(expected, actual, ColorSpaceComparer);
Assert.Equal(expectedOutput.A, output.A, FloatRoundingComparer);
Assert.Equal(expectedOutput.B, output.B, FloatRoundingComparer);
} }
[Theory] [Theory]
@ -88,20 +80,15 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
public void Adapt_Xyz_D65_To_D50_Bradford(float x1, float y1, float z1, float x2, float y2, float z2) public void Adapt_Xyz_D65_To_D50_Bradford(float x1, float y1, float z1, float x2, float y2, float z2)
{ {
// Arrange // Arrange
CieXyz input = new CieXyz(x1, y1, z1); var input = new CieXyz(x1, y1, z1);
CieXyz expectedOutput = new CieXyz(x2, y2, z2); var expected = new CieXyz(x2, y2, z2);
ColorSpaceConverter converter = new ColorSpaceConverter var converter = new ColorSpaceConverter { WhitePoint = Illuminants.D50 };
{
WhitePoint = Illuminants.D50
};
// Action // Action
CieXyz output = converter.Adapt(input, Illuminants.D65); CieXyz actual = converter.Adapt(input, Illuminants.D65);
// Assert // Assert
Assert.Equal(expectedOutput.X, output.X, FloatRoundingComparer); Assert.Equal(expected, actual, ColorSpaceComparer);
Assert.Equal(expectedOutput.Y, output.Y, FloatRoundingComparer);
Assert.Equal(expectedOutput.Z, output.Z, FloatRoundingComparer);
} }
[Theory] [Theory]
@ -111,7 +98,7 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
{ {
// Arrange // Arrange
var input = new CieXyz(x1, y1, z1); var input = new CieXyz(x1, y1, z1);
var expectedOutput = new CieXyz(x2, y2, z2); var expected = new CieXyz(x2, y2, z2);
var converter = new ColorSpaceConverter var converter = new ColorSpaceConverter
{ {
ChromaticAdaptation = new VonKriesChromaticAdaptation(LmsAdaptationMatrix.XyzScaling), ChromaticAdaptation = new VonKriesChromaticAdaptation(LmsAdaptationMatrix.XyzScaling),
@ -119,12 +106,10 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
}; };
// Action // Action
CieXyz output = converter.Adapt(input, Illuminants.D65); CieXyz actual = converter.Adapt(input, Illuminants.D65);
// Assert // Assert
Assert.Equal(expectedOutput.X, output.X, FloatRoundingComparer); Assert.Equal(expected, actual, ColorSpaceComparer);
Assert.Equal(expectedOutput.Y, output.Y, FloatRoundingComparer);
Assert.Equal(expectedOutput.Z, output.Z, FloatRoundingComparer);
} }
[Theory] [Theory]
@ -134,7 +119,7 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
{ {
// Arrange // Arrange
var input = new CieXyz(x1, y1, z1); var input = new CieXyz(x1, y1, z1);
var expectedOutput = new CieXyz(x2, y2, z2); var expected = new CieXyz(x2, y2, z2);
var converter = new ColorSpaceConverter var converter = new ColorSpaceConverter
{ {
ChromaticAdaptation = new VonKriesChromaticAdaptation(LmsAdaptationMatrix.XyzScaling), ChromaticAdaptation = new VonKriesChromaticAdaptation(LmsAdaptationMatrix.XyzScaling),
@ -142,12 +127,10 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
}; };
// Action // Action
CieXyz output = converter.Adapt(input, Illuminants.D65); CieXyz actual = converter.Adapt(input, Illuminants.D65);
// Assert // Assert
Assert.Equal(expectedOutput.X, output.X, FloatRoundingComparer); Assert.Equal(expected, actual, ColorSpaceComparer);
Assert.Equal(expectedOutput.Y, output.Y, FloatRoundingComparer);
Assert.Equal(expectedOutput.Z, output.Z, FloatRoundingComparer);
} }
} }
} }

445
tests/ImageSharp.Tests/Colorspaces/ColorSpaceEqualityTests.cs

@ -17,297 +17,158 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
/// </summary> /// </summary>
public class ColorSpaceEqualityTests public class ColorSpaceEqualityTests
{ {
//internal static readonly Dictionary<string, IColorVector> EmptyDataLookup = [Fact]
// new Dictionary<string, IColorVector> public void CieLabEquality()
// { {
// {nameof( CieLab), default(CieLab) }, var x = default(CieLab);
// {nameof( CieLch), default(CieLch) }, var y = new CieLab(Vector3.One);
// {nameof( CieLchuv), default(CieLchuv) }, Assert.Equal(default(CieLab), default(CieLab));
// {nameof( CieLuv), default(CieLuv) }, Assert.Equal(new CieLab(1, 0, 1), new CieLab(1, 0, 1));
// {nameof( CieXyz), default(CieXyz) }, Assert.Equal(new CieLab(Vector3.One), new CieLab(Vector3.One));
// {nameof( CieXyy), default(CieXyy) }, Assert.False(x.Equals(y));
// {nameof( Hsl), default(Hsl) }, }
// {nameof( HunterLab), default(HunterLab) },
// {nameof( Lms), default(Lms) }, [Fact]
// {nameof( LinearRgb), default(LinearRgb) }, public void CieLchEquality()
// {nameof( Rgb), default(Rgb) }, {
// {nameof( YCbCr), default(YCbCr) } var x = default(CieLch);
// }; var y = new CieLch(Vector3.One);
Assert.Equal(default(CieLch), default(CieLch));
//public static readonly IEnumerable<object[]> EmptyData = EmptyDataLookup.Select(x => new[] { x.Key }); Assert.Equal(new CieLch(1, 0, 1), new CieLch(1, 0, 1));
Assert.Equal(new CieLch(Vector3.One), new CieLch(Vector3.One));
//public static readonly TheoryData<object, object, Type> EqualityData = Assert.False(x.Equals(y));
// new TheoryData<object, object, Type> }
// {
// { new CieLab(Vector3.One), new CieLab(Vector3.One), typeof(CieLab) }, [Fact]
// { new CieLch(Vector3.One), new CieLch(Vector3.One), typeof(CieLch) }, public void CieLchuvEquality()
// { new CieLchuv(Vector3.One), new CieLchuv(Vector3.One), typeof(CieLchuv) }, {
// { new CieLuv(Vector3.One), new CieLuv(Vector3.One), typeof(CieLuv) }, var x = default(CieLchuv);
// { new CieXyz(Vector3.One), new CieXyz(Vector3.One), typeof(CieXyz) }, var y = new CieLchuv(Vector3.One);
// { new CieXyy(Vector3.One), new CieXyy(Vector3.One), typeof(CieXyy) }, Assert.Equal(default(CieLchuv), default(CieLchuv));
// { new HunterLab(Vector3.One), new HunterLab(Vector3.One), typeof(HunterLab) }, Assert.Equal(new CieLchuv(1, 0, 1), new CieLchuv(1, 0, 1));
// { new Lms(Vector3.One), new Lms(Vector3.One), typeof(Lms) }, Assert.Equal(new CieLchuv(Vector3.One), new CieLchuv(Vector3.One));
// { new LinearRgb(Vector3.One), new LinearRgb(Vector3.One), typeof(LinearRgb) }, Assert.False(x.Equals(y));
// { new Rgb(Vector3.One), new Rgb(Vector3.One), typeof(Rgb) }, }
// { new Hsl(Vector3.One), new Hsl(Vector3.One), typeof(Hsl) },
// { new Hsv(Vector3.One), new Hsv(Vector3.One), typeof(Hsv) }, [Fact]
// { new YCbCr(Vector3.One), new YCbCr(Vector3.One), typeof(YCbCr) }, public void CieLuvEquality()
// }; {
var x = default(CieLuv);
//public static readonly TheoryData<object, object, Type> NotEqualityDataNulls = var y = new CieLuv(Vector3.One);
// new TheoryData<object, object, Type> Assert.Equal(default(CieLuv), default(CieLuv));
// { Assert.Equal(new CieLuv(1, 0, 1), new CieLuv(1, 0, 1));
// // Valid object against null Assert.Equal(new CieLuv(Vector3.One), new CieLuv(Vector3.One));
// { new CieLab(Vector3.One), null, typeof(CieLab) }, Assert.False(x.Equals(y));
// { new CieLch(Vector3.One), null, typeof(CieLch) }, }
// { new CieLchuv(Vector3.One), null, typeof(CieLchuv) },
// { new CieLuv(Vector3.One), null, typeof(CieLuv) }, [Fact]
// { new CieXyz(Vector3.One), null, typeof(CieXyz) }, public void CieXyzEquality()
// { new CieXyy(Vector3.One), null, typeof(CieXyy) }, {
// { new HunterLab(Vector3.One), null, typeof(HunterLab) }, var x = default(CieXyz);
// { new Lms(Vector3.One), null, typeof(Lms) }, var y = new CieXyz(Vector3.One);
// { new LinearRgb(Vector3.One), null, typeof(LinearRgb) }, Assert.Equal(default(CieXyz), default(CieXyz));
// { new Rgb(Vector3.One), null, typeof(Rgb) }, Assert.Equal(new CieXyz(1, 0, 1), new CieXyz(1, 0, 1));
// { new Hsl(Vector3.One), null, typeof(Hsl) }, Assert.Equal(new CieXyz(Vector3.One), new CieXyz(Vector3.One));
// { new Hsv(Vector3.One), null, typeof(Hsv) }, Assert.False(x.Equals(y));
// { new YCbCr(Vector3.One), null, typeof(YCbCr) }, }
// };
[Fact]
//public static readonly TheoryData<object, object, Type> NotEqualityDataDifferentObjects = public void CieXyyEquality()
// new TheoryData<object, object, Type> {
// { var x = default(CieXyy);
// // Valid objects of different types but not equal var y = new CieXyy(Vector3.One);
// { new CieLab(Vector3.One), new CieLch(Vector3.Zero), null }, Assert.Equal(default(CieXyy), default(CieXyy));
// { new CieLuv(Vector3.One), new CieLchuv(Vector3.Zero), null }, Assert.Equal(new CieXyy(1, 0, 1), new CieXyy(1, 0, 1));
// { new CieXyz(Vector3.One), new HunterLab(Vector3.Zero), null }, Assert.Equal(new CieXyy(Vector3.One), new CieXyy(Vector3.One));
// { new Rgb(Vector3.One), new LinearRgb(Vector3.Zero), null }, Assert.False(x.Equals(y));
// { new Rgb(Vector3.One), new Lms(Vector3.Zero), null }, }
// { new Cmyk(Vector4.One), new Hsl(Vector3.Zero), null },
// { new YCbCr(Vector3.One), new CieXyy(Vector3.Zero), null }, [Fact]
// { new Hsv(Vector3.One), new Hsl(Vector3.Zero), null }, public void HslEquality()
// }; {
var x = default(Hsl);
//public static readonly TheoryData<object, object, Type> NotEqualityData = var y = new Hsl(Vector3.One);
// new TheoryData<object, object, Type> Assert.Equal(default(Hsl), default(Hsl));
// { Assert.Equal(new Hsl(1, 0, 1), new Hsl(1, 0, 1));
// // Valid objects of the same type but not equal Assert.Equal(new Hsl(Vector3.One), new Hsl(Vector3.One));
// { new CieLab(Vector3.One), new CieLab(Vector3.Zero), typeof(CieLab) }, Assert.False(x.Equals(y));
// { new CieLch(Vector3.One), new CieLch(Vector3.Zero), typeof(CieLch) }, }
// { new CieLchuv(Vector3.One), new CieLchuv(Vector3.Zero), typeof(CieLchuv) },
// { new CieLuv(Vector3.One), new CieLuv(Vector3.Zero), typeof(CieLuv) }, [Fact]
// { new CieXyz(Vector3.One), new CieXyz(Vector3.Zero), typeof(CieXyz) }, public void HsvEquality()
// { new CieXyy(Vector3.One), new CieXyy(Vector3.Zero), typeof(CieXyy) }, {
// { new HunterLab(Vector3.One), new HunterLab(Vector3.Zero), typeof(HunterLab) }, var x = default(Hsv);
// { new Lms(Vector3.One), new Lms(Vector3.Zero), typeof(Lms) }, var y = new Hsv(Vector3.One);
// { new LinearRgb(Vector3.One), new LinearRgb(Vector3.Zero), typeof(LinearRgb) }, Assert.Equal(default(Hsv), default(Hsv));
// { new Rgb(Vector3.One), new Rgb(Vector3.Zero), typeof(Rgb) }, Assert.Equal(new Hsv(1, 0, 1), new Hsv(1, 0, 1));
// { new Cmyk(Vector4.One), new Cmyk(Vector4.Zero), typeof(Cmyk) }, Assert.Equal(new Hsv(Vector3.One), new Hsv(Vector3.One));
// { new Hsl(Vector3.One), new Hsl(Vector3.Zero), typeof(Hsl) }, Assert.False(x.Equals(y));
// { new Hsv(Vector3.One), new Hsv(Vector3.Zero), typeof(Hsv) }, }
// { new YCbCr(Vector3.One), new YCbCr(Vector3.Zero), typeof(YCbCr) },
// }; [Fact]
public void HunterLabEquality()
//public static readonly TheoryData<object, object, Type, float> AlmostEqualsData = {
// new TheoryData<object, object, Type, float> var x = default(HunterLab);
// { var y = new HunterLab(Vector3.One);
// { new CieLab(0F, 0F, 0F), new CieLab(0F, 0F, 0F), typeof(CieLab), 0F }, Assert.Equal(default(HunterLab), default(HunterLab));
// { new CieLab(0F, 0F, 0F), new CieLab(0F, 0F, 0F), typeof(CieLab), .001F }, Assert.Equal(new HunterLab(1, 0, 1), new HunterLab(1, 0, 1));
// { new CieLab(0F, 0F, 0F), new CieLab(0F, 0F, 0F), typeof(CieLab), .0001F }, Assert.Equal(new HunterLab(Vector3.One), new HunterLab(Vector3.One));
// { new CieLab(0F, 0F, 0F), new CieLab(0F, 0F, 0F), typeof(CieLab), .0005F }, Assert.False(x.Equals(y));
// { new CieLab(0F, 0F, 0F), new CieLab(0F, .001F, 0F), typeof(CieLab), .001F }, }
// { new CieLab(0F, 0F, 0F), new CieLab(0F, 0F, .0001F), typeof(CieLab), .0001F },
// { new CieLab(0F, 0F, 0F), new CieLab(.0005F, 0F, 0F), typeof(CieLab), .0005F }, [Fact]
// { new CieLch(0F, 0F, 0F), new CieLch(0F, .001F, 0F), typeof(CieLch), .001F }, public void LmsEquality()
// { new CieLchuv(0F, 0F, 0F), new CieLchuv(0F, .001F, 0F), typeof(CieLchuv), .001F }, {
// { new CieLuv(0F, 0F, 0F), new CieLuv(0F, .001F, 0F), typeof(CieLuv), .001F }, var x = default(Lms);
// { new CieXyz(380F, 380F, 380F), new CieXyz(380F, 380F, 380F), typeof(CieXyz), 0F }, var y = new Lms(Vector3.One);
// { new CieXyz(380F, 380F, 380F), new CieXyz(380.001F, 380F, 380F), typeof(CieXyz), .01F }, Assert.Equal(default(Lms), default(Lms));
// { new CieXyz(380F, 380F, 380F), new CieXyz(380F, 380.001F, 380F), typeof(CieXyz), .01F }, Assert.Equal(new Lms(1, 0, 1), new Lms(1, 0, 1));
// { new CieXyz(380F, 380F, 380F), new CieXyz(380F, 380F, 380.001F), typeof(CieXyz), .01F }, Assert.Equal(new Lms(Vector3.One), new Lms(Vector3.One));
// { new Cmyk(1, 1, 1, 1), new Cmyk(1, 1, 1, .99F), typeof(Cmyk), .01F }, Assert.False(x.Equals(y));
// { new YCbCr(255F, 128F, 128F), new YCbCr(255F, 128F, 128.001F), typeof(YCbCr), .01F }, }
// { new Hsv(0F, 0F, 0F), new Hsv(0F, 0F, 0F), typeof(Hsv), 0F },
// { new Hsl(0F, 0F, 0F), new Hsl(0F, 0F, 0F), typeof(Hsl), 0F }, [Fact]
// }; public void LinearRgbEquality()
{
//public static readonly TheoryData<object, object, Type, float> AlmostNotEqualsData = var x = default(LinearRgb);
// new TheoryData<object, object, Type, float> var y = new LinearRgb(Vector3.One);
// { Assert.Equal(default(LinearRgb), default(LinearRgb));
// { new CieLab(0F, 0F, 0F), new CieLab(0.1F, 0F, 0F), typeof(CieLab), .001F }, Assert.Equal(new LinearRgb(1, 0, 1), new LinearRgb(1, 0, 1));
// { new CieLab(0F, 0F, 0F), new CieLab(0F, 0.1F, 0F), typeof(CieLab), .001F }, Assert.Equal(new LinearRgb(Vector3.One), new LinearRgb(Vector3.One));
// { new CieLab(0F, 0F, 0F), new CieLab(0F, 0F, 0.1F), typeof(CieLab), .001F }, Assert.False(x.Equals(y));
// { new CieXyz(380F, 380F, 380F), new CieXyz(380.1F, 380F, 380F), typeof(CieXyz), .001F }, }
// { new CieXyz(380F, 380F, 380F), new CieXyz(380F, 380.1F, 380F), typeof(CieXyz), .001F },
// { new CieXyz(380F, 380F, 380F), new CieXyz(380F, 380F, 380.1F), typeof(CieXyz), .001F }, [Fact]
// }; public void RgbEquality()
{
//[Theory] var x = default(Rgb);
//[MemberData(nameof(EmptyData))] var y = new Rgb(Vector3.One);
//public void Vector_Equals_WhenTrue(string color) Assert.Equal(default(Rgb), default(Rgb));
//{ Assert.Equal(new Rgb(1, 0, 1), new Rgb(1, 0, 1));
// IColorVector colorVector = EmptyDataLookup[color]; Assert.Equal(new Rgb(Vector3.One), new Rgb(Vector3.One));
// // Act Assert.False(x.Equals(y));
// bool equal = colorVector.Vector.Equals(Vector3.Zero); }
// // Assert [Fact]
// Assert.True(equal); public void YCbCrEquality()
//} {
var x = default(YCbCr);
//[Theory] var y = new YCbCr(Vector3.One);
//[MemberData(nameof(EqualityData))] Assert.Equal(default(YCbCr), default(YCbCr));
//public void Equals_WhenTrue(object first, object second, Type type) Assert.Equal(new YCbCr(1, 0, 1), new YCbCr(1, 0, 1));
//{ Assert.Equal(new YCbCr(Vector3.One), new YCbCr(Vector3.One));
// // Act Assert.False(x.Equals(y));
// bool equal = first.Equals(second); }
// // Assert [Fact]
// Assert.True(equal); public void CmykEquality()
//} {
var x = default(Cmyk);
//[Theory] var y = new Cmyk(Vector4.One);
//[MemberData(nameof(NotEqualityDataNulls))] Assert.Equal(default(Cmyk), default(Cmyk));
//[MemberData(nameof(NotEqualityDataDifferentObjects))] Assert.Equal(new Cmyk(1, 0, 1, 0), new Cmyk(1, 0, 1, 0));
//[MemberData(nameof(NotEqualityData))] Assert.Equal(new Cmyk(Vector4.One), new Cmyk(Vector4.One));
//public void Equals_WhenFalse(object first, object second, Type type) Assert.False(x.Equals(y));
//{ }
// // Act
// bool equal = first.Equals(second);
// // Assert
// Assert.False(equal);
//}
//[Theory]
//[MemberData(nameof(EqualityData))]
//public void GetHashCode_WhenEqual(object first, object second, Type type)
//{
// // Act
// bool equal = first.GetHashCode() == second.GetHashCode();
// // Assert
// Assert.True(equal);
//}
//[Theory]
//[MemberData(nameof(NotEqualityDataDifferentObjects))]
//public void GetHashCode_WhenNotEqual(object first, object second, Type type)
//{
// // Act
// bool equal = first.GetHashCode() == second.GetHashCode();
// // Assert
// Assert.False(equal);
//}
//[Theory]
//[MemberData(nameof(EqualityData))]
//public void GenericEquals_WhenTrue(object first, object second, Type type)
//{
// // Arrange
// // Cast to the known object types, this is so that we can hit the
// // equality operator on the concrete type, otherwise it goes to the
// // default "object" one :)
// dynamic firstObject = Convert.ChangeType(first, type);
// dynamic secondObject = Convert.ChangeType(second, type);
// // Act
// dynamic equal = firstObject.Equals(secondObject);
// // Assert
// Assert.True(equal);
//}
//[Theory]
//[MemberData(nameof(NotEqualityData))]
//public void GenericEquals_WhenFalse(object first, object second, Type type)
//{
// // Arrange
// // Cast to the known object types, this is so that we can hit the
// // equality operator on the concrete type, otherwise it goes to the
// // default "object" one :)
// dynamic firstObject = Convert.ChangeType(first, type);
// dynamic secondObject = Convert.ChangeType(second, type);
// // Act
// dynamic equal = firstObject.Equals(secondObject);
// // Assert
// Assert.False(equal);
//}
//// TODO:Disabled due to RuntypeBinder errors while structs are internal
////[Theory]
////[MemberData(nameof(EqualityData))]
////public void EqualityOperator(object first, object second, Type type)
////{
//// // Arrange
//// // Cast to the known object types, this is so that we can hit the
//// // equality operator on the concrete type, otherwise it goes to the
//// // default "object" one :)
//// dynamic firstObject = Convert.ChangeType(first, type);
//// dynamic secondObject = Convert.ChangeType(second, type);
//// // Act
//// dynamic equal = firstObject == secondObject;
//// // Assert
//// Assert.True(equal);
////}
//[Theory]
//[MemberData(nameof(NotEqualityData))]
//public void Operator_WhenTrue(object first, object second, Type type)
//{
// // Arrange
// // Cast to the known object types, this is so that we can hit the
// // equality operator on the concrete type, otherwise it goes to the
// // default "object" one :)
// dynamic firstObject = Convert.ChangeType(first, type);
// dynamic secondObject = Convert.ChangeType(second, type);
// // Act
// dynamic notEqual = firstObject != secondObject;
// // Assert
// Assert.True(notEqual);
//}
//// TODO:Disabled due to RuntypeBinder errors while structs are internal
////[Theory]
////[MemberData(nameof(AlmostEqualsData))]
////public void AlmostEquals(object first, object second, Type type, float precision)
////{
//// // Arrange
//// // Cast to the known object types, this is so that we can hit the
//// // equality operator on the concrete type, otherwise it goes to the
//// // default "object" one :)
//// dynamic firstObject = Convert.ChangeType(first, type);
//// dynamic secondObject = Convert.ChangeType(second, type);
//// // Act
//// dynamic almostEqual = firstObject.AlmostEquals(secondObject, precision);
//// // Assert
//// Assert.True(almostEqual);
////}
//// TODO:Disabled due to RuntypeBinder errors while structs are internal
////[Theory]
////[MemberData(nameof(AlmostNotEqualsData))]
////public void AlmostNotEquals(object first, object second, Type type, float precision)
////{
//// // Arrange
//// // Cast to the known object types, this is so that we can hit the
//// // equality operator on the concrete type, otherwise it goes to the
//// // default "object" one :)
//// dynamic firstObject = Convert.ChangeType(first, type);
//// dynamic secondObject = Convert.ChangeType(second, type);
//// // Act
//// dynamic almostEqual = firstObject.AlmostEquals(secondObject, precision);
//// // Assert
//// Assert.False(almostEqual);
////}
} }
} }

2
tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs

@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
seed); seed);
} }
private static void ValidateYCbCr(JpegColorConverter.ComponentValues values, Vector4[] result, int i) private static void ValidateYCbCr(in JpegColorConverter.ComponentValues values, Vector4[] result, int i)
{ {
float y = values.Component0[i]; float y = values.Component0[i];
float cb = values.Component1[i]; float cb = values.Component1[i];

Loading…
Cancel
Save