From 2222db8e0baf52f46623b0668b356b8e42c37bb9 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sun, 8 Nov 2020 17:45:29 +0100 Subject: [PATCH] Use Interlocked.Increment(ref Unsafe.Add(ref histogramBase, luminance)); --- .../GlobalHistogramEqualizationProcessor{TPixel}.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs index 0c5a109a62..488426f939 100644 --- a/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs @@ -115,6 +115,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization #endif public void Invoke(int y) { + ref int histogramBase = ref MemoryMarshal.GetReference(this.histogramBuffer.GetSpan()); ref TPixel pixelBase = ref MemoryMarshal.GetReference(this.source.GetPixelRowSpan(y)); int levels = this.luminanceLevels; @@ -123,8 +124,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization // TODO: We should bulk convert here. var vector = Unsafe.Add(ref pixelBase, x).ToVector4(); int luminance = ImageMaths.GetBT709Luminance(ref vector, levels); - ref int histogramAtLuminance = ref MemoryMarshal.GetReference(this.histogramBuffer.Slice(luminance)); - Interlocked.Increment(ref histogramAtLuminance); + Interlocked.Increment(ref Unsafe.Add(ref histogramBase, luminance)); } } }