diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs
index 2720b81fe1..17cdb2ef27 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs
@@ -1,6 +1,8 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System;
+using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
@@ -24,7 +26,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
Guard.NotNull(color, nameof(color));
- // Conversion (perserving white point)
+ // Conversion (preserving white point)
CieLab unadapted = CieLchToCieLabConverter.Convert(color);
if (!this.IsChromaticAdaptationPerformed)
@@ -36,6 +38,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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(Span source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLch sourceRef = ref source.DangerousGetPinnableReference();
+ ref CieLab destRef = ref destination.DangerousGetPinnableReference();
+
+ 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
///
@@ -49,6 +72,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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(Span source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLchuv sourceRef = ref source.DangerousGetPinnableReference();
+ ref CieLab destRef = ref destination.DangerousGetPinnableReference();
+
+ 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
///
@@ -62,6 +106,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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(Span source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieLuv sourceRef = ref source.DangerousGetPinnableReference();
+ ref CieLab destRef = ref destination.DangerousGetPinnableReference();
+
+ 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
///
@@ -75,6 +140,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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(Span source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieXyy sourceRef = ref source.DangerousGetPinnableReference();
+ ref CieLab destRef = ref destination.DangerousGetPinnableReference();
+
+ 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
///
@@ -94,6 +180,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
return converter.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(Span source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref CieXyz sourceRef = ref source.DangerousGetPinnableReference();
+ ref CieLab destRef = ref destination.DangerousGetPinnableReference();
+
+ 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);
+ }
+ }
+
///
/// Converts a into a
///
@@ -107,6 +214,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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(Span source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Cmyk sourceRef = ref source.DangerousGetPinnableReference();
+ ref CieLab destRef = ref destination.DangerousGetPinnableReference();
+
+ 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
///
@@ -120,6 +248,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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(Span source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Hsl sourceRef = ref source.DangerousGetPinnableReference();
+ ref CieLab destRef = ref destination.DangerousGetPinnableReference();
+
+ 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
///
@@ -133,6 +282,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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(Span source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Hsv sourceRef = ref source.DangerousGetPinnableReference();
+ ref CieLab destRef = ref destination.DangerousGetPinnableReference();
+
+ 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
///
@@ -146,6 +316,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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(Span source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref HunterLab sourceRef = ref source.DangerousGetPinnableReference();
+ ref CieLab destRef = ref destination.DangerousGetPinnableReference();
+
+ 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
///
@@ -159,6 +350,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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(Span source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Lms sourceRef = ref source.DangerousGetPinnableReference();
+ ref CieLab destRef = ref destination.DangerousGetPinnableReference();
+
+ 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
///
@@ -172,6 +384,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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(Span source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref LinearRgb sourceRef = ref source.DangerousGetPinnableReference();
+ ref CieLab destRef = ref destination.DangerousGetPinnableReference();
+
+ 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
///
@@ -185,6 +418,27 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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(Span source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref Rgb sourceRef = ref source.DangerousGetPinnableReference();
+ ref CieLab destRef = ref destination.DangerousGetPinnableReference();
+
+ 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
///
@@ -197,5 +451,26 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
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(Span source, Span destination, int count)
+ {
+ Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
+
+ ref YCbCr sourceRef = ref source.DangerousGetPinnableReference();
+ ref CieLab destRef = ref destination.DangerousGetPinnableReference();
+
+ 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);
+ }
+ }
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/Common/Helpers/Guard.cs b/src/ImageSharp/Common/Helpers/Guard.cs
index b0546bf9a9..279c67b3e4 100644
--- a/src/ImageSharp/Common/Helpers/Guard.cs
+++ b/src/ImageSharp/Common/Helpers/Guard.cs
@@ -246,5 +246,27 @@ namespace SixLabors.ImageSharp
throw new ArgumentException($"Span-s must be at least of length {minLength}!", parameterName);
}
}
+
+ ///
+ /// Verifies that the given 'source' and 'dest' spans are at least of 'minLength' size.
+ /// Throwing an if the condition is not met.
+ ///
+ /// The source element type
+ /// The destination element type
+ /// The source span
+ /// The source parameter name
+ /// The destination span
+ /// The destination parameter name
+ /// The minimum length
+ public static void SpansMustBeSizedAtLeast(
+ Span source,
+ string sourceParamName,
+ Span dest,
+ string destParamName,
+ int minLength)
+ {
+ MustBeSizedAtLeast(source, minLength, sourceParamName);
+ MustBeSizedAtLeast(dest, minLength, destParamName);
+ }
}
}