|
|
@ -459,10 +459,14 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization |
|
|
private readonly Configuration configuration; |
|
|
private readonly Configuration configuration; |
|
|
private readonly MemoryAllocator memoryAllocator; |
|
|
private readonly MemoryAllocator memoryAllocator; |
|
|
|
|
|
|
|
|
// Used for storing the minimum value for each CDF entry.
|
|
|
/// <summary>
|
|
|
|
|
|
/// Used for storing the minimum value for each CDF entry.
|
|
|
|
|
|
/// </summary>
|
|
|
private readonly Buffer2D<int> cdfMinBuffer2D; |
|
|
private readonly Buffer2D<int> cdfMinBuffer2D; |
|
|
|
|
|
|
|
|
// Used for storing the LUT for each CDF entry.
|
|
|
/// <summary>
|
|
|
|
|
|
/// Used for storing the LUT for each CDF entry.
|
|
|
|
|
|
/// </summary>
|
|
|
private readonly Buffer2D<int> cdfLutBuffer2D; |
|
|
private readonly Buffer2D<int> cdfLutBuffer2D; |
|
|
private readonly int pixelsInTile; |
|
|
private readonly int pixelsInTile; |
|
|
private readonly int sourceWidth; |
|
|
private readonly int sourceWidth; |
|
|
@ -596,6 +600,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization |
|
|
int y = this.tileYStartPositions[index].y; |
|
|
int y = this.tileYStartPositions[index].y; |
|
|
int endY = Math.Min(y + this.tileHeight, this.sourceHeight); |
|
|
int endY = Math.Min(y + this.tileHeight, this.sourceHeight); |
|
|
Span<int> cdfMinSpan = this.cdfMinBuffer2D.GetRowSpan(cdfY); |
|
|
Span<int> cdfMinSpan = this.cdfMinBuffer2D.GetRowSpan(cdfY); |
|
|
|
|
|
cdfMinSpan.Clear(); |
|
|
|
|
|
|
|
|
using IMemoryOwner<int> histogramBuffer = this.allocator.Allocate<int>(this.luminanceLevels); |
|
|
using IMemoryOwner<int> histogramBuffer = this.allocator.Allocate<int>(this.luminanceLevels); |
|
|
Span<int> histogram = histogramBuffer.GetSpan(); |
|
|
Span<int> histogram = histogramBuffer.GetSpan(); |
|
|
@ -614,7 +619,9 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization |
|
|
for (int dx = x; dx < xlimit; dx++) |
|
|
for (int dx = x; dx < xlimit; dx++) |
|
|
{ |
|
|
{ |
|
|
int luminance = GetLuminance(rowSpan[dx], this.luminanceLevels); |
|
|
int luminance = GetLuminance(rowSpan[dx], this.luminanceLevels); |
|
|
histogram[luminance]++; |
|
|
|
|
|
|
|
|
// This is safe. The index maxes out to the span length.
|
|
|
|
|
|
Unsafe.Add(ref histogramBase, luminance)++; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|