Browse Source

Merge pull request #455 from SixLabors/mono-workaround

Move swap to classes to avoid odd issues on Mono.
af/merge-core
Dirk Lemstra 8 years ago
committed by GitHub
parent
commit
5610d0e5d5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      src/ImageSharp/Common/Extensions/ComparableExtensions.cs
  2. 12
      src/ImageSharp/Formats/Png/PngDecoderCore.cs
  3. 5
      src/ImageSharp/Formats/Png/PngEncoderCore.cs
  4. 4
      src/ImageSharp/Image/ImageFrame{TPixel}.cs

14
src/ImageSharp/Common/Extensions/ComparableExtensions.cs

@ -169,19 +169,5 @@ namespace SixLabors.ImageSharp
{
return (byte)value.Clamp(0, 255);
}
/// <summary>
/// Swaps the references to two objects in memory.
/// </summary>
/// <param name="first">The first reference.</param>
/// <param name="second">The second reference.</param>
/// <typeparam name="T">The type of object.</typeparam>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Swap<T>(ref T first, ref T second)
{
T temp = second;
second = first;
first = temp;
}
}
}

12
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<TPixel> 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<byte> temp = this.previousScanline;
this.previousScanline = this.scanline;
this.scanline = temp;
}
}
}

5
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<byte> r = this.EncodePixelRow(pixels.GetPixelRowSpan(y), y);
deflateStream.Write(r.Array, 0, resultLength);
Swap(ref this.rawScanline, ref this.previousScanline);
Buffer<byte> temp = this.rawScanline;
this.rawScanline = this.previousScanline;
this.previousScanline = temp;
}
}

4
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<TPixel> temp = this.pixelBuffer;
this.pixelBuffer = pixelSource.pixelBuffer;
pixelSource.pixelBuffer = temp;
}
/// <summary>

Loading…
Cancel
Save