diff --git a/src/ImageProcessorCore/Colors/Color.cs b/src/ImageProcessorCore/Colors/Color.cs index f4b774e25..36cb548fb 100644 --- a/src/ImageProcessorCore/Colors/Color.cs +++ b/src/ImageProcessorCore/Colors/Color.cs @@ -84,9 +84,7 @@ namespace ImageProcessorCore float a = Convert.ToByte(hex.Substring(0, 2), 16); // Do division of Vector4 instead of each component to utilize SIMD optimizations - this.backingVector = new Vector4(r, g, b, a) / 255f; - - this.backingVector = FromNonPremultiplied(this.backingVector, this.A); + this.backingVector = FromNonPremultiplied(new Vector4(r, g, b, a) / 255f, this.A); } else if (hex.Length == 6) diff --git a/src/ImageProcessorCore/Colors/Colorspaces/CieLab.cs b/src/ImageProcessorCore/Colors/Colorspaces/CieLab.cs index 2f684e45c..cce92601a 100644 --- a/src/ImageProcessorCore/Colors/Colorspaces/CieLab.cs +++ b/src/ImageProcessorCore/Colors/Colorspaces/CieLab.cs @@ -172,9 +172,11 @@ namespace ImageProcessorCore /// public bool AlmostEquals(CieLab other, float precision) { - return Math.Abs(this.L - other.L) < precision - && Math.Abs(this.B - other.B) < precision - && Math.Abs(this.B - other.B) < precision; + Vector3 result = Vector3.Abs(this.backingVector - other.backingVector); + + return result.X < precision + && result.Y < precision + && result.Z < precision; } /// diff --git a/src/ImageProcessorCore/Colors/Colorspaces/CieXyz.cs b/src/ImageProcessorCore/Colors/Colorspaces/CieXyz.cs index a14c04bdd..8f41c8abb 100644 --- a/src/ImageProcessorCore/Colors/Colorspaces/CieXyz.cs +++ b/src/ImageProcessorCore/Colors/Colorspaces/CieXyz.cs @@ -163,9 +163,11 @@ namespace ImageProcessorCore /// public bool AlmostEquals(CieXyz other, float precision) { - return Math.Abs(this.X - other.X) < precision - && Math.Abs(this.Y - other.Y) < precision - && Math.Abs(this.Z - other.Z) < precision; + Vector3 result = Vector3.Abs(this.backingVector - other.backingVector); + + return result.X < precision + && result.Y < precision + && result.Z < precision; } /// diff --git a/src/ImageProcessorCore/Colors/Colorspaces/Cmyk.cs b/src/ImageProcessorCore/Colors/Colorspaces/Cmyk.cs index 1d8e8d852..b343288a6 100644 --- a/src/ImageProcessorCore/Colors/Colorspaces/Cmyk.cs +++ b/src/ImageProcessorCore/Colors/Colorspaces/Cmyk.cs @@ -175,10 +175,12 @@ namespace ImageProcessorCore /// public bool AlmostEquals(Cmyk other, float precision) { - return Math.Abs(this.C - other.C) < precision - && Math.Abs(this.M - other.M) < precision - && Math.Abs(this.Y - other.Y) < precision - && Math.Abs(this.K - other.K) < precision; + Vector4 result = Vector4.Abs(this.backingVector - other.backingVector); + + return result.X < precision + && result.Y < precision + && result.Z < precision + && result.W < precision; } /// diff --git a/src/ImageProcessorCore/Colors/Colorspaces/Hsl.cs b/src/ImageProcessorCore/Colors/Colorspaces/Hsl.cs index e585ecf4d..e6eee42e3 100644 --- a/src/ImageProcessorCore/Colors/Colorspaces/Hsl.cs +++ b/src/ImageProcessorCore/Colors/Colorspaces/Hsl.cs @@ -192,9 +192,11 @@ namespace ImageProcessorCore /// public bool AlmostEquals(Hsl other, float precision) { - return Math.Abs(this.H - other.H) < precision - && Math.Abs(this.S - other.S) < precision - && Math.Abs(this.L - other.L) < precision; + Vector3 result = Vector3.Abs(this.backingVector - other.backingVector); + + return result.X < precision + && result.Y < precision + && result.Z < precision; } /// diff --git a/src/ImageProcessorCore/Colors/Colorspaces/Hsv.cs b/src/ImageProcessorCore/Colors/Colorspaces/Hsv.cs index 8ce2183de..914df51c9 100644 --- a/src/ImageProcessorCore/Colors/Colorspaces/Hsv.cs +++ b/src/ImageProcessorCore/Colors/Colorspaces/Hsv.cs @@ -186,9 +186,11 @@ namespace ImageProcessorCore /// public bool AlmostEquals(Hsv other, float precision) { - return Math.Abs(this.H - other.H) < precision - && Math.Abs(this.S - other.S) < precision - && Math.Abs(this.V - other.V) < precision; + Vector3 result = Vector3.Abs(this.backingVector - other.backingVector); + + return result.X < precision + && result.Y < precision + && result.Z < precision; } /// diff --git a/src/ImageProcessorCore/Colors/Colorspaces/YCbCr.cs b/src/ImageProcessorCore/Colors/Colorspaces/YCbCr.cs index 5cef084cc..5c47c6c08 100644 --- a/src/ImageProcessorCore/Colors/Colorspaces/YCbCr.cs +++ b/src/ImageProcessorCore/Colors/Colorspaces/YCbCr.cs @@ -162,9 +162,11 @@ namespace ImageProcessorCore /// public bool AlmostEquals(YCbCr other, float precision) { - return Math.Abs(this.Y - other.Y) < precision - && Math.Abs(this.Cb - other.Cb) < precision - && Math.Abs(this.Cr - other.Cr) < precision; + Vector3 result = Vector3.Abs(this.backingVector - other.backingVector); + + return result.X < precision + && result.Y < precision + && result.Z < precision; } ///