Browse Source

make it parallel again!

af/merge-core
Anton Firszov 10 years ago
parent
commit
3502db1f48
  1. 24
      src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs

24
src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs

@ -110,13 +110,21 @@ namespace ImageSharp.Processing.Processors
{ {
firstPassPixels.Clear(); firstPassPixels.Clear();
using (PinnedBuffer<Vector4> tempRowBuffer = new PinnedBuffer<Vector4>(sourcePixels.Width)) Parallel.For(
0,
sourceRectangle.Bottom,
this.ParallelOptions,
y =>
{ {
for (int y = 0; y < sourceRectangle.Bottom; y++) // TODO: Without Parallel.For() this buffer object could be reused:
using (PinnedBuffer<Vector4> tempRowBuffer = new PinnedBuffer<Vector4>(sourcePixels.Width))
{ {
BufferSpan<TColor> sourceRow = sourcePixels.GetRowSpan(y); BufferSpan<TColor> sourceRow = sourcePixels.GetRowSpan(y);
BulkPixelOperations<TColor>.Instance.ToVector4(sourceRow, tempRowBuffer, sourceRow.Length); BulkPixelOperations<TColor>.Instance.ToVector4(
sourceRow,
tempRowBuffer,
sourceRow.Length);
if (this.Compand) if (this.Compand)
{ {
@ -135,10 +143,14 @@ namespace ImageSharp.Processing.Processors
} }
} }
} }
} });
// Now process the rows. // Now process the rows.
for (int y = minY; y < maxY; y++) Parallel.For(
minY,
maxY,
this.ParallelOptions,
y =>
{ {
// Ensure offsets are normalised for cropping and padding. // Ensure offsets are normalised for cropping and padding.
WeightsWindow window = this.VerticalWeights.Weights[y - startY]; WeightsWindow window = this.VerticalWeights.Weights[y - startY];
@ -167,7 +179,7 @@ namespace ImageSharp.Processing.Processors
targetPixels[x, y] = d; targetPixels[x, y] = d;
} }
} }
} });
} }
source.SwapPixelsBuffers(targetPixels); source.SwapPixelsBuffers(targetPixels);

Loading…
Cancel
Save