diff --git a/src/ImageProcessor/Imaging/CropLayer.cs b/src/ImageProcessor/Imaging/CropLayer.cs index 8d10f3b407..97da50d44b 100644 --- a/src/ImageProcessor/Imaging/CropLayer.cs +++ b/src/ImageProcessor/Imaging/CropLayer.cs @@ -107,17 +107,22 @@ namespace ImageProcessor.Imaging } /// - /// Returns a hash code for this instance. + /// Serves as a hash function for a particular type. /// /// - /// A hash code for this instance, suitable for use in hashing algorithms - /// and data structures like a hash table. + /// A hash code for the current . /// public override int GetHashCode() { - return this.Top.GetHashCode() + this.Right.GetHashCode() + - this.Bottom.GetHashCode() + this.Left.GetHashCode() + - this.CropMode.GetHashCode(); + unchecked + { + int hashCode = this.Left.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Top.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Right.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Bottom.GetHashCode(); + hashCode = (hashCode * 397) ^ (int)this.CropMode; + return hashCode; + } } } } diff --git a/src/ImageProcessor/Imaging/FastBitmap.cs b/src/ImageProcessor/Imaging/FastBitmap.cs index 539f941c29..aea18d3265 100644 --- a/src/ImageProcessor/Imaging/FastBitmap.cs +++ b/src/ImageProcessor/Imaging/FastBitmap.cs @@ -213,6 +213,36 @@ namespace ImageProcessor.Imaging GC.SuppressFinalize(this); } + /// + /// Determines whether the specified is equal to the current . + /// + /// + /// true if the specified object is equal to the current object; otherwise, false. + /// + /// The object to compare with the current object. + public override bool Equals(object obj) + { + FastBitmap fastBitmap = obj as FastBitmap; + + if (fastBitmap == null) + { + return false; + } + + return this.bitmap == fastBitmap.bitmap; + } + + /// + /// Serves as a hash function for a particular type. + /// + /// + /// A hash code for the current . + /// + public override int GetHashCode() + { + return this.bitmap.GetHashCode(); + } + /// /// Disposes the object and frees resources for the Garbage Collector. /// diff --git a/src/ImageProcessor/Imaging/Filters/Photo/MatrixFilterBase.cs b/src/ImageProcessor/Imaging/Filters/Photo/MatrixFilterBase.cs index 482dfd5e31..83aa8d7bf8 100644 --- a/src/ImageProcessor/Imaging/Filters/Photo/MatrixFilterBase.cs +++ b/src/ImageProcessor/Imaging/Filters/Photo/MatrixFilterBase.cs @@ -54,14 +54,19 @@ namespace ImageProcessor.Imaging.Filters.Photo } /// - /// Returns a hash code for this instance. + /// Returns the hash code for this instance. /// /// - /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// A 32-bit signed integer that is the hash code for this instance. /// public override int GetHashCode() { - return this.GetType().Name.GetHashCode() ^ this.Matrix.GetHashCode(); + unchecked + { + int hashCode = GetType().Name.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Matrix.GetHashCode(); + return hashCode; + } } } } \ No newline at end of file diff --git a/src/ImageProcessor/Imaging/Formats/FormatBase.cs b/src/ImageProcessor/Imaging/Formats/FormatBase.cs index 189bad8c38..c741346702 100644 --- a/src/ImageProcessor/Imaging/Formats/FormatBase.cs +++ b/src/ImageProcessor/Imaging/Formats/FormatBase.cs @@ -147,14 +147,20 @@ namespace ImageProcessor.Imaging.Formats } /// - /// Returns a hash code for this instance. + /// Returns the hash code for this instance. /// /// - /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// A 32-bit signed integer that is the hash code for this instance. /// public override int GetHashCode() { - return this.MimeType.GetHashCode(); + unchecked + { + int hashCode = this.MimeType.GetHashCode(); + hashCode = (hashCode * 397) ^ this.IsIndexed.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Quality; + return hashCode; + } } } } diff --git a/src/ImageProcessor/Imaging/GaussianLayer.cs b/src/ImageProcessor/Imaging/GaussianLayer.cs index 6daf65a1a2..20d6a059ab 100644 --- a/src/ImageProcessor/Imaging/GaussianLayer.cs +++ b/src/ImageProcessor/Imaging/GaussianLayer.cs @@ -166,14 +166,20 @@ namespace ImageProcessor.Imaging } /// - /// Returns a hash code value that represents this object. + /// Serves as a hash function for a particular type. /// /// - /// A hash code that represents this object. + /// A hash code for the current . /// public override int GetHashCode() { - return this.Size.GetHashCode() + this.Sigma.GetHashCode() + this.Threshold.GetHashCode(); + unchecked + { + int hashCode = this.Size; + hashCode = (hashCode * 397) ^ this.Size.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Threshold; + return hashCode; + } } } } diff --git a/src/ImageProcessor/Imaging/PixelData.cs b/src/ImageProcessor/Imaging/PixelData.cs index b899ab5b24..741b295cdc 100644 --- a/src/ImageProcessor/Imaging/PixelData.cs +++ b/src/ImageProcessor/Imaging/PixelData.cs @@ -10,6 +10,8 @@ namespace ImageProcessor.Imaging { + using System.Collections.Generic; + /// /// Contains the component parts that make up a single pixel. /// @@ -34,5 +36,56 @@ namespace ImageProcessor.Imaging /// The alpha component. /// public byte A; + + /// + /// Indicates whether this instance and a specified object are equal. + /// + /// + /// true if and this instance are the same type and represent the same value; otherwise, false. + /// + /// Another object to compare to. + public override bool Equals(object obj) + { + if (obj is PixelData) + { + PixelData pixelData = (PixelData)obj; + + return this.B == pixelData.B && this.G == pixelData.G & this.R == pixelData.R & this.A == pixelData.A; + } + + return false; + } + + /// + /// Returns the hash code for this instance. + /// + /// + /// A 32-bit signed integer that is the hash code for this instance. + /// + public override int GetHashCode() + { + return this.GetHashCode(this); + } + + /// + /// Returns the hash code for the given 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(PixelData obj) + { + unchecked + { + int hashCode = obj.B.GetHashCode(); + hashCode = (hashCode * 397) ^ obj.G.GetHashCode(); + hashCode = (hashCode * 397) ^ obj.R.GetHashCode(); + hashCode = (hashCode * 397) ^ obj.A.GetHashCode(); + return hashCode; + } + } } } \ No newline at end of file diff --git a/src/ImageProcessor/Imaging/ResizeLayer.cs b/src/ImageProcessor/Imaging/ResizeLayer.cs index dc5185922e..b26631768a 100644 --- a/src/ImageProcessor/Imaging/ResizeLayer.cs +++ b/src/ImageProcessor/Imaging/ResizeLayer.cs @@ -100,21 +100,27 @@ namespace ImageProcessor.Imaging return this.Size == resizeLayer.Size && this.ResizeMode == resizeLayer.ResizeMode && this.AnchorPosition == resizeLayer.AnchorPosition - && this.Upscale == resizeLayer.Upscale; + && this.Upscale == resizeLayer.Upscale + && this.CenterCoordinates == resizeLayer.CenterCoordinates; } /// - /// Returns a hash code value that represents this object. + /// Returns the hash code for this instance. /// /// - /// A hash code that represents this object. + /// A 32-bit signed integer that is the hash code for this instance. /// public override int GetHashCode() { - return this.Size.GetHashCode() + - this.ResizeMode.GetHashCode() + - this.AnchorPosition.GetHashCode() + - this.Upscale.GetHashCode(); + unchecked + { + int hashCode = this.Size.GetHashCode(); + hashCode = (hashCode * 397) ^ (int)this.ResizeMode; + hashCode = (hashCode * 397) ^ (int)this.AnchorPosition; + hashCode = (hashCode * 397) ^ this.Upscale.GetHashCode(); + hashCode = (hashCode * 397) ^ (this.CenterCoordinates != null ? this.CenterCoordinates.GetHashCode() : 0); + return hashCode; + } } } } \ No newline at end of file diff --git a/src/ImageProcessor/Imaging/RoundedCornerLayer.cs b/src/ImageProcessor/Imaging/RoundedCornerLayer.cs index 05606d4b2d..efa3deacc1 100644 --- a/src/ImageProcessor/Imaging/RoundedCornerLayer.cs +++ b/src/ImageProcessor/Imaging/RoundedCornerLayer.cs @@ -96,16 +96,22 @@ namespace ImageProcessor.Imaging } /// - /// Returns a hash code value that represents this object. + /// Returns the hash code for this instance. /// /// - /// A hash code that represents this object. + /// A 32-bit signed integer that is the hash code for this instance. /// public override int GetHashCode() { - return this.Radius.GetHashCode() + - this.TopLeft.GetHashCode() + this.TopRight.GetHashCode() + - this.BottomLeft.GetHashCode() + this.BottomRight.GetHashCode(); + unchecked + { + int hashCode = this.Radius; + hashCode = (hashCode * 397) ^ this.TopLeft.GetHashCode(); + hashCode = (hashCode * 397) ^ this.TopRight.GetHashCode(); + hashCode = (hashCode * 397) ^ this.BottomLeft.GetHashCode(); + hashCode = (hashCode * 397) ^ this.BottomRight.GetHashCode(); + return hashCode; + } } } } diff --git a/src/ImageProcessor/Imaging/TextLayer.cs b/src/ImageProcessor/Imaging/TextLayer.cs index 490b7f95e4..22c854ec24 100644 --- a/src/ImageProcessor/Imaging/TextLayer.cs +++ b/src/ImageProcessor/Imaging/TextLayer.cs @@ -160,21 +160,25 @@ namespace ImageProcessor.Imaging } /// - /// Returns a hash code value that represents this object. + /// Returns the hash code for this instance. /// /// - /// A hash code that represents this object. + /// A 32-bit signed integer that is the hash code for this instance. /// public override int GetHashCode() { - return this.Text.GetHashCode() + - this.FontColor.GetHashCode() + - this.FontFamily.GetHashCode() + - this.FontSize.GetHashCode() + - this.Style.GetHashCode() + - this.DropShadow.GetHashCode() + - this.Opacity.GetHashCode() + - this.Position.GetHashCode(); + unchecked + { + int hashCode = this.Text != null ? this.Text.GetHashCode() : 0; + hashCode = (hashCode * 397) ^ this.DropShadow.GetHashCode(); + hashCode = (hashCode * 397) ^ (this.FontFamily != null ? this.FontFamily.GetHashCode() : 0); + hashCode = (hashCode * 397) ^ (int)this.Style; + hashCode = (hashCode * 397) ^ this.FontColor.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Opacity; + hashCode = (hashCode * 397) ^ this.FontSize; + hashCode = (hashCode * 397) ^ this.Position.GetHashCode(); + return hashCode; + } } } } diff --git a/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/Imaging/ContentAwareResizeLayer.cs b/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/Imaging/ContentAwareResizeLayer.cs index c8b5dc02fe..648f318791 100644 --- a/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/Imaging/ContentAwareResizeLayer.cs +++ b/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/Imaging/ContentAwareResizeLayer.cs @@ -182,20 +182,24 @@ namespace ImageProcessor.Plugins.Cair.Imaging } /// - /// Returns a hash code value that represents this object. + /// Returns the hash code for this instance. /// /// - /// A hash code that represents this object. + /// A 32-bit signed integer that is the hash code for this instance. /// public override int GetHashCode() { - return this.Size.GetHashCode() + - this.ConvolutionType.GetHashCode() + - this.EnergyFunction.GetHashCode() + - this.OutputType.GetHashCode() + - this.Parallelize.GetHashCode() + - this.Timeout.GetHashCode() + - this.WeightPath.GetHashCode(); + unchecked + { + int hashCode = (int)this.ConvolutionType; + hashCode = (hashCode * 397) ^ (int)this.EnergyFunction; + hashCode = (hashCode * 397) ^ this.Parallelize.GetHashCode(); + hashCode = (hashCode * 397) ^ (int)this.OutputType; + hashCode = (hashCode * 397) ^ this.Timeout; + hashCode = (hashCode * 397) ^ this.Size.GetHashCode(); + hashCode = (hashCode * 397) ^ (this.WeightPath != null ? this.WeightPath.GetHashCode() : 0); + return hashCode; + } } } }