diff --git a/src/ImageSharp/MetaData/ImageProperty.cs b/src/ImageSharp/MetaData/ImageProperty.cs
index a08a95fed..4644f9b68 100644
--- a/src/ImageSharp/MetaData/ImageProperty.cs
+++ b/src/ImageSharp/MetaData/ImageProperty.cs
@@ -106,7 +106,7 @@ namespace SixLabors.ImageSharp.MetaData
int hashCode = this.Name.GetHashCode();
if (this.Value != null)
{
- hashCode = (hashCode * 397) ^ this.Value.GetHashCode();
+ hashCode = HashHelpers.Combine(hashCode, this.Value.GetHashCode());
}
return hashCode;
diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccParametricCurve.cs b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccParametricCurve.cs
index a241acd21..f707ee595 100644
--- a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccParametricCurve.cs
+++ b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccParametricCurve.cs
@@ -157,13 +157,13 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
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();
+ hashCode = HashHelpers.Combine(hashCode, this.G.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.A.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.B.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.C.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.D.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.E.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.F.GetHashCode());
return hashCode;
}
}
diff --git a/src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs
index 2687e10b6..4c6bb0785 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/IccCrdInfoTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCrdInfoTagDataEntry.cs
index cc1aea319..9af77ba7c 100644
--- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCrdInfoTagDataEntry.cs
+++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCrdInfoTagDataEntry.cs
@@ -124,11 +124,11 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
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);
+ hashCode = HashHelpers.Combine(hashCode, this.PostScriptProductName?.GetHashCode() ?? 0);
+ hashCode = HashHelpers.Combine(hashCode, this.RenderingIntent0Crd?.GetHashCode() ?? 0);
+ hashCode = HashHelpers.Combine(hashCode, this.RenderingIntent1Crd?.GetHashCode() ?? 0);
+ hashCode = HashHelpers.Combine(hashCode, this.RenderingIntent2Crd?.GetHashCode() ?? 0);
+ hashCode = HashHelpers.Combine(hashCode, this.RenderingIntent3Crd?.GetHashCode() ?? 0);
return hashCode;
}
}
diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs
index e11562f44..281b17ba9 100644
--- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs
+++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs
@@ -140,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();
- hashCode = (hashCode * 397) ^ this.ClutValues.GetHashCode();
- hashCode = (hashCode * 397) ^ this.OutputValues.GetHashCode();
- return hashCode;
- }
+ int hashCode = base.GetHashCode();
+ hashCode = HashHelpers.Combine(hashCode, this.Matrix.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.InputValues.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.ClutValues.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.OutputValues.GetHashCode());
+ return hashCode;
}
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 b448b481a..e3c45adb4 100644
--- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs
+++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs
@@ -143,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();
- hashCode = (hashCode * 397) ^ this.ClutValues.GetHashCode();
- hashCode = (hashCode * 397) ^ this.OutputValues.GetHashCode();
- return hashCode;
- }
+ int hashCode = base.GetHashCode();
+ hashCode = HashHelpers.Combine(hashCode, this.Matrix.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.InputValues.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.ClutValues.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.OutputValues.GetHashCode());
+ return hashCode;
}
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 22d5f7b2f..3dadee2da 100644
--- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutAToBTagDataEntry.cs
+++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutAToBTagDataEntry.cs
@@ -183,19 +183,16 @@ 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;
- }
+ int hashCode = base.GetHashCode();
+ hashCode = HashHelpers.Combine(hashCode, this.InputChannelCount.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.OutputChannelCount.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.Matrix3x3.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.Matrix3x1.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.ClutValues?.GetHashCode() ?? 0);
+ hashCode = HashHelpers.Combine(hashCode, this.CurveB?.GetHashCode() ?? 0);
+ hashCode = HashHelpers.Combine(hashCode, this.CurveM?.GetHashCode() ?? 0);
+ hashCode = HashHelpers.Combine(hashCode, this.CurveA?.GetHashCode() ?? 0);
+ return hashCode;
}
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 a739358b5..09d080380 100644
--- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutBToATagDataEntry.cs
+++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutBToATagDataEntry.cs
@@ -183,19 +183,16 @@ 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);
+ hashCode = HashHelpers.Combine(hashCode, this.InputChannelCount.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.OutputChannelCount.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.Matrix3x3.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.Matrix3x1.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.ClutValues?.GetHashCode() ?? 0);
+ hashCode = HashHelpers.Combine(hashCode, this.CurveB?.GetHashCode() ?? 0);
+ hashCode = HashHelpers.Combine(hashCode, this.CurveM?.GetHashCode() ?? 0);
+ hashCode = HashHelpers.Combine(hashCode, this.CurveA?.GetHashCode() ?? 0);
return hashCode;
- }
}
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 262129a38..6f918660f 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;
- }
+ int hashCode = base.GetHashCode();
+ hashCode = HashHelpers.Combine(hashCode, this.Observer.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.XyzBacking.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.Geometry.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.Flare.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.Illuminant.GetHashCode());
+ return hashCode;
}
}
}
diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccNamedColor2TagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccNamedColor2TagDataEntry.cs
index c32a45182..0da1f3e9f 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;
- }
+ int hashCode = base.GetHashCode();
+ hashCode = HashHelpers.Combine(hashCode, this.CoordinateCount.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.Prefix?.GetHashCode() ?? 0);
+ hashCode = HashHelpers.Combine(hashCode, this.Suffix?.GetHashCode() ?? 0);
+ hashCode = HashHelpers.Combine(hashCode, this.VendorFlags.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.Colors.GetHashCode());
+ return hashCode;
}
}
}
diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs
index ca1e4c491..9f9e5cef7 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;
- }
+ int hashCode = base.GetHashCode();
+ hashCode = HashHelpers.Combine(hashCode, this.Ascii?.GetHashCode() ?? 0);
+ hashCode = HashHelpers.Combine(hashCode, this.Unicode?.GetHashCode() ?? 0);
+ hashCode = HashHelpers.Combine(hashCode, this.ScriptCode?.GetHashCode() ?? 0);
+ hashCode = HashHelpers.Combine(hashCode, this.UnicodeLanguageCode.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.ScriptCodeCode.GetHashCode());
+ return hashCode;
}
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccClut.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccClut.cs
index 3424a11ed..685b5884f 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();
- hashCode = (hashCode * 397) ^ (int)this.DataType;
- hashCode = (hashCode * 397) ^ this.InputChannelCount;
- hashCode = (hashCode * 397) ^ this.OutputChannelCount;
- hashCode = (hashCode * 397) ^ this.GridPointCount.GetHashCode();
- return hashCode;
- }
+ int hashCode = this.Values.GetHashCode();
+ hashCode = HashHelpers.Combine(hashCode, this.DataType.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.InputChannelCount.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.OutputChannelCount.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.GridPointCount.GetHashCode());
+ return hashCode;
}
private bool EqualsValuesArray(IccClut other)
diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileDescription.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileDescription.cs
index 4319b0e8b..3af6dc6a8 100644
--- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileDescription.cs
+++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileDescription.cs
@@ -84,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();
- hashCode = (hashCode * 397) ^ this.DeviceModelInfo.GetHashCode();
- return hashCode;
- }
+ int hashCode = this.DeviceManufacturer.GetHashCode();
+ hashCode = HashHelpers.Combine(hashCode, this.DeviceModel.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.DeviceAttributes.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.TechnologyInformation.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.DeviceManufacturerInfo.GetHashCode());
+ hashCode = HashHelpers.Combine(hashCode, this.DeviceModelInfo.GetHashCode());
+ return hashCode;
}
}
}