diff --git a/src/ImageProcessor.Plugins.Cair/ImageProcessor.Plugins.Cair.csproj b/src/ImageProcessor.Plugins.Cair/ImageProcessor.Plugins.Cair.csproj
index 7ff8c49dd..377af60a4 100644
--- a/src/ImageProcessor.Plugins.Cair/ImageProcessor.Plugins.Cair.csproj
+++ b/src/ImageProcessor.Plugins.Cair/ImageProcessor.Plugins.Cair.csproj
@@ -38,6 +38,9 @@
+
+ ..\..\packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll
+
@@ -62,6 +65,7 @@
+
diff --git a/src/ImageProcessor.Plugins.Cair/Imaging/ContentAwareResizeLayer.cs b/src/ImageProcessor.Plugins.Cair/Imaging/ContentAwareResizeLayer.cs
index 4fd5f4f1b..1b8e3f613 100644
--- a/src/ImageProcessor.Plugins.Cair/Imaging/ContentAwareResizeLayer.cs
+++ b/src/ImageProcessor.Plugins.Cair/Imaging/ContentAwareResizeLayer.cs
@@ -10,18 +10,14 @@
namespace ImageProcessor.Plugins.Cair.Imaging
{
+ using System;
using System.Drawing;
///
/// Encapsulates the properties required to resize an image using content aware resizing.
///
- public class ContentAwareResizeLayer
+ public class ContentAwareResizeLayer : IEquatable
{
- ///
- /// The expected output type.
- ///
- private OutputType outputType = OutputType.Cair;
-
///
/// Initializes a new instance of the class.
///
@@ -33,6 +29,11 @@ public ContentAwareResizeLayer(Size size)
this.Size = size;
}
+ ///
+ /// Gets or sets the size.
+ ///
+ public Size Size { get; set; }
+
///
/// Gets or sets the content aware resize convolution type (Default ContentAwareResizeConvolutionType.Prewitt).
///
@@ -46,23 +47,7 @@ public ContentAwareResizeLayer(Size size)
///
/// Gets or sets the expected output type.
///
- public OutputType OutputType
- {
- get
- {
- return this.outputType;
- }
-
- set
- {
- this.outputType = value;
- }
- }
-
- ///
- /// Gets or sets the size.
- ///
- public Size Size { get; set; }
+ public OutputType OutputType { get; set; } = OutputType.Cair;
///
/// Gets or sets the the file path to a bitmap file that provides weight indicators specified using
@@ -88,54 +73,36 @@ public OutputType OutputType
public int Timeout { get; set; } = 60000;
///
- /// Returns a value that indicates whether the specified object is an
- /// object that is equivalent to
- /// this object.
+ /// Determines whether the specified , is equal to this instance.
///
- ///
- /// The object to test.
- ///
+ /// The to compare with this instance.
///
- /// True if the given object is an object that is equivalent to
- /// this object; otherwise, false.
+ /// true if the specified is equal to this instance; otherwise, false.
///
- public override bool Equals(object obj)
- {
- ContentAwareResizeLayer resizeLayer = obj as ContentAwareResizeLayer;
-
- if (resizeLayer == null)
- {
- return false;
- }
+ public override bool Equals(object obj) => obj is ContentAwareResizeLayer contentAwareResizeLayer && this.Equals(contentAwareResizeLayer);
- return this.Size == resizeLayer.Size
- && this.ConvolutionType == resizeLayer.ConvolutionType
- && this.EnergyFunction == resizeLayer.EnergyFunction
- && this.OutputType == resizeLayer.OutputType
- && this.Parallelize == resizeLayer.Parallelize
- && this.Timeout == resizeLayer.Timeout
- && this.WeightPath == resizeLayer.WeightPath;
- }
+ ///
+ /// Indicates whether the current object is equal to another object of the same type.
+ ///
+ /// An object to compare with this object.
+ ///
+ /// true if the current object is equal to the parameter; otherwise, false.
+ ///
+ public bool Equals(ContentAwareResizeLayer other) => other != null
+ && this.Size == other.Size
+ && this.ConvolutionType == other.ConvolutionType
+ && this.EnergyFunction == other.EnergyFunction
+ && this.OutputType == other.OutputType
+ && this.WeightPath == other.WeightPath
+ && this.Parallelize == other.Parallelize
+ && this.Timeout == other.Timeout;
///
- /// Returns the hash code for this instance.
+ /// Returns a hash code for this instance.
///
///
- /// A 32-bit signed integer that is 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.
///
- public override int 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;
- }
- }
+ public override int GetHashCode() => (this.Size, this.ConvolutionType, this.EnergyFunction, this.OutputType, this.WeightPath, this.Parallelize, this.Timeout).GetHashCode();
}
}
diff --git a/src/ImageProcessor.Plugins.Cair/packages.config b/src/ImageProcessor.Plugins.Cair/packages.config
new file mode 100644
index 000000000..8653b8e4c
--- /dev/null
+++ b/src/ImageProcessor.Plugins.Cair/packages.config
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/src/ImageProcessor/ImageProcessor.csproj b/src/ImageProcessor/ImageProcessor.csproj
index 1ad521cdb..de8e37d34 100644
--- a/src/ImageProcessor/ImageProcessor.csproj
+++ b/src/ImageProcessor/ImageProcessor.csproj
@@ -42,6 +42,9 @@
+
+ ..\..\packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll
+
@@ -202,5 +205,8 @@
+
+
+
\ No newline at end of file
diff --git a/src/ImageProcessor/Imaging/Colors/CmykColor.cs b/src/ImageProcessor/Imaging/Colors/CmykColor.cs
index 1dbf47b4b..5a1f3d8d1 100644
--- a/src/ImageProcessor/Imaging/Colors/CmykColor.cs
+++ b/src/ImageProcessor/Imaging/Colors/CmykColor.cs
@@ -247,54 +247,49 @@ public override string ToString()
}
///
- /// Indicates whether this instance and a specified object are equal.
+ /// Determines whether the specified , is equal to this instance.
///
+ /// The to compare with this instance.
///
- /// true if and this instance are the same type and represent the same value; otherwise, false.
+ /// true if the specified is equal to this instance; otherwise, false.
///
- /// Another object to compare to.
public override bool Equals(object obj) => obj is CmykColor cmykColor && this.Equals(cmykColor);
///
/// Indicates whether the current object is equal to another object of the same type.
///
/// An object to compare with this object.
- /// true if the current object is equal to the parameter; otherwise, false.
- public bool Equals(CmykColor other)
- {
- Color thisColor = this;
- Color otherColor = other;
- return thisColor.Equals(otherColor);
- }
+ ///
+ /// true if the current object is equal to the parameter; otherwise, false.
+ ///
+ public bool Equals(CmykColor other) =>
+ this.C == other.C
+ && this.M == other.M
+ && this.Y == other.Y
+ && this.K == other.K;
///
- /// Returns the hash code for this instance.
+ /// Returns a hash code for this instance.
///
///
- /// A 32-bit signed integer that is 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.
///
- public override int GetHashCode()
- {
- Color thisColor = this;
- return thisColor.GetHashCode();
- }
+ public override int GetHashCode() => (this.C, this.M, this.Y, this.K).GetHashCode();
///
/// Checks the range of the given value to ensure that it remains within the acceptable boundaries.
///
- ///
- /// The value to check.
- ///
+ /// The value to check.
///
- /// The sanitized .
+ /// The sanitized .
///
private static float Clamp(float value) => ImageMaths.Clamp(value, 0, 100);
///
- /// Returns a value indicating whether the current instance is empty.
+ /// Determines whether this instance is empty.
///
///
- /// The true if this instance is empty; otherwise, false.
+ /// true if this instance is empty; otherwise, false.
///
private bool IsEmpty()
{
diff --git a/src/ImageProcessor/Imaging/Colors/Color32.cs b/src/ImageProcessor/Imaging/Colors/Color32.cs
index 4e01e031e..0e989c481 100644
--- a/src/ImageProcessor/Imaging/Colors/Color32.cs
+++ b/src/ImageProcessor/Imaging/Colors/Color32.cs
@@ -86,47 +86,29 @@ public Color32(int argb)
public Color Color => Color.FromArgb(this.A, this.R, this.G, this.B);
///
- /// Indicates whether this instance and a specified object are equal.
+ /// Determines whether the specified , is equal to this instance.
///
+ /// The to compare with this instance.
///
- /// true if and this instance are the same type and represent the same value; otherwise, false.
+ /// true if the specified is equal to this instance; otherwise, false.
///
- /// Another object to compare to.
public override bool Equals(object obj) => obj is Color32 color32 && this.Equals(color32);
///
/// Indicates whether the current object is equal to another object of the same type.
///
/// An object to compare with this object.
- /// true if the current object is equal to the parameter; otherwise, false.
- public bool Equals(Color32 other) => this.Argb.Equals(other.Argb);
-
- ///
- /// Returns the hash code for this instance.
- ///
///
- /// A 32-bit signed integer that is the hash code for this instance.
+ /// true if the current object is equal to the parameter; otherwise, false.
///
- public override int GetHashCode() => this.GetHashCode(this);
+ public bool Equals(Color32 other) => this.Argb == other.Argb;
///
- /// Returns the hash code for the given instance.
+ /// Returns a 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.
+ /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
///
- private int GetHashCode(Color32 obj)
- {
- unchecked
- {
- int hashCode = obj.B.GetHashCode();
- hashCode = (hashCode * 397) ^ obj.G.GetHashCode();
- hashCode = (hashCode * 397) ^ obj.R.GetHashCode();
- return (hashCode * 397) ^ obj.A.GetHashCode();
- }
- }
+ public override int GetHashCode() => this.Argb.GetHashCode();
}
}
\ No newline at end of file
diff --git a/src/ImageProcessor/Imaging/Colors/HSLAColor.cs b/src/ImageProcessor/Imaging/Colors/HSLAColor.cs
index 23e9483ff..d47f8eb79 100644
--- a/src/ImageProcessor/Imaging/Colors/HSLAColor.cs
+++ b/src/ImageProcessor/Imaging/Colors/HSLAColor.cs
@@ -242,37 +242,34 @@ public override string ToString()
}
///
- /// Indicates whether this instance and a specified object are equal.
+ /// Determines whether the specified , is equal to this instance.
///
+ /// The to compare with this instance.
///
- /// true if and this instance are the same type and represent the same value; otherwise, false.
+ /// true if the specified is equal to this instance; otherwise, false.
///
- /// Another object to compare to.
public override bool Equals(object obj) => obj is HslaColor hslaColor && this.Equals(hslaColor);
///
/// Indicates whether the current object is equal to another object of the same type.
///
/// An object to compare with this object.
- /// true if the current object is equal to the parameter; otherwise, false.
- public bool Equals(HslaColor other)
- {
- Color thisColor = this;
- Color otherColor = other;
- return thisColor.Equals(otherColor);
- }
+ ///
+ /// true if the current object is equal to the parameter; otherwise, false.
+ ///
+ public bool Equals(HslaColor other) =>
+ this.H == other.H
+ && this.S == other.S
+ && this.L == other.L
+ && this.A == other.A;
///
- /// Returns the hash code for this instance.
+ /// Returns a hash code for this instance.
///
///
- /// A 32-bit signed integer that is 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.
///
- public override int GetHashCode()
- {
- Color thisColor = this;
- return thisColor.GetHashCode();
- }
+ public override int GetHashCode() => (this.H, this.S, this.L, this.A).GetHashCode();
///
/// Gets the color component from the given hue values.
diff --git a/src/ImageProcessor/Imaging/Colors/RGBAColor.cs b/src/ImageProcessor/Imaging/Colors/RGBAColor.cs
index 3a4bd6e3a..defa82056 100644
--- a/src/ImageProcessor/Imaging/Colors/RGBAColor.cs
+++ b/src/ImageProcessor/Imaging/Colors/RGBAColor.cs
@@ -190,36 +190,33 @@ public override string ToString()
}
///
- /// Indicates whether this instance and a specified object are equal.
+ /// Determines whether the specified , is equal to this instance.
///
+ /// The to compare with this instance.
///
- /// true if and this instance are the same type and represent the same value; otherwise, false.
+ /// true if the specified is equal to this instance; otherwise, false.
///
- /// Another object to compare to.
public override bool Equals(object obj) => obj is RgbaColor rgbaColor && this.Equals(rgbaColor);
///
/// Indicates whether the current object is equal to another object of the same type.
///
/// An object to compare with this object.
- /// true if the current object is equal to the parameter; otherwise, false.
- public bool Equals(RgbaColor other)
- {
- Color thisColor = this;
- Color otherColor = other;
- return thisColor.Equals(otherColor);
- }
+ ///
+ /// true if the current object is equal to the parameter; otherwise, false.
+ ///
+ public bool Equals(RgbaColor other) =>
+ this.R == other.R
+ && this.G == other.G
+ && this.B == other.B
+ && this.A == other.A;
///
- /// Returns the hash code for this instance.
+ /// Returns a hash code for this instance.
///
///
- /// A 32-bit signed integer that is 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.
///
- public override int GetHashCode()
- {
- Color thisColor = this;
- return thisColor.GetHashCode();
- }
+ public override int GetHashCode() => (this.R, this.G, this.B, this.A).GetHashCode();
}
}
\ No newline at end of file
diff --git a/src/ImageProcessor/Imaging/Colors/YCbCrColor.cs b/src/ImageProcessor/Imaging/Colors/YCbCrColor.cs
index 7c969c001..957e6cede 100644
--- a/src/ImageProcessor/Imaging/Colors/YCbCrColor.cs
+++ b/src/ImageProcessor/Imaging/Colors/YCbCrColor.cs
@@ -168,37 +168,33 @@ public override string ToString()
}
///
- /// Indicates whether this instance and a specified object are equal.
+ /// Determines whether the specified , is equal to this instance.
///
+ /// The to compare with this instance.
///
- /// true if and this instance are the same type and represent the same value; otherwise, false.
+ /// true if the specified is equal to this instance; otherwise, false.
///
- /// Another object to compare to.
public override bool Equals(object obj) => obj is YCbCrColor yCbCrColor && this.Equals(yCbCrColor);
///
/// Indicates whether the current object is equal to another object of the same type.
///
/// An object to compare with this object.
- /// true if the current object is equal to the parameter; otherwise, false.
- public bool Equals(YCbCrColor other)
- {
- Color thisColor = this;
- Color otherColor = other;
- return thisColor.Equals(otherColor);
- }
+ ///
+ /// true if the current object is equal to the parameter; otherwise, false.
+ ///
+ public bool Equals(YCbCrColor other) =>
+ this.Y == other.Y
+ && this.Cb == other.Cb
+ && this.Cr == other.Cr;
///
- /// Returns the hash code for this instance.
+ /// Returns a hash code for this instance.
///
///
- /// A 32-bit signed integer that is 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.
///
- public override int GetHashCode()
- {
- Color thisColor = this;
- return thisColor.GetHashCode();
- }
+ public override int GetHashCode() => (this.Y, this.Cb, this.Cr).GetHashCode();
///
/// Returns a value indicating whether the current instance is empty.
diff --git a/src/ImageProcessor/Imaging/CropLayer.cs b/src/ImageProcessor/Imaging/CropLayer.cs
index f1fdee181..7582201e8 100644
--- a/src/ImageProcessor/Imaging/CropLayer.cs
+++ b/src/ImageProcessor/Imaging/CropLayer.cs
@@ -15,7 +15,7 @@ namespace ImageProcessor.Imaging
///
/// Encapsulates the properties required to crop an image.
///
- public class CropLayer
+ public class CropLayer : IEquatable
{
///
/// Initializes a new instance of the class.
@@ -31,9 +31,24 @@ public class CropLayer
///
public CropLayer(float left, float top, float right, float bottom, CropMode cropMode = CropMode.Percentage)
{
- if (left < 0 || top < 0 || right < 0 || bottom < 0)
+ if (left < 0)
{
- throw new ArgumentOutOfRangeException();
+ throw new ArgumentOutOfRangeException(nameof(left));
+ }
+
+ if (top < 0)
+ {
+ throw new ArgumentOutOfRangeException(nameof(top));
+ }
+
+ if (right < 0)
+ {
+ throw new ArgumentOutOfRangeException(nameof(right));
+ }
+
+ if (bottom < 0)
+ {
+ throw new ArgumentOutOfRangeException(nameof(bottom));
}
this.Left = left;
@@ -69,47 +84,34 @@ public CropLayer(float left, float top, float right, float bottom, CropMode crop
public CropMode CropMode { get; set; }
///
- /// Determines whether the specified , is
- /// equal to this instance.
+ /// Determines whether the specified , is equal to this instance.
///
- ///
- /// The to compare with this instance.
- ///
+ /// The to compare with this instance.
///
- /// true if the specified is equal to
- /// this instance; otherwise, false.
+ /// true if the specified is equal to this instance; otherwise, false.
///
- public override bool Equals(object obj)
- {
- if (!(obj is CropLayer cropLayer))
- {
- return false;
- }
+ public override bool Equals(object obj) => obj is CropLayer cropLayer && this.Equals(cropLayer);
- // Define the tolerance for variation in their values
- return Math.Abs(this.Top - cropLayer.Top) <= Math.Abs(this.Top * .0001)
- && Math.Abs(this.Right - cropLayer.Right) <= Math.Abs(this.Right * .0001)
- && Math.Abs(this.Bottom - cropLayer.Bottom) <= Math.Abs(this.Bottom * .0001)
- && Math.Abs(this.Left - cropLayer.Left) <= Math.Abs(this.Left * .0001)
- && this.CropMode.Equals(cropLayer.CropMode);
- }
+ ///
+ /// Indicates whether the current object is equal to another object of the same type.
+ ///
+ /// An object to compare with this object.
+ ///
+ /// true if the current object is equal to the parameter; otherwise, false.
+ ///
+ public bool Equals(CropLayer other) => other != null
+ && this.Left == other.Left
+ && this.Top == other.Top
+ && this.Right == other.Right
+ && this.Bottom == other.Bottom
+ && this.CropMode == other.CropMode;
///
- /// Serves as a hash function for a particular type.
+ /// Returns a hash code for this instance.
///
///
- /// A hash code for the current .
+ /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
///
- public override int 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();
- return (hashCode * 397) ^ (int)this.CropMode;
- }
- }
+ public override int GetHashCode() => (this.Left, this.Top, this.Right, this.Bottom, this.CropMode).GetHashCode();
}
}
diff --git a/src/ImageProcessor/Imaging/FastBitmap.cs b/src/ImageProcessor/Imaging/FastBitmap.cs
index 02b0bd2b4..d9c2080fc 100644
--- a/src/ImageProcessor/Imaging/FastBitmap.cs
+++ b/src/ImageProcessor/Imaging/FastBitmap.cs
@@ -20,7 +20,7 @@ namespace ImageProcessor.Imaging
///
/// Allows fast access to 's pixel data.
///
- public unsafe class FastBitmap : IDisposable
+ public unsafe class FastBitmap : IDisposable, IEquatable
{
///
/// The integral representation of the 8bppIndexed pixel format.
@@ -400,27 +400,29 @@ public void Dispose()
}
///
- /// Determines whether the specified is equal to the current .
+ /// Determines whether the specified , is equal to this instance.
///
+ /// The to compare with this instance.
///
- /// true if the specified object is equal to the current object; otherwise, false.
+ /// true if the specified is equal to this instance; otherwise, false.
///
- /// The object to compare with the current object.
- public override bool Equals(object obj)
- {
- if (!(obj is FastBitmap fastBitmap))
- {
- return false;
- }
+ public override bool Equals(object obj) => obj is FastBitmap fastBitmap && this.Equals(fastBitmap);
- return this.bitmap == fastBitmap.bitmap;
- }
+ ///
+ /// Indicates whether the current object is equal to another object of the same type.
+ ///
+ /// An object to compare with this object.
+ ///
+ /// true if the current object is equal to the parameter; otherwise, false.
+ ///
+ public bool Equals(FastBitmap other) => other != null
+ && this.bitmap == other.bitmap;
///
- /// Serves as a hash function for a particular type.
+ /// Returns a hash code for this instance.
///
///
- /// A hash code for the current .
+ /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
///
public override int GetHashCode() => this.bitmap.GetHashCode();
diff --git a/src/ImageProcessor/Imaging/Filters/Photo/MatrixFilterBase.cs b/src/ImageProcessor/Imaging/Filters/Photo/MatrixFilterBase.cs
index 9bb760f83..7c37cb4f4 100644
--- a/src/ImageProcessor/Imaging/Filters/Photo/MatrixFilterBase.cs
+++ b/src/ImageProcessor/Imaging/Filters/Photo/MatrixFilterBase.cs
@@ -10,13 +10,14 @@
namespace ImageProcessor.Imaging.Filters.Photo
{
+ using System;
using System.Drawing;
using System.Drawing.Imaging;
///
/// The matrix filter base contains equality methods.
///
- public abstract class MatrixFilterBase : IMatrixFilter
+ public abstract class MatrixFilterBase : IMatrixFilter, IEquatable
{
///
/// Gets the for this filter instance.
@@ -29,41 +30,88 @@ public abstract class MatrixFilterBase : IMatrixFilter
/// The current image to process
/// The new image to return
///
- /// The processed .
+ /// The processed .
///
public abstract Bitmap TransformImage(Image source, Image destination);
///
- /// Determines whether the specified , is equal to this instance.
+ /// Determines whether the specified , is equal to this instance.
///
- /// The to compare with this instance.
+ /// The to compare with this instance.
///
- /// true if the specified is equal to this instance; otherwise, false.
+ /// true if the specified is equal to this instance; otherwise, false.
///
- public override bool Equals(object obj)
- {
- if (!(obj is IMatrixFilter filter))
- {
- return false;
- }
+ public override bool Equals(object obj) => obj is IMatrixFilter matrixFilter && this.Equals(matrixFilter);
- return this.GetType().Name == filter.GetType().Name
- && this.Matrix.Equals(filter.Matrix);
- }
+ ///
+ /// Indicates whether the current object is equal to another object of the same type.
+ ///
+ /// An object to compare with this object.
+ ///
+ /// true if the current object is equal to the parameter; otherwise, false.
+ ///
+ public bool Equals(IMatrixFilter other) => other != null
+ && this.GetType() == other.GetType()
+ && (this.Matrix == null || other.Matrix == null ? this.Matrix == other.Matrix : (
+ this.Matrix.Matrix00 == other.Matrix.Matrix00
+ && this.Matrix.Matrix01 == other.Matrix.Matrix01
+ && this.Matrix.Matrix02 == other.Matrix.Matrix02
+ && this.Matrix.Matrix03 == other.Matrix.Matrix03
+ && this.Matrix.Matrix04 == other.Matrix.Matrix04
+ && this.Matrix.Matrix10 == other.Matrix.Matrix10
+ && this.Matrix.Matrix11 == other.Matrix.Matrix11
+ && this.Matrix.Matrix12 == other.Matrix.Matrix12
+ && this.Matrix.Matrix13 == other.Matrix.Matrix13
+ && this.Matrix.Matrix14 == other.Matrix.Matrix14
+ && this.Matrix.Matrix20 == other.Matrix.Matrix20
+ && this.Matrix.Matrix21 == other.Matrix.Matrix21
+ && this.Matrix.Matrix22 == other.Matrix.Matrix22
+ && this.Matrix.Matrix23 == other.Matrix.Matrix23
+ && this.Matrix.Matrix24 == other.Matrix.Matrix24
+ && this.Matrix.Matrix30 == other.Matrix.Matrix30
+ && this.Matrix.Matrix31 == other.Matrix.Matrix31
+ && this.Matrix.Matrix32 == other.Matrix.Matrix32
+ && this.Matrix.Matrix33 == other.Matrix.Matrix33
+ && this.Matrix.Matrix34 == other.Matrix.Matrix34
+ && this.Matrix.Matrix40 == other.Matrix.Matrix40
+ && this.Matrix.Matrix41 == other.Matrix.Matrix41
+ && this.Matrix.Matrix42 == other.Matrix.Matrix42
+ && this.Matrix.Matrix43 == other.Matrix.Matrix43
+ && this.Matrix.Matrix44 == other.Matrix.Matrix44
+ ));
///
- /// Returns the hash code for this instance.
+ /// Returns a hash code for this instance.
///
///
- /// A 32-bit signed integer that is 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.
///
- public override int GetHashCode()
- {
- unchecked
- {
- int hashCode = this.GetType().Name.GetHashCode();
- return (hashCode * 397) ^ this.Matrix.GetHashCode();
- }
- }
+ public override int GetHashCode() => (
+ this.GetType(),
+ this.Matrix?.Matrix00,
+ this.Matrix?.Matrix01,
+ this.Matrix?.Matrix02,
+ this.Matrix?.Matrix03,
+ this.Matrix?.Matrix04,
+ this.Matrix?.Matrix10,
+ this.Matrix?.Matrix11,
+ this.Matrix?.Matrix12,
+ this.Matrix?.Matrix13,
+ this.Matrix?.Matrix14,
+ this.Matrix?.Matrix20,
+ this.Matrix?.Matrix21,
+ this.Matrix?.Matrix22,
+ this.Matrix?.Matrix23,
+ this.Matrix?.Matrix24,
+ this.Matrix?.Matrix30,
+ this.Matrix?.Matrix31,
+ this.Matrix?.Matrix32,
+ this.Matrix?.Matrix33,
+ this.Matrix?.Matrix34,
+ this.Matrix?.Matrix40,
+ this.Matrix?.Matrix41,
+ this.Matrix?.Matrix42,
+ this.Matrix?.Matrix43,
+ this.Matrix?.Matrix44).GetHashCode();
}
}
\ No newline at end of file
diff --git a/src/ImageProcessor/Imaging/Formats/FormatBase.cs b/src/ImageProcessor/Imaging/Formats/FormatBase.cs
index d5e582243..4651b865c 100644
--- a/src/ImageProcessor/Imaging/Formats/FormatBase.cs
+++ b/src/ImageProcessor/Imaging/Formats/FormatBase.cs
@@ -18,7 +18,7 @@ namespace ImageProcessor.Imaging.Formats
///
/// The supported format base. Implement this class when building a supported format.
///
- public abstract class FormatBase : ISupportedImageFormat
+ public abstract class FormatBase : ISupportedImageFormat, IEquatable
{
///
/// Initializes a new instance of the class.
@@ -123,36 +123,31 @@ public virtual Image Save(string path, Image image, long bitDepth)
}
///
- /// Determines whether the specified , is equal to this instance.
+ /// Determines whether the specified , is equal to this instance.
///
- /// The to compare with this instance.
+ /// The to compare with this instance.
///
- /// true if the specified is equal to this instance; otherwise, false.
+ /// true if the specified is equal to this instance; otherwise, false.
///
- public override bool Equals(object obj)
- {
- if (!(obj is ISupportedImageFormat format))
- {
- return false;
- }
+ public override bool Equals(object obj) => obj is ISupportedImageFormat format && this.Equals(format);
- return this.MimeType.Equals(format.MimeType) && this.IsIndexed.Equals(format.IsIndexed);
- }
+ ///
+ /// Indicates whether the current object is equal to another object of the same type.
+ ///
+ /// An object to compare with this object.
+ ///
+ /// true if the current object is equal to the parameter; otherwise, false.
+ ///
+ public bool Equals(ISupportedImageFormat other) => other != null
+ && this.MimeType == other.MimeType
+ && this.IsIndexed == other.IsIndexed;
///
- /// Returns the hash code for this instance.
+ /// Returns a hash code for this instance.
///
///
- /// A 32-bit signed integer that is 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.
///
- public override int GetHashCode()
- {
- unchecked
- {
- int hashCode = this.MimeType.GetHashCode();
- hashCode = (hashCode * 397) ^ this.IsIndexed.GetHashCode();
- return (hashCode * 397) ^ this.Quality;
- }
- }
+ public override int GetHashCode() => (this.MimeType, this.IsIndexed).GetHashCode();
}
}
diff --git a/src/ImageProcessor/Imaging/GaussianLayer.cs b/src/ImageProcessor/Imaging/GaussianLayer.cs
index 15d45b15a..55668d397 100644
--- a/src/ImageProcessor/Imaging/GaussianLayer.cs
+++ b/src/ImageProcessor/Imaging/GaussianLayer.cs
@@ -15,7 +15,7 @@ namespace ImageProcessor.Imaging
///
/// A Gaussian layer for applying sharpening and blurring methods to an image.
///
- public class GaussianLayer
+ public class GaussianLayer : IEquatable
{
///
/// The size.
@@ -131,43 +131,32 @@ public int Threshold
}
///
- /// Returns a value that indicates whether the specified object is an
- /// object that is equivalent to
- /// this object.
+ /// Determines whether the specified , is equal to this instance.
///
- ///
- /// The object to test.
- ///
+ /// The to compare with this instance.
///
- /// True if the given object is an object that is equivalent to
- /// this object; otherwise, false.
+ /// true if the specified is equal to this instance; otherwise, false.
///
- public override bool Equals(object obj)
- {
- if (!(obj is GaussianLayer gaussianLayer))
- {
- return false;
- }
+ public override bool Equals(object obj) => obj is GaussianLayer gaussianLayer && this.Equals(gaussianLayer);
- return this.Size == gaussianLayer.Size
- && Math.Abs(this.Sigma - gaussianLayer.Sigma) < 0.0001
- && this.Threshold == gaussianLayer.Threshold;
- }
+ ///
+ /// Indicates whether the current object is equal to another object of the same type.
+ ///
+ /// An object to compare with this object.
+ ///
+ /// true if the current object is equal to the parameter; otherwise, false.
+ ///
+ public bool Equals(GaussianLayer other) => other != null
+ && this.Size == other.Size
+ && this.Sigma == other.Sigma
+ && this.Threshold == other.Threshold;
///
- /// Serves as a hash function for a particular type.
+ /// Returns a hash code for this instance.
///
///
- /// A hash code for the current .
+ /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
///
- public override int GetHashCode()
- {
- unchecked
- {
- int hashCode = this.Size;
- hashCode = (hashCode * 397) ^ this.Size.GetHashCode();
- return (hashCode * 397) ^ this.Threshold;
- }
- }
+ public override int GetHashCode() => (this.Size, this.Sigma, this.Threshold).GetHashCode();
}
}
diff --git a/src/ImageProcessor/Imaging/ImageLayer.cs b/src/ImageProcessor/Imaging/ImageLayer.cs
index 99bd9e57a..578dc04f7 100644
--- a/src/ImageProcessor/Imaging/ImageLayer.cs
+++ b/src/ImageProcessor/Imaging/ImageLayer.cs
@@ -15,7 +15,7 @@ namespace ImageProcessor.Imaging
///
/// Encapsulates the properties required to add an image layer to an image.
///
- public class ImageLayer : IDisposable
+ public class ImageLayer : IDisposable, IEquatable
{
///
/// A value indicating whether this instance of the given entity has been disposed.
@@ -51,46 +51,34 @@ public class ImageLayer : IDisposable
public Point? Position { get; set; }
///
- /// Returns a value that indicates whether the specified object is an
- /// object that is equivalent to
- /// this object.
+ /// Determines whether the specified , is equal to this instance.
///
- ///
- /// The object to test.
- ///
+ /// The to compare with this instance.
///
- /// True if the given object is an object that is equivalent to
- /// this object; otherwise, false.
+ /// true if the specified is equal to this instance; otherwise, false.
///
- public override bool Equals(object obj)
- {
- if (!(obj is ImageLayer imageLayer))
- {
- return false;
- }
+ public override bool Equals(object obj) => obj is ImageLayer imageLayer && this.Equals(imageLayer);
- return this.Image == imageLayer.Image
- && this.Size == imageLayer.Size
- && this.Opacity == imageLayer.Opacity
- && this.Position == imageLayer.Position;
- }
+ ///
+ /// Indicates whether the current object is equal to another object of the same type.
+ ///
+ /// An object to compare with this object.
+ ///
+ /// true if the current object is equal to the parameter; otherwise, false.
+ ///
+ public bool Equals(ImageLayer other) => other != null
+ && this.Image == other.Image
+ && this.Size == other.Size
+ && this.Opacity == other.Opacity
+ && this.Position == other.Position;
///
- /// Returns the hash code for this instance.
+ /// Returns a hash code for this instance.
///
///
- /// A 32-bit signed integer that is 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.
///
- public override int GetHashCode()
- {
- unchecked
- {
- int hashCode = this.Image.GetHashCode();
- hashCode = (hashCode * 397) ^ this.Size.GetHashCode();
- hashCode = (hashCode * 397) ^ this.Opacity;
- return (hashCode * 397) ^ this.Position.GetHashCode();
- }
- }
+ public override int GetHashCode() => (this.Image, this.Size, this.Opacity, this.Position).GetHashCode();
///
/// Disposes the object and frees resources for the Garbage Collector.
diff --git a/src/ImageProcessor/Imaging/MetaData/Rational.cs b/src/ImageProcessor/Imaging/MetaData/Rational.cs
index 32bd97adf..499842290 100644
--- a/src/ImageProcessor/Imaging/MetaData/Rational.cs
+++ b/src/ImageProcessor/Imaging/MetaData/Rational.cs
@@ -1000,27 +1000,20 @@ public int CompareTo(object obj)
public override string ToString() => Convert.ToString(this, CultureInfo.InvariantCulture);
///
- /// Indicates whether this instance and a specified object are equal.
+ /// Determines whether the specified , is equal to this instance.
///
+ /// The to compare with this instance.
///
- /// true if and this instance are the same type and represent the same value;
- /// otherwise, false.
+ /// true if the specified is equal to this instance; otherwise, false.
///
- /// The object to compare with the current instance.
public override bool Equals(object obj) => this.CompareTo(obj) == 0;
///
- /// Returns the hash code for this instance.
+ /// Returns a hash code for this instance.
///
///
- /// A 32-bit signed integer that is 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.
///
- public override int GetHashCode()
- {
- // Adapted from Anonymous Type: { uint Numerator, uint Denominator }
- int num = 0x1fb8d67d;
- num = (-1521134295 * num) + EqualityComparer.Default.GetHashCode(this.numerator);
- return (-1521134295 * num) + EqualityComparer.Default.GetHashCode(this.denominator);
- }
+ public override int GetHashCode() => (this.Numerator, this.Denominator).GetHashCode();
}
}
diff --git a/src/ImageProcessor/Imaging/ResizeLayer.cs b/src/ImageProcessor/Imaging/ResizeLayer.cs
index 1c3b81271..685144ce7 100644
--- a/src/ImageProcessor/Imaging/ResizeLayer.cs
+++ b/src/ImageProcessor/Imaging/ResizeLayer.cs
@@ -10,6 +10,7 @@
namespace ImageProcessor.Imaging
{
+ using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
@@ -17,7 +18,8 @@ namespace ImageProcessor.Imaging
///
/// Encapsulates the properties required to resize an image.
///
- public class ResizeLayer
+ ///
+ public class ResizeLayer : IEquatable
{
///
/// Initializes a new instance of the class.
@@ -110,59 +112,37 @@ public ResizeLayer(
public Point? AnchorPoint { get; set; }
///
- /// Returns a value that indicates whether the specified object is an
- /// object that is equivalent to
- /// this object.
+ /// Determines whether the specified , is equal to this instance.
///
- ///
- /// The object to test.
- ///
+ /// The to compare with this instance.
///
- /// True if the given object is an object that is equivalent to
- /// this object; otherwise, false.
+ /// true if the specified is equal to this instance; otherwise, false.
///
- public override bool Equals(object obj)
- {
- if (!(obj is ResizeLayer resizeLayer))
- {
- return false;
- }
+ public override bool Equals(object obj) => obj is ResizeLayer resizeLayer && this.Equals(resizeLayer);
- return this.Size == resizeLayer.Size
- && this.ResizeMode == resizeLayer.ResizeMode
- && this.AnchorPosition == resizeLayer.AnchorPosition
- && this.Upscale == resizeLayer.Upscale
- && ((this.CenterCoordinates != null
- && resizeLayer.CenterCoordinates != null
- && this.CenterCoordinates.SequenceEqual(resizeLayer.CenterCoordinates))
- || (this.CenterCoordinates == resizeLayer.CenterCoordinates))
- && this.MaxSize == resizeLayer.MaxSize
- && ((this.RestrictedSizes != null
- && resizeLayer.RestrictedSizes != null
- && this.RestrictedSizes.SequenceEqual(resizeLayer.RestrictedSizes))
- || (this.RestrictedSizes == resizeLayer.RestrictedSizes))
- && this.AnchorPoint == resizeLayer.AnchorPoint;
- }
+ ///
+ /// Indicates whether the current object is equal to another object of the same type.
+ ///
+ /// An object to compare with this object.
+ ///
+ /// true if the current object is equal to the parameter; otherwise, false.
+ ///
+ public bool Equals(ResizeLayer other) => other != null
+ && this.Size == other.Size
+ && this.MaxSize == other.MaxSize
+ && (this.RestrictedSizes == null || other.RestrictedSizes == null ? this.RestrictedSizes == other.RestrictedSizes : this.RestrictedSizes.SequenceEqual(other.RestrictedSizes))
+ && this.ResizeMode == other.ResizeMode
+ && this.AnchorPosition == other.AnchorPosition
+ && this.Upscale == other.Upscale
+ && (this.CenterCoordinates == null || other.CenterCoordinates == null ? this.CenterCoordinates == other.CenterCoordinates : this.CenterCoordinates.SequenceEqual(other.CenterCoordinates))
+ && this.AnchorPoint == other.AnchorPoint;
///
- /// Returns the hash code for this instance.
+ /// Returns a hash code for this instance.
///
///
- /// A 32-bit signed integer that is 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.
///
- public override int GetHashCode()
- {
- unchecked
- {
- int hashCode = this.Size.GetHashCode();
- hashCode = (hashCode * 397) ^ this.MaxSize.GetHashCode();
- hashCode = (hashCode * 397) ^ (this.RestrictedSizes?.GetHashCode() ?? 0);
- hashCode = (hashCode * 397) ^ (int)this.ResizeMode;
- hashCode = (hashCode * 397) ^ (int)this.AnchorPosition;
- hashCode = (hashCode * 397) ^ this.Upscale.GetHashCode();
- hashCode = (hashCode * 397) ^ (this.CenterCoordinates?.GetHashCode() ?? 0);
- return (hashCode * 397) ^ this.AnchorPoint.GetHashCode();
- }
- }
+ public override int GetHashCode() => (this.Size, this.MaxSize, this.ResizeMode, this.AnchorPosition, this.Upscale, this.AnchorPoint).GetHashCode();
}
}
\ No newline at end of file
diff --git a/src/ImageProcessor/Imaging/RoundedCornerLayer.cs b/src/ImageProcessor/Imaging/RoundedCornerLayer.cs
index 3e4e3017c..69442befc 100644
--- a/src/ImageProcessor/Imaging/RoundedCornerLayer.cs
+++ b/src/ImageProcessor/Imaging/RoundedCornerLayer.cs
@@ -10,10 +10,12 @@
namespace ImageProcessor.Imaging
{
+ using System;
+
///
/// Encapsulates the properties required to add rounded corners to an image.
///
- public class RoundedCornerLayer
+ public class RoundedCornerLayer : IEquatable
{
///
/// Initializes a new instance of the class.
@@ -68,45 +70,34 @@ public RoundedCornerLayer(int radius, bool topLeft = true, bool topRight = true,
public bool BottomRight { get; set; }
///
- /// Returns a value that indicates whether the specified object is an
- /// object that is equivalent to
- /// this object.
+ /// Determines whether the specified , is equal to this instance.
///
- ///
- /// The object to test.
- ///
+ /// The to compare with this instance.
///
- /// True if the given object is an object that is equivalent to
- /// this object; otherwise, false.
+ /// true if the specified is equal to this instance; otherwise, false.
///
- public override bool Equals(object obj)
- {
- if (!(obj is RoundedCornerLayer rounded))
- {
- return false;
- }
+ public override bool Equals(object obj) => obj is RoundedCornerLayer roundedCornerLayer && this.Equals(roundedCornerLayer);
- return this.Radius == rounded.Radius
- && this.TopLeft == rounded.TopLeft && this.TopRight == rounded.TopRight
- && this.BottomLeft == rounded.BottomLeft && this.BottomRight == rounded.BottomRight;
- }
+ ///
+ /// Indicates whether the current object is equal to another object of the same type.
+ ///
+ /// An object to compare with this object.
+ ///
+ /// true if the current object is equal to the parameter; otherwise, false.
+ ///
+ public bool Equals(RoundedCornerLayer other) => other != null
+ && this.Radius == other.Radius
+ && this.TopLeft == other.TopLeft
+ && this.TopRight == other.TopRight
+ && this.BottomLeft == other.BottomLeft
+ && this.BottomRight == other.BottomRight;
///
- /// Returns the hash code for this instance.
+ /// Returns a hash code for this instance.
///
///
- /// A 32-bit signed integer that is 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.
///
- public override int GetHashCode()
- {
- unchecked
- {
- int hashCode = this.Radius;
- hashCode = (hashCode * 397) ^ this.TopLeft.GetHashCode();
- hashCode = (hashCode * 397) ^ this.TopRight.GetHashCode();
- hashCode = (hashCode * 397) ^ this.BottomLeft.GetHashCode();
- return (hashCode * 397) ^ this.BottomRight.GetHashCode();
- }
- }
+ public override int GetHashCode() => (this.Radius, this.TopLeft, this.TopRight, this.BottomLeft, this.BottomRight).GetHashCode();
}
}
diff --git a/src/ImageProcessor/Imaging/TextLayer.cs b/src/ImageProcessor/Imaging/TextLayer.cs
index 049fa92af..837299c18 100644
--- a/src/ImageProcessor/Imaging/TextLayer.cs
+++ b/src/ImageProcessor/Imaging/TextLayer.cs
@@ -18,7 +18,7 @@ namespace ImageProcessor.Imaging
///
/// Encapsulates the properties required to add a layer of text to an image.
///
- public class TextLayer : IDisposable
+ public class TextLayer : IDisposable, IEquatable
{
///
/// A value indicating whether this instance of the given entity has been disposed.
@@ -96,58 +96,40 @@ public class TextLayer : IDisposable
public bool RightToLeft { get; set; }
///
- /// Returns a value that indicates whether the specified object is an
- /// object that is equivalent to
- /// this object.
+ /// Determines whether the specified , is equal to this instance.
///
- ///
- /// The object to test.
- ///
+ /// The to compare with this instance.
///
- /// True if the given object is an object that is equivalent to
- /// this object; otherwise, false.
+ /// true if the specified is equal to this instance; otherwise, false.
///
- public override bool Equals(object obj)
- {
- if (!(obj is TextLayer textLayer))
- {
- return false;
- }
+ public override bool Equals(object obj) => obj is TextLayer textLayer && this.Equals(textLayer);
- return this.Text == textLayer.Text
- && this.FontColor == textLayer.FontColor
- && this.FontFamily.Equals(textLayer.FontFamily)
- && this.FontSize == textLayer.FontSize
- && this.Style == textLayer.Style
- && this.DropShadow == textLayer.DropShadow
- && this.Opacity == textLayer.Opacity
- && this.Position == textLayer.Position
- && this.Vertical == textLayer.Vertical
- && this.RightToLeft == textLayer.RightToLeft;
- }
+ ///
+ /// Indicates whether the current object is equal to another object of the same type.
+ ///
+ /// An object to compare with this object.
+ ///
+ /// true if the current object is equal to the parameter; otherwise, false.
+ ///
+ public bool Equals(TextLayer other) => other != null
+ && this.Text == other.Text
+ && this.FontColor == other.FontColor
+ && (this.FontFamily == null || other.FontFamily == null ? this.FontFamily == other.FontFamily : this.FontFamily.Equals(other.FontFamily))
+ && this.FontSize == other.FontSize
+ && this.Style == other.Style
+ && this.Opacity == other.Opacity
+ && this.Position == other.Position
+ && this.DropShadow == other.DropShadow
+ && this.Vertical == other.Vertical
+ && this.RightToLeft == other.RightToLeft;
///
- /// Returns the hash code for this instance.
+ /// Returns a hash code for this instance.
///
///
- /// A 32-bit signed integer that is 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.
///
- public override int GetHashCode()
- {
- unchecked
- {
- int hashCode = this.Text?.GetHashCode() ?? 0;
- hashCode = (hashCode * 397) ^ this.DropShadow.GetHashCode();
- hashCode = (hashCode * 397) ^ (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();
- hashCode = (hashCode * 397) ^ this.Vertical.GetHashCode();
- return (hashCode * 397) ^ this.RightToLeft.GetHashCode();
- }
- }
+ public override int GetHashCode() => (this.Text, this.FontColor, this.FontFamily, this.FontSize, this.Style, this.Opacity, this.Position, this.DropShadow, this.Vertical, this.RightToLeft).GetHashCode();
///
/// Disposes the object and frees resources for the Garbage Collector.
diff --git a/src/ImageProcessor/packages.config b/src/ImageProcessor/packages.config
new file mode 100644
index 000000000..8653b8e4c
--- /dev/null
+++ b/src/ImageProcessor/packages.config
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/tests/ImageProcessor.UnitTests/Imaging/Filters/Photo/MatrixFilterBaseTests.cs b/tests/ImageProcessor.UnitTests/Imaging/Filters/Photo/MatrixFilterBaseTests.cs
index d5b76bb3f..c87f8afdf 100644
--- a/tests/ImageProcessor.UnitTests/Imaging/Filters/Photo/MatrixFilterBaseTests.cs
+++ b/tests/ImageProcessor.UnitTests/Imaging/Filters/Photo/MatrixFilterBaseTests.cs
@@ -29,7 +29,7 @@ public static void MatrixFilterBaseImplementsEqualsBasedOnMatrixPropertyVariant(
VariantFilterBase first = new VariantFilterBase();
VariantFilterBase second = new VariantFilterBase();
- first.Equals(second).Should().BeFalse();
+ first.Equals(second).Should().BeTrue();
}
internal static ColorMatrix InvariantColorMatrix = new ColorMatrix(new[]