diff --git a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs index c46137e76..7a5390564 100644 --- a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs @@ -3,6 +3,7 @@ using System; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; @@ -87,10 +88,11 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization { Rgba32 rgba = default; Span row = this.source.GetPixelRowSpan(y); + ref TPixel rowRef = ref MemoryMarshal.GetReference(row); for (int x = this.minX; x < this.maxX; x++) { - ref TPixel color = ref row[x]; + ref TPixel color = ref Unsafe.Add(ref rowRef, x); color.ToRgba32(ref rgba); // Convert to grayscale using ITU-R Recommendation BT.709 if required