From 7a9efabaea05087416de18fcb0474ca3c002e157 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Sat, 28 Jul 2018 15:53:35 +0100 Subject: [PATCH] Cleanup ToString() and remove unused operator --- src/ImageSharp/ColorSpaces/CieLab.cs | 18 +++-- src/ImageSharp/ColorSpaces/CieLch.cs | 22 +++---- src/ImageSharp/ColorSpaces/CieLchuv.cs | 16 ++--- src/ImageSharp/ColorSpaces/CieLuv.cs | 18 +++-- .../CieXyChromaticityCoordinates.cs | 14 ++-- src/ImageSharp/ColorSpaces/CieXyy.cs | 14 ++-- src/ImageSharp/ColorSpaces/CieXyz.cs | 14 ++-- src/ImageSharp/ColorSpaces/Cmyk.cs | 16 ++--- src/ImageSharp/ColorSpaces/Hsl.cs | 16 ++--- src/ImageSharp/ColorSpaces/Hsv.cs | 66 ++----------------- src/ImageSharp/ColorSpaces/HunterLab.cs | 18 +++-- src/ImageSharp/ColorSpaces/LinearRgb.cs | 22 +++---- src/ImageSharp/ColorSpaces/Lms.cs | 16 ++--- src/ImageSharp/ColorSpaces/Rgb.cs | 24 ++++--- src/ImageSharp/ColorSpaces/YCbCr.cs | 14 ++-- 15 files changed, 114 insertions(+), 194 deletions(-) diff --git a/src/ImageSharp/ColorSpaces/CieLab.cs b/src/ImageSharp/ColorSpaces/CieLab.cs index 305a3da4fb..5ab133cf90 100644 --- a/src/ImageSharp/ColorSpaces/CieLab.cs +++ b/src/ImageSharp/ColorSpaces/CieLab.cs @@ -49,7 +49,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// The a (green - magenta) component. /// The b (blue - yellow) component. /// Uses as white point. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public CieLab(float l, float a, float b) : this(l, a, b, DefaultWhitePoint) { @@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// The a (green - magenta) component. /// The b (blue - yellow) component. /// The reference white point. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public CieLab(float l, float a, float b, CieXyz whitePoint) { this.L = l; @@ -76,7 +76,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// The vector representing the l, a, b components. /// Uses as white point. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public CieLab(Vector3 vector) : this(vector, DefaultWhitePoint) { @@ -87,7 +87,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// The vector representing the l, a, b components. /// The reference white point. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public CieLab(Vector3 vector, CieXyz whitePoint) : this() { @@ -105,7 +105,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static bool operator ==(CieLab left, CieLab right) => left.Equals(right); /// @@ -116,7 +116,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static bool operator !=(CieLab left, CieLab right) => !left.Equals(right); /// @@ -131,16 +131,14 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override string ToString() { - return this.Equals(default) - ? "CieLab [Empty]" - : $"CieLab [ L={this.L:#0.##}, A={this.A:#0.##}, B={this.B:#0.##}]"; + return $"CieLab [ L={this.L:#0.##}, A={this.A:#0.##}, B={this.B:#0.##}]"; } /// public override bool Equals(object obj) => obj is CieLab other && this.Equals(other); /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public bool Equals(CieLab other) { return this.L.Equals(other.L) diff --git a/src/ImageSharp/ColorSpaces/CieLch.cs b/src/ImageSharp/ColorSpaces/CieLch.cs index 793b68879a..d2b3d378df 100644 --- a/src/ImageSharp/ColorSpaces/CieLch.cs +++ b/src/ImageSharp/ColorSpaces/CieLch.cs @@ -49,7 +49,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// The chroma, relative saturation. /// The hue in degrees. /// Uses as white point. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public CieLch(float l, float c, float h) : this(l, c, h, DefaultWhitePoint) { @@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// The chroma, relative saturation. /// The hue in degrees. /// The reference white point. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public CieLch(float l, float c, float h, CieXyz whitePoint) { this.L = l; @@ -76,7 +76,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// The vector representing the l, c, h components. /// Uses as white point. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public CieLch(Vector3 vector) : this(vector, DefaultWhitePoint) { @@ -87,7 +87,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// The vector representing the l, c, h components. /// The reference white point. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public CieLch(Vector3 vector, CieXyz whitePoint) { this.L = vector.X; @@ -104,7 +104,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static bool operator ==(CieLch left, CieLch right) { return left.Equals(right); @@ -118,7 +118,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static bool operator !=(CieLch left, CieLch right) => !left.Equals(right); /// @@ -133,17 +133,15 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override string ToString() { - return this.Equals(default) - ? "CieLch [Empty]" - : $"CieLch [ L={this.L:#0.##}, C={this.C:#0.##}, H={this.H:#0.##}]"; + return $"CieLch [ L={this.L:#0.##}, C={this.C:#0.##}, H={this.H:#0.##}]"; } /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public override bool Equals(object obj) => obj is CieLch other && this.Equals(other); /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public bool Equals(CieLch other) { return this.L.Equals(other.L) @@ -159,7 +157,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// A value ranging from 0 to 100. /// /// The - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public float Saturation() { float result = 100 * (this.C / this.L); diff --git a/src/ImageSharp/ColorSpaces/CieLchuv.cs b/src/ImageSharp/ColorSpaces/CieLchuv.cs index 1a592c93f8..d46c93c75e 100644 --- a/src/ImageSharp/ColorSpaces/CieLchuv.cs +++ b/src/ImageSharp/ColorSpaces/CieLchuv.cs @@ -49,7 +49,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// The chroma, relative saturation. /// The hue in degrees. /// Uses as white point. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public CieLchuv(float l, float c, float h) : this(l, c, h, DefaultWhitePoint) { @@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// The chroma, relative saturation. /// The hue in degrees. /// The reference white point. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public CieLchuv(float l, float c, float h, CieXyz whitePoint) { this.L = l; @@ -76,7 +76,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// The vector representing the l, c, h components. /// Uses as white point. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public CieLchuv(Vector3 vector) : this(vector, DefaultWhitePoint) { @@ -87,7 +87,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// The vector representing the l, c, h components. /// The reference white point. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public CieLchuv(Vector3 vector, CieXyz whitePoint) : this() { @@ -129,16 +129,14 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override string ToString() { - return this.Equals(default) - ? "CieLchuv [Empty]" - : $"CieLchuv [ L={this.L:#0.##}, C={this.C:#0.##}, H={this.H:#0.##}"; + return $"CieLchuv [ L={this.L:#0.##}, C={this.C:#0.##}, H={this.H:#0.##}"; } /// public override bool Equals(object obj) => obj is CieLchuv other && this.Equals(other); /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public bool Equals(CieLchuv other) { return this.L.Equals(other.L) @@ -154,7 +152,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// A value ranging from 0 to 100. /// /// The - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public float Saturation() { float result = 100 * (this.C / this.L); diff --git a/src/ImageSharp/ColorSpaces/CieLuv.cs b/src/ImageSharp/ColorSpaces/CieLuv.cs index f6b2cd1103..edf865d3c5 100644 --- a/src/ImageSharp/ColorSpaces/CieLuv.cs +++ b/src/ImageSharp/ColorSpaces/CieLuv.cs @@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// The blue-yellow chromaticity coordinate of the given whitepoint. /// The red-green chromaticity coordinate of the given whitepoint. /// Uses as white point. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public CieLuv(float l, float u, float v) : this(l, u, v, DefaultWhitePoint) { @@ -64,7 +64,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// The blue-yellow chromaticity coordinate of the given whitepoint. /// The red-green chromaticity coordinate of the given whitepoint. /// The reference white point. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public CieLuv(float l, float u, float v, CieXyz whitePoint) { this.L = l; @@ -78,7 +78,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// The vector representing the l, u, v components. /// Uses as white point. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public CieLuv(Vector3 vector) : this(vector, DefaultWhitePoint) { @@ -89,7 +89,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// The vector representing the l, u, v components. /// The reference white point. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public CieLuv(Vector3 vector, CieXyz whitePoint) { this.L = vector.X; @@ -106,7 +106,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static bool operator ==(CieLuv left, CieLuv right) => left.Equals(right); /// @@ -117,7 +117,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static bool operator !=(CieLuv left, CieLuv right) => !left.Equals(right); /// @@ -132,16 +132,14 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override string ToString() { - return this.Equals(default) - ? "CieLuv [ Empty ]" - : $"CieLuv [ L={this.L:#0.##}, U={this.U:#0.##}, V={this.V:#0.##} ]"; + return $"CieLuv [ L={this.L:#0.##}, U={this.U:#0.##}, V={this.V:#0.##} ]"; } /// public override bool Equals(object obj) => obj is CieLuv other && this.Equals(other); /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public bool Equals(CieLuv other) { return this.L.Equals(other.L) diff --git a/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs b/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs index db292041bc..9b258eda78 100644 --- a/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs +++ b/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs @@ -33,7 +33,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// Chromaticity coordinate x (usually from 0 to 1) /// Chromaticity coordinate y (usually from 0 to 1) - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public CieXyChromaticityCoordinates(float x, float y) { this.X = x; @@ -48,7 +48,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static bool operator ==(CieXyChromaticityCoordinates left, CieXyChromaticityCoordinates right) { return left.Equals(right); @@ -62,29 +62,27 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static bool operator !=(CieXyChromaticityCoordinates left, CieXyChromaticityCoordinates right) { return !left.Equals(right); } /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public override int GetHashCode() => HashHelpers.Combine(this.X.GetHashCode(), this.Y.GetHashCode()); /// public override string ToString() { - return this.Equals(default) - ? "CieXyChromaticityCoordinates [Empty]" - : $"CieXyChromaticityCoordinates [ X={this.X:#0.##}, Y={this.Y:#0.##}]"; + return $"CieXyChromaticityCoordinates [ X={this.X:#0.##}, Y={this.Y:#0.##}]"; } /// public override bool Equals(object obj) => obj is CieXyChromaticityCoordinates other && this.Equals(other); /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public bool Equals(CieXyChromaticityCoordinates other) => this.X.Equals(other.X) && this.Y.Equals(other.Y); } } \ No newline at end of file diff --git a/src/ImageSharp/ColorSpaces/CieXyy.cs b/src/ImageSharp/ColorSpaces/CieXyy.cs index 9d2fed225d..831c357027 100644 --- a/src/ImageSharp/ColorSpaces/CieXyy.cs +++ b/src/ImageSharp/ColorSpaces/CieXyy.cs @@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// The x chroma component. /// The y chroma component. /// The y luminance component. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public CieXyy(float x, float y, float yl) { // Not clamping as documentation about this space seems to indicate "usual" ranges @@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// Initializes a new instance of the struct. /// /// The vector representing the x, y, Y components. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public CieXyy(Vector3 vector) : this() { @@ -68,7 +68,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static bool operator ==(CieXyy left, CieXyy right) => left.Equals(right); /// @@ -79,7 +79,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static bool operator !=(CieXyy left, CieXyy right) => !left.Equals(right); /// @@ -93,9 +93,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override string ToString() { - return this.Equals(default) - ? "CieXyy [ Empty ]" - : $"CieXyy [ X={this.X:#0.##}, Y={this.Y:#0.##}, Yl={this.Yl:#0.##} ]"; + return $"CieXyy [ X={this.X:#0.##}, Y={this.Y:#0.##}, Yl={this.Yl:#0.##} ]"; } /// @@ -105,7 +103,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public bool Equals(CieXyy other) { return this.X.Equals(other.X) diff --git a/src/ImageSharp/ColorSpaces/CieXyz.cs b/src/ImageSharp/ColorSpaces/CieXyz.cs index 5d4acbcfda..a5d409f6b3 100644 --- a/src/ImageSharp/ColorSpaces/CieXyz.cs +++ b/src/ImageSharp/ColorSpaces/CieXyz.cs @@ -38,7 +38,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// X is a mix (a linear combination) of cone response curves chosen to be nonnegative /// The y luminance component. /// Z is quasi-equal to blue stimulation, or the S cone of the human eye. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public CieXyz(float x, float y, float z) : this(new Vector3(x, y, z)) { @@ -69,7 +69,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static bool operator ==(CieXyz left, CieXyz right) { return left.Equals(right); @@ -83,7 +83,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static bool operator !=(CieXyz left, CieXyz right) { return !left.Equals(right); @@ -93,7 +93,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// Returns a new representing this instance. /// /// The . - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public Vector3 ToVector3() => new Vector3(this.X, this.Y, this.Z); /// @@ -107,16 +107,14 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override string ToString() { - return this.Equals(default) - ? "CieXyz [ Empty ]" - : $"CieXyz [ X={this.X:#0.##}, Y={this.Y:#0.##}, Z={this.Z:#0.##} ]"; + return $"CieXyz [ X={this.X:#0.##}, Y={this.Y:#0.##}, Z={this.Z:#0.##} ]"; } /// public override bool Equals(object obj) => obj is CieXyz other && this.Equals(other); /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public bool Equals(CieXyz other) { return this.X.Equals(other.X) diff --git a/src/ImageSharp/ColorSpaces/Cmyk.cs b/src/ImageSharp/ColorSpaces/Cmyk.cs index f862151890..bc1131aa37 100644 --- a/src/ImageSharp/ColorSpaces/Cmyk.cs +++ b/src/ImageSharp/ColorSpaces/Cmyk.cs @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// The magenta component. /// The yellow component. /// The keyline black component. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public Cmyk(float c, float m, float y, float k) : this(new Vector4(c, m, y, k)) { @@ -53,7 +53,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// Initializes a new instance of the struct. /// /// The vector representing the c, m, y, k components. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public Cmyk(Vector4 vector) { vector = Vector4.Clamp(vector, Vector4.Zero, Vector4.One); @@ -71,7 +71,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static bool operator ==(Cmyk left, Cmyk right) => left.Equals(right); /// @@ -82,11 +82,11 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static bool operator !=(Cmyk left, Cmyk right) => !left.Equals(right); /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public override int GetHashCode() { int hash = this.C.GetHashCode(); @@ -98,16 +98,14 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override string ToString() { - return this.Equals(default) - ? "Cmyk [Empty]" - : $"Cmyk [ C={this.C:#0.##}, M={this.M:#0.##}, Y={this.Y:#0.##}, K={this.K:#0.##}]"; + return $"Cmyk [ C={this.C:#0.##}, M={this.M:#0.##}, Y={this.Y:#0.##}, K={this.K:#0.##}]"; } /// public override bool Equals(object obj) => obj is Cmyk other && this.Equals(other); /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public bool Equals(Cmyk other) { return this.C.Equals(other.C) diff --git a/src/ImageSharp/ColorSpaces/Hsl.cs b/src/ImageSharp/ColorSpaces/Hsl.cs index 04d8974f01..c6e1e4f9d4 100644 --- a/src/ImageSharp/ColorSpaces/Hsl.cs +++ b/src/ImageSharp/ColorSpaces/Hsl.cs @@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// The h hue component. /// The s saturation component. /// The l value (lightness) component. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public Hsl(float h, float s, float l) : this(new Vector3(h, s, l)) { @@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// Initializes a new instance of the struct. /// /// The vector representing the h, s, l components. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public Hsl(Vector3 vector) { vector = Vector3.Clamp(vector, Vector3.Zero, VectorMax); @@ -70,7 +70,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static bool operator ==(Hsl left, Hsl right) => left.Equals(right); /// @@ -81,11 +81,11 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static bool operator !=(Hsl left, Hsl right) => !left.Equals(right); /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public override int GetHashCode() { int hash = this.H.GetHashCode(); @@ -96,16 +96,14 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override string ToString() { - return this.Equals(default) - ? "Hsl [ Empty ]" - : $"Hsl [ H={this.H:#0.##}, S={this.S:#0.##}, L={this.L:#0.##} ]"; + return $"Hsl [ H={this.H:#0.##}, S={this.S:#0.##}, L={this.L:#0.##} ]"; } /// public override bool Equals(object obj) => obj is Hsl other && this.Equals(other); /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public bool Equals(Hsl other) { return this.H.Equals(other.H) diff --git a/src/ImageSharp/ColorSpaces/Hsv.cs b/src/ImageSharp/ColorSpaces/Hsv.cs index 54fd0eee2e..5fdc287ced 100644 --- a/src/ImageSharp/ColorSpaces/Hsv.cs +++ b/src/ImageSharp/ColorSpaces/Hsv.cs @@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// The h hue component. /// The s saturation component. /// The v value (brightness) component. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public Hsv(float h, float s, float v) : this(new Vector3(h, s, v)) { @@ -54,7 +54,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// Initializes a new instance of the struct. /// /// The vector representing the h, s, v components. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public Hsv(Vector3 vector) { vector = Vector3.Clamp(vector, Vector3.Zero, VectorMax); @@ -63,56 +63,6 @@ namespace SixLabors.ImageSharp.ColorSpaces this.V = vector.Z; } - /// - /// Allows the implicit conversion of an instance of to a - /// . - /// - /// The instance of to convert. - /// - /// An instance of . - /// - public static implicit operator Hsv(Rgba32 color) - { - float r = color.R / 255F; - float g = color.G / 255F; - float b = color.B / 255F; - - float max = MathF.Max(r, MathF.Max(g, b)); - float min = MathF.Min(r, MathF.Min(g, b)); - float chroma = max - min; - float h = 0; - float s = 0; - float v = max; - - if (MathF.Abs(chroma) < Constants.Epsilon) - { - return new Hsv(0, s, v); - } - - if (MathF.Abs(r - max) < Constants.Epsilon) - { - h = (g - b) / chroma; - } - else if (MathF.Abs(g - max) < Constants.Epsilon) - { - h = 2 + ((b - r) / chroma); - } - else if (MathF.Abs(b - max) < Constants.Epsilon) - { - h = 4 + ((r - g) / chroma); - } - - h *= 60; - if (h < 0.0) - { - h += 360; - } - - s = chroma / v; - - return new Hsv(h, s, v); - } - /// /// Compares two objects for equality. /// @@ -121,7 +71,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static bool operator ==(Hsv left, Hsv right) => left.Equals(right); /// @@ -132,11 +82,11 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static bool operator !=(Hsv left, Hsv right) => !left.Equals(right); /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public override int GetHashCode() { int hash = this.H.GetHashCode(); @@ -147,16 +97,14 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override string ToString() { - return this.Equals(default) - ? "Hsv [ Empty ]" - : $"Hsv [ H={this.H:#0.##}, S={this.S:#0.##}, V={this.V:#0.##} ]"; + return $"Hsv [ H={this.H:#0.##}, S={this.S:#0.##}, V={this.V:#0.##} ]"; } /// public override bool Equals(object obj) => obj is Hsv other && this.Equals(other); /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public bool Equals(Hsv other) { return this.H.Equals(other.H) diff --git a/src/ImageSharp/ColorSpaces/HunterLab.cs b/src/ImageSharp/ColorSpaces/HunterLab.cs index 15f3acc95f..d458fa7895 100644 --- a/src/ImageSharp/ColorSpaces/HunterLab.cs +++ b/src/ImageSharp/ColorSpaces/HunterLab.cs @@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// The a (green - magenta) component. /// The b (blue - yellow) component. /// Uses as white point. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public HunterLab(float l, float a, float b) : this(new Vector3(l, a, b), DefaultWhitePoint) { @@ -63,7 +63,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// The a (green - magenta) component. /// The b (blue - yellow) component. /// The reference white point. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public HunterLab(float l, float a, float b, CieXyz whitePoint) : this(new Vector3(l, a, b), whitePoint) { @@ -74,7 +74,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// The vector representing the l, a, b components. /// Uses as white point. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public HunterLab(Vector3 vector) : this(vector, DefaultWhitePoint) { @@ -85,7 +85,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// The vector representing the l a b components. /// The reference white point. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public HunterLab(Vector3 vector, CieXyz whitePoint) { // TODO: Clamp? @@ -113,11 +113,11 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static bool operator !=(HunterLab left, HunterLab right) => !left.Equals(right); /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public override int GetHashCode() { int hash = this.L.GetHashCode(); @@ -129,16 +129,14 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override string ToString() { - return this.Equals(default) - ? "HunterLab [Empty]" - : $"HunterLab [ L={this.L:#0.##}, A={this.A:#0.##}, B={this.B:#0.##}]"; + return $"HunterLab [ L={this.L:#0.##}, A={this.A:#0.##}, B={this.B:#0.##}]"; } /// public override bool Equals(object obj) => obj is HunterLab other && this.Equals(other); /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public bool Equals(HunterLab other) { return this.L.Equals(other.L) diff --git a/src/ImageSharp/ColorSpaces/LinearRgb.cs b/src/ImageSharp/ColorSpaces/LinearRgb.cs index 343c6f1c54..e7c74cb2dd 100644 --- a/src/ImageSharp/ColorSpaces/LinearRgb.cs +++ b/src/ImageSharp/ColorSpaces/LinearRgb.cs @@ -47,7 +47,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// The red component ranging between 0 and 1. /// The green component ranging between 0 and 1. /// The blue component ranging between 0 and 1. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public LinearRgb(float r, float g, float b) : this(new Vector3(r, g, b)) { @@ -60,7 +60,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// The green component ranging between 0 and 1. /// The blue component ranging between 0 and 1. /// The rgb working space. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public LinearRgb(float r, float g, float b, RgbWorkingSpace workingSpace) : this(new Vector3(r, g, b), workingSpace) { @@ -70,7 +70,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// Initializes a new instance of the struct. /// /// The vector representing the r, g, b components. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public LinearRgb(Vector3 vector) : this(vector, DefaultWorkingSpace) { @@ -81,7 +81,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// The vector representing the r, g, b components. /// The LinearRgb working space. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public LinearRgb(Vector3 vector, RgbWorkingSpace workingSpace) { // Clamp to 0-1 range. @@ -100,7 +100,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static bool operator ==(LinearRgb left, LinearRgb right) => left.Equals(right); /// @@ -111,18 +111,18 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static bool operator !=(LinearRgb left, LinearRgb right) => !left.Equals(right); /// /// Returns a new representing this instance. /// /// The . - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public Vector3 ToVector3() => new Vector3(this.R, this.G, this.B); /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public override int GetHashCode() { int hash = this.R.GetHashCode(); @@ -133,16 +133,14 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override string ToString() { - return this.Equals(default) - ? "LinearRgb [ Empty ]" - : $"LinearRgb [ R={this.R:#0.##}, G={this.G:#0.##}, B={this.B:#0.##} ]"; + return $"LinearRgb [ R={this.R:#0.##}, G={this.G:#0.##}, B={this.B:#0.##} ]"; } /// public override bool Equals(object obj) => obj is LinearRgb other && this.Equals(other); /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public bool Equals(LinearRgb other) { return this.R.Equals(other.R) diff --git a/src/ImageSharp/ColorSpaces/Lms.cs b/src/ImageSharp/ColorSpaces/Lms.cs index 3f55d8891d..0204a0ebcf 100644 --- a/src/ImageSharp/ColorSpaces/Lms.cs +++ b/src/ImageSharp/ColorSpaces/Lms.cs @@ -38,7 +38,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// L represents the responsivity at long wavelengths. /// M represents the responsivity at medium wavelengths. /// S represents the responsivity at short wavelengths. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public Lms(float l, float m, float s) { this.L = l; @@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// Initializes a new instance of the struct. /// /// The vector representing the l, m, s components. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public Lms(Vector3 vector) { // Not clamping as documentation about this space seems to indicate "usual" ranges @@ -67,7 +67,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static bool operator ==(Lms left, Lms right) => left.Equals(right); /// @@ -78,14 +78,14 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static bool operator !=(Lms left, Lms right) => !left.Equals(right); /// /// Returns a new representing this instance. /// /// The . - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public Vector3 ToVector3() => new Vector3(this.L, this.M, this.S); /// @@ -99,16 +99,14 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override string ToString() { - return this.Equals(default) - ? "Lms [ Empty ]" - : $"Lms [ L={this.L:#0.##}, M={this.M:#0.##}, S={this.S:#0.##} ]"; + return $"Lms [ L={this.L:#0.##}, M={this.M:#0.##}, S={this.S:#0.##} ]"; } /// public override bool Equals(object obj) => obj is Lms other && this.Equals(other); /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public bool Equals(Lms other) { return this.L.Equals(other.L) diff --git a/src/ImageSharp/ColorSpaces/Rgb.cs b/src/ImageSharp/ColorSpaces/Rgb.cs index bec279ad3f..db2c8e86b5 100644 --- a/src/ImageSharp/ColorSpaces/Rgb.cs +++ b/src/ImageSharp/ColorSpaces/Rgb.cs @@ -48,7 +48,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// The red component ranging between 0 and 1. /// The green component ranging between 0 and 1. /// The blue component ranging between 0 and 1. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public Rgb(float r, float g, float b) : this(r, g, b, DefaultWorkingSpace) { @@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// The green component ranging between 0 and 1. /// The blue component ranging between 0 and 1. /// The rgb working space. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public Rgb(float r, float g, float b, RgbWorkingSpace workingSpace) { // Clamp to 0-1 range. @@ -75,7 +75,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// Initializes a new instance of the struct. /// /// The vector representing the r, g, b components. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public Rgb(Vector3 vector) : this(vector, DefaultWorkingSpace) { @@ -86,7 +86,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// The vector representing the r, g, b components. /// The rgb working space. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public Rgb(Vector3 vector, RgbWorkingSpace workingSpace) { // Clamp to 0-1 range. @@ -103,7 +103,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// The instance of to convert. /// An instance of . - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static implicit operator Rgb(Rgb24 color) { return new Rgb(color.R / 255F, color.G / 255F, color.B / 255F); @@ -115,7 +115,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// The instance of to convert. /// An instance of . - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static implicit operator Rgb(Rgba32 color) { return new Rgba32(color.R / 255F, color.G / 255F, color.B / 255F); @@ -133,7 +133,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static bool operator ==(Rgb left, Rgb right) => left.Equals(right); /// @@ -144,14 +144,14 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static bool operator !=(Rgb left, Rgb right) => !left.Equals(right); /// /// Returns a new representing this instance. /// /// The . - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public Vector3 ToVector3() => new Vector3(this.R, this.G, this.B); /// @@ -165,16 +165,14 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override string ToString() { - return this.Equals(default) - ? "Rgb [ Empty ]" - : $"Rgb [ R={this.R:#0.##}, G={this.G:#0.##}, B={this.B:#0.##} ]"; + return $"Rgb [ R={this.R:#0.##}, G={this.G:#0.##}, B={this.B:#0.##} ]"; } /// public override bool Equals(object obj) => obj is Rgb other && this.Equals(other); /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public bool Equals(Rgb other) { return this.R.Equals(other.R) diff --git a/src/ImageSharp/ColorSpaces/YCbCr.cs b/src/ImageSharp/ColorSpaces/YCbCr.cs index 88f7cac4c3..0d426f3c24 100644 --- a/src/ImageSharp/ColorSpaces/YCbCr.cs +++ b/src/ImageSharp/ColorSpaces/YCbCr.cs @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// The y luminance component. /// The cb chroma component. /// The cr chroma component. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public YCbCr(float y, float cb, float cr) : this(new Vector3(y, cb, cr)) { @@ -53,7 +53,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// Initializes a new instance of the struct. /// /// The vector representing the y, cb, cr components. - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public YCbCr(Vector3 vector) { vector = Vector3.Clamp(vector, Vector3.Zero, VectorMax); @@ -80,11 +80,11 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static bool operator !=(YCbCr left, YCbCr right) => !left.Equals(right); /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public override int GetHashCode() { int hash = this.Y.GetHashCode(); @@ -95,16 +95,14 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override string ToString() { - return this.Equals(default) - ? "YCbCr [ Empty ]" - : $"YCbCr [ Y={this.Y}, Cb={this.Cb}, Cr={this.Cr} ]"; + return $"YCbCr [ Y={this.Y}, Cb={this.Cb}, Cr={this.Cr} ]"; } /// public override bool Equals(object obj) => obj is YCbCr other && this.Equals(other); /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public bool Equals(YCbCr other) { return this.Y.Equals(other.Y)