From ec4a56b6b70ea39293295bd0f3be5f339fb50d5b Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 27 Feb 2020 13:22:56 +0100 Subject: [PATCH] Micro-optimization in BinaryThresholdProcessor --- .../Binarization/BinaryThresholdProcessor{TPixel}.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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