|
|
|
@ -66,47 +66,45 @@ namespace ImageSharp.Processing.Processors |
|
|
|
// Get the range on the y-plane to choose from.
|
|
|
|
IEnumerable<int> range = EnumerableExtensions.SteppedRange(minY, i => i < maxY, size); |
|
|
|
|
|
|
|
using (PixelAccessor<TPixel> sourcePixels = source.Lock()) |
|
|
|
{ |
|
|
|
Parallel.ForEach( |
|
|
|
range, |
|
|
|
this.ParallelOptions, |
|
|
|
y => |
|
|
|
Parallel.ForEach( |
|
|
|
range, |
|
|
|
this.ParallelOptions, |
|
|
|
y => |
|
|
|
{ |
|
|
|
int offsetY = y - startY; |
|
|
|
int offsetPy = offset; |
|
|
|
|
|
|
|
// Make sure that the offset is within the boundary of the image.
|
|
|
|
while (offsetY + offsetPy >= maxY) |
|
|
|
{ |
|
|
|
int offsetY = y - startY; |
|
|
|
int offsetPy = offset; |
|
|
|
offsetPy--; |
|
|
|
} |
|
|
|
|
|
|
|
for (int x = minX; x < maxX; x += size) |
|
|
|
{ |
|
|
|
int offsetX = x - startX; |
|
|
|
int offsetPx = offset; |
|
|
|
Span<TPixel> row = source.GetRowSpan(offsetY + offsetPy); |
|
|
|
|
|
|
|
// Make sure that the offset is within the boundary of the image.
|
|
|
|
while (offsetY + offsetPy >= maxY) |
|
|
|
{ |
|
|
|
offsetPy--; |
|
|
|
} |
|
|
|
for (int x = minX; x < maxX; x += size) |
|
|
|
{ |
|
|
|
int offsetX = x - startX; |
|
|
|
int offsetPx = offset; |
|
|
|
|
|
|
|
while (x + offsetPx >= maxX) |
|
|
|
{ |
|
|
|
offsetPx--; |
|
|
|
} |
|
|
|
while (x + offsetPx >= maxX) |
|
|
|
{ |
|
|
|
offsetPx--; |
|
|
|
} |
|
|
|
|
|
|
|
// Get the pixel color in the centre of the soon to be pixelated area.
|
|
|
|
// ReSharper disable AccessToDisposedClosure
|
|
|
|
TPixel pixel = sourcePixels[offsetX + offsetPx, offsetY + offsetPy]; |
|
|
|
// Get the pixel color in the centre of the soon to be pixelated area.
|
|
|
|
TPixel pixel = row[offsetX + offsetPx]; |
|
|
|
|
|
|
|
// For each pixel in the pixelate size, set it to the centre color.
|
|
|
|
for (int l = offsetY; l < offsetY + size && l < maxY; l++) |
|
|
|
// For each pixel in the pixelate size, set it to the centre color.
|
|
|
|
for (int l = offsetY; l < offsetY + size && l < maxY; l++) |
|
|
|
{ |
|
|
|
for (int k = offsetX; k < offsetX + size && k < maxX; k++) |
|
|
|
{ |
|
|
|
for (int k = offsetX; k < offsetX + size && k < maxX; k++) |
|
|
|
{ |
|
|
|
sourcePixels[k, l] = pixel; |
|
|
|
} |
|
|
|
source[k, l] = pixel; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |