Skip to content

Commit 9d8ed6c

Browse files
committed
Use GetPixelRowSpan to access pixel data in global hist equalization
1 parent 440d8cf commit 9d8ed6c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ public GrayscaleLevelsRowOperation(
116116
public void Invoke(int y)
117117
{
118118
ref int histogramBase = ref MemoryMarshal.GetReference(this.histogramBuffer.GetSpan());
119-
ref TPixel pixelBase = ref MemoryMarshal.GetReference(this.source.GetPixelRowSpan(y));
119+
Span<TPixel> pixelRow = this.source.GetPixelRowSpan(y);
120120
int levels = this.luminanceLevels;
121121

122122
for (int x = 0; x < this.bounds.Width; x++)
123123
{
124124
// TODO: We should bulk convert here.
125-
var vector = Unsafe.Add(ref pixelBase, x).ToVector4();
125+
var vector = pixelRow[x].ToVector4();
126126
int luminance = ImageMaths.GetBT709Luminance(ref vector, levels);
127127
Interlocked.Increment(ref Unsafe.Add(ref histogramBase, luminance));
128128
}
@@ -165,18 +165,18 @@ public CdfApplicationRowOperation(
165165
public void Invoke(int y)
166166
{
167167
ref int cdfBase = ref MemoryMarshal.GetReference(this.cdfBuffer.GetSpan());
168-
ref TPixel pixelBase = ref MemoryMarshal.GetReference(this.source.GetPixelRowSpan(y));
168+
Span<TPixel> pixelRow = this.source.GetPixelRowSpan(y);
169169
int levels = this.luminanceLevels;
170170
float noOfPixelsMinusCdfMin = this.numberOfPixelsMinusCdfMin;
171171

172172
for (int x = 0; x < this.bounds.Width; x++)
173173
{
174174
// TODO: We should bulk convert here.
175-
ref TPixel pixel = ref Unsafe.Add(ref pixelBase, x);
175+
TPixel pixel = pixelRow[x];
176176
var vector = pixel.ToVector4();
177177
int luminance = ImageMaths.GetBT709Luminance(ref vector, levels);
178178
float luminanceEqualized = Unsafe.Add(ref cdfBase, luminance) / noOfPixelsMinusCdfMin;
179-
pixel.FromVector4(new Vector4(luminanceEqualized, luminanceEqualized, luminanceEqualized, vector.W));
179+
pixelRow[x].FromVector4(new Vector4(luminanceEqualized, luminanceEqualized, luminanceEqualized, vector.W));
180180
}
181181
}
182182
}

0 commit comments

Comments
 (0)