diff --git a/src/ImageSharp/Common/Helpers/ColorNumerics.cs b/src/ImageSharp/Common/Helpers/ColorNumerics.cs
index 47c4b296bd..128092b427 100644
--- a/src/ImageSharp/Common/Helpers/ColorNumerics.cs
+++ b/src/ImageSharp/Common/Helpers/ColorNumerics.cs
@@ -137,6 +137,23 @@ internal static class ColorNumerics
public static int GetColorCountForBitDepth(int bitDepth)
=> 1 << bitDepth;
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ internal static Vector4 Transform(Vector4 vector, in ColorMatrix.Impl matrix)
+ {
+ Vector4 result = matrix.X * vector.X;
+
+ result += matrix.Y * vector.Y;
+ result += matrix.Z * vector.Z;
+ result += matrix.W * vector.W;
+
+ result.X += matrix.V.X;
+ result.Y += matrix.V.Y;
+ result.Z += matrix.V.Z;
+ result.W += matrix.V.W;
+
+ return result;
+ }
+
///
/// Transforms a vector by the given color matrix.
///
@@ -144,17 +161,7 @@ internal static class ColorNumerics
/// 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;
- }
+ => vector = Transform(vector, matrix.AsImpl());
///
/// Bulk variant of .