From b62434cea90e9ab8fd705591727929ae78904016 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Thu, 6 Feb 2020 17:16:48 +1100 Subject: [PATCH] Rename class and add native memory profiler --- .../{ParallelUtils => }/IRowIntervalAction.cs | 3 ++- .../IRowIntervalAction{TBuffer}.cs | 9 ++++--- .../ParallelExecutionSettings.cs | 8 +++---- ...rallelHelper.cs => ParallelRowIterator.cs} | 4 ++-- src/ImageSharp/ImageFrame{TPixel}.cs | 4 +--- src/ImageSharp/ImageSharp.csproj | 6 ++--- .../BinaryThresholdProcessor{TPixel}.cs | 4 +--- .../Convolution/BokehBlurProcessor{TPixel}.cs | 11 ++++----- .../Convolution2DProcessor{TPixel}.cs | 5 ++-- .../Convolution2PassProcessor{TPixel}.cs | 5 ++-- .../ConvolutionProcessor{TPixel}.cs | 5 ++-- .../EdgeDetectorCompassProcessor{TPixel}.cs | 5 ++-- .../DrawImageProcessor{TPixelBg,TPixelFg}.cs | 4 +--- .../Effects/OilPaintingProcessor{TPixel}.cs | 4 +--- .../PixelRowDelegateProcessorBase{TPixel}.cs | 3 +-- .../Filters/FilterProcessor{TPixel}.cs | 3 +-- ...lHistogramEqualizationProcessor{TPixel}.cs | 6 ++--- .../BackgroundColorProcessor{TPixel}.cs | 4 +--- .../Overlays/GlowProcessor{TPixel}.cs | 4 +--- .../Overlays/VignetteProcessor{TPixel}.cs | 4 +--- .../AffineTransformProcessor{TPixel}.cs | 5 ++-- .../Transforms/CropProcessor{TPixel}.cs | 3 +-- .../Transforms/FlipProcessor{TPixel}.cs | 4 +--- .../ProjectiveTransformProcessor{TPixel}.cs | 6 ++--- .../Resize/ResizeProcessor{TPixel}.cs | 3 +-- .../Transforms/RotateProcessor{TPixel}.cs | 8 +++---- tests/Directory.Build.targets | 1 + tests/ImageSharp.Benchmarks/Config.cs | 22 +++++++++++++++++ .../ImageSharp.Benchmarks.csproj | 1 + .../Helpers/ParallelExecutionSettingsTests.cs | 2 +- ...erTests.cs => ParallelRowIteratorTests.cs} | 24 +++++++++---------- .../TestUtilities/TestImageExtensions.cs | 3 +-- 32 files changed, 87 insertions(+), 96 deletions(-) rename src/ImageSharp/Advanced/{ParallelUtils => }/IRowIntervalAction.cs (95%) rename src/ImageSharp/Advanced/{ParallelUtils => }/IRowIntervalAction{TBuffer}.cs (88%) rename src/ImageSharp/Advanced/{ParallelUtils => }/ParallelExecutionSettings.cs (95%) rename src/ImageSharp/Advanced/{ParallelUtils/ParallelHelper.cs => ParallelRowIterator.cs} (99%) rename tests/ImageSharp.Tests/Helpers/{ParallelHelperTests.cs => ParallelRowIteratorTests.cs} (94%) diff --git a/src/ImageSharp/Advanced/ParallelUtils/IRowIntervalAction.cs b/src/ImageSharp/Advanced/IRowIntervalAction.cs similarity index 95% rename from src/ImageSharp/Advanced/ParallelUtils/IRowIntervalAction.cs rename to src/ImageSharp/Advanced/IRowIntervalAction.cs index cb38b89bd2..df422a65fb 100644 --- a/src/ImageSharp/Advanced/ParallelUtils/IRowIntervalAction.cs +++ b/src/ImageSharp/Advanced/IRowIntervalAction.cs @@ -5,7 +5,7 @@ using System; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.Memory; -namespace SixLabors.ImageSharp.Advanced.ParallelUtils +namespace SixLabors.ImageSharp.Advanced { /// /// Defines the contract for an action that operates on a row interval. @@ -46,6 +46,7 @@ namespace SixLabors.ImageSharp.Advanced.ParallelUtils private readonly WrappingRowIntervalInfo info; private readonly T action; + [MethodImpl(InliningOptions.ShortMethod)] public WrappingRowIntervalAction(in WrappingRowIntervalInfo info, in T action) { this.info = info; diff --git a/src/ImageSharp/Advanced/ParallelUtils/IRowIntervalAction{TBuffer}.cs b/src/ImageSharp/Advanced/IRowIntervalAction{TBuffer}.cs similarity index 88% rename from src/ImageSharp/Advanced/ParallelUtils/IRowIntervalAction{TBuffer}.cs rename to src/ImageSharp/Advanced/IRowIntervalAction{TBuffer}.cs index 6943405cd3..7b841b9cde 100644 --- a/src/ImageSharp/Advanced/ParallelUtils/IRowIntervalAction{TBuffer}.cs +++ b/src/ImageSharp/Advanced/IRowIntervalAction{TBuffer}.cs @@ -6,7 +6,7 @@ using System.Buffers; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.Memory; -namespace SixLabors.ImageSharp.Advanced.ParallelUtils +namespace SixLabors.ImageSharp.Advanced { /// /// Defines the contract for an action that operates on a row interval with a temporary buffer. @@ -31,6 +31,7 @@ namespace SixLabors.ImageSharp.Advanced.ParallelUtils private readonly MemoryAllocator allocator; private readonly T action; + [MethodImpl(InliningOptions.ShortMethod)] public WrappingRowIntervalAction( in WrappingRowIntervalInfo info, MemoryAllocator allocator, @@ -54,10 +55,8 @@ namespace SixLabors.ImageSharp.Advanced.ParallelUtils int yMax = Math.Min(yMin + this.info.StepY, this.info.MaxY); var rows = new RowInterval(yMin, yMax); - using (IMemoryOwner buffer = this.allocator.Allocate(this.info.MaxX)) - { - this.action.Invoke(in rows, buffer.Memory); - } + using IMemoryOwner buffer = this.allocator.Allocate(this.info.MaxX); + this.action.Invoke(in rows, buffer.Memory); } } } diff --git a/src/ImageSharp/Advanced/ParallelUtils/ParallelExecutionSettings.cs b/src/ImageSharp/Advanced/ParallelExecutionSettings.cs similarity index 95% rename from src/ImageSharp/Advanced/ParallelUtils/ParallelExecutionSettings.cs rename to src/ImageSharp/Advanced/ParallelExecutionSettings.cs index f17d70a2a0..54ee069184 100644 --- a/src/ImageSharp/Advanced/ParallelUtils/ParallelExecutionSettings.cs +++ b/src/ImageSharp/Advanced/ParallelExecutionSettings.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors and contributors. +// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; @@ -6,10 +6,10 @@ using System.Threading.Tasks; using SixLabors.ImageSharp.Memory; -namespace SixLabors.ImageSharp.Advanced.ParallelUtils +namespace SixLabors.ImageSharp.Advanced { /// - /// Defines execution settings for methods in . + /// Defines execution settings for methods in . /// public readonly struct ParallelExecutionSettings { @@ -89,7 +89,7 @@ namespace SixLabors.ImageSharp.Advanced.ParallelUtils } /// - /// Get the default for a + /// Get the default for a /// /// The . /// The . diff --git a/src/ImageSharp/Advanced/ParallelUtils/ParallelHelper.cs b/src/ImageSharp/Advanced/ParallelRowIterator.cs similarity index 99% rename from src/ImageSharp/Advanced/ParallelUtils/ParallelHelper.cs rename to src/ImageSharp/Advanced/ParallelRowIterator.cs index ea975a0ee5..3bc9e1f90b 100644 --- a/src/ImageSharp/Advanced/ParallelUtils/ParallelHelper.cs +++ b/src/ImageSharp/Advanced/ParallelRowIterator.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; using SixLabors.ImageSharp.Memory; -namespace SixLabors.ImageSharp.Advanced.ParallelUtils +namespace SixLabors.ImageSharp.Advanced { /// /// Utility methods for batched processing of pixel row intervals. @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Advanced.ParallelUtils /// or . /// Using this class is preferred over direct usage of utility methods. /// - public static class ParallelHelper + public static class ParallelRowIterator { /// /// Iterate through the rows of a rectangle in optimized batches defined by -s. diff --git a/src/ImageSharp/ImageFrame{TPixel}.cs b/src/ImageSharp/ImageFrame{TPixel}.cs index e1112c0170..88591af69d 100644 --- a/src/ImageSharp/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/ImageFrame{TPixel}.cs @@ -4,9 +4,7 @@ using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Advanced.ParallelUtils; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Metadata; using SixLabors.ImageSharp.PixelFormats; @@ -262,7 +260,7 @@ namespace SixLabors.ImageSharp var target = new ImageFrame(configuration, this.Width, this.Height, this.Metadata.DeepClone()); - ParallelHelper.IterateRows( + ParallelRowIterator.IterateRows( this.Bounds(), configuration, rows => diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj index 0fd449d90f..be0e9032b6 100644 --- a/src/ImageSharp/ImageSharp.csproj +++ b/src/ImageSharp/ImageSharp.csproj @@ -24,9 +24,9 @@ - - - + + + diff --git a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs index 380ce64d24..9bc7f47b11 100644 --- a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs @@ -2,9 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; - using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Advanced.ParallelUtils; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Processing.Processors.Binarization @@ -51,7 +49,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization var workingRect = Rectangle.FromLTRB(startX, startY, endX, endY); - ParallelHelper.IterateRows( + ParallelRowIterator.IterateRows( workingRect, configuration, rows => diff --git a/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs index 316579da70..bb89f03188 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs @@ -7,8 +7,7 @@ using System.Collections.Generic; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - -using SixLabors.ImageSharp.Advanced.ParallelUtils; +using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors.Convolution.Parameters; @@ -342,7 +341,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution var workingRectangle = Rectangle.FromLTRB(startX, startY, endX, endY); int width = workingRectangle.Width; - ParallelHelper.IterateRows( + ParallelRowIterator.IterateRows( workingRectangle, configuration, rows => @@ -389,7 +388,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution var workingRectangle = Rectangle.FromLTRB(startX, startY, endX, endY); int width = workingRectangle.Width; - ParallelHelper.IterateRows( + ParallelRowIterator.IterateRows( workingRectangle, configuration, rows => @@ -428,7 +427,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution int width = workingRectangle.Width; float exp = this.gamma; - ParallelHelper.IterateRowsWithTempBuffer( + ParallelRowIterator.IterateRowsWithTempBuffer( workingRectangle, configuration, (rows, vectorBuffer) => @@ -479,7 +478,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution int width = workingRectangle.Width; float expGamma = 1 / this.gamma; - ParallelHelper.IterateRows( + ParallelRowIterator.IterateRows( workingRectangle, configuration, rows => diff --git a/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor{TPixel}.cs index c2b85a4ab8..431e1c6043 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor{TPixel}.cs @@ -4,8 +4,7 @@ using System; using System.Numerics; using System.Runtime.InteropServices; - -using SixLabors.ImageSharp.Advanced.ParallelUtils; +using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; @@ -79,7 +78,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution var workingRectangle = Rectangle.FromLTRB(startX, startY, endX, endY); int width = workingRectangle.Width; - ParallelHelper.IterateRowsWithTempBuffer( + ParallelRowIterator.IterateRowsWithTempBuffer( workingRectangle, this.Configuration, (rows, vectorBuffer) => diff --git a/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor{TPixel}.cs index 32bdf6bc5c..ce13b4074f 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor{TPixel}.cs @@ -4,8 +4,7 @@ using System; using System.Numerics; using System.Runtime.InteropServices; - -using SixLabors.ImageSharp.Advanced.ParallelUtils; +using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; @@ -98,7 +97,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution var workingRectangle = Rectangle.FromLTRB(startX, startY, endX, endY); int width = workingRectangle.Width; - ParallelHelper.IterateRowsWithTempBuffer( + ParallelRowIterator.IterateRowsWithTempBuffer( workingRectangle, configuration, (rows, vectorBuffer) => diff --git a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs index 285bcab279..faffbd5758 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs @@ -4,8 +4,7 @@ using System; using System.Numerics; using System.Runtime.InteropServices; - -using SixLabors.ImageSharp.Advanced.ParallelUtils; +using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; @@ -69,7 +68,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution var workingRectangle = Rectangle.FromLTRB(startX, startY, endX, endY); int width = workingRectangle.Width; - ParallelHelper.IterateRowsWithTempBuffer( + ParallelRowIterator.IterateRowsWithTempBuffer( workingRectangle, this.Configuration, (rows, vectorBuffer) => diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor{TPixel}.cs index c1897bed8d..1851427589 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor{TPixel}.cs @@ -5,8 +5,7 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - -using SixLabors.ImageSharp.Advanced.ParallelUtils; +using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors.Filters; @@ -109,7 +108,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution Buffer2D passPixels = pass.PixelBuffer; Buffer2D targetPixels = source.PixelBuffer; - ParallelHelper.IterateRows( + ParallelRowIterator.IterateRows( workingRect, this.Configuration, rows => diff --git a/src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs b/src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs index a8b9093e5e..e435013ad6 100644 --- a/src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs +++ b/src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs @@ -2,9 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; - using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Advanced.ParallelUtils; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Processing.Processors.Drawing @@ -99,7 +97,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing "Cannot draw image because the source image does not overlap the target image."); } - ParallelHelper.IterateRows( + ParallelRowIterator.IterateRows( workingRect, configuration, rows => diff --git a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs index 472c07aa7f..b34db8e192 100644 --- a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs @@ -5,9 +5,7 @@ using System; using System.Buffers; using System.Numerics; using System.Runtime.CompilerServices; - using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Advanced.ParallelUtils; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; @@ -63,7 +61,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects source.CopyTo(targetPixels); var workingRect = Rectangle.FromLTRB(startX, startY, endX, endY); - ParallelHelper.IterateRows( + ParallelRowIterator.IterateRows( workingRect, this.Configuration, (rows) => diff --git a/src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessorBase{TPixel}.cs b/src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessorBase{TPixel}.cs index 019509dc23..bca2887832 100644 --- a/src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessorBase{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessorBase{TPixel}.cs @@ -4,7 +4,6 @@ using System; using System.Numerics; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Advanced.ParallelUtils; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Processing.Processors.Effects @@ -40,7 +39,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects Configuration configuration = this.Configuration; PixelConversionModifiers modifiers = this.modifiers; - ParallelHelper.IterateRowsWithTempBuffer( + ParallelRowIterator.IterateRowsWithTempBuffer( interest, this.Configuration, (rows, vectorBuffer) => diff --git a/src/ImageSharp/Processing/Processors/Filters/FilterProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Filters/FilterProcessor{TPixel}.cs index 28a5837dea..64d705a2f7 100644 --- a/src/ImageSharp/Processing/Processors/Filters/FilterProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Filters/FilterProcessor{TPixel}.cs @@ -4,7 +4,6 @@ using System; using System.Numerics; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Advanced.ParallelUtils; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Processing.Processors.Filters @@ -39,7 +38,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters ColorMatrix matrix = this.definition.Matrix; - ParallelHelper.IterateRowsWithTempBuffer( + ParallelRowIterator.IterateRowsWithTempBuffer( interest, this.Configuration, (rows, vectorBuffer) => diff --git a/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs index ff34457fbb..ff68d00497 100644 --- a/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs @@ -6,9 +6,7 @@ using System.Buffers; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Advanced.ParallelUtils; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; @@ -55,7 +53,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization using (IMemoryOwner cdfBuffer = memoryAllocator.Allocate(this.LuminanceLevels, AllocationOptions.Clean)) { // Build the histogram of the grayscale levels. - ParallelHelper.IterateRows( + ParallelRowIterator.IterateRows( workingRect, this.Configuration, rows => @@ -88,7 +86,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization float numberOfPixelsMinusCdfMin = numberOfPixels - cdfMin; // Apply the cdf to each pixel of the image - ParallelHelper.IterateRows( + ParallelRowIterator.IterateRows( workingRect, this.Configuration, rows => diff --git a/src/ImageSharp/Processing/Processors/Overlays/BackgroundColorProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Overlays/BackgroundColorProcessor{TPixel}.cs index c4fabead2b..7423fdbfe3 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/BackgroundColorProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/BackgroundColorProcessor{TPixel}.cs @@ -3,9 +3,7 @@ using System; using System.Buffers; - using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Advanced.ParallelUtils; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; @@ -79,7 +77,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays PixelBlender blender = PixelOperations.Instance.GetPixelBlender(graphicsOptions); - ParallelHelper.IterateRows( + ParallelRowIterator.IterateRows( workingRect, configuration, rows => diff --git a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor{TPixel}.cs index 363e670d02..0032a79839 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor{TPixel}.cs @@ -4,9 +4,7 @@ using System; using System.Buffers; using System.Numerics; - using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Advanced.ParallelUtils; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; @@ -83,7 +81,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays { rowColors.GetSpan().Fill(glowColor); - ParallelHelper.IterateRowsWithTempBuffer( + ParallelRowIterator.IterateRowsWithTempBuffer( workingRect, configuration, (rows, amounts) => diff --git a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor{TPixel}.cs index 3e037189da..95fe35b091 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor{TPixel}.cs @@ -4,9 +4,7 @@ using System; using System.Buffers; using System.Numerics; - using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Advanced.ParallelUtils; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; @@ -87,7 +85,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays { rowColors.GetSpan().Fill(vignetteColor); - ParallelHelper.IterateRowsWithTempBuffer( + ParallelRowIterator.IterateRowsWithTempBuffer( workingRect, configuration, (rows, amounts) => diff --git a/src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor{TPixel}.cs index 1b9ff82bf9..11f8719ef3 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor{TPixel}.cs @@ -4,7 +4,6 @@ using System; using System.Numerics; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Advanced.ParallelUtils; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Processing.Processors.Transforms @@ -58,7 +57,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms if (this.resampler is NearestNeighborResampler) { - ParallelHelper.IterateRows( + ParallelRowIterator.IterateRows( targetBounds, configuration, rows => @@ -85,7 +84,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms try { - ParallelHelper.IterateRowsWithTempBuffer( + ParallelRowIterator.IterateRowsWithTempBuffer( targetBounds, configuration, (rows, vectorBuffer) => diff --git a/src/ImageSharp/Processing/Processors/Transforms/CropProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/CropProcessor{TPixel}.cs index 8d3fec97dc..6baea69ed0 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/CropProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/CropProcessor{TPixel}.cs @@ -4,7 +4,6 @@ using System; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Advanced.ParallelUtils; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; @@ -54,7 +53,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms var rowAction = new RowAction(ref bounds, source, destination); - ParallelHelper.IterateRows( + ParallelRowIterator.IterateRows( bounds, in parallelSettings, in rowAction); diff --git a/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor{TPixel}.cs index d3afc72057..c01cdd8ef4 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor{TPixel}.cs @@ -3,9 +3,7 @@ using System; using System.Buffers; - using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Advanced.ParallelUtils; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Processing.Processors.Transforms @@ -79,7 +77,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms /// The configuration. private void FlipY(ImageFrame source, Configuration configuration) { - ParallelHelper.IterateRows( + ParallelRowIterator.IterateRows( source.Bounds(), configuration, rows => diff --git a/src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor{TPixel}.cs index 56df606a77..b63e7eff3b 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor{TPixel}.cs @@ -3,9 +3,7 @@ using System; using System.Numerics; - using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Advanced.ParallelUtils; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Processing.Processors.Transforms @@ -59,7 +57,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms if (this.resampler is NearestNeighborResampler) { - ParallelHelper.IterateRows( + ParallelRowIterator.IterateRows( targetBounds, configuration, rows => @@ -89,7 +87,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms try { - ParallelHelper.IterateRowsWithTempBuffer( + ParallelRowIterator.IterateRowsWithTempBuffer( targetBounds, configuration, (rows, vectorBuffer) => diff --git a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs index 2e94f88aca..5cfbbcb481 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs @@ -4,7 +4,6 @@ using System; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Advanced.ParallelUtils; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; @@ -101,7 +100,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms float widthFactor = sourceRectangle.Width / (float)this.targetRectangle.Width; float heightFactor = sourceRectangle.Height / (float)this.targetRectangle.Height; - ParallelHelper.IterateRows( + ParallelRowIterator.IterateRows( targetWorkingRect, configuration, rows => diff --git a/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor{TPixel}.cs index 8f1cf28ce4..142068a487 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor{TPixel}.cs @@ -2,9 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; - using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Advanced.ParallelUtils; using SixLabors.ImageSharp.Metadata.Profiles.Exif; using SixLabors.ImageSharp.PixelFormats; @@ -136,7 +134,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms int width = source.Width; int height = source.Height; - ParallelHelper.IterateRows( + ParallelRowIterator.IterateRows( source.Bounds(), configuration, rows => @@ -166,7 +164,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms int height = source.Height; Rectangle destinationBounds = destination.Bounds(); - ParallelHelper.IterateRows( + ParallelRowIterator.IterateRows( source.Bounds(), configuration, rows => @@ -201,7 +199,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms int height = source.Height; Rectangle destinationBounds = destination.Bounds(); - ParallelHelper.IterateRows( + ParallelRowIterator.IterateRows( source.Bounds(), configuration, rows => diff --git a/tests/Directory.Build.targets b/tests/Directory.Build.targets index bacaaa7093..3c3b3b5ece 100644 --- a/tests/Directory.Build.targets +++ b/tests/Directory.Build.targets @@ -26,6 +26,7 @@ + diff --git a/tests/ImageSharp.Benchmarks/Config.cs b/tests/ImageSharp.Benchmarks/Config.cs index fc93fc04e2..6a0aea0ac3 100644 --- a/tests/ImageSharp.Benchmarks/Config.cs +++ b/tests/ImageSharp.Benchmarks/Config.cs @@ -1,8 +1,12 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +#if Windows_NT +using System.Security.Principal; +#endif using BenchmarkDotNet.Configs; using BenchmarkDotNet.Diagnosers; +using BenchmarkDotNet.Diagnostics.Windows; using BenchmarkDotNet.Environments; using BenchmarkDotNet.Jobs; @@ -13,6 +17,14 @@ namespace SixLabors.ImageSharp.Benchmarks public Config() { this.Add(MemoryDiagnoser.Default); + +#if Windows_NT + if (this.IsElevated) + { + this.Add(new NativeMemoryProfiler()); + } +#endif + } public class ShortClr : Config @@ -25,5 +37,15 @@ namespace SixLabors.ImageSharp.Benchmarks Job.Default.With(CoreRuntime.Core21).WithLaunchCount(1).WithWarmupCount(3).WithIterationCount(3)); } } + +#if Windows_NT + private bool IsElevated + { + get + { + return new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator); + } + } +#endif } } diff --git a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj index 60b1fde8e0..3cf0a7da34 100644 --- a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj +++ b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj @@ -19,6 +19,7 @@ + diff --git a/tests/ImageSharp.Tests/Helpers/ParallelExecutionSettingsTests.cs b/tests/ImageSharp.Tests/Helpers/ParallelExecutionSettingsTests.cs index 3cfce6b8e2..fbe259d2bd 100644 --- a/tests/ImageSharp.Tests/Helpers/ParallelExecutionSettingsTests.cs +++ b/tests/ImageSharp.Tests/Helpers/ParallelExecutionSettingsTests.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; -using SixLabors.ImageSharp.Advanced.ParallelUtils; +using SixLabors.ImageSharp.Advanced; using Xunit; namespace SixLabors.ImageSharp.Tests.Helpers diff --git a/tests/ImageSharp.Tests/Helpers/ParallelHelperTests.cs b/tests/ImageSharp.Tests/Helpers/ParallelRowIteratorTests.cs similarity index 94% rename from tests/ImageSharp.Tests/Helpers/ParallelHelperTests.cs rename to tests/ImageSharp.Tests/Helpers/ParallelRowIteratorTests.cs index f9db1a429c..0abc9aa130 100644 --- a/tests/ImageSharp.Tests/Helpers/ParallelHelperTests.cs +++ b/tests/ImageSharp.Tests/Helpers/ParallelRowIteratorTests.cs @@ -7,7 +7,7 @@ using System.Linq; using System.Numerics; using System.Threading; -using SixLabors.ImageSharp.Advanced.ParallelUtils; +using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; @@ -16,11 +16,11 @@ using Xunit.Abstractions; namespace SixLabors.ImageSharp.Tests.Helpers { - public class ParallelHelperTests + public class ParallelRowIteratorTests { private readonly ITestOutputHelper output; - public ParallelHelperTests(ITestOutputHelper output) + public ParallelRowIteratorTests(ITestOutputHelper output) { this.output = output; } @@ -64,7 +64,7 @@ namespace SixLabors.ImageSharp.Tests.Helpers int actualNumberOfSteps = 0; - ParallelHelper.IterateRows( + ParallelRowIterator.IterateRows( rectangle, parallelSettings, rows => @@ -102,7 +102,7 @@ namespace SixLabors.ImageSharp.Tests.Helpers int[] expectedData = Enumerable.Repeat(0, minY).Concat(Enumerable.Range(minY, maxY - minY)).ToArray(); var actualData = new int[maxY]; - ParallelHelper.IterateRows( + ParallelRowIterator.IterateRows( rectangle, parallelSettings, rows => @@ -136,7 +136,7 @@ namespace SixLabors.ImageSharp.Tests.Helpers var bufferHashes = new ConcurrentBag(); int actualNumberOfSteps = 0; - ParallelHelper.IterateRowsWithTempBuffer( + ParallelRowIterator.IterateRowsWithTempBuffer( rectangle, parallelSettings, (RowInterval rows, Memory buffer) => @@ -179,7 +179,7 @@ namespace SixLabors.ImageSharp.Tests.Helpers int[] expectedData = Enumerable.Repeat(0, minY).Concat(Enumerable.Range(minY, maxY - minY)).ToArray(); var actualData = new int[maxY]; - ParallelHelper.IterateRowsWithTempBuffer( + ParallelRowIterator.IterateRowsWithTempBuffer( rectangle, parallelSettings, (RowInterval rows, Memory buffer) => @@ -225,7 +225,7 @@ namespace SixLabors.ImageSharp.Tests.Helpers int actualNumberOfSteps = 0; - ParallelHelper.IterateRows( + ParallelRowIterator.IterateRows( rectangle, parallelSettings, rows => @@ -262,7 +262,7 @@ namespace SixLabors.ImageSharp.Tests.Helpers var rectangle = new Rectangle(0, 0, width, height); int actualNumberOfSteps = 0; - ParallelHelper.IterateRowsWithTempBuffer( + ParallelRowIterator.IterateRowsWithTempBuffer( rectangle, parallelSettings, (RowInterval rows, Memory buffer) => @@ -325,7 +325,7 @@ namespace SixLabors.ImageSharp.Tests.Helpers // Fill actual data using IterateRows: var settings = new ParallelExecutionSettings(maxDegreeOfParallelism, memoryAllocator); - ParallelHelper.IterateRows( + ParallelRowIterator.IterateRows( rect, settings, rows => @@ -354,7 +354,7 @@ namespace SixLabors.ImageSharp.Tests.Helpers var rect = new Rectangle(0, 0, width, height); ArgumentOutOfRangeException ex = Assert.Throws( - () => ParallelHelper.IterateRows(rect, parallelSettings, rows => { })); + () => ParallelRowIterator.IterateRows(rect, parallelSettings, rows => { })); Assert.Contains(width <= 0 ? "Width" : "Height", ex.Message); } @@ -371,7 +371,7 @@ namespace SixLabors.ImageSharp.Tests.Helpers var rect = new Rectangle(0, 0, width, height); ArgumentOutOfRangeException ex = Assert.Throws( - () => ParallelHelper.IterateRowsWithTempBuffer(rect, parallelSettings, (rows, memory) => { })); + () => ParallelRowIterator.IterateRowsWithTempBuffer(rect, parallelSettings, (rows, memory) => { })); Assert.Contains(width <= 0 ? "Width" : "Height", ex.Message); } diff --git a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs index 70d39024e4..4c9318f93b 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs @@ -7,7 +7,6 @@ using System.IO; using System.Numerics; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Advanced.ParallelUtils; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; @@ -703,7 +702,7 @@ namespace SixLabors.ImageSharp.Tests { Rectangle sourceRectangle = this.SourceRectangle; Configuration configuration = this.Configuration; - ParallelHelper.IterateRowsWithTempBuffer( + ParallelRowIterator.IterateRowsWithTempBuffer( sourceRectangle, configuration, (rows, temp) =>