Browse Source

Use GetPixelRowSpan to access pixel data in global hist equalization

js/color-alpha-handling
Brian Popow 6 years ago
parent
commit
9d8ed6c852
  1. 10
      src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs

10
src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs

@ -116,13 +116,13 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization
public void Invoke(int y) public void Invoke(int y)
{ {
ref int histogramBase = ref MemoryMarshal.GetReference(this.histogramBuffer.GetSpan()); ref int histogramBase = ref MemoryMarshal.GetReference(this.histogramBuffer.GetSpan());
ref TPixel pixelBase = ref MemoryMarshal.GetReference(this.source.GetPixelRowSpan(y)); Span<TPixel> pixelRow = this.source.GetPixelRowSpan(y);
int levels = this.luminanceLevels; int levels = this.luminanceLevels;
for (int x = 0; x < this.bounds.Width; x++) for (int x = 0; x < this.bounds.Width; x++)
{ {
// TODO: We should bulk convert here. // TODO: We should bulk convert here.
var vector = Unsafe.Add(ref pixelBase, x).ToVector4(); var vector = pixelRow[x].ToVector4();
int luminance = ImageMaths.GetBT709Luminance(ref vector, levels); int luminance = ImageMaths.GetBT709Luminance(ref vector, levels);
Interlocked.Increment(ref Unsafe.Add(ref histogramBase, luminance)); Interlocked.Increment(ref Unsafe.Add(ref histogramBase, luminance));
} }
@ -165,18 +165,18 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization
public void Invoke(int y) public void Invoke(int y)
{ {
ref int cdfBase = ref MemoryMarshal.GetReference(this.cdfBuffer.GetSpan()); ref int cdfBase = ref MemoryMarshal.GetReference(this.cdfBuffer.GetSpan());
ref TPixel pixelBase = ref MemoryMarshal.GetReference(this.source.GetPixelRowSpan(y)); Span<TPixel> pixelRow = this.source.GetPixelRowSpan(y);
int levels = this.luminanceLevels; int levels = this.luminanceLevels;
float noOfPixelsMinusCdfMin = this.numberOfPixelsMinusCdfMin; float noOfPixelsMinusCdfMin = this.numberOfPixelsMinusCdfMin;
for (int x = 0; x < this.bounds.Width; x++) for (int x = 0; x < this.bounds.Width; x++)
{ {
// TODO: We should bulk convert here. // TODO: We should bulk convert here.
ref TPixel pixel = ref Unsafe.Add(ref pixelBase, x); TPixel pixel = pixelRow[x];
var vector = pixel.ToVector4(); var vector = pixel.ToVector4();
int luminance = ImageMaths.GetBT709Luminance(ref vector, levels); int luminance = ImageMaths.GetBT709Luminance(ref vector, levels);
float luminanceEqualized = Unsafe.Add(ref cdfBase, luminance) / noOfPixelsMinusCdfMin; float luminanceEqualized = Unsafe.Add(ref cdfBase, luminance) / noOfPixelsMinusCdfMin;
pixel.FromVector4(new Vector4(luminanceEqualized, luminanceEqualized, luminanceEqualized, vector.W)); pixelRow[x].FromVector4(new Vector4(luminanceEqualized, luminanceEqualized, luminanceEqualized, vector.W));
} }
} }
} }

Loading…
Cancel
Save