From 9a80514f2c5bc248ef73498cf9453bb16ce0c38e Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Thu, 21 Jun 2018 14:11:05 +1000 Subject: [PATCH] Faster 32-64 bit conversion, update references, and cleanup. --- src/ImageSharp/PixelFormats/Argb32.cs | 23 +++++++--- src/ImageSharp/PixelFormats/Bgr24.cs | 29 +++++++----- src/ImageSharp/PixelFormats/Bgra32.cs | 29 +++++++----- src/ImageSharp/PixelFormats/Byte4.cs | 2 +- src/ImageSharp/PixelFormats/Rgb24.cs | 31 +++++++------ src/ImageSharp/PixelFormats/Rgb48.cs | 41 ++++++++--------- src/ImageSharp/PixelFormats/Rgba32.cs | 24 +++++++--- src/ImageSharp/PixelFormats/Rgba64.cs | 44 +++++++++---------- src/ImageSharp/PixelFormats/Short4.cs | 3 +- .../ImageComparison/TolerantImageComparer.cs | 17 ++++--- .../ReferenceCodecs/SystemDrawingBridge.cs | 3 +- .../TestUtilities/TestEnvironment.cs | 2 +- tests/Images/External | 2 +- 13 files changed, 145 insertions(+), 105 deletions(-) diff --git a/src/ImageSharp/PixelFormats/Argb32.cs b/src/ImageSharp/PixelFormats/Argb32.cs index bd4c93d28b..ccb17a2a5e 100644 --- a/src/ImageSharp/PixelFormats/Argb32.cs +++ b/src/ImageSharp/PixelFormats/Argb32.cs @@ -63,7 +63,7 @@ namespace SixLabors.ImageSharp.PixelFormats this.R = r; this.G = g; this.B = b; - this.A = 255; + this.A = byte.MaxValue; } /// @@ -312,7 +312,13 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void PackFromRgb48(Rgb48 source) => this.PackFromScaledVector4(source.ToScaledVector4()); + public void PackFromRgb48(Rgb48 source) + { + this.R = (byte)(((source.R * 255) + 32895) >> 16); + this.G = (byte)(((source.G * 255) + 32895) >> 16); + this.B = (byte)(((source.B * 255) + 32895) >> 16); + this.A = byte.MaxValue; + } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -320,7 +326,13 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void PackFromRgba64(Rgba64 source) => this.PackFromScaledVector4(source.ToScaledVector4()); + public void PackFromRgba64(Rgba64 source) + { + this.R = (byte)(((source.R * 255) + 32895) >> 16); + this.G = (byte)(((source.G * 255) + 32895) >> 16); + this.B = (byte)(((source.B * 255) + 32895) >> 16); + this.A = (byte)(((source.A * 255) + 32895) >> 16); + } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -352,8 +364,9 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { - // ReSharper disable once NonReadonlyMemberInGetHashCode - return this.Argb.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()); } /// diff --git a/src/ImageSharp/PixelFormats/Bgr24.cs b/src/ImageSharp/PixelFormats/Bgr24.cs index 13673aa472..8655210844 100644 --- a/src/ImageSharp/PixelFormats/Bgr24.cs +++ b/src/ImageSharp/PixelFormats/Bgr24.cs @@ -69,13 +69,8 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { - unchecked - { - int hashCode = this.B; - hashCode = (hashCode * 397) ^ this.G; - hashCode = (hashCode * 397) ^ this.R; - return hashCode; - } + int hash = HashHelpers.Combine(this.R.GetHashCode(), this.G.GetHashCode()); + return HashHelpers.Combine(hash, this.B.GetHashCode()); } /// @@ -149,7 +144,7 @@ namespace SixLabors.ImageSharp.PixelFormats dest.R = this.R; dest.G = this.G; dest.B = this.B; - dest.A = 255; + dest.A = byte.MaxValue; } /// @@ -159,7 +154,7 @@ namespace SixLabors.ImageSharp.PixelFormats dest.R = this.R; dest.G = this.G; dest.B = this.B; - dest.A = 255; + dest.A = byte.MaxValue; } /// @@ -174,12 +169,17 @@ namespace SixLabors.ImageSharp.PixelFormats dest.R = this.R; dest.G = this.G; dest.B = this.B; - dest.A = 255; + dest.A = byte.MaxValue; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void PackFromRgb48(Rgb48 source) => this.PackFromScaledVector4(source.ToScaledVector4()); + public void PackFromRgb48(Rgb48 source) + { + this.R = (byte)(((source.R * 255) + 32895) >> 16); + this.G = (byte)(((source.G * 255) + 32895) >> 16); + this.B = (byte)(((source.B * 255) + 32895) >> 16); + } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -187,7 +187,12 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void PackFromRgba64(Rgba64 source) => this.PackFromScaledVector4(source.ToScaledVector4()); + public void PackFromRgba64(Rgba64 source) + { + this.R = (byte)(((source.R * 255) + 32895) >> 16); + this.G = (byte)(((source.G * 255) + 32895) >> 16); + this.B = (byte)(((source.B * 255) + 32895) >> 16); + } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/ImageSharp/PixelFormats/Bgra32.cs b/src/ImageSharp/PixelFormats/Bgra32.cs index 86a141bc52..f951be8811 100644 --- a/src/ImageSharp/PixelFormats/Bgra32.cs +++ b/src/ImageSharp/PixelFormats/Bgra32.cs @@ -60,7 +60,7 @@ namespace SixLabors.ImageSharp.PixelFormats this.R = r; this.G = g; this.B = b; - this.A = 255; + this.A = byte.MaxValue; } /// @@ -113,14 +113,9 @@ namespace SixLabors.ImageSharp.PixelFormats /// public override int GetHashCode() { - unchecked - { - int hashCode = this.B; - hashCode = (hashCode * 397) ^ this.G; - hashCode = (hashCode * 397) ^ this.R; - hashCode = (hashCode * 397) ^ this.A; - return hashCode; - } + int hash = HashHelpers.Combine(this.R.GetHashCode(), this.G.GetHashCode()); + hash = HashHelpers.Combine(hash, this.B.GetHashCode()); + return HashHelpers.Combine(hash, this.A.GetHashCode()); } /// @@ -248,7 +243,13 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void PackFromRgb48(Rgb48 source) => this.PackFromScaledVector4(source.ToScaledVector4()); + public void PackFromRgb48(Rgb48 source) + { + this.R = (byte)(((source.R * 255) + 32895) >> 16); + this.G = (byte)(((source.G * 255) + 32895) >> 16); + this.B = (byte)(((source.B * 255) + 32895) >> 16); + this.A = byte.MaxValue; + } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -256,7 +257,13 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void PackFromRgba64(Rgba64 source) => this.PackFromScaledVector4(source.ToScaledVector4()); + public void PackFromRgba64(Rgba64 source) + { + this.R = (byte)(((source.R * 255) + 32895) >> 16); + this.G = (byte)(((source.G * 255) + 32895) >> 16); + this.B = (byte)(((source.B * 255) + 32895) >> 16); + this.A = (byte)(((source.A * 255) + 32895) >> 16); + } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/ImageSharp/PixelFormats/Byte4.cs b/src/ImageSharp/PixelFormats/Byte4.cs index 48430d17a3..4269557270 100644 --- a/src/ImageSharp/PixelFormats/Byte4.cs +++ b/src/ImageSharp/PixelFormats/Byte4.cs @@ -198,7 +198,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// public override bool Equals(object obj) { - return (obj is Byte4) && this.Equals((Byte4)obj); + return obj is Byte4 byte4 && this.Equals(byte4); } /// diff --git a/src/ImageSharp/PixelFormats/Rgb24.cs b/src/ImageSharp/PixelFormats/Rgb24.cs index c3ad827558..4c7ad5909a 100644 --- a/src/ImageSharp/PixelFormats/Rgb24.cs +++ b/src/ImageSharp/PixelFormats/Rgb24.cs @@ -70,13 +70,8 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { - unchecked - { - int hashCode = this.R; - hashCode = (hashCode * 397) ^ this.G; - hashCode = (hashCode * 397) ^ this.B; - return hashCode; - } + int hash = HashHelpers.Combine(this.R.GetHashCode(), this.G.GetHashCode()); + return HashHelpers.Combine(hash, this.B.GetHashCode()); } /// @@ -131,7 +126,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector4 ToVector4() { - return new Rgba32(this.R, this.G, this.B, 255).ToVector4(); + return new Rgba32(this.R, this.G, this.B, byte.MaxValue).ToVector4(); } /// @@ -142,7 +137,7 @@ namespace SixLabors.ImageSharp.PixelFormats public void ToRgba32(ref Rgba32 dest) { dest.Rgb = this; - dest.A = 255; + dest.A = byte.MaxValue; } /// @@ -151,7 +146,7 @@ namespace SixLabors.ImageSharp.PixelFormats dest.R = this.R; dest.G = this.G; dest.B = this.B; - dest.A = 255; + dest.A = byte.MaxValue; } /// @@ -168,12 +163,17 @@ namespace SixLabors.ImageSharp.PixelFormats dest.R = this.R; dest.G = this.G; dest.B = this.B; - dest.A = 255; + dest.A = byte.MaxValue; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void PackFromRgb48(Rgb48 source) => this.PackFromScaledVector4(source.ToScaledVector4()); + public void PackFromRgb48(Rgb48 source) + { + this.R = (byte)(((source.R * 255) + 32895) >> 16); + this.G = (byte)(((source.G * 255) + 32895) >> 16); + this.B = (byte)(((source.B * 255) + 32895) >> 16); + } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -181,7 +181,12 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void PackFromRgba64(Rgba64 source) => this.PackFromScaledVector4(source.ToScaledVector4()); + public void PackFromRgba64(Rgba64 source) + { + this.R = (byte)(((source.R * 255) + 32895) >> 16); + this.G = (byte)(((source.G * 255) + 32895) >> 16); + this.B = (byte)(((source.B * 255) + 32895) >> 16); + } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/ImageSharp/PixelFormats/Rgb48.cs b/src/ImageSharp/PixelFormats/Rgb48.cs index 8340060118..2d92b0e4e3 100644 --- a/src/ImageSharp/PixelFormats/Rgb48.cs +++ b/src/ImageSharp/PixelFormats/Rgb48.cs @@ -166,53 +166,48 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToRgb24(ref Rgb24 dest) { - Vector4 vector = this.ToVector4() * 255F; - dest.R = (byte)MathF.Round(vector.X); - dest.G = (byte)MathF.Round(vector.Y); - dest.B = (byte)MathF.Round(vector.Z); + dest.R = (byte)(((this.R * 255) + 32895) >> 16); + dest.G = (byte)(((this.G * 255) + 32895) >> 16); + dest.B = (byte)(((this.B * 255) + 32895) >> 16); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToRgba32(ref Rgba32 dest) { - Vector4 vector = this.ToVector4() * 255F; - dest.R = (byte)MathF.Round(vector.X); - dest.G = (byte)MathF.Round(vector.Y); - dest.B = (byte)MathF.Round(vector.Z); - dest.A = (byte)MathF.Round(vector.W); + dest.R = (byte)(((this.R * 255) + 32895) >> 16); + dest.G = (byte)(((this.G * 255) + 32895) >> 16); + dest.B = (byte)(((this.B * 255) + 32895) >> 16); + dest.A = 255; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToArgb32(ref Argb32 dest) { - Vector4 vector = this.ToVector4() * 255F; - dest.R = (byte)MathF.Round(vector.X); - dest.G = (byte)MathF.Round(vector.Y); - dest.B = (byte)MathF.Round(vector.Z); - dest.A = (byte)MathF.Round(vector.W); + dest.R = (byte)(((this.R * 255) + 32895) >> 16); + dest.G = (byte)(((this.G * 255) + 32895) >> 16); + dest.B = (byte)(((this.B * 255) + 32895) >> 16); + dest.A = 255; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToBgr24(ref Bgr24 dest) { - Vector4 vector = this.ToVector4() * 255F; - dest.R = (byte)MathF.Round(vector.X); - dest.G = (byte)MathF.Round(vector.Y); - dest.B = (byte)MathF.Round(vector.Z); + dest.R = (byte)(((this.R * 255) + 32895) >> 16); + dest.G = (byte)(((this.G * 255) + 32895) >> 16); + dest.B = (byte)(((this.B * 255) + 32895) >> 16); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToBgra32(ref Bgra32 dest) { - Vector4 vector = this.ToVector4() * 255F; - dest.R = (byte)MathF.Round(vector.X); - dest.G = (byte)MathF.Round(vector.Y); - dest.B = (byte)MathF.Round(vector.Z); - dest.A = (byte)MathF.Round(vector.W); + dest.R = (byte)(((this.R * 255) + 32895) >> 16); + dest.G = (byte)(((this.G * 255) + 32895) >> 16); + dest.B = (byte)(((this.B * 255) + 32895) >> 16); + dest.A = 255; } /// diff --git a/src/ImageSharp/PixelFormats/Rgba32.cs b/src/ImageSharp/PixelFormats/Rgba32.cs index c585dbfda8..79794ee462 100644 --- a/src/ImageSharp/PixelFormats/Rgba32.cs +++ b/src/ImageSharp/PixelFormats/Rgba32.cs @@ -83,7 +83,7 @@ namespace SixLabors.ImageSharp.PixelFormats this.R = r; this.G = g; this.B = b; - this.A = 255; + this.A = byte.MaxValue; } /// @@ -389,7 +389,13 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void PackFromRgb48(Rgb48 source) => this.PackFromScaledVector4(source.ToScaledVector4()); + public void PackFromRgb48(Rgb48 source) + { + this.R = (byte)(((source.R * 255) + 32895) >> 16); + this.G = (byte)(((source.G * 255) + 32895) >> 16); + this.B = (byte)(((source.B * 255) + 32895) >> 16); + this.A = byte.MaxValue; + } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -397,7 +403,14 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void PackFromRgba64(Rgba64 source) => this.PackFromScaledVector4(source.ToScaledVector4()); + public void PackFromRgba64(Rgba64 source) + { + // Taken from libpng pngtran.c line: 2419 + this.R = (byte)(((source.R * 255) + 32895) >> 16); + this.G = (byte)(((source.G * 255) + 32895) >> 16); + this.B = (byte)(((source.B * 255) + 32895) >> 16); + this.A = (byte)(((source.A * 255) + 32895) >> 16); + } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -426,8 +439,9 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { - // ReSharper disable once NonReadonlyMemberInGetHashCode - return this.Rgba.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()); } /// diff --git a/src/ImageSharp/PixelFormats/Rgba64.cs b/src/ImageSharp/PixelFormats/Rgba64.cs index ad7d2dc9dd..b0aeab92ea 100644 --- a/src/ImageSharp/PixelFormats/Rgba64.cs +++ b/src/ImageSharp/PixelFormats/Rgba64.cs @@ -170,7 +170,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector4 ToVector4() { - return new Vector4(this.R / Max, this.G / Max, this.B / Max, this.A / Max); + return new Vector4(this.R, this.G, this.B, this.A) / Max; } /// @@ -213,21 +213,20 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToRgb24(ref Rgb24 dest) { - Vector4 vector = this.ToVector4() * 255F; - dest.R = (byte)MathF.Round(vector.X); - dest.G = (byte)MathF.Round(vector.Y); - dest.B = (byte)MathF.Round(vector.Z); + dest.R = (byte)(((this.R * 255) + 32895) >> 16); + dest.G = (byte)(((this.G * 255) + 32895) >> 16); + dest.B = (byte)(((this.B * 255) + 32895) >> 16); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToRgba32(ref Rgba32 dest) { - Vector4 vector = this.ToVector4() * 255F; - dest.R = (byte)MathF.Round(vector.X); - dest.G = (byte)MathF.Round(vector.Y); - dest.B = (byte)MathF.Round(vector.Z); - dest.A = (byte)MathF.Round(vector.W); + // Taken from libpng pngtran.c line: 2419 + dest.R = (byte)(((this.R * 255) + 32895) >> 16); + dest.G = (byte)(((this.G * 255) + 32895) >> 16); + dest.B = (byte)(((this.B * 255) + 32895) >> 16); + dest.A = (byte)(((this.A * 255) + 32895) >> 16); } /// @@ -250,32 +249,29 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToArgb32(ref Argb32 dest) { - Vector4 vector = this.ToVector4() * 255F; - dest.R = (byte)MathF.Round(vector.X); - dest.G = (byte)MathF.Round(vector.Y); - dest.B = (byte)MathF.Round(vector.Z); - dest.A = (byte)MathF.Round(vector.W); + dest.R = (byte)(((this.R * 255) + 32895) >> 16); + dest.G = (byte)(((this.G * 255) + 32895) >> 16); + dest.B = (byte)(((this.B * 255) + 32895) >> 16); + dest.A = (byte)(((this.A * 255) + 32895) >> 16); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToBgr24(ref Bgr24 dest) { - Vector4 vector = this.ToVector4() * 255F; - dest.R = (byte)MathF.Round(vector.X); - dest.G = (byte)MathF.Round(vector.Y); - dest.B = (byte)MathF.Round(vector.Z); + dest.R = (byte)(((this.R * 255) + 32895) >> 16); + dest.G = (byte)(((this.G * 255) + 32895) >> 16); + dest.B = (byte)(((this.B * 255) + 32895) >> 16); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToBgra32(ref Bgra32 dest) { - Vector4 vector = this.ToVector4() * 255F; - dest.R = (byte)MathF.Round(vector.X); - dest.G = (byte)MathF.Round(vector.Y); - dest.B = (byte)MathF.Round(vector.Z); - dest.A = (byte)MathF.Round(vector.W); + dest.R = (byte)(((this.R * 255) + 32895) >> 16); + dest.G = (byte)(((this.G * 255) + 32895) >> 16); + dest.B = (byte)(((this.B * 255) + 32895) >> 16); + dest.A = (byte)(((this.A * 255) + 32895) >> 16); } /// diff --git a/src/ImageSharp/PixelFormats/Short4.cs b/src/ImageSharp/PixelFormats/Short4.cs index 41371362e1..5683ffceea 100644 --- a/src/ImageSharp/PixelFormats/Short4.cs +++ b/src/ImageSharp/PixelFormats/Short4.cs @@ -295,8 +295,7 @@ namespace SixLabors.ImageSharp.PixelFormats vector *= 255; vector += Half; vector += Round; - vector = Vector4.Clamp(vector, Vector4.Zero, MaxBytes); - return vector; + return Vector4.Clamp(vector, Vector4.Zero, MaxBytes); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs index ccc5094707..674603380f 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs @@ -18,6 +18,8 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison /// /// Individual manhattan pixel difference is only added to total image difference when the individual difference is over 'perPixelManhattanThreshold'. /// + /// The maximal tolerated difference represented by a value between 0.0 and 1.0 scaled to 0 and 65535. + /// Gets the threshold of the individual pixels before they acumulate towards the overall difference. public TolerantImageComparer(float imageThreshold, int perPixelManhattanThreshold = 0) { Guard.MustBeGreaterThanOrEqualTo(imageThreshold, 0, nameof(imageThreshold)); @@ -27,24 +29,27 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison } /// - /// The maximal tolerated difference represented by a value between 0.0 and 1.0. + /// + /// Gets the maximal tolerated difference represented by a value between 0.0 and 1.0 scaled to 0 and 65535. /// Examples of percentage differences on a single pixel: /// 1. PixelA = (65535,65535,65535,0) PixelB =(0,0,0,65535) leads to 100% difference on a single pixel /// 2. PixelA = (65535,65535,65535,0) PixelB =(65535,65535,65535,65535) leads to 25% difference on a single pixel - /// 3. PixelA = (65535,65535,65535,0) PixelB =(128,128,128,128) leads to 50% difference on a single pixel - /// + /// 3. PixelA = (65535,65535,65535,0) PixelB =(32767,32767,32767,32767) leads to 50% difference on a single pixel + /// + /// /// The total differences is the sum of all pixel differences normalized by image dimensions! /// The individual distances are calculated using the Manhattan function: /// /// https://en.wikipedia.org/wiki/Taxicab_geometry /// - /// ImageThresholdInPercents = 1.0/65535 means that we allow one unit difference per channel on a 1x1 image - /// ImageThresholdInPercents = 1.0/(100*100*65535) means that we allow only one unit difference per channel on a 100x100 image + /// ImageThresholdInPercents = 1/255 = 257/65535 means that we allow one unit difference per channel on a 1x1 image + /// ImageThresholdInPercents = 1/(100*100*255) = 257/(100*100*65535) means that we allow only one unit difference per channel on a 100x100 image + /// /// public float ImageThreshold { get; } /// - /// The threshold of the individual pixels before they acumulate towards the overall difference. + /// Gets the threshold of the individual pixels before they acumulate towards the overall difference. /// For an individual pixel pair the value is the Manhattan distance of pixels: /// /// https://en.wikipedia.org/wiki/Taxicab_geometry diff --git a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs index c281b50c38..f0daa0abb4 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs @@ -19,6 +19,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs /// /// Returns an image from the given System.Drawing bitmap. /// + /// The pixel format. /// The input bitmap. /// Thrown if the image pixel format is not of type internal static unsafe Image From32bppArgbSystemDrawingBitmap(Bitmap bmp) @@ -64,6 +65,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs /// /// Returns an image from the given System.Drawing bitmap. /// + /// The pixel format. /// The input bitmap. /// Thrown if the image pixel format is not of type internal static unsafe Image From24bppRgbSystemDrawingBitmap(Bitmap bmp) @@ -124,7 +126,6 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs { fixed (Bgra32* sourcePtr = &workBuffer.GetReference()) { - for (int y = 0; y < h; y++) { Span row = image.Frames.RootFrame.GetPixelRowSpan(y); diff --git a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs index 4cee650e8a..d766378863 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs @@ -27,7 +27,7 @@ namespace SixLabors.ImageSharp.Tests () => { bool isCi; - return Boolean.TryParse(Environment.GetEnvironmentVariable("CI"), out isCi) && isCi; + return bool.TryParse(Environment.GetEnvironmentVariable("CI"), out isCi) && isCi; }); // ReSharper disable once InconsistentNaming diff --git a/tests/Images/External b/tests/Images/External index 1473062944..94cc43a65e 160000 --- a/tests/Images/External +++ b/tests/Images/External @@ -1 +1 @@ -Subproject commit 147306294437dc03f6e640f5db2dcd496a43ced7 +Subproject commit 94cc43a65e304aa312bea9d098206086095e6dff