From 4cfe946cf8ce988934a62ea706aeea44b55d8741 Mon Sep 17 00:00:00 2001 From: Olivia Date: Wed, 28 Dec 2016 11:07:32 +0200 Subject: [PATCH 1/6] Fixing namespace for Color spaces. --- src/ImageSharp/Colors/ColorspaceTransforms.cs | 1 + src/ImageSharp/Colors/{Colorspaces => Spaces}/Bgra32.cs | 2 +- src/ImageSharp/Colors/{Colorspaces => Spaces}/CieLab.cs | 2 +- src/ImageSharp/Colors/{Colorspaces => Spaces}/CieXyz.cs | 2 +- src/ImageSharp/Colors/{Colorspaces => Spaces}/Cmyk.cs | 2 +- src/ImageSharp/Colors/{Colorspaces => Spaces}/Hsl.cs | 2 +- src/ImageSharp/Colors/{Colorspaces => Spaces}/Hsv.cs | 2 +- .../Colors/{Colorspaces => Spaces}/IAlmostEquatable.cs | 2 +- src/ImageSharp/Colors/{Colorspaces => Spaces}/YCbCr.cs | 2 +- tests/ImageSharp.Tests/Colors/ColorConversionTests.cs | 2 +- 10 files changed, 10 insertions(+), 9 deletions(-) rename src/ImageSharp/Colors/{Colorspaces => Spaces}/Bgra32.cs (99%) rename src/ImageSharp/Colors/{Colorspaces => Spaces}/CieLab.cs (99%) rename src/ImageSharp/Colors/{Colorspaces => Spaces}/CieXyz.cs (99%) rename src/ImageSharp/Colors/{Colorspaces => Spaces}/Cmyk.cs (99%) rename src/ImageSharp/Colors/{Colorspaces => Spaces}/Hsl.cs (99%) rename src/ImageSharp/Colors/{Colorspaces => Spaces}/Hsv.cs (99%) rename src/ImageSharp/Colors/{Colorspaces => Spaces}/IAlmostEquatable.cs (97%) rename src/ImageSharp/Colors/{Colorspaces => Spaces}/YCbCr.cs (99%) diff --git a/src/ImageSharp/Colors/ColorspaceTransforms.cs b/src/ImageSharp/Colors/ColorspaceTransforms.cs index 0c70dd98b1..7315b9e9d2 100644 --- a/src/ImageSharp/Colors/ColorspaceTransforms.cs +++ b/src/ImageSharp/Colors/ColorspaceTransforms.cs @@ -7,6 +7,7 @@ namespace ImageSharp { using System; using System.Numerics; + using Colors.Spaces; /// /// Packed vector type containing four 8-bit unsigned normalized values ranging from 0 to 255. diff --git a/src/ImageSharp/Colors/Colorspaces/Bgra32.cs b/src/ImageSharp/Colors/Spaces/Bgra32.cs similarity index 99% rename from src/ImageSharp/Colors/Colorspaces/Bgra32.cs rename to src/ImageSharp/Colors/Spaces/Bgra32.cs index ff9203b03a..e590b9e388 100644 --- a/src/ImageSharp/Colors/Colorspaces/Bgra32.cs +++ b/src/ImageSharp/Colors/Spaces/Bgra32.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.Colors.Spaces { using System; using System.ComponentModel; diff --git a/src/ImageSharp/Colors/Colorspaces/CieLab.cs b/src/ImageSharp/Colors/Spaces/CieLab.cs similarity index 99% rename from src/ImageSharp/Colors/Colorspaces/CieLab.cs rename to src/ImageSharp/Colors/Spaces/CieLab.cs index e3300f3b87..78aa0dc70d 100644 --- a/src/ImageSharp/Colors/Colorspaces/CieLab.cs +++ b/src/ImageSharp/Colors/Spaces/CieLab.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.Colors.Spaces { using System; using System.ComponentModel; diff --git a/src/ImageSharp/Colors/Colorspaces/CieXyz.cs b/src/ImageSharp/Colors/Spaces/CieXyz.cs similarity index 99% rename from src/ImageSharp/Colors/Colorspaces/CieXyz.cs rename to src/ImageSharp/Colors/Spaces/CieXyz.cs index 16d5cb8275..3a8704171d 100644 --- a/src/ImageSharp/Colors/Colorspaces/CieXyz.cs +++ b/src/ImageSharp/Colors/Spaces/CieXyz.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.Colors.Spaces { using System; using System.ComponentModel; diff --git a/src/ImageSharp/Colors/Colorspaces/Cmyk.cs b/src/ImageSharp/Colors/Spaces/Cmyk.cs similarity index 99% rename from src/ImageSharp/Colors/Colorspaces/Cmyk.cs rename to src/ImageSharp/Colors/Spaces/Cmyk.cs index 15bea263cc..9e0f10898b 100644 --- a/src/ImageSharp/Colors/Colorspaces/Cmyk.cs +++ b/src/ImageSharp/Colors/Spaces/Cmyk.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.Colors.Spaces { using System; using System.ComponentModel; diff --git a/src/ImageSharp/Colors/Colorspaces/Hsl.cs b/src/ImageSharp/Colors/Spaces/Hsl.cs similarity index 99% rename from src/ImageSharp/Colors/Colorspaces/Hsl.cs rename to src/ImageSharp/Colors/Spaces/Hsl.cs index 1cc54ec8c3..8c1d293021 100644 --- a/src/ImageSharp/Colors/Colorspaces/Hsl.cs +++ b/src/ImageSharp/Colors/Spaces/Hsl.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.Colors.Spaces { using System; using System.ComponentModel; diff --git a/src/ImageSharp/Colors/Colorspaces/Hsv.cs b/src/ImageSharp/Colors/Spaces/Hsv.cs similarity index 99% rename from src/ImageSharp/Colors/Colorspaces/Hsv.cs rename to src/ImageSharp/Colors/Spaces/Hsv.cs index b55e07e6bd..eebf034ce9 100644 --- a/src/ImageSharp/Colors/Colorspaces/Hsv.cs +++ b/src/ImageSharp/Colors/Spaces/Hsv.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.Colors.Spaces { using System; using System.ComponentModel; diff --git a/src/ImageSharp/Colors/Colorspaces/IAlmostEquatable.cs b/src/ImageSharp/Colors/Spaces/IAlmostEquatable.cs similarity index 97% rename from src/ImageSharp/Colors/Colorspaces/IAlmostEquatable.cs rename to src/ImageSharp/Colors/Spaces/IAlmostEquatable.cs index 1163657edb..a2183d396c 100644 --- a/src/ImageSharp/Colors/Colorspaces/IAlmostEquatable.cs +++ b/src/ImageSharp/Colors/Spaces/IAlmostEquatable.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.Colors.Spaces { using System; diff --git a/src/ImageSharp/Colors/Colorspaces/YCbCr.cs b/src/ImageSharp/Colors/Spaces/YCbCr.cs similarity index 99% rename from src/ImageSharp/Colors/Colorspaces/YCbCr.cs rename to src/ImageSharp/Colors/Spaces/YCbCr.cs index c9a0872c51..8d94ebccaf 100644 --- a/src/ImageSharp/Colors/Colorspaces/YCbCr.cs +++ b/src/ImageSharp/Colors/Spaces/YCbCr.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.Colors.Spaces { using System; using System.ComponentModel; diff --git a/tests/ImageSharp.Tests/Colors/ColorConversionTests.cs b/tests/ImageSharp.Tests/Colors/ColorConversionTests.cs index f1b6d5f9b5..4884557522 100644 --- a/tests/ImageSharp.Tests/Colors/ColorConversionTests.cs +++ b/tests/ImageSharp.Tests/Colors/ColorConversionTests.cs @@ -7,7 +7,7 @@ namespace ImageSharp.Tests { using System; using System.Diagnostics.CodeAnalysis; - + using ImageSharp.Colors.Spaces; using Xunit; /// From 6fcd81158fa825787d28b3de9e9837d503c8b846 Mon Sep 17 00:00:00 2001 From: Olivia Date: Wed, 28 Dec 2016 12:42:37 +0200 Subject: [PATCH 2/6] Adding backing vector3 to YCbCr. --- src/ImageSharp/Colors/ColorspaceTransforms.cs | 12 +++--- src/ImageSharp/Colors/Spaces/YCbCr.cs | 37 ++++++++++++------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/ImageSharp/Colors/ColorspaceTransforms.cs b/src/ImageSharp/Colors/ColorspaceTransforms.cs index 7315b9e9d2..3994e2407b 100644 --- a/src/ImageSharp/Colors/ColorspaceTransforms.cs +++ b/src/ImageSharp/Colors/ColorspaceTransforms.cs @@ -63,13 +63,13 @@ namespace ImageSharp /// public static implicit operator Color(YCbCr color) { - byte y = color.Y; - int cb = color.Cb - 128; - int cr = color.Cr - 128; + float y = color.Y; + float cb = color.Cb - 128; + float cr = color.Cr - 128; - byte r = (byte)(y + (1.402F * cr)).Clamp(0, 255); - byte g = (byte)(y - (0.34414F * cb) - (0.71414F * cr)).Clamp(0, 255); - byte b = (byte)(y + (1.772F * cb)).Clamp(0, 255); + float r = (y + (1.402F * cr)).Clamp(0, 255); + float g = (y - (0.34414F * cb) - (0.71414F * cr)).Clamp(0, 255); + float b = (y + (1.772F * cb)).Clamp(0, 255); return new Color(r, g, b); } diff --git a/src/ImageSharp/Colors/Spaces/YCbCr.cs b/src/ImageSharp/Colors/Spaces/YCbCr.cs index 8d94ebccaf..ada36c831e 100644 --- a/src/ImageSharp/Colors/Spaces/YCbCr.cs +++ b/src/ImageSharp/Colors/Spaces/YCbCr.cs @@ -7,6 +7,7 @@ namespace ImageSharp.Colors.Spaces { using System; using System.ComponentModel; + using System.Numerics; /// /// Represents an YCbCr (luminance, blue chroma, red chroma) color conforming to the full range standard used in digital imaging systems. @@ -19,6 +20,11 @@ namespace ImageSharp.Colors.Spaces /// public static readonly YCbCr Empty = default(YCbCr); + /// + /// The backing vector for SIMD support. + /// + private Vector3 backingVector; + /// /// Initializes a new instance of the struct. /// @@ -28,28 +34,26 @@ namespace ImageSharp.Colors.Spaces public YCbCr(byte y, byte cb, byte cr) : this() { - this.Y = y; - this.Cb = cb; - this.Cr = cr; + this.backingVector = Vector3.Clamp(new Vector3(y, cb, cr), Vector3.Zero, new Vector3(255)); } /// /// Gets the Y luminance component. /// A value ranging between 0 and 255. /// - public byte Y { get; } + public float Y => this.backingVector.X; /// /// Gets the Cb chroma component. /// A value ranging between 0 and 255. /// - public byte Cb { get; } + public float Cb => this.backingVector.Y; /// /// Gets the Cr chroma component. /// A value ranging between 0 and 255. /// - public byte Cr { get; } + public float Cr => this.backingVector.Z; /// /// Gets a value indicating whether this is empty. @@ -117,13 +121,7 @@ namespace ImageSharp.Colors.Spaces /// public override int GetHashCode() { - unchecked - { - int hashCode = this.Y.GetHashCode(); - hashCode = (hashCode * 397) ^ this.Cb.GetHashCode(); - hashCode = (hashCode * 397) ^ this.Cr.GetHashCode(); - return hashCode; - } + return GetHashCode(this); } /// @@ -151,7 +149,18 @@ namespace ImageSharp.Colors.Spaces /// public bool Equals(YCbCr other) { - return this.Y == other.Y && this.Cb == other.Cb && this.Cr == other.Cr; + return this.backingVector.Equals(other.backingVector); } + + /// + /// Returns the hash code for this instance. + /// + /// + /// The instance of to return the hash code for. + /// + /// + /// A 32-bit signed integer that is the hash code for this instance. + /// + private static int GetHashCode(YCbCr color) => color.backingVector.GetHashCode(); } } \ No newline at end of file From 51cee78385053a678bbfdee838be14cef4848e7d Mon Sep 17 00:00:00 2001 From: Olivia Date: Wed, 28 Dec 2016 12:46:36 +0200 Subject: [PATCH 3/6] Fixing conversion. --- src/ImageSharp/Colors/ColorspaceTransforms.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ImageSharp/Colors/ColorspaceTransforms.cs b/src/ImageSharp/Colors/ColorspaceTransforms.cs index 3994e2407b..9785a888f4 100644 --- a/src/ImageSharp/Colors/ColorspaceTransforms.cs +++ b/src/ImageSharp/Colors/ColorspaceTransforms.cs @@ -67,9 +67,9 @@ namespace ImageSharp float cb = color.Cb - 128; float cr = color.Cr - 128; - float r = (y + (1.402F * cr)).Clamp(0, 255); - float g = (y - (0.34414F * cb) - (0.71414F * cr)).Clamp(0, 255); - float b = (y + (1.772F * cb)).Clamp(0, 255); + byte r = (byte)(y + (1.402F * cr)).Clamp(0, 255); + byte g = (byte)(y - (0.34414F * cb) - (0.71414F * cr)).Clamp(0, 255); + byte b = (byte)(y + (1.772F * cb)).Clamp(0, 255); return new Color(r, g, b); } From cdaf4d869b4077147f93f170f414e11d1066b581 Mon Sep 17 00:00:00 2001 From: Olivia Date: Wed, 28 Dec 2016 13:26:07 +0200 Subject: [PATCH 4/6] Removing unnecessary GetHashCode indirection. --- src/ImageSharp/Colors/Spaces/Bgra32.cs | 13 +------------ src/ImageSharp/Colors/Spaces/CieLab.cs | 13 +------------ src/ImageSharp/Colors/Spaces/CieXyz.cs | 13 +------------ src/ImageSharp/Colors/Spaces/Cmyk.cs | 13 +------------ src/ImageSharp/Colors/Spaces/Hsl.cs | 13 +------------ src/ImageSharp/Colors/Spaces/Hsv.cs | 13 +------------ src/ImageSharp/Colors/Spaces/YCbCr.cs | 13 +------------ 7 files changed, 7 insertions(+), 84 deletions(-) diff --git a/src/ImageSharp/Colors/Spaces/Bgra32.cs b/src/ImageSharp/Colors/Spaces/Bgra32.cs index e590b9e388..4325b1cd64 100644 --- a/src/ImageSharp/Colors/Spaces/Bgra32.cs +++ b/src/ImageSharp/Colors/Spaces/Bgra32.cs @@ -133,7 +133,7 @@ namespace ImageSharp.Colors.Spaces /// public override int GetHashCode() { - return GetHashCode(this); + return this.backingVector.GetHashCode(); } /// @@ -152,16 +152,5 @@ namespace ImageSharp.Colors.Spaces { return this.backingVector.Equals(other.backingVector); } - - /// - /// Returns the hash code for this instance. - /// - /// - /// The instance of to return the hash code for. - /// - /// - /// A 32-bit signed integer that is the hash code for this instance. - /// - private static int GetHashCode(Bgra32 color) => color.backingVector.GetHashCode(); } } diff --git a/src/ImageSharp/Colors/Spaces/CieLab.cs b/src/ImageSharp/Colors/Spaces/CieLab.cs index 78aa0dc70d..505c7a6905 100644 --- a/src/ImageSharp/Colors/Spaces/CieLab.cs +++ b/src/ImageSharp/Colors/Spaces/CieLab.cs @@ -138,7 +138,7 @@ namespace ImageSharp.Colors.Spaces /// public override int GetHashCode() { - return GetHashCode(this); + return this.backingVector.GetHashCode(); } /// @@ -178,16 +178,5 @@ namespace ImageSharp.Colors.Spaces && result.Y < precision && result.Z < precision; } - - /// - /// Returns the hash code for this instance. - /// - /// - /// The instance of to return the hash code for. - /// - /// - /// A 32-bit signed integer that is the hash code for this instance. - /// - private static int GetHashCode(CieLab color) => color.backingVector.GetHashCode(); } } diff --git a/src/ImageSharp/Colors/Spaces/CieXyz.cs b/src/ImageSharp/Colors/Spaces/CieXyz.cs index 3a8704171d..2dd063163a 100644 --- a/src/ImageSharp/Colors/Spaces/CieXyz.cs +++ b/src/ImageSharp/Colors/Spaces/CieXyz.cs @@ -129,7 +129,7 @@ namespace ImageSharp.Colors.Spaces /// public override int GetHashCode() { - return GetHashCode(this); + return this.backingVector.GetHashCode(); } /// @@ -169,16 +169,5 @@ namespace ImageSharp.Colors.Spaces && result.Y < precision && result.Z < precision; } - - /// - /// Returns the hash code for this instance. - /// - /// - /// The instance of to return the hash code for. - /// - /// - /// A 32-bit signed integer that is the hash code for this instance. - /// - private static int GetHashCode(CieXyz color) => color.backingVector.GetHashCode(); } } diff --git a/src/ImageSharp/Colors/Spaces/Cmyk.cs b/src/ImageSharp/Colors/Spaces/Cmyk.cs index 9e0f10898b..48bd5c83a0 100644 --- a/src/ImageSharp/Colors/Spaces/Cmyk.cs +++ b/src/ImageSharp/Colors/Spaces/Cmyk.cs @@ -139,7 +139,7 @@ namespace ImageSharp.Colors.Spaces /// public override int GetHashCode() { - return GetHashCode(this); + return this.backingVector.GetHashCode(); } /// @@ -180,16 +180,5 @@ namespace ImageSharp.Colors.Spaces && result.Z < precision && result.W < precision; } - - /// - /// Returns the hash code for this instance. - /// - /// - /// The instance of to return the hash code for. - /// - /// - /// A 32-bit signed integer that is the hash code for this instance. - /// - private static int GetHashCode(Cmyk color) => color.backingVector.GetHashCode(); } } diff --git a/src/ImageSharp/Colors/Spaces/Hsl.cs b/src/ImageSharp/Colors/Spaces/Hsl.cs index 8c1d293021..67a0ef094e 100644 --- a/src/ImageSharp/Colors/Spaces/Hsl.cs +++ b/src/ImageSharp/Colors/Spaces/Hsl.cs @@ -158,7 +158,7 @@ namespace ImageSharp.Colors.Spaces /// public override int GetHashCode() { - return GetHashCode(this); + return this.backingVector.GetHashCode(); } /// @@ -198,16 +198,5 @@ namespace ImageSharp.Colors.Spaces && result.Y < precision && result.Z < precision; } - - /// - /// Returns the hash code for this instance. - /// - /// - /// The instance of to return the hash code for. - /// - /// - /// A 32-bit signed integer that is the hash code for this instance. - /// - private static int GetHashCode(Hsl color) => color.backingVector.GetHashCode(); } } diff --git a/src/ImageSharp/Colors/Spaces/Hsv.cs b/src/ImageSharp/Colors/Spaces/Hsv.cs index eebf034ce9..4cd382e782 100644 --- a/src/ImageSharp/Colors/Spaces/Hsv.cs +++ b/src/ImageSharp/Colors/Spaces/Hsv.cs @@ -151,7 +151,7 @@ namespace ImageSharp.Colors.Spaces /// public override int GetHashCode() { - return GetHashCode(this); + return this.backingVector.GetHashCode(); } /// @@ -191,16 +191,5 @@ namespace ImageSharp.Colors.Spaces && result.Y < precision && result.Z < precision; } - - /// - /// Returns the hash code for this instance. - /// - /// - /// The instance of to return the hash code for. - /// - /// - /// A 32-bit signed integer that is the hash code for this instance. - /// - private static int GetHashCode(Hsv color) => color.backingVector.GetHashCode(); } } diff --git a/src/ImageSharp/Colors/Spaces/YCbCr.cs b/src/ImageSharp/Colors/Spaces/YCbCr.cs index ada36c831e..a91fdb2d67 100644 --- a/src/ImageSharp/Colors/Spaces/YCbCr.cs +++ b/src/ImageSharp/Colors/Spaces/YCbCr.cs @@ -121,7 +121,7 @@ namespace ImageSharp.Colors.Spaces /// public override int GetHashCode() { - return GetHashCode(this); + return this.backingVector.GetHashCode(); } /// @@ -151,16 +151,5 @@ namespace ImageSharp.Colors.Spaces { return this.backingVector.Equals(other.backingVector); } - - /// - /// Returns the hash code for this instance. - /// - /// - /// The instance of to return the hash code for. - /// - /// - /// A 32-bit signed integer that is the hash code for this instance. - /// - private static int GetHashCode(YCbCr color) => color.backingVector.GetHashCode(); } } \ No newline at end of file From cb8dc38dd6953ad4816a35c7b47ac0b18a7f4824 Mon Sep 17 00:00:00 2001 From: Olivia Date: Wed, 28 Dec 2016 13:36:12 +0200 Subject: [PATCH 5/6] Making backing vectors readonly. --- src/ImageSharp/Colors/Spaces/Bgra32.cs | 2 +- src/ImageSharp/Colors/Spaces/CieLab.cs | 2 +- src/ImageSharp/Colors/Spaces/CieXyz.cs | 2 +- src/ImageSharp/Colors/Spaces/Cmyk.cs | 2 +- src/ImageSharp/Colors/Spaces/Hsl.cs | 2 +- src/ImageSharp/Colors/Spaces/Hsv.cs | 2 +- src/ImageSharp/Colors/Spaces/YCbCr.cs | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ImageSharp/Colors/Spaces/Bgra32.cs b/src/ImageSharp/Colors/Spaces/Bgra32.cs index 4325b1cd64..09475f42c8 100644 --- a/src/ImageSharp/Colors/Spaces/Bgra32.cs +++ b/src/ImageSharp/Colors/Spaces/Bgra32.cs @@ -22,7 +22,7 @@ namespace ImageSharp.Colors.Spaces /// /// The backing vector for SIMD support. /// - private Vector4 backingVector; + private readonly Vector4 backingVector; /// /// Initializes a new instance of the struct. diff --git a/src/ImageSharp/Colors/Spaces/CieLab.cs b/src/ImageSharp/Colors/Spaces/CieLab.cs index 505c7a6905..faa6c24724 100644 --- a/src/ImageSharp/Colors/Spaces/CieLab.cs +++ b/src/ImageSharp/Colors/Spaces/CieLab.cs @@ -28,7 +28,7 @@ namespace ImageSharp.Colors.Spaces /// /// The backing vector for SIMD support. /// - private Vector3 backingVector; + private readonly Vector3 backingVector; /// /// Initializes a new instance of the struct. diff --git a/src/ImageSharp/Colors/Spaces/CieXyz.cs b/src/ImageSharp/Colors/Spaces/CieXyz.cs index 2dd063163a..9deffe0669 100644 --- a/src/ImageSharp/Colors/Spaces/CieXyz.cs +++ b/src/ImageSharp/Colors/Spaces/CieXyz.cs @@ -28,7 +28,7 @@ namespace ImageSharp.Colors.Spaces /// /// The backing vector for SIMD support. /// - private Vector3 backingVector; + private readonly Vector3 backingVector; /// /// Initializes a new instance of the struct. diff --git a/src/ImageSharp/Colors/Spaces/Cmyk.cs b/src/ImageSharp/Colors/Spaces/Cmyk.cs index 48bd5c83a0..e8f2a41f5c 100644 --- a/src/ImageSharp/Colors/Spaces/Cmyk.cs +++ b/src/ImageSharp/Colors/Spaces/Cmyk.cs @@ -27,7 +27,7 @@ namespace ImageSharp.Colors.Spaces /// /// The backing vector for SIMD support. /// - private Vector4 backingVector; + private readonly Vector4 backingVector; /// /// Initializes a new instance of the struct. diff --git a/src/ImageSharp/Colors/Spaces/Hsl.cs b/src/ImageSharp/Colors/Spaces/Hsl.cs index 67a0ef094e..5c478ecf14 100644 --- a/src/ImageSharp/Colors/Spaces/Hsl.cs +++ b/src/ImageSharp/Colors/Spaces/Hsl.cs @@ -27,7 +27,7 @@ namespace ImageSharp.Colors.Spaces /// /// The backing vector for SIMD support. /// - private Vector3 backingVector; + private readonly Vector3 backingVector; /// /// Initializes a new instance of the struct. diff --git a/src/ImageSharp/Colors/Spaces/Hsv.cs b/src/ImageSharp/Colors/Spaces/Hsv.cs index 4cd382e782..9df16a27b4 100644 --- a/src/ImageSharp/Colors/Spaces/Hsv.cs +++ b/src/ImageSharp/Colors/Spaces/Hsv.cs @@ -27,7 +27,7 @@ namespace ImageSharp.Colors.Spaces /// /// The backing vector for SIMD support. /// - private Vector3 backingVector; + private readonly Vector3 backingVector; /// /// Initializes a new instance of the struct. diff --git a/src/ImageSharp/Colors/Spaces/YCbCr.cs b/src/ImageSharp/Colors/Spaces/YCbCr.cs index a91fdb2d67..9f1479d35b 100644 --- a/src/ImageSharp/Colors/Spaces/YCbCr.cs +++ b/src/ImageSharp/Colors/Spaces/YCbCr.cs @@ -23,7 +23,7 @@ namespace ImageSharp.Colors.Spaces /// /// The backing vector for SIMD support. /// - private Vector3 backingVector; + private readonly Vector3 backingVector; /// /// Initializes a new instance of the struct. From fac940d9d4fc4cd27515af9d2de2e2515190ede4 Mon Sep 17 00:00:00 2001 From: Olivia Date: Wed, 28 Dec 2016 14:47:36 +0200 Subject: [PATCH 6/6] Making max value vector static. --- src/ImageSharp/Colors/Spaces/YCbCr.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ImageSharp/Colors/Spaces/YCbCr.cs b/src/ImageSharp/Colors/Spaces/YCbCr.cs index 9f1479d35b..83bddff7d0 100644 --- a/src/ImageSharp/Colors/Spaces/YCbCr.cs +++ b/src/ImageSharp/Colors/Spaces/YCbCr.cs @@ -20,6 +20,11 @@ namespace ImageSharp.Colors.Spaces /// public static readonly YCbCr Empty = default(YCbCr); + /// + /// Vector which is used in clamping to the max value + /// + private static readonly Vector3 VectorMax = new Vector3(255); + /// /// The backing vector for SIMD support. /// @@ -34,7 +39,7 @@ namespace ImageSharp.Colors.Spaces public YCbCr(byte y, byte cb, byte cr) : this() { - this.backingVector = Vector3.Clamp(new Vector3(y, cb, cr), Vector3.Zero, new Vector3(255)); + this.backingVector = Vector3.Clamp(new Vector3(y, cb, cr), Vector3.Zero, VectorMax); } ///