diff --git a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
index 4144487e4..a732d1da2 100644
--- a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
+++ b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
@@ -6,6 +6,7 @@
0.0.1
SixLabors and contributors
netstandard1.1;netstandard2.0
+ 7.2
true
true
SixLabors.ImageSharp.Drawing
diff --git a/src/ImageSharp/Formats/Jpeg/Common/Block8x8.cs b/src/ImageSharp/Formats/Jpeg/Common/Block8x8.cs
index 8a571fa6b..efaa0b4a4 100644
--- a/src/ImageSharp/Formats/Jpeg/Common/Block8x8.cs
+++ b/src/ImageSharp/Formats/Jpeg/Common/Block8x8.cs
@@ -35,7 +35,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common
public Block8x8(Span coefficients)
{
ref byte selfRef = ref Unsafe.As(ref this);
- ref byte sourceRef = ref MemoryMarshal.GetReference(coefficients.NonPortableCast());
+ ref byte sourceRef = ref MemoryMarshal.GetReference(MemoryMarshal.Cast(coefficients));
Unsafe.CopyBlock(ref selfRef, ref sourceRef, Size * sizeof(short));
}
@@ -205,7 +205,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common
public void CopyTo(Span destination)
{
ref byte selfRef = ref Unsafe.As(ref this);
- ref byte destRef = ref MemoryMarshal.GetReference(destination.NonPortableCast());
+ ref byte destRef = ref MemoryMarshal.GetReference(MemoryMarshal.Cast(destination));
Unsafe.CopyBlock(ref destRef, ref selfRef, Size * sizeof(short));
}
diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs
index 234ed6bbd..b3904c0a3 100644
--- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs
+++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs
@@ -8,6 +8,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
using System.Text;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats.Png.Filters;
@@ -776,7 +777,7 @@ namespace SixLabors.ImageSharp.Formats.Png
// TODO: Should we use pack from vector here instead?
this.From16BitTo8Bit(scanlineBuffer, compressed.Span, length);
- Span rgb24Span = compressed.Span.NonPortableCast();
+ Span rgb24Span = MemoryMarshal.Cast(compressed.Span);
for (int x = 0; x < this.header.Width; x++)
{
ref Rgb24 rgb24 = ref rgb24Span[x];
@@ -791,7 +792,7 @@ namespace SixLabors.ImageSharp.Formats.Png
}
else
{
- ReadOnlySpan rgb24Span = scanlineBuffer.NonPortableCast();
+ ReadOnlySpan rgb24Span = MemoryMarshal.Cast(scanlineBuffer);
for (int x = 0; x < this.header.Width; x++)
{
ref readonly Rgb24 rgb24 = ref rgb24Span[x];
diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs
index 17aae1762..676a93ee0 100644
--- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs
+++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs
@@ -559,7 +559,7 @@ namespace SixLabors.ImageSharp.Formats.Png
{
for (int y = 0; y < this.height; y++)
{
- IManagedByteBuffer r = this.EncodePixelRow(pixels.GetPixelRowSpan(y).AsReadOnlySpan(), y);
+ IManagedByteBuffer r = this.EncodePixelRow((ReadOnlySpan)pixels.GetPixelRowSpan(y), y);
deflateStream.Write(r.Array, 0, resultLength);
IManagedByteBuffer temp = this.rawScanline;
diff --git a/src/ImageSharp/Image.LoadPixelData.cs b/src/ImageSharp/Image.LoadPixelData.cs
index f90f4c895..b0bb03580 100644
--- a/src/ImageSharp/Image.LoadPixelData.cs
+++ b/src/ImageSharp/Image.LoadPixelData.cs
@@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0.
using System;
+using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;
@@ -71,7 +72,7 @@ namespace SixLabors.ImageSharp
/// A new .
public static Image LoadPixelData(Configuration config, byte[] data, int width, int height)
where TPixel : struct, IPixel
- => LoadPixelData(config, new Span(data).NonPortableCast(), width, height);
+ => LoadPixelData(config, MemoryMarshal.Cast(data.AsSpan()), width, height);
///
/// Create a new instance of the class from the given byte array in format.
@@ -84,7 +85,7 @@ namespace SixLabors.ImageSharp
/// A new .
private static Image LoadPixelData(Configuration config, Span data, int width, int height)
where TPixel : struct, IPixel
- => LoadPixelData(config, data.NonPortableCast(), width, height);
+ => LoadPixelData(config, MemoryMarshal.Cast(data), width, height);
///
/// Create a new instance of the class from the raw data.
diff --git a/src/ImageSharp/ImageExtensions.cs b/src/ImageSharp/ImageExtensions.cs
index 294da3dc4..1f7e418ad 100644
--- a/src/ImageSharp/ImageExtensions.cs
+++ b/src/ImageSharp/ImageExtensions.cs
@@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
using System.Text;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats;
@@ -112,7 +113,7 @@ namespace SixLabors.ImageSharp
}
///
- /// Saves the raw image pixels to a byte array in row-major order.
+ /// Saves the raw image pixels to a byte array in row-major order.
///
/// The Pixel format.
/// The source image
@@ -120,7 +121,7 @@ namespace SixLabors.ImageSharp
/// Thrown if the stream is null.
public static byte[] SavePixelData(this ImageFrame source)
where TPixel : struct, IPixel
- => source.GetPixelSpan().AsBytes().ToArray();
+ => MemoryMarshal.AsBytes(source.GetPixelSpan()).ToArray();
///
/// Saves the raw image pixels to the given byte array in row-major order.
@@ -131,7 +132,7 @@ namespace SixLabors.ImageSharp
/// Thrown if the stream is null.
public static void SavePixelData(this ImageFrame source, byte[] buffer)
where TPixel : struct, IPixel
- => SavePixelData(source, buffer.AsSpan().NonPortableCast());
+ => SavePixelData(source, MemoryMarshal.Cast(buffer.AsSpan()));
///
/// Saves the raw image pixels to the given TPixel array in row-major order.
@@ -205,7 +206,7 @@ namespace SixLabors.ImageSharp
/// Thrown if the stream is null.
internal static void SavePixelData(this Image source, Span buffer)
where TPixel : struct, IPixel
- => source.Frames.RootFrame.SavePixelData(buffer.NonPortableCast());
+ => source.Frames.RootFrame.SavePixelData(MemoryMarshal.Cast(buffer));
///
/// Saves the raw image to the given bytes.
diff --git a/src/ImageSharp/ImageFrame.LoadPixelData.cs b/src/ImageSharp/ImageFrame.LoadPixelData.cs
index 9a733fb53..1306c2836 100644
--- a/src/ImageSharp/ImageFrame.LoadPixelData.cs
+++ b/src/ImageSharp/ImageFrame.LoadPixelData.cs
@@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0.
using System;
+using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
@@ -24,7 +25,7 @@ namespace SixLabors.ImageSharp
/// A new .
public static ImageFrame LoadPixelData(MemoryManager memoryManager, Span data, int width, int height)
where TPixel : struct, IPixel
- => LoadPixelData(memoryManager, data.NonPortableCast(), width, height);
+ => LoadPixelData(memoryManager, MemoryMarshal.Cast(data), width, height);
///
/// Create a new instance of the class from the raw data.
diff --git a/src/ImageSharp/ImageFrameCollection.cs b/src/ImageSharp/ImageFrameCollection.cs
index e85e67c74..ef4f70959 100644
--- a/src/ImageSharp/ImageFrameCollection.cs
+++ b/src/ImageSharp/ImageFrameCollection.cs
@@ -77,6 +77,8 @@ namespace SixLabors.ImageSharp
///
public ImageFrame AddFrame(TPixel[] data)
{
+ Guard.NotNull(data, nameof(data));
+
var frame = ImageFrame.LoadPixelData(
this.parent.GetMemoryManager(),
new Span(data),
diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj
index db1de7b6c..8bb0442a1 100644
--- a/src/ImageSharp/ImageSharp.csproj
+++ b/src/ImageSharp/ImageSharp.csproj
@@ -41,8 +41,8 @@
All
-
-
+
+
diff --git a/src/ImageSharp/Memory/ArrayPoolMemoryManager.Buffer{T}.cs b/src/ImageSharp/Memory/ArrayPoolMemoryManager.Buffer{T}.cs
index d4f58fb6f..5ca81b5ec 100644
--- a/src/ImageSharp/Memory/ArrayPoolMemoryManager.Buffer{T}.cs
+++ b/src/ImageSharp/Memory/ArrayPoolMemoryManager.Buffer{T}.cs
@@ -3,6 +3,7 @@
using System;
using System.Buffers;
+using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.Memory
{
@@ -44,7 +45,7 @@ namespace SixLabors.ImageSharp.Memory
protected byte[] Data { get; private set; }
///
- public Span Span => this.Data.AsSpan().NonPortableCast().Slice(0, this.length);
+ public Span Span => MemoryMarshal.Cast(this.Data.AsSpan()).Slice(0, this.length);
///
public void Dispose()
diff --git a/src/ImageSharp/PixelFormats/Generated/PixelOperations{TPixel}.Generated.cs b/src/ImageSharp/PixelFormats/Generated/PixelOperations{TPixel}.Generated.cs
index c8fe5ab88..81a86cdc5 100644
--- a/src/ImageSharp/PixelFormats/Generated/PixelOperations{TPixel}.Generated.cs
+++ b/src/ImageSharp/PixelFormats/Generated/PixelOperations{TPixel}.Generated.cs
@@ -10,8 +10,8 @@ namespace SixLabors.ImageSharp.PixelFormats
public partial class PixelOperations
{
-
- ///
+
+ ///
/// Converts 'count' elements in 'source` span of data to a span of -s.
///
/// The source of data.
@@ -19,8 +19,8 @@ namespace SixLabors.ImageSharp.PixelFormats
/// The number of pixels to convert.
internal virtual void PackFromRgba32(ReadOnlySpan source, Span destPixels, int count)
{
- GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count);
-
+ GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count);
+
ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(source);
ref TPixel destRef = ref MemoryMarshal.GetReference(destPixels);
@@ -30,11 +30,11 @@ namespace SixLabors.ImageSharp.PixelFormats
{
ref TPixel dp = ref Unsafe.Add(ref destRef, i);
rgba = Unsafe.Add(ref sourceRef, i);
- dp.PackFromRgba32(rgba);
+ dp.PackFromRgba32(rgba);
}
}
-
- ///
+
+ ///
/// A helper for that expects a byte span.
/// The layout of the data in 'sourceBytes' must be compatible with layout.
///
@@ -44,10 +44,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void PackFromRgba32Bytes(ReadOnlySpan sourceBytes, Span destPixels, int count)
{
- this.PackFromRgba32(sourceBytes.NonPortableCast(), destPixels, count);
+ this.PackFromRgba32(MemoryMarshal.Cast(sourceBytes), destPixels, count);
}
-
- ///
+
+ ///
/// Converts 'count' pixels in 'sourcePixels` span to a span of -s.
/// Bulk version of .
///
@@ -69,20 +69,20 @@ namespace SixLabors.ImageSharp.PixelFormats
}
}
- ///
+ ///
/// A helper for that expects a byte span as destination.
/// The layout of the data in 'destBytes' must be compatible with layout.
///
/// The to the source colors.
/// The to the destination bytes.
/// The number of pixels to convert.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void ToRgba32Bytes(ReadOnlySpan sourceColors, Span destBytes, int count)
{
- this.ToRgba32(sourceColors, destBytes.NonPortableCast(), count);
+ this.ToRgba32(sourceColors, MemoryMarshal.Cast(destBytes), count);
}
-
- ///
+
+ ///
/// Converts 'count' elements in 'source` span of data to a span of -s.
///
/// The source of data.
@@ -90,22 +90,22 @@ namespace SixLabors.ImageSharp.PixelFormats
/// The number of pixels to convert.
internal virtual void PackFromBgra32(ReadOnlySpan source, Span destPixels, int count)
{
- GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count);
-
+ GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count);
+
ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(source);
ref TPixel destRef = ref MemoryMarshal.GetReference(destPixels);
- Rgba32 rgba = new Rgba32(0, 0, 0, 255);
+ var rgba = new Rgba32(0, 0, 0, 255);
for (int i = 0; i < count; i++)
{
ref TPixel dp = ref Unsafe.Add(ref destRef, i);
rgba = Unsafe.Add(ref sourceRef, i).ToRgba32();
- dp.PackFromRgba32(rgba);
+ dp.PackFromRgba32(rgba);
}
}
-
- ///
+
+ ///
/// A helper for that expects a byte span.
/// The layout of the data in 'sourceBytes' must be compatible with layout.
///
@@ -115,10 +115,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void PackFromBgra32Bytes(ReadOnlySpan sourceBytes, Span destPixels, int count)
{
- this.PackFromBgra32(sourceBytes.NonPortableCast(), destPixels, count);
+ this.PackFromBgra32(MemoryMarshal.Cast(sourceBytes), destPixels, count);
}
-
- ///
+
+ ///
/// Converts 'count' pixels in 'sourcePixels` span to a span of -s.
/// Bulk version of .
///
@@ -140,20 +140,20 @@ namespace SixLabors.ImageSharp.PixelFormats
}
}
- ///
+ ///
/// A helper for that expects a byte span as destination.
/// The layout of the data in 'destBytes' must be compatible with layout.
///
/// The to the source colors.
/// The to the destination bytes.
/// The number of pixels to convert.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void ToBgra32Bytes(ReadOnlySpan sourceColors, Span destBytes, int count)
{
- this.ToBgra32(sourceColors, destBytes.NonPortableCast(), count);
+ this.ToBgra32(sourceColors, MemoryMarshal.Cast(destBytes), count);
}
-
- ///
+
+ ///
/// Converts 'count' elements in 'source` span of data to a span of -s.
///
/// The source of data.
@@ -161,22 +161,22 @@ namespace SixLabors.ImageSharp.PixelFormats
/// The number of pixels to convert.
internal virtual void PackFromRgb24(ReadOnlySpan source, Span destPixels, int count)
{
- GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count);
-
+ GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count);
+
ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(source);
ref TPixel destRef = ref MemoryMarshal.GetReference(destPixels);
- Rgba32 rgba = new Rgba32(0, 0, 0, 255);
+ var rgba = new Rgba32(0, 0, 0, 255);
for (int i = 0; i < count; i++)
{
ref TPixel dp = ref Unsafe.Add(ref destRef, i);
rgba.Rgb = Unsafe.Add(ref sourceRef, i);
- dp.PackFromRgba32(rgba);
+ dp.PackFromRgba32(rgba);
}
}
-
- ///
+
+ ///
/// A helper for that expects a byte span.
/// The layout of the data in 'sourceBytes' must be compatible with layout.
///
@@ -186,10 +186,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void PackFromRgb24Bytes(ReadOnlySpan sourceBytes, Span destPixels, int count)
{
- this.PackFromRgb24(sourceBytes.NonPortableCast(), destPixels, count);
+ this.PackFromRgb24(MemoryMarshal.Cast(sourceBytes), destPixels, count);
}
-
- ///
+
+ ///
/// Converts 'count' pixels in 'sourcePixels` span to a span of -s.
/// Bulk version of .
///
@@ -211,20 +211,20 @@ namespace SixLabors.ImageSharp.PixelFormats
}
}
- ///
+ ///
/// A helper for that expects a byte span as destination.
/// The layout of the data in 'destBytes' must be compatible with layout.
///
/// The to the source colors.
/// The to the destination bytes.
/// The number of pixels to convert.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void ToRgb24Bytes(ReadOnlySpan sourceColors, Span destBytes, int count)
{
- this.ToRgb24(sourceColors, destBytes.NonPortableCast(), count);
+ this.ToRgb24(sourceColors, MemoryMarshal.Cast(destBytes), count);
}
-
- ///
+
+ ///
/// Converts 'count' elements in 'source` span of data to a span of -s.
///
/// The source of data.
@@ -232,8 +232,8 @@ namespace SixLabors.ImageSharp.PixelFormats
/// The number of pixels to convert.
internal virtual void PackFromBgr24(ReadOnlySpan source, Span destPixels, int count)
{
- GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count);
-
+ GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count);
+
ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(source);
ref TPixel destRef = ref MemoryMarshal.GetReference(destPixels);
@@ -243,11 +243,11 @@ namespace SixLabors.ImageSharp.PixelFormats
{
ref TPixel dp = ref Unsafe.Add(ref destRef, i);
rgba.Bgr = Unsafe.Add(ref sourceRef, i);
- dp.PackFromRgba32(rgba);
+ dp.PackFromRgba32(rgba);
}
}
-
- ///
+
+ ///
/// A helper for that expects a byte span.
/// The layout of the data in 'sourceBytes' must be compatible with layout.
///
@@ -257,10 +257,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void PackFromBgr24Bytes(ReadOnlySpan sourceBytes, Span destPixels, int count)
{
- this.PackFromBgr24(sourceBytes.NonPortableCast(), destPixels, count);
+ this.PackFromBgr24(MemoryMarshal.Cast(sourceBytes), destPixels, count);
}
-
- ///
+
+ ///
/// Converts 'count' pixels in 'sourcePixels` span to a span of -s.
/// Bulk version of .
///
@@ -282,18 +282,18 @@ namespace SixLabors.ImageSharp.PixelFormats
}
}
- ///
+ ///
/// A helper for that expects a byte span as destination.
/// The layout of the data in 'destBytes' must be compatible with layout.
///
/// The to the source colors.
/// The to the destination bytes.
/// The number of pixels to convert.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void ToBgr24Bytes(ReadOnlySpan sourceColors, Span destBytes, int count)
{
- this.ToBgr24(sourceColors, destBytes.NonPortableCast(), count);
+ this.ToBgr24(sourceColors, MemoryMarshal.Cast(destBytes), count);
}
-
- }
+
+ }
}
\ No newline at end of file
diff --git a/src/ImageSharp/PixelFormats/NamedColors{TPixel}.cs b/src/ImageSharp/PixelFormats/NamedColors{TPixel}.cs
index e27bde882..0f42e182c 100644
--- a/src/ImageSharp/PixelFormats/NamedColors{TPixel}.cs
+++ b/src/ImageSharp/PixelFormats/NamedColors{TPixel}.cs
@@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0.
using System;
+using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.PixelFormats
{
@@ -737,7 +738,7 @@ namespace SixLabors.ImageSharp.PixelFormats
Rgba32[] constants = ColorConstants.WebSafeColors;
var safe = new TPixel[constants.Length + 1];
- Span constantsBytes = constants.AsSpan().NonPortableCast();
+ Span constantsBytes = MemoryMarshal.Cast(constants.AsSpan());
PixelOperations.Instance.PackFromRgba32Bytes(constantsBytes, safe, constants.Length);
return safe;
}
diff --git a/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs b/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs
index beb0bd3ab..b1eba3275 100644
--- a/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs
+++ b/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs
@@ -131,8 +131,8 @@ namespace SixLabors.ImageSharp.PixelFormats
if (alignedCount > 0)
{
- ReadOnlySpan flatSrc = sourceVectors.Slice(0, alignedCount).NonPortableCast();
- Span flatDest = destColors.NonPortableCast();
+ ReadOnlySpan flatSrc = MemoryMarshal.Cast(sourceVectors.Slice(0, alignedCount));
+ Span flatDest = MemoryMarshal.Cast(destColors);
SimdUtils.BulkConvertNormalizedFloatToByteClampOverflows(flatSrc, flatDest);
}
diff --git a/src/ImageSharp/PixelFormats/RgbaVector.PixelOperations.cs b/src/ImageSharp/PixelFormats/RgbaVector.PixelOperations.cs
index 6a9f38d7f..ce40665cd 100644
--- a/src/ImageSharp/PixelFormats/RgbaVector.PixelOperations.cs
+++ b/src/ImageSharp/PixelFormats/RgbaVector.PixelOperations.cs
@@ -3,6 +3,7 @@
using System;
using System.Numerics;
+using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.PixelFormats
{
@@ -21,7 +22,7 @@ namespace SixLabors.ImageSharp.PixelFormats
{
GuardSpans(sourceColors, nameof(sourceColors), destVectors, nameof(destVectors), count);
- sourceColors.NonPortableCast().Slice(0, count).CopyTo(destVectors);
+ MemoryMarshal.Cast(sourceColors).Slice(0, count).CopyTo(destVectors);
}
}
}
diff --git a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj
index 6dcfbaf81..6a723f928 100644
--- a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj
+++ b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj
@@ -5,6 +5,7 @@
True
SixLabors.ImageSharp.Benchmarks
ImageSharp.Benchmarks
+ 7.2
win7-x64
@@ -18,8 +19,8 @@
-
-
+
+
diff --git a/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj b/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj
index 7d56686eb..3cbe2071d 100644
--- a/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj
+++ b/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj
@@ -11,6 +11,7 @@
James Jackson-South and contributors
James Jackson-South
SixLabors.ImageSharp.Sandbox46
+ 7.2
@@ -20,6 +21,7 @@
+
diff --git a/tests/ImageSharp.Tests/Common/SimdUtilsTests.cs b/tests/ImageSharp.Tests/Common/SimdUtilsTests.cs
index 8014925e2..d16c053cd 100644
--- a/tests/ImageSharp.Tests/Common/SimdUtilsTests.cs
+++ b/tests/ImageSharp.Tests/Common/SimdUtilsTests.cs
@@ -7,7 +7,7 @@ namespace SixLabors.ImageSharp.Tests.Common
{
using System.Linq;
using System.Runtime.CompilerServices;
-
+ using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Common.Tuples;
using Xunit.Abstractions;
@@ -238,14 +238,14 @@ namespace SixLabors.ImageSharp.Tests.Common
private void MagicConvert(Span source, Span dest)
{
- Vector magick = new Vector(32768.0f);
+ var magick = new Vector(32768.0f);
Vector scale = new Vector(255f) / new Vector(256f);
- Vector x = source.NonPortableCast>()[0];
+ Vector x = MemoryMarshal.Cast>(source)[0];
x = (x * scale) + magick;
- Tuple8.OfUInt32 ii = default(Tuple8.OfUInt32);
+ Tuple8.OfUInt32 ii = default;
ref Vector iiRef = ref Unsafe.As>(ref ii);
@@ -253,7 +253,7 @@ namespace SixLabors.ImageSharp.Tests.Common
//Tuple8.OfUInt32 ii = Unsafe.As, Tuple8.OfUInt32>(ref x);
- ref Tuple8.OfByte d = ref dest.NonPortableCast()[0];
+ ref Tuple8.OfByte d = ref MemoryMarshal.Cast(dest)[0];
d.LoadFrom(ref ii);
this.Output.WriteLine(ii.ToString());
diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.cs
index 587511020..5b9c77f32 100644
--- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.cs
+++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.cs
@@ -1,11 +1,11 @@
+using System;
+using System.Runtime.InteropServices;
+using System.Diagnostics;
+using System.IO;
+using System.Numerics;
+
namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
{
- using System;
- using System.Diagnostics;
- using System.IO;
- using System.Numerics;
- using System.Reflection;
-
using SixLabors.ImageSharp.Formats.Jpeg.Common;
///
@@ -39,7 +39,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
totalDiff += diff;
}
}
-
+
int count = w * h;
double total = (double)totalDiff;
double average = (double)totalDiff / (count * Block8x8.Size);
@@ -85,22 +85,22 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
try
{
RunDumpJpegCoeffsTool(testFile.FullPath, coeffFileFullPath);
-
+
using (var dumpStream = new FileStream(coeffFileFullPath, FileMode.Open))
using (var rdr = new BinaryReader(dumpStream))
{
int componentCount = rdr.ReadInt16();
- ComponentData[] result = new ComponentData[componentCount];
+ var result = new ComponentData[componentCount];
for (int i = 0; i < componentCount; i++)
{
int widthInBlocks = rdr.ReadInt16();
int heightInBlocks = rdr.ReadInt16();
- ComponentData resultComponent = new ComponentData(widthInBlocks, heightInBlocks, i);
+ var resultComponent = new ComponentData(widthInBlocks, heightInBlocks, i);
result[i] = resultComponent;
}
- byte[] buffer = new byte[64*sizeof(short)];
+ byte[] buffer = new byte[64 * sizeof(short)];
for (int i = 0; i < result.Length; i++)
{
@@ -112,7 +112,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
{
rdr.Read(buffer, 0, buffer.Length);
- short[] block = buffer.AsSpan().NonPortableCast().ToArray();
+ short[] block = MemoryMarshal.Cast(buffer.AsSpan()).ToArray();
c.MakeBlock(block, y, x);
}
}
diff --git a/tests/ImageSharp.Tests/Image/ImageFramesCollectionTests.cs b/tests/ImageSharp.Tests/Image/ImageFramesCollectionTests.cs
index 987805ca1..4f00931de 100644
--- a/tests/ImageSharp.Tests/Image/ImageFramesCollectionTests.cs
+++ b/tests/ImageSharp.Tests/Image/ImageFramesCollectionTests.cs
@@ -39,7 +39,6 @@ namespace SixLabors.ImageSharp.Tests
[Fact]
public void AddNewFrame_Frame_FramesNotBeNull()
{
-
ArgumentNullException ex = Assert.Throws(() =>
{
this.collection.AddFrame((ImageFrame)null);
@@ -49,12 +48,13 @@ namespace SixLabors.ImageSharp.Tests
}
[Fact]
- public void AddNewFrame_PixelBuffer_FramesNotBeNull()
+ public void AddNewFrame_PixelBuffer_DataMustNotBeNull()
{
+ Rgba32[] data = null;
ArgumentNullException ex = Assert.Throws(() =>
{
- this.collection.AddFrame((Rgba32[])null);
+ this.collection.AddFrame(data);
});
Assert.StartsWith("Value cannot be null.", ex.Message);
@@ -63,7 +63,6 @@ namespace SixLabors.ImageSharp.Tests
[Fact]
public void AddNewFrame_PixelBuffer_BufferIncorrectSize()
{
-
ArgumentOutOfRangeException ex = Assert.Throws(() =>
{
this.collection.AddFrame(new Rgba32[0]);
@@ -75,7 +74,6 @@ namespace SixLabors.ImageSharp.Tests
[Fact]
public void InsertNewFrame_FramesMustHaveSameSize()
{
-
ArgumentException ex = Assert.Throws(() =>
{
this.collection.InsertFrame(1, new ImageFrame(Configuration.Default.MemoryManager, 1, 1));
@@ -87,7 +85,6 @@ namespace SixLabors.ImageSharp.Tests
[Fact]
public void InsertNewFrame_FramesNotBeNull()
{
-
ArgumentNullException ex = Assert.Throws(() =>
{
this.collection.InsertFrame(1, null);
@@ -99,7 +96,6 @@ namespace SixLabors.ImageSharp.Tests
[Fact]
public void Constructor_FramesMustHaveSameSize()
{
-
ArgumentException ex = Assert.Throws(() =>
{
var collection = new ImageFrameCollection(this.image, new[] {
@@ -198,7 +194,7 @@ namespace SixLabors.ImageSharp.Tests
{
using (Image img = provider.GetImage())
{
- img.Frames.AddFrame(new ImageFrame(Configuration.Default.MemoryManager,10, 10));// add a frame anyway
+ img.Frames.AddFrame(new ImageFrame(Configuration.Default.MemoryManager, 10, 10));// add a frame anyway
using (Image cloned = img.Frames.CloneFrame(0))
{
Assert.Equal(2, img.Frames.Count);
@@ -216,7 +212,7 @@ namespace SixLabors.ImageSharp.Tests
{
var sourcePixelData = img.GetPixelSpan().ToArray();
- img.Frames.AddFrame(new ImageFrame(Configuration.Default.MemoryManager,10, 10));
+ img.Frames.AddFrame(new ImageFrame(Configuration.Default.MemoryManager, 10, 10));
using (Image cloned = img.Frames.ExportFrame(0))
{
Assert.Equal(1, img.Frames.Count);
@@ -244,7 +240,7 @@ namespace SixLabors.ImageSharp.Tests
public void AddFrame_clones_sourceFrame()
{
var pixelData = this.image.Frames.RootFrame.GetPixelSpan().ToArray();
- var otherFRame = new ImageFrame(Configuration.Default.MemoryManager,10, 10);
+ var otherFRame = new ImageFrame(Configuration.Default.MemoryManager, 10, 10);
var addedFrame = this.image.Frames.AddFrame(otherFRame);
addedFrame.ComparePixelBufferTo(otherFRame.GetPixelSpan());
Assert.NotEqual(otherFRame, addedFrame);
@@ -254,7 +250,7 @@ namespace SixLabors.ImageSharp.Tests
public void InsertFrame_clones_sourceFrame()
{
var pixelData = this.image.Frames.RootFrame.GetPixelSpan().ToArray();
- var otherFRame = new ImageFrame(Configuration.Default.MemoryManager,10, 10);
+ var otherFRame = new ImageFrame(Configuration.Default.MemoryManager, 10, 10);
var addedFrame = this.image.Frames.InsertFrame(0, otherFRame);
addedFrame.ComparePixelBufferTo(otherFRame.GetPixelSpan());
Assert.NotEqual(otherFRame, addedFrame);
@@ -308,7 +304,7 @@ namespace SixLabors.ImageSharp.Tests
this.image.Frames.CreateFrame();
}
- var frame = new ImageFrame(Configuration.Default.MemoryManager,10, 10);
+ var frame = new ImageFrame(Configuration.Default.MemoryManager, 10, 10);
Assert.False(this.image.Frames.Contains(frame));
}
diff --git a/tests/ImageSharp.Tests/Image/ImageSaveTests.cs b/tests/ImageSharp.Tests/Image/ImageSaveTests.cs
index 028313e63..857ecb1d0 100644
--- a/tests/ImageSharp.Tests/Image/ImageSaveTests.cs
+++ b/tests/ImageSharp.Tests/Image/ImageSaveTests.cs
@@ -14,6 +14,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests
{
using System.Runtime.CompilerServices;
+ using System.Runtime.InteropServices;
///
/// Tests the class.
@@ -54,7 +55,7 @@ namespace SixLabors.ImageSharp.Tests
{
using (Image image = provider.GetImage())
{
- TPixel[] buffer = new TPixel[image.Width * image.Height];
+ var buffer = new TPixel[image.Width * image.Height];
image.SavePixelData(buffer);
image.ComparePixelBufferTo(buffer);
@@ -74,7 +75,7 @@ namespace SixLabors.ImageSharp.Tests
image.SavePixelData(buffer);
- image.ComparePixelBufferTo(buffer.AsSpan().NonPortableCast());
+ image.ComparePixelBufferTo(MemoryMarshal.Cast(buffer.AsSpan()));
}
}
diff --git a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj
index 8eb88ed32..765d9b32e 100644
--- a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj
+++ b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj
@@ -2,6 +2,7 @@
net471;netcoreapp2.0;net462;net47
True
+ 7.2
full
portable
True
@@ -26,8 +27,8 @@
-
-
+
+
diff --git a/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs b/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs
index 82163d2bb..d092df45a 100644
--- a/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs
+++ b/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs
@@ -33,11 +33,11 @@ namespace SixLabors.ImageSharp.Tests.Memory
{
internal override IBuffer Allocate(int length, bool clear)
{
- T[] array = new T[length + 42];
+ var array = new T[length + 42];
if (!clear)
{
- Span data = array.AsSpan().NonPortableCast();
+ Span data = MemoryMarshal.Cast(array.AsSpan());
for (int i = 0; i < data.Length; i++)
{
data[i] = 42;
diff --git a/tests/ImageSharp.Tests/Memory/SpanUtilityTests.cs b/tests/ImageSharp.Tests/Memory/SpanUtilityTests.cs
index 908830fb7..08f7a93b9 100644
--- a/tests/ImageSharp.Tests/Memory/SpanUtilityTests.cs
+++ b/tests/ImageSharp.Tests/Memory/SpanUtilityTests.cs
@@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
-
+ using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Tests.Common;
@@ -84,7 +84,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
public void GenericToOwnType_Aligned(int count)
{
TestStructs.AlignedFoo[] source = TestStructs.AlignedFoo.CreateArray(count + 2);
- TestStructs.AlignedFoo[] dest = new TestStructs.AlignedFoo[count + 5];
+ var dest = new TestStructs.AlignedFoo[count + 5];
var apSource = new Span(source, 1, source.Length - 1);
var apDest = new Span(dest, 1, dest.Length - 1);
@@ -136,7 +136,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
var apSource = new Span(source, 1, source.Length - 1);
var apDest = new Span(dest, sizeof(TestStructs.Foo), dest.Length - sizeof(TestStructs.Foo));
- apSource.AsBytes().Slice(0, (count - 1) * sizeof(TestStructs.Foo)).CopyTo(apDest);
+ MemoryMarshal.AsBytes(apSource).Slice(0, (count - 1) * sizeof(TestStructs.Foo)).CopyTo(apDest);
AssertNotDefault(source, 1);
@@ -159,7 +159,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
var apSource = new Span(source, 1, source.Length - 1);
var apDest = new Span(dest, sizeof(TestStructs.AlignedFoo), dest.Length - sizeof(TestStructs.AlignedFoo));
- apSource.AsBytes().Slice(0, (count - 1) * sizeof(TestStructs.AlignedFoo)).CopyTo(apDest);
+ MemoryMarshal.AsBytes(apSource).Slice(0, (count - 1) * sizeof(TestStructs.AlignedFoo)).CopyTo(apDest);
AssertNotDefault(source, 1);
@@ -182,7 +182,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
var apSource = new Span(source);
var apDest = new Span(dest);
- apSource.AsBytes().Slice(0, count * sizeof(int)).CopyTo(apDest);
+ MemoryMarshal.AsBytes(apSource).Slice(0, count * sizeof(int)).CopyTo(apDest);
AssertNotDefault(source, 1);
@@ -203,7 +203,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
var apSource = new Span(source);
var apDest = new Span(dest);
- apSource.Slice(0, count * sizeof(TestStructs.Foo)).CopyTo(apDest.AsBytes());
+ apSource.Slice(0, count * sizeof(TestStructs.Foo)).CopyTo(MemoryMarshal.AsBytes(apDest));
AssertNotDefault(source, sizeof(TestStructs.Foo) + 1);
AssertNotDefault(dest, 1);
diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs
index 4e9a4ea69..4ea179d09 100644
--- a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs
@@ -3,6 +3,7 @@
using System;
using System.Numerics;
+using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using Xunit;
@@ -412,8 +413,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
if (typeof(TDest) == typeof(Vector4))
{
- Span expected = this.ExpectedDestBuffer.AsSpan().NonPortableCast();
- Span actual = this.ActualDestBuffer.Span.NonPortableCast();
+ Span expected = MemoryMarshal.Cast(this.ExpectedDestBuffer.AsSpan());
+ Span actual = MemoryMarshal.Cast(this.ActualDestBuffer.Span);
for (int i = 0; i < count; i++)
{