diff --git a/src/ImageSharp/Color/Color.cs b/src/ImageSharp/Color/Color.cs
index 424329863..72f16528a 100644
--- a/src/ImageSharp/Color/Color.cs
+++ b/src/ImageSharp/Color/Color.cs
@@ -27,19 +27,19 @@ namespace SixLabors.ImageSharp
private Color(byte r, byte g, byte b, byte a)
{
this.data = new Rgba64(
- ImageMath.UpscaleFrom8BitTo16Bit(r),
- ImageMath.UpscaleFrom8BitTo16Bit(g),
- ImageMath.UpscaleFrom8BitTo16Bit(b),
- ImageMath.UpscaleFrom8BitTo16Bit(a));
+ ColorNumerics.UpscaleFrom8BitTo16Bit(r),
+ ColorNumerics.UpscaleFrom8BitTo16Bit(g),
+ ColorNumerics.UpscaleFrom8BitTo16Bit(b),
+ ColorNumerics.UpscaleFrom8BitTo16Bit(a));
}
[MethodImpl(InliningOptions.ShortMethod)]
private Color(byte r, byte g, byte b)
{
this.data = new Rgba64(
- ImageMath.UpscaleFrom8BitTo16Bit(r),
- ImageMath.UpscaleFrom8BitTo16Bit(g),
- ImageMath.UpscaleFrom8BitTo16Bit(b),
+ ColorNumerics.UpscaleFrom8BitTo16Bit(r),
+ ColorNumerics.UpscaleFrom8BitTo16Bit(g),
+ ColorNumerics.UpscaleFrom8BitTo16Bit(b),
ushort.MaxValue);
}
diff --git a/src/ImageSharp/Common/Helpers/ColorNumerics.cs b/src/ImageSharp/Common/Helpers/ColorNumerics.cs
new file mode 100644
index 000000000..6f225b110
--- /dev/null
+++ b/src/ImageSharp/Common/Helpers/ColorNumerics.cs
@@ -0,0 +1,177 @@
+// Copyright (c) Six Labors.
+// Licensed under the Apache License, Version 2.0.
+
+using System;
+using System.Numerics;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+namespace SixLabors.ImageSharp
+{
+ ///
+ /// Provides optimized static methods for common mathematical functions specific
+ /// to color processing.
+ ///
+ internal static class ColorNumerics
+ {
+ ///
+ /// Vector for converting pixel to gray value as specified by
+ /// ITU-R Recommendation BT.709.
+ ///
+ private static readonly Vector4 Bt709 = new Vector4(.2126f, .7152f, .0722f, 0.0f);
+
+ ///
+ /// Convert a pixel value to grayscale using ITU-R Recommendation BT.709.
+ ///
+ /// The vector to get the luminance from.
+ ///
+ /// The number of luminance levels (256 for 8 bit, 65536 for 16 bit grayscale images).
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static int GetBT709Luminance(ref Vector4 vector, int luminanceLevels)
+ => (int)MathF.Round(Vector4.Dot(vector, Bt709) * (luminanceLevels - 1));
+
+ ///
+ /// Gets the luminance from the rgb components using the formula
+ /// as specified by ITU-R Recommendation BT.709.
+ ///
+ /// The red component.
+ /// The green component.
+ /// The blue component.
+ /// The .
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static byte Get8BitBT709Luminance(byte r, byte g, byte b)
+ => (byte)((r * .2126F) + (g * .7152F) + (b * .0722F) + 0.5F);
+
+ ///
+ /// Gets the luminance from the rgb components using the formula as
+ /// specified by ITU-R Recommendation BT.709.
+ ///
+ /// The red component.
+ /// The green component.
+ /// The blue component.
+ /// The .
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static ushort Get16BitBT709Luminance(ushort r, ushort g, ushort b)
+ => (ushort)((r * .2126F) + (g * .7152F) + (b * .0722F) + 0.5F);
+
+ ///
+ /// Gets the luminance from the rgb components using the formula as specified
+ /// by ITU-R Recommendation BT.709.
+ ///
+ /// The red component.
+ /// The green component.
+ /// The blue component.
+ /// The .
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static ushort Get16BitBT709Luminance(float r, float g, float b)
+ => (ushort)((r * .2126F) + (g * .7152F) + (b * .0722F) + 0.5F);
+
+ ///
+ /// Scales a value from a 16 bit to an
+ /// 8 bit equivalent.
+ ///
+ /// The 8 bit component value.
+ /// The
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static byte DownScaleFrom16BitTo8Bit(ushort component)
+ {
+ // To scale to 8 bits From a 16-bit value V the required value (from the PNG specification) is:
+ //
+ // (V * 255) / 65535
+ //
+ // This reduces to round(V / 257), or floor((V + 128.5)/257)
+ //
+ // Represent V as the two byte value vhi.vlo. Make a guess that the
+ // result is the top byte of V, vhi, then the correction to this value
+ // is:
+ //
+ // error = floor(((V-vhi.vhi) + 128.5) / 257)
+ // = floor(((vlo-vhi) + 128.5) / 257)
+ //
+ // This can be approximated using integer arithmetic (and a signed
+ // shift):
+ //
+ // error = (vlo-vhi+128) >> 8;
+ //
+ // The approximate differs from the exact answer only when (vlo-vhi) is
+ // 128; it then gives a correction of +1 when the exact correction is
+ // 0. This gives 128 errors. The exact answer (correct for all 16-bit
+ // input values) is:
+ //
+ // error = (vlo-vhi+128)*65535 >> 24;
+ //
+ // An alternative arithmetic calculation which also gives no errors is:
+ //
+ // (V * 255 + 32895) >> 16
+ return (byte)(((component * 255) + 32895) >> 16);
+ }
+
+ ///
+ /// Scales a value from an 8 bit to
+ /// an 16 bit equivalent.
+ ///
+ /// The 8 bit component value.
+ /// The
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static ushort UpscaleFrom8BitTo16Bit(byte component)
+ => (ushort)(component * 257);
+
+ ///
+ /// Returns how many bits are required to store the specified number of colors.
+ /// Performs a Log2() on the value.
+ ///
+ /// The number of colors.
+ ///
+ /// The
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static int GetBitsNeededForColorDepth(int colors)
+ => Math.Max(1, (int)Math.Ceiling(Math.Log(colors, 2)));
+
+ ///
+ /// Returns how many colors will be created by the specified number of bits.
+ ///
+ /// The bit depth.
+ /// The
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static int GetColorCountForBitDepth(int bitDepth)
+ => 1 << bitDepth;
+
+ ///
+ /// Transforms a vector by the given color matrix.
+ ///
+ /// The source vector.
+ /// The transformation color matrix.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static void Transform(ref Vector4 vector, ref ColorMatrix matrix)
+ {
+ float x = vector.X;
+ float y = vector.Y;
+ float z = vector.Z;
+ float w = vector.W;
+
+ vector.X = (x * matrix.M11) + (y * matrix.M21) + (z * matrix.M31) + (w * matrix.M41) + matrix.M51;
+ vector.Y = (x * matrix.M12) + (y * matrix.M22) + (z * matrix.M32) + (w * matrix.M42) + matrix.M52;
+ vector.Z = (x * matrix.M13) + (y * matrix.M23) + (z * matrix.M33) + (w * matrix.M43) + matrix.M53;
+ vector.W = (x * matrix.M14) + (y * matrix.M24) + (z * matrix.M34) + (w * matrix.M44) + matrix.M54;
+ }
+
+ ///
+ /// Bulk variant of .
+ ///
+ /// The span of vectors
+ /// The transformation color matrix.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static void Transform(Span vectors, ref ColorMatrix matrix)
+ {
+ ref Vector4 baseRef = ref MemoryMarshal.GetReference(vectors);
+
+ for (int i = 0; i < vectors.Length; i++)
+ {
+ ref Vector4 v = ref Unsafe.Add(ref baseRef, i);
+ Transform(ref v, ref matrix);
+ }
+ }
+ }
+}
diff --git a/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs b/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs
index 7da2528fa..f265bdd51 100644
--- a/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs
+++ b/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs
@@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp
ref Vector4 target = ref Unsafe.Add(ref targetRowRef, column);
vector.W = target.W;
- Vector4Utils.UnPremultiply(ref vector);
+ Numerics.UnPremultiply(ref vector);
target = vector;
}
@@ -105,7 +105,7 @@ namespace SixLabors.ImageSharp
out Vector4 vector);
ref Vector4 target = ref Unsafe.Add(ref targetRowRef, column);
- Vector4Utils.UnPremultiply(ref vector);
+ Numerics.UnPremultiply(ref vector);
target = vector;
}
@@ -140,7 +140,7 @@ namespace SixLabors.ImageSharp
{
int offsetX = Numerics.Clamp(sourceOffsetColumnBase + x - radiusX, minColumn, maxColumn);
var currentColor = sourceRowSpan[offsetX].ToVector4();
- Vector4Utils.Premultiply(ref currentColor);
+ Numerics.Premultiply(ref currentColor);
vectorX += matrixX[y, x] * currentColor;
vectorY += matrixY[y, x] * currentColor;
@@ -193,7 +193,7 @@ namespace SixLabors.ImageSharp
ref Vector4 target = ref Unsafe.Add(ref targetRowRef, column);
vector.W = target.W;
- Vector4Utils.UnPremultiply(ref vector);
+ Numerics.UnPremultiply(ref vector);
target = vector;
}
@@ -238,7 +238,7 @@ namespace SixLabors.ImageSharp
ref vector);
ref Vector4 target = ref Unsafe.Add(ref targetRowRef, column);
- Vector4Utils.UnPremultiply(ref vector);
+ Numerics.UnPremultiply(ref vector);
target = vector;
}
@@ -270,7 +270,7 @@ namespace SixLabors.ImageSharp
{
int offsetX = Numerics.Clamp(sourceOffsetColumnBase + x - radiusX, minColumn, maxColumn);
var currentColor = sourceRowSpan[offsetX].ToVector4();
- Vector4Utils.Premultiply(ref currentColor);
+ Numerics.Premultiply(ref currentColor);
vector += matrix[y, x] * currentColor;
}
}
diff --git a/src/ImageSharp/Common/Helpers/ImageMath.cs b/src/ImageSharp/Common/Helpers/ImageMath.cs
deleted file mode 100644
index 59f9ad021..000000000
--- a/src/ImageSharp/Common/Helpers/ImageMath.cs
+++ /dev/null
@@ -1,257 +0,0 @@
-// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-using System.Numerics;
-using System.Runtime.CompilerServices;
-using SixLabors.ImageSharp.PixelFormats;
-
-namespace SixLabors.ImageSharp
-{
- ///
- /// Provides common mathematical methods used for image processing.
- ///
- internal static class ImageMath
- {
- ///
- /// Vector for converting pixel to gray value as specified by ITU-R Recommendation BT.709.
- ///
- private static readonly Vector4 Bt709 = new Vector4(.2126f, .7152f, .0722f, 0.0f);
-
- ///
- /// Convert a pixel value to grayscale using ITU-R Recommendation BT.709.
- ///
- /// The vector to get the luminance from.
- /// The number of luminance levels (256 for 8 bit, 65536 for 16 bit grayscale images)
- [MethodImpl(InliningOptions.ShortMethod)]
- public static int GetBT709Luminance(ref Vector4 vector, int luminanceLevels)
- => (int)MathF.Round(Vector4.Dot(vector, Bt709) * (luminanceLevels - 1));
-
- ///
- /// Gets the luminance from the rgb components using the formula as specified by ITU-R Recommendation BT.709.
- ///
- /// The red component.
- /// The green component.
- /// The blue component.
- /// The .
- [MethodImpl(InliningOptions.ShortMethod)]
- public static byte Get8BitBT709Luminance(byte r, byte g, byte b) =>
- (byte)((r * .2126F) + (g * .7152F) + (b * .0722F) + 0.5F);
-
- ///
- /// Gets the luminance from the rgb components using the formula as specified by ITU-R Recommendation BT.709.
- ///
- /// The red component.
- /// The green component.
- /// The blue component.
- /// The .
- [MethodImpl(InliningOptions.ShortMethod)]
- public static ushort Get16BitBT709Luminance(ushort r, ushort g, ushort b) =>
- (ushort)((r * .2126F) + (g * .7152F) + (b * .0722F) + 0.5F);
-
- ///
- /// Gets the luminance from the rgb components using the formula as specified by ITU-R Recommendation BT.709.
- ///
- /// The red component.
- /// The green component.
- /// The blue component.
- /// The .
- [MethodImpl(InliningOptions.ShortMethod)]
- public static ushort Get16BitBT709Luminance(float r, float g, float b) =>
- (ushort)((r * .2126F) + (g * .7152F) + (b * .0722F) + 0.5F);
-
- ///
- /// Scales a value from a 16 bit to it's 8 bit equivalent.
- ///
- /// The 8 bit component value.
- /// The
- [MethodImpl(InliningOptions.ShortMethod)]
- public static byte DownScaleFrom16BitTo8Bit(ushort component)
- {
- // To scale to 8 bits From a 16-bit value V the required value (from the PNG specification) is:
- //
- // (V * 255) / 65535
- //
- // This reduces to round(V / 257), or floor((V + 128.5)/257)
- //
- // Represent V as the two byte value vhi.vlo. Make a guess that the
- // result is the top byte of V, vhi, then the correction to this value
- // is:
- //
- // error = floor(((V-vhi.vhi) + 128.5) / 257)
- // = floor(((vlo-vhi) + 128.5) / 257)
- //
- // This can be approximated using integer arithmetic (and a signed
- // shift):
- //
- // error = (vlo-vhi+128) >> 8;
- //
- // The approximate differs from the exact answer only when (vlo-vhi) is
- // 128; it then gives a correction of +1 when the exact correction is
- // 0. This gives 128 errors. The exact answer (correct for all 16-bit
- // input values) is:
- //
- // error = (vlo-vhi+128)*65535 >> 24;
- //
- // An alternative arithmetic calculation which also gives no errors is:
- //
- // (V * 255 + 32895) >> 16
- return (byte)(((component * 255) + 32895) >> 16);
- }
-
- ///
- /// Scales a value from an 8 bit to it's 16 bit equivalent.
- ///
- /// The 8 bit component value.
- /// The
- [MethodImpl(InliningOptions.ShortMethod)]
- public static ushort UpscaleFrom8BitTo16Bit(byte component) => (ushort)(component * 257);
-
- ///
- /// Returns how many bits are required to store the specified number of colors.
- /// Performs a Log2() on the value.
- ///
- /// The number of colors.
- ///
- /// The
- ///
- [MethodImpl(InliningOptions.ShortMethod)]
- public static int GetBitsNeededForColorDepth(int colors) => Math.Max(1, (int)Math.Ceiling(Math.Log(colors, 2)));
-
- ///
- /// Returns how many colors will be created by the specified number of bits.
- ///
- /// The bit depth.
- /// The
- [MethodImpl(InliningOptions.ShortMethod)]
- public static int GetColorCountForBitDepth(int bitDepth) => 1 << bitDepth;
-
- ///
- /// Gets the bounding from the given points.
- ///
- ///
- /// The designating the top left position.
- ///
- ///
- /// The designating the bottom right position.
- ///
- ///
- /// The bounding .
- ///
- [MethodImpl(InliningOptions.ShortMethod)]
- public static Rectangle GetBoundingRectangle(Point topLeft, Point bottomRight) => new Rectangle(topLeft.X, topLeft.Y, bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y);
-
- ///
- /// Finds the bounding rectangle based on the first instance of any color component other
- /// than the given one.
- ///
- /// The pixel format.
- /// The to search within.
- /// The color component value to remove.
- /// The channel to test against.
- ///
- /// The .
- ///
- public static Rectangle GetFilteredBoundingRectangle(ImageFrame bitmap, float componentValue, RgbaComponent channel = RgbaComponent.B)
- where TPixel : unmanaged, IPixel
- {
- int width = bitmap.Width;
- int height = bitmap.Height;
- Point topLeft = default;
- Point bottomRight = default;
-
- Func, int, int, float, bool> delegateFunc;
-
- // Determine which channel to check against
- switch (channel)
- {
- case RgbaComponent.R:
- delegateFunc = (pixels, x, y, b) => MathF.Abs(pixels[x, y].ToVector4().X - b) > Constants.Epsilon;
- break;
-
- case RgbaComponent.G:
- delegateFunc = (pixels, x, y, b) => MathF.Abs(pixels[x, y].ToVector4().Y - b) > Constants.Epsilon;
- break;
-
- case RgbaComponent.B:
- delegateFunc = (pixels, x, y, b) => MathF.Abs(pixels[x, y].ToVector4().Z - b) > Constants.Epsilon;
- break;
-
- default:
- delegateFunc = (pixels, x, y, b) => MathF.Abs(pixels[x, y].ToVector4().W - b) > Constants.Epsilon;
- break;
- }
-
- int GetMinY(ImageFrame pixels)
- {
- for (int y = 0; y < height; y++)
- {
- for (int x = 0; x < width; x++)
- {
- if (delegateFunc(pixels, x, y, componentValue))
- {
- return y;
- }
- }
- }
-
- return 0;
- }
-
- int GetMaxY(ImageFrame pixels)
- {
- for (int y = height - 1; y > -1; y--)
- {
- for (int x = 0; x < width; x++)
- {
- if (delegateFunc(pixels, x, y, componentValue))
- {
- return y;
- }
- }
- }
-
- return height;
- }
-
- int GetMinX(ImageFrame pixels)
- {
- for (int x = 0; x < width; x++)
- {
- for (int y = 0; y < height; y++)
- {
- if (delegateFunc(pixels, x, y, componentValue))
- {
- return x;
- }
- }
- }
-
- return 0;
- }
-
- int GetMaxX(ImageFrame pixels)
- {
- for (int x = width - 1; x > -1; x--)
- {
- for (int y = 0; y < height; y++)
- {
- if (delegateFunc(pixels, x, y, componentValue))
- {
- return x;
- }
- }
- }
-
- return width;
- }
-
- topLeft.Y = GetMinY(bitmap);
- topLeft.X = GetMinX(bitmap);
- bottomRight.Y = Numerics.Clamp(GetMaxY(bitmap) + 1, 0, height);
- bottomRight.X = Numerics.Clamp(GetMaxX(bitmap) + 1, 0, width);
-
- return GetBoundingRectangle(topLeft, bottomRight);
- }
- }
-}
diff --git a/src/ImageSharp/Common/Helpers/Numerics.cs b/src/ImageSharp/Common/Helpers/Numerics.cs
index c1e564781..b2bedb87b 100644
--- a/src/ImageSharp/Common/Helpers/Numerics.cs
+++ b/src/ImageSharp/Common/Helpers/Numerics.cs
@@ -5,6 +5,10 @@ using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+#if SUPPORTS_RUNTIME_INTRINSICS
+using System.Runtime.Intrinsics;
+using System.Runtime.Intrinsics.X86;
+#endif
namespace SixLabors.ImageSharp
{
@@ -14,9 +18,15 @@ namespace SixLabors.ImageSharp
///
internal static class Numerics
{
+#if SUPPORTS_RUNTIME_INTRINSICS
+ private const int BlendAlphaControl = 0b_10_00_10_00;
+ private const int ShuffleAlphaControl = 0b_11_11_11_11;
+#endif
+
///
/// Determine the Greatest CommonDivisor (GCD) of two numbers.
///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int GreatestCommonDivisor(int a, int b)
{
while (b != 0)
@@ -32,6 +42,7 @@ namespace SixLabors.ImageSharp
///
/// Determine the Least Common Multiple (LCM) of two numbers.
///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int LeastCommonMultiple(int a, int b)
{
// https://en.wikipedia.org/wiki/Least_common_multiple#Reduction_by_the_greatest_common_divisor
@@ -262,7 +273,7 @@ namespace SixLabors.ImageSharp
/// The minimum inclusive value.
/// The maximum inclusive value.
/// The clamped .
- [MethodImpl(InliningOptions.ShortMethod)]
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4 Clamp(Vector4 value, Vector4 min, Vector4 max)
=> Vector4.Min(Vector4.Max(value, min), max);
@@ -426,5 +437,115 @@ namespace SixLabors.ImageSharp
}
}
}
+
+ ///
+ /// Pre-multiplies the "x", "y", "z" components of a vector by its "w" component leaving the "w" component intact.
+ ///
+ /// The to premultiply
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static void Premultiply(ref Vector4 source)
+ {
+ float w = source.W;
+ source *= w;
+ source.W = w;
+ }
+
+ ///
+ /// Reverses the result of premultiplying a vector via .
+ ///
+ /// The to premultiply
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static void UnPremultiply(ref Vector4 source)
+ {
+ float w = source.W;
+ source /= w;
+ source.W = w;
+ }
+
+ ///
+ /// Bulk variant of
+ ///
+ /// The span of vectors
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static void Premultiply(Span vectors)
+ {
+#if SUPPORTS_RUNTIME_INTRINSICS
+ if (Avx2.IsSupported && vectors.Length >= 2)
+ {
+ ref Vector256 vectorsBase =
+ ref Unsafe.As>(ref MemoryMarshal.GetReference(vectors));
+
+ // Divide by 2 as 4 elements per Vector4 and 8 per Vector256
+ ref Vector256 vectorsLast = ref Unsafe.Add(ref vectorsBase, (IntPtr)((uint)vectors.Length / 2u));
+
+ while (Unsafe.IsAddressLessThan(ref vectorsBase, ref vectorsLast))
+ {
+ Vector256 source = vectorsBase;
+ Vector256 multiply = Avx.Shuffle(source, source, ShuffleAlphaControl);
+ vectorsBase = Avx.Blend(Avx.Multiply(source, multiply), source, BlendAlphaControl);
+ vectorsBase = ref Unsafe.Add(ref vectorsBase, 1);
+ }
+
+ if (Modulo2(vectors.Length) != 0)
+ {
+ // Vector4 fits neatly in pairs. Any overlap has to be equal to 1.
+ Premultiply(ref MemoryMarshal.GetReference(vectors.Slice(vectors.Length - 1)));
+ }
+ }
+ else
+#endif
+ {
+ ref Vector4 baseRef = ref MemoryMarshal.GetReference(vectors);
+
+ for (int i = 0; i < vectors.Length; i++)
+ {
+ ref Vector4 v = ref Unsafe.Add(ref baseRef, i);
+ Premultiply(ref v);
+ }
+ }
+ }
+
+ ///
+ /// Bulk variant of
+ ///
+ /// The span of vectors
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static void UnPremultiply(Span vectors)
+ {
+#if SUPPORTS_RUNTIME_INTRINSICS
+ if (Avx2.IsSupported && vectors.Length >= 2)
+ {
+ ref Vector256 vectorsBase =
+ ref Unsafe.As>(ref MemoryMarshal.GetReference(vectors));
+
+ // Divide by 2 as 4 elements per Vector4 and 8 per Vector256
+ ref Vector256 vectorsLast = ref Unsafe.Add(ref vectorsBase, (IntPtr)((uint)vectors.Length / 2u));
+
+ while (Unsafe.IsAddressLessThan(ref vectorsBase, ref vectorsLast))
+ {
+ Vector256 source = vectorsBase;
+ Vector256 multiply = Avx.Shuffle(source, source, ShuffleAlphaControl);
+ vectorsBase = Avx.Blend(Avx.Divide(source, multiply), source, BlendAlphaControl);
+ vectorsBase = ref Unsafe.Add(ref vectorsBase, 1);
+ }
+
+ if (Modulo2(vectors.Length) != 0)
+ {
+ // Vector4 fits neatly in pairs. Any overlap has to be equal to 1.
+ UnPremultiply(ref MemoryMarshal.GetReference(vectors.Slice(vectors.Length - 1)));
+ }
+ }
+ else
+#endif
+ {
+ ref Vector4 baseRef = ref MemoryMarshal.GetReference(vectors);
+
+ for (int i = 0; i < vectors.Length; i++)
+ {
+ ref Vector4 v = ref Unsafe.Add(ref baseRef, i);
+ UnPremultiply(ref v);
+ }
+ }
+ }
}
}
diff --git a/src/ImageSharp/Common/Helpers/Vector4Utils.cs b/src/ImageSharp/Common/Helpers/Vector4Utils.cs
deleted file mode 100644
index 05661991a..000000000
--- a/src/ImageSharp/Common/Helpers/Vector4Utils.cs
+++ /dev/null
@@ -1,169 +0,0 @@
-// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-using System.Numerics;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-#if SUPPORTS_RUNTIME_INTRINSICS
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-#endif
-
-namespace SixLabors.ImageSharp
-{
- ///
- /// Utility methods for the struct.
- ///
- internal static class Vector4Utils
- {
- private const int BlendAlphaControl = 0b_10_00_10_00;
- private const int ShuffleAlphaControl = 0b_11_11_11_11;
-
- ///
- /// Pre-multiplies the "x", "y", "z" components of a vector by its "w" component leaving the "w" component intact.
- ///
- /// The to premultiply
- [MethodImpl(InliningOptions.ShortMethod)]
- public static void Premultiply(ref Vector4 source)
- {
- float w = source.W;
- source *= w;
- source.W = w;
- }
-
- ///
- /// Reverses the result of premultiplying a vector via .
- ///
- /// The to premultiply
- [MethodImpl(InliningOptions.ShortMethod)]
- public static void UnPremultiply(ref Vector4 source)
- {
- float w = source.W;
- source /= w;
- source.W = w;
- }
-
- ///
- /// Bulk variant of
- ///
- /// The span of vectors
- [MethodImpl(InliningOptions.ShortMethod)]
- public static void Premultiply(Span vectors)
- {
-#if SUPPORTS_RUNTIME_INTRINSICS
- if (Avx2.IsSupported && vectors.Length >= 2)
- {
- ref Vector256 vectorsBase =
- ref Unsafe.As>(ref MemoryMarshal.GetReference(vectors));
-
- // Divide by 2 as 4 elements per Vector4 and 8 per Vector256
- ref Vector256 vectorsLast = ref Unsafe.Add(ref vectorsBase, (IntPtr)((uint)vectors.Length / 2u));
-
- while (Unsafe.IsAddressLessThan(ref vectorsBase, ref vectorsLast))
- {
- Vector256 source = vectorsBase;
- Vector256 multiply = Avx.Shuffle(source, source, ShuffleAlphaControl);
- vectorsBase = Avx.Blend(Avx.Multiply(source, multiply), source, BlendAlphaControl);
- vectorsBase = ref Unsafe.Add(ref vectorsBase, 1);
- }
-
- if (Numerics.Modulo2(vectors.Length) != 0)
- {
- // Vector4 fits neatly in pairs. Any overlap has to be equal to 1.
- Premultiply(ref MemoryMarshal.GetReference(vectors.Slice(vectors.Length - 1)));
- }
- }
- else
-#endif
- {
- ref Vector4 baseRef = ref MemoryMarshal.GetReference(vectors);
-
- for (int i = 0; i < vectors.Length; i++)
- {
- ref Vector4 v = ref Unsafe.Add(ref baseRef, i);
- Premultiply(ref v);
- }
- }
- }
-
- ///
- /// Bulk variant of
- ///
- /// The span of vectors
- [MethodImpl(InliningOptions.ShortMethod)]
- public static void UnPremultiply(Span vectors)
- {
-#if SUPPORTS_RUNTIME_INTRINSICS
- if (Avx2.IsSupported && vectors.Length >= 2)
- {
- ref Vector256 vectorsBase =
- ref Unsafe.As>(ref MemoryMarshal.GetReference(vectors));
-
- // Divide by 2 as 4 elements per Vector4 and 8 per Vector256
- ref Vector256 vectorsLast = ref Unsafe.Add(ref vectorsBase, (IntPtr)((uint)vectors.Length / 2u));
-
- while (Unsafe.IsAddressLessThan(ref vectorsBase, ref vectorsLast))
- {
- Vector256 source = vectorsBase;
- Vector256 multiply = Avx.Shuffle(source, source, ShuffleAlphaControl);
- vectorsBase = Avx.Blend(Avx.Divide(source, multiply), source, BlendAlphaControl);
- vectorsBase = ref Unsafe.Add(ref vectorsBase, 1);
- }
-
- if (Numerics.Modulo2(vectors.Length) != 0)
- {
- // Vector4 fits neatly in pairs. Any overlap has to be equal to 1.
- UnPremultiply(ref MemoryMarshal.GetReference(vectors.Slice(vectors.Length - 1)));
- }
- }
- else
-#endif
- {
- ref Vector4 baseRef = ref MemoryMarshal.GetReference(vectors);
-
- for (int i = 0; i < vectors.Length; i++)
- {
- ref Vector4 v = ref Unsafe.Add(ref baseRef, i);
- UnPremultiply(ref v);
- }
- }
- }
-
- ///
- /// Transforms a vector by the given matrix.
- ///
- /// The source vector.
- /// The transformation matrix.
- [MethodImpl(InliningOptions.ShortMethod)]
- public static void Transform(ref Vector4 vector, ref ColorMatrix matrix)
- {
- float x = vector.X;
- float y = vector.Y;
- float z = vector.Z;
- float w = vector.W;
-
- vector.X = (x * matrix.M11) + (y * matrix.M21) + (z * matrix.M31) + (w * matrix.M41) + matrix.M51;
- vector.Y = (x * matrix.M12) + (y * matrix.M22) + (z * matrix.M32) + (w * matrix.M42) + matrix.M52;
- vector.Z = (x * matrix.M13) + (y * matrix.M23) + (z * matrix.M33) + (w * matrix.M43) + matrix.M53;
- vector.W = (x * matrix.M14) + (y * matrix.M24) + (z * matrix.M34) + (w * matrix.M44) + matrix.M54;
- }
-
- ///
- /// Bulk variant of .
- ///
- /// The span of vectors
- /// The transformation matrix.
- [MethodImpl(InliningOptions.ShortMethod)]
- public static void Transform(Span vectors, ref ColorMatrix matrix)
- {
- ref Vector4 baseRef = ref MemoryMarshal.GetReference(vectors);
-
- for (int i = 0; i < vectors.Length; i++)
- {
- ref Vector4 v = ref Unsafe.Add(ref baseRef, i);
- Transform(ref v, ref matrix);
- }
- }
- }
-}
diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
index 0dd667850..0be038572 100644
--- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
@@ -1385,7 +1385,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
{
case BmpFileMarkerType.Bitmap:
colorMapSizeBytes = this.fileHeader.Offset - BmpFileHeader.Size - this.infoHeader.HeaderSize;
- int colorCountForBitDepth = ImageMath.GetColorCountForBitDepth(this.infoHeader.BitsPerPixel);
+ int colorCountForBitDepth = ColorNumerics.GetColorCountForBitDepth(this.infoHeader.BitsPerPixel);
bytesPerColorMapEntry = colorMapSizeBytes / colorCountForBitDepth;
// Edge case for less-than-full-sized palette: bytesPerColorMapEntry should be at least 3.
@@ -1399,7 +1399,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
case BmpFileMarkerType.Pointer:
// OS/2 bitmaps always have 3 colors per color palette entry.
bytesPerColorMapEntry = 3;
- colorMapSizeBytes = ImageMath.GetColorCountForBitDepth(this.infoHeader.BitsPerPixel) * bytesPerColorMapEntry;
+ colorMapSizeBytes = ColorNumerics.GetColorCountForBitDepth(this.infoHeader.BitsPerPixel) * bytesPerColorMapEntry;
break;
}
}
diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs
index f4288e97f..9c1e95285 100644
--- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs
+++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs
@@ -105,7 +105,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
}
// Get the number of bits.
- this.bitDepth = ImageMath.GetBitsNeededForColorDepth(quantized.Palette.Length);
+ this.bitDepth = ColorNumerics.GetBitsNeededForColorDepth(quantized.Palette.Length);
// Write the header.
this.WriteHeader(stream);
@@ -212,7 +212,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
}
}
- this.bitDepth = ImageMath.GetBitsNeededForColorDepth(quantized.Palette.Length);
+ this.bitDepth = ColorNumerics.GetBitsNeededForColorDepth(quantized.Palette.Length);
this.WriteGraphicalControlExtension(frameMetadata, this.GetTransparentIndex(quantized), stream);
this.WriteImageDescriptor(frame, true, stream);
this.WriteColorTable(quantized, stream);
@@ -468,7 +468,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
where TPixel : unmanaged, IPixel
{
// The maximum number of colors for the bit depth
- int colorTableLength = ImageMath.GetColorCountForBitDepth(this.bitDepth) * Unsafe.SizeOf();
+ int colorTableLength = ColorNumerics.GetColorCountForBitDepth(this.bitDepth) * Unsafe.SizeOf();
using IManagedByteBuffer colorTable = this.memoryAllocator.AllocateManagedByteBuffer(colorTableLength, AllocationOptions.Clean);
PixelOperations.Instance.ToRgb24Bytes(
diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs
index 4e05f459f..5d2af8ec6 100644
--- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs
+++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs
@@ -284,7 +284,7 @@ namespace SixLabors.ImageSharp.Formats.Png
rowSpan.Length,
AllocationOptions.Clean))
{
- int scaleFactor = 255 / (ImageMath.GetColorCountForBitDepth(this.bitDepth) - 1);
+ int scaleFactor = 255 / (ColorNumerics.GetColorCountForBitDepth(this.bitDepth) - 1);
Span tempSpan = temp.GetSpan();
// We need to first create an array of luminance bytes then scale them down to the correct bit depth.
@@ -314,7 +314,7 @@ namespace SixLabors.ImageSharp.Formats.Png
for (int x = 0, o = 0; x < rgbaSpan.Length; x++, o += 4)
{
Rgba64 rgba = Unsafe.Add(ref rgbaRef, x);
- ushort luminance = ImageMath.Get16BitBT709Luminance(rgba.R, rgba.G, rgba.B);
+ ushort luminance = ColorNumerics.Get16BitBT709Luminance(rgba.R, rgba.G, rgba.B);
BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o, 2), luminance);
BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o + 2, 2), rgba.A);
}
@@ -329,7 +329,7 @@ namespace SixLabors.ImageSharp.Formats.Png
{
Unsafe.Add(ref rowSpanRef, x).ToRgba32(ref rgba);
Unsafe.Add(ref rawScanlineSpanRef, o) =
- ImageMath.Get8BitBT709Luminance(rgba.R, rgba.G, rgba.B);
+ ColorNumerics.Get8BitBT709Luminance(rgba.R, rgba.G, rgba.B);
Unsafe.Add(ref rawScanlineSpanRef, o + 1) = rgba.A;
}
}
diff --git a/src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs b/src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs
index f1f5145ca..23ca86993 100644
--- a/src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs
+++ b/src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs
@@ -75,7 +75,7 @@ namespace SixLabors.ImageSharp.Formats.Png
if (options.Quantizer is null)
{
byte bits = (byte)options.BitDepth;
- var maxColors = ImageMath.GetColorCountForBitDepth(bits);
+ var maxColors = ColorNumerics.GetColorCountForBitDepth(bits);
options.Quantizer = new WuQuantizer(new QuantizerOptions { MaxColors = maxColors });
}
@@ -101,7 +101,7 @@ namespace SixLabors.ImageSharp.Formats.Png
byte bitDepth;
if (options.ColorType == PngColorType.Palette)
{
- byte quantizedBits = (byte)Numerics.Clamp(ImageMath.GetBitsNeededForColorDepth(quantizedFrame.Palette.Length), 1, 8);
+ byte quantizedBits = (byte)Numerics.Clamp(ColorNumerics.GetBitsNeededForColorDepth(quantizedFrame.Palette.Length), 1, 8);
byte bits = Math.Max((byte)options.BitDepth, quantizedBits);
// Png only supports in four pixel depths: 1, 2, 4, and 8 bits when using the PLTE chunk
diff --git a/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs b/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs
index 16d6aa19f..58fa5aca8 100644
--- a/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs
+++ b/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs
@@ -27,7 +27,7 @@ namespace SixLabors.ImageSharp.Formats.Png
TPixel pixel = default;
ref byte scanlineSpanRef = ref MemoryMarshal.GetReference(scanlineSpan);
ref TPixel rowSpanRef = ref MemoryMarshal.GetReference(rowSpan);
- int scaleFactor = 255 / (ImageMath.GetColorCountForBitDepth(header.BitDepth) - 1);
+ int scaleFactor = 255 / (ColorNumerics.GetColorCountForBitDepth(header.BitDepth) - 1);
if (!hasTrans)
{
@@ -96,7 +96,7 @@ namespace SixLabors.ImageSharp.Formats.Png
TPixel pixel = default;
ref byte scanlineSpanRef = ref MemoryMarshal.GetReference(scanlineSpan);
ref TPixel rowSpanRef = ref MemoryMarshal.GetReference(rowSpan);
- int scaleFactor = 255 / (ImageMath.GetColorCountForBitDepth(header.BitDepth) - 1);
+ int scaleFactor = 255 / (ColorNumerics.GetColorCountForBitDepth(header.BitDepth) - 1);
if (!hasTrans)
{
diff --git a/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs b/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs
index 92474b6fc..1d31ea9f4 100644
--- a/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs
+++ b/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs
@@ -365,7 +365,7 @@ namespace SixLabors.ImageSharp.Formats.Tga
where TPixel : unmanaged, IPixel
{
var vector = sourcePixel.ToVector4();
- return ImageMath.GetBT709Luminance(ref vector, 256);
+ return ColorNumerics.GetBT709Luminance(ref vector, 256);
}
}
}
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs b/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs
index fa08bbe62..77df2bc80 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs
@@ -105,7 +105,7 @@ namespace SixLabors.ImageSharp.PixelFormats
///
[MethodImpl(InliningOptions.ShortMethod)]
- public void FromLa32(La32 source) => this.PackedValue = ImageMath.DownScaleFrom16BitTo8Bit(source.A);
+ public void FromLa32(La32 source) => this.PackedValue = ColorNumerics.DownScaleFrom16BitTo8Bit(source.A);
///
[MethodImpl(InliningOptions.ShortMethod)]
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs
index 9e6db8b70..3ac9b523f 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs
@@ -244,7 +244,7 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromL16(L16 source)
{
- byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.PackedValue);
+ byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(source.PackedValue);
this.R = rgb;
this.G = rgb;
this.B = rgb;
@@ -265,11 +265,11 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromLa32(La32 source)
{
- byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.L);
+ byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(source.L);
this.R = rgb;
this.G = rgb;
this.B = rgb;
- this.A = ImageMath.DownScaleFrom16BitTo8Bit(source.A);
+ this.A = ColorNumerics.DownScaleFrom16BitTo8Bit(source.A);
}
///
@@ -306,9 +306,9 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgb48(Rgb48 source)
{
- this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R);
- this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G);
- this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B);
+ this.R = ColorNumerics.DownScaleFrom16BitTo8Bit(source.R);
+ this.G = ColorNumerics.DownScaleFrom16BitTo8Bit(source.G);
+ this.B = ColorNumerics.DownScaleFrom16BitTo8Bit(source.B);
this.A = byte.MaxValue;
}
@@ -316,10 +316,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgba64(Rgba64 source)
{
- this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R);
- this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G);
- this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B);
- this.A = ImageMath.DownScaleFrom16BitTo8Bit(source.A);
+ this.R = ColorNumerics.DownScaleFrom16BitTo8Bit(source.R);
+ this.G = ColorNumerics.DownScaleFrom16BitTo8Bit(source.G);
+ this.B = ColorNumerics.DownScaleFrom16BitTo8Bit(source.B);
+ this.A = ColorNumerics.DownScaleFrom16BitTo8Bit(source.A);
}
///
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs
index 9063516a3..6cff5fd77 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs
@@ -151,7 +151,7 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromL16(L16 source)
{
- byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.PackedValue);
+ byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(source.PackedValue);
this.R = rgb;
this.G = rgb;
this.B = rgb;
@@ -170,7 +170,7 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromLa32(La32 source)
{
- byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.L);
+ byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(source.L);
this.R = rgb;
this.G = rgb;
this.B = rgb;
@@ -203,18 +203,18 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgb48(Rgb48 source)
{
- this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R);
- this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G);
- this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B);
+ this.R = ColorNumerics.DownScaleFrom16BitTo8Bit(source.R);
+ this.G = ColorNumerics.DownScaleFrom16BitTo8Bit(source.G);
+ this.B = ColorNumerics.DownScaleFrom16BitTo8Bit(source.B);
}
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgba64(Rgba64 source)
{
- this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R);
- this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G);
- this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B);
+ this.R = ColorNumerics.DownScaleFrom16BitTo8Bit(source.R);
+ this.G = ColorNumerics.DownScaleFrom16BitTo8Bit(source.G);
+ this.B = ColorNumerics.DownScaleFrom16BitTo8Bit(source.B);
}
///
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs
index 2058c4e00..190345dda 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs
@@ -197,7 +197,7 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromL16(L16 source)
{
- byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.PackedValue);
+ byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(source.PackedValue);
this.R = rgb;
this.G = rgb;
this.B = rgb;
@@ -218,11 +218,11 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromLa32(La32 source)
{
- byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.L);
+ byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(source.L);
this.R = rgb;
this.G = rgb;
this.B = rgb;
- this.A = ImageMath.DownScaleFrom16BitTo8Bit(source.A);
+ this.A = ColorNumerics.DownScaleFrom16BitTo8Bit(source.A);
}
///
@@ -259,9 +259,9 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgb48(Rgb48 source)
{
- this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R);
- this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G);
- this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B);
+ this.R = ColorNumerics.DownScaleFrom16BitTo8Bit(source.R);
+ this.G = ColorNumerics.DownScaleFrom16BitTo8Bit(source.G);
+ this.B = ColorNumerics.DownScaleFrom16BitTo8Bit(source.B);
this.A = byte.MaxValue;
}
@@ -269,10 +269,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgba64(Rgba64 source)
{
- this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R);
- this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G);
- this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B);
- this.A = ImageMath.DownScaleFrom16BitTo8Bit(source.A);
+ this.R = ColorNumerics.DownScaleFrom16BitTo8Bit(source.R);
+ this.G = ColorNumerics.DownScaleFrom16BitTo8Bit(source.G);
+ this.B = ColorNumerics.DownScaleFrom16BitTo8Bit(source.B);
+ this.A = ColorNumerics.DownScaleFrom16BitTo8Bit(source.A);
}
///
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs b/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs
index cda2f32e8..dd31aae2f 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs
@@ -74,30 +74,30 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromArgb32(Argb32 source)
{
- this.PackedValue = ImageMath.Get16BitBT709Luminance(
- ImageMath.UpscaleFrom8BitTo16Bit(source.R),
- ImageMath.UpscaleFrom8BitTo16Bit(source.G),
- ImageMath.UpscaleFrom8BitTo16Bit(source.B));
+ this.PackedValue = ColorNumerics.Get16BitBT709Luminance(
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.R),
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.G),
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.B));
}
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgr24(Bgr24 source)
{
- this.PackedValue = ImageMath.Get16BitBT709Luminance(
- ImageMath.UpscaleFrom8BitTo16Bit(source.R),
- ImageMath.UpscaleFrom8BitTo16Bit(source.G),
- ImageMath.UpscaleFrom8BitTo16Bit(source.B));
+ this.PackedValue = ColorNumerics.Get16BitBT709Luminance(
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.R),
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.G),
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.B));
}
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source)
{
- this.PackedValue = ImageMath.Get16BitBT709Luminance(
- ImageMath.UpscaleFrom8BitTo16Bit(source.R),
- ImageMath.UpscaleFrom8BitTo16Bit(source.G),
- ImageMath.UpscaleFrom8BitTo16Bit(source.B));
+ this.PackedValue = ColorNumerics.Get16BitBT709Luminance(
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.R),
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.G),
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.B));
}
///
@@ -106,7 +106,7 @@ namespace SixLabors.ImageSharp.PixelFormats
///
[MethodImpl(InliningOptions.ShortMethod)]
- public void FromL8(L8 source) => this.PackedValue = ImageMath.UpscaleFrom8BitTo16Bit(source.PackedValue);
+ public void FromL8(L8 source) => this.PackedValue = ColorNumerics.UpscaleFrom8BitTo16Bit(source.PackedValue);
///
[MethodImpl(InliningOptions.ShortMethod)]
@@ -114,7 +114,7 @@ namespace SixLabors.ImageSharp.PixelFormats
///
[MethodImpl(InliningOptions.ShortMethod)]
- public void FromLa16(La16 source) => this.PackedValue = ImageMath.UpscaleFrom8BitTo16Bit(source.L);
+ public void FromLa16(La16 source) => this.PackedValue = ColorNumerics.UpscaleFrom8BitTo16Bit(source.L);
///
[MethodImpl(InliningOptions.ShortMethod)]
@@ -124,27 +124,27 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgb24(Rgb24 source)
{
- this.PackedValue = ImageMath.Get16BitBT709Luminance(
- ImageMath.UpscaleFrom8BitTo16Bit(source.R),
- ImageMath.UpscaleFrom8BitTo16Bit(source.G),
- ImageMath.UpscaleFrom8BitTo16Bit(source.B));
+ this.PackedValue = ColorNumerics.Get16BitBT709Luminance(
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.R),
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.G),
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.B));
}
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgba32(Rgba32 source)
{
- this.PackedValue = ImageMath.Get16BitBT709Luminance(
- ImageMath.UpscaleFrom8BitTo16Bit(source.R),
- ImageMath.UpscaleFrom8BitTo16Bit(source.G),
- ImageMath.UpscaleFrom8BitTo16Bit(source.B));
+ this.PackedValue = ColorNumerics.Get16BitBT709Luminance(
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.R),
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.G),
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.B));
}
///
[MethodImpl(InliningOptions.ShortMethod)]
public void ToRgba32(ref Rgba32 dest)
{
- byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(this.PackedValue);
+ byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(this.PackedValue);
dest.R = rgb;
dest.G = rgb;
dest.B = rgb;
@@ -153,11 +153,11 @@ namespace SixLabors.ImageSharp.PixelFormats
///
[MethodImpl(InliningOptions.ShortMethod)]
- public void FromRgb48(Rgb48 source) => this.PackedValue = ImageMath.Get16BitBT709Luminance(source.R, source.G, source.B);
+ public void FromRgb48(Rgb48 source) => this.PackedValue = ColorNumerics.Get16BitBT709Luminance(source.R, source.G, source.B);
///
[MethodImpl(InliningOptions.ShortMethod)]
- public void FromRgba64(Rgba64 source) => this.PackedValue = ImageMath.Get16BitBT709Luminance(source.R, source.G, source.B);
+ public void FromRgba64(Rgba64 source) => this.PackedValue = ColorNumerics.Get16BitBT709Luminance(source.R, source.G, source.B);
///
public override readonly bool Equals(object obj) => obj is L16 other && this.Equals(other);
@@ -177,7 +177,7 @@ namespace SixLabors.ImageSharp.PixelFormats
internal void ConvertFromRgbaScaledVector4(Vector4 vector)
{
vector = Numerics.Clamp(vector, Vector4.Zero, Vector4.One) * Max;
- this.PackedValue = ImageMath.Get16BitBT709Luminance(
+ this.PackedValue = ColorNumerics.Get16BitBT709Luminance(
vector.X,
vector.Y,
vector.Z);
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs b/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs
index 938d83feb..c570c33a1 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs
@@ -73,15 +73,15 @@ namespace SixLabors.ImageSharp.PixelFormats
///
[MethodImpl(InliningOptions.ShortMethod)]
- public void FromArgb32(Argb32 source) => this.PackedValue = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B);
+ public void FromArgb32(Argb32 source) => this.PackedValue = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B);
///
[MethodImpl(InliningOptions.ShortMethod)]
- public void FromBgr24(Bgr24 source) => this.PackedValue = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B);
+ public void FromBgr24(Bgr24 source) => this.PackedValue = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B);
///
[MethodImpl(InliningOptions.ShortMethod)]
- public void FromBgra32(Bgra32 source) => this.PackedValue = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B);
+ public void FromBgra32(Bgra32 source) => this.PackedValue = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B);
///
[MethodImpl(InliningOptions.ShortMethod)]
@@ -93,7 +93,7 @@ namespace SixLabors.ImageSharp.PixelFormats
///
[MethodImpl(InliningOptions.ShortMethod)]
- public void FromL16(L16 source) => this.PackedValue = ImageMath.DownScaleFrom16BitTo8Bit(source.PackedValue);
+ public void FromL16(L16 source) => this.PackedValue = ColorNumerics.DownScaleFrom16BitTo8Bit(source.PackedValue);
///
[MethodImpl(InliningOptions.ShortMethod)]
@@ -101,15 +101,15 @@ namespace SixLabors.ImageSharp.PixelFormats
///
[MethodImpl(InliningOptions.ShortMethod)]
- public void FromLa32(La32 source) => this.PackedValue = ImageMath.DownScaleFrom16BitTo8Bit(source.L);
+ public void FromLa32(La32 source) => this.PackedValue = ColorNumerics.DownScaleFrom16BitTo8Bit(source.L);
///
[MethodImpl(InliningOptions.ShortMethod)]
- public void FromRgb24(Rgb24 source) => this.PackedValue = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B);
+ public void FromRgb24(Rgb24 source) => this.PackedValue = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B);
///
[MethodImpl(InliningOptions.ShortMethod)]
- public void FromRgba32(Rgba32 source) => this.PackedValue = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B);
+ public void FromRgba32(Rgba32 source) => this.PackedValue = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B);
///
[MethodImpl(InliningOptions.ShortMethod)]
@@ -124,18 +124,18 @@ namespace SixLabors.ImageSharp.PixelFormats
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgb48(Rgb48 source)
- => this.PackedValue = ImageMath.Get8BitBT709Luminance(
- ImageMath.DownScaleFrom16BitTo8Bit(source.R),
- ImageMath.DownScaleFrom16BitTo8Bit(source.G),
- ImageMath.DownScaleFrom16BitTo8Bit(source.B));
+ => this.PackedValue = ColorNumerics.Get8BitBT709Luminance(
+ ColorNumerics.DownScaleFrom16BitTo8Bit(source.R),
+ ColorNumerics.DownScaleFrom16BitTo8Bit(source.G),
+ ColorNumerics.DownScaleFrom16BitTo8Bit(source.B));
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgba64(Rgba64 source)
- => this.PackedValue = ImageMath.Get8BitBT709Luminance(
- ImageMath.DownScaleFrom16BitTo8Bit(source.R),
- ImageMath.DownScaleFrom16BitTo8Bit(source.G),
- ImageMath.DownScaleFrom16BitTo8Bit(source.B));
+ => this.PackedValue = ColorNumerics.Get8BitBT709Luminance(
+ ColorNumerics.DownScaleFrom16BitTo8Bit(source.R),
+ ColorNumerics.DownScaleFrom16BitTo8Bit(source.G),
+ ColorNumerics.DownScaleFrom16BitTo8Bit(source.B));
///
public override readonly bool Equals(object obj) => obj is L8 other && this.Equals(other);
@@ -157,7 +157,7 @@ namespace SixLabors.ImageSharp.PixelFormats
vector *= MaxBytes;
vector += Half;
vector = Numerics.Clamp(vector, Vector4.Zero, MaxBytes);
- this.PackedValue = ImageMath.Get8BitBT709Luminance((byte)vector.X, (byte)vector.Y, (byte)vector.Z);
+ this.PackedValue = ColorNumerics.Get8BitBT709Luminance((byte)vector.X, (byte)vector.Y, (byte)vector.Z);
}
}
}
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs b/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs
index 21d983494..5a69431a1 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs
@@ -92,7 +92,7 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromArgb32(Argb32 source)
{
- this.L = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B);
+ this.L = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B);
this.A = source.A;
}
@@ -100,7 +100,7 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgr24(Bgr24 source)
{
- this.L = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B);
+ this.L = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B);
this.A = byte.MaxValue;
}
@@ -108,7 +108,7 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source)
{
- this.L = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B);
+ this.L = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B);
this.A = source.A;
}
@@ -120,7 +120,7 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromL16(L16 source)
{
- this.L = ImageMath.DownScaleFrom16BitTo8Bit(source.PackedValue);
+ this.L = ColorNumerics.DownScaleFrom16BitTo8Bit(source.PackedValue);
this.A = byte.MaxValue;
}
@@ -140,15 +140,15 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromLa32(La32 source)
{
- this.L = ImageMath.DownScaleFrom16BitTo8Bit(source.L);
- this.A = ImageMath.DownScaleFrom16BitTo8Bit(source.A);
+ this.L = ColorNumerics.DownScaleFrom16BitTo8Bit(source.L);
+ this.A = ColorNumerics.DownScaleFrom16BitTo8Bit(source.A);
}
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgb24(Rgb24 source)
{
- this.L = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B);
+ this.L = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B);
this.A = byte.MaxValue;
}
@@ -156,10 +156,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgb48(Rgb48 source)
{
- this.L = ImageMath.Get8BitBT709Luminance(
- ImageMath.DownScaleFrom16BitTo8Bit(source.R),
- ImageMath.DownScaleFrom16BitTo8Bit(source.G),
- ImageMath.DownScaleFrom16BitTo8Bit(source.B));
+ this.L = ColorNumerics.Get8BitBT709Luminance(
+ ColorNumerics.DownScaleFrom16BitTo8Bit(source.R),
+ ColorNumerics.DownScaleFrom16BitTo8Bit(source.G),
+ ColorNumerics.DownScaleFrom16BitTo8Bit(source.B));
this.A = byte.MaxValue;
}
@@ -168,19 +168,19 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgba32(Rgba32 source)
{
- this.L = ImageMath.Get8BitBT709Luminance(source.R, source.G, source.B);
+ this.L = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B);
this.A = source.A;
}
///
public void FromRgba64(Rgba64 source)
{
- this.L = ImageMath.Get8BitBT709Luminance(
- ImageMath.DownScaleFrom16BitTo8Bit(source.R),
- ImageMath.DownScaleFrom16BitTo8Bit(source.G),
- ImageMath.DownScaleFrom16BitTo8Bit(source.B));
+ this.L = ColorNumerics.Get8BitBT709Luminance(
+ ColorNumerics.DownScaleFrom16BitTo8Bit(source.R),
+ ColorNumerics.DownScaleFrom16BitTo8Bit(source.G),
+ ColorNumerics.DownScaleFrom16BitTo8Bit(source.B));
- this.A = ImageMath.DownScaleFrom16BitTo8Bit(source.A);
+ this.A = ColorNumerics.DownScaleFrom16BitTo8Bit(source.A);
}
///
@@ -220,7 +220,7 @@ namespace SixLabors.ImageSharp.PixelFormats
vector *= MaxBytes;
vector += Half;
vector = Numerics.Clamp(vector, Vector4.Zero, MaxBytes);
- this.L = ImageMath.Get8BitBT709Luminance((byte)vector.X, (byte)vector.Y, (byte)vector.Z);
+ this.L = ColorNumerics.Get8BitBT709Luminance((byte)vector.X, (byte)vector.Y, (byte)vector.Z);
this.A = (byte)vector.W;
}
}
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs
index 319775061..66d0e38c7 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs
@@ -95,22 +95,22 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromArgb32(Argb32 source)
{
- this.L = ImageMath.Get16BitBT709Luminance(
- ImageMath.UpscaleFrom8BitTo16Bit(source.R),
- ImageMath.UpscaleFrom8BitTo16Bit(source.G),
- ImageMath.UpscaleFrom8BitTo16Bit(source.B));
+ this.L = ColorNumerics.Get16BitBT709Luminance(
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.R),
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.G),
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.B));
- this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A);
+ this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A);
}
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgr24(Bgr24 source)
{
- this.L = ImageMath.Get16BitBT709Luminance(
- ImageMath.UpscaleFrom8BitTo16Bit(source.R),
- ImageMath.UpscaleFrom8BitTo16Bit(source.G),
- ImageMath.UpscaleFrom8BitTo16Bit(source.B));
+ this.L = ColorNumerics.Get16BitBT709Luminance(
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.R),
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.G),
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.B));
this.A = ushort.MaxValue;
}
@@ -119,12 +119,12 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source)
{
- this.L = ImageMath.Get16BitBT709Luminance(
- ImageMath.UpscaleFrom8BitTo16Bit(source.R),
- ImageMath.UpscaleFrom8BitTo16Bit(source.G),
- ImageMath.UpscaleFrom8BitTo16Bit(source.B));
+ this.L = ColorNumerics.Get16BitBT709Luminance(
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.R),
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.G),
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.B));
- this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A);
+ this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A);
}
///
@@ -143,7 +143,7 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromL8(L8 source)
{
- this.L = ImageMath.UpscaleFrom8BitTo16Bit(source.PackedValue);
+ this.L = ColorNumerics.UpscaleFrom8BitTo16Bit(source.PackedValue);
this.A = ushort.MaxValue;
}
@@ -151,8 +151,8 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromLa16(La16 source)
{
- this.L = ImageMath.UpscaleFrom8BitTo16Bit(source.L);
- this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A);
+ this.L = ColorNumerics.UpscaleFrom8BitTo16Bit(source.L);
+ this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A);
}
///
@@ -163,10 +163,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgb24(Rgb24 source)
{
- this.L = ImageMath.Get16BitBT709Luminance(
- ImageMath.UpscaleFrom8BitTo16Bit(source.R),
- ImageMath.UpscaleFrom8BitTo16Bit(source.G),
- ImageMath.UpscaleFrom8BitTo16Bit(source.B));
+ this.L = ColorNumerics.Get16BitBT709Luminance(
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.R),
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.G),
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.B));
this.A = ushort.MaxValue;
}
@@ -175,7 +175,7 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgb48(Rgb48 source)
{
- this.L = ImageMath.Get16BitBT709Luminance(source.R, source.G, source.B);
+ this.L = ColorNumerics.Get16BitBT709Luminance(source.R, source.G, source.B);
this.A = ushort.MaxValue;
}
@@ -183,19 +183,19 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgba32(Rgba32 source)
{
- this.L = ImageMath.Get16BitBT709Luminance(
- ImageMath.UpscaleFrom8BitTo16Bit(source.R),
- ImageMath.UpscaleFrom8BitTo16Bit(source.G),
- ImageMath.UpscaleFrom8BitTo16Bit(source.B));
+ this.L = ColorNumerics.Get16BitBT709Luminance(
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.R),
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.G),
+ ColorNumerics.UpscaleFrom8BitTo16Bit(source.B));
- this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A);
+ this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A);
}
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgba64(Rgba64 source)
{
- this.L = ImageMath.Get16BitBT709Luminance(source.R, source.G, source.B);
+ this.L = ColorNumerics.Get16BitBT709Luminance(source.R, source.G, source.B);
this.A = source.A;
}
@@ -211,11 +211,11 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void ToRgba32(ref Rgba32 dest)
{
- byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(this.L);
+ byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(this.L);
dest.R = rgb;
dest.G = rgb;
dest.B = rgb;
- dest.A = ImageMath.DownScaleFrom16BitTo8Bit(this.A);
+ dest.A = ColorNumerics.DownScaleFrom16BitTo8Bit(this.A);
}
///
@@ -234,7 +234,7 @@ namespace SixLabors.ImageSharp.PixelFormats
internal void ConvertFromRgbaScaledVector4(Vector4 vector)
{
vector = Numerics.Clamp(vector, Vector4.Zero, Vector4.One) * Max;
- this.L = ImageMath.Get16BitBT709Luminance(
+ this.L = ColorNumerics.Get16BitBT709Luminance(
vector.X,
vector.Y,
vector.Z);
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs
index b7e831cfa..7fd63c676 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs
@@ -166,7 +166,7 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromL16(L16 source)
{
- byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.PackedValue);
+ byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(source.PackedValue);
this.R = rgb;
this.G = rgb;
this.B = rgb;
@@ -185,7 +185,7 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromLa32(La32 source)
{
- byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.L);
+ byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(source.L);
this.R = rgb;
this.G = rgb;
this.B = rgb;
@@ -227,18 +227,18 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgb48(Rgb48 source)
{
- this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R);
- this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G);
- this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B);
+ this.R = ColorNumerics.DownScaleFrom16BitTo8Bit(source.R);
+ this.G = ColorNumerics.DownScaleFrom16BitTo8Bit(source.G);
+ this.B = ColorNumerics.DownScaleFrom16BitTo8Bit(source.B);
}
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgba64(Rgba64 source)
{
- this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R);
- this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G);
- this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B);
+ this.R = ColorNumerics.DownScaleFrom16BitTo8Bit(source.R);
+ this.G = ColorNumerics.DownScaleFrom16BitTo8Bit(source.G);
+ this.B = ColorNumerics.DownScaleFrom16BitTo8Bit(source.B);
}
///
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs
index 23297806d..e3738b70c 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs
@@ -99,27 +99,27 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromArgb32(Argb32 source)
{
- this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R);
- this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G);
- this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B);
+ this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R);
+ this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G);
+ this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B);
}
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgr24(Bgr24 source)
{
- this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R);
- this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G);
- this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B);
+ this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R);
+ this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G);
+ this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B);
}
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source)
{
- this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R);
- this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G);
- this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B);
+ this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R);
+ this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G);
+ this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B);
}
///
@@ -134,7 +134,7 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromL8(L8 source)
{
- ushort rgb = ImageMath.UpscaleFrom8BitTo16Bit(source.PackedValue);
+ ushort rgb = ColorNumerics.UpscaleFrom8BitTo16Bit(source.PackedValue);
this.R = rgb;
this.G = rgb;
this.B = rgb;
@@ -153,7 +153,7 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromLa16(La16 source)
{
- ushort rgb = ImageMath.UpscaleFrom8BitTo16Bit(source.L);
+ ushort rgb = ColorNumerics.UpscaleFrom8BitTo16Bit(source.L);
this.R = rgb;
this.G = rgb;
this.B = rgb;
@@ -172,27 +172,27 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgb24(Rgb24 source)
{
- this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R);
- this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G);
- this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B);
+ this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R);
+ this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G);
+ this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B);
}
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgba32(Rgba32 source)
{
- this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R);
- this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G);
- this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B);
+ this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R);
+ this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G);
+ this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B);
}
///
[MethodImpl(InliningOptions.ShortMethod)]
public void ToRgba32(ref Rgba32 dest)
{
- dest.R = ImageMath.DownScaleFrom16BitTo8Bit(this.R);
- dest.G = ImageMath.DownScaleFrom16BitTo8Bit(this.G);
- dest.B = ImageMath.DownScaleFrom16BitTo8Bit(this.B);
+ dest.R = ColorNumerics.DownScaleFrom16BitTo8Bit(this.R);
+ dest.G = ColorNumerics.DownScaleFrom16BitTo8Bit(this.G);
+ dest.B = ColorNumerics.DownScaleFrom16BitTo8Bit(this.B);
dest.A = byte.MaxValue;
}
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs
index 19c1bd083..868165e9c 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs
@@ -351,7 +351,7 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromL16(L16 source)
{
- byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.PackedValue);
+ byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(source.PackedValue);
this.R = rgb;
this.G = rgb;
this.B = rgb;
@@ -372,11 +372,11 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromLa32(La32 source)
{
- byte rgb = ImageMath.DownScaleFrom16BitTo8Bit(source.L);
+ byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(source.L);
this.R = rgb;
this.G = rgb;
this.B = rgb;
- this.A = ImageMath.DownScaleFrom16BitTo8Bit(source.A);
+ this.A = ColorNumerics.DownScaleFrom16BitTo8Bit(source.A);
}
///
@@ -402,9 +402,9 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgb48(Rgb48 source)
{
- this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R);
- this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G);
- this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B);
+ this.R = ColorNumerics.DownScaleFrom16BitTo8Bit(source.R);
+ this.G = ColorNumerics.DownScaleFrom16BitTo8Bit(source.G);
+ this.B = ColorNumerics.DownScaleFrom16BitTo8Bit(source.B);
this.A = byte.MaxValue;
}
@@ -412,10 +412,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgba64(Rgba64 source)
{
- this.R = ImageMath.DownScaleFrom16BitTo8Bit(source.R);
- this.G = ImageMath.DownScaleFrom16BitTo8Bit(source.G);
- this.B = ImageMath.DownScaleFrom16BitTo8Bit(source.B);
- this.A = ImageMath.DownScaleFrom16BitTo8Bit(source.A);
+ this.R = ColorNumerics.DownScaleFrom16BitTo8Bit(source.R);
+ this.G = ColorNumerics.DownScaleFrom16BitTo8Bit(source.G);
+ this.B = ColorNumerics.DownScaleFrom16BitTo8Bit(source.B);
+ this.A = ColorNumerics.DownScaleFrom16BitTo8Bit(source.A);
}
///
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs
index f8b40d7e0..9add3d718 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs
@@ -62,10 +62,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public Rgba64(Rgba32 source)
{
- this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R);
- this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G);
- this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B);
- this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A);
+ this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R);
+ this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G);
+ this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B);
+ this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A);
}
///
@@ -75,10 +75,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public Rgba64(Bgra32 source)
{
- this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R);
- this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G);
- this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B);
- this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A);
+ this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R);
+ this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G);
+ this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B);
+ this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A);
}
///
@@ -88,10 +88,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public Rgba64(Argb32 source)
{
- this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R);
- this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G);
- this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B);
- this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A);
+ this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R);
+ this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G);
+ this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B);
+ this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A);
}
///
@@ -101,9 +101,9 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public Rgba64(Rgb24 source)
{
- this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R);
- this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G);
- this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B);
+ this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R);
+ this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G);
+ this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B);
this.A = ushort.MaxValue;
}
@@ -114,9 +114,9 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public Rgba64(Bgr24 source)
{
- this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R);
- this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G);
- this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B);
+ this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R);
+ this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G);
+ this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B);
this.A = ushort.MaxValue;
}
@@ -224,19 +224,19 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromArgb32(Argb32 source)
{
- this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R);
- this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G);
- this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B);
- this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A);
+ this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R);
+ this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G);
+ this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B);
+ this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A);
}
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgr24(Bgr24 source)
{
- this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R);
- this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G);
- this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B);
+ this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R);
+ this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G);
+ this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B);
this.A = ushort.MaxValue;
}
@@ -244,10 +244,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source)
{
- this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R);
- this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G);
- this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B);
- this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A);
+ this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R);
+ this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G);
+ this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B);
+ this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A);
}
///
@@ -258,7 +258,7 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromL8(L8 source)
{
- ushort rgb = ImageMath.UpscaleFrom8BitTo16Bit(source.PackedValue);
+ ushort rgb = ColorNumerics.UpscaleFrom8BitTo16Bit(source.PackedValue);
this.R = rgb;
this.G = rgb;
this.B = rgb;
@@ -279,11 +279,11 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromLa16(La16 source)
{
- ushort rgb = ImageMath.UpscaleFrom8BitTo16Bit(source.L);
+ ushort rgb = ColorNumerics.UpscaleFrom8BitTo16Bit(source.L);
this.R = rgb;
this.G = rgb;
this.B = rgb;
- this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A);
+ this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A);
}
///
@@ -300,9 +300,9 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgb24(Rgb24 source)
{
- this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R);
- this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G);
- this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B);
+ this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R);
+ this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G);
+ this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B);
this.A = ushort.MaxValue;
}
@@ -310,20 +310,20 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgba32(Rgba32 source)
{
- this.R = ImageMath.UpscaleFrom8BitTo16Bit(source.R);
- this.G = ImageMath.UpscaleFrom8BitTo16Bit(source.G);
- this.B = ImageMath.UpscaleFrom8BitTo16Bit(source.B);
- this.A = ImageMath.UpscaleFrom8BitTo16Bit(source.A);
+ this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R);
+ this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G);
+ this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B);
+ this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A);
}
///
[MethodImpl(InliningOptions.ShortMethod)]
public void ToRgba32(ref Rgba32 dest)
{
- dest.R = ImageMath.DownScaleFrom16BitTo8Bit(this.R);
- dest.G = ImageMath.DownScaleFrom16BitTo8Bit(this.G);
- dest.B = ImageMath.DownScaleFrom16BitTo8Bit(this.B);
- dest.A = ImageMath.DownScaleFrom16BitTo8Bit(this.A);
+ dest.R = ColorNumerics.DownScaleFrom16BitTo8Bit(this.R);
+ dest.G = ColorNumerics.DownScaleFrom16BitTo8Bit(this.G);
+ dest.B = ColorNumerics.DownScaleFrom16BitTo8Bit(this.B);
+ dest.A = ColorNumerics.DownScaleFrom16BitTo8Bit(this.A);
}
///
@@ -345,10 +345,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public readonly Rgba32 ToRgba32()
{
- byte r = ImageMath.DownScaleFrom16BitTo8Bit(this.R);
- byte g = ImageMath.DownScaleFrom16BitTo8Bit(this.G);
- byte b = ImageMath.DownScaleFrom16BitTo8Bit(this.B);
- byte a = ImageMath.DownScaleFrom16BitTo8Bit(this.A);
+ byte r = ColorNumerics.DownScaleFrom16BitTo8Bit(this.R);
+ byte g = ColorNumerics.DownScaleFrom16BitTo8Bit(this.G);
+ byte b = ColorNumerics.DownScaleFrom16BitTo8Bit(this.B);
+ byte a = ColorNumerics.DownScaleFrom16BitTo8Bit(this.A);
return new Rgba32(r, g, b, a);
}
@@ -359,10 +359,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public readonly Bgra32 ToBgra32()
{
- byte r = ImageMath.DownScaleFrom16BitTo8Bit(this.R);
- byte g = ImageMath.DownScaleFrom16BitTo8Bit(this.G);
- byte b = ImageMath.DownScaleFrom16BitTo8Bit(this.B);
- byte a = ImageMath.DownScaleFrom16BitTo8Bit(this.A);
+ byte r = ColorNumerics.DownScaleFrom16BitTo8Bit(this.R);
+ byte g = ColorNumerics.DownScaleFrom16BitTo8Bit(this.G);
+ byte b = ColorNumerics.DownScaleFrom16BitTo8Bit(this.B);
+ byte a = ColorNumerics.DownScaleFrom16BitTo8Bit(this.A);
return new Bgra32(r, g, b, a);
}
@@ -373,10 +373,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public readonly Argb32 ToArgb32()
{
- byte r = ImageMath.DownScaleFrom16BitTo8Bit(this.R);
- byte g = ImageMath.DownScaleFrom16BitTo8Bit(this.G);
- byte b = ImageMath.DownScaleFrom16BitTo8Bit(this.B);
- byte a = ImageMath.DownScaleFrom16BitTo8Bit(this.A);
+ byte r = ColorNumerics.DownScaleFrom16BitTo8Bit(this.R);
+ byte g = ColorNumerics.DownScaleFrom16BitTo8Bit(this.G);
+ byte b = ColorNumerics.DownScaleFrom16BitTo8Bit(this.B);
+ byte a = ColorNumerics.DownScaleFrom16BitTo8Bit(this.A);
return new Argb32(r, g, b, a);
}
@@ -387,9 +387,9 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public readonly Rgb24 ToRgb24()
{
- byte r = ImageMath.DownScaleFrom16BitTo8Bit(this.R);
- byte g = ImageMath.DownScaleFrom16BitTo8Bit(this.G);
- byte b = ImageMath.DownScaleFrom16BitTo8Bit(this.B);
+ byte r = ColorNumerics.DownScaleFrom16BitTo8Bit(this.R);
+ byte g = ColorNumerics.DownScaleFrom16BitTo8Bit(this.G);
+ byte b = ColorNumerics.DownScaleFrom16BitTo8Bit(this.B);
return new Rgb24(r, g, b);
}
@@ -400,9 +400,9 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public readonly Bgr24 ToBgr24()
{
- byte r = ImageMath.DownScaleFrom16BitTo8Bit(this.R);
- byte g = ImageMath.DownScaleFrom16BitTo8Bit(this.G);
- byte b = ImageMath.DownScaleFrom16BitTo8Bit(this.B);
+ byte r = ColorNumerics.DownScaleFrom16BitTo8Bit(this.R);
+ byte g = ColorNumerics.DownScaleFrom16BitTo8Bit(this.G);
+ byte b = ColorNumerics.DownScaleFrom16BitTo8Bit(this.B);
return new Bgr24(r, g, b);
}
diff --git a/src/ImageSharp/PixelFormats/Utils/Vector4Converters.cs b/src/ImageSharp/PixelFormats/Utils/Vector4Converters.cs
index 977722b81..acc2725ce 100644
--- a/src/ImageSharp/PixelFormats/Utils/Vector4Converters.cs
+++ b/src/ImageSharp/PixelFormats/Utils/Vector4Converters.cs
@@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.PixelFormats.Utils
if (modifiers.IsDefined(PixelConversionModifiers.Premultiply))
{
- Vector4Utils.Premultiply(vectors);
+ Numerics.Premultiply(vectors);
}
}
@@ -36,7 +36,7 @@ namespace SixLabors.ImageSharp.PixelFormats.Utils
{
if (modifiers.IsDefined(PixelConversionModifiers.Premultiply))
{
- Vector4Utils.UnPremultiply(vectors);
+ Numerics.UnPremultiply(vectors);
}
if (modifiers.IsDefined(PixelConversionModifiers.SRgbCompand))
diff --git a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs
index a47937baf..df95b6f1b 100644
--- a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs
@@ -96,7 +96,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization
color.ToRgba32(ref rgba);
// Convert to grayscale using ITU-R Recommendation BT.709 if required
- byte luminance = this.isAlphaOnly ? rgba.A : ImageMath.Get8BitBT709Luminance(rgba.R, rgba.G, rgba.B);
+ byte luminance = this.isAlphaOnly ? rgba.A : ColorNumerics.Get8BitBT709Luminance(rgba.R, rgba.G, rgba.B);
color = luminance >= this.threshold ? this.upper : this.lower;
}
}
diff --git a/src/ImageSharp/Processing/Processors/Dithering/OrderedDither.cs b/src/ImageSharp/Processing/Processors/Dithering/OrderedDither.cs
index 0f3c20f5e..9b99a5257 100644
--- a/src/ImageSharp/Processing/Processors/Dithering/OrderedDither.cs
+++ b/src/ImageSharp/Processing/Processors/Dithering/OrderedDither.cs
@@ -218,7 +218,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
this.source = source;
this.destination = destination;
this.bounds = bounds;
- this.bitDepth = ImageMath.GetBitsNeededForColorDepth(destination.Palette.Length);
+ this.bitDepth = ColorNumerics.GetBitsNeededForColorDepth(destination.Palette.Length);
}
[MethodImpl(InliningOptions.ShortMethod)]
@@ -262,7 +262,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
this.source = source;
this.bounds = bounds;
this.scale = processor.DitherScale;
- this.bitDepth = ImageMath.GetBitsNeededForColorDepth(processor.Palette.Length);
+ this.bitDepth = ColorNumerics.GetBitsNeededForColorDepth(processor.Palette.Length);
}
[MethodImpl(InliningOptions.ShortMethod)]
diff --git a/src/ImageSharp/Processing/Processors/Filters/FilterProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Filters/FilterProcessor{TPixel}.cs
index e28d4add7..4dc9e4196 100644
--- a/src/ImageSharp/Processing/Processors/Filters/FilterProcessor{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Filters/FilterProcessor{TPixel}.cs
@@ -74,7 +74,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
Span rowSpan = this.source.GetPixelRowSpan(y).Slice(this.startX, span.Length);
PixelOperations.Instance.ToVector4(this.configuration, rowSpan, span);
- Vector4Utils.Transform(span, ref Unsafe.AsRef(this.matrix));
+ ColorNumerics.Transform(span, ref Unsafe.AsRef(this.matrix));
PixelOperations.Instance.FromVector4Destructive(this.configuration, span, rowSpan);
}
diff --git a/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs
index 255812078..b9383e331 100644
--- a/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs
@@ -259,7 +259,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization
{
for (int idx = 0; idx < length; idx++)
{
- int luminance = ImageMath.GetBT709Luminance(ref Unsafe.Add(ref greyValuesBase, idx), luminanceLevels);
+ int luminance = ColorNumerics.GetBT709Luminance(ref Unsafe.Add(ref greyValuesBase, idx), luminanceLevels);
Unsafe.Add(ref histogramBase, luminance)++;
}
}
@@ -276,7 +276,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization
{
for (int idx = 0; idx < length; idx++)
{
- int luminance = ImageMath.GetBT709Luminance(ref Unsafe.Add(ref greyValuesBase, idx), luminanceLevels);
+ int luminance = ColorNumerics.GetBT709Luminance(ref Unsafe.Add(ref greyValuesBase, idx), luminanceLevels);
Unsafe.Add(ref histogramBase, luminance)--;
}
}
diff --git a/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs
index b45773e9a..70d3e075d 100644
--- a/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs
@@ -123,7 +123,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization
{
// TODO: We should bulk convert here.
var vector = pixelRow[x].ToVector4();
- int luminance = ImageMath.GetBT709Luminance(ref vector, levels);
+ int luminance = ColorNumerics.GetBT709Luminance(ref vector, levels);
Interlocked.Increment(ref Unsafe.Add(ref histogramBase, luminance));
}
}
@@ -174,7 +174,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization
// TODO: We should bulk convert here.
ref TPixel pixel = ref pixelRow[x];
var vector = pixel.ToVector4();
- int luminance = ImageMath.GetBT709Luminance(ref vector, levels);
+ int luminance = ColorNumerics.GetBT709Luminance(ref vector, levels);
float luminanceEqualized = Unsafe.Add(ref cdfBase, luminance) / noOfPixelsMinusCdfMin;
pixel.FromVector4(new Vector4(luminanceEqualized, luminanceEqualized, luminanceEqualized, vector.W));
}
diff --git a/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor{TPixel}.cs
index 3bba95bc6..59df3058d 100644
--- a/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor{TPixel}.cs
@@ -143,7 +143,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization
public static int GetLuminance(TPixel sourcePixel, int luminanceLevels)
{
var vector = sourcePixel.ToVector4();
- return ImageMath.GetBT709Luminance(ref vector, luminanceLevels);
+ return ColorNumerics.GetBT709Luminance(ref vector, luminanceLevels);
}
}
}
diff --git a/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs
index 1e1d1c953..6b64da1c9 100644
--- a/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs
@@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
this.Options = options;
this.maxColors = this.Options.MaxColors;
- this.octree = new Octree(Numerics.Clamp(ImageMath.GetBitsNeededForColorDepth(this.maxColors), 1, 8));
+ this.octree = new Octree(Numerics.Clamp(ColorNumerics.GetBitsNeededForColorDepth(this.maxColors), 1, 8));
this.paletteOwner = configuration.MemoryAllocator.Allocate(this.maxColors, AllocationOptions.Clean);
this.palette = default;
this.pixelMap = default;
diff --git a/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor{TPixel}.cs
index 27d40e77b..675d6fe0d 100644
--- a/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor{TPixel}.cs
@@ -1,6 +1,8 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
+using System;
+using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors.Binarization;
@@ -48,7 +50,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
new BinaryThresholdProcessor(this.definition.Threshold).Execute(this.Configuration, temp, this.SourceRectangle);
// Search for the first white pixels
- rectangle = ImageMath.GetFilteredBoundingRectangle(temp.Frames.RootFrame, 0);
+ rectangle = GetFilteredBoundingRectangle(temp.Frames.RootFrame, 0);
}
new CropProcessor(rectangle, this.Source.Size()).Execute(this.Configuration, this.Source, this.SourceRectangle);
@@ -61,5 +63,136 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
{
// All processing happens at the image level within BeforeImageApply();
}
+
+ ///
+ /// Gets the bounding from the given points.
+ ///
+ ///
+ /// The designating the top left position.
+ ///
+ ///
+ /// The designating the bottom right position.
+ ///
+ ///
+ /// The bounding .
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private static Rectangle GetBoundingRectangle(Point topLeft, Point bottomRight)
+ => new Rectangle(
+ topLeft.X,
+ topLeft.Y,
+ bottomRight.X - topLeft.X,
+ bottomRight.Y - topLeft.Y);
+
+ ///
+ /// Finds the bounding rectangle based on the first instance of any color component other
+ /// than the given one.
+ ///
+ /// The to search within.
+ /// The color component value to remove.
+ /// The channel to test against.
+ ///
+ /// The .
+ ///
+ private static Rectangle GetFilteredBoundingRectangle(ImageFrame bitmap, float componentValue, RgbaComponent channel = RgbaComponent.B)
+ {
+ int width = bitmap.Width;
+ int height = bitmap.Height;
+ Point topLeft = default;
+ Point bottomRight = default;
+
+ Func, int, int, float, bool> delegateFunc;
+
+ // Determine which channel to check against
+ switch (channel)
+ {
+ case RgbaComponent.R:
+ delegateFunc = (pixels, x, y, b) => MathF.Abs(pixels[x, y].ToVector4().X - b) > Constants.Epsilon;
+ break;
+
+ case RgbaComponent.G:
+ delegateFunc = (pixels, x, y, b) => MathF.Abs(pixels[x, y].ToVector4().Y - b) > Constants.Epsilon;
+ break;
+
+ case RgbaComponent.B:
+ delegateFunc = (pixels, x, y, b) => MathF.Abs(pixels[x, y].ToVector4().Z - b) > Constants.Epsilon;
+ break;
+
+ default:
+ delegateFunc = (pixels, x, y, b) => MathF.Abs(pixels[x, y].ToVector4().W - b) > Constants.Epsilon;
+ break;
+ }
+
+ int GetMinY(ImageFrame pixels)
+ {
+ for (int y = 0; y < height; y++)
+ {
+ for (int x = 0; x < width; x++)
+ {
+ if (delegateFunc(pixels, x, y, componentValue))
+ {
+ return y;
+ }
+ }
+ }
+
+ return 0;
+ }
+
+ int GetMaxY(ImageFrame pixels)
+ {
+ for (int y = height - 1; y > -1; y--)
+ {
+ for (int x = 0; x < width; x++)
+ {
+ if (delegateFunc(pixels, x, y, componentValue))
+ {
+ return y;
+ }
+ }
+ }
+
+ return height;
+ }
+
+ int GetMinX(ImageFrame pixels)
+ {
+ for (int x = 0; x < width; x++)
+ {
+ for (int y = 0; y < height; y++)
+ {
+ if (delegateFunc(pixels, x, y, componentValue))
+ {
+ return x;
+ }
+ }
+ }
+
+ return 0;
+ }
+
+ int GetMaxX(ImageFrame pixels)
+ {
+ for (int x = width - 1; x > -1; x--)
+ {
+ for (int y = 0; y < height; y++)
+ {
+ if (delegateFunc(pixels, x, y, componentValue))
+ {
+ return x;
+ }
+ }
+ }
+
+ return width;
+ }
+
+ topLeft.Y = GetMinY(bitmap);
+ topLeft.X = GetMinX(bitmap);
+ bottomRight.Y = Numerics.Clamp(GetMaxY(bitmap) + 1, 0, height);
+ bottomRight.X = Numerics.Clamp(GetMaxX(bitmap) + 1, 0, width);
+
+ return GetBoundingRectangle(topLeft, bottomRight);
+ }
}
}
diff --git a/src/ImageSharp/Processing/Processors/Transforms/Linear/LinearTransformUtils.cs b/src/ImageSharp/Processing/Processors/Transforms/Linear/LinearTransformUtils.cs
index 07e784ec5..e65b2cbe9 100644
--- a/src/ImageSharp/Processing/Processors/Transforms/Linear/LinearTransformUtils.cs
+++ b/src/ImageSharp/Processing/Processors/Transforms/Linear/LinearTransformUtils.cs
@@ -78,13 +78,13 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
// Values are first premultiplied to prevent darkening of edge pixels.
var current = sourcePixels[x, y].ToVector4();
- Vector4Utils.Premultiply(ref current);
+ Numerics.Premultiply(ref current);
sum += current * xWeight * yWeight;
}
}
// Reverse the premultiplication
- Vector4Utils.UnPremultiply(ref sum);
+ Numerics.UnPremultiply(ref sum);
targetRow[column] = sum;
}
diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/PremultiplyVector4.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/PremultiplyVector4.cs
index d441b5e0b..b88f5090b 100644
--- a/tests/ImageSharp.Benchmarks/Color/Bulk/PremultiplyVector4.cs
+++ b/tests/ImageSharp.Benchmarks/Color/Bulk/PremultiplyVector4.cs
@@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk
[Benchmark]
public void Premultiply()
{
- Vector4Utils.Premultiply(Vectors);
+ Numerics.Premultiply(Vectors);
}
[MethodImpl(InliningOptions.ShortMethod)]
diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/UnPremultiplyVector4.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/UnPremultiplyVector4.cs
index 819f34b92..aa73bc3d0 100644
--- a/tests/ImageSharp.Benchmarks/Color/Bulk/UnPremultiplyVector4.cs
+++ b/tests/ImageSharp.Benchmarks/Color/Bulk/UnPremultiplyVector4.cs
@@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk
[Benchmark]
public void UnPremultiply()
{
- Vector4Utils.UnPremultiply(Vectors);
+ Numerics.UnPremultiply(Vectors);
}
[MethodImpl(InliningOptions.ShortMethod)]
diff --git a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs
index cd5e3a5e4..11bab17fb 100644
--- a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs
+++ b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs
@@ -435,7 +435,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
Rgba32 expectedColor = Color.Blue;
if (colorType == PngColorType.Grayscale || colorType == PngColorType.GrayscaleWithAlpha)
{
- var luminance = ImageMath.Get8BitBT709Luminance(expectedColor.R, expectedColor.G, expectedColor.B);
+ var luminance = ColorNumerics.Get8BitBT709Luminance(expectedColor.R, expectedColor.G, expectedColor.B);
expectedColor = new Rgba32(luminance, luminance, luminance);
}
diff --git a/tests/ImageSharp.Tests/Helpers/ImageMathTests.cs b/tests/ImageSharp.Tests/Helpers/ColorNumericsTests.cs
similarity index 79%
rename from tests/ImageSharp.Tests/Helpers/ImageMathTests.cs
rename to tests/ImageSharp.Tests/Helpers/ColorNumericsTests.cs
index 687c13fd5..7d7f5f15a 100644
--- a/tests/ImageSharp.Tests/Helpers/ImageMathTests.cs
+++ b/tests/ImageSharp.Tests/Helpers/ColorNumericsTests.cs
@@ -7,7 +7,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Helpers
{
- public class ImageMathTests
+ public class ColorNumericsTests
{
[Theory]
[InlineData(0.2f, 0.7f, 0.1f, 256, 140)]
@@ -20,12 +20,12 @@ namespace SixLabors.ImageSharp.Tests.Helpers
var vector = new Vector4(x, y, z, 0.0f);
// act
- int actual = ImageMath.GetBT709Luminance(ref vector, luminanceLevels);
+ int actual = ColorNumerics.GetBT709Luminance(ref vector, luminanceLevels);
// assert
Assert.Equal(expected, actual);
}
- // TODO: We need to test all ImageMaths methods!
+ // TODO: We need to test all ColorNumerics methods!
}
}
diff --git a/tests/ImageSharp.Tests/Helpers/NumericsTests.cs b/tests/ImageSharp.Tests/Helpers/NumericsTests.cs
index f1678cfa1..98363b751 100644
--- a/tests/ImageSharp.Tests/Helpers/NumericsTests.cs
+++ b/tests/ImageSharp.Tests/Helpers/NumericsTests.cs
@@ -2,13 +2,17 @@
// Licensed under the Apache License, Version 2.0.
using System;
+using System.Linq;
+using System.Numerics;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Helpers
{
public class NumericsTests
{
- public delegate void SpanAction(Span span, TArg arg, TArg1 arg1);
+ private delegate void SpanAction(Span span, TArg arg, TArg1 arg1);
+
+ private readonly ApproximateFloatComparer approximateFloatComparer = new ApproximateFloatComparer(1e-6f);
[Theory]
[InlineData(0)]
@@ -154,6 +158,46 @@ namespace SixLabors.ImageSharp.Tests.Helpers
Assert.Equal(expected, actual);
}
+ [Theory]
+ [InlineData(0)]
+ [InlineData(1)]
+ [InlineData(30)]
+ [InlineData(63)]
+ public void PremultiplyVectorSpan(int length)
+ {
+ var rnd = new Random(42);
+ Vector4[] source = rnd.GenerateRandomVectorArray(length, 0, 1);
+ Vector4[] expected = source.Select(v =>
+ {
+ Numerics.Premultiply(ref v);
+ return v;
+ }).ToArray();
+
+ Numerics.Premultiply(source);
+
+ Assert.Equal(expected, source, this.approximateFloatComparer);
+ }
+
+ [Theory]
+ [InlineData(0)]
+ [InlineData(1)]
+ [InlineData(30)]
+ [InlineData(63)]
+ public void UnPremultiplyVectorSpan(int length)
+ {
+ var rnd = new Random(42);
+ Vector4[] source = rnd.GenerateRandomVectorArray(length, 0, 1);
+ Vector4[] expected = source.Select(v =>
+ {
+ Numerics.UnPremultiply(ref v);
+ return v;
+ }).ToArray();
+
+ Numerics.UnPremultiply(source);
+
+ Assert.Equal(expected, source, this.approximateFloatComparer);
+ }
+
[Theory]
[InlineData(64, 36, 96)]
[InlineData(128, 16, 196)]
diff --git a/tests/ImageSharp.Tests/Helpers/Vector4UtilsTests.cs b/tests/ImageSharp.Tests/Helpers/Vector4UtilsTests.cs
deleted file mode 100644
index 605aa7d5a..000000000
--- a/tests/ImageSharp.Tests/Helpers/Vector4UtilsTests.cs
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-using System.Linq;
-using System.Numerics;
-
-using Xunit;
-
-namespace SixLabors.ImageSharp.Tests.Helpers
-{
- public class Vector4UtilsTests
- {
- private readonly ApproximateFloatComparer approximateFloatComparer = new ApproximateFloatComparer(1e-6f);
-
- [Theory]
- [InlineData(0)]
- [InlineData(1)]
- [InlineData(30)]
- [InlineData(63)]
- public void Premultiply_VectorSpan(int length)
- {
- var rnd = new Random(42);
- Vector4[] source = rnd.GenerateRandomVectorArray(length, 0, 1);
- Vector4[] expected = source.Select(v =>
- {
- Vector4Utils.Premultiply(ref v);
- return v;
- }).ToArray();
-
- Vector4Utils.Premultiply(source);
-
- Assert.Equal(expected, source, this.approximateFloatComparer);
- }
-
- [Theory]
- [InlineData(0)]
- [InlineData(1)]
- [InlineData(30)]
- [InlineData(63)]
- public void UnPremultiply_VectorSpan(int length)
- {
- var rnd = new Random(42);
- Vector4[] source = rnd.GenerateRandomVectorArray(length, 0, 1);
- Vector4[] expected = source.Select(v =>
- {
- Vector4Utils.UnPremultiply(ref v);
- return v;
- }).ToArray();
-
- Vector4Utils.UnPremultiply(source);
-
- Assert.Equal(expected, source, this.approximateFloatComparer);
- }
- }
-}
diff --git a/tests/ImageSharp.Tests/PixelFormats/L16Tests.cs b/tests/ImageSharp.Tests/PixelFormats/L16Tests.cs
index 113a39bff..453eac568 100644
--- a/tests/ImageSharp.Tests/PixelFormats/L16Tests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/L16Tests.cs
@@ -113,8 +113,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
// Arrange
L16 gray = default;
const byte rgb = 128;
- ushort scaledRgb = ImageMath.UpscaleFrom8BitTo16Bit(rgb);
- ushort expected = ImageMath.Get16BitBT709Luminance(scaledRgb, scaledRgb, scaledRgb);
+ ushort scaledRgb = ColorNumerics.UpscaleFrom8BitTo16Bit(rgb);
+ ushort expected = ColorNumerics.Get16BitBT709Luminance(scaledRgb, scaledRgb, scaledRgb);
// Act
gray.FromRgba32(new Rgba32(rgb, rgb, rgb));
@@ -131,7 +131,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
public void L16_ToRgba32(ushort input)
{
// Arrange
- ushort expected = ImageMath.DownScaleFrom16BitTo8Bit(input);
+ ushort expected = ColorNumerics.DownScaleFrom16BitTo8Bit(input);
var gray = new L16(input);
// Act
diff --git a/tests/ImageSharp.Tests/PixelFormats/L8Tests.cs b/tests/ImageSharp.Tests/PixelFormats/L8Tests.cs
index 798eb3b1a..a0895df12 100644
--- a/tests/ImageSharp.Tests/PixelFormats/L8Tests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/L8Tests.cs
@@ -136,7 +136,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
{
// Arrange
L8 gray = default;
- byte expected = ImageMath.Get8BitBT709Luminance(rgb, rgb, rgb);
+ byte expected = ColorNumerics.Get8BitBT709Luminance(rgb, rgb, rgb);
// Act
gray.FromRgba32(new Rgba32(rgb, rgb, rgb));
diff --git a/tests/ImageSharp.Tests/PixelFormats/La16Tests.cs b/tests/ImageSharp.Tests/PixelFormats/La16Tests.cs
index 46d7d09b4..b241adb20 100644
--- a/tests/ImageSharp.Tests/PixelFormats/La16Tests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/La16Tests.cs
@@ -138,7 +138,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
{
// Arrange
La16 gray = default;
- byte expected = ImageMath.Get8BitBT709Luminance(rgb, rgb, rgb);
+ byte expected = ColorNumerics.Get8BitBT709Luminance(rgb, rgb, rgb);
// Act
gray.FromRgba32(new Rgba32(rgb, rgb, rgb));
diff --git a/tests/ImageSharp.Tests/PixelFormats/La32Tests.cs b/tests/ImageSharp.Tests/PixelFormats/La32Tests.cs
index 159abac4a..6d1b595c7 100644
--- a/tests/ImageSharp.Tests/PixelFormats/La32Tests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/La32Tests.cs
@@ -117,8 +117,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
// Arrange
La32 gray = default;
const byte rgb = 128;
- ushort scaledRgb = ImageMath.UpscaleFrom8BitTo16Bit(rgb);
- ushort expected = ImageMath.Get16BitBT709Luminance(scaledRgb, scaledRgb, scaledRgb);
+ ushort scaledRgb = ColorNumerics.UpscaleFrom8BitTo16Bit(rgb);
+ ushort expected = ColorNumerics.Get16BitBT709Luminance(scaledRgb, scaledRgb, scaledRgb);
// Act
gray.FromRgba32(new Rgba32(rgb, rgb, rgb));
@@ -136,7 +136,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
public void La32_ToRgba32(ushort input)
{
// Arrange
- ushort expected = ImageMath.DownScaleFrom16BitTo8Bit(input);
+ ushort expected = ColorNumerics.DownScaleFrom16BitTo8Bit(input);
var gray = new La32(input, ushort.MaxValue);
// Act
diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs
index e56cfe226..0d83e2e7f 100644
--- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs
@@ -197,7 +197,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
{
if (this.HasUnassociatedAlpha)
{
- Vector4Utils.Premultiply(ref v);
+ Numerics.Premultiply(ref v);
}
}
@@ -205,7 +205,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
{
if (this.HasUnassociatedAlpha)
{
- Vector4Utils.UnPremultiply(ref v);
+ Numerics.UnPremultiply(ref v);
}
}
@@ -232,7 +232,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
{
if (this.HasUnassociatedAlpha)
{
- Vector4Utils.Premultiply(ref v);
+ Numerics.Premultiply(ref v);
}
}
@@ -240,7 +240,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
{
if (this.HasUnassociatedAlpha)
{
- Vector4Utils.UnPremultiply(ref v);
+ Numerics.UnPremultiply(ref v);
}
}
@@ -273,7 +273,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
if (this.HasUnassociatedAlpha)
{
- Vector4Utils.Premultiply(ref v);
+ Numerics.Premultiply(ref v);
}
}
@@ -281,7 +281,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
{
if (this.HasUnassociatedAlpha)
{
- Vector4Utils.UnPremultiply(ref v);
+ Numerics.UnPremultiply(ref v);
}
SRgbCompanding.Compress(ref v);
@@ -394,12 +394,12 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
{
void SourceAction(ref Vector4 v)
{
- Vector4Utils.UnPremultiply(ref v);
+ Numerics.UnPremultiply(ref v);
}
void ExpectedAction(ref Vector4 v)
{
- Vector4Utils.Premultiply(ref v);
+ Numerics.Premultiply(ref v);
}
TPixel[] source = CreatePixelTestData(count, (ref Vector4 v) => SourceAction(ref v));
@@ -417,12 +417,12 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
{
void SourceAction(ref Vector4 v)
{
- Vector4Utils.UnPremultiply(ref v);
+ Numerics.UnPremultiply(ref v);
}
void ExpectedAction(ref Vector4 v)
{
- Vector4Utils.Premultiply(ref v);
+ Numerics.Premultiply(ref v);
}
TPixel[] source = CreateScaledPixelTestData(count, (ref Vector4 v) => SourceAction(ref v));
@@ -444,14 +444,14 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
{
void SourceAction(ref Vector4 v)
{
- Vector4Utils.UnPremultiply(ref v);
+ Numerics.UnPremultiply(ref v);
SRgbCompanding.Compress(ref v);
}
void ExpectedAction(ref Vector4 v)
{
SRgbCompanding.Expand(ref v);
- Vector4Utils.Premultiply(ref v);
+ Numerics.Premultiply(ref v);
}
TPixel[] source = CreateScaledPixelTestData(count, (ref Vector4 v) => SourceAction(ref v));