diff --git a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj index ae5069be1d..a6f529ee36 100644 --- a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj +++ b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj @@ -1,10 +1,15 @@  - - An extension to ImageSharp that allows the drawing of images, paths, and text. + SixLabors.ImageSharp.Drawing + SixLabors and contributors + Six Labors + Copyright (c) Six Labors and contributors. + SixLabors.ImageSharp + An extension to ImageSharp that allows the drawing of images, paths, and text. + en + $(packageversion) 0.0.1 - SixLabors and contributors netstandard1.3;netstandard2.0 7.3 true @@ -17,15 +22,6 @@ http://www.apache.org/licenses/LICENSE-2.0 git https://github.com/SixLabors/ImageSharp - false - false - false - false - false - false - false - false - false full portable True diff --git a/src/ImageSharp/ColorSpaces/CieLab.cs b/src/ImageSharp/ColorSpaces/CieLab.cs index ea6df86e27..146acf12ee 100644 --- a/src/ImageSharp/ColorSpaces/CieLab.cs +++ b/src/ImageSharp/ColorSpaces/CieLab.cs @@ -118,13 +118,7 @@ namespace SixLabors.ImageSharp.ColorSpaces public static bool operator !=(CieLab left, CieLab right) => !left.Equals(right); /// - public override int GetHashCode() - { - int hash = this.L.GetHashCode(); - hash = HashHelpers.Combine(hash, this.A.GetHashCode()); - hash = HashHelpers.Combine(hash, this.B.GetHashCode()); - return HashHelpers.Combine(hash, this.WhitePoint.GetHashCode()); - } + public override int GetHashCode() => HashCode.Combine(this.L, this.A, this.B, this.WhitePoint); /// public override string ToString() => FormattableString.Invariant($"CieLab({this.L:#0.##}, {this.A:#0.##}, {this.B:#0.##})"); diff --git a/src/ImageSharp/ColorSpaces/CieLch.cs b/src/ImageSharp/ColorSpaces/CieLch.cs index f1a7425e9e..074bc1516b 100644 --- a/src/ImageSharp/ColorSpaces/CieLch.cs +++ b/src/ImageSharp/ColorSpaces/CieLch.cs @@ -122,10 +122,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override int GetHashCode() { - int hash = this.L.GetHashCode(); - hash = HashHelpers.Combine(hash, this.C.GetHashCode()); - hash = HashHelpers.Combine(hash, this.H.GetHashCode()); - return HashHelpers.Combine(hash, this.WhitePoint.GetHashCode()); + return HashCode.Combine(this.L, this.C, this.H, this.WhitePoint); } /// diff --git a/src/ImageSharp/ColorSpaces/CieLchuv.cs b/src/ImageSharp/ColorSpaces/CieLchuv.cs index 256b5dc0fd..ab6f639a2b 100644 --- a/src/ImageSharp/ColorSpaces/CieLchuv.cs +++ b/src/ImageSharp/ColorSpaces/CieLchuv.cs @@ -119,13 +119,7 @@ namespace SixLabors.ImageSharp.ColorSpaces public static bool operator !=(CieLchuv left, CieLchuv right) => !left.Equals(right); /// - public override int GetHashCode() - { - int hash = this.L.GetHashCode(); - hash = HashHelpers.Combine(hash, this.C.GetHashCode()); - hash = HashHelpers.Combine(hash, this.H.GetHashCode()); - return HashHelpers.Combine(hash, this.WhitePoint.GetHashCode()); - } + public override int GetHashCode() => HashCode.Combine(this.L, this.C, this.H, this.WhitePoint); /// public override string ToString() => FormattableString.Invariant($"CieLchuv({this.L:#0.##}, {this.C:#0.##}, {this.H:#0.##})"); diff --git a/src/ImageSharp/ColorSpaces/CieLuv.cs b/src/ImageSharp/ColorSpaces/CieLuv.cs index 8fe073d6bf..d54d92b62a 100644 --- a/src/ImageSharp/ColorSpaces/CieLuv.cs +++ b/src/ImageSharp/ColorSpaces/CieLuv.cs @@ -119,13 +119,7 @@ namespace SixLabors.ImageSharp.ColorSpaces public static bool operator !=(CieLuv left, CieLuv right) => !left.Equals(right); /// - public override int GetHashCode() - { - int hash = this.L.GetHashCode(); - hash = HashHelpers.Combine(hash, this.U.GetHashCode()); - hash = HashHelpers.Combine(hash, this.V.GetHashCode()); - return HashHelpers.Combine(hash, this.WhitePoint.GetHashCode()); - } + public override int GetHashCode() => HashCode.Combine(this.L, this.U, this.V, this.WhitePoint); /// public override string ToString() => FormattableString.Invariant($"CieLuv({this.L:#0.##}, {this.U:#0.##}, {this.V:#0.##})"); diff --git a/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs b/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs index f625bb7616..49c1da9f10 100644 --- a/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs +++ b/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs @@ -64,7 +64,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// [MethodImpl(InliningOptions.ShortMethod)] - public override int GetHashCode() => HashHelpers.Combine(this.X.GetHashCode(), this.Y.GetHashCode()); + public override int GetHashCode() => HashCode.Combine(this.X, this.Y); /// public override string ToString() => FormattableString.Invariant($"CieXyChromaticityCoordinates({this.X:#0.##}, {this.Y:#0.##})"); diff --git a/src/ImageSharp/ColorSpaces/CieXyy.cs b/src/ImageSharp/ColorSpaces/CieXyy.cs index 7137360e94..fff296945e 100644 --- a/src/ImageSharp/ColorSpaces/CieXyy.cs +++ b/src/ImageSharp/ColorSpaces/CieXyy.cs @@ -83,12 +83,7 @@ namespace SixLabors.ImageSharp.ColorSpaces public static bool operator !=(CieXyy left, CieXyy right) => !left.Equals(right); /// - public override int GetHashCode() - { - int hash = this.X.GetHashCode(); - hash = HashHelpers.Combine(hash, this.Y.GetHashCode()); - return HashHelpers.Combine(hash, this.Yl.GetHashCode()); - } + public override int GetHashCode() => HashCode.Combine(this.X, this.Y, this.Yl); /// public override string ToString() => FormattableString.Invariant($"CieXyy({this.X:#0.##}, {this.Y:#0.##}, {this.Yl:#0.##})"); diff --git a/src/ImageSharp/ColorSpaces/CieXyz.cs b/src/ImageSharp/ColorSpaces/CieXyz.cs index c0ed356601..30521476e5 100644 --- a/src/ImageSharp/ColorSpaces/CieXyz.cs +++ b/src/ImageSharp/ColorSpaces/CieXyz.cs @@ -86,12 +86,7 @@ namespace SixLabors.ImageSharp.ColorSpaces public Vector3 ToVector3() => new Vector3(this.X, this.Y, this.Z); /// - public override int GetHashCode() - { - int hash = this.X.GetHashCode(); - hash = HashHelpers.Combine(hash, this.Y.GetHashCode()); - return HashHelpers.Combine(hash, this.Z.GetHashCode()); - } + public override int GetHashCode() => HashCode.Combine(this.X, this.Y, this.Z); /// public override string ToString() => FormattableString.Invariant($"CieXyz({this.X:#0.##}, {this.Y:#0.##}, {this.Z:#0.##})"); diff --git a/src/ImageSharp/ColorSpaces/Cmyk.cs b/src/ImageSharp/ColorSpaces/Cmyk.cs index 634667c0c6..04901126c1 100644 --- a/src/ImageSharp/ColorSpaces/Cmyk.cs +++ b/src/ImageSharp/ColorSpaces/Cmyk.cs @@ -90,13 +90,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// [MethodImpl(InliningOptions.ShortMethod)] - public override int GetHashCode() - { - int hash = this.C.GetHashCode(); - hash = HashHelpers.Combine(hash, this.M.GetHashCode()); - hash = HashHelpers.Combine(hash, this.Y.GetHashCode()); - return HashHelpers.Combine(hash, this.K.GetHashCode()); - } + public override int GetHashCode() => HashCode.Combine(this.C, this.M, this.Y, this.K); /// public override string ToString() => FormattableString.Invariant($"Cmyk({this.C:#0.##}, {this.M:#0.##}, {this.Y:#0.##}, {this.K:#0.##})"); diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/RGBPrimariesChromaticityCoordinates.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/RGBPrimariesChromaticityCoordinates.cs index 68b4d95fc6..4c69133e0f 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/RGBPrimariesChromaticityCoordinates.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/RGBPrimariesChromaticityCoordinates.cs @@ -86,14 +86,6 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation } /// - public override int GetHashCode() - { - unchecked - { - int hashCode = this.R.GetHashCode(); - hashCode = (hashCode * 397) ^ this.G.GetHashCode(); - return (hashCode * 397) ^ this.B.GetHashCode(); - } - } + public override int GetHashCode() => HashCode.Combine(this.R, this.G, this.B); } } \ No newline at end of file diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/GammaWorkingSpace.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/GammaWorkingSpace.cs index 73aa60b6cb..639d0b2933 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/GammaWorkingSpace.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/GammaWorkingSpace.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using System; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.ColorSpaces.Companding; @@ -57,10 +58,9 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation } /// - public override int GetHashCode() - { - int hash = base.GetHashCode(); - return HashHelpers.Combine(hash, this.Gamma.GetHashCode()); - } + public override int GetHashCode() => HashCode.Combine( + this.WhitePoint, + this.ChromaticityCoordinates, + this.Gamma); } } \ No newline at end of file diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/RgbWorkingSpaceBase.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/RgbWorkingSpaceBase.cs index 5a89321c8f..6051f52865 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/RgbWorkingSpaceBase.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/RgbWorkingSpaceBase.cs @@ -1,6 +1,8 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using System; + namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation { /// @@ -76,8 +78,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation /// public override int GetHashCode() { - int hash = this.WhitePoint.GetHashCode(); - return HashHelpers.Combine(hash, this.ChromaticityCoordinates.GetHashCode()); + return HashCode.Combine(this.WhitePoint, this.ChromaticityCoordinates); } } } \ No newline at end of file diff --git a/src/ImageSharp/ColorSpaces/Hsl.cs b/src/ImageSharp/ColorSpaces/Hsl.cs index f6e531df35..04b3bea41f 100644 --- a/src/ImageSharp/ColorSpaces/Hsl.cs +++ b/src/ImageSharp/ColorSpaces/Hsl.cs @@ -84,12 +84,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// [MethodImpl(InliningOptions.ShortMethod)] - public override int GetHashCode() - { - int hash = this.H.GetHashCode(); - hash = HashHelpers.Combine(hash, this.S.GetHashCode()); - return HashHelpers.Combine(hash, this.L.GetHashCode()); - } + public override int GetHashCode() => HashCode.Combine(this.H, this.S, this.L); /// public override string ToString() => FormattableString.Invariant($"Hsl({this.H:#0.##}, {this.S:#0.##}, {this.L:#0.##})"); diff --git a/src/ImageSharp/ColorSpaces/Hsv.cs b/src/ImageSharp/ColorSpaces/Hsv.cs index 631f03d09f..8ccc74ae09 100644 --- a/src/ImageSharp/ColorSpaces/Hsv.cs +++ b/src/ImageSharp/ColorSpaces/Hsv.cs @@ -82,12 +82,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// [MethodImpl(InliningOptions.ShortMethod)] - public override int GetHashCode() - { - int hash = this.H.GetHashCode(); - hash = HashHelpers.Combine(hash, this.S.GetHashCode()); - return HashHelpers.Combine(hash, this.V.GetHashCode()); - } + public override int GetHashCode() => HashCode.Combine(this.H, this.S, this.V); /// public override string ToString() => FormattableString.Invariant($"Hsv({this.H:#0.##}, {this.S:#0.##}, {this.V:#0.##})"); diff --git a/src/ImageSharp/ColorSpaces/HunterLab.cs b/src/ImageSharp/ColorSpaces/HunterLab.cs index f4fa29d314..dcae65e425 100644 --- a/src/ImageSharp/ColorSpaces/HunterLab.cs +++ b/src/ImageSharp/ColorSpaces/HunterLab.cs @@ -119,10 +119,7 @@ namespace SixLabors.ImageSharp.ColorSpaces [MethodImpl(InliningOptions.ShortMethod)] public override int GetHashCode() { - int hash = this.L.GetHashCode(); - hash = HashHelpers.Combine(hash, this.A.GetHashCode()); - hash = HashHelpers.Combine(hash, this.B.GetHashCode()); - return HashHelpers.Combine(hash, this.WhitePoint.GetHashCode()); + return HashCode.Combine(this.L, this.A, this.B, this.WhitePoint); } /// diff --git a/src/ImageSharp/ColorSpaces/LinearRgb.cs b/src/ImageSharp/ColorSpaces/LinearRgb.cs index ec6d18be2b..46b2275968 100644 --- a/src/ImageSharp/ColorSpaces/LinearRgb.cs +++ b/src/ImageSharp/ColorSpaces/LinearRgb.cs @@ -126,12 +126,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// [MethodImpl(InliningOptions.ShortMethod)] - public override int GetHashCode() - { - int hash = this.R.GetHashCode(); - hash = HashHelpers.Combine(hash, this.G.GetHashCode()); - return HashHelpers.Combine(hash, this.B.GetHashCode()); - } + public override int GetHashCode() => HashCode.Combine(this.R, this.G, this.B); /// public override string ToString() => FormattableString.Invariant($"LinearRgb({this.R:#0.##}, {this.G:#0.##}, {this.B:#0.##})"); diff --git a/src/ImageSharp/ColorSpaces/Lms.cs b/src/ImageSharp/ColorSpaces/Lms.cs index 0a8b7aa7b9..0ee56abbc2 100644 --- a/src/ImageSharp/ColorSpaces/Lms.cs +++ b/src/ImageSharp/ColorSpaces/Lms.cs @@ -87,12 +87,7 @@ namespace SixLabors.ImageSharp.ColorSpaces public Vector3 ToVector3() => new Vector3(this.L, this.M, this.S); /// - public override int GetHashCode() - { - int hash = this.L.GetHashCode(); - hash = HashHelpers.Combine(hash, this.M.GetHashCode()); - return HashHelpers.Combine(hash, this.S.GetHashCode()); - } + public override int GetHashCode() => HashCode.Combine(this.L, this.M, this.S); /// public override string ToString() => FormattableString.Invariant($"Lms({this.L:#0.##}, {this.M:#0.##}, {this.S:#0.##})"); diff --git a/src/ImageSharp/ColorSpaces/Rgb.cs b/src/ImageSharp/ColorSpaces/Rgb.cs index 97fafbaf37..cdc9e90ad4 100644 --- a/src/ImageSharp/ColorSpaces/Rgb.cs +++ b/src/ImageSharp/ColorSpaces/Rgb.cs @@ -147,12 +147,7 @@ namespace SixLabors.ImageSharp.ColorSpaces public Vector3 ToVector3() => new Vector3(this.R, this.G, this.B); /// - public override int GetHashCode() - { - int hash = this.R.GetHashCode(); - hash = HashHelpers.Combine(hash, this.G.GetHashCode()); - return HashHelpers.Combine(hash, this.B.GetHashCode()); - } + public override int GetHashCode() => HashCode.Combine(this.R, this.G, this.B); /// public override string ToString() => FormattableString.Invariant($"Rgb({this.R:#0.##}, {this.G:#0.##}, {this.B:#0.##})"); diff --git a/src/ImageSharp/ColorSpaces/YCbCr.cs b/src/ImageSharp/ColorSpaces/YCbCr.cs index 6aa191c2de..b0563bb899 100644 --- a/src/ImageSharp/ColorSpaces/YCbCr.cs +++ b/src/ImageSharp/ColorSpaces/YCbCr.cs @@ -83,12 +83,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// [MethodImpl(InliningOptions.ShortMethod)] - public override int GetHashCode() - { - int hash = this.Y.GetHashCode(); - hash = HashHelpers.Combine(hash, this.Cb.GetHashCode()); - return HashHelpers.Combine(hash, this.Cr.GetHashCode()); - } + public override int GetHashCode() => HashCode.Combine(this.Y, this.Cb, this.Cr); /// public override string ToString() => FormattableString.Invariant($"YCbCr({this.Y}, {this.Cb}, {this.Cr})"); diff --git a/src/ImageSharp/Common/ParallelUtils/ParallelHelper.cs b/src/ImageSharp/Common/ParallelUtils/ParallelHelper.cs index 1d1734a863..782333219f 100644 --- a/src/ImageSharp/Common/ParallelUtils/ParallelHelper.cs +++ b/src/ImageSharp/Common/ParallelUtils/ParallelHelper.cs @@ -85,7 +85,7 @@ namespace SixLabors.ImageSharp.ParallelUtils Rectangle rectangle, in ParallelExecutionSettings parallelSettings, Action> body) - where T : struct + where T : unmanaged { int maxSteps = DivideCeil(rectangle.Width * rectangle.Height, parallelSettings.MinimumPixelsProcessedPerTask); @@ -135,7 +135,7 @@ namespace SixLabors.ImageSharp.ParallelUtils Rectangle rectangle, Configuration configuration, Action> body) - where T : struct + where T : unmanaged { IterateRowsWithTempBuffer(rectangle, configuration.GetParallelSettings(), body); } diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/AdobeMarker.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/AdobeMarker.cs index af0938d302..43de39ac78 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/AdobeMarker.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/AdobeMarker.cs @@ -100,13 +100,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder /// public override int GetHashCode() { - return HashHelpers.Combine( - this.DCTEncodeVersion.GetHashCode(), - HashHelpers.Combine( - this.APP14Flags0.GetHashCode(), - HashHelpers.Combine( - this.APP14Flags1.GetHashCode(), - this.ColorTransform.GetHashCode()))); + return HashCode.Combine( + this.DCTEncodeVersion, + this.APP14Flags0, + this.APP14Flags1, + this.ColorTransform); } } } \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs index 4bff492486..c51a2f4da5 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs @@ -112,13 +112,12 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder /// public override int GetHashCode() { - return HashHelpers.Combine( - this.MajorVersion.GetHashCode(), - HashHelpers.Combine( - this.MinorVersion.GetHashCode(), - HashHelpers.Combine( - this.DensityUnits.GetHashCode(), - HashHelpers.Combine(this.XDensity, this.YDensity)))); + return HashCode.Combine( + this.MajorVersion, + this.MinorVersion, + this.DensityUnits, + this.XDensity, + this.YDensity); } } } \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs index f6da9cb2ec..faa7c3bc9a 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs @@ -553,12 +553,12 @@ namespace SixLabors.ImageSharp.Formats.Jpeg if (this.exifData is null) { // The first 6 bytes (Exif00) will be skipped, because this is Jpeg specific - this.exifData = profile.Skip(Exif00).ToArray(); + this.exifData = profile.AsSpan(Exif00).ToArray(); } else { // If the EXIF information exceeds 64K, it will be split over multiple APP1 markers - this.ExtendProfile(ref this.exifData, profile.Skip(Exif00).ToArray()); + this.ExtendProfile(ref this.exifData, profile.AsSpan(Exif00).ToArray()); } } } diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index 292de007ca..216f3129f9 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -237,7 +237,7 @@ namespace SixLabors.ImageSharp.Formats.Png } // Use the metadata to determine what quantization depth to use if no quantizer has been set. - if (this.quantizer == null) + if (this.quantizer is null) { this.quantizer = new WuQuantizer(ImageMaths.GetColorCountForBitDepth(bits)); } diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj index c19c92426f..1cdee81a26 100644 --- a/src/ImageSharp/ImageSharp.csproj +++ b/src/ImageSharp/ImageSharp.csproj @@ -1,10 +1,15 @@  - A cross-platform library for the processing of image files; written in C# SixLabors.ImageSharp + Six Labors and contributors + Six Labors + Copyright (c) Six Labors and contributors. + SixLabors.ImageSharp + A cross-platform library for the processing of image files; written in C# + en + $(packageversion) 0.0.1 - Six Labors and contributors netstandard1.3;netstandard2.0;netcoreapp2.1;net472 true true @@ -16,20 +21,11 @@ http://www.apache.org/licenses/LICENSE-2.0 git https://github.com/SixLabors/ImageSharp - false - false - false - false - false - false - false - false - false full portable True IOperation - Latest + 7.3 @@ -42,7 +38,7 @@ - + All diff --git a/src/ImageSharp/MetaData/ImageProperty.cs b/src/ImageSharp/MetaData/ImageProperty.cs index a08a95fed4..24a3686de2 100644 --- a/src/ImageSharp/MetaData/ImageProperty.cs +++ b/src/ImageSharp/MetaData/ImageProperty.cs @@ -99,19 +99,7 @@ namespace SixLabors.ImageSharp.MetaData /// /// A 32-bit signed integer that is the hash code for this instance. /// - public override int GetHashCode() - { - unchecked - { - int hashCode = this.Name.GetHashCode(); - if (this.Value != null) - { - hashCode = (hashCode * 397) ^ this.Value.GetHashCode(); - } - - return hashCode; - } - } + public override int GetHashCode() => HashCode.Combine(this.Name, this.Value); /// /// Returns the fully qualified type name of this instance. diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs index 100649c0fd..8ec9eea275 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs @@ -27,9 +27,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif public ExifReader(byte[] exifData) { - DebugGuard.NotNull(exifData, nameof(exifData)); - - this.exifData = exifData; + this.exifData = exifData ?? throw new ArgumentNullException(nameof(exifData)); } private delegate TDataType ConverterMethod(ReadOnlySpan data); @@ -374,7 +372,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif private void AddInvalidTag(ExifTag tag) { - if (this.invalidTags == null) + if (this.invalidTags is null) { this.invalidTags = new List(); } diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs index ccacfd0bf9..409c55253a 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs @@ -198,7 +198,10 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif } /// - public override int GetHashCode() => this.GetHashCode(this); + public override int GetHashCode() + { + return HashCode.Combine(this.Tag, this.DataType, this.Value); + } /// public override string ToString() @@ -714,20 +717,5 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif throw new NotSupportedException(); } } - - /// - /// 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 int GetHashCode(ExifValue exif) - { - int hashCode = exif.Tag.GetHashCode() ^ exif.DataType.GetHashCode(); - return hashCode ^ exif.Value?.GetHashCode() ?? hashCode; - } } } \ No newline at end of file diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccParametricCurve.cs b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccParametricCurve.cs index a241acd216..efc2ca5377 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccParametricCurve.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccParametricCurve.cs @@ -154,18 +154,15 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override int GetHashCode() { - unchecked - { - int hashCode = (int)this.Type; - hashCode = (hashCode * 397) ^ this.G.GetHashCode(); - hashCode = (hashCode * 397) ^ this.A.GetHashCode(); - hashCode = (hashCode * 397) ^ this.B.GetHashCode(); - hashCode = (hashCode * 397) ^ this.C.GetHashCode(); - hashCode = (hashCode * 397) ^ this.D.GetHashCode(); - hashCode = (hashCode * 397) ^ this.E.GetHashCode(); - hashCode = (hashCode * 397) ^ this.F.GetHashCode(); - return hashCode; - } + return HashCode.Combine( + this.Type, + this.G.GetHashCode(), + this.A.GetHashCode(), + this.B.GetHashCode(), + this.C.GetHashCode(), + this.D.GetHashCode(), + this.E.GetHashCode(), + this.F.GetHashCode()); } } } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccResponseCurve.cs b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccResponseCurve.cs index 02ab301bd2..de08485ac8 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccResponseCurve.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccResponseCurve.cs @@ -73,13 +73,10 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override int GetHashCode() { - unchecked - { - int hashCode = (int)this.CurveType; - hashCode = (hashCode * 397) ^ (this.XyzValues?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (this.ResponseArrays?.GetHashCode() ?? 0); - return hashCode; - } + return HashCode.Combine( + this.CurveType, + this.XyzValues, + this.ResponseArrays); } private bool EqualsResponseArray(IccResponseCurve other) diff --git a/src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs index 2687e10b66..4c6bb07858 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs @@ -64,12 +64,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc } /// - public override int GetHashCode() - { - unchecked - { - return (int)this.Signature * 397; - } - } + public override int GetHashCode() => this.Signature.GetHashCode(); } } \ No newline at end of file diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccChromaticityTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccChromaticityTagDataEntry.cs index a87dae8c5d..e9a812d8ca 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccChromaticityTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccChromaticityTagDataEntry.cs @@ -110,13 +110,10 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override int GetHashCode() { - unchecked - { - int hashCode = base.GetHashCode(); - hashCode = (hashCode * 397) ^ (int)this.ColorantType; - hashCode = (hashCode * 397) ^ (this.ChannelValues?.GetHashCode() ?? 0); - return hashCode; - } + return HashCode.Combine( + this.Signature, + this.ColorantType, + this.ChannelValues); } private static double[][] GetColorantArray(IccColorantEncoding colorantType) diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantOrderTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantOrderTagDataEntry.cs index 54c2056151..b5f8fd5c49 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantOrderTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantOrderTagDataEntry.cs @@ -70,10 +70,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override int GetHashCode() { - unchecked - { - return (base.GetHashCode() * 397) ^ (this.ColorantNumber?.GetHashCode() ?? 0); - } + return HashCode.Combine(this.Signature, this.ColorantNumber); } } } \ No newline at end of file diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantTableTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantTableTagDataEntry.cs index dd99a2f9fb..9f2b4c90ad 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantTableTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantTableTagDataEntry.cs @@ -72,10 +72,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override int GetHashCode() { - unchecked - { - return (base.GetHashCode() * 397) ^ (this.ColorantData?.GetHashCode() ?? 0); - } + return HashCode.Combine(this.Signature, this.ColorantData); } } } \ No newline at end of file diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCrdInfoTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCrdInfoTagDataEntry.cs index cc1aea3192..4d393dfb33 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCrdInfoTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCrdInfoTagDataEntry.cs @@ -121,16 +121,13 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override int GetHashCode() { - unchecked - { - int hashCode = base.GetHashCode(); - hashCode = (hashCode * 397) ^ (this.PostScriptProductName?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (this.RenderingIntent0Crd?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (this.RenderingIntent1Crd?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (this.RenderingIntent2Crd?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (this.RenderingIntent3Crd?.GetHashCode() ?? 0); - return hashCode; - } + return HashCode.Combine( + this.Signature, + this.PostScriptProductName, + this.RenderingIntent0Crd, + this.RenderingIntent1Crd, + this.RenderingIntent2Crd, + this.RenderingIntent3Crd); } } } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs index 77a913b14e..0d34d3ceba 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs @@ -116,12 +116,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc } /// - public override int GetHashCode() - { - unchecked - { - return (base.GetHashCode() * 397) ^ (this.CurveData?.GetHashCode() ?? 0); - } - } + public override int GetHashCode() => HashCode.Combine(this.Signature, this.CurveData); } } \ No newline at end of file diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs index 4510882904..0b8367303d 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs @@ -91,13 +91,10 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override int GetHashCode() { - unchecked - { - int hashCode = base.GetHashCode(); - hashCode = (hashCode * 397) ^ (this.Data?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ this.IsAscii.GetHashCode(); - return hashCode; - } + return HashCode.Combine( + this.Signature, + this.Data, + this.IsAscii); } } } \ No newline at end of file diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDateTimeTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDateTimeTagDataEntry.cs index 792c653f6c..104d243099 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDateTimeTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDateTimeTagDataEntry.cs @@ -66,10 +66,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override int GetHashCode() { - unchecked - { - return (base.GetHashCode() * 397) ^ this.Value.GetHashCode(); - } + return HashCode.Combine(this.Signature, this.Value); } } } \ No newline at end of file diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccFix16ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccFix16ArrayTagDataEntry.cs index a76310927b..0a114ea1f9 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccFix16ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccFix16ArrayTagDataEntry.cs @@ -64,12 +64,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc } /// - public override int GetHashCode() - { - unchecked - { - return (base.GetHashCode() * 397) ^ (this.Data?.GetHashCode() ?? 0); - } - } + public override int GetHashCode() => HashCode.Combine(this.Signature, this.Data); } } \ No newline at end of file diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs index 9a7f2123e2..dd180b2997 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs @@ -62,17 +62,14 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc : base(IccTypeSignature.Lut16, tagSignature) { Guard.NotNull(matrix, nameof(matrix)); - Guard.NotNull(inputValues, nameof(inputValues)); - Guard.NotNull(clutValues, nameof(clutValues)); - Guard.NotNull(outputValues, nameof(outputValues)); bool is3By3 = matrix.GetLength(0) == 3 && matrix.GetLength(1) == 3; Guard.IsTrue(is3By3, nameof(matrix), "Matrix must have a size of three by three"); this.Matrix = this.CreateMatrix(matrix); - this.InputValues = inputValues; - this.ClutValues = clutValues; - this.OutputValues = outputValues; + this.InputValues = inputValues ?? throw new ArgumentNullException(nameof(inputValues)); + this.ClutValues = clutValues ?? throw new ArgumentNullException(nameof(clutValues)); + this.OutputValues = outputValues ?? throw new ArgumentNullException(nameof(outputValues)); Guard.IsTrue(this.InputChannelCount == clutValues.InputChannelCount, nameof(clutValues), "Input channel count does not match the CLUT size"); Guard.IsTrue(this.OutputChannelCount == clutValues.OutputChannelCount, nameof(clutValues), "Output channel count does not match the CLUT size"); @@ -143,15 +140,12 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override int GetHashCode() { - unchecked - { - int hashCode = base.GetHashCode(); - hashCode = (hashCode * 397) ^ this.Matrix.GetHashCode(); - hashCode = (hashCode * 397) ^ (this.InputValues?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (this.ClutValues?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (this.OutputValues?.GetHashCode() ?? 0); - return hashCode; - } + return HashCode.Combine( + this.Signature, + this.Matrix, + this.InputValues, + this.ClutValues, + this.OutputValues); } private Matrix4x4 CreateMatrix(float[,] matrix) diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs index bc0335cd8b..b345d14a54 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs @@ -62,17 +62,14 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc : base(IccTypeSignature.Lut8, tagSignature) { Guard.NotNull(matrix, nameof(matrix)); - Guard.NotNull(inputValues, nameof(inputValues)); - Guard.NotNull(clutValues, nameof(clutValues)); - Guard.NotNull(outputValues, nameof(outputValues)); bool is3By3 = matrix.GetLength(0) == 3 && matrix.GetLength(1) == 3; Guard.IsTrue(is3By3, nameof(matrix), "Matrix must have a size of three by three"); this.Matrix = this.CreateMatrix(matrix); - this.InputValues = inputValues; - this.ClutValues = clutValues; - this.OutputValues = outputValues; + this.InputValues = inputValues ?? throw new ArgumentNullException(nameof(inputValues)); + this.ClutValues = clutValues ?? throw new ArgumentNullException(nameof(clutValues)); + this.OutputValues = outputValues ?? throw new ArgumentNullException(nameof(outputValues)); Guard.IsTrue(this.InputChannelCount == clutValues.InputChannelCount, nameof(clutValues), "Input channel count does not match the CLUT size"); Guard.IsTrue(this.OutputChannelCount == clutValues.OutputChannelCount, nameof(clutValues), "Output channel count does not match the CLUT size"); @@ -146,15 +143,12 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override int GetHashCode() { - unchecked - { - int hashCode = base.GetHashCode(); - hashCode = (hashCode * 397) ^ this.Matrix.GetHashCode(); - hashCode = (hashCode * 397) ^ (this.InputValues?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (this.ClutValues?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (this.OutputValues?.GetHashCode() ?? 0); - return hashCode; - } + return HashCode.Combine( + this.Signature, + this.Matrix, + this.InputValues, + this.ClutValues, + this.OutputValues); } private Matrix4x4 CreateMatrix(float[,] matrix) diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutAToBTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutAToBTagDataEntry.cs index 22d5f7b2f1..f7c0946320 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutAToBTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutAToBTagDataEntry.cs @@ -183,19 +183,21 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override int GetHashCode() { - unchecked - { - int hashCode = base.GetHashCode(); - hashCode = (hashCode * 397) ^ this.InputChannelCount; - hashCode = (hashCode * 397) ^ this.OutputChannelCount; - hashCode = (hashCode * 397) ^ this.Matrix3x3.GetHashCode(); - hashCode = (hashCode * 397) ^ this.Matrix3x1.GetHashCode(); - hashCode = (hashCode * 397) ^ (this.ClutValues?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (this.CurveB?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (this.CurveM?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (this.CurveA?.GetHashCode() ?? 0); - return hashCode; - } +#pragma warning disable SA1129 // Do not use default value type constructor + var hashCode = new HashCode(); +#pragma warning restore SA1129 // Do not use default value type constructor + + hashCode.Add(this.Signature); + hashCode.Add(this.InputChannelCount); + hashCode.Add(this.OutputChannelCount); + hashCode.Add(this.Matrix3x3); + hashCode.Add(this.Matrix3x1); + hashCode.Add(this.ClutValues); + hashCode.Add(this.CurveB); + hashCode.Add(this.CurveM); + hashCode.Add(this.CurveA); + + return hashCode.ToHashCode(); } private bool EqualsCurve(IccTagDataEntry[] thisCurves, IccTagDataEntry[] entryCurves) diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutBToATagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutBToATagDataEntry.cs index a739358b56..27572acd0b 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutBToATagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutBToATagDataEntry.cs @@ -183,19 +183,21 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override int GetHashCode() { - unchecked - { - int hashCode = base.GetHashCode(); - hashCode = (hashCode * 397) ^ this.InputChannelCount; - hashCode = (hashCode * 397) ^ this.OutputChannelCount; - hashCode = (hashCode * 397) ^ this.Matrix3x3.GetHashCode(); - hashCode = (hashCode * 397) ^ this.Matrix3x1.GetHashCode(); - hashCode = (hashCode * 397) ^ (this.ClutValues?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (this.CurveB?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (this.CurveM?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (this.CurveA?.GetHashCode() ?? 0); - return hashCode; - } +#pragma warning disable SA1129 // Do not use default value type constructor + var hashCode = new HashCode(); +#pragma warning restore SA1129 // Do not use default value type constructor + + hashCode.Add(this.Signature); + hashCode.Add(this.InputChannelCount); + hashCode.Add(this.OutputChannelCount); + hashCode.Add(this.Matrix3x3); + hashCode.Add(this.Matrix3x1); + hashCode.Add(this.ClutValues); + hashCode.Add(this.CurveB); + hashCode.Add(this.CurveM); + hashCode.Add(this.CurveA); + + return hashCode.ToHashCode(); } private bool EqualsCurve(IccTagDataEntry[] thisCurves, IccTagDataEntry[] entryCurves) diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMeasurementTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMeasurementTagDataEntry.cs index 262129a380..9247ca593f 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMeasurementTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMeasurementTagDataEntry.cs @@ -106,16 +106,13 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override int GetHashCode() { - unchecked - { - int hashCode = base.GetHashCode(); - hashCode = (hashCode * 397) ^ (int)this.Observer; - hashCode = (hashCode * 397) ^ this.XyzBacking.GetHashCode(); - hashCode = (hashCode * 397) ^ (int)this.Geometry; - hashCode = (hashCode * 397) ^ this.Flare.GetHashCode(); - hashCode = (hashCode * 397) ^ (int)this.Illuminant; - return hashCode; - } + return HashCode.Combine( + this.Signature, + this.Observer, + this.XyzBacking, + this.Geometry, + this.Flare, + this.Illuminant); } } } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiLocalizedUnicodeTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiLocalizedUnicodeTagDataEntry.cs index 48ed048bf9..1a06eb5880 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiLocalizedUnicodeTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiLocalizedUnicodeTagDataEntry.cs @@ -66,12 +66,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc } /// - public override int GetHashCode() - { - unchecked - { - return (base.GetHashCode() * 397) ^ (this.Texts?.GetHashCode() ?? 0); - } - } + public override int GetHashCode() => HashCode.Combine(this.Signature, this.Texts); } } \ No newline at end of file diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiProcessElementsTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiProcessElementsTagDataEntry.cs index 1429a0a878..f13fdb17fb 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiProcessElementsTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiProcessElementsTagDataEntry.cs @@ -90,14 +90,11 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override int GetHashCode() { - unchecked - { - int hashCode = base.GetHashCode(); - hashCode = (hashCode * 397) ^ this.InputChannelCount; - hashCode = (hashCode * 397) ^ this.OutputChannelCount; - hashCode = (hashCode * 397) ^ (this.Data?.GetHashCode() ?? 0); - return hashCode; - } + return HashCode.Combine( + this.Signature, + this.InputChannelCount, + this.OutputChannelCount, + this.Data); } } } \ No newline at end of file diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccNamedColor2TagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccNamedColor2TagDataEntry.cs index c32a45182d..957b8d5c3f 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccNamedColor2TagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccNamedColor2TagDataEntry.cs @@ -83,6 +83,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc if (colors.Length > 0) { coordinateCount = colors[0].DeviceCoordinates?.Length ?? 0; + Guard.IsFalse(colors.Any(t => (t.DeviceCoordinates?.Length ?? 0) != coordinateCount), nameof(colors), "Device coordinate count must be the same for all colors"); } @@ -154,16 +155,13 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override int GetHashCode() { - unchecked - { - int hashCode = base.GetHashCode(); - hashCode = (hashCode * 397) ^ this.CoordinateCount; - hashCode = (hashCode * 397) ^ (this.Prefix?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (this.Suffix?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ this.VendorFlags; - hashCode = (hashCode * 397) ^ (this.Colors?.GetHashCode() ?? 0); - return hashCode; - } + return HashCode.Combine( + this.Signature, + this.CoordinateCount, + this.Prefix, + this.Suffix, + this.VendorFlags, + this.Colors); } } } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccParametricCurveTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccParametricCurveTagDataEntry.cs index 46719b80f7..9ec497d3be 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccParametricCurveTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccParametricCurveTagDataEntry.cs @@ -28,7 +28,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc public IccParametricCurveTagDataEntry(IccParametricCurve curve, IccProfileTag tagSignature) : base(IccTypeSignature.ParametricCurve, tagSignature) { - this.Curve = curve; + this.Curve = curve ?? throw new ArgumentNullException(nameof(curve)); } /// @@ -65,12 +65,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc } /// - public override int GetHashCode() - { - unchecked - { - return (base.GetHashCode() * 397) ^ (this.Curve?.GetHashCode() ?? 0); - } - } + public override int GetHashCode() => HashCode.Combine(this.Signature, this.Curve); } } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceDescTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceDescTagDataEntry.cs index da6fcd7a2a..ff69115267 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceDescTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceDescTagDataEntry.cs @@ -67,12 +67,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc } /// - public override int GetHashCode() - { - unchecked - { - return (base.GetHashCode() * 397) ^ (this.Descriptions?.GetHashCode() ?? 0); - } - } + public override int GetHashCode() => HashCode.Combine(this.Signature, this.Descriptions); } } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceIdentifierTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceIdentifierTagDataEntry.cs index 51528a0736..c6cc0903c5 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceIdentifierTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceIdentifierTagDataEntry.cs @@ -65,12 +65,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc } /// - public override int GetHashCode() - { - unchecked - { - return (base.GetHashCode() * 397) ^ (this.Data?.GetHashCode() ?? 0); - } - } + public override int GetHashCode() => HashCode.Combine(this.Signature, this.Data); } } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccResponseCurveSet16TagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccResponseCurveSet16TagDataEntry.cs index e2cd5860bc..494aa2888b 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccResponseCurveSet16TagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccResponseCurveSet16TagDataEntry.cs @@ -83,13 +83,10 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override int GetHashCode() { - unchecked - { - int hashCode = base.GetHashCode(); - hashCode = (hashCode * 397) ^ this.ChannelCount.GetHashCode(); - hashCode = (hashCode * 397) ^ (this.Curves?.GetHashCode() ?? 0); - return hashCode; - } + return HashCode.Combine( + this.Signature, + this.ChannelCount, + this.Curves); } } } \ No newline at end of file diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccScreeningTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccScreeningTagDataEntry.cs index 0bf8abfcac..a073291ad1 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccScreeningTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccScreeningTagDataEntry.cs @@ -77,13 +77,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override int GetHashCode() { - unchecked - { - int hashCode = base.GetHashCode(); - hashCode = (hashCode * 397) ^ (int)this.Flags; - hashCode = (hashCode * 397) ^ (this.Channels?.GetHashCode() ?? 0); - return hashCode; - } + return HashCode.Combine(this.Signature, this.Flags, this.Channels); } } } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccSignatureTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccSignatureTagDataEntry.cs index da557e644f..287f0efb0c 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccSignatureTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccSignatureTagDataEntry.cs @@ -65,12 +65,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc } /// - public override int GetHashCode() - { - unchecked - { - return (base.GetHashCode() * 397) ^ (this.SignatureData?.GetHashCode() ?? 0); - } - } + public override int GetHashCode() => HashCode.Combine(this.Signature, this.SignatureData); } } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs index ca1e4c4915..8e6f4bc196 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs @@ -166,16 +166,13 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override int GetHashCode() { - unchecked - { - int hashCode = base.GetHashCode(); - hashCode = (hashCode * 397) ^ (this.Ascii?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (this.Unicode?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (this.ScriptCode?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (int)this.UnicodeLanguageCode; - hashCode = (hashCode * 397) ^ this.ScriptCodeCode.GetHashCode(); - return hashCode; - } + return HashCode.Combine( + this.Signature, + this.Ascii, + this.Unicode, + this.ScriptCode, + this.UnicodeLanguageCode, + this.ScriptCodeCode); } } } \ No newline at end of file diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextTagDataEntry.cs index f10712d96c..ab3b3fb6fb 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextTagDataEntry.cs @@ -64,12 +64,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc } /// - public override int GetHashCode() - { - unchecked - { - return (base.GetHashCode() * 397) ^ (this.Text?.GetHashCode() ?? 0); - } - } + public override int GetHashCode() => HashCode.Combine(this.Signature, this.Text); } } \ No newline at end of file diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUFix16ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUFix16ArrayTagDataEntry.cs index 19430dc7b8..464cbb9e75 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUFix16ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUFix16ArrayTagDataEntry.cs @@ -64,12 +64,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc } /// - public override int GetHashCode() - { - unchecked - { - return (base.GetHashCode() * 397) ^ (this.Data?.GetHashCode() ?? 0); - } - } + public override int GetHashCode() => HashCode.Combine(this.Signature, this.Data); } } \ No newline at end of file diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt16ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt16ArrayTagDataEntry.cs index d9c093bda0..1e7a7f8a90 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt16ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt16ArrayTagDataEntry.cs @@ -64,12 +64,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc } /// - public override int GetHashCode() - { - unchecked - { - return (base.GetHashCode() * 397) ^ (this.Data?.GetHashCode() ?? 0); - } - } + public override int GetHashCode() => HashCode.Combine(this.Signature, this.Data); } -} +} \ No newline at end of file diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt32ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt32ArrayTagDataEntry.cs index 8031919290..affdc8720b 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt32ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt32ArrayTagDataEntry.cs @@ -64,12 +64,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc } /// - public override int GetHashCode() - { - unchecked - { - return (base.GetHashCode() * 397) ^ (this.Data?.GetHashCode() ?? 0); - } - } + public override int GetHashCode() => HashCode.Combine(this.Signature, this.Data); } } \ No newline at end of file diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt64ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt64ArrayTagDataEntry.cs index 2973b9ae6b..36d48d6135 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt64ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt64ArrayTagDataEntry.cs @@ -65,12 +65,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc } /// - public override int GetHashCode() - { - unchecked - { - return (base.GetHashCode() * 397) ^ (this.Data?.GetHashCode() ?? 0); - } - } + public override int GetHashCode() => HashCode.Combine(this.Signature, this.Data); } } \ No newline at end of file diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt8ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt8ArrayTagDataEntry.cs index 2391ce96a6..b2f2677575 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt8ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt8ArrayTagDataEntry.cs @@ -64,12 +64,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc } /// - public override int GetHashCode() - { - unchecked - { - return (base.GetHashCode() * 397) ^ (this.Data?.GetHashCode() ?? 0); - } - } + public override int GetHashCode() => HashCode.Combine(this.Signature, this.Data); } } \ No newline at end of file diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUcrBgTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUcrBgTagDataEntry.cs index eed4f97d47..510930e397 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUcrBgTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUcrBgTagDataEntry.cs @@ -86,14 +86,11 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override int GetHashCode() { - unchecked - { - int hashCode = base.GetHashCode(); - hashCode = (hashCode * 397) ^ (this.UcrCurve?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (this.BgCurve?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (this.Description?.GetHashCode() ?? 0); - return hashCode; - } + return HashCode.Combine( + this.Signature, + this.UcrCurve, + this.BgCurve, + this.Description); } } } \ No newline at end of file diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUnknownTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUnknownTagDataEntry.cs index da206a968b..a0089e7359 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUnknownTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUnknownTagDataEntry.cs @@ -64,12 +64,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc } /// - public override int GetHashCode() - { - unchecked - { - return (base.GetHashCode() * 397) ^ (this.Data?.GetHashCode() ?? 0); - } - } + public override int GetHashCode() => HashCode.Combine(this.Signature, this.Data); } } \ No newline at end of file diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccViewingConditionsTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccViewingConditionsTagDataEntry.cs index 6be21dcc95..bd636d4f2c 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccViewingConditionsTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccViewingConditionsTagDataEntry.cs @@ -86,14 +86,11 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override int GetHashCode() { - unchecked - { - int hashCode = base.GetHashCode(); - hashCode = (hashCode * 397) ^ this.IlluminantXyz.GetHashCode(); - hashCode = (hashCode * 397) ^ this.SurroundXyz.GetHashCode(); - hashCode = (hashCode * 397) ^ (int)this.Illuminant; - return hashCode; - } + return HashCode.Combine( + this.Signature, + this.IlluminantXyz, + this.SurroundXyz, + this.Illuminant); } } } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccClut.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccClut.cs index 4878d96e4b..3f7cad3afe 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccClut.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccClut.cs @@ -142,15 +142,12 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override int GetHashCode() { - unchecked - { - int hashCode = this.Values?.GetHashCode() ?? 0; - hashCode = (hashCode * 397) ^ (int)this.DataType; - hashCode = (hashCode * 397) ^ this.InputChannelCount; - hashCode = (hashCode * 397) ^ this.OutputChannelCount; - hashCode = (hashCode * 397) ^ (this.GridPointCount?.GetHashCode() ?? 0); - return hashCode; - } + return HashCode.Combine( + this.Values, + this.DataType, + this.InputChannelCount, + this.OutputChannelCount, + this.GridPointCount); } private bool EqualsValuesArray(IccClut other) diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccColorantTableEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccColorantTableEntry.cs index 56aa8b335d..8f273dd603 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccColorantTableEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccColorantTableEntry.cs @@ -102,14 +102,11 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override int GetHashCode() { - unchecked - { - int hashCode = this.Name.GetHashCode(); - hashCode = (hashCode * 397) ^ this.Pcs1.GetHashCode(); - hashCode = (hashCode * 397) ^ this.Pcs2.GetHashCode(); - hashCode = (hashCode * 397) ^ this.Pcs3.GetHashCode(); - return hashCode; - } + return HashCode.Combine( + this.Name, + this.Pcs1, + this.Pcs2, + this.Pcs3); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccNamedColor.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccNamedColor.cs index 5b013fc2c1..b7cb5bc495 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccNamedColor.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccNamedColor.cs @@ -80,27 +80,23 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc } /// - public bool Equals(IccNamedColor other) => - this.Name == other.Name && - this.PcsCoordinates.SequenceEqual(other.PcsCoordinates) && - this.DeviceCoordinates.SequenceEqual(other.DeviceCoordinates); + public bool Equals(IccNamedColor other) + { + return this.Name.Equals(other.Name) + && this.PcsCoordinates.SequenceEqual(other.PcsCoordinates) + && this.DeviceCoordinates.SequenceEqual(other.DeviceCoordinates); + } /// public override int GetHashCode() { - unchecked - { - int hashCode = this.Name.GetHashCode(); - hashCode = (hashCode * 397) ^ this.PcsCoordinates.GetHashCode(); - hashCode = (hashCode * 397) ^ this.DeviceCoordinates.GetHashCode(); - return hashCode; - } + return HashCode.Combine( + this.Name, + this.PcsCoordinates, + this.DeviceCoordinates); } /// - public override string ToString() - { - return this.Name; - } + public override string ToString() => this.Name; } } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccPositionNumber.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccPositionNumber.cs index aad130b0de..745312f563 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccPositionNumber.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccPositionNumber.cs @@ -73,15 +73,9 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc this.Size == other.Size; /// - public override int GetHashCode() - { - return unchecked((int)(this.Offset ^ this.Size)); - } + public override int GetHashCode() => unchecked((int)(this.Offset ^ this.Size)); /// - public override string ToString() - { - return $"{this.Offset}; {this.Size}"; - } + public override string ToString() => $"{this.Offset}; {this.Size}"; } } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileDescription.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileDescription.cs index 9db4bb9c48..7e7c527ead 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileDescription.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileDescription.cs @@ -28,15 +28,12 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc IccLocalizedString[] deviceManufacturerInfo, IccLocalizedString[] deviceModelInfo) { - Guard.NotNull(deviceManufacturerInfo, nameof(deviceManufacturerInfo)); - Guard.NotNull(deviceModelInfo, nameof(deviceModelInfo)); - this.DeviceManufacturer = deviceManufacturer; this.DeviceModel = deviceModel; this.DeviceAttributes = deviceAttributes; this.TechnologyInformation = technologyInformation; - this.DeviceManufacturerInfo = deviceManufacturerInfo; - this.DeviceModelInfo = deviceModelInfo; + this.DeviceManufacturerInfo = deviceManufacturerInfo ?? throw new ArgumentNullException(nameof(deviceManufacturerInfo)); + this.DeviceModelInfo = deviceModelInfo ?? throw new ArgumentNullException(nameof(deviceModelInfo)); } /// @@ -87,16 +84,13 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override int GetHashCode() { - unchecked - { - int hashCode = (int)this.DeviceManufacturer; - hashCode = (hashCode * 397) ^ (int)this.DeviceModel; - hashCode = (hashCode * 397) ^ this.DeviceAttributes.GetHashCode(); - hashCode = (hashCode * 397) ^ (int)this.TechnologyInformation; - hashCode = (hashCode * 397) ^ (this.DeviceManufacturerInfo?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (this.DeviceModelInfo?.GetHashCode() ?? 0); - return hashCode; - } + return HashCode.Combine( + this.DeviceManufacturer, + this.DeviceModel, + this.DeviceAttributes, + this.TechnologyInformation, + this.DeviceManufacturerInfo, + this.DeviceModelInfo); } } } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileId.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileId.cs index 1389997109..f64d5409ae 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileId.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileId.cs @@ -101,14 +101,11 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override int GetHashCode() { - unchecked - { - int hashCode = this.Part1.GetHashCode(); - hashCode = (hashCode * 397) ^ this.Part2.GetHashCode(); - hashCode = (hashCode * 397) ^ this.Part3.GetHashCode(); - hashCode = (hashCode * 397) ^ this.Part4.GetHashCode(); - return hashCode; - } + return HashCode.Combine( + this.Part1, + this.Part2, + this.Part3, + this.Part4); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileSequenceIdentifier.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileSequenceIdentifier.cs index d5362ad706..ae451c5db8 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileSequenceIdentifier.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileSequenceIdentifier.cs @@ -18,10 +18,8 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// Description of the profile public IccProfileSequenceIdentifier(IccProfileId id, IccLocalizedString[] description) { - Guard.NotNull(description, nameof(description)); - this.Id = id; - this.Description = description; + this.Description = description ?? throw new ArgumentNullException(nameof(description)); } /// @@ -46,12 +44,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc } /// - public override int GetHashCode() - { - unchecked - { - return (this.Id.GetHashCode() * 397) ^ (this.Description?.GetHashCode() ?? 0); - } - } + public override int GetHashCode() => HashCode.Combine(this.Id, this.Description); } } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccResponseNumber.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccResponseNumber.cs index d1da2366e7..8cae869925 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccResponseNumber.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccResponseNumber.cs @@ -73,20 +73,9 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc this.MeasurementValue == other.MeasurementValue; /// - public override int GetHashCode() - { - unchecked - { - int hashCode = this.DeviceCode.GetHashCode(); - hashCode = (hashCode * 397) ^ this.MeasurementValue.GetHashCode(); - return hashCode; - } - } + public override int GetHashCode() => HashCode.Combine(this.DeviceCode, this.MeasurementValue); /// - public override string ToString() - { - return $"Code: {this.DeviceCode}; Value: {this.MeasurementValue}"; - } + public override string ToString() => $"Code: {this.DeviceCode}; Value: {this.MeasurementValue}"; } } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccScreeningChannel.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccScreeningChannel.cs index 1c4ac8465c..e8885a66bf 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccScreeningChannel.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccScreeningChannel.cs @@ -85,13 +85,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override int GetHashCode() { - unchecked - { - int hashCode = this.Frequency.GetHashCode(); - hashCode = (hashCode * 397) ^ this.Angle.GetHashCode(); - hashCode = (hashCode * 397) ^ (int)this.SpotShape; - return hashCode; - } + return HashCode.Combine(this.Frequency, this.Angle, this.SpotShape); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccTagTableEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccTagTableEntry.cs index 04357dcf67..d93e068c52 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccTagTableEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccTagTableEntry.cs @@ -76,20 +76,14 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccTagTableEntry other) => - this.Signature == other.Signature && - this.Offset == other.Offset && - this.DataSize == other.DataSize; + this.Signature.Equals(other.Signature) && + this.Offset.Equals(other.Offset) && + this.DataSize.Equals(other.DataSize); /// public override int GetHashCode() { - unchecked - { - int hashCode = this.Signature.GetHashCode(); - hashCode = (hashCode * 397) ^ this.Offset.GetHashCode(); - hashCode = (hashCode * 397) ^ this.DataSize.GetHashCode(); - return hashCode; - } + return HashCode.Combine(this.Signature, this.Offset, this.DataSize); } /// diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs index 9207f046c4..96ff7da6f6 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using System; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -189,10 +190,6 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public override int GetHashCode() - { - int hash = HashHelpers.Combine(this.R.GetHashCode(), this.G.GetHashCode()); - return HashHelpers.Combine(hash, this.B.GetHashCode()); - } + public override int GetHashCode() => HashCode.Combine(this.R, this.B, this.G); } } \ No newline at end of file diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs index 293fe0acbf..86565731d2 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using System; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -200,11 +201,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public override int GetHashCode() - { - int hash = HashHelpers.Combine(this.R.GetHashCode(), this.G.GetHashCode()); - return HashHelpers.Combine(hash, this.B.GetHashCode()); - } + public override int GetHashCode() => HashCode.Combine(this.R, this.B, this.G); /// public override string ToString() => $"Rgb24({this.R}, {this.G}, {this.B})"; diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs index 81497e5f18..eda116a46c 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs @@ -189,11 +189,6 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public override int GetHashCode() - { - return HashHelpers.Combine( - this.R.GetHashCode(), - HashHelpers.Combine(this.G.GetHashCode(), this.B.GetHashCode())); - } + public override int GetHashCode() => HashCode.Combine(this.R, this.G, this.B); } } \ No newline at end of file diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs b/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs index ff4c69d701..d65a5ade78 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs @@ -197,11 +197,6 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - public override int GetHashCode() - { - int hash = HashHelpers.Combine(this.R.GetHashCode(), this.G.GetHashCode()); - hash = HashHelpers.Combine(hash, this.B.GetHashCode()); - return HashHelpers.Combine(hash, this.A.GetHashCode()); - } + public override int GetHashCode() => HashCode.Combine(this.R, this.G, this.B, this.A); } } \ No newline at end of file diff --git a/src/ImageSharp/Primitives/ValueSize.cs b/src/ImageSharp/Primitives/ValueSize.cs index 8af9ba2e48..e5e086540d 100644 --- a/src/ImageSharp/Primitives/ValueSize.cs +++ b/src/ImageSharp/Primitives/ValueSize.cs @@ -133,9 +133,6 @@ namespace SixLabors.ImageSharp.Primitives } /// - public override int GetHashCode() - { - return HashHelpers.Combine(this.Value.GetHashCode(), this.Type.GetHashCode()); - } + public override int GetHashCode() => HashCode.Combine(this.Value, this.Type); } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessorBase.cs b/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessorBase.cs index f01865ec05..43f6c8a454 100644 --- a/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessorBase.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessorBase.cs @@ -95,7 +95,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering base.BeforeFrameApply(source, sourceRectangle, configuration); // Lazy init paletteVector: - if (this.paletteVector == null) + if (this.paletteVector is null) { this.paletteVector = new Vector4[this.Palette.Length]; PixelOperations.Instance.ToScaledVector4(configuration, this.Palette, this.paletteVector); diff --git a/src/ImageSharp/Processing/Processors/Dithering/PixelPair.cs b/src/ImageSharp/Processing/Processors/Dithering/PixelPair.cs index b7bea2c746..13660d30ab 100644 --- a/src/ImageSharp/Processing/Processors/Dithering/PixelPair.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/PixelPair.cs @@ -43,7 +43,6 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering => obj is PixelPair other && this.First.Equals(other.First) && this.Second.Equals(other.Second); /// - public override int GetHashCode() - => HashHelpers.Combine(this.First.GetHashCode(), this.Second.GetHashCode()); + public override int GetHashCode() => HashCode.Combine(this.First, this.Second); } } \ No newline at end of file diff --git a/src/Shared/AssemblyInfo.Common.cs b/src/Shared/AssemblyInfo.Common.cs index 327d3abd75..82e1dac6c4 100644 --- a/src/Shared/AssemblyInfo.Common.cs +++ b/src/Shared/AssemblyInfo.Common.cs @@ -5,32 +5,6 @@ using System.Reflection; using System.Resources; using System.Runtime.CompilerServices; -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyDescription("A cross-platform library for processing of image files; written in C#")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Six Labors")] -[assembly: AssemblyProduct("SixLabors.ImageSharp")] -[assembly: AssemblyCopyright("Copyright (c) Six Labors and contributors.")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: NeutralResourcesLanguage("en")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] -[assembly: AssemblyInformationalVersion("1.0.0.0")] - // Ensure the internals can be built and tested. [assembly: InternalsVisibleTo("SixLabors.ImageSharp.Drawing")] [assembly: InternalsVisibleTo("ImageSharp.Benchmarks")] diff --git a/tests/ImageSharp.Benchmarks/General/BasicMath/ModuloPowerOfTwoConstant.cs b/tests/ImageSharp.Benchmarks/General/BasicMath/ModuloPowerOfTwoConstant.cs index 9ddfad7222..94349b20b6 100644 --- a/tests/ImageSharp.Benchmarks/General/BasicMath/ModuloPowerOfTwoConstant.cs +++ b/tests/ImageSharp.Benchmarks/General/BasicMath/ModuloPowerOfTwoConstant.cs @@ -1,5 +1,4 @@ using BenchmarkDotNet.Attributes; -using BenchmarkDotNet.Attributes.Jobs; namespace SixLabors.ImageSharp.Benchmarks.General.BasicMath { diff --git a/tests/ImageSharp.Benchmarks/General/BasicMath/ModuloPowerOfTwoVariable.cs b/tests/ImageSharp.Benchmarks/General/BasicMath/ModuloPowerOfTwoVariable.cs index 5c2fe81fa2..d5683673fe 100644 --- a/tests/ImageSharp.Benchmarks/General/BasicMath/ModuloPowerOfTwoVariable.cs +++ b/tests/ImageSharp.Benchmarks/General/BasicMath/ModuloPowerOfTwoVariable.cs @@ -1,5 +1,4 @@ using BenchmarkDotNet.Attributes; -using BenchmarkDotNet.Attributes.Jobs; namespace SixLabors.ImageSharp.Benchmarks.General.BasicMath { diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_Rgba32_To_Bgra32.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_Rgba32_To_Bgra32.cs index a8fea68661..3b288260c5 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_Rgba32_To_Bgra32.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_Rgba32_To_Bgra32.cs @@ -4,7 +4,6 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using BenchmarkDotNet.Attributes; -using BenchmarkDotNet.Attributes.Jobs; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Tuples; diff --git a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj index a705c9bacb..f941203db1 100644 --- a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj +++ b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj @@ -16,7 +16,7 @@ - + diff --git a/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj b/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj index 4d7b7de759..cb286cc286 100644 --- a/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj +++ b/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj @@ -18,19 +18,13 @@ - - - - + - - - \ No newline at end of file diff --git a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj index 86c1a7a259..7452d6e498 100644 --- a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj +++ b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj @@ -28,15 +28,12 @@ - - - - - + +