|
|
|
@ -6,6 +6,7 @@ using System.Buffers; |
|
|
|
using System.Numerics; |
|
|
|
using System.Runtime.CompilerServices; |
|
|
|
using System.Runtime.InteropServices; |
|
|
|
using System.Threading; |
|
|
|
using SixLabors.ImageSharp.Advanced; |
|
|
|
using SixLabors.ImageSharp.Memory; |
|
|
|
using SixLabors.ImageSharp.PixelFormats; |
|
|
|
@ -51,7 +52,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization |
|
|
|
|
|
|
|
using IMemoryOwner<int> histogramBuffer = memoryAllocator.Allocate<int>(this.LuminanceLevels, AllocationOptions.Clean); |
|
|
|
|
|
|
|
// Build the histogram of the grayscale levels
|
|
|
|
// Build the histogram of the grayscale levels.
|
|
|
|
var grayscaleOperation = new GrayscaleLevelsRowOperation(interest, histogramBuffer, source, this.LuminanceLevels); |
|
|
|
ParallelRowIterator.IterateRows( |
|
|
|
this.Configuration, |
|
|
|
@ -114,7 +115,6 @@ 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,7 +123,8 @@ 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); |
|
|
|
Unsafe.Add(ref histogramBase, luminance)++; |
|
|
|
ref int histogramAtLuminance = ref MemoryMarshal.GetReference(this.histogramBuffer.Slice(luminance)); |
|
|
|
Interlocked.Increment(ref histogramAtLuminance); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|