From 75bc37c423264e9c888f917cb51efbeb4c2897ba Mon Sep 17 00:00:00 2001 From: popow Date: Mon, 2 Jul 2018 15:50:05 +0200 Subject: [PATCH] using memoryAllocator --- .../Normalization/HistogramEqualizationProcessor.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs b/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs index a1f37b039e..75bd2d256e 100644 --- a/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs +++ b/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs @@ -5,6 +5,7 @@ using System; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Processing.Normalization @@ -21,12 +22,13 @@ namespace SixLabors.ImageSharp.Processing.Normalization { var rgb48 = default(Rgb48); var rgb24 = default(Rgb24); + MemoryAllocator memoryAllocator = configuration.MemoryAllocator; int numberOfPixels = source.Width * source.Height; bool is16bitPerChannel = typeof(TPixel) == typeof(Rgb48) || typeof(TPixel) == typeof(Rgba64); // build the histogram of the grayscale levels int luminanceLevels = is16bitPerChannel ? 65536 : 256; - int[] histogram = new int[luminanceLevels]; + Span histogram = memoryAllocator.Allocate(luminanceLevels, clear: true).GetSpan(); for (int y = 0; y < source.Height; y++) { Span row = source.GetPixelRowSpan(y); @@ -39,7 +41,7 @@ namespace SixLabors.ImageSharp.Processing.Normalization } // calculate the cumulative distribution function (which will be the cumulative histogram) - int[] cdf = new int[luminanceLevels]; + Span cdf = memoryAllocator.Allocate(luminanceLevels, clear: true).GetSpan(); int histSum = 0; for (int i = 0; i < histogram.Length; i++) { @@ -47,6 +49,7 @@ namespace SixLabors.ImageSharp.Processing.Normalization cdf[i] = histSum; } + // get the first none zero value of the cumulative histogram int cdfMin = 0; for (int i = 0; i < histogram.Length; i++) { @@ -57,7 +60,7 @@ namespace SixLabors.ImageSharp.Processing.Normalization } } - int[] lut = new int[luminanceLevels]; + Span lut = memoryAllocator.Allocate(luminanceLevels, clear: true).GetSpan(); for (int i = 0; i < histogram.Length; i++) { lut[i] = cdf[i] - cdfMin;