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.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

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

@ -1,6 +1,9 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
@ -23,6 +26,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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>
/// Converts a <see cref="CieLch"/> into a <see cref="Rgb"/>
/// </summary>
@ -34,6 +58,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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>
/// Converts a <see cref="CieLchuv"/> into a <see cref="Rgb"/>
/// </summary>
@ -45,6 +90,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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>
/// Converts a <see cref="CieLuv"/> into a <see cref="Rgb"/>
/// </summary>
@ -56,6 +122,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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>
/// Converts a <see cref="CieXyy"/> into a <see cref="Rgb"/>
/// </summary>
@ -67,6 +154,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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>
/// Converts a <see cref="CieXyz"/> into a <see cref="Rgb"/>
/// </summary>
@ -81,6 +189,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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>
/// Converts a <see cref="Cmyk"/> into a <see cref="Rgb"/>
/// </summary>
@ -92,6 +221,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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>
/// Converts a <see cref="Hsv"/> into a <see cref="Rgb"/>
/// </summary>
@ -103,6 +253,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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>
/// Converts a <see cref="Hsl"/> into a <see cref="Rgb"/>
/// </summary>
@ -114,6 +285,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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>
/// Converts a <see cref="HunterLab"/> into a <see cref="Rgb"/>
/// </summary>
@ -125,6 +317,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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>
/// Converts a <see cref="LinearRgb"/> into a <see cref="Rgb"/>
/// </summary>
@ -136,6 +349,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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>
/// Converts a <see cref="Lms"/> into a <see cref="Rgb"/>
/// </summary>
@ -147,6 +381,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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>
/// Converts a <see cref="YCbCr"/> into a <see cref="Rgb"/>
/// </summary>
@ -160,5 +415,26 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
// Adaptation
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.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
@ -24,6 +27,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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>
/// Converts a <see cref="CieLch"/> into a <see cref="YCbCr"/>
/// </summary>
@ -37,15 +61,24 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
}
/// <summary>
/// Converts a <see cref="CieLchuv"/> into a <see cref="YCbCr"/>
/// Performs the bulk conversion from <see cref="CieLch"/> into <see cref="YCbCr"/>
/// </summary>
/// <param name="color">The color to convert.</param>
/// <returns>The <see cref="YCbCr"/></returns>
public YCbCr ToYCbCr(in CieLchuv color)
/// <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<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>
@ -60,6 +93,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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>
/// Converts a <see cref="CieXyy"/> into a <see cref="YCbCr"/>
/// </summary>
@ -72,6 +126,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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>
/// Converts a <see cref="CieXyz"/> into a <see cref="YCbCr"/>
/// </summary>
@ -84,6 +159,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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>
/// Converts a <see cref="Cmyk"/> into a <see cref="YCbCr"/>
/// </summary>
@ -96,6 +192,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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>
/// Converts a <see cref="Hsl"/> into a <see cref="YCbCr"/>
/// </summary>
@ -108,6 +225,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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>
/// Converts a <see cref="Hsv"/> into a <see cref="YCbCr"/>
/// </summary>
@ -120,6 +258,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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>
/// Converts a <see cref="HunterLab"/> into a <see cref="YCbCr"/>
/// </summary>
@ -132,6 +291,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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>
/// Converts a <see cref="LinearRgb"/> into a <see cref="YCbCr"/>
/// </summary>
@ -144,6 +324,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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>
/// Converts a <see cref="Lms"/> into a <see cref="YCbCr"/>
/// </summary>
@ -156,6 +357,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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>
/// Converts a <see cref="Rgb"/> into a <see cref="YCbCr"/>
/// </summary>
@ -165,5 +387,26 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
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>
/// Allows the approximate comparison of colorspace component values.
/// </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;
@ -36,10 +45,121 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
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)
{
float d = x - y;
return d >= -this.Epsilon && d <= this.Epsilon;
}
}

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

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

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

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

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

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

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

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

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

@ -17,8 +17,7 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
/// </remarks>
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();
[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)
{
var input = new CieXyy(x, y, yl);
var expected = new CieXyz(xyzX, xyzY, xyzZ);
// Act
CieXyz output = Converter.ToCieXyz(input);
var actual = Converter.ToCieXyz(input);
// Assert
Assert.Equal(xyzX, output.X, FloatRoundingComparer);
Assert.Equal(xyzY, output.Y, FloatRoundingComparer);
Assert.Equal(xyzZ, output.Z, FloatRoundingComparer);
Assert.Equal(expected, actual, ColorSpaceComparer);
}
[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)
{
var input = new CieXyz(xyzX, xyzY, xyzZ);
var expected = new CieXyy(x, y, yl);
// Act
CieXyy output = Converter.ToCieXyy(input);
var actual = Converter.ToCieXyy(input);
// Assert
Assert.Equal(x, output.X, FloatRoundingComparer);
Assert.Equal(y, output.Y, FloatRoundingComparer);
Assert.Equal(yl, output.Yl, FloatRoundingComparer);
Assert.Equal(expected, actual, ColorSpaceComparer);
}
}
}

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

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

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

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

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

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

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

@ -17,297 +17,158 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
/// </summary>
public class ColorSpaceEqualityTests
{
//internal static readonly Dictionary<string, IColorVector> EmptyDataLookup =
// new Dictionary<string, IColorVector>
// {
// {nameof( CieLab), default(CieLab) },
// {nameof( CieLch), default(CieLch) },
// {nameof( CieLchuv), default(CieLchuv) },
// {nameof( CieLuv), default(CieLuv) },
// {nameof( CieXyz), default(CieXyz) },
// {nameof( CieXyy), default(CieXyy) },
// {nameof( Hsl), default(Hsl) },
// {nameof( HunterLab), default(HunterLab) },
// {nameof( Lms), default(Lms) },
// {nameof( LinearRgb), default(LinearRgb) },
// {nameof( Rgb), default(Rgb) },
// {nameof( YCbCr), default(YCbCr) }
// };
//public static readonly IEnumerable<object[]> EmptyData = EmptyDataLookup.Select(x => new[] { x.Key });
//public static readonly TheoryData<object, object, Type> EqualityData =
// new TheoryData<object, object, Type>
// {
// { new CieLab(Vector3.One), new CieLab(Vector3.One), typeof(CieLab) },
// { new CieLch(Vector3.One), new CieLch(Vector3.One), typeof(CieLch) },
// { new CieLchuv(Vector3.One), new CieLchuv(Vector3.One), typeof(CieLchuv) },
// { new CieLuv(Vector3.One), new CieLuv(Vector3.One), typeof(CieLuv) },
// { new CieXyz(Vector3.One), new CieXyz(Vector3.One), typeof(CieXyz) },
// { new CieXyy(Vector3.One), new CieXyy(Vector3.One), typeof(CieXyy) },
// { new HunterLab(Vector3.One), new HunterLab(Vector3.One), typeof(HunterLab) },
// { new Lms(Vector3.One), new Lms(Vector3.One), typeof(Lms) },
// { new LinearRgb(Vector3.One), new LinearRgb(Vector3.One), typeof(LinearRgb) },
// { 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) },
// { new YCbCr(Vector3.One), new YCbCr(Vector3.One), typeof(YCbCr) },
// };
//public static readonly TheoryData<object, object, Type> NotEqualityDataNulls =
// new TheoryData<object, object, Type>
// {
// // Valid object against null
// { new CieLab(Vector3.One), null, typeof(CieLab) },
// { new CieLch(Vector3.One), null, typeof(CieLch) },
// { new CieLchuv(Vector3.One), null, typeof(CieLchuv) },
// { new CieLuv(Vector3.One), null, typeof(CieLuv) },
// { new CieXyz(Vector3.One), null, typeof(CieXyz) },
// { new CieXyy(Vector3.One), null, typeof(CieXyy) },
// { new HunterLab(Vector3.One), null, typeof(HunterLab) },
// { new Lms(Vector3.One), null, typeof(Lms) },
// { new LinearRgb(Vector3.One), null, typeof(LinearRgb) },
// { new Rgb(Vector3.One), null, typeof(Rgb) },
// { new Hsl(Vector3.One), null, typeof(Hsl) },
// { new Hsv(Vector3.One), null, typeof(Hsv) },
// { new YCbCr(Vector3.One), null, typeof(YCbCr) },
// };
//public static readonly TheoryData<object, object, Type> NotEqualityDataDifferentObjects =
// new TheoryData<object, object, Type>
// {
// // Valid objects of different types but not equal
// { new CieLab(Vector3.One), new CieLch(Vector3.Zero), null },
// { new CieLuv(Vector3.One), new CieLchuv(Vector3.Zero), null },
// { new CieXyz(Vector3.One), new HunterLab(Vector3.Zero), null },
// { new Rgb(Vector3.One), new LinearRgb(Vector3.Zero), null },
// { 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 },
// { new Hsv(Vector3.One), new Hsl(Vector3.Zero), null },
// };
//public static readonly TheoryData<object, object, Type> NotEqualityData =
// new TheoryData<object, object, Type>
// {
// // Valid objects of the same type but not equal
// { new CieLab(Vector3.One), new CieLab(Vector3.Zero), typeof(CieLab) },
// { 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) },
// { new CieXyz(Vector3.One), new CieXyz(Vector3.Zero), typeof(CieXyz) },
// { new CieXyy(Vector3.One), new CieXyy(Vector3.Zero), typeof(CieXyy) },
// { new HunterLab(Vector3.One), new HunterLab(Vector3.Zero), typeof(HunterLab) },
// { new Lms(Vector3.One), new Lms(Vector3.Zero), typeof(Lms) },
// { new LinearRgb(Vector3.One), new LinearRgb(Vector3.Zero), typeof(LinearRgb) },
// { new Rgb(Vector3.One), new Rgb(Vector3.Zero), typeof(Rgb) },
// { new Cmyk(Vector4.One), new Cmyk(Vector4.Zero), typeof(Cmyk) },
// { new Hsl(Vector3.One), new Hsl(Vector3.Zero), typeof(Hsl) },
// { new Hsv(Vector3.One), new Hsv(Vector3.Zero), typeof(Hsv) },
// { new YCbCr(Vector3.One), new YCbCr(Vector3.Zero), typeof(YCbCr) },
// };
//public static readonly TheoryData<object, object, Type, float> AlmostEqualsData =
// new TheoryData<object, object, Type, float>
// {
// { new CieLab(0F, 0F, 0F), new CieLab(0F, 0F, 0F), typeof(CieLab), 0F },
// { new CieLab(0F, 0F, 0F), new CieLab(0F, 0F, 0F), typeof(CieLab), .001F },
// { new CieLab(0F, 0F, 0F), new CieLab(0F, 0F, 0F), typeof(CieLab), .0001F },
// { new CieLab(0F, 0F, 0F), new CieLab(0F, 0F, 0F), typeof(CieLab), .0005F },
// { 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 },
// { new CieLch(0F, 0F, 0F), new CieLch(0F, .001F, 0F), typeof(CieLch), .001F },
// { 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 },
// { new CieXyz(380F, 380F, 380F), new CieXyz(380F, 380F, 380F), typeof(CieXyz), 0F },
// { new CieXyz(380F, 380F, 380F), new CieXyz(380.001F, 380F, 380F), typeof(CieXyz), .01F },
// { new CieXyz(380F, 380F, 380F), new CieXyz(380F, 380.001F, 380F), typeof(CieXyz), .01F },
// { new CieXyz(380F, 380F, 380F), new CieXyz(380F, 380F, 380.001F), typeof(CieXyz), .01F },
// { new Cmyk(1, 1, 1, 1), new Cmyk(1, 1, 1, .99F), typeof(Cmyk), .01F },
// { 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 },
// };
//public static readonly TheoryData<object, object, Type, float> AlmostNotEqualsData =
// new TheoryData<object, object, Type, float>
// {
// { new CieLab(0F, 0F, 0F), new CieLab(0.1F, 0F, 0F), typeof(CieLab), .001F },
// { new CieLab(0F, 0F, 0F), new CieLab(0F, 0.1F, 0F), typeof(CieLab), .001F },
// { new CieLab(0F, 0F, 0F), new CieLab(0F, 0F, 0.1F), typeof(CieLab), .001F },
// { 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 },
// };
//[Theory]
//[MemberData(nameof(EmptyData))]
//public void Vector_Equals_WhenTrue(string color)
//{
// IColorVector colorVector = EmptyDataLookup[color];
// // Act
// bool equal = colorVector.Vector.Equals(Vector3.Zero);
// // Assert
// Assert.True(equal);
//}
//[Theory]
//[MemberData(nameof(EqualityData))]
//public void Equals_WhenTrue(object first, object second, Type type)
//{
// // Act
// bool equal = first.Equals(second);
// // Assert
// Assert.True(equal);
//}
//[Theory]
//[MemberData(nameof(NotEqualityDataNulls))]
//[MemberData(nameof(NotEqualityDataDifferentObjects))]
//[MemberData(nameof(NotEqualityData))]
//public void Equals_WhenFalse(object first, object second, Type type)
//{
// // 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);
////}
[Fact]
public void CieLabEquality()
{
var x = default(CieLab);
var y = new CieLab(Vector3.One);
Assert.Equal(default(CieLab), default(CieLab));
Assert.Equal(new CieLab(1, 0, 1), new CieLab(1, 0, 1));
Assert.Equal(new CieLab(Vector3.One), new CieLab(Vector3.One));
Assert.False(x.Equals(y));
}
[Fact]
public void CieLchEquality()
{
var x = default(CieLch);
var y = new CieLch(Vector3.One);
Assert.Equal(default(CieLch), default(CieLch));
Assert.Equal(new CieLch(1, 0, 1), new CieLch(1, 0, 1));
Assert.Equal(new CieLch(Vector3.One), new CieLch(Vector3.One));
Assert.False(x.Equals(y));
}
[Fact]
public void CieLchuvEquality()
{
var x = default(CieLchuv);
var y = new CieLchuv(Vector3.One);
Assert.Equal(default(CieLchuv), default(CieLchuv));
Assert.Equal(new CieLchuv(1, 0, 1), new CieLchuv(1, 0, 1));
Assert.Equal(new CieLchuv(Vector3.One), new CieLchuv(Vector3.One));
Assert.False(x.Equals(y));
}
[Fact]
public void CieLuvEquality()
{
var x = default(CieLuv);
var y = new CieLuv(Vector3.One);
Assert.Equal(default(CieLuv), default(CieLuv));
Assert.Equal(new CieLuv(1, 0, 1), new CieLuv(1, 0, 1));
Assert.Equal(new CieLuv(Vector3.One), new CieLuv(Vector3.One));
Assert.False(x.Equals(y));
}
[Fact]
public void CieXyzEquality()
{
var x = default(CieXyz);
var y = new CieXyz(Vector3.One);
Assert.Equal(default(CieXyz), default(CieXyz));
Assert.Equal(new CieXyz(1, 0, 1), new CieXyz(1, 0, 1));
Assert.Equal(new CieXyz(Vector3.One), new CieXyz(Vector3.One));
Assert.False(x.Equals(y));
}
[Fact]
public void CieXyyEquality()
{
var x = default(CieXyy);
var y = new CieXyy(Vector3.One);
Assert.Equal(default(CieXyy), default(CieXyy));
Assert.Equal(new CieXyy(1, 0, 1), new CieXyy(1, 0, 1));
Assert.Equal(new CieXyy(Vector3.One), new CieXyy(Vector3.One));
Assert.False(x.Equals(y));
}
[Fact]
public void HslEquality()
{
var x = default(Hsl);
var y = new Hsl(Vector3.One);
Assert.Equal(default(Hsl), default(Hsl));
Assert.Equal(new Hsl(1, 0, 1), new Hsl(1, 0, 1));
Assert.Equal(new Hsl(Vector3.One), new Hsl(Vector3.One));
Assert.False(x.Equals(y));
}
[Fact]
public void HsvEquality()
{
var x = default(Hsv);
var y = new Hsv(Vector3.One);
Assert.Equal(default(Hsv), default(Hsv));
Assert.Equal(new Hsv(1, 0, 1), new Hsv(1, 0, 1));
Assert.Equal(new Hsv(Vector3.One), new Hsv(Vector3.One));
Assert.False(x.Equals(y));
}
[Fact]
public void HunterLabEquality()
{
var x = default(HunterLab);
var y = new HunterLab(Vector3.One);
Assert.Equal(default(HunterLab), default(HunterLab));
Assert.Equal(new HunterLab(1, 0, 1), new HunterLab(1, 0, 1));
Assert.Equal(new HunterLab(Vector3.One), new HunterLab(Vector3.One));
Assert.False(x.Equals(y));
}
[Fact]
public void LmsEquality()
{
var x = default(Lms);
var y = new Lms(Vector3.One);
Assert.Equal(default(Lms), default(Lms));
Assert.Equal(new Lms(1, 0, 1), new Lms(1, 0, 1));
Assert.Equal(new Lms(Vector3.One), new Lms(Vector3.One));
Assert.False(x.Equals(y));
}
[Fact]
public void LinearRgbEquality()
{
var x = default(LinearRgb);
var y = new LinearRgb(Vector3.One);
Assert.Equal(default(LinearRgb), default(LinearRgb));
Assert.Equal(new LinearRgb(1, 0, 1), new LinearRgb(1, 0, 1));
Assert.Equal(new LinearRgb(Vector3.One), new LinearRgb(Vector3.One));
Assert.False(x.Equals(y));
}
[Fact]
public void RgbEquality()
{
var x = default(Rgb);
var y = new Rgb(Vector3.One);
Assert.Equal(default(Rgb), default(Rgb));
Assert.Equal(new Rgb(1, 0, 1), new Rgb(1, 0, 1));
Assert.Equal(new Rgb(Vector3.One), new Rgb(Vector3.One));
Assert.False(x.Equals(y));
}
[Fact]
public void YCbCrEquality()
{
var x = default(YCbCr);
var y = new YCbCr(Vector3.One);
Assert.Equal(default(YCbCr), default(YCbCr));
Assert.Equal(new YCbCr(1, 0, 1), new YCbCr(1, 0, 1));
Assert.Equal(new YCbCr(Vector3.One), new YCbCr(Vector3.One));
Assert.False(x.Equals(y));
}
[Fact]
public void CmykEquality()
{
var x = default(Cmyk);
var y = new Cmyk(Vector4.One);
Assert.Equal(default(Cmyk), default(Cmyk));
Assert.Equal(new Cmyk(1, 0, 1, 0), new Cmyk(1, 0, 1, 0));
Assert.Equal(new Cmyk(Vector4.One), new Cmyk(Vector4.One));
Assert.False(x.Equals(y));
}
}
}

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

@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
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 cb = values.Component1[i];

Loading…
Cancel
Save