diff --git a/src/ImageSharp/Advanced/ParallelRowIterator.cs b/src/ImageSharp/Advanced/ParallelRowIterator.cs index 275c3d10eb..7802d96533 100644 --- a/src/ImageSharp/Advanced/ParallelRowIterator.cs +++ b/src/ImageSharp/Advanced/ParallelRowIterator.cs @@ -18,64 +18,6 @@ namespace SixLabors.ImageSharp.Advanced /// public static class ParallelRowIterator { - /// - /// Iterate through the rows of a rectangle in optimized batches defined by -s. - /// - /// The type of row action to perform. - /// The . - /// The to get the parallel settings from. - /// The method body defining the iteration logic on a single . - [MethodImpl(InliningOptions.ShortMethod)] - public static void IterateRows(Rectangle rectangle, Configuration configuration, in T body) - where T : struct, IRowIntervalAction - { - var parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration); - IterateRows(rectangle, in parallelSettings, in body); - } - - /// - /// Iterate through the rows of a rectangle in optimized batches defined by -s. - /// - /// The type of row action to perform. - /// The . - /// The . - /// The method body defining the iteration logic on a single . - public static void IterateRows( - Rectangle rectangle, - in ParallelExecutionSettings parallelSettings, - in T body) - where T : struct, IRowIntervalAction - { - ValidateRectangle(rectangle); - - int top = rectangle.Top; - int bottom = rectangle.Bottom; - int width = rectangle.Width; - int height = rectangle.Height; - - int maxSteps = DivideCeil(width * height, parallelSettings.MinimumPixelsProcessedPerTask); - int numOfSteps = Math.Min(parallelSettings.MaxDegreeOfParallelism, maxSteps); - - // Avoid TPL overhead in this trivial case: - if (numOfSteps == 1) - { - var rows = new RowInterval(top, bottom); - Unsafe.AsRef(body).Invoke(in rows); - return; - } - - int verticalStep = DivideCeil(rectangle.Height, numOfSteps); - var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps }; - var rowInfo = new WrappingRowIntervalInfo(top, bottom, verticalStep); - var rowAction = new WrappingRowIntervalAction(in rowInfo, in body); - - Parallel.For( - 0, - numOfSteps, - parallelOptions, - rowAction.Invoke); - } - /// /// Iterate through the rows of a rectangle in optimized batches. /// @@ -84,11 +26,11 @@ namespace SixLabors.ImageSharp.Advanced /// The to get the parallel settings from. /// The method body defining the iteration logic on a single row. [MethodImpl(InliningOptions.ShortMethod)] - public static void IterateRows2(Rectangle rectangle, Configuration configuration, in T body) + public static void IterateRows(Rectangle rectangle, Configuration configuration, in T body) where T : struct, IRowAction { var parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration); - IterateRows2(rectangle, in parallelSettings, in body); + IterateRows(rectangle, in parallelSettings, in body); } /// @@ -98,7 +40,7 @@ namespace SixLabors.ImageSharp.Advanced /// The . /// The . /// The method body defining the iteration logic on a single row. - public static void IterateRows2( + public static void IterateRows( Rectangle rectangle, in ParallelExecutionSettings parallelSettings, in T body) diff --git a/src/ImageSharp/ImageFrame{TPixel}.cs b/src/ImageSharp/ImageFrame{TPixel}.cs index 0a345db7c8..57b8a953a0 100644 --- a/src/ImageSharp/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/ImageFrame{TPixel}.cs @@ -260,7 +260,7 @@ namespace SixLabors.ImageSharp var target = new ImageFrame(configuration, this.Width, this.Height, this.Metadata.DeepClone()); - ParallelRowIterator.IterateRows2( + ParallelRowIterator.IterateRows( this.Bounds(), configuration, new RowAction(this, target, configuration)); diff --git a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs index 26685d75be..4db2b938ff 100644 --- a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs @@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization var workingRect = Rectangle.FromLTRB(startX, startY, endX, endY); - ParallelRowIterator.IterateRows2( + ParallelRowIterator.IterateRows( workingRect, configuration, new RowAction(source, upper, lower, threshold, startX, endX, isAlphaOnly)); diff --git a/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs index 71647234b5..3265229963 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs @@ -282,7 +282,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution float inverseGamma = 1 / this.gamma; // Apply the inverse gamma exposure pass, and write the final pixel data - ParallelRowIterator.IterateRows2( + ParallelRowIterator.IterateRows( this.SourceRectangle, this.Configuration, new ApplyInverseGammaExposureRowAction(this.SourceRectangle, source.PixelBuffer, processingBuffer, this.Configuration, inverseGamma)); @@ -314,13 +314,13 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution Vector4 parameters = Unsafe.Add(ref paramsRef, i); // Compute the vertical 1D convolution - ParallelRowIterator.IterateRows2( + ParallelRowIterator.IterateRows( sourceRectangle, configuration, new ApplyVerticalConvolutionRowAction(ref sourceRectangle, firstPassBuffer, source.PixelBuffer, kernel)); // Compute the horizontal 1D convolutions and accumulate the partial results on the target buffer - ParallelRowIterator.IterateRows2( + ParallelRowIterator.IterateRows( sourceRectangle, configuration, new ApplyHorizontalConvolutionRowAction(ref sourceRectangle, processingBuffer, firstPassBuffer, kernel, parameters.Z, parameters.W)); diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor{TPixel}.cs index 6ccd9914bb..85736cbd9a 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor{TPixel}.cs @@ -102,7 +102,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution processor.Apply(pass); } - ParallelRowIterator.IterateRows2( + ParallelRowIterator.IterateRows( Rectangle.FromLTRB(minX, minY, maxX, maxY), this.Configuration, new RowAction(source.PixelBuffer, pass.PixelBuffer, minX, maxX, shiftY, shiftX)); diff --git a/src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs b/src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs index 55399c5fde..a12bcb1fdc 100644 --- a/src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs +++ b/src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs @@ -98,7 +98,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing "Cannot draw image because the source image does not overlap the target image."); } - ParallelRowIterator.IterateRows2( + ParallelRowIterator.IterateRows( workingRect, configuration, new RowAction(source, targetImage, blender, configuration, minX, width, locationY, targetX, this.Opacity)); diff --git a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs index 728e4850d4..45f221c937 100644 --- a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs @@ -47,7 +47,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects source.CopyTo(targetPixels); - ParallelRowIterator.IterateRows2( + ParallelRowIterator.IterateRows( this.SourceRectangle, this.Configuration, new RowAction(this.SourceRectangle, targetPixels, source, this.Configuration, brushSize >> 1, this.definition.Levels)); diff --git a/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs index b6ae981fc1..a4a643425f 100644 --- a/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs @@ -52,7 +52,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization using IMemoryOwner histogramBuffer = memoryAllocator.Allocate(this.LuminanceLevels, AllocationOptions.Clean); // Build the histogram of the grayscale levels - ParallelRowIterator.IterateRows2( + ParallelRowIterator.IterateRows( workingRect, this.Configuration, new GrayscaleLevelsRowAction(workingRect, histogramBuffer, source, this.LuminanceLevels)); @@ -74,7 +74,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization float numberOfPixelsMinusCdfMin = numberOfPixels - cdfMin; // Apply the cdf to each pixel of the image - ParallelRowIterator.IterateRows2( + ParallelRowIterator.IterateRows( workingRect, this.Configuration, new CdfApplicationRowAction(workingRect, cdfBuffer, source, this.LuminanceLevels, numberOfPixelsMinusCdfMin)); diff --git a/src/ImageSharp/Processing/Processors/Overlays/BackgroundColorProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Overlays/BackgroundColorProcessor{TPixel}.cs index cb19211c29..2c17d71c6c 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/BackgroundColorProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/BackgroundColorProcessor{TPixel}.cs @@ -49,7 +49,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays PixelBlender blender = PixelOperations.Instance.GetPixelBlender(graphicsOptions); - ParallelRowIterator.IterateRows2( + ParallelRowIterator.IterateRows( interest, configuration, new RowAction(configuration, interest, blender, amount, colors, source)); diff --git a/src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor{TPixel}.cs index 9bf9dc5076..8a44dcd9bb 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor{TPixel}.cs @@ -58,7 +58,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms if (this.resampler is NearestNeighborResampler) { - ParallelRowIterator.IterateRows2( + ParallelRowIterator.IterateRows( targetBounds, configuration, new NearestNeighborRowAction(this.SourceRectangle, ref matrix, width, source, destination)); diff --git a/src/ImageSharp/Processing/Processors/Transforms/CropProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/CropProcessor{TPixel}.cs index 55b1534675..b294ef465b 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/CropProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/CropProcessor{TPixel}.cs @@ -49,7 +49,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms // Copying is cheap, we should process more pixels per task: ParallelExecutionSettings parallelSettings = ParallelExecutionSettings.FromConfiguration(this.Configuration).MultiplyMinimumPixelsPerTask(4); - ParallelRowIterator.IterateRows2( + ParallelRowIterator.IterateRows( bounds, in parallelSettings, new RowAction(ref bounds, source, destination)); diff --git a/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor{TPixel}.cs index b88ead08fa..91cb478917 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor{TPixel}.cs @@ -75,7 +75,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms /// The configuration. private void FlipY(ImageFrame source, Configuration configuration) { - ParallelRowIterator.IterateRows2( + ParallelRowIterator.IterateRows( source.Bounds(), configuration, new RowAction(source)); diff --git a/src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor{TPixel}.cs index 5a13619c55..6619ea8927 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor{TPixel}.cs @@ -60,7 +60,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms { Rectangle sourceBounds = this.SourceRectangle; - ParallelRowIterator.IterateRows2( + ParallelRowIterator.IterateRows( targetBounds, configuration, new NearestNeighborRowAction(ref sourceBounds, ref matrix, width, source, destination)); diff --git a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs index 027846fc4e..3eeda1781f 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs @@ -95,7 +95,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms float widthFactor = sourceRectangle.Width / (float)this.targetRectangle.Width; float heightFactor = sourceRectangle.Height / (float)this.targetRectangle.Height; - ParallelRowIterator.IterateRows2( + ParallelRowIterator.IterateRows( interest, configuration, new RowAction(sourceRectangle, this.targetRectangle, widthFactor, heightFactor, source, destination)); diff --git a/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor{TPixel}.cs index 6107c8ef9c..d20954d0f8 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor{TPixel}.cs @@ -131,7 +131,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms /// The configuration. private void Rotate180(ImageFrame source, ImageFrame destination, Configuration configuration) { - ParallelRowIterator.IterateRows2( + ParallelRowIterator.IterateRows( source.Bounds(), configuration, new Rotate180RowAction(source.Width, source.Height, source, destination)); @@ -145,7 +145,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms /// The configuration. private void Rotate270(ImageFrame source, ImageFrame destination, Configuration configuration) { - ParallelRowIterator.IterateRows2( + ParallelRowIterator.IterateRows( source.Bounds(), configuration, new Rotate270RowAction(destination.Bounds(), source.Width, source.Height, source, destination)); @@ -159,7 +159,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms /// The configuration. private void Rotate90(ImageFrame source, ImageFrame destination, Configuration configuration) { - ParallelRowIterator.IterateRows2( + ParallelRowIterator.IterateRows( source.Bounds(), configuration, new Rotate90RowAction(destination.Bounds(), source.Width, source.Height, source, destination));