From 28f793d5e8bbace345af2db084cfd00dd19c8115 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Thu, 26 Jul 2018 19:17:35 +0100 Subject: [PATCH] Begin colorspace test cleanup. --- .../Conversion/ColorSpaceConverter.Lms.cs | 1 + .../Conversion/ColorSpaceConverter.Rgb.cs | 276 +++++++++++ .../Conversion/ColorSpaceConverter.YCbCr.cs | 255 +++++++++- .../ApproximateColorspaceComparer.cs | 124 ++++- .../CieLabAndCieLchConversionTests.cs | 18 +- .../CieLuvAndCieLchuvConversionTests.cs | 18 +- .../CieXyzAndCieLabConversionTest.cs | 17 +- .../CieXyzAndCieLuvConversionTest.cs | 17 +- .../CieXyzAndCieXyyConversionTest.cs | 17 +- .../CieXyzAndHunterLabConversionTest.cs | 26 +- .../Colorspaces/CieXyzAndLmsConversionTest.cs | 18 +- .../Colorspaces/ColorConverterAdaptTest.cs | 65 +-- .../Colorspaces/ColorSpaceEqualityTests.cs | 445 ++++++------------ .../Formats/Jpg/JpegColorConverterTests.cs | 2 +- 14 files changed, 880 insertions(+), 419 deletions(-) diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Lms.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Lms.cs index 4f1e4b5a1..052aeb6d1 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Lms.cs +++ b/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; diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs index bea6e0801..5ef793448 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs +++ b/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); } + /// + /// Performs the bulk conversion from into + /// + /// The span to the source colors + /// The span to the destination colors + /// The number of colors to convert. + public void Convert(Span source, Span 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); + } + } + /// /// Converts a into a /// @@ -34,6 +58,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion return this.ToRgb(xyzColor); } + /// + /// Performs the bulk conversion from into + /// + /// The span to the source colors + /// The span to the destination colors + /// The number of colors to convert. + public void Convert(Span source, Span 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); + } + } + /// /// Converts a into a /// @@ -45,6 +90,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion return this.ToRgb(xyzColor); } + /// + /// Performs the bulk conversion from into + /// + /// The span to the source colors + /// The span to the destination colors + /// The number of colors to convert. + public void Convert(Span source, Span 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); + } + } + /// /// Converts a into a /// @@ -56,6 +122,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion return this.ToRgb(xyzColor); } + /// + /// Performs the bulk conversion from into + /// + /// The span to the source colors + /// The span to the destination colors + /// The number of colors to convert. + public void Convert(Span source, Span 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); + } + } + /// /// Converts a into a /// @@ -67,6 +154,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion return this.ToRgb(xyzColor); } + /// + /// Performs the bulk conversion from into + /// + /// The span to the source colors + /// The span to the destination colors + /// The number of colors to convert. + public void Convert(Span source, Span 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); + } + } + /// /// Converts a into a /// @@ -81,6 +189,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion return this.ToRgb(linear); } + /// + /// Performs the bulk conversion from into + /// + /// The span to the source colors + /// The span to the destination colors + /// The number of colors to convert. + public void Convert(Span source, Span 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); + } + } + /// /// Converts a into a /// @@ -92,6 +221,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion return CmykAndRgbConverter.Convert(color); } + /// + /// Performs the bulk conversion from into + /// + /// The span to the source colors + /// The span to the destination colors + /// The number of colors to convert. + public void Convert(Span source, Span 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); + } + } + /// /// Converts a into a /// @@ -103,6 +253,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion return HsvAndRgbConverter.Convert(color); } + /// + /// Performs the bulk conversion from into + /// + /// The span to the source colors + /// The span to the destination colors + /// The number of colors to convert. + public void Convert(Span source, Span 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); + } + } + /// /// Converts a into a /// @@ -114,6 +285,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion return HslAndRgbConverter.Convert(color); } + /// + /// Performs the bulk conversion from into + /// + /// The span to the source colors + /// The span to the destination colors + /// The number of colors to convert. + public void Convert(Span source, Span 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); + } + } + /// /// Converts a into a /// @@ -125,6 +317,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion return this.ToRgb(xyzColor); } + /// + /// Performs the bulk conversion from into + /// + /// The span to the source colors + /// The span to the destination colors + /// The number of colors to convert. + public void Convert(Span source, Span 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); + } + } + /// /// Converts a into a /// @@ -136,6 +349,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion return LinearRgbToRgbConverter.Convert(color); } + /// + /// Performs the bulk conversion from into + /// + /// The span to the source colors + /// The span to the destination colors + /// The number of colors to convert. + public void Convert(Span source, Span 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); + } + } + /// /// Converts a into a /// @@ -147,6 +381,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion return this.ToRgb(xyzColor); } + /// + /// Performs the bulk conversion from into + /// + /// The span to the source colors + /// The span to the destination colors + /// The number of colors to convert. + public void Convert(Span source, Span 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); + } + } + /// /// Converts a into a /// @@ -160,5 +415,26 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion // Adaptation return this.Adapt(rgb); } + + /// + /// Performs the bulk conversion from into + /// + /// The span to the source colors + /// The span to the destination colors + /// The number of colors to convert. + public void Convert(Span source, Span 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); + } + } } } \ No newline at end of file diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.YCbCr.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.YCbCr.cs index 4726d3d49..4bb3db82c 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.YCbCr.cs +++ b/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); } + /// + /// Performs the bulk conversion from into + /// + /// The span to the source colors + /// The span to the destination colors + /// The number of colors to convert. + public void Convert(Span source, Span 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); + } + } + /// /// Converts a into a /// @@ -37,15 +61,24 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion } /// - /// Converts a into a + /// Performs the bulk conversion from into /// - /// The color to convert. - /// The - public YCbCr ToYCbCr(in CieLchuv color) + /// The span to the source colors + /// The span to the destination colors + /// The number of colors to convert. + public void Convert(Span source, Span 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); + } } /// @@ -60,6 +93,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion return this.ToYCbCr(xyzColor); } + /// + /// Performs the bulk conversion from into + /// + /// The span to the source colors + /// The span to the destination colors + /// The number of colors to convert. + public void Convert(Span source, Span 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); + } + } + /// /// Converts a into a /// @@ -72,6 +126,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion return this.ToYCbCr(xyzColor); } + /// + /// Performs the bulk conversion from into + /// + /// The span to the source colors + /// The span to the destination colors + /// The number of colors to convert. + public void Convert(Span source, Span 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); + } + } + /// /// Converts a into a /// @@ -84,6 +159,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion return YCbCrAndRgbConverter.Convert(rgb); } + /// + /// Performs the bulk conversion from into + /// + /// The span to the source colors + /// The span to the destination colors + /// The number of colors to convert. + public void Convert(Span source, Span 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); + } + } + /// /// Converts a into a /// @@ -96,6 +192,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion return YCbCrAndRgbConverter.Convert(rgb); } + /// + /// Performs the bulk conversion from into + /// + /// The span to the source colors + /// The span to the destination colors + /// The number of colors to convert. + public void Convert(Span source, Span 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); + } + } + /// /// Converts a into a /// @@ -108,6 +225,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion return YCbCrAndRgbConverter.Convert(rgb); } + /// + /// Performs the bulk conversion from into + /// + /// The span to the source colors + /// The span to the destination colors + /// The number of colors to convert. + public void Convert(Span source, Span 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); + } + } + /// /// Converts a into a /// @@ -120,6 +258,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion return YCbCrAndRgbConverter.Convert(rgb); } + /// + /// Performs the bulk conversion from into + /// + /// The span to the source colors + /// The span to the destination colors + /// The number of colors to convert. + public void Convert(Span source, Span 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); + } + } + /// /// Converts a into a /// @@ -132,6 +291,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion return this.ToYCbCr(xyzColor); } + /// + /// Performs the bulk conversion from into + /// + /// The span to the source colors + /// The span to the destination colors + /// The number of colors to convert. + public void Convert(Span source, Span 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); + } + } + /// /// Converts a into a /// @@ -144,6 +324,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion return YCbCrAndRgbConverter.Convert(rgb); } + /// + /// Performs the bulk conversion from into + /// + /// The span to the source colors + /// The span to the destination colors + /// The number of colors to convert. + public void Convert(Span source, Span 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); + } + } + /// /// Converts a into a /// @@ -156,6 +357,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion return this.ToYCbCr(xyzColor); } + /// + /// Performs the bulk conversion from into + /// + /// The span to the source colors + /// The span to the destination colors + /// The number of colors to convert. + public void Convert(Span source, Span 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); + } + } + /// /// Converts a into a /// @@ -165,5 +387,26 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion { return YCbCrAndRgbConverter.Convert(color); } + + /// + /// Performs the bulk conversion from into + /// + /// The span to the source colors + /// The span to the destination colors + /// The number of colors to convert. + public void Convert(Span source, Span 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); + } + } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Colorspaces/ApproximateColorspaceComparer.cs b/tests/ImageSharp.Tests/Colorspaces/ApproximateColorspaceComparer.cs index 28e2fdf82..faba575de 100644 --- a/tests/ImageSharp.Tests/Colorspaces/ApproximateColorspaceComparer.cs +++ b/tests/ImageSharp.Tests/Colorspaces/ApproximateColorspaceComparer.cs @@ -9,7 +9,16 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces /// /// Allows the approximate comparison of colorspace component values. /// - internal class ApproximateColorSpaceComparer : IEqualityComparer + internal class ApproximateColorSpaceComparer : + IEqualityComparer, + IEqualityComparer, + IEqualityComparer, + IEqualityComparer, + IEqualityComparer, + IEqualityComparer, + IEqualityComparer, + IEqualityComparer, + IEqualityComparer { private readonly float Epsilon; @@ -36,10 +45,121 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces return obj.GetHashCode(); } + /// + 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); + } + + /// + public int GetHashCode(CieLab obj) + { + return obj.GetHashCode(); + } + + /// + 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); + } + + /// + public int GetHashCode(CieLch obj) + { + return obj.GetHashCode(); + } + + /// + 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); + } + + /// + public int GetHashCode(CieLchuv obj) + { + return obj.GetHashCode(); + } + + /// + 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); + } + + /// + public int GetHashCode(CieLuv obj) + { + return obj.GetHashCode(); + } + + /// + 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); + } + + /// + public int GetHashCode(CieXyz obj) + { + return obj.GetHashCode(); + } + + /// + 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); + } + + /// + public int GetHashCode(CieXyy obj) + { + return obj.GetHashCode(); + } + + /// + 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); + } + + /// + public int GetHashCode(HunterLab obj) + { + return obj.GetHashCode(); + } + + /// + 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); + } + + /// + 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; } } diff --git a/tests/ImageSharp.Tests/Colorspaces/CieLabAndCieLchConversionTests.cs b/tests/ImageSharp.Tests/Colorspaces/CieLabAndCieLchConversionTests.cs index 299b9e9e5..0425d8e20 100644 --- a/tests/ImageSharp.Tests/Colorspaces/CieLabAndCieLchConversionTests.cs +++ b/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 /// public class CieLabAndCieLchConversionTests { - private static readonly IEqualityComparer FloatRoundingComparer = new FloatRoundingComparer(4); - + private static readonly ApproximateColorSpaceComparer ColorSpaceComparer = new ApproximateColorSpaceComparer(.0001F); private static readonly ColorSpaceConverter Converter = new ColorSpaceConverter(); /// @@ -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); } /// @@ -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); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Colorspaces/CieLuvAndCieLchuvConversionTests.cs b/tests/ImageSharp.Tests/Colorspaces/CieLuvAndCieLchuvConversionTests.cs index cbcddcfe5..1bff994e1 100644 --- a/tests/ImageSharp.Tests/Colorspaces/CieLuvAndCieLchuvConversionTests.cs +++ b/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 /// public class CieLuvAndCieLchuvuvConversionTests { - private static readonly IEqualityComparer FloatRoundingComparer = new FloatRoundingComparer(4); - + private static readonly ApproximateColorSpaceComparer ColorSpaceComparer = new ApproximateColorSpaceComparer(.0001F); private static readonly ColorSpaceConverter Converter = new ColorSpaceConverter(); /// @@ -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); } /// @@ -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); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Colorspaces/CieXyzAndCieLabConversionTest.cs b/tests/ImageSharp.Tests/Colorspaces/CieXyzAndCieLabConversionTest.cs index 1be3ac971..bf582650b 100644 --- a/tests/ImageSharp.Tests/Colorspaces/CieXyzAndCieLabConversionTest.cs +++ b/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 /// public class CieXyzAndCieLabConversionTest { - private static readonly IEqualityComparer FloatRoundingComparer = new FloatRoundingComparer(4); + private static readonly ApproximateColorSpaceComparer ColorSpaceComparer = new ApproximateColorSpaceComparer(.0001F); /// /// Tests conversion from to (). @@ -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); } /// @@ -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); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Colorspaces/CieXyzAndCieLuvConversionTest.cs b/tests/ImageSharp.Tests/Colorspaces/CieXyzAndCieLuvConversionTest.cs index 46f4f15b8..66150fe04 100644 --- a/tests/ImageSharp.Tests/Colorspaces/CieXyzAndCieLuvConversionTest.cs +++ b/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 /// public class CieXyzAndCieLuvConversionTest { - private static readonly IEqualityComparer FloatRoundingComparer = new FloatRoundingComparer(4); + private static readonly ApproximateColorSpaceComparer ColorSpaceComparer = new ApproximateColorSpaceComparer(.0001F); /// /// Tests conversion from to (). @@ -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); } /// @@ -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); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Colorspaces/CieXyzAndCieXyyConversionTest.cs b/tests/ImageSharp.Tests/Colorspaces/CieXyzAndCieXyyConversionTest.cs index d461acd56..46bdf8070 100644 --- a/tests/ImageSharp.Tests/Colorspaces/CieXyzAndCieXyyConversionTest.cs +++ b/tests/ImageSharp.Tests/Colorspaces/CieXyzAndCieXyyConversionTest.cs @@ -17,8 +17,7 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces /// public class CieXyzAndCieXyyConversionTest { - private static readonly IEqualityComparer 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); } } } diff --git a/tests/ImageSharp.Tests/Colorspaces/CieXyzAndHunterLabConversionTest.cs b/tests/ImageSharp.Tests/Colorspaces/CieXyzAndHunterLabConversionTest.cs index bea392c16..91ee9f131 100644 --- a/tests/ImageSharp.Tests/Colorspaces/CieXyzAndHunterLabConversionTest.cs +++ b/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 { /// - /// Tests - conversions. + /// Tests - conversions. /// /// /// Test data generated using: @@ -17,7 +16,7 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces /// public class CieXyzAndHunterLabConversionTest { - private static readonly IEqualityComparer FloatRoundingComparer = new FloatRoundingComparer(4); + private static readonly ApproximateColorSpaceComparer ColorSpaceComparer = new ApproximateColorSpaceComparer(.0001F); /// /// Tests conversion from to (). @@ -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); } /// @@ -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); } /// @@ -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); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Colorspaces/CieXyzAndLmsConversionTest.cs b/tests/ImageSharp.Tests/Colorspaces/CieXyzAndLmsConversionTest.cs index 45ca9049a..f7f341467 100644 --- a/tests/ImageSharp.Tests/Colorspaces/CieXyzAndLmsConversionTest.cs +++ b/tests/ImageSharp.Tests/Colorspaces/CieXyzAndLmsConversionTest.cs @@ -9,14 +9,14 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Colorspaces { /// - /// Tests - conversions. + /// Tests - conversions. /// /// /// Test data generated using original colorful library. /// public class CieXyzAndLmsConversionTest { - private static readonly IEqualityComparer FloatRoundingComparer = new FloatRoundingComparer(5); + private static readonly ApproximateColorSpaceComparer ColorSpaceComparer = new ApproximateColorSpaceComparer(.0001F); /// /// Tests conversion from () to . @@ -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); } /// @@ -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); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Colorspaces/ColorConverterAdaptTest.cs b/tests/ImageSharp.Tests/Colorspaces/ColorConverterAdaptTest.cs index 1cb3f56c7..d4d1956f5 100644 --- a/tests/ImageSharp.Tests/Colorspaces/ColorConverterAdaptTest.cs +++ b/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 /// public class ColorConverterAdaptTest { - private static readonly IEqualityComparer 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); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Colorspaces/ColorSpaceEqualityTests.cs b/tests/ImageSharp.Tests/Colorspaces/ColorSpaceEqualityTests.cs index b895ee9a4..466c1dca1 100644 --- a/tests/ImageSharp.Tests/Colorspaces/ColorSpaceEqualityTests.cs +++ b/tests/ImageSharp.Tests/Colorspaces/ColorSpaceEqualityTests.cs @@ -17,297 +17,158 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces /// public class ColorSpaceEqualityTests { - //internal static readonly Dictionary EmptyDataLookup = - // new Dictionary - // { - // {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 EmptyData = EmptyDataLookup.Select(x => new[] { x.Key }); - - //public static readonly TheoryData EqualityData = - // new TheoryData - // { - // { 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 NotEqualityDataNulls = - // new TheoryData - // { - // // 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 NotEqualityDataDifferentObjects = - // new TheoryData - // { - // // 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 NotEqualityData = - // new TheoryData - // { - // // 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 AlmostEqualsData = - // new TheoryData - // { - // { 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 AlmostNotEqualsData = - // new TheoryData - // { - // { 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)); + } } } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs index 8fa796c12..7c2eb8238 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs +++ b/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];