diff --git a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs
index 612ced5d8..24d2dd4cc 100644
--- a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs
+++ b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs
@@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0.
using System;
+using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
@@ -148,6 +149,6 @@ namespace SixLabors.ImageSharp.Advanced
/// A reference to the element.
private static ref TPixel DangerousGetPinnableReferenceToPixelBuffer(IPixelSource source)
where TPixel : struct, IPixel
- => ref source.PixelBuffer.Span.DangerousGetPinnableReference();
+ => ref MemoryMarshal.GetReference(source.PixelBuffer.Span);
}
}
diff --git a/src/ImageSharp/ColorSpaces/CieLab.cs b/src/ImageSharp/ColorSpaces/CieLab.cs
index 107be4cb2..cb08d08bf 100644
--- a/src/ImageSharp/ColorSpaces/CieLab.cs
+++ b/src/ImageSharp/ColorSpaces/CieLab.cs
@@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// Represents a CIE L*a*b* 1976 color.
///
///
- internal struct CieLab : IColorVector, IEquatable, IAlmostEquatable
+ internal readonly struct CieLab : IColorVector, IEquatable, IAlmostEquatable
{
///
/// D50 standard illuminant.
diff --git a/src/ImageSharp/ColorSpaces/CieLch.cs b/src/ImageSharp/ColorSpaces/CieLch.cs
index 834ef56a8..94443fd86 100644
--- a/src/ImageSharp/ColorSpaces/CieLch.cs
+++ b/src/ImageSharp/ColorSpaces/CieLch.cs
@@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// Represents the CIE L*C*h°, cylindrical form of the CIE L*a*b* 1976 color.
///
///
- internal struct CieLch : IColorVector, IEquatable, IAlmostEquatable
+ internal readonly struct CieLch : IColorVector, IEquatable, IAlmostEquatable
{
///
/// D50 standard illuminant.
diff --git a/src/ImageSharp/ColorSpaces/CieLchuv.cs b/src/ImageSharp/ColorSpaces/CieLchuv.cs
index f35914d64..705b770d3 100644
--- a/src/ImageSharp/ColorSpaces/CieLchuv.cs
+++ b/src/ImageSharp/ColorSpaces/CieLchuv.cs
@@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// Represents the CIE L*C*h°, cylindrical form of the CIE L*u*v* 1976 color.
///
///
- internal struct CieLchuv : IColorVector, IEquatable, IAlmostEquatable
+ internal readonly struct CieLchuv : IColorVector, IEquatable, IAlmostEquatable
{
///
/// D50 standard illuminant.
diff --git a/src/ImageSharp/ColorSpaces/CieLuv.cs b/src/ImageSharp/ColorSpaces/CieLuv.cs
index 9b5251708..b0ae048ab 100644
--- a/src/ImageSharp/ColorSpaces/CieLuv.cs
+++ b/src/ImageSharp/ColorSpaces/CieLuv.cs
@@ -14,7 +14,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// attempted perceptual uniformity
///
///
- internal struct CieLuv : IColorVector, IEquatable, IAlmostEquatable
+ internal readonly struct CieLuv : IColorVector, IEquatable, IAlmostEquatable
{
///
/// D65 standard illuminant.
diff --git a/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs b/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs
index 487f464d8..d0a70dd19 100644
--- a/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs
+++ b/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs
@@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
///
/// Represents the coordinates of CIEXY chromaticity space
///
- internal struct CieXyChromaticityCoordinates : IEquatable, IAlmostEquatable
+ internal readonly struct CieXyChromaticityCoordinates : IEquatable, IAlmostEquatable
{
///
/// Represents a that has X, Y values set to zero.
diff --git a/src/ImageSharp/ColorSpaces/CieXyy.cs b/src/ImageSharp/ColorSpaces/CieXyy.cs
index d5ef4b15d..751830a0b 100644
--- a/src/ImageSharp/ColorSpaces/CieXyy.cs
+++ b/src/ImageSharp/ColorSpaces/CieXyy.cs
@@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// Represents an CIE xyY 1931 color
///
///
- internal struct CieXyy : IColorVector, IEquatable, IAlmostEquatable
+ internal readonly struct CieXyy : IColorVector, IEquatable, IAlmostEquatable
{
///
/// Represents a that has X, Y, and Y values set to zero.
diff --git a/src/ImageSharp/ColorSpaces/CieXyz.cs b/src/ImageSharp/ColorSpaces/CieXyz.cs
index 908408000..0f1866009 100644
--- a/src/ImageSharp/ColorSpaces/CieXyz.cs
+++ b/src/ImageSharp/ColorSpaces/CieXyz.cs
@@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// Represents an CIE XYZ 1931 color
///
///
- internal struct CieXyz : IColorVector, IEquatable, IAlmostEquatable
+ internal readonly struct CieXyz : IColorVector, IEquatable, IAlmostEquatable
{
///
/// Represents a that has X, Y, and Z values set to zero.
diff --git a/src/ImageSharp/ColorSpaces/Cmyk.cs b/src/ImageSharp/ColorSpaces/Cmyk.cs
index 2a58a5762..2eb148a8c 100644
--- a/src/ImageSharp/ColorSpaces/Cmyk.cs
+++ b/src/ImageSharp/ColorSpaces/Cmyk.cs
@@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
///
/// Represents an CMYK (cyan, magenta, yellow, keyline) color.
///
- internal struct Cmyk : IEquatable, IAlmostEquatable
+ internal readonly struct Cmyk : IEquatable, IAlmostEquatable
{
///
/// Represents a that has C, M, Y, and K values set to zero.
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbWorkingSpace.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbWorkingSpace.cs
index 8a2c66a80..5a5c39647 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbWorkingSpace.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbWorkingSpace.cs
@@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSap
///
/// Trivial implementation of
///
- internal struct RgbWorkingSpace : IRgbWorkingSpace
+ internal readonly struct RgbWorkingSpace : IRgbWorkingSpace
{
///
/// Initializes a new instance of the struct.
diff --git a/src/ImageSharp/ColorSpaces/Hsl.cs b/src/ImageSharp/ColorSpaces/Hsl.cs
index cf880f154..1944ac0c6 100644
--- a/src/ImageSharp/ColorSpaces/Hsl.cs
+++ b/src/ImageSharp/ColorSpaces/Hsl.cs
@@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
///
/// Represents a Hsl (hue, saturation, lightness) color.
///
- internal struct Hsl : IColorVector, IEquatable, IAlmostEquatable
+ internal readonly struct Hsl : IColorVector, IEquatable, IAlmostEquatable
{
///
/// Represents a that has H, S, and L values set to zero.
diff --git a/src/ImageSharp/ColorSpaces/Hsv.cs b/src/ImageSharp/ColorSpaces/Hsv.cs
index 9f4739379..45ffd7f12 100644
--- a/src/ImageSharp/ColorSpaces/Hsv.cs
+++ b/src/ImageSharp/ColorSpaces/Hsv.cs
@@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
///
/// Represents a HSV (hue, saturation, value) color. Also known as HSB (hue, saturation, brightness).
///
- internal struct Hsv : IColorVector, IEquatable, IAlmostEquatable
+ internal readonly struct Hsv : IColorVector, IEquatable, IAlmostEquatable
{
///
/// Represents a that has H, S, and V values set to zero.
diff --git a/src/ImageSharp/ColorSpaces/HunterLab.cs b/src/ImageSharp/ColorSpaces/HunterLab.cs
index b5ba7c86c..de42518d7 100644
--- a/src/ImageSharp/ColorSpaces/HunterLab.cs
+++ b/src/ImageSharp/ColorSpaces/HunterLab.cs
@@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// Represents an Hunter LAB color.
///
///
- internal struct HunterLab : IColorVector, IEquatable, IAlmostEquatable
+ internal readonly struct HunterLab : IColorVector, IEquatable, IAlmostEquatable
{
///
/// D50 standard illuminant.
diff --git a/src/ImageSharp/ColorSpaces/LinearRgb.cs b/src/ImageSharp/ColorSpaces/LinearRgb.cs
index 07889c352..b8c446285 100644
--- a/src/ImageSharp/ColorSpaces/LinearRgb.cs
+++ b/src/ImageSharp/ColorSpaces/LinearRgb.cs
@@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
///
/// Represents an linear Rgb color with specified working space
///
- internal struct LinearRgb : IColorVector, IEquatable, IAlmostEquatable
+ internal readonly struct LinearRgb : IColorVector, IEquatable, IAlmostEquatable
{
///
/// Represents a that has R, G, and B values set to zero.
diff --git a/src/ImageSharp/ColorSpaces/Lms.cs b/src/ImageSharp/ColorSpaces/Lms.cs
index 82c291de3..72ac16f21 100644
--- a/src/ImageSharp/ColorSpaces/Lms.cs
+++ b/src/ImageSharp/ColorSpaces/Lms.cs
@@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// named after their responsivity (sensitivity) at long, medium and short wavelengths.
///
///
- internal struct Lms : IColorVector, IEquatable, IAlmostEquatable
+ internal readonly struct Lms : IColorVector, IEquatable, IAlmostEquatable
{
///
/// Represents a that has L, M, and S values set to zero.
diff --git a/src/ImageSharp/ColorSpaces/Rgb.cs b/src/ImageSharp/ColorSpaces/Rgb.cs
index 8ac8411b2..53fa6086d 100644
--- a/src/ImageSharp/ColorSpaces/Rgb.cs
+++ b/src/ImageSharp/ColorSpaces/Rgb.cs
@@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
///
/// Represents an RGB color with specified working space
///
- internal struct Rgb : IColorVector, IEquatable, IAlmostEquatable
+ internal readonly struct Rgb : IColorVector, IEquatable, IAlmostEquatable
{
///
/// Represents a that has R, G, and B values set to zero.
diff --git a/src/ImageSharp/ColorSpaces/YCbCr.cs b/src/ImageSharp/ColorSpaces/YCbCr.cs
index 708a74308..44a0b245d 100644
--- a/src/ImageSharp/ColorSpaces/YCbCr.cs
+++ b/src/ImageSharp/ColorSpaces/YCbCr.cs
@@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
///
///
///
- internal struct YCbCr : IColorVector, IEquatable, IAlmostEquatable
+ internal readonly struct YCbCr : IColorVector, IEquatable, IAlmostEquatable
{
///
/// Represents a that has Y, Cb, and Cr values set to zero.
diff --git a/src/ImageSharp/Common/Extensions/SimdUtils.cs b/src/ImageSharp/Common/Extensions/SimdUtils.cs
index 7f46b7a84..7b77fefca 100644
--- a/src/ImageSharp/Common/Extensions/SimdUtils.cs
+++ b/src/ImageSharp/Common/Extensions/SimdUtils.cs
@@ -76,8 +76,8 @@ namespace SixLabors.ImageSharp
return;
}
- ref Vector srcBase = ref Unsafe.As>(ref source.DangerousGetPinnableReference());
- ref Octet.OfByte destBase = ref Unsafe.As(ref dest.DangerousGetPinnableReference());
+ ref Vector srcBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source));
+ ref Octet.OfByte destBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest));
int n = source.Length / 8;
Vector magick = new Vector(32768.0f);
@@ -117,8 +117,8 @@ namespace SixLabors.ImageSharp
return;
}
- ref Vector srcBase = ref Unsafe.As>(ref source.DangerousGetPinnableReference());
- ref Octet.OfByte destBase = ref Unsafe.As(ref dest.DangerousGetPinnableReference());
+ ref Vector srcBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source));
+ ref Octet.OfByte destBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest));
int n = source.Length / 8;
Vector magick = new Vector(32768.0f);
diff --git a/src/ImageSharp/Formats/Gif/PackedField.cs b/src/ImageSharp/Formats/Gif/PackedField.cs
index 962e2082b..28a415e2b 100644
--- a/src/ImageSharp/Formats/Gif/PackedField.cs
+++ b/src/ImageSharp/Formats/Gif/PackedField.cs
@@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// Represents a byte of data in a GIF data stream which contains a number
/// of data items.
///
- internal struct PackedField : IEquatable
+ internal readonly struct PackedField : IEquatable
{
///
/// The individual bits representing the packed byte.
diff --git a/src/ImageSharp/Formats/Jpeg/Common/Block8x8.cs b/src/ImageSharp/Formats/Jpeg/Common/Block8x8.cs
index 1066cfa80..11a456ef9 100644
--- a/src/ImageSharp/Formats/Jpeg/Common/Block8x8.cs
+++ b/src/ImageSharp/Formats/Jpeg/Common/Block8x8.cs
@@ -4,6 +4,7 @@
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
using System.Text;
namespace SixLabors.ImageSharp.Formats.Jpeg.Common
@@ -34,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 coefficients.NonPortableCast().DangerousGetPinnableReference();
+ ref byte sourceRef = ref MemoryMarshal.GetReference(coefficients.NonPortableCast());
Unsafe.CopyBlock(ref selfRef, ref sourceRef, Size * sizeof(short));
}
@@ -204,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 destination.NonPortableCast().DangerousGetPinnableReference();
+ ref byte destRef = ref MemoryMarshal.GetReference(destination.NonPortableCast());
Unsafe.CopyBlock(ref destRef, ref selfRef, Size * sizeof(short));
}
diff --git a/src/ImageSharp/Formats/Jpeg/Common/Block8x8F.cs b/src/ImageSharp/Formats/Jpeg/Common/Block8x8F.cs
index 2dd42288c..f45b5df4e 100644
--- a/src/ImageSharp/Formats/Jpeg/Common/Block8x8F.cs
+++ b/src/ImageSharp/Formats/Jpeg/Common/Block8x8F.cs
@@ -163,7 +163,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void LoadFrom(Span source)
{
- ref byte s = ref Unsafe.As(ref source.DangerousGetPinnableReference());
+ ref byte s = ref Unsafe.As(ref MemoryMarshal.GetReference(source));
ref byte d = ref Unsafe.As(ref this);
Unsafe.CopyBlock(ref d, ref s, Size * sizeof(float));
@@ -203,7 +203,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void CopyTo(Span dest)
{
- ref byte d = ref Unsafe.As(ref dest.DangerousGetPinnableReference());
+ ref byte d = ref Unsafe.As(ref MemoryMarshal.GetReference(dest));
ref byte s = ref Unsafe.As(ref this);
Unsafe.CopyBlock(ref d, ref s, Size * sizeof(float));
diff --git a/src/ImageSharp/Formats/Jpeg/Common/Decoder/AdobeMarker.cs b/src/ImageSharp/Formats/Jpeg/Common/Decoder/AdobeMarker.cs
index 0ec2297d7..d55e36bd4 100644
--- a/src/ImageSharp/Formats/Jpeg/Common/Decoder/AdobeMarker.cs
+++ b/src/ImageSharp/Formats/Jpeg/Common/Decoder/AdobeMarker.cs
@@ -10,7 +10,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder
/// Provides information about the Adobe marker segment.
///
/// See the included 5116.DCT.pdf file in the source for more information.
- internal struct AdobeMarker : IEquatable
+ internal readonly struct AdobeMarker : IEquatable
{
///
/// Gets the length of an adobe marker segment.
diff --git a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimd.cs b/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimd.cs
index a7fc136af..2f214f88a 100644
--- a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimd.cs
+++ b/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimd.cs
@@ -4,6 +4,7 @@
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Common.Tuples;
namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder.ColorConverters
@@ -37,14 +38,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder.ColorConverters
DebugGuard.IsTrue(result.Length % 8 == 0, nameof(result), "result.Length should be divisable by 8!");
ref Vector4Pair yBase =
- ref Unsafe.As(ref values.Component0.DangerousGetPinnableReference());
+ ref Unsafe.As(ref MemoryMarshal.GetReference(values.Component0));
ref Vector4Pair cbBase =
- ref Unsafe.As(ref values.Component1.DangerousGetPinnableReference());
+ ref Unsafe.As(ref MemoryMarshal.GetReference(values.Component1));
ref Vector4Pair crBase =
- ref Unsafe.As(ref values.Component2.DangerousGetPinnableReference());
+ ref Unsafe.As(ref MemoryMarshal.GetReference(values.Component2));
ref Vector4Octet resultBase =
- ref Unsafe.As(ref result.DangerousGetPinnableReference());
+ ref Unsafe.As(ref MemoryMarshal.GetReference(result));
var chromaOffset = new Vector4(-128f);
diff --git a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimdAvx2.cs b/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimdAvx2.cs
index 77e74c32b..f8a451422 100644
--- a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimdAvx2.cs
+++ b/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimdAvx2.cs
@@ -4,6 +4,7 @@
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Common.Tuples;
// ReSharper disable ImpureMethodCallOnReadonlyValueField
@@ -46,14 +47,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder.ColorConverters
}
ref Vector yBase =
- ref Unsafe.As>(ref values.Component0.DangerousGetPinnableReference());
+ ref Unsafe.As>(ref MemoryMarshal.GetReference(values.Component0));
ref Vector cbBase =
- ref Unsafe.As>(ref values.Component1.DangerousGetPinnableReference());
+ ref Unsafe.As>(ref MemoryMarshal.GetReference(values.Component1));
ref Vector crBase =
- ref Unsafe.As>(ref values.Component2.DangerousGetPinnableReference());
+ ref Unsafe.As>(ref MemoryMarshal.GetReference(values.Component2));
ref Vector4Octet resultBase =
- ref Unsafe.As(ref result.DangerousGetPinnableReference());
+ ref Unsafe.As(ref MemoryMarshal.GetReference(result));
var chromaOffset = new Vector(-128f);
diff --git a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.cs b/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.cs
index e0abc3215..187b65f72 100644
--- a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.cs
+++ b/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.cs
@@ -66,7 +66,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder.ColorConverters
///
/// A stack-only struct to reference the input buffers using -s.
///
- public struct ComponentValues
+#pragma warning disable SA1206 // Declaration keywords should follow order
+ public readonly ref struct ComponentValues
+#pragma warning restore SA1206 // Declaration keywords should follow order
{
///
/// The component count
diff --git a/src/ImageSharp/Formats/Jpeg/Common/Decoder/JFifMarker.cs b/src/ImageSharp/Formats/Jpeg/Common/Decoder/JFifMarker.cs
index cba7be553..c856fd04a 100644
--- a/src/ImageSharp/Formats/Jpeg/Common/Decoder/JFifMarker.cs
+++ b/src/ImageSharp/Formats/Jpeg/Common/Decoder/JFifMarker.cs
@@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder
/// Provides information about the JFIF marker segment
/// TODO: Thumbnail?
///
- internal struct JFifMarker : IEquatable
+ internal readonly struct JFifMarker : IEquatable
{
///
/// Gets the length of an JFIF marker segment.
diff --git a/src/ImageSharp/Formats/Jpeg/Common/GenericBlock8x8.cs b/src/ImageSharp/Formats/Jpeg/Common/GenericBlock8x8.cs
index e20e850d7..09a7eb73a 100644
--- a/src/ImageSharp/Formats/Jpeg/Common/GenericBlock8x8.cs
+++ b/src/ImageSharp/Formats/Jpeg/Common/GenericBlock8x8.cs
@@ -85,7 +85,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common
ref byte blockStart = ref Unsafe.As, byte>(ref this);
ref byte imageStart = ref Unsafe.As(
- ref Unsafe.Add(ref source.GetRowSpan(sourceY).DangerousGetPinnableReference(), sourceX));
+ ref Unsafe.Add(ref MemoryMarshal.GetReference(source.GetRowSpan(sourceY)), sourceX));
int blockRowSizeInBytes = 8 * Unsafe.SizeOf();
int imageRowSizeInBytes = source.Width * Unsafe.SizeOf();
diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/InputProcessor.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/InputProcessor.cs
index 88599808f..fd6a7833a 100644
--- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/InputProcessor.cs
+++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/InputProcessor.cs
@@ -5,8 +5,6 @@ using System;
using System.IO;
using System.Runtime.CompilerServices;
-using SixLabors.ImageSharp.Memory;
-
namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
{
///
diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffmanLut.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffmanLut.cs
index 2fb01c5c8..7756a7e3b 100644
--- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffmanLut.cs
+++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffmanLut.cs
@@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Encoder
/// codeword size in bits and the 24 least significant bits hold the codeword.
/// The maximum codeword size is 16 bits.
///
- internal struct HuffmanLut
+ internal readonly struct HuffmanLut
{
///
/// The compiled representations of theHuffmanSpec.
diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffmanSpec.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffmanSpec.cs
index 8e40cb368..1c8228aaa 100644
--- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffmanSpec.cs
+++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffmanSpec.cs
@@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Encoder
///
/// The Huffman encoding specifications.
///
- internal struct HuffmanSpec
+ internal readonly struct HuffmanSpec
{
#pragma warning disable SA1118 // ParameterMustNotSpanMultipleLines
diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsYCbCrToRgbTables.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsYCbCrToRgbTables.cs
index ddc577270..203a7b1eb 100644
--- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsYCbCrToRgbTables.cs
+++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsYCbCrToRgbTables.cs
@@ -10,7 +10,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
/// Provides 8-bit lookup tables for converting from YCbCr to Rgb colorspace.
/// Methods to build the tables are based on libjpeg implementation.
///
- internal struct PdfJsYCbCrToRgbTables
+ internal readonly struct PdfJsYCbCrToRgbTables
{
///
/// The red red-chrominance table
diff --git a/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs b/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs
index 0d3a65dbd..de62d4702 100644
--- a/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs
+++ b/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs
@@ -3,6 +3,7 @@
using System;
using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.Formats.Png.Filters
{
@@ -24,8 +25,8 @@ namespace SixLabors.ImageSharp.Formats.Png.Filters
{
DebugGuard.MustBeSameSized(scanline, previousScanline, nameof(scanline));
- ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference();
- ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference();
+ ref byte scanBaseRef = ref MemoryMarshal.GetReference(scanline);
+ ref byte prevBaseRef = ref MemoryMarshal.GetReference(previousScanline);
// Average(x) + floor((Raw(x-bpp)+Prior(x))/2)
for (int x = 1; x < scanline.Length; x++)
@@ -60,9 +61,9 @@ namespace SixLabors.ImageSharp.Formats.Png.Filters
DebugGuard.MustBeSameSized(scanline, previousScanline, nameof(scanline));
DebugGuard.MustBeSizedAtLeast(result, scanline, nameof(result));
- ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference();
- ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference();
- ref byte resultBaseRef = ref result.DangerousGetPinnableReference();
+ ref byte scanBaseRef = ref MemoryMarshal.GetReference(scanline);
+ ref byte prevBaseRef = ref MemoryMarshal.GetReference(previousScanline);
+ ref byte resultBaseRef = ref MemoryMarshal.GetReference(result);
sum = 0;
// Average(x) = Raw(x) - floor((Raw(x-bpp)+Prior(x))/2)
diff --git a/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs b/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs
index 08e493880..7e05d736f 100644
--- a/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs
+++ b/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs
@@ -3,6 +3,7 @@
using System;
using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.Formats.Png.Filters
{
@@ -25,8 +26,8 @@ namespace SixLabors.ImageSharp.Formats.Png.Filters
{
DebugGuard.MustBeSameSized(scanline, previousScanline, nameof(scanline));
- ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference();
- ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference();
+ ref byte scanBaseRef = ref MemoryMarshal.GetReference(scanline);
+ ref byte prevBaseRef = ref MemoryMarshal.GetReference(previousScanline);
// Paeth(x) + PaethPredictor(Raw(x-bpp), Prior(x), Prior(x-bpp))
int offset = bytesPerPixel + 1;
@@ -61,9 +62,9 @@ namespace SixLabors.ImageSharp.Formats.Png.Filters
DebugGuard.MustBeSameSized(scanline, previousScanline, nameof(scanline));
DebugGuard.MustBeSizedAtLeast(result, scanline, nameof(result));
- ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference();
- ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference();
- ref byte resultBaseRef = ref result.DangerousGetPinnableReference();
+ ref byte scanBaseRef = ref MemoryMarshal.GetReference(scanline);
+ ref byte prevBaseRef = ref MemoryMarshal.GetReference(previousScanline);
+ ref byte resultBaseRef = ref MemoryMarshal.GetReference(result);
sum = 0;
// Paeth(x) = Raw(x) - PaethPredictor(Raw(x-bpp), Prior(x), Prior(x - bpp))
diff --git a/src/ImageSharp/Formats/Png/Filters/SubFilter.cs b/src/ImageSharp/Formats/Png/Filters/SubFilter.cs
index 5ee866440..c0db7da93 100644
--- a/src/ImageSharp/Formats/Png/Filters/SubFilter.cs
+++ b/src/ImageSharp/Formats/Png/Filters/SubFilter.cs
@@ -3,6 +3,7 @@
using System;
using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.Formats.Png.Filters
{
@@ -21,7 +22,7 @@ namespace SixLabors.ImageSharp.Formats.Png.Filters
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Decode(Span scanline, int bytesPerPixel)
{
- ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference();
+ ref byte scanBaseRef = ref MemoryMarshal.GetReference(scanline);
// Sub(x) + Raw(x-bpp)
for (int x = 1; x < scanline.Length; x++)
@@ -52,8 +53,8 @@ namespace SixLabors.ImageSharp.Formats.Png.Filters
{
DebugGuard.MustBeSizedAtLeast(result, scanline, nameof(result));
- ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference();
- ref byte resultBaseRef = ref result.DangerousGetPinnableReference();
+ ref byte scanBaseRef = ref MemoryMarshal.GetReference(scanline);
+ ref byte resultBaseRef = ref MemoryMarshal.GetReference(result);
sum = 0;
// Sub(x) = Raw(x) - Raw(x-bpp)
diff --git a/src/ImageSharp/Formats/Png/Filters/UpFilter.cs b/src/ImageSharp/Formats/Png/Filters/UpFilter.cs
index 6e8f780e5..81c063ea9 100644
--- a/src/ImageSharp/Formats/Png/Filters/UpFilter.cs
+++ b/src/ImageSharp/Formats/Png/Filters/UpFilter.cs
@@ -3,6 +3,7 @@
using System;
using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.Formats.Png.Filters
{
@@ -23,8 +24,8 @@ namespace SixLabors.ImageSharp.Formats.Png.Filters
{
DebugGuard.MustBeSameSized(scanline, previousScanline, nameof(scanline));
- ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference();
- ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference();
+ ref byte scanBaseRef = ref MemoryMarshal.GetReference(scanline);
+ ref byte prevBaseRef = ref MemoryMarshal.GetReference(previousScanline);
// Up(x) + Prior(x)
for (int x = 1; x < scanline.Length; x++)
@@ -48,9 +49,9 @@ namespace SixLabors.ImageSharp.Formats.Png.Filters
DebugGuard.MustBeSameSized(scanline, previousScanline, nameof(scanline));
DebugGuard.MustBeSizedAtLeast(result, scanline, nameof(result));
- ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference();
- ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference();
- ref byte resultBaseRef = ref result.DangerousGetPinnableReference();
+ ref byte scanBaseRef = ref MemoryMarshal.GetReference(scanline);
+ ref byte prevBaseRef = ref MemoryMarshal.GetReference(previousScanline);
+ ref byte resultBaseRef = ref MemoryMarshal.GetReference(result);
sum = 0;
// Up(x) = Raw(x) - Prior(x)
diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs
index fbff0ae1d..c1dccdcaf 100644
--- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs
+++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs
@@ -701,7 +701,7 @@ namespace SixLabors.ImageSharp.Formats.Png
Span rowSpan = pixels.GetPixelRowSpan(this.currentRow);
// Trim the first marker byte from the buffer
- var scanlineBuffer = new Span(defilteredScanline, 1);
+ var scanlineBuffer = new Span(defilteredScanline, 1, defilteredScanline.Length - 1);
switch (this.pngColorType)
{
@@ -932,7 +932,7 @@ namespace SixLabors.ImageSharp.Formats.Png
var color = default(TPixel);
// Trim the first marker byte from the buffer
- var scanlineBuffer = new Span(defilteredScanline, 1);
+ var scanlineBuffer = new Span(defilteredScanline, 1, defilteredScanline.Length - 1);
switch (this.pngColorType)
{
diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj
index cb0539f78..86a0ab7ea 100644
--- a/src/ImageSharp/ImageSharp.csproj
+++ b/src/ImageSharp/ImageSharp.csproj
@@ -29,6 +29,7 @@
portable
True
IOperation
+ 7.2
@@ -40,12 +41,11 @@
All
-
-
+
+
-
diff --git a/src/ImageSharp/Memory/BufferArea{T}.cs b/src/ImageSharp/Memory/BufferArea{T}.cs
index 588eae483..990b494fc 100644
--- a/src/ImageSharp/Memory/BufferArea{T}.cs
+++ b/src/ImageSharp/Memory/BufferArea{T}.cs
@@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Memory
/// This type is kind-of 2D Span, but it can live on heap.
///
/// The element type
- internal struct BufferArea
+ internal readonly struct BufferArea
where T : struct
{
///
diff --git a/src/ImageSharp/Memory/BufferExtensions.cs b/src/ImageSharp/Memory/BufferExtensions.cs
index 919a6ef34..dd3114c21 100644
--- a/src/ImageSharp/Memory/BufferExtensions.cs
+++ b/src/ImageSharp/Memory/BufferExtensions.cs
@@ -4,6 +4,7 @@
using System;
using System.IO;
using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.Memory
{
@@ -53,7 +54,7 @@ namespace SixLabors.ImageSharp.Memory
public static ref T DangerousGetPinnableReference(this IBuffer buffer)
where T : struct =>
- ref buffer.Span.DangerousGetPinnableReference();
+ ref MemoryMarshal.GetReference(buffer.Span);
public static void Read(this Stream stream, IManagedByteBuffer buffer)
{
diff --git a/src/ImageSharp/Memory/SpanHelper.cs b/src/ImageSharp/Memory/SpanHelper.cs
index 73bc5f55d..0c327484a 100644
--- a/src/ImageSharp/Memory/SpanHelper.cs
+++ b/src/ImageSharp/Memory/SpanHelper.cs
@@ -4,6 +4,7 @@
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.Memory
{
@@ -22,7 +23,7 @@ namespace SixLabors.ImageSharp.Memory
public static ref Vector FetchVector(this Span span)
where T : struct
{
- return ref Unsafe.As>(ref span.DangerousGetPinnableReference());
+ return ref Unsafe.As>(ref MemoryMarshal.GetReference(span));
}
///
@@ -39,8 +40,8 @@ namespace SixLabors.ImageSharp.Memory
DebugGuard.MustBeLessThanOrEqualTo(count, source.Length, nameof(count));
DebugGuard.MustBeLessThanOrEqualTo(count, destination.Length, nameof(count));
- ref byte srcRef = ref Unsafe.As(ref source.DangerousGetPinnableReference());
- ref byte destRef = ref Unsafe.As(ref destination.DangerousGetPinnableReference());
+ ref byte srcRef = ref Unsafe.As(ref MemoryMarshal.GetReference(source));
+ ref byte destRef = ref Unsafe.As(ref MemoryMarshal.GetReference(destination));
int byteCount = Unsafe.SizeOf() * count;
diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccColorantTableEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccColorantTableEntry.cs
index 17127110d..c5b005ea0 100644
--- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccColorantTableEntry.cs
+++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccColorantTableEntry.cs
@@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
///
/// Entry of ICC colorant table
///
- internal struct IccColorantTableEntry : IEquatable
+ internal readonly struct IccColorantTableEntry : IEquatable
{
///
/// Initializes a new instance of the struct.
diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccNamedColor.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccNamedColor.cs
index 98107e828..22916c134 100644
--- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccNamedColor.cs
+++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccNamedColor.cs
@@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
///
/// A specific color with a name
///
- internal struct IccNamedColor : IEquatable
+ internal readonly struct IccNamedColor : IEquatable
{
///
/// Initializes a new instance of the struct.
diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccPositionNumber.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccPositionNumber.cs
index 6258ca2f3..d886dc099 100644
--- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccPositionNumber.cs
+++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccPositionNumber.cs
@@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
///
/// Position of an object within an ICC profile
///
- internal struct IccPositionNumber : IEquatable
+ internal readonly struct IccPositionNumber : IEquatable
{
///
/// Initializes a new instance of the struct.
diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileId.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileId.cs
index 1f96540df..4070f835d 100644
--- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileId.cs
+++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileId.cs
@@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
///
/// ICC Profile ID
///
- public struct IccProfileId : IEquatable
+ public readonly struct IccProfileId : IEquatable
{
///
/// A profile ID with all values set to zero
diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccResponseNumber.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccResponseNumber.cs
index a10c55f4e..c786a0fd4 100644
--- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccResponseNumber.cs
+++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccResponseNumber.cs
@@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
///
/// Associates a normalized device code with a measurement value
///
- internal struct IccResponseNumber : IEquatable
+ internal readonly struct IccResponseNumber : IEquatable
{
///
/// Initializes a new instance of the struct.
diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccScreeningChannel.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccScreeningChannel.cs
index f41858f30..e1f1bb32f 100644
--- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccScreeningChannel.cs
+++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccScreeningChannel.cs
@@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
///
/// A single channel of a
///
- internal struct IccScreeningChannel : IEquatable
+ internal readonly struct IccScreeningChannel : IEquatable
{
///
/// Initializes a new instance of the struct.
diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccTagTableEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccTagTableEntry.cs
index 5464de9c5..7cb5c7901 100644
--- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccTagTableEntry.cs
+++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccTagTableEntry.cs
@@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
///
/// Entry of ICC tag table
///
- internal struct IccTagTableEntry : IEquatable
+ internal readonly struct IccTagTableEntry : IEquatable
{
///
/// Initializes a new instance of the struct.
diff --git a/src/ImageSharp/Numerics/ValueSize.cs b/src/ImageSharp/Numerics/ValueSize.cs
index 659e0ebfe..fcf61a586 100644
--- a/src/ImageSharp/Numerics/ValueSize.cs
+++ b/src/ImageSharp/Numerics/ValueSize.cs
@@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp
///
/// Represents a value in relation to a value on the image
///
- internal struct ValueSize : IEquatable
+ internal readonly struct ValueSize : IEquatable
{
///
/// Initializes a new instance of the struct.
diff --git a/src/ImageSharp/PixelFormats/Generated/PixelOperations{TPixel}.Generated.cs b/src/ImageSharp/PixelFormats/Generated/PixelOperations{TPixel}.Generated.cs
index 9553ec82d..9505ee6cf 100644
--- a/src/ImageSharp/PixelFormats/Generated/PixelOperations{TPixel}.Generated.cs
+++ b/src/ImageSharp/PixelFormats/Generated/PixelOperations{TPixel}.Generated.cs
@@ -6,7 +6,8 @@ namespace SixLabors.ImageSharp.PixelFormats
{
using System;
using System.Runtime.CompilerServices;
-
+ using System.Runtime.InteropServices;
+
public partial class PixelOperations
{
@@ -20,8 +21,8 @@ namespace SixLabors.ImageSharp.PixelFormats
{
GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count);
- ref Rgba32 sourceRef = ref source.DangerousGetPinnableReference();
- ref TPixel destRef = ref destPixels.DangerousGetPinnableReference();
+ ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(source);
+ ref TPixel destRef = ref MemoryMarshal.GetReference(destPixels);
Rgba32 rgba = new Rgba32(0, 0, 0, 255);
@@ -57,8 +58,8 @@ namespace SixLabors.ImageSharp.PixelFormats
{
GuardSpans(sourcePixels, nameof(sourcePixels), dest, nameof(dest), count);
- ref TPixel sourceBaseRef = ref sourcePixels.DangerousGetPinnableReference();
- ref Rgba32 destBaseRef = ref dest.DangerousGetPinnableReference();
+ ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
+ ref Rgba32 destBaseRef = ref MemoryMarshal.GetReference(dest);
for (int i = 0; i < count; i++)
{
@@ -91,8 +92,8 @@ namespace SixLabors.ImageSharp.PixelFormats
{
GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count);
- ref Bgra32 sourceRef = ref source.DangerousGetPinnableReference();
- ref TPixel destRef = ref destPixels.DangerousGetPinnableReference();
+ ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(source);
+ ref TPixel destRef = ref MemoryMarshal.GetReference(destPixels);
Rgba32 rgba = new Rgba32(0, 0, 0, 255);
@@ -128,8 +129,8 @@ namespace SixLabors.ImageSharp.PixelFormats
{
GuardSpans(sourcePixels, nameof(sourcePixels), dest, nameof(dest), count);
- ref TPixel sourceBaseRef = ref sourcePixels.DangerousGetPinnableReference();
- ref Bgra32 destBaseRef = ref dest.DangerousGetPinnableReference();
+ ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
+ ref Bgra32 destBaseRef = ref MemoryMarshal.GetReference(dest);
for (int i = 0; i < count; i++)
{
@@ -162,8 +163,8 @@ namespace SixLabors.ImageSharp.PixelFormats
{
GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count);
- ref Rgb24 sourceRef = ref source.DangerousGetPinnableReference();
- ref TPixel destRef = ref destPixels.DangerousGetPinnableReference();
+ ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(source);
+ ref TPixel destRef = ref MemoryMarshal.GetReference(destPixels);
Rgba32 rgba = new Rgba32(0, 0, 0, 255);
@@ -199,8 +200,8 @@ namespace SixLabors.ImageSharp.PixelFormats
{
GuardSpans(sourcePixels, nameof(sourcePixels), dest, nameof(dest), count);
- ref TPixel sourceBaseRef = ref sourcePixels.DangerousGetPinnableReference();
- ref Rgb24 destBaseRef = ref dest.DangerousGetPinnableReference();
+ ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
+ ref Rgb24 destBaseRef = ref MemoryMarshal.GetReference(dest);
for (int i = 0; i < count; i++)
{
@@ -233,8 +234,8 @@ namespace SixLabors.ImageSharp.PixelFormats
{
GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count);
- ref Bgr24 sourceRef = ref source.DangerousGetPinnableReference();
- ref TPixel destRef = ref destPixels.DangerousGetPinnableReference();
+ ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(source);
+ ref TPixel destRef = ref MemoryMarshal.GetReference(destPixels);
Rgba32 rgba = new Rgba32(0, 0, 0, 255);
@@ -270,8 +271,8 @@ namespace SixLabors.ImageSharp.PixelFormats
{
GuardSpans(sourcePixels, nameof(sourcePixels), dest, nameof(dest), count);
- ref TPixel sourceBaseRef = ref sourcePixels.DangerousGetPinnableReference();
- ref Bgr24 destBaseRef = ref dest.DangerousGetPinnableReference();
+ ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
+ ref Bgr24 destBaseRef = ref MemoryMarshal.GetReference(dest);
for (int i = 0; i < count; i++)
{
diff --git a/src/ImageSharp/PixelFormats/Generated/PixelOperations{TPixel}.Generated.tt b/src/ImageSharp/PixelFormats/Generated/PixelOperations{TPixel}.Generated.tt
index aa88b6606..365f5cb51 100644
--- a/src/ImageSharp/PixelFormats/Generated/PixelOperations{TPixel}.Generated.tt
+++ b/src/ImageSharp/PixelFormats/Generated/PixelOperations{TPixel}.Generated.tt
@@ -7,6 +7,7 @@
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
+<#@ import namespace="System.Runtime.InteropServices" #>
<#@ output extension=".cs" #>
<#
void GenerateToDestFormatMethods(string pixelType)
@@ -24,8 +25,8 @@
{
GuardSpans(sourcePixels, nameof(sourcePixels), dest, nameof(dest), count);
- ref TPixel sourceBaseRef = ref sourcePixels.DangerousGetPinnableReference();
- ref <#=pixelType#> destBaseRef = ref dest.DangerousGetPinnableReference();
+ ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
+ ref <#=pixelType#> destBaseRef = ref MemoryMarshal.GetReference(dest);
for (int i = 0; i < count; i++)
{
@@ -64,8 +65,8 @@
{
GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count);
- ref <#=pixelType#> sourceRef = ref source.DangerousGetPinnableReference();
- ref TPixel destRef = ref destPixels.DangerousGetPinnableReference();
+ ref <#=pixelType#> sourceRef = ref MemoryMarshal.GetReference(source);
+ ref TPixel destRef = ref MemoryMarshal.GetReference(destPixels);
Rgba32 rgba = new Rgba32(0, 0, 0, 255);
@@ -101,7 +102,8 @@ namespace SixLabors.ImageSharp.PixelFormats
{
using System;
using System.Runtime.CompilerServices;
-
+ using System.Runtime.InteropServices;
+
public partial class PixelOperations
{
<#
diff --git a/src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.cs
index 659e70228..edf6a88e1 100644
--- a/src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.cs
+++ b/src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.cs
@@ -6,9 +6,9 @@ namespace SixLabors.ImageSharp
{
using System;
using System.Runtime.CompilerServices;
-
+ using System.Runtime.InteropServices;
using SixLabors.ImageSharp.PixelFormats;
-
+
///
/// Provides optimized overrides for bulk operations.
///
@@ -22,8 +22,8 @@ namespace SixLabors.ImageSharp
{
GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count);
- ref Rgb24 sourceRef = ref source.DangerousGetPinnableReference();
- ref Rgba32 destRef = ref destPixels.DangerousGetPinnableReference();
+ ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Rgba32 destRef = ref MemoryMarshal.GetReference(destPixels);
for (int i = 0; i < count; i++)
{
@@ -38,8 +38,8 @@ namespace SixLabors.ImageSharp
{
GuardSpans(sourcePixels, nameof(sourcePixels), dest, nameof(dest), count);
- ref Rgba32 sourceRef = ref sourcePixels.DangerousGetPinnableReference();
- ref Rgb24 destRef = ref dest.DangerousGetPinnableReference();
+ ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
+ ref Rgb24 destRef = ref MemoryMarshal.GetReference(dest);
for (int i = 0; i < count; i++)
{
@@ -54,8 +54,8 @@ namespace SixLabors.ImageSharp
{
GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count);
- ref Bgr24 sourceRef = ref source.DangerousGetPinnableReference();
- ref Rgba32 destRef = ref destPixels.DangerousGetPinnableReference();
+ ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Rgba32 destRef = ref MemoryMarshal.GetReference(destPixels);
for (int i = 0; i < count; i++)
{
@@ -70,8 +70,8 @@ namespace SixLabors.ImageSharp
{
GuardSpans(sourcePixels, nameof(sourcePixels), dest, nameof(dest), count);
- ref Rgba32 sourceRef = ref sourcePixels.DangerousGetPinnableReference();
- ref Bgr24 destRef = ref dest.DangerousGetPinnableReference();
+ ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
+ ref Bgr24 destRef = ref MemoryMarshal.GetReference(dest);
for (int i = 0; i < count; i++)
{
@@ -86,8 +86,8 @@ namespace SixLabors.ImageSharp
{
GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count);
- ref Bgra32 sourceRef = ref source.DangerousGetPinnableReference();
- ref Rgba32 destRef = ref destPixels.DangerousGetPinnableReference();
+ ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Rgba32 destRef = ref MemoryMarshal.GetReference(destPixels);
for (int i = 0; i < count; i++)
{
@@ -102,8 +102,8 @@ namespace SixLabors.ImageSharp
{
GuardSpans(sourcePixels, nameof(sourcePixels), dest, nameof(dest), count);
- ref Rgba32 sourceRef = ref sourcePixels.DangerousGetPinnableReference();
- ref Bgra32 destRef = ref dest.DangerousGetPinnableReference();
+ ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
+ ref Bgra32 destRef = ref MemoryMarshal.GetReference(dest);
for (int i = 0; i < count; i++)
{
diff --git a/src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.tt b/src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.tt
index 9d2229394..d83e49f77 100644
--- a/src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.tt
+++ b/src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.tt
@@ -18,8 +18,8 @@
{
GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count);
- ref <#=pixelType#> sourceRef = ref source.DangerousGetPinnableReference();
- ref Rgba32 destRef = ref destPixels.DangerousGetPinnableReference();
+ ref <#=pixelType#> sourceRef = ref MemoryMarshal.GetReference(source);
+ ref Rgba32 destRef = ref MemoryMarshal.GetReference(destPixels);
for (int i = 0; i < count; i++)
{
@@ -40,8 +40,8 @@
{
GuardSpans(sourcePixels, nameof(sourcePixels), dest, nameof(dest), count);
- ref Rgba32 sourceRef = ref sourcePixels.DangerousGetPinnableReference();
- ref <#=pixelType#> destRef = ref dest.DangerousGetPinnableReference();
+ ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
+ ref <#=pixelType#> destRef = ref MemoryMarshal.GetReference(dest);
for (int i = 0; i < count; i++)
{
@@ -61,9 +61,9 @@ namespace SixLabors.ImageSharp
{
using System;
using System.Runtime.CompilerServices;
-
+ using System.Runtime.InteropServices;
using SixLabors.ImageSharp.PixelFormats;
-
+
///
/// Provides optimized overrides for bulk operations.
///
diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs
index 4f879fbdc..6f7975240 100644
--- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs
+++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs
@@ -4,6 +4,7 @@
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.PixelFormats
{
@@ -30,8 +31,8 @@ namespace SixLabors.ImageSharp.PixelFormats
{
GuardSpans(sourceVectors, nameof(sourceVectors), destColors, nameof(destColors), count);
- ref Vector4 sourceRef = ref sourceVectors.DangerousGetPinnableReference();
- ref TPixel destRef = ref destColors.DangerousGetPinnableReference();
+ ref Vector4 sourceRef = ref MemoryMarshal.GetReference(sourceVectors);
+ ref TPixel destRef = ref MemoryMarshal.GetReference(destColors);
for (int i = 0; i < count; i++)
{
@@ -51,8 +52,8 @@ namespace SixLabors.ImageSharp.PixelFormats
{
GuardSpans(sourceColors, nameof(sourceColors), destVectors, nameof(destVectors), count);
- ref TPixel sourceRef = ref sourceColors.DangerousGetPinnableReference();
- ref Vector4 destRef = ref destVectors.DangerousGetPinnableReference();
+ ref TPixel sourceRef = ref MemoryMarshal.GetReference(sourceColors);
+ ref Vector4 destRef = ref MemoryMarshal.GetReference(destVectors);
for (int i = 0; i < count; i++)
{
diff --git a/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs b/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs
index 552ac0a01..89a4aba26 100644
--- a/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs
+++ b/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs
@@ -57,8 +57,8 @@ namespace SixLabors.ImageSharp
int unpackedRawCount = count * 4;
- ref uint sourceBase = ref Unsafe.As(ref sourceColors.DangerousGetPinnableReference());
- ref UnpackedRGBA destBaseAsUnpacked = ref Unsafe.As(ref destVectors.DangerousGetPinnableReference());
+ ref uint sourceBase = ref Unsafe.As(ref MemoryMarshal.GetReference(sourceColors));
+ ref UnpackedRGBA destBaseAsUnpacked = ref Unsafe.As(ref MemoryMarshal.GetReference(destVectors));
ref Vector destBaseAsUInt = ref Unsafe.As>(ref destBaseAsUnpacked);
ref Vector destBaseAsFloat = ref Unsafe.As>(ref destBaseAsUnpacked);
diff --git a/src/ImageSharp/Processing/Processors/Dithering/PixelPair.cs b/src/ImageSharp/Processing/Processors/Dithering/PixelPair.cs
index e3b9c11bd..07045bb5a 100644
--- a/src/ImageSharp/Processing/Processors/Dithering/PixelPair.cs
+++ b/src/ImageSharp/Processing/Processors/Dithering/PixelPair.cs
@@ -10,7 +10,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// Represents a composite pair of pixels. Used for caching color distance lookups.
///
/// The pixel format.
- internal struct PixelPair : IEquatable>
+ internal readonly struct PixelPair : IEquatable>
where TPixel : struct, IPixel
{
///
diff --git a/src/ImageSharp/Processing/Processors/Transforms/WeightsWindow.cs b/src/ImageSharp/Processing/Processors/Transforms/WeightsWindow.cs
index 399b3db84..26aaec502 100644
--- a/src/ImageSharp/Processing/Processors/Transforms/WeightsWindow.cs
+++ b/src/ImageSharp/Processing/Processors/Transforms/WeightsWindow.cs
@@ -4,7 +4,7 @@
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
-
+using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Processing.Processors
@@ -79,7 +79,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
{
ref float horizontalValues = ref this.GetStartReference();
int left = this.Left;
- ref Vector4 vecPtr = ref Unsafe.Add(ref rowSpan.DangerousGetPinnableReference(), left + sourceX);
+ ref Vector4 vecPtr = ref Unsafe.Add(ref MemoryMarshal.GetReference(rowSpan), left + sourceX);
// Destination color components
Vector4 result = Vector4.Zero;
@@ -106,7 +106,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
{
ref float horizontalValues = ref this.GetStartReference();
int left = this.Left;
- ref Vector4 vecPtr = ref Unsafe.Add(ref rowSpan.DangerousGetPinnableReference(), left + sourceX);
+ ref Vector4 vecPtr = ref Unsafe.Add(ref MemoryMarshal.GetReference(rowSpan), left + sourceX);
// Destination color components
Vector4 result = Vector4.Zero;
diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs
index 7d8519875..7bac44a98 100644
--- a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs
+++ b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs
@@ -3,7 +3,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Color.Bulk
{
using System.Numerics;
using System.Runtime.CompilerServices;
-
+ using System.Runtime.InteropServices;
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.Memory;
@@ -37,8 +37,8 @@ namespace SixLabors.ImageSharp.Benchmarks.Color.Bulk
[Benchmark(Baseline = true)]
public void PerElement()
{
- ref Vector4 s = ref this.source.Span.DangerousGetPinnableReference();
- ref TPixel d = ref this.destination.Span.DangerousGetPinnableReference();
+ ref Vector4 s = ref MemoryMarshal.GetReference(this.source.Span);
+ ref TPixel d = ref MemoryMarshal.GetReference(this.destination.Span);
for (int i = 0; i < this.Count; i++)
{
diff --git a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj
index 2e0b93515..6dcfbaf81 100644
--- a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj
+++ b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj
@@ -17,11 +17,11 @@
-
-
-
-
+
+
+
+
diff --git a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj
index 16f062c6e..d6ea4a130 100644
--- a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj
+++ b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj
@@ -16,7 +16,8 @@
-
+
+
diff --git a/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs b/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs
index a199bb319..c73ce9631 100644
--- a/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs
+++ b/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs
@@ -133,7 +133,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
public void ReleaseRetainedResources_ReplacesInnerArrayPool(bool keepBufferAlive)
{
IBuffer buffer = this.MemoryManager.Allocate(32);
- ref int ptrToPrev0 = ref buffer.Span.DangerousGetPinnableReference();
+ ref int ptrToPrev0 = ref MemoryMarshal.GetReference(buffer.Span);
if (!keepBufferAlive)
{
diff --git a/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs b/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs
index 565e06572..82163d2bb 100644
--- a/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs
+++ b/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs
@@ -5,7 +5,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
{
using System;
using System.Runtime.CompilerServices;
-
+ using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Tests.Common;
using SixLabors.Primitives;
@@ -20,7 +20,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
public static void SpanPointsTo(Span span, IBuffer buffer, int bufferOffset = 0)
where T : struct
{
- ref T actual = ref span.DangerousGetPinnableReference();
+ ref T actual = ref MemoryMarshal.GetReference(span);
ref T expected = ref Unsafe.Add(ref buffer.DangerousGetPinnableReference(), bufferOffset);
Assert.True(Unsafe.AreSame(ref expected, ref actual), "span does not point to the expected position");
diff --git a/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs b/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs
index 50477cb5c..eff1f197a 100644
--- a/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs
+++ b/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs
@@ -3,6 +3,7 @@
using System;
using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Memory;
using Xunit;
// ReSharper disable InconsistentNaming
@@ -165,9 +166,9 @@ namespace SixLabors.ImageSharp.Tests.Memory
{
using (IBuffer buffer = this.Allocate(desiredLength, false, testManagedByteBuffer))
{
- ref T a = ref buffer.Span.DangerousGetPinnableReference();
- ref T b = ref buffer.Span.DangerousGetPinnableReference();
- ref T c = ref buffer.Span.DangerousGetPinnableReference();
+ ref T a = ref MemoryMarshal.GetReference(buffer.Span);
+ ref T b = ref MemoryMarshal.GetReference(buffer.Span);
+ ref T c = ref MemoryMarshal.GetReference(buffer.Span);
Assert.True(Unsafe.AreSame(ref a, ref b));
Assert.True(Unsafe.AreSame(ref b, ref c));
diff --git a/tests/ImageSharp.Tests/Memory/SpanUtilityTests.cs b/tests/ImageSharp.Tests/Memory/SpanUtilityTests.cs
index 049c4c6ba..23bc29743 100644
--- a/tests/ImageSharp.Tests/Memory/SpanUtilityTests.cs
+++ b/tests/ImageSharp.Tests/Memory/SpanUtilityTests.cs
@@ -78,8 +78,8 @@ namespace SixLabors.ImageSharp.Tests.Memory
TestStructs.Foo[] source = TestStructs.Foo.CreateArray(count + 2);
TestStructs.Foo[] dest = new TestStructs.Foo[count + 5];
- var apSource = new Span(source, 1);
- var apDest = new Span(dest, 1);
+ var apSource = new Span(source, 1, source.Length - 1);
+ var apDest = new Span(dest, 1, dest.Length - 1);
SpanHelper.Copy(apSource, apDest, count - 1);
@@ -101,8 +101,8 @@ namespace SixLabors.ImageSharp.Tests.Memory
TestStructs.AlignedFoo[] source = TestStructs.AlignedFoo.CreateArray(count + 2);
TestStructs.AlignedFoo[] dest = new TestStructs.AlignedFoo[count + 5];
- var apSource = new Span(source, 1);
- var apDest = new Span(dest, 1);
+ var apSource = new Span(source, 1, source.Length - 1);
+ var apDest = new Span(dest, 1, dest.Length - 1);
SpanHelper.Copy(apSource, apDest, count - 1);
@@ -124,8 +124,8 @@ namespace SixLabors.ImageSharp.Tests.Memory
int[] source = CreateTestInts(count + 2);
int[] dest = new int[count + 5];
- var apSource = new Span(source, 1);
- var apDest = new Span(dest, 1);
+ var apSource = new Span(source, 1, source.Length - 1);
+ var apDest = new Span(dest, 1, dest.Length - 1);
SpanHelper.Copy(apSource, apDest, count - 1);
@@ -148,8 +148,8 @@ namespace SixLabors.ImageSharp.Tests.Memory
TestStructs.Foo[] source = TestStructs.Foo.CreateArray(count + 2);
byte[] dest = new byte[destCount + sizeof(TestStructs.Foo) * 2];
- var apSource = new Span(source, 1);
- var apDest = new Span(dest, sizeof(TestStructs.Foo));
+ var apSource = new Span(source, 1, source.Length - 1);
+ var apDest = new Span(dest, sizeof(TestStructs.Foo), dest.Length - sizeof(TestStructs.Foo));
SpanHelper.Copy(apSource.AsBytes(), apDest, (count - 1) * sizeof(TestStructs.Foo));
@@ -171,8 +171,8 @@ namespace SixLabors.ImageSharp.Tests.Memory
TestStructs.AlignedFoo[] source = TestStructs.AlignedFoo.CreateArray(count + 2);
byte[] dest = new byte[destCount + sizeof(TestStructs.AlignedFoo) * 2];
- var apSource = new Span(source, 1);
- var apDest = new Span(dest, sizeof(TestStructs.AlignedFoo));
+ var apSource = new Span(source, 1, source.Length - 1);
+ var apDest = new Span(dest, sizeof(TestStructs.AlignedFoo), dest.Length - sizeof(TestStructs.AlignedFoo));
SpanHelper.Copy(apSource.AsBytes(), apDest, (count - 1) * sizeof(TestStructs.AlignedFoo));