From 5679c42dcaa130aec19defba5ffa821071e88f8e Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Sat, 3 Feb 2018 17:57:14 +0100 Subject: [PATCH] Move swap to classes to avoid odd issues on Mono. --- .../Common/Extensions/ComparableExtensions.cs | 14 -------------- src/ImageSharp/Formats/Png/PngDecoderCore.cs | 12 +++++++++--- src/ImageSharp/Formats/Png/PngEncoderCore.cs | 5 +++-- src/ImageSharp/Image/ImageFrame{TPixel}.cs | 4 +++- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/ImageSharp/Common/Extensions/ComparableExtensions.cs b/src/ImageSharp/Common/Extensions/ComparableExtensions.cs index 8bebb3de7..d6dade770 100644 --- a/src/ImageSharp/Common/Extensions/ComparableExtensions.cs +++ b/src/ImageSharp/Common/Extensions/ComparableExtensions.cs @@ -169,19 +169,5 @@ namespace SixLabors.ImageSharp { return (byte)value.Clamp(0, 255); } - - /// - /// Swaps the references to two objects in memory. - /// - /// The first reference. - /// The second reference. - /// The type of object. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Swap(ref T first, ref T second) - { - T temp = second; - second = first; - first = temp; - } } } diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index 5cdf80289..e39187e08 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -14,7 +14,6 @@ using SixLabors.ImageSharp.Formats.Png.Zlib; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.PixelFormats; -using static SixLabors.ImageSharp.ComparableExtensions; namespace SixLabors.ImageSharp.Formats.Png { @@ -589,7 +588,7 @@ namespace SixLabors.ImageSharp.Formats.Png this.ProcessDefilteredScanline(this.scanline.Array, image); - Swap(ref this.scanline, ref this.previousScanline); + this.SwapBuffers(); this.currentRow++; } } @@ -665,7 +664,7 @@ namespace SixLabors.ImageSharp.Formats.Png Span rowSpan = image.GetPixelRowSpan(this.currentRow); this.ProcessInterlacedDefilteredScanline(this.scanline.Array, rowSpan, Adam7FirstColumn[this.pass], Adam7ColumnIncrement[this.pass]); - Swap(ref this.scanline, ref this.previousScanline); + this.SwapBuffers(); this.currentRow += Adam7RowIncrement[this.pass]; } @@ -1348,5 +1347,12 @@ namespace SixLabors.ImageSharp.Formats.Png default: throw new ArgumentException($"Not a valid pass index: {passIndex}"); } } + + private void SwapBuffers() + { + Buffer temp = this.previousScanline; + this.previousScanline = this.scanline; + this.scanline = temp; + } } } diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index 6dbf2eeb8..385d40b6b 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -11,7 +11,6 @@ using SixLabors.ImageSharp.Formats.Png.Zlib; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Quantizers; -using static SixLabors.ImageSharp.ComparableExtensions; namespace SixLabors.ImageSharp.Formats.Png { @@ -645,7 +644,9 @@ namespace SixLabors.ImageSharp.Formats.Png Buffer r = this.EncodePixelRow(pixels.GetPixelRowSpan(y), y); deflateStream.Write(r.Array, 0, resultLength); - Swap(ref this.rawScanline, ref this.previousScanline); + Buffer temp = this.rawScanline; + this.rawScanline = this.previousScanline; + this.previousScanline = temp; } } diff --git a/src/ImageSharp/Image/ImageFrame{TPixel}.cs b/src/ImageSharp/Image/ImageFrame{TPixel}.cs index e39cc1ab2..ba475f9cf 100644 --- a/src/ImageSharp/Image/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/Image/ImageFrame{TPixel}.cs @@ -168,7 +168,9 @@ namespace SixLabors.ImageSharp { Guard.NotNull(pixelSource, nameof(pixelSource)); - ComparableExtensions.Swap(ref this.pixelBuffer, ref pixelSource.pixelBuffer); + Buffer2D temp = this.pixelBuffer; + this.pixelBuffer = pixelSource.pixelBuffer; + pixelSource.pixelBuffer = temp; } ///