Browse Source

Fixing hash code implementations.

Former-commit-id: f38a8859ae25e045a6778ff2393246ab0be95f9d
Former-commit-id: bc9b4d589a62248e50f2e8f77deb7edf0558e562
pull/17/head
James South 12 years ago
parent
commit
9f61b129d2
  1. 17
      src/ImageProcessor/Imaging/CropLayer.cs
  2. 30
      src/ImageProcessor/Imaging/FastBitmap.cs
  3. 11
      src/ImageProcessor/Imaging/Filters/Photo/MatrixFilterBase.cs
  4. 12
      src/ImageProcessor/Imaging/Formats/FormatBase.cs
  5. 12
      src/ImageProcessor/Imaging/GaussianLayer.cs
  6. 53
      src/ImageProcessor/Imaging/PixelData.cs
  7. 20
      src/ImageProcessor/Imaging/ResizeLayer.cs
  8. 16
      src/ImageProcessor/Imaging/RoundedCornerLayer.cs
  9. 24
      src/ImageProcessor/Imaging/TextLayer.cs
  10. 22
      src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/Imaging/ContentAwareResizeLayer.cs

17
src/ImageProcessor/Imaging/CropLayer.cs

@ -107,17 +107,22 @@ namespace ImageProcessor.Imaging
}
/// <summary>
/// Returns a hash code for this instance.
/// Serves as a hash function for a particular type.
/// </summary>
/// <returns>
/// 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 <see cref="T:System.Object"/>.
/// </returns>
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;
}
}
}
}

30
src/ImageProcessor/Imaging/FastBitmap.cs

@ -213,6 +213,36 @@ namespace ImageProcessor.Imaging
GC.SuppressFinalize(this);
}
/// <summary>
/// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
/// </summary>
/// <returns>
/// true if the specified object is equal to the current object; otherwise, false.
/// </returns>
/// <param name="obj">The object to compare with the current object. </param>
public override bool Equals(object obj)
{
FastBitmap fastBitmap = obj as FastBitmap;
if (fastBitmap == null)
{
return false;
}
return this.bitmap == fastBitmap.bitmap;
}
/// <summary>
/// Serves as a hash function for a particular type.
/// </summary>
/// <returns>
/// A hash code for the current <see cref="T:System.Object"/>.
/// </returns>
public override int GetHashCode()
{
return this.bitmap.GetHashCode();
}
/// <summary>
/// Disposes the object and frees resources for the Garbage Collector.
/// </summary>

11
src/ImageProcessor/Imaging/Filters/Photo/MatrixFilterBase.cs

@ -54,14 +54,19 @@ namespace ImageProcessor.Imaging.Filters.Photo
}
/// <summary>
/// Returns a hash code for this instance.
/// Returns the hash code for this instance.
/// </summary>
/// <returns>
/// 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.
/// </returns>
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;
}
}
}
}

12
src/ImageProcessor/Imaging/Formats/FormatBase.cs

@ -147,14 +147,20 @@ namespace ImageProcessor.Imaging.Formats
}
/// <summary>
/// Returns a hash code for this instance.
/// Returns the hash code for this instance.
/// </summary>
/// <returns>
/// 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.
/// </returns>
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;
}
}
}
}

12
src/ImageProcessor/Imaging/GaussianLayer.cs

@ -166,14 +166,20 @@ namespace ImageProcessor.Imaging
}
/// <summary>
/// Returns a hash code value that represents this object.
/// Serves as a hash function for a particular type.
/// </summary>
/// <returns>
/// A hash code that represents this object.
/// A hash code for the current <see cref="T:System.Object"/>.
/// </returns>
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;
}
}
}
}

53
src/ImageProcessor/Imaging/PixelData.cs

@ -10,6 +10,8 @@
namespace ImageProcessor.Imaging
{
using System.Collections.Generic;
/// <summary>
/// Contains the component parts that make up a single pixel.
/// </summary>
@ -34,5 +36,56 @@ namespace ImageProcessor.Imaging
/// The alpha component.
/// </summary>
public byte A;
/// <summary>
/// Indicates whether this instance and a specified object are equal.
/// </summary>
/// <returns>
/// true if <paramref name="obj"/> and this instance are the same type and represent the same value; otherwise, false.
/// </returns>
/// <param name="obj">Another object to compare to. </param>
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;
}
/// <summary>
/// Returns the hash code for this instance.
/// </summary>
/// <returns>
/// A 32-bit signed integer that is the hash code for this instance.
/// </returns>
public override int GetHashCode()
{
return this.GetHashCode(this);
}
/// <summary>
/// Returns the hash code for the given instance.
/// </summary>
/// <param name="obj">
/// The instance of <see cref="PixelData"/> to return the hash code for.
/// </param>
/// <returns>
/// A 32-bit signed integer that is the hash code for this instance.
/// </returns>
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;
}
}
}
}

20
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;
}
/// <summary>
/// Returns a hash code value that represents this object.
/// Returns the hash code for this instance.
/// </summary>
/// <returns>
/// A hash code that represents this object.
/// A 32-bit signed integer that is the hash code for this instance.
/// </returns>
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;
}
}
}
}

16
src/ImageProcessor/Imaging/RoundedCornerLayer.cs

@ -96,16 +96,22 @@ namespace ImageProcessor.Imaging
}
/// <summary>
/// Returns a hash code value that represents this object.
/// Returns the hash code for this instance.
/// </summary>
/// <returns>
/// A hash code that represents this object.
/// A 32-bit signed integer that is the hash code for this instance.
/// </returns>
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;
}
}
}
}

24
src/ImageProcessor/Imaging/TextLayer.cs

@ -160,21 +160,25 @@ namespace ImageProcessor.Imaging
}
/// <summary>
/// Returns a hash code value that represents this object.
/// Returns the hash code for this instance.
/// </summary>
/// <returns>
/// A hash code that represents this object.
/// A 32-bit signed integer that is the hash code for this instance.
/// </returns>
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;
}
}
}
}

22
src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/Imaging/ContentAwareResizeLayer.cs

@ -182,20 +182,24 @@ namespace ImageProcessor.Plugins.Cair.Imaging
}
/// <summary>
/// Returns a hash code value that represents this object.
/// Returns the hash code for this instance.
/// </summary>
/// <returns>
/// A hash code that represents this object.
/// A 32-bit signed integer that is the hash code for this instance.
/// </returns>
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;
}
}
}
}

Loading…
Cancel
Save