diff --git a/src/ImageSharp/ColorSpaces/CieLab.cs b/src/ImageSharp/ColorSpaces/CieLab.cs
index 82975d9330..230ea0bdc3 100644
--- a/src/ImageSharp/ColorSpaces/CieLab.cs
+++ b/src/ImageSharp/ColorSpaces/CieLab.cs
@@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0.
using System;
-using System.ComponentModel;
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -12,7 +11,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// Represents a CIE L*a*b* 1976 color.
///
///
- internal readonly struct CieLab : IColorVector, IEquatable, IAlmostEquatable
+ public readonly struct CieLab : IEquatable
{
///
/// D50 standard illuminant.
@@ -21,9 +20,27 @@ namespace SixLabors.ImageSharp.ColorSpaces
public static readonly CieXyz DefaultWhitePoint = Illuminants.D50;
///
- /// The backing vector for SIMD support.
+ /// Gets the lightness dimension.
+ /// A value usually ranging between 0 (black), 100 (diffuse white) or higher (specular white).
+ ///
+ public readonly float L;
+
+ ///
+ /// Gets the a color component.
+ /// A value usually ranging from -100 to 100. Negative is green, positive magenta.
+ ///
+ public readonly float A;
+
+ ///
+ /// Gets the b color component.
+ /// A value usually ranging from -100 to 100. Negative is blue, positive is yellow
+ ///
+ public readonly float B;
+
+ ///
+ /// Gets the reference white point of this color
///
- private readonly Vector3 backingVector;
+ public readonly CieXyz WhitePoint;
///
/// Initializes a new instance of the struct.
@@ -32,9 +49,9 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// The a (green - magenta) component.
/// The b (blue - yellow) component.
/// Uses as white point.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(InliningOptions.ShortMethod)]
public CieLab(float l, float a, float b)
- : this(new Vector3(l, a, b), DefaultWhitePoint)
+ : this(l, a, b, DefaultWhitePoint)
{
}
@@ -45,7 +62,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// The a (green - magenta) component.
/// The b (blue - yellow) component.
/// The reference white point.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(InliningOptions.ShortMethod)]
public CieLab(float l, float a, float b, CieXyz whitePoint)
: this(new Vector3(l, a, b), whitePoint)
{
@@ -56,7 +73,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
///
/// The vector representing the l, a, b components.
/// Uses as white point.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(InliningOptions.ShortMethod)]
public CieLab(Vector3 vector)
: this(vector, DefaultWhitePoint)
{
@@ -67,126 +84,62 @@ namespace SixLabors.ImageSharp.ColorSpaces
///
/// The vector representing the l, a, b components.
/// The reference white point.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(InliningOptions.ShortMethod)]
public CieLab(Vector3 vector, CieXyz whitePoint)
: this()
{
- this.backingVector = vector;
+ // Not clamping as documentation about this space only indicates "usual" ranges
+ this.L = vector.X;
+ this.A = vector.Y;
+ this.B = vector.Z;
this.WhitePoint = whitePoint;
}
- ///
- /// Gets the reference white point of this color
- ///
- public CieXyz WhitePoint { get; }
-
- ///
- /// Gets the lightness dimension.
- /// A value ranging between 0 (black), 100 (diffuse white) or higher (specular white).
- ///
- public float L
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => this.backingVector.X;
- }
-
- ///
- /// Gets the a color component.
- /// A value ranging from -100 to 100. Negative is green, positive magenta.
- ///
- public float A
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => this.backingVector.Y;
- }
-
- ///
- /// Gets the b color component.
- /// A value ranging from -100 to 100. Negative is blue, positive is yellow
- ///
- public float B
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => this.backingVector.Z;
- }
-
- ///
- public Vector3 Vector => this.backingVector;
-
///
/// Compares two objects for equality.
///
- ///
- /// The on the left side of the operand.
- ///
- ///
- /// The on the right side of the operand.
- ///
+ /// The on the left side of the operand.
+ /// The on the right side of the operand.
///
/// True if the current left is equal to the parameter; otherwise, false.
///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator ==(CieLab left, CieLab right)
- {
- return left.Equals(right);
- }
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public static bool operator ==(CieLab left, CieLab right) => left.Equals(right);
///
/// Compares two objects for inequality
///
- ///
- /// The on the left side of the operand.
- ///
- ///
- /// The on the right side of the operand.
- ///
+ /// The on the left side of the operand.
+ /// The on the right side of the operand.
///
/// True if the current left is unequal to the parameter; otherwise, false.
///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator !=(CieLab left, CieLab right)
- {
- return !left.Equals(right);
- }
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public static bool operator !=(CieLab left, CieLab right) => !left.Equals(right);
///
public override int GetHashCode()
{
- return HashHelpers.Combine(this.WhitePoint.GetHashCode(), this.backingVector.GetHashCode());
+ int hash = this.L.GetHashCode();
+ hash = HashHelpers.Combine(hash, this.A.GetHashCode());
+ hash = HashHelpers.Combine(hash, this.B.GetHashCode());
+ return HashHelpers.Combine(hash, this.WhitePoint.GetHashCode());
}
///
- public override string ToString()
- {
- return this.Equals(default)
- ? "CieLab [Empty]"
- : $"CieLab [ L={this.L:#0.##}, A={this.A:#0.##}, B={this.B:#0.##}]";
- }
+ public override string ToString() => $"CieLab({this.L:#0.##}, {this.A:#0.##}, {this.B:#0.##})";
///
- public override bool Equals(object obj)
- {
- return obj is CieLab other && this.Equals(other);
- }
+ public override bool Equals(object obj) => obj is CieLab other && this.Equals(other);
///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(InliningOptions.ShortMethod)]
public bool Equals(CieLab other)
{
- return this.backingVector.Equals(other.backingVector)
+ return this.L.Equals(other.L)
+ && this.A.Equals(other.A)
+ && this.B.Equals(other.B)
&& this.WhitePoint.Equals(other.WhitePoint);
}
-
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool AlmostEquals(CieLab other, float precision)
- {
- var result = Vector3.Abs(this.backingVector - other.backingVector);
-
- return this.WhitePoint.Equals(other.WhitePoint)
- && result.X <= precision
- && result.Y <= precision
- && result.Z <= precision;
- }
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/ColorSpaces/CieLch.cs b/src/ImageSharp/ColorSpaces/CieLch.cs
index 67a9956bdc..2c8f030e24 100644
--- a/src/ImageSharp/ColorSpaces/CieLch.cs
+++ b/src/ImageSharp/ColorSpaces/CieLch.cs
@@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0.
using System;
-using System.ComponentModel;
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -12,8 +11,11 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// Represents the CIE L*C*h°, cylindrical form of the CIE L*a*b* 1976 color.
///
///
- internal readonly struct CieLch : IColorVector, IEquatable, IAlmostEquatable
+ public readonly struct CieLch : IEquatable
{
+ private static readonly Vector3 Min = new Vector3(0, -200, 0);
+ private static readonly Vector3 Max = new Vector3(100, 200, 360);
+
///
/// D50 standard illuminant.
/// Used when reference white is not specified explicitly.
@@ -21,9 +23,27 @@ namespace SixLabors.ImageSharp.ColorSpaces
public static readonly CieXyz DefaultWhitePoint = Illuminants.D50;
///
- /// The backing vector for SIMD support.
+ /// Gets the lightness dimension.
+ /// A value ranging between 0 (black), 100 (diffuse white) or higher (specular white).
+ ///
+ public readonly float L;
+
+ ///
+ /// Gets the a chroma component.
+ /// A value ranging from 0 to 200.
+ ///
+ public readonly float C;
+
+ ///
+ /// Gets the h° hue component in degrees.
+ /// A value ranging from 0 to 360.
///
- private readonly Vector3 backingVector;
+ public readonly float H;
+
+ ///
+ /// Gets the reference white point of this color
+ ///
+ public readonly CieXyz WhitePoint;
///
/// Initializes a new instance of the struct.
@@ -32,9 +52,9 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// The chroma, relative saturation.
/// The hue in degrees.
/// Uses as white point.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(InliningOptions.ShortMethod)]
public CieLch(float l, float c, float h)
- : this(new Vector3(l, c, h), DefaultWhitePoint)
+ : this(l, c, h, DefaultWhitePoint)
{
}
@@ -45,7 +65,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// The chroma, relative saturation.
/// The hue in degrees.
/// The reference white point.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(InliningOptions.ShortMethod)]
public CieLch(float l, float c, float h, CieXyz whitePoint)
: this(new Vector3(l, c, h), whitePoint)
{
@@ -56,7 +76,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
///
/// The vector representing the l, c, h components.
/// Uses as white point.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(InliningOptions.ShortMethod)]
public CieLch(Vector3 vector)
: this(vector, DefaultWhitePoint)
{
@@ -67,129 +87,64 @@ namespace SixLabors.ImageSharp.ColorSpaces
///
/// The vector representing the l, c, h components.
/// The reference white point.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(InliningOptions.ShortMethod)]
public CieLch(Vector3 vector, CieXyz whitePoint)
- : this()
{
- this.backingVector = vector;
+ vector = Vector3.Clamp(vector, Min, Max);
+ this.L = vector.X;
+ this.C = vector.Y;
+ this.H = vector.Z;
this.WhitePoint = whitePoint;
}
- ///
- /// Gets the reference white point of this color
- ///
- public CieXyz WhitePoint { get; }
-
- ///
- /// Gets the lightness dimension.
- /// A value ranging between 0 (black), 100 (diffuse white) or higher (specular white).
- ///
- public float L
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => this.backingVector.X;
- }
-
- ///
- /// Gets the a chroma component.
- /// A value ranging from 0 to 100.
- ///
- public float C
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => this.backingVector.Y;
- }
-
- ///
- /// Gets the h° hue component in degrees.
- /// A value ranging from 0 to 360.
- ///
- public float H
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => this.backingVector.Z;
- }
-
- ///
- public Vector3 Vector => this.backingVector;
-
///
/// Compares two objects for equality.
///
- ///
- /// The on the left side of the operand.
- ///
- ///
- /// The on the right side of the operand.
- ///
+ /// The on the left side of the operand.
+ /// The on the right side of the operand.
///
/// True if the current left is equal to the parameter; otherwise, false.
///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator ==(CieLch left, CieLch right)
- {
- return left.Equals(right);
- }
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public static bool operator ==(CieLch left, CieLch right) => left.Equals(right);
///
/// Compares two objects for inequality
///
- ///
- /// The on the left side of the operand.
- ///
- ///
- /// The on the right side of the operand.
- ///
+ /// The on the left side of the operand.
+ /// The on the right side of the operand.
///
/// True if the current left is unequal to the parameter; otherwise, false.
///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator !=(CieLch left, CieLch right)
- {
- return !left.Equals(right);
- }
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public static bool operator !=(CieLch left, CieLch right) => !left.Equals(right);
///
public override int GetHashCode()
{
- return HashHelpers.Combine(this.WhitePoint.GetHashCode(), this.backingVector.GetHashCode());
+ int hash = this.L.GetHashCode();
+ hash = HashHelpers.Combine(hash, this.C.GetHashCode());
+ hash = HashHelpers.Combine(hash, this.H.GetHashCode());
+ return HashHelpers.Combine(hash, this.WhitePoint.GetHashCode());
}
///
- public override string ToString()
- {
- return this.Equals(default)
- ? "CieLch [Empty]"
- : $"CieLch [ L={this.L:#0.##}, C={this.C:#0.##}, H={this.H:#0.##}]";
- }
+ public override string ToString() => $"CieLch({this.L:#0.##}, {this.C:#0.##}, {this.H:#0.##})";
///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override bool Equals(object obj)
- {
- return obj is CieLch other && this.Equals(other);
- }
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public override bool Equals(object obj) => obj is CieLch other && this.Equals(other);
///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(InliningOptions.ShortMethod)]
public bool Equals(CieLch other)
{
- return this.backingVector.Equals(other.backingVector)
+ return this.L.Equals(other.L)
+ && this.C.Equals(other.C)
+ && this.H.Equals(other.H)
&& this.WhitePoint.Equals(other.WhitePoint);
}
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool AlmostEquals(CieLch other, float precision)
- {
- var result = Vector3.Abs(this.backingVector - other.backingVector);
-
- return this.WhitePoint.Equals(other.WhitePoint)
- && result.X <= precision
- && result.Y <= precision
- && result.Z <= precision;
- }
-
///
/// Computes the saturation of the color (chroma normalized by lightness)
///
@@ -197,7 +152,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// A value ranging from 0 to 100.
///
/// The
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(InliningOptions.ShortMethod)]
public float Saturation()
{
float result = 100 * (this.C / this.L);
diff --git a/src/ImageSharp/ColorSpaces/CieLchuv.cs b/src/ImageSharp/ColorSpaces/CieLchuv.cs
index 0b4c7a9036..2aaff48a09 100644
--- a/src/ImageSharp/ColorSpaces/CieLchuv.cs
+++ b/src/ImageSharp/ColorSpaces/CieLchuv.cs
@@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0.
using System;
-using System.ComponentModel;
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -10,10 +9,13 @@ namespace SixLabors.ImageSharp.ColorSpaces
{
///
/// Represents the CIE L*C*h°, cylindrical form of the CIE L*u*v* 1976 color.
- ///
+ ///
///
- internal readonly struct CieLchuv : IColorVector, IEquatable, IAlmostEquatable
+ public readonly struct CieLchuv : IEquatable
{
+ private static readonly Vector3 Min = new Vector3(0, -200, 0);
+ private static readonly Vector3 Max = new Vector3(100, 200, 360);
+
///
/// D50 standard illuminant.
/// Used when reference white is not specified explicitly.
@@ -21,9 +23,27 @@ namespace SixLabors.ImageSharp.ColorSpaces
public static readonly CieXyz DefaultWhitePoint = Illuminants.D65;
///
- /// The backing vector for SIMD support.
+ /// Gets the lightness dimension.
+ /// A value ranging between 0 (black), 100 (diffuse white) or higher (specular white).
+ ///
+ public readonly float L;
+
+ ///
+ /// Gets the a chroma component.
+ /// A value ranging from 0 to 200.
+ ///
+ public readonly float C;
+
+ ///
+ /// Gets the h° hue component in degrees.
+ /// A value ranging from 0 to 360.
///
- private readonly Vector3 backingVector;
+ public readonly float H;
+
+ ///
+ /// Gets the reference white point of this color
+ ///
+ public readonly CieXyz WhitePoint;
///
/// Initializes a new instance of the struct.
@@ -32,9 +52,9 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// The chroma, relative saturation.
/// The hue in degrees.
/// Uses as white point.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(InliningOptions.ShortMethod)]
public CieLchuv(float l, float c, float h)
- : this(new Vector3(l, c, h), DefaultWhitePoint)
+ : this(l, c, h, DefaultWhitePoint)
{
}
@@ -45,9 +65,9 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// The chroma, relative saturation.
/// The hue in degrees.
/// The reference white point.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(InliningOptions.ShortMethod)]
public CieLchuv(float l, float c, float h, CieXyz whitePoint)
- : this(new Vector3(l, c, h), whitePoint)
+ : this(new Vector3(l, c, h), whitePoint)
{
}
@@ -56,7 +76,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
///
/// The vector representing the l, c, h components.
/// Uses as white point.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(InliningOptions.ShortMethod)]
public CieLchuv(Vector3 vector)
: this(vector, DefaultWhitePoint)
{
@@ -67,127 +87,62 @@ namespace SixLabors.ImageSharp.ColorSpaces
///
/// The vector representing the l, c, h components.
/// The reference white point.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(InliningOptions.ShortMethod)]
public CieLchuv(Vector3 vector, CieXyz whitePoint)
: this()
{
- this.backingVector = vector;
+ vector = Vector3.Clamp(vector, Min, Max);
+ this.L = vector.X;
+ this.C = vector.Y;
+ this.H = vector.Z;
this.WhitePoint = whitePoint;
}
- ///
- /// Gets the reference white point of this color
- ///
- public CieXyz WhitePoint { get; }
-
- ///
- /// Gets the lightness dimension.
- /// A value ranging between 0 (black), 100 (diffuse white) or higher (specular white).
- ///
- public float L
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => this.backingVector.X;
- }
-
- ///
- /// Gets the a chroma component.
- /// A value ranging from 0 to 100.
- ///
- public float C
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => this.backingVector.Y;
- }
-
- ///
- /// Gets the h° hue component in degrees.
- /// A value ranging from 0 to 360.
- ///
- public float H
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => this.backingVector.Z;
- }
-
- ///
- public Vector3 Vector => this.backingVector;
-
///
/// Compares two objects for equality.
///
- ///
- /// The on the left side of the operand.
- ///
- ///
- /// The on the right side of the operand.
- ///
+ /// The on the left side of the operand.
+ /// The on the right side of the operand.
///
/// True if the current left is equal to the parameter; otherwise, false.
///
- public static bool operator ==(CieLchuv left, CieLchuv right)
- {
- return left.Equals(right);
- }
+ public static bool operator ==(CieLchuv left, CieLchuv right) => left.Equals(right);
///
/// Compares two objects for inequality
///
- ///
- /// The on the left side of the operand.
- ///
- ///
- /// The on the right side of the operand.
- ///
+ /// The on the left side of the operand.
+ /// The on the right side of the operand.
///
/// True if the current left is unequal to the parameter; otherwise, false.
///
- public static bool operator !=(CieLchuv left, CieLchuv right)
- {
- return !left.Equals(right);
- }
+ public static bool operator !=(CieLchuv left, CieLchuv right) => !left.Equals(right);
///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
public override int GetHashCode()
{
- return HashHelpers.Combine(this.WhitePoint.GetHashCode(), this.backingVector.GetHashCode());
+ int hash = this.L.GetHashCode();
+ hash = HashHelpers.Combine(hash, this.C.GetHashCode());
+ hash = HashHelpers.Combine(hash, this.H.GetHashCode());
+ return HashHelpers.Combine(hash, this.WhitePoint.GetHashCode());
}
///
- public override string ToString()
- {
- return this.Equals(default)
- ? "CieLchuv [Empty]"
- : $"CieLchuv [ L={this.L:#0.##}, C={this.C:#0.##}, H={this.H:#0.##}";
- }
+ public override string ToString() => $"CieLchuv({this.L:#0.##}, {this.C:#0.##}, {this.H:#0.##})";
///
- public override bool Equals(object obj)
- {
- return obj is CieLchuv other && this.Equals(other);
- }
+ public override bool Equals(object obj) => obj is CieLchuv other && this.Equals(other);
///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(InliningOptions.ShortMethod)]
public bool Equals(CieLchuv other)
{
- return this.backingVector.Equals(other.backingVector)
+ return this.L.Equals(other.L)
+ && this.C.Equals(other.C)
+ && this.H.Equals(other.H)
&& this.WhitePoint.Equals(other.WhitePoint);
}
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool AlmostEquals(CieLchuv other, float precision)
- {
- var result = Vector3.Abs(this.backingVector - other.backingVector);
-
- return this.WhitePoint.Equals(other.WhitePoint)
- && result.X <= precision
- && result.Y <= precision
- && result.Z <= precision;
- }
-
///
/// Computes the saturation of the color (chroma normalized by lightness)
///
@@ -195,7 +150,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// A value ranging from 0 to 100.
///
/// The
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(InliningOptions.ShortMethod)]
public float Saturation()
{
float result = 100 * (this.C / this.L);
diff --git a/src/ImageSharp/ColorSpaces/CieLuv.cs b/src/ImageSharp/ColorSpaces/CieLuv.cs
index dbc3b6dee5..9aac268e1c 100644
--- a/src/ImageSharp/ColorSpaces/CieLuv.cs
+++ b/src/ImageSharp/ColorSpaces/CieLuv.cs
@@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0.
using System;
-using System.ComponentModel;
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -14,7 +13,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// attempted perceptual uniformity
///
///
- internal readonly struct CieLuv : IColorVector, IEquatable, IAlmostEquatable
+ public readonly struct CieLuv : IEquatable
{
///
/// D65 standard illuminant.
@@ -23,9 +22,27 @@ namespace SixLabors.ImageSharp.ColorSpaces
public static readonly CieXyz DefaultWhitePoint = Illuminants.D65;
///
- /// The backing vector for SIMD support.
+ /// Gets the lightness dimension
+ /// A value usually ranging between 0 and 100.
+ ///
+ public readonly float L;
+
+ ///
+ /// Gets the blue-yellow chromaticity coordinate of the given whitepoint.
+ /// A value usually ranging between -100 and 100.
+ ///
+ public readonly float U;
+
+ ///
+ /// Gets the red-green chromaticity coordinate of the given whitepoint.
+ /// A value usually ranging between -100 and 100.
+ ///
+ public readonly float V;
+
+ ///
+ /// Gets the reference white point of this color
///
- private readonly Vector3 backingVector;
+ public readonly CieXyz WhitePoint;
///
/// Initializes a new instance of the struct.
@@ -34,9 +51,9 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// The blue-yellow chromaticity coordinate of the given whitepoint.
/// The red-green chromaticity coordinate of the given whitepoint.
/// Uses as white point.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(InliningOptions.ShortMethod)]
public CieLuv(float l, float u, float v)
- : this(new Vector3(l, u, v), DefaultWhitePoint)
+ : this(l, u, v, DefaultWhitePoint)
{
}
@@ -47,7 +64,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// The blue-yellow chromaticity coordinate of the given whitepoint.
/// The red-green chromaticity coordinate of the given whitepoint.
/// The reference white point.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(InliningOptions.ShortMethod)]
public CieLuv(float l, float u, float v, CieXyz whitePoint)
: this(new Vector3(l, u, v), whitePoint)
{
@@ -58,7 +75,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
///
/// The vector representing the l, u, v components.
/// Uses as white point.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(InliningOptions.ShortMethod)]
public CieLuv(Vector3 vector)
: this(vector, DefaultWhitePoint)
{
@@ -69,126 +86,61 @@ namespace SixLabors.ImageSharp.ColorSpaces
///
/// The vector representing the l, u, v components.
/// The reference white point.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(InliningOptions.ShortMethod)]
public CieLuv(Vector3 vector, CieXyz whitePoint)
- : this()
{
- this.backingVector = vector;
+ // Not clamping as documentation about this space only indicates "usual" ranges
+ this.L = vector.X;
+ this.U = vector.Y;
+ this.V = vector.Z;
this.WhitePoint = whitePoint;
}
- ///
- /// Gets the reference white point of this color
- ///
- public CieXyz WhitePoint { get; }
-
- ///
- /// Gets the lightness dimension
- /// A value usually ranging between 0 and 100.
- ///
- public float L
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => this.backingVector.X;
- }
-
- ///
- /// Gets the blue-yellow chromaticity coordinate of the given whitepoint.
- /// A value usually ranging between -100 and 100.
- ///
- public float U
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => this.backingVector.Y;
- }
-
- ///
- /// Gets the red-green chromaticity coordinate of the given whitepoint.
- /// A value usually ranging between -100 and 100.
- ///
- public float V
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => this.backingVector.Z;
- }
-
- ///
- public Vector3 Vector => this.backingVector;
-
///
/// Compares two objects for equality.
///
- ///
- /// The on the left side of the operand.
- ///
- ///
- /// The on the right side of the operand.
- ///
+ /// The on the left side of the operand.
+ /// The on the right side of the operand.
///
/// True if the current left is equal to the parameter; otherwise, false.
///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator ==(CieLuv left, CieLuv right)
- {
- return left.Equals(right);
- }
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public static bool operator ==(CieLuv left, CieLuv right) => left.Equals(right);
///
/// Compares two objects for inequality.
///
- ///
- /// The on the left side of the operand.
- ///
- ///
- /// The on the right side of the operand.
- ///
+ /// The on the left side of the operand.
+ /// The on the right side of the operand.
///
/// True if the current left is unequal to the parameter; otherwise, false.
///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator !=(CieLuv left, CieLuv right)
- {
- return !left.Equals(right);
- }
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public static bool operator !=(CieLuv left, CieLuv right) => !left.Equals(right);
///
public override int GetHashCode()
{
- return HashHelpers.Combine(this.WhitePoint.GetHashCode(), this.backingVector.GetHashCode());
+ int hash = this.L.GetHashCode();
+ hash = HashHelpers.Combine(hash, this.U.GetHashCode());
+ hash = HashHelpers.Combine(hash, this.V.GetHashCode());
+ return HashHelpers.Combine(hash, this.WhitePoint.GetHashCode());
}
///
- public override string ToString()
- {
- return this.Equals(default)
- ? "CieLuv [ Empty ]"
- : $"CieLuv [ L={this.L:#0.##}, U={this.U:#0.##}, V={this.V:#0.##} ]";
- }
+ public override string ToString() => $"CieLuv({this.L:#0.##}, {this.U:#0.##}, {this.V:#0.##})";
///
- public override bool Equals(object obj)
- {
- return obj is CieLuv other && this.Equals(other);
- }
+ public override bool Equals(object obj) => obj is CieLuv other && this.Equals(other);
///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(InliningOptions.ShortMethod)]
public bool Equals(CieLuv other)
{
- return this.backingVector.Equals(other.backingVector)
- && this.WhitePoint.Equals(other.WhitePoint);
- }
-
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool AlmostEquals(CieLuv other, float precision)
- {
- var result = Vector3.Abs(this.backingVector - other.backingVector);
-
- return this.WhitePoint.Equals(other.WhitePoint)
- && result.X <= precision
- && result.Y <= precision
- && result.Z <= precision;
+ return this.L.Equals(other.L)
+ && this.U.Equals(other.U)
+ && this.V.Equals(other.V)
+ && this.WhitePoint.Equals(other.WhitePoint);
}
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs b/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs
index 4f4f951472..06aaafb553 100644
--- a/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs
+++ b/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs
@@ -2,8 +2,6 @@
// Licensed under the Apache License, Version 2.0.
using System;
-using System.ComponentModel;
-using System.Numerics;
using System.Runtime.CompilerServices;
// ReSharper disable CompareOfFloatsByEqualityOperator
@@ -12,45 +10,15 @@ namespace SixLabors.ImageSharp.ColorSpaces
///
/// Represents the coordinates of CIEXY chromaticity space
///
- internal readonly struct CieXyChromaticityCoordinates : IEquatable, IAlmostEquatable
+ public readonly struct CieXyChromaticityCoordinates : IEquatable
{
- ///
- /// The backing vector for SIMD support.
- ///
- private readonly Vector2 backingVector;
-
- ///
- /// Initializes a new instance of the struct.
- ///
- /// Chromaticity coordinate x (usually from 0 to 1)
- /// Chromaticity coordinate y (usually from 0 to 1)
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public CieXyChromaticityCoordinates(float x, float y)
- : this(new Vector2(x, y))
- {
- }
-
- ///
- /// Initializes a new instance of the struct.
- ///
- /// The vector containing the XY Chromaticity coordinates
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public CieXyChromaticityCoordinates(Vector2 vector)
- {
- this.backingVector = vector;
- }
-
///
/// Gets the chromaticity X-coordinate.
///
///
/// Ranges usually from 0 to 1.
///
- public float X
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => this.backingVector.X;
- }
+ public readonly float X;
///
/// Gets the chromaticity Y-coordinate
@@ -58,85 +26,54 @@ namespace SixLabors.ImageSharp.ColorSpaces
///
/// Ranges usually from 0 to 1.
///
- public float Y
+ public readonly float Y;
+
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ /// Chromaticity coordinate x (usually from 0 to 1)
+ /// Chromaticity coordinate y (usually from 0 to 1)
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public CieXyChromaticityCoordinates(float x, float y)
{
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => this.backingVector.Y;
+ this.X = x;
+ this.Y = y;
}
///
/// Compares two objects for equality.
///
- ///
- /// The on the left side of the operand.
- ///
- ///
- /// The on the right side of the operand.
- ///
+ /// The on the left side of the operand.
+ /// The on the right side of the operand.
///
/// True if the current left is equal to the parameter; otherwise, false.
///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator ==(CieXyChromaticityCoordinates left, CieXyChromaticityCoordinates right)
- {
- return left.Equals(right);
- }
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public static bool operator ==(CieXyChromaticityCoordinates left, CieXyChromaticityCoordinates right) => left.Equals(right);
///
/// Compares two objects for inequality
///
- ///
- /// The on the left side of the operand.
- ///
- ///
- /// The on the right side of the operand.
- ///
+ /// The on the left side of the operand.
+ /// The on the right side of the operand.
///
/// True if the current left is unequal to the parameter; otherwise, false.
///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator !=(CieXyChromaticityCoordinates left, CieXyChromaticityCoordinates right)
- {
- return !left.Equals(right);
- }
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public static bool operator !=(CieXyChromaticityCoordinates left, CieXyChromaticityCoordinates right) => !left.Equals(right);
///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override int GetHashCode()
- {
- return this.backingVector.GetHashCode();
- }
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public override int GetHashCode() => HashHelpers.Combine(this.X.GetHashCode(), this.Y.GetHashCode());
///
- public override string ToString()
- {
- return this.Equals(default)
- ? "CieXyChromaticityCoordinates [Empty]"
- : $"CieXyChromaticityCoordinates [ X={this.X:#0.##}, Y={this.Y:#0.##}]";
- }
+ public override string ToString() => $"CieXyChromaticityCoordinates({this.X:#0.##}, {this.Y:#0.##})";
///
- public override bool Equals(object obj)
- {
- return obj is CieXyChromaticityCoordinates other && this.Equals(other);
- }
+ public override bool Equals(object obj) => obj is CieXyChromaticityCoordinates other && this.Equals(other);
///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool Equals(CieXyChromaticityCoordinates other)
- {
- // The memberwise comparison here is a workaround for https://github.com/dotnet/coreclr/issues/16443
- return this.X == other.X && this.Y == other.Y;
- }
-
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool AlmostEquals(CieXyChromaticityCoordinates other, float precision)
- {
- var result = Vector2.Abs(this.backingVector - other.backingVector);
-
- return result.X <= precision
- && result.Y <= precision;
- }
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public bool Equals(CieXyChromaticityCoordinates other) => this.X.Equals(other.X) && this.Y.Equals(other.Y);
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/ColorSpaces/CieXyy.cs b/src/ImageSharp/ColorSpaces/CieXyy.cs
index ac1a4532c5..44696a9dba 100644
--- a/src/ImageSharp/ColorSpaces/CieXyy.cs
+++ b/src/ImageSharp/ColorSpaces/CieXyy.cs
@@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0.
using System;
-using System.ComponentModel;
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -12,12 +11,25 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// Represents an CIE xyY 1931 color
///
///
- internal readonly struct CieXyy : IColorVector, IEquatable, IAlmostEquatable
+ public readonly struct CieXyy : IEquatable
{
///
- /// The backing vector for SIMD support.
+ /// Gets the X chrominance component.
+ /// A value usually ranging between 0 and 1.
+ ///
+ public readonly float X;
+
+ ///
+ /// Gets the Y chrominance component.
+ /// A value usually ranging between 0 and 1.
+ ///
+ public readonly float Y;
+
+ ///
+ /// Gets the Y luminance component.
+ /// A value usually ranging between 0 and 1.
///
- private readonly Vector3 backingVector;
+ public readonly float Yl;
///
/// Initializes a new instance of the struct.
@@ -25,130 +37,72 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// The x chroma component.
/// The y chroma component.
/// The y luminance component.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(InliningOptions.ShortMethod)]
public CieXyy(float x, float y, float yl)
- : this(new Vector3(x, y, yl))
{
+ // Not clamping as documentation about this space only indicates "usual" ranges
+ this.X = x;
+ this.Y = y;
+ this.Yl = yl;
}
///
/// Initializes a new instance of the struct.
///
/// The vector representing the x, y, Y components.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(InliningOptions.ShortMethod)]
public CieXyy(Vector3 vector)
: this()
{
- // Not clamping as documentation about this space seems to indicate "usual" ranges
- this.backingVector = vector;
+ // Not clamping as documentation about this space only indicates "usual" ranges
+ this.X = vector.X;
+ this.Y = vector.Y;
+ this.Yl = vector.Z;
}
- ///
- /// Gets the X chrominance component.
- /// A value usually ranging between 0 and 1.
- ///
- public float X
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => this.backingVector.X;
- }
-
- ///
- /// Gets the Y chrominance component.
- /// A value usually ranging between 0 and 1.
- ///
- public float Y
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => this.backingVector.Y;
- }
-
- ///
- /// Gets the Y luminance component.
- /// A value usually ranging between 0 and 1.
- ///
- public float Yl
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => this.backingVector.Z;
- }
-
- ///
- public Vector3 Vector => this.backingVector;
-
///
/// Compares two objects for equality.
///
- ///
- /// The on the left side of the operand.
- ///
- ///
- /// The on the right side of the operand.
- ///
+ /// The on the left side of the operand.
+ /// The on the right side of the operand.
///
/// True if the current left is equal to the parameter; otherwise, false.
///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator ==(CieXyy left, CieXyy right)
- {
- return left.Equals(right);
- }
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public static bool operator ==(CieXyy left, CieXyy right) => left.Equals(right);
///
/// Compares two objects for inequality.
///
- ///
- /// The on the left side of the operand.
- ///
- ///
- /// The on the right side of the operand.
- ///
+ /// The on the left side of the operand.
+ /// The on the right side of the operand.
///
/// True if the current left is unequal to the parameter; otherwise, false.
///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator !=(CieXyy left, CieXyy right)
- {
- return !left.Equals(right);
- }
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public static bool operator !=(CieXyy left, CieXyy right) => !left.Equals(right);
///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
public override int GetHashCode()
{
- return this.backingVector.GetHashCode();
+ int hash = this.X.GetHashCode();
+ hash = HashHelpers.Combine(hash, this.Y.GetHashCode());
+ return HashHelpers.Combine(hash, this.Yl.GetHashCode());
}
///
- public override string ToString()
- {
- return this.Equals(default)
- ? "CieXyy [ Empty ]"
- : $"CieXyy [ X={this.X:#0.##}, Y={this.Y:#0.##}, Yl={this.Yl:#0.##} ]";
- }
+ public override string ToString() => $"CieXyy({this.X:#0.##}, {this.Y:#0.##}, {this.Yl:#0.##})";
///
- public override bool Equals(object obj)
- {
- return obj is CieXyy other && this.Equals(other);
- }
+ public override bool Equals(object obj) => obj is CieXyy other && this.Equals(other);
///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(InliningOptions.ShortMethod)]
public bool Equals(CieXyy other)
{
- return this.backingVector.Equals(other.backingVector);
- }
-
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool AlmostEquals(CieXyy other, float precision)
- {
- var result = Vector3.Abs(this.backingVector - other.backingVector);
-
- return result.X <= precision
- && result.Y <= precision
- && result.Z <= precision;
+ return this.X.Equals(other.X)
+ && this.Y.Equals(other.Y)
+ && this.Yl.Equals(other.Yl);
}
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/ColorSpaces/CieXyz.cs b/src/ImageSharp/ColorSpaces/CieXyz.cs
index fa4261b46d..4fed9f4eda 100644
--- a/src/ImageSharp/ColorSpaces/CieXyz.cs
+++ b/src/ImageSharp/ColorSpaces/CieXyz.cs
@@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0.
using System;
-using System.ComponentModel;
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -12,12 +11,25 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// Represents an CIE XYZ 1931 color
///
///
- internal readonly struct CieXyz : IColorVector, IEquatable, IAlmostEquatable
+ public readonly struct CieXyz : IEquatable
{
///
- /// The backing vector for SIMD support.
+ /// Gets the X component. A mix (a linear combination) of cone response curves chosen to be nonnegative.
+ /// A value usually ranging between 0 and 1.
+ ///
+ public readonly float X;
+
+ ///
+ /// Gets the Y luminance component.
+ /// A value usually ranging between 0 and 1.
///
- private readonly Vector3 backingVector;
+ public readonly float Y;
+
+ ///
+ /// Gets the Z component. Quasi-equal to blue stimulation, or the S cone response
+ /// A value usually ranging between 0 and 1.
+ ///
+ public readonly float Z;
///
/// Initializes a new instance of the struct.
@@ -25,7 +37,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// X is a mix (a linear combination) of cone response curves chosen to be nonnegative
/// The y luminance component.
/// Z is quasi-equal to blue stimulation, or the S cone of the human eye.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(InliningOptions.ShortMethod)]
public CieXyz(float x, float y, float z)
: this(new Vector3(x, y, z))
{
@@ -38,116 +50,62 @@ namespace SixLabors.ImageSharp.ColorSpaces
public CieXyz(Vector3 vector)
: this()
{
- // Not clamping as documentation about this space seems to indicate "usual" ranges
- this.backingVector = vector;
- }
-
- ///
- /// Gets the X component. A mix (a linear combination) of cone response curves chosen to be nonnegative.
- /// A value usually ranging between 0 and 1.
- ///
- public float X
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => this.backingVector.X;
- }
-
- ///
- /// Gets the Y luminance component.
- /// A value usually ranging between 0 and 1.
- ///
- public float Y
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => this.backingVector.Y;
+ // Not clamping as documentation about this space only indicates "usual" ranges
+ this.X = vector.X;
+ this.Y = vector.Y;
+ this.Z = vector.Z;
}
- ///
- /// Gets the Z component. Quasi-equal to blue stimulation, or the S cone response
- /// A value usually ranging between 0 and 1.
- ///
- public float Z
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => this.backingVector.Z;
- }
-
- ///
- public Vector3 Vector => this.backingVector;
-
///
/// Compares two objects for equality.
///
- ///
- /// The on the left side of the operand.
- ///
- ///
- /// The on the right side of the operand.
- ///
+ /// The on the left side of the operand.
+ /// The on the right side of the operand.
///
/// True if the current left is equal to the parameter; otherwise, false.
///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator ==(CieXyz left, CieXyz right)
- {
- return left.Equals(right);
- }
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public static bool operator ==(CieXyz left, CieXyz right) => left.Equals(right);
///
/// Compares two objects for inequality.
///
- ///
- /// The on the left side of the operand.
- ///
- ///
- /// The on the right side of the operand.
- ///
+ /// The on the left side of the operand.
+ /// The on the right side of the operand.
///
/// True if the current left is unequal to the parameter; otherwise, false.
///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator !=(CieXyz left, CieXyz right)
- {
- return !left.Equals(right);
- }
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public static bool operator !=(CieXyz left, CieXyz right) => !left.Equals(right);
+
+ ///
+ /// Returns a new representing this instance.
+ ///
+ /// The .
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public Vector3 ToVector3() => new Vector3(this.X, this.Y, this.Z);
///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
public override int GetHashCode()
{
- return this.backingVector.GetHashCode();
+ int hash = this.X.GetHashCode();
+ hash = HashHelpers.Combine(hash, this.Y.GetHashCode());
+ return HashHelpers.Combine(hash, this.Z.GetHashCode());
}
///
- public override string ToString()
- {
- return this.Equals(default)
- ? "CieXyz [ Empty ]"
- : $"CieXyz [ X={this.X:#0.##}, Y={this.Y:#0.##}, Z={this.Z:#0.##} ]";
- }
+ public override string ToString() => $"CieXyz({this.X:#0.##}, {this.Y:#0.##}, {this.Z:#0.##})";
///
- public override bool Equals(object obj)
- {
- return obj is CieXyz other && this.Equals(other);
- }
+ public override bool Equals(object obj) => obj is CieXyz other && this.Equals(other);
///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(InliningOptions.ShortMethod)]
public bool Equals(CieXyz other)
{
- return this.backingVector.Equals(other.backingVector);
- }
-
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool AlmostEquals(CieXyz other, float precision)
- {
- var result = Vector3.Abs(this.backingVector - other.backingVector);
-
- return result.X <= precision
- && result.Y <= precision
- && result.Z <= precision;
+ return this.X.Equals(other.X)
+ && this.Y.Equals(other.Y)
+ && this.Z.Equals(other.Z);
}
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/ColorSpaces/Cmyk.cs b/src/ImageSharp/ColorSpaces/Cmyk.cs
index 2702d4ba33..1d64e19951 100644
--- a/src/ImageSharp/ColorSpaces/Cmyk.cs
+++ b/src/ImageSharp/ColorSpaces/Cmyk.cs
@@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0.
using System;
-using System.ComponentModel;
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -11,151 +10,108 @@ namespace SixLabors.ImageSharp.ColorSpaces
///
/// Represents an CMYK (cyan, magenta, yellow, keyline) color.
///
- internal readonly struct Cmyk : IEquatable, IAlmostEquatable
+ public readonly struct Cmyk : IEquatable
{
- ///
- /// The backing vector for SIMD support.
- ///
- private readonly Vector4 backingVector;
+ private static readonly Vector4 Min = Vector4.Zero;
+ private static readonly Vector4 Max = Vector4.One;
///
- /// Initializes a new instance of the struct.
+ /// Gets the cyan color component.
+ /// A value ranging between 0 and 1.
///
- /// The cyan component.
- /// The magenta component.
- /// The yellow component.
- /// The keyline black component.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public Cmyk(float c, float m, float y, float k)
- : this(new Vector4(c, m, y, k))
- {
- }
+ public readonly float C;
///
- /// Initializes a new instance of the struct.
+ /// Gets the magenta color component.
+ /// A value ranging between 0 and 1.
///
- /// The vector representing the c, m, y, k components.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public Cmyk(Vector4 vector)
- : this()
- {
- this.backingVector = Vector4.Clamp(vector, Vector4.Zero, Vector4.One);
- }
+ public readonly float M;
///
- /// Gets the cyan color component.
+ /// Gets the yellow color component.
/// A value ranging between 0 and 1.
///
- public float C
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => this.backingVector.X;
- }
+ public readonly float Y;
///
- /// Gets the magenta color component.
+ /// Gets the keyline black color component.
/// A value ranging between 0 and 1.
///
- public float M
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => this.backingVector.Y;
- }
+ public readonly float K;
///
- /// Gets the yellow color component.
- /// A value ranging between 0 and 1.
+ /// Initializes a new instance of the struct.
///
- public float Y
+ /// The cyan component.
+ /// The magenta component.
+ /// The yellow component.
+ /// The keyline black component.
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public Cmyk(float c, float m, float y, float k)
+ : this(new Vector4(c, m, y, k))
{
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => this.backingVector.Z;
}
///
- /// Gets the keyline black color component.
- /// A value ranging between 0 and 1.
+ /// Initializes a new instance of the struct.
///
- public float K
+ /// The vector representing the c, m, y, k components.
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public Cmyk(Vector4 vector)
{
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => this.backingVector.W;
+ vector = Vector4.Clamp(vector, Min, Max);
+ this.C = vector.X;
+ this.M = vector.Y;
+ this.Y = vector.Z;
+ this.K = vector.W;
}
///
/// Compares two objects for equality.
///
- ///
- /// The on the left side of the operand.
- ///
- ///
- /// The on the right side of the operand.
- ///
+ /// The on the left side of the operand.
+ /// The on the right side of the operand.
///
/// True if the current left is equal to the parameter; otherwise, false.
///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator ==(Cmyk left, Cmyk right)
- {
- return left.Equals(right);
- }
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public static bool operator ==(Cmyk left, Cmyk right) => left.Equals(right);
///
/// Compares two objects for inequality
///
- ///
- /// The on the left side of the operand.
- ///
- ///
- /// The on the right side of the operand.
- ///
+ /// The on the left side of the operand.
+ /// The on the right side of the operand.
///
/// True if the current left is unequal to the parameter; otherwise, false.
///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator !=(Cmyk left, Cmyk right)
- {
- return !left.Equals(right);
- }
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public static bool operator !=(Cmyk left, Cmyk right) => !left.Equals(right);
///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(InliningOptions.ShortMethod)]
public override int GetHashCode()
{
- return this.backingVector.GetHashCode();
+ int hash = this.C.GetHashCode();
+ hash = HashHelpers.Combine(hash, this.M.GetHashCode());
+ hash = HashHelpers.Combine(hash, this.Y.GetHashCode());
+ return HashHelpers.Combine(hash, this.K.GetHashCode());
}
///
- public override string ToString()
- {
- return this.Equals(default)
- ? "Cmyk [Empty]"
- : $"Cmyk [ C={this.C:#0.##}, M={this.M:#0.##}, Y={this.Y:#0.##}, K={this.K:#0.##}]";
- }
+ public override string ToString() => $"Cmyk({this.C:#0.##}, {this.M:#0.##}, {this.Y:#0.##}, {this.K:#0.##})";
///
- public override bool Equals(object obj)
- {
- return obj is Cmyk other && this.Equals(other);
- }
+ public override bool Equals(object obj) => obj is Cmyk other && this.Equals(other);
///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(InliningOptions.ShortMethod)]
public bool Equals(Cmyk other)
{
- return this.backingVector.Equals(other.backingVector);
- }
-
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool AlmostEquals(Cmyk other, float precision)
- {
- var result = Vector4.Abs(this.backingVector - other.backingVector);
-
- return result.X <= precision
- && result.Y <= precision
- && result.Z <= precision
- && result.W <= precision;
+ return this.C.Equals(other.C)
+ && this.M.Equals(other.M)
+ && this.Y.Equals(other.Y)
+ && this.K.Equals(other.K);
}
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Adapt.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Adapt.cs
index e2c1308fa8..892c0d5e38 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Adapt.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Adapt.cs
@@ -1,151 +1,130 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
-using System;
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce;
+using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Performs chromatic adaptation on the various color spaces.
///
- internal partial class ColorSpaceConverter
+ public partial class ColorSpaceConverter
{
///
/// Performs chromatic adaptation of given color.
- /// Target white point is .
+ /// Target white point is .
///
/// The color to adapt
- /// The white point to adapt for
+ /// The source white point.
/// The adapted color
- public CieXyz Adapt(in CieXyz color, in CieXyz sourceWhitePoint)
+ public CieXyz Adapt(in CieXyz color, in CieXyz sourceWhitePoint) => this.Adapt(color, sourceWhitePoint, this.whitePoint);
+
+ ///
+ /// Performs chromatic adaptation of given color.
+ /// Target white point is .
+ ///
+ /// The color to adapt
+ /// The source white point.
+ /// The target white point.
+ /// The adapted color
+ public CieXyz Adapt(in CieXyz color, in CieXyz sourceWhitePoint, in CieXyz targetWhitePoint)
{
- if (!this.IsChromaticAdaptationPerformed)
+ if (!this.performChromaticAdaptation || sourceWhitePoint.Equals(targetWhitePoint))
{
- throw new InvalidOperationException("Cannot perform chromatic adaptation, provide a chromatic adaptation method and white point.");
+ return color;
}
- return this.ChromaticAdaptation.Transform(color, sourceWhitePoint, this.WhitePoint);
+ return this.chromaticAdaptation.Transform(color, sourceWhitePoint, targetWhitePoint);
}
///
- /// Adapts color from the source white point to white point set in .
+ /// Adapts color from the source white point to white point set in .
///
/// The color to adapt
/// The adapted color
public CieLab Adapt(in CieLab color)
{
- if (!this.IsChromaticAdaptationPerformed)
- {
- throw new InvalidOperationException("Cannot perform chromatic adaptation, provide a chromatic adaptation method and white point.");
- }
-
- if (color.WhitePoint.Equals(this.TargetLabWhitePoint))
+ if (!this.performChromaticAdaptation || color.WhitePoint.Equals(this.targetLabWhitePoint))
{
return color;
}
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
return this.ToCieLab(xyzColor);
}
///
- /// Adapts color from the source white point to white point set in .
+ /// Adapts color from the source white point to white point set in .
///
/// The color to adapt
/// The adapted color
public CieLch Adapt(in CieLch color)
{
- if (!this.IsChromaticAdaptationPerformed)
- {
- throw new InvalidOperationException("Cannot perform chromatic adaptation, provide a chromatic adaptation method and white point.");
- }
-
- if (color.WhitePoint.Equals(this.TargetLabWhitePoint))
+ if (!this.performChromaticAdaptation || color.WhitePoint.Equals(this.targetLabWhitePoint))
{
return color;
}
- CieLab labColor = this.ToCieLab(color);
+ var labColor = this.ToCieLab(color);
return this.ToCieLch(labColor);
}
///
- /// Adapts color from the source white point to white point set in .
+ /// Adapts color from the source white point to white point set in .
///
/// The color to adapt
/// The adapted color
public CieLchuv Adapt(in CieLchuv color)
{
- if (!this.IsChromaticAdaptationPerformed)
- {
- throw new InvalidOperationException("Cannot perform chromatic adaptation, provide a chromatic adaptation method and white point.");
- }
-
- if (color.WhitePoint.Equals(this.TargetLabWhitePoint))
+ if (!this.performChromaticAdaptation || color.WhitePoint.Equals(this.targetLabWhitePoint))
{
return color;
}
- CieLuv luvColor = this.ToCieLuv(color);
+ var luvColor = this.ToCieLuv(color);
return this.ToCieLchuv(luvColor);
}
///
- /// Adapts color from the source white point to white point set in .
+ /// Adapts color from the source white point to white point set in .
///
/// The color to adapt
/// The adapted color
public CieLuv Adapt(in CieLuv color)
{
- if (!this.IsChromaticAdaptationPerformed)
- {
- throw new InvalidOperationException("Cannot perform chromatic adaptation, provide a chromatic adaptation method and white point.");
- }
-
- if (color.WhitePoint.Equals(this.TargetLuvWhitePoint))
+ if (!this.performChromaticAdaptation || color.WhitePoint.Equals(this.targetLuvWhitePoint))
{
return color;
}
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
return this.ToCieLuv(xyzColor);
}
///
- /// Adapts color from the source white point to white point set in .
+ /// Adapts color from the source white point to white point set in .
///
/// The color to adapt
/// The adapted color
public HunterLab Adapt(in HunterLab color)
{
- if (!this.IsChromaticAdaptationPerformed)
- {
- throw new InvalidOperationException("Cannot perform chromatic adaptation, provide a chromatic adaptation method and white point.");
- }
-
- if (color.WhitePoint.Equals(this.TargetHunterLabWhitePoint))
+ if (!this.performChromaticAdaptation || color.WhitePoint.Equals(this.targetHunterLabWhitePoint))
{
return color;
}
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
return this.ToHunterLab(xyzColor);
}
///
- /// Adapts a color from the source working space to working space set in .
+ /// Adapts a color from the source working space to working space set in .
///
/// The color to adapt
/// The adapted color
public LinearRgb Adapt(in LinearRgb color)
{
- if (!this.IsChromaticAdaptationPerformed)
- {
- throw new InvalidOperationException("Cannot perform chromatic adaptation, provide a chromatic adaptation method and white point.");
- }
-
- if (color.WorkingSpace.Equals(this.TargetRgbWorkingSpace))
+ if (!this.performChromaticAdaptation || color.WorkingSpace.Equals(this.targetRgbWorkingSpace))
{
return color;
}
@@ -155,21 +134,25 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
CieXyz unadapted = converterToXYZ.Convert(color);
// Adaptation
- CieXyz adapted = this.ChromaticAdaptation.Transform(unadapted, color.WorkingSpace.WhitePoint, this.TargetRgbWorkingSpace.WhitePoint);
+ CieXyz adapted = this.chromaticAdaptation.Transform(unadapted, color.WorkingSpace.WhitePoint, this.targetRgbWorkingSpace.WhitePoint);
// Conversion back to RGB
- CieXyzToLinearRgbConverter converterToRGB = this.GetCieXyxToLinearRgbConverter(this.TargetRgbWorkingSpace);
- return converterToRGB.Convert(adapted);
+ return this.cieXyzToLinearRgbConverter.Convert(adapted);
}
///
- /// Adapts an color from the source working space to working space set in .
+ /// Adapts an color from the source working space to working space set in .
///
/// The color to adapt
/// The adapted color
public Rgb Adapt(in Rgb color)
{
- LinearRgb linearInput = this.ToLinearRgb(color);
+ if (!this.performChromaticAdaptation)
+ {
+ return color;
+ }
+
+ var linearInput = this.ToLinearRgb(color);
LinearRgb linearOutput = this.Adapt(linearInput);
return this.ToRgb(linearOutput);
}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs
index 1cead3001f..3ce14cdea4 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs
@@ -1,15 +1,17 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLabColorSapce;
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLchColorSapce;
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Allows conversion to .
///
- internal partial class ColorSpaceConverter
+ public partial class ColorSpaceConverter
{
///
/// The converter for converting between CieLch to CieLab.
@@ -26,15 +28,31 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
// Conversion (perserving white point)
CieLab unadapted = CieLchToCieLabConverter.Convert(color);
- if (!this.IsChromaticAdaptationPerformed)
- {
- return unadapted;
- }
-
// Adaptation
return this.Adapt(unadapted);
}
+ ///
+ /// 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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLch sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLab destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLch sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLab dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLab(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -42,10 +60,32 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLab ToCieLab(in CieLchuv color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
+
return this.ToCieLab(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLab destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLab dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLab(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -53,10 +93,32 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLab ToCieLab(in CieLuv color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
+
return this.ToCieLab(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLab destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLab dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLab(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -64,10 +126,32 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLab ToCieLab(in CieXyy color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
+
return this.ToCieLab(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLab destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLab dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLab(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -76,13 +160,31 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
public CieLab ToCieLab(in CieXyz color)
{
// Adaptation
- CieXyz adapted = !this.WhitePoint.Equals(this.TargetLabWhitePoint) && this.IsChromaticAdaptationPerformed
- ? this.ChromaticAdaptation.Transform(color, this.WhitePoint, this.TargetLabWhitePoint)
- : color;
+ CieXyz adapted = this.Adapt(color, this.whitePoint, this.targetLabWhitePoint);
// Conversion
- var converter = new CieXyzToCieLabConverter(this.TargetLabWhitePoint);
- return converter.Convert(adapted);
+ return this.cieXyzToCieLabConverter.Convert(adapted);
+ }
+
+ ///
+ /// 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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLab destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLab dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLab(sp);
+ }
}
///
@@ -92,10 +194,31 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLab ToCieLab(in Cmyk color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
return this.ToCieLab(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLab destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLab dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLab(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -103,10 +226,32 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLab ToCieLab(in Hsl color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
+
return this.ToCieLab(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Hsl sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLab destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Hsl sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLab dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLab(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -114,10 +259,31 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLab ToCieLab(in Hsv color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
return this.ToCieLab(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Hsv sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLab destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Hsv sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLab dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLab(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -125,10 +291,32 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLab ToCieLab(in HunterLab color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
+
return this.ToCieLab(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLab destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLab dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLab(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -136,10 +324,32 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLab ToCieLab(in Lms color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
+
return this.ToCieLab(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Lms sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLab destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Lms sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLab dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLab(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -147,10 +357,32 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLab ToCieLab(in LinearRgb color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
+
return this.ToCieLab(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLab destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLab dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLab(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -158,10 +390,32 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLab ToCieLab(in Rgb color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
+
return this.ToCieLab(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Rgb sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLab destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Rgb sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLab dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLab(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -169,8 +423,30 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLab ToCieLab(in YCbCr color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
+
return this.ToCieLab(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLab destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLab dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLab(sp);
+ }
+ }
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLch.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLch.cs
index cbefc5ac59..3c9e6658cd 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLch.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLch.cs
@@ -1,14 +1,17 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLchColorSapce;
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Allows conversion to .
///
- internal partial class ColorSpaceConverter
+ public partial class ColorSpaceConverter
{
///
/// The converter for converting between CieLab to CieLch.
@@ -23,12 +26,33 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
public CieLch ToCieLch(in CieLab color)
{
// Adaptation
- CieLab adapted = this.IsChromaticAdaptationPerformed ? this.Adapt(color) : color;
+ CieLab adapted = this.Adapt(color);
// Conversion
return CieLabToCieLchConverter.Convert(adapted);
}
+ ///
+ /// 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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLab sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLch destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLab sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLch dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLch(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -36,10 +60,32 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLch ToCieLch(in CieLchuv color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
+
return this.ToCieLch(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLch destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLch dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLch(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -47,10 +93,32 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLch ToCieLch(in CieLuv color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
+
return this.ToCieLch(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLch destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLch dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLch(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -58,10 +126,32 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLch ToCieLch(in CieXyy color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
+
return this.ToCieLch(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLch destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLch dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLch(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -69,10 +159,32 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLch ToCieLch(in CieXyz color)
{
- CieLab labColor = this.ToCieLab(color);
+ var labColor = this.ToCieLab(color);
+
return this.ToCieLch(labColor);
}
+ ///
+ /// 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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLch destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLch dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLch(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -80,10 +192,31 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLch ToCieLch(in Cmyk color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
return this.ToCieLch(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLch destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLch dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLch(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -91,10 +224,32 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLch ToCieLch(in Hsl color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
+
return this.ToCieLch(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Hsl sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLch destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Hsl sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLch dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLch(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -102,10 +257,32 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLch ToCieLch(in Hsv color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
+
return this.ToCieLch(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Hsv sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLch destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Hsv sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLch dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLch(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -113,10 +290,32 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLch ToCieLch(in HunterLab color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
+
return this.ToCieLch(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLch destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLch dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLch(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -124,10 +323,32 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLch ToCieLch(in LinearRgb color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
+
return this.ToCieLch(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLch destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLch dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLch(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -135,10 +356,32 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLch ToCieLch(in Lms color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
+
return this.ToCieLch(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Lms sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLch destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Lms sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLch dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLch(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -146,10 +389,32 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLch ToCieLch(in Rgb color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
+
return this.ToCieLch(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Rgb sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLch destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Rgb sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLch dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLch(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -157,8 +422,30 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLch ToCieLch(in YCbCr color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
+
return this.ToCieLch(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLch destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLch dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLch(sp);
+ }
+ }
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLchuv.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLchuv.cs
index 49c25462ea..01de794885 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLchuv.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLchuv.cs
@@ -1,14 +1,17 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLchuvColorSapce;
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Allows conversion to .
///
- internal partial class ColorSpaceConverter
+ public partial class ColorSpaceConverter
{
///
/// The converter for converting between CieLab to CieLchuv.
@@ -22,10 +25,32 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLchuv ToCieLchuv(in CieLab color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
+
return this.ToCieLchuv(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLab sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLab sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLchuv dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLchuv(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -33,10 +58,32 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLchuv ToCieLchuv(in CieLch color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
+
return this.ToCieLchuv(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLch sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLch sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLchuv dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLchuv(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -45,12 +92,33 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
public CieLchuv ToCieLchuv(in CieLuv color)
{
// Adaptation
- CieLuv adapted = this.IsChromaticAdaptationPerformed ? this.Adapt(color) : color;
+ CieLuv adapted = this.Adapt(color);
// Conversion
return CieLuvToCieLchuvConverter.Convert(adapted);
}
+ ///
+ /// 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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLchuv dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLchuv(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -58,10 +126,32 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLchuv ToCieLchuv(in CieXyy color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
+
return this.ToCieLchuv(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLchuv dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLchuv(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -69,8 +159,30 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLchuv ToCieLchuv(in CieXyz color)
{
- CieLab labColor = this.ToCieLab(color);
- return this.ToCieLchuv(labColor);
+ var luvColor = this.ToCieLuv(color);
+
+ return this.ToCieLchuv(luvColor);
+ }
+
+ ///
+ /// 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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLchuv dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLchuv(sp);
+ }
}
///
@@ -80,10 +192,32 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLchuv ToCieLchuv(in Cmyk color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
+
return this.ToCieLchuv(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLchuv dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLchuv(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -91,10 +225,32 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLchuv ToCieLchuv(in Hsl color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
+
return this.ToCieLchuv(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Hsl sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Hsl sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLchuv dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLchuv(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -102,10 +258,32 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLchuv ToCieLchuv(in Hsv color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
+
return this.ToCieLchuv(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Hsv sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Hsv sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLchuv dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLchuv(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -113,10 +291,32 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLchuv ToCieLchuv(in HunterLab color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
+
return this.ToCieLchuv(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLchuv dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLchuv(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -124,10 +324,32 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLchuv ToCieLchuv(in LinearRgb color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
+
return this.ToCieLchuv(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLchuv dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLchuv(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -135,10 +357,32 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLchuv ToCieLchuv(in Lms color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
+
return this.ToCieLchuv(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Lms sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Lms sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLchuv dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLchuv(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -146,10 +390,32 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLchuv ToCieLchuv(in Rgb color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
+
return this.ToCieLchuv(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Rgb sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Rgb sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLchuv dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLchuv(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -157,8 +423,29 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// The
public CieLchuv ToCieLchuv(in YCbCr color)
{
- CieXyz xyzColor = this.ToCieXyz(color);
+ var xyzColor = this.ToCieXyz(color);
return this.ToCieLchuv(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLchuv dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLchuv(sp);
+ }
+ }
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs
index 36e6501a5f..0b469e065f 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs
@@ -1,16 +1,17 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
-using SixLabors.ImageSharp.ColorSpaces;
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLchuvColorSapce;
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLuvColorSapce;
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Allows conversion to .
///
- internal partial class ColorSpaceConverter
+ public partial class ColorSpaceConverter
{
private static readonly CieLchuvToCieLuvConverter CieLchuvToCieLuvConverter = new CieLchuvToCieLuvConverter();
@@ -25,6 +26,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCieLuv(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLab sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLuv destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLab sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLuv dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLuv(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -36,6 +58,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCieLuv(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLch sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLuv destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLch sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLuv dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLuv(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -46,15 +89,31 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
// Conversion (perserving white point)
CieLuv unadapted = CieLchuvToCieLuvConverter.Convert(color);
- if (!this.IsChromaticAdaptationPerformed)
- {
- return unadapted;
- }
-
// Adaptation
return this.Adapt(unadapted);
}
+ ///
+ /// 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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLuv destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLuv dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLuv(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -66,6 +125,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCieLuv(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLuv destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLuv dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLuv(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -74,13 +154,31 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
public CieLuv ToCieLuv(in CieXyz color)
{
// Adaptation
- CieXyz adapted = !this.WhitePoint.Equals(this.TargetLabWhitePoint) && this.IsChromaticAdaptationPerformed
- ? this.ChromaticAdaptation.Transform(color, this.WhitePoint, this.TargetLabWhitePoint)
- : color;
+ CieXyz adapted = this.Adapt(color, this.whitePoint, this.targetLuvWhitePoint);
// Conversion
- var converter = new CieXyzToCieLuvConverter(this.TargetLuvWhitePoint);
- return converter.Convert(adapted);
+ return this.cieXyzToCieLuvConverter.Convert(adapted);
+ }
+
+ ///
+ /// 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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLuv destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLuv dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLuv(sp);
+ }
}
///
@@ -94,6 +192,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCieLuv(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLuv destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLuv dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLuv(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -105,6 +224,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCieLuv(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Hsl sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLuv destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Hsl sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLuv dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLuv(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -116,6 +256,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCieLuv(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Hsv sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLuv destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Hsv sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLuv dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLuv(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -127,6 +288,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCieLuv(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLuv destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLuv dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLuv(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -138,6 +320,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCieLuv(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Lms sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLuv destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Lms sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLuv dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLuv(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -149,6 +352,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCieLuv(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLuv destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLuv dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLuv(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -160,6 +384,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCieLuv(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Rgb sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLuv destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Rgb sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLuv dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLuv(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -170,5 +415,26 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
var xyzColor = this.ToCieXyz(color);
return this.ToCieLuv(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieLuv destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieLuv dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieLuv(sp);
+ }
+ }
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyy.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyy.cs
index 25a9f75a4b..b77f48325f 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyy.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyy.cs
@@ -1,14 +1,17 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieXyyColorSapce;
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Allows conversion to .
///
- internal partial class ColorSpaceConverter
+ public partial class ColorSpaceConverter
{
private static readonly CieXyzAndCieXyyConverter CieXyzAndCieXyyConverter = new CieXyzAndCieXyyConverter();
@@ -24,6 +27,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCieXyy(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLab sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieXyy destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLab sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieXyy dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieXyy(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -36,6 +60,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCieXyy(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLch sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieXyy destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLch sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieXyy dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieXyy(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -48,6 +93,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCieXyy(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieXyy destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieXyy dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieXyy(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -60,14 +126,53 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCieXyy(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieXyy destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieXyy dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieXyy(sp);
+ }
+ }
+
///
/// Converts a into a
///
/// The color to convert.
/// The
- public CieXyy ToCieXyy(in CieXyz color)
+ public CieXyy ToCieXyy(in CieXyz color) => CieXyzAndCieXyyConverter.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(ReadOnlySpan source, Span destination, int count)
{
- return CieXyzAndCieXyyConverter.Convert(color);
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieXyy destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieXyy dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieXyy(sp);
+ }
}
///
@@ -82,6 +187,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCieXyy(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieXyy destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieXyy dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieXyy(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -94,6 +220,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCieXyy(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Hsl sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieXyy destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Hsl sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieXyy dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieXyy(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -106,6 +253,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCieXyy(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Hsv sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieXyy destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Hsv sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieXyy dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieXyy(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -118,6 +286,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCieXyy(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieXyy destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieXyy dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieXyy(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -130,6 +319,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCieXyy(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieXyy destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieXyy dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieXyy(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -142,6 +352,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCieXyy(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Lms sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieXyy destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Lms sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieXyy dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieXyy(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -154,6 +385,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCieXyy(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Rgb sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieXyy destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Rgb sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieXyy dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieXyy(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -165,5 +417,26 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCieXyy(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieXyy destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieXyy dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieXyy(sp);
+ }
+ }
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs
index f4f28401f1..8963ad495a 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs
@@ -1,17 +1,17 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLabColorSapce;
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLuvColorSapce;
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.HunterLabColorSapce;
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce;
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Allows conversion to .
///
- internal partial class ColorSpaceConverter
+ public partial class ColorSpaceConverter
{
private static readonly CieLabToCieXyzConverter CieLabToCieXyzConverter = new CieLabToCieXyzConverter();
@@ -32,11 +32,28 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
CieXyz unadapted = CieLabToCieXyzConverter.Convert(color);
// Adaptation
- CieXyz adapted = color.WhitePoint.Equals(this.WhitePoint) || !this.IsChromaticAdaptationPerformed
- ? unadapted
- : this.Adapt(unadapted, color.WhitePoint);
+ return this.Adapt(unadapted, color.WhitePoint);
+ }
+
+ ///
+ /// 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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLab sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieXyz destRef = ref MemoryMarshal.GetReference(destination);
- return adapted;
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLab sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieXyz dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieXyz(sp);
+ }
}
///
@@ -53,6 +70,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCieXyz(labColor);
}
+ ///
+ /// 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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLch sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieXyz destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLch sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieXyz dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieXyz(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -67,6 +105,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCieXyz(luvColor);
}
+ ///
+ /// 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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieXyz destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieXyz dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieXyz(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -78,11 +137,28 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
CieXyz unadapted = CieLuvToCieXyzConverter.Convert(color);
// Adaptation
- CieXyz adapted = color.WhitePoint.Equals(this.WhitePoint) || !this.IsChromaticAdaptationPerformed
- ? unadapted
- : this.Adapt(unadapted, color.WhitePoint);
+ return this.Adapt(unadapted, color.WhitePoint);
+ }
- return adapted;
+ ///
+ /// 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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieXyz destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieXyz dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieXyz(sp);
+ }
}
///
@@ -96,6 +172,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return CieXyzAndCieXyyConverter.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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieXyz destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieXyz dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieXyz(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -109,6 +206,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCieXyz(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieXyz destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieXyz dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieXyz(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -122,6 +240,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCieXyz(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Hsl sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieXyz destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Hsl sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieXyz dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieXyz(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -135,6 +274,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCieXyz(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Hsv sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieXyz destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Hsv sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieXyz dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieXyz(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -146,11 +306,28 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
CieXyz unadapted = HunterLabToCieXyzConverter.Convert(color);
// Adaptation
- CieXyz adapted = color.WhitePoint.Equals(this.WhitePoint) || !this.IsChromaticAdaptationPerformed
- ? unadapted
- : this.Adapt(unadapted, color.WhitePoint);
+ return this.Adapt(unadapted, color.WhitePoint);
+ }
- return adapted;
+ ///
+ /// 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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieXyz destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieXyz dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieXyz(sp);
+ }
}
///
@@ -165,9 +342,28 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
CieXyz unadapted = converter.Convert(color);
// Adaptation
- return color.WorkingSpace.WhitePoint.Equals(this.WhitePoint) || !this.IsChromaticAdaptationPerformed
- ? unadapted
- : this.Adapt(unadapted, color.WorkingSpace.WhitePoint);
+ return this.Adapt(unadapted, color.WorkingSpace.WhitePoint);
+ }
+
+ ///
+ /// 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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieXyz destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieXyz dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieXyz(sp);
+ }
}
///
@@ -178,7 +374,28 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
public CieXyz ToCieXyz(in Lms color)
{
// Conversion
- return this.cachedCieXyzAndLmsConverter.Convert(color);
+ return this.cieXyzAndLmsConverter.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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Lms sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieXyz destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Lms sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieXyz dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieXyz(sp);
+ }
}
///
@@ -193,6 +410,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCieXyz(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Rgb sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieXyz destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Rgb sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieXyz dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieXyz(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -206,14 +444,35 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCieXyz(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source);
+ ref CieXyz destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i);
+ ref CieXyz dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCieXyz(sp);
+ }
+ }
+
///
/// Gets the correct converter for the given rgb working space.
///
/// The source working space
/// The
- private LinearRgbToCieXyzConverter GetLinearRgbToCieXyzConverter(RgbWorkingSpace workingSpace)
+ private LinearRgbToCieXyzConverter GetLinearRgbToCieXyzConverter(RgbWorkingSpaceBase workingSpace)
{
- if (this.linearRgbToCieXyzConverter != null && this.linearRgbToCieXyzConverter.SourceWorkingSpace.Equals(workingSpace))
+ if (this.linearRgbToCieXyzConverter?.SourceWorkingSpace.Equals(workingSpace) == true)
{
return this.linearRgbToCieXyzConverter;
}
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Cmyk.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Cmyk.cs
index 1e403828a2..6f8fe61469 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Cmyk.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Cmyk.cs
@@ -1,14 +1,17 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CmykColorSapce;
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Allows conversion to .
///
- internal partial class ColorSpaceConverter
+ public partial class ColorSpaceConverter
{
private static readonly CmykAndRgbConverter CmykAndRgbConverter = new CmykAndRgbConverter();
@@ -24,6 +27,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCmyk(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLab sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Cmyk destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLab sp = ref Unsafe.Add(ref sourceRef, i);
+ ref Cmyk dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCmyk(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -36,6 +60,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCmyk(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLch sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Cmyk destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLch sp = ref Unsafe.Add(ref sourceRef, i);
+ ref Cmyk dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCmyk(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -48,6 +93,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCmyk(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Cmyk destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i);
+ ref Cmyk dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCmyk(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -60,6 +126,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCmyk(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Cmyk destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i);
+ ref Cmyk dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCmyk(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -72,6 +159,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCmyk(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Cmyk destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i);
+ ref Cmyk dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCmyk(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -84,6 +192,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return CmykAndRgbConverter.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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Cmyk destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i);
+ ref Cmyk dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCmyk(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -96,6 +225,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return CmykAndRgbConverter.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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Hsl sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Cmyk destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Hsl sp = ref Unsafe.Add(ref sourceRef, i);
+ ref Cmyk dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCmyk(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -108,6 +258,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return CmykAndRgbConverter.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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Hsv sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Cmyk destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Hsv sp = ref Unsafe.Add(ref sourceRef, i);
+ ref Cmyk dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCmyk(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -120,6 +291,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCmyk(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Cmyk destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i);
+ ref Cmyk dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCmyk(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -132,6 +324,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return CmykAndRgbConverter.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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Cmyk destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i);
+ ref Cmyk dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCmyk(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -144,14 +357,53 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToCmyk(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Lms sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Cmyk destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Lms sp = ref Unsafe.Add(ref sourceRef, i);
+ ref Cmyk dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCmyk(sp);
+ }
+ }
+
///
/// Converts a into a
///
/// The color to convert.
/// The
- public Cmyk ToCmyk(in Rgb color)
+ public Cmyk ToCmyk(in Rgb color) => 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(ReadOnlySpan source, Span destination, int count)
{
- return CmykAndRgbConverter.Convert(color);
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Rgb sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Cmyk destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Rgb sp = ref Unsafe.Add(ref sourceRef, i);
+ ref Cmyk dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCmyk(sp);
+ }
}
///
@@ -165,5 +417,26 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return CmykAndRgbConverter.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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Cmyk destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i);
+ ref Cmyk dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToCmyk(sp);
+ }
+ }
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsl.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsl.cs
index 78f8c36fb6..106e8956f1 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsl.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsl.cs
@@ -1,14 +1,17 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.HslColorSapce;
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Allows conversion to .
///
- internal partial class ColorSpaceConverter
+ public partial class ColorSpaceConverter
{
private static readonly HslAndRgbConverter HslAndRgbConverter = new HslAndRgbConverter();
@@ -24,6 +27,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToHsl(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLab sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Hsl destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLab sp = ref Unsafe.Add(ref sourceRef, i);
+ ref Hsl dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToHsl(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -36,6 +60,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToHsl(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLch sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Hsl destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLch sp = ref Unsafe.Add(ref sourceRef, i);
+ ref Hsl dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToHsl(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -48,6 +93,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToHsl(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Hsl destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i);
+ ref Hsl dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToHsl(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -60,6 +126,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToHsl(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Hsl destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i);
+ ref Hsl dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToHsl(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -72,6 +159,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToHsl(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Hsl destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i);
+ ref Hsl dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToHsl(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -84,6 +192,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return HslAndRgbConverter.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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Hsl destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i);
+ ref Hsl dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToHsl(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -96,6 +225,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return HslAndRgbConverter.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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Hsl destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i);
+ ref Hsl dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToHsl(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -108,6 +258,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return HslAndRgbConverter.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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Hsv sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Hsl destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Hsv sp = ref Unsafe.Add(ref sourceRef, i);
+ ref Hsl dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToHsl(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -120,6 +291,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToHsl(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Hsl destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i);
+ ref Hsl dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToHsl(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -132,6 +324,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return HslAndRgbConverter.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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Hsl destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i);
+ ref Hsl dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToHsl(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -144,14 +357,53 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToHsl(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Lms sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Hsl destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Lms sp = ref Unsafe.Add(ref sourceRef, i);
+ ref Hsl dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToHsl(sp);
+ }
+ }
+
///
/// Converts a into a
///
/// The color to convert.
/// The
- public Hsl ToHsl(in Rgb color)
+ public Hsl ToHsl(in Rgb color) => 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(ReadOnlySpan source, Span destination, int count)
{
- return HslAndRgbConverter.Convert(color);
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Rgb sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Hsl destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref Rgb sp = ref Unsafe.Add(ref sourceRef, i);
+ ref Hsl dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToHsl(sp);
+ }
}
///
@@ -165,5 +417,26 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return HslAndRgbConverter.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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Hsl destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i);
+ ref Hsl dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToHsl(sp);
+ }
+ }
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsv.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsv.cs
index 3edd72c59b..8b4e29215c 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsv.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsv.cs
@@ -1,14 +1,17 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
-using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.HsvColorSapce;
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
///
/// Allows conversion to .
///
- internal partial class ColorSpaceConverter
+ public partial class ColorSpaceConverter
{
private static readonly HsvAndRgbConverter HsvAndRgbConverter = new HsvAndRgbConverter();
@@ -24,6 +27,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToHsv(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLab sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Hsv destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLab sp = ref Unsafe.Add(ref sourceRef, i);
+ ref Hsv dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToHsv(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -36,6 +60,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToHsv(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLch sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Hsv destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLch sp = ref Unsafe.Add(ref sourceRef, i);
+ ref Hsv dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToHsv(sp);
+ }
+ }
+
///
/// Converts a into a
///
@@ -48,6 +93,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return this.ToHsv(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(ReadOnlySpan source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Hsv destRef = ref MemoryMarshal.GetReference(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i);
+ ref Hsv dp = ref Unsafe.Add(ref destRef, i);
+ dp = this.ToHsv(sp);
+ }
+ }
+
///
/// Converts a