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