diff --git a/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs b/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs
index 25eddaf0bb..213ab1b4a7 100644
--- a/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs
+++ b/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs
@@ -60,7 +60,7 @@ namespace SixLabors.ImageSharp.Drawing.Processors
public Point Location { get; }
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
Image disposableImage = null;
Image targetImage = this.Image;
@@ -96,7 +96,7 @@ namespace SixLabors.ImageSharp.Drawing.Processors
Parallel.For(
minY,
maxY,
- source.Configuration().ParallelOptions,
+ configuration.ParallelOptions,
y =>
{
Span background = sourcePixels.GetRowSpan(y).Slice(minX, width);
diff --git a/src/ImageSharp.Drawing/Processors/FillProcessor.cs b/src/ImageSharp.Drawing/Processors/FillProcessor.cs
index c6f11891b9..679ca6a228 100644
--- a/src/ImageSharp.Drawing/Processors/FillProcessor.cs
+++ b/src/ImageSharp.Drawing/Processors/FillProcessor.cs
@@ -40,7 +40,7 @@ namespace SixLabors.ImageSharp.Drawing.Processors
}
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
int startX = sourceRectangle.X;
int endX = sourceRectangle.Right;
@@ -77,7 +77,7 @@ namespace SixLabors.ImageSharp.Drawing.Processors
Parallel.For(
minY,
maxY,
- source.Configuration().ParallelOptions,
+ configuration.ParallelOptions,
y =>
{
int offsetY = y - startY;
diff --git a/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs b/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs
index 1022f63083..6340b1db3e 100644
--- a/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs
+++ b/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs
@@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.Drawing.Processors
public GraphicsOptions Options { get; }
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
Region region = this.Region;
Rectangle rect = region.Bounds;
diff --git a/src/ImageSharp/Advanced/IConfigurable.cs b/src/ImageSharp/Advanced/IConfigurable.cs
new file mode 100644
index 0000000000..347bc9253b
--- /dev/null
+++ b/src/ImageSharp/Advanced/IConfigurable.cs
@@ -0,0 +1,22 @@
+// Copyright (c) Six Labors and contributors.
+// Licensed under the Apache License, Version 2.0.
+
+using System;
+using SixLabors.ImageSharp.Advanced;
+using SixLabors.ImageSharp.Memory;
+using SixLabors.ImageSharp.MetaData;
+using SixLabors.ImageSharp.PixelFormats;
+
+namespace SixLabors.ImageSharp.Advanced
+{
+ ///
+ /// Encapsulates the properties for configuration
+ ///
+ internal interface IConfigurable
+ {
+ ///
+ /// Gets the pixel buffer.
+ ///
+ Configuration Configuration { get; }
+ }
+}
\ No newline at end of file
diff --git a/src/ImageSharp/Advanced/ImageExtensions.cs b/src/ImageSharp/Advanced/ImageExtensions.cs
index fdfbd923a6..135acefa48 100644
--- a/src/ImageSharp/Advanced/ImageExtensions.cs
+++ b/src/ImageSharp/Advanced/ImageExtensions.cs
@@ -80,18 +80,16 @@ namespace SixLabors.ImageSharp.Advanced
/// The Pixel format.
/// The source image
/// Returns the bounds of the image
- public static Configuration Configuration(this ImageFrame source)
+ public static Configuration Configuration(this Image source)
where TPixel : struct, IPixel
- => source?.Parent?.ImageConfiguration ?? SixLabors.ImageSharp.Configuration.Default;
+ => GetConfiguration(source);
///
/// Gets the bounds of the image.
///
- /// The Pixel format.
/// The source image
/// Returns the bounds of the image
- public static Configuration Configuration(this Image source)
- where TPixel : struct, IPixel
- => source?.ImageConfiguration ?? SixLabors.ImageSharp.Configuration.Default;
+ private static Configuration GetConfiguration(IConfigurable source)
+ => source?.Configuration ?? SixLabors.ImageSharp.Configuration.Default;
}
}
diff --git a/src/ImageSharp/Image/ImageFrame{TPixel}.cs b/src/ImageSharp/Image/ImageFrame{TPixel}.cs
index a8cf640e20..bb00ebf115 100644
--- a/src/ImageSharp/Image/ImageFrame{TPixel}.cs
+++ b/src/ImageSharp/Image/ImageFrame{TPixel}.cs
@@ -73,11 +73,6 @@ namespace SixLabors.ImageSharp
///
public int Height => this.pixelBuffer.Height;
- ///
- /// Gets the configuration providing initialization code which allows extending the library.
- ///
- public Image Parent { get; private set; }
-
///
/// Gets the meta data of the frame.
///
@@ -222,7 +217,7 @@ namespace SixLabors.ImageSharp
Parallel.For(
0,
target.Height,
- this.Configuration().ParallelOptions,
+ Configuration.Default.ParallelOptions,
y =>
{
for (int x = 0; x < target.Width; x++)
diff --git a/src/ImageSharp/Image/Image{TPixel}.cs b/src/ImageSharp/Image/Image{TPixel}.cs
index f7ecae375a..f228d766d1 100644
--- a/src/ImageSharp/Image/Image{TPixel}.cs
+++ b/src/ImageSharp/Image/Image{TPixel}.cs
@@ -17,9 +17,11 @@ namespace SixLabors.ImageSharp
/// Encapsulates an image, which consists of the pixel data for a graphics image and its attributes.
///
/// The pixel format.
- public sealed partial class Image : IDisposable
+ public sealed partial class Image : IDisposable, IConfigurable
where TPixel : struct, IPixel
{
+ private Configuration configuration;
+
///
/// Initializes a new instance of the class
/// with the height and the width of the image.
@@ -71,7 +73,7 @@ namespace SixLabors.ImageSharp
/// The frames that will be owned by this image instance.
internal Image(Configuration configuration, int width, int height, ImageMetaData metadata, IEnumerable> frames)
{
- this.ImageConfiguration = configuration ?? Configuration.Default;
+ this.configuration = configuration ?? Configuration.Default;
this.MetaData = metadata ?? new ImageMetaData();
this.Frames = new ImageFrameCollection();
@@ -91,12 +93,9 @@ namespace SixLabors.ImageSharp
}
///
- /// Gets the configuration.
+ /// Gets the pixel buffer.
///
- ///
- /// The configuration.
- ///
- internal Configuration ImageConfiguration { get; }
+ Configuration IConfigurable.Configuration => this.configuration;
///
/// Gets the width.
@@ -158,7 +157,7 @@ namespace SixLabors.ImageSharp
{
IEnumerable> frames = this.Frames.Select(x => x.Clone()).ToArray();
- return new Image(this.ImageConfiguration, this.Width, this.Height, this.MetaData.Clone(), frames);
+ return new Image(this.configuration, this.Width, this.Height, this.MetaData.Clone(), frames);
}
///
@@ -176,7 +175,7 @@ namespace SixLabors.ImageSharp
where TPixel2 : struct, IPixel
{
IEnumerable> frames = this.Frames.Select(x => x.CloneAs()).ToArray();
- var target = new Image(this.ImageConfiguration, this.Width, this.Height, this.MetaData, frames);
+ var target = new Image(this.configuration, this.Width, this.Height, this.MetaData, frames);
return target;
}
diff --git a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs
index 4a2ca38077..d736b91ee6 100644
--- a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs
@@ -48,13 +48,13 @@ namespace SixLabors.ImageSharp.Processing.Processors
public TPixel LowerColor { get; set; }
///
- protected override void BeforeApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void BeforeApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
- new GrayscaleBt709Processor().Apply(source, sourceRectangle);
+ new GrayscaleBt709Processor().Apply(source, sourceRectangle, configuration);
}
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
float threshold = this.Threshold;
TPixel upper = this.UpperColor;
@@ -85,7 +85,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
Parallel.For(
minY,
maxY,
- source.Configuration().ParallelOptions,
+ configuration.ParallelOptions,
y =>
{
Span row = source.GetPixelRowSpan(y - startY);
diff --git a/src/ImageSharp/Processing/Processors/Binarization/ErrorDiffusionDitherProcessor.cs b/src/ImageSharp/Processing/Processors/Binarization/ErrorDiffusionDitherProcessor.cs
index 719a7ea34b..8907770e15 100644
--- a/src/ImageSharp/Processing/Processors/Binarization/ErrorDiffusionDitherProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Binarization/ErrorDiffusionDitherProcessor.cs
@@ -55,13 +55,13 @@ namespace SixLabors.ImageSharp.Processing.Processors
public TPixel LowerColor { get; set; }
///
- protected override void BeforeApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void BeforeApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
- new GrayscaleBt709Processor().Apply(source, sourceRectangle);
+ new GrayscaleBt709Processor().Apply(source, sourceRectangle, configuration);
}
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
var interest = Rectangle.Intersect(sourceRectangle, source.Bounds());
int startY = interest.Y;
diff --git a/src/ImageSharp/Processing/Processors/Binarization/OrderedDitherProcessor.cs b/src/ImageSharp/Processing/Processors/Binarization/OrderedDitherProcessor.cs
index d8b132c6c5..203a64cf16 100644
--- a/src/ImageSharp/Processing/Processors/Binarization/OrderedDitherProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Binarization/OrderedDitherProcessor.cs
@@ -63,13 +63,13 @@ namespace SixLabors.ImageSharp.Processing.Processors
public TPixel LowerColor { get; set; }
///
- protected override void BeforeApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void BeforeApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
- new GrayscaleBt709Processor().Apply(source, sourceRectangle);
+ new GrayscaleBt709Processor().Apply(source, sourceRectangle, configuration);
}
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
var interest = Rectangle.Intersect(sourceRectangle, source.Bounds());
int startY = interest.Y;
diff --git a/src/ImageSharp/Processing/Processors/CloningImageProcessor.cs b/src/ImageSharp/Processing/Processors/CloningImageProcessor.cs
index 1279792dc4..176266ca6e 100644
--- a/src/ImageSharp/Processing/Processors/CloningImageProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/CloningImageProcessor.cs
@@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0.
using System;
-
+using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives;
@@ -27,6 +27,7 @@ namespace SixLabors.ImageSharp.Processing
throw new ImageProcessingException($"An error occured when processing the image using {this.GetType().Name}. The processor changed the number of frames.");
}
+ var configuration = source.Configuration();
this.BeforeImageApply(source, clone, sourceRectangle);
for (int i = 0; i < source.Frames.Count; i++)
@@ -34,10 +35,9 @@ namespace SixLabors.ImageSharp.Processing
ImageFrame sourceFrame = source.Frames[i];
ImageFrame clonedFrame = clone.Frames[i];
- this.BeforeApply(sourceFrame, clonedFrame, sourceRectangle);
-
- this.OnApply(sourceFrame, clonedFrame, sourceRectangle);
- this.AfterApply(sourceFrame, clonedFrame, sourceRectangle);
+ this.BeforeApply(sourceFrame, clonedFrame, sourceRectangle, configuration);
+ this.OnApply(sourceFrame, clonedFrame, sourceRectangle, configuration);
+ this.AfterApply(sourceFrame, clonedFrame, sourceRectangle, configuration);
}
this.AfterImageApply(source, clone, sourceRectangle);
@@ -99,33 +99,30 @@ namespace SixLabors.ImageSharp.Processing
///
/// The source image. Cannot be null.
/// The cloned/destination image. Cannot be null.
- ///
- /// The structure that specifies the portion of the image object to draw.
- ///
- protected virtual void BeforeApply(ImageFrame source, ImageFrame destination, Rectangle sourceRectangle)
+ /// The structure that specifies the portion of the image object to draw.
+ /// The configuration.
+ protected virtual void BeforeApply(ImageFrame source, ImageFrame destination, Rectangle sourceRectangle, Configuration configuration)
{
}
///
- /// Applies the process to the specified portion of the specified at the specified location
+ /// Applies the process to the specified portion of the specified at the specified location
/// and with the specified size.
///
/// The source image. Cannot be null.
/// The cloned/destination image. Cannot be null.
- ///
- /// The structure that specifies the portion of the image object to draw.
- ///
- protected abstract void OnApply(ImageFrame source, ImageFrame destination, Rectangle sourceRectangle);
+ /// The structure that specifies the portion of the image object to draw.
+ /// The configuration.
+ protected abstract void OnApply(ImageFrame source, ImageFrame destination, Rectangle sourceRectangle, Configuration configuration);
///
/// This method is called after the process is applied to prepare the processor.
///
/// The source image. Cannot be null.
/// The cloned/destination image. Cannot be null.
- ///
- /// The structure that specifies the portion of the image object to draw.
- ///
- protected virtual void AfterApply(ImageFrame source, ImageFrame destination, Rectangle sourceRectangle)
+ /// The structure that specifies the portion of the image object to draw.
+ /// The configuration.
+ protected virtual void AfterApply(ImageFrame source, ImageFrame destination, Rectangle sourceRectangle, Configuration configuration)
{
}
diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorMatrixProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorMatrixProcessor.cs
index b48da3a144..4a64bfaa0d 100644
--- a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorMatrixProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorMatrixProcessor.cs
@@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public virtual bool Compand { get; set; } = true;
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
int startY = sourceRectangle.Y;
int endY = sourceRectangle.Bottom;
@@ -54,7 +54,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
Parallel.For(
minY,
maxY,
- source.Configuration().ParallelOptions,
+ configuration.ParallelOptions,
y =>
{
Span row = source.GetPixelRowSpan(y - startY);
diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/LomographProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/LomographProcessor.cs
index 5c702af211..1ec76bf554 100644
--- a/src/ImageSharp/Processing/Processors/ColorMatrix/LomographProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/ColorMatrix/LomographProcessor.cs
@@ -39,9 +39,9 @@ namespace SixLabors.ImageSharp.Processing.Processors
};
///
- protected override void AfterApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void AfterApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
- new VignetteProcessor(VeryDarkGreen, this.options).Apply(source, sourceRectangle);
+ new VignetteProcessor(VeryDarkGreen, this.options).Apply(source, sourceRectangle, configuration);
}
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/PolaroidProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/PolaroidProcessor.cs
index 78e25c147d..f910562e64 100644
--- a/src/ImageSharp/Processing/Processors/ColorMatrix/PolaroidProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/ColorMatrix/PolaroidProcessor.cs
@@ -46,10 +46,10 @@ namespace SixLabors.ImageSharp.Processing.Processors
};
///
- protected override void AfterApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void AfterApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
- new VignetteProcessor(VeryDarkOrange, this.options).Apply(source, sourceRectangle);
- new GlowProcessor(LightOrange, source.Width / 4F, this.options).Apply(source, sourceRectangle);
+ new VignetteProcessor(VeryDarkOrange, this.options).Apply(source, sourceRectangle, configuration);
+ new GlowProcessor(LightOrange, source.Width / 4F, this.options).Apply(source, sourceRectangle, configuration);
}
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs
index 75d134137b..8056141a09 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs
@@ -50,9 +50,9 @@ namespace SixLabors.ImageSharp.Processing.Processors
public Fast2DArray KernelY { get; }
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
- new Convolution2PassProcessor(this.KernelX, this.KernelY).Apply(source, sourceRectangle);
+ new Convolution2PassProcessor(this.KernelX, this.KernelY).Apply(source, sourceRectangle, configuration);
}
///
diff --git a/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs
index 37174c49da..b85432ac54 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs
@@ -40,7 +40,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public Fast2DArray KernelY { get; }
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
int kernelYHeight = this.KernelY.Height;
int kernelYWidth = this.KernelY.Width;
@@ -63,7 +63,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
Parallel.For(
startY,
endY,
- source.Configuration().ParallelOptions,
+ configuration.ParallelOptions,
y =>
{
Span sourceRow = source.GetPixelRowSpan(y);
diff --git a/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs
index 1aeb37862c..362fa5c508 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs
@@ -41,11 +41,11 @@ namespace SixLabors.ImageSharp.Processing.Processors
public Fast2DArray KernelY { get; }
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
int width = source.Width;
int height = source.Height;
- ParallelOptions parallelOptions = source.Configuration().ParallelOptions;
+ ParallelOptions parallelOptions = configuration.ParallelOptions;
using (var firstPassPixels = new PixelAccessor(width, height))
using (PixelAccessor sourcePixels = source.Lock())
diff --git a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs
index f2bc82f3b4..c0d3fdcfec 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs
@@ -33,7 +33,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public Fast2DArray KernelXY { get; }
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
int kernelLength = this.KernelXY.Height;
int radius = kernelLength >> 1;
@@ -52,7 +52,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
Parallel.For(
startY,
endY,
- source.Configuration().ParallelOptions,
+ configuration.ParallelOptions,
y =>
{
Span sourceRow = source.GetPixelRowSpan(y);
diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetector2DProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetector2DProcessor.cs
index 3198ae0a28..f93787d129 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetector2DProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetector2DProcessor.cs
@@ -40,17 +40,17 @@ namespace SixLabors.ImageSharp.Processing.Processors
public bool Grayscale { get; set; }
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
- new Convolution2DProcessor(this.KernelX, this.KernelY).Apply(source, sourceRectangle);
+ new Convolution2DProcessor(this.KernelX, this.KernelY).Apply(source, sourceRectangle, configuration);
}
///
- protected override void BeforeApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void BeforeApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
if (this.Grayscale)
{
- new GrayscaleBt709Processor().Apply(source, sourceRectangle);
+ new GrayscaleBt709Processor().Apply(source, sourceRectangle, configuration);
}
}
}
diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs
index bbe527eb70..32c22a8ce9 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs
@@ -62,16 +62,16 @@ namespace SixLabors.ImageSharp.Processing.Processors
public bool Grayscale { get; set; }
///
- protected override void BeforeApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void BeforeApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
if (this.Grayscale)
{
- new GrayscaleBt709Processor().Apply(source, sourceRectangle);
+ new GrayscaleBt709Processor().Apply(source, sourceRectangle, configuration);
}
}
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
Fast2DArray[] kernels = { this.North, this.NorthWest, this.West, this.SouthWest, this.South, this.SouthEast, this.East, this.NorthEast };
@@ -89,7 +89,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
// we need a clean copy for each pass to start from
using (ImageFrame cleanCopy = source.Clone())
{
- new ConvolutionProcessor(kernels[0]).Apply(source, sourceRectangle);
+ new ConvolutionProcessor(kernels[0]).Apply(source, sourceRectangle, configuration);
if (kernels.Length == 1)
{
@@ -116,7 +116,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
{
using (ImageFrame pass = cleanCopy.Clone())
{
- new ConvolutionProcessor(kernels[i]).Apply(pass, sourceRectangle);
+ new ConvolutionProcessor(kernels[i]).Apply(pass, sourceRectangle, configuration);
using (PixelAccessor passPixels = pass.Lock())
using (PixelAccessor targetPixels = source.Lock())
@@ -124,7 +124,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
Parallel.For(
minY,
maxY,
- source.Configuration().ParallelOptions,
+ configuration.ParallelOptions,
y =>
{
int offsetY = y - shiftY;
diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorProcessor.cs
index d43ee6d64d..3b98b77fc8 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorProcessor.cs
@@ -33,18 +33,18 @@ namespace SixLabors.ImageSharp.Processing.Processors
public Fast2DArray KernelXY { get; }
///
- protected override void BeforeApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void BeforeApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
if (this.Grayscale)
{
- new GrayscaleBt709Processor().Apply(source, sourceRectangle);
+ new GrayscaleBt709Processor().Apply(source, sourceRectangle, configuration);
}
}
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
- new ConvolutionProcessor(this.KernelXY).Apply(source, sourceRectangle);
+ new ConvolutionProcessor(this.KernelXY).Apply(source, sourceRectangle, configuration);
}
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs
index 2a1da29382..c897efeed8 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs
@@ -85,9 +85,9 @@ namespace SixLabors.ImageSharp.Processing.Processors
public Fast2DArray KernelY { get; }
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
- new Convolution2PassProcessor(this.KernelX, this.KernelY).Apply(source, sourceRectangle);
+ new Convolution2PassProcessor(this.KernelX, this.KernelY).Apply(source, sourceRectangle, configuration);
}
///
diff --git a/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs
index 263abbdcf1..b960e9075f 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs
@@ -87,9 +87,9 @@ namespace SixLabors.ImageSharp.Processing.Processors
public Fast2DArray KernelY { get; }
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
- new Convolution2PassProcessor(this.KernelX, this.KernelY).Apply(source, sourceRectangle);
+ new Convolution2PassProcessor(this.KernelX, this.KernelY).Apply(source, sourceRectangle, configuration);
}
///
diff --git a/src/ImageSharp/Processing/Processors/DelegateProcessor.cs b/src/ImageSharp/Processing/Processors/DelegateProcessor.cs
index 7fc70bd79c..f17c39681e 100644
--- a/src/ImageSharp/Processing/Processors/DelegateProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/DelegateProcessor.cs
@@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.Processing
}
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
// NOP, we did all we wanted to do inside BeforeImageApply
}
diff --git a/src/ImageSharp/Processing/Processors/Effects/AlphaProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/AlphaProcessor.cs
index fbc5a15d77..7e5bd02abc 100644
--- a/src/ImageSharp/Processing/Processors/Effects/AlphaProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Effects/AlphaProcessor.cs
@@ -36,7 +36,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public float Value { get; }
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
int startY = sourceRectangle.Y;
int endY = sourceRectangle.Bottom;
@@ -65,7 +65,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
Parallel.For(
minY,
maxY,
- source.Configuration().ParallelOptions,
+ configuration.ParallelOptions,
y =>
{
Span row = source.GetPixelRowSpan(y - startY);
diff --git a/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs
index 9e4813f2b6..72e9b8f555 100644
--- a/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs
@@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public TPixel Value { get; }
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
int startY = sourceRectangle.Y;
int endY = sourceRectangle.Bottom;
@@ -80,7 +80,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
Parallel.For(
minY,
maxY,
- source.Configuration().ParallelOptions,
+ configuration.ParallelOptions,
y =>
{
Span destination = source.GetPixelRowSpan(y - startY).Slice(minX - startX, width);
diff --git a/src/ImageSharp/Processing/Processors/Effects/BrightnessProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/BrightnessProcessor.cs
index 8143d662e4..c864330c9d 100644
--- a/src/ImageSharp/Processing/Processors/Effects/BrightnessProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Effects/BrightnessProcessor.cs
@@ -36,7 +36,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public int Value { get; }
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
float brightness = this.Value / 100F;
@@ -65,7 +65,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
Parallel.For(
minY,
maxY,
- source.Configuration().ParallelOptions,
+ configuration.ParallelOptions,
y =>
{
Span row = source.GetPixelRowSpan(y - startY);
diff --git a/src/ImageSharp/Processing/Processors/Effects/ContrastProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/ContrastProcessor.cs
index 545363e271..5ab2662110 100644
--- a/src/ImageSharp/Processing/Processors/Effects/ContrastProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Effects/ContrastProcessor.cs
@@ -36,7 +36,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public int Value { get; }
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
float contrast = (100F + this.Value) / 100F;
@@ -67,7 +67,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
Parallel.For(
minY,
maxY,
- source.Configuration().ParallelOptions,
+ configuration.ParallelOptions,
y =>
{
Span row = source.GetPixelRowSpan(y - startY);
diff --git a/src/ImageSharp/Processing/Processors/Effects/InvertProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/InvertProcessor.cs
index 3fe179cd80..448025f70a 100644
--- a/src/ImageSharp/Processing/Processors/Effects/InvertProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Effects/InvertProcessor.cs
@@ -18,7 +18,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
where TPixel : struct, IPixel
{
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
int startY = sourceRectangle.Y;
int endY = sourceRectangle.Bottom;
@@ -46,7 +46,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
Parallel.For(
minY,
maxY,
- source.Configuration().ParallelOptions,
+ configuration.ParallelOptions,
y =>
{
Span row = source.GetPixelRowSpan(y - startY);
diff --git a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs
index 88b4a2babe..b22a497987 100644
--- a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs
@@ -48,7 +48,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public int BrushSize { get; }
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
if (this.BrushSize <= 0 || this.BrushSize > source.Height || this.BrushSize > source.Width)
{
@@ -72,7 +72,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
Parallel.For(
startY,
maxY,
- source.Configuration().ParallelOptions,
+ configuration.ParallelOptions,
y =>
{
Span sourceRow = source.GetPixelRowSpan(y);
diff --git a/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs
index 64522b67e5..0ab21f65ac 100644
--- a/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs
@@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public int Size { get; }
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
if (this.Size <= 0 || this.Size > source.Height || this.Size > source.Width)
{
@@ -73,7 +73,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
Parallel.ForEach(
range,
- source.Configuration().ParallelOptions,
+ configuration.ParallelOptions,
y =>
{
int offsetY = y - startY;
diff --git a/src/ImageSharp/Processing/Processors/ImageProcessor.cs b/src/ImageSharp/Processing/Processors/ImageProcessor.cs
index 26e0843059..4799b09951 100644
--- a/src/ImageSharp/Processing/Processors/ImageProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/ImageProcessor.cs
@@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0.
using System;
-
+using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives;
@@ -20,13 +20,12 @@ namespace SixLabors.ImageSharp.Processing
{
try
{
+ var config = source.Configuration();
this.BeforeImageApply(source, sourceRectangle);
foreach (ImageFrame sourceFrame in source.Frames)
{
- this.BeforeApply(sourceFrame, sourceRectangle);
- this.OnApply(sourceFrame, sourceRectangle);
- this.AfterApply(sourceFrame, sourceRectangle);
+ this.Apply(sourceFrame, sourceRectangle, config);
}
this.AfterImageApply(source, sourceRectangle);
@@ -48,13 +47,14 @@ namespace SixLabors.ImageSharp.Processing
///
/// the source image
/// the target
- public void Apply(ImageFrame source, Rectangle sourceRectangle)
+ /// The configuration.
+ public void Apply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
try
{
- this.BeforeApply(source, sourceRectangle);
- this.OnApply(source, sourceRectangle);
- this.AfterApply(source, sourceRectangle);
+ this.BeforeApply(source, sourceRectangle, configuration);
+ this.OnApply(source, sourceRectangle, configuration);
+ this.AfterApply(source, sourceRectangle, configuration);
}
#if DEBUG
catch (Exception)
@@ -72,9 +72,7 @@ namespace SixLabors.ImageSharp.Processing
/// This method is called before the process is applied to prepare the processor.
///
/// The source image. Cannot be null.
- ///
- /// The structure that specifies the portion of the image object to draw.
- ///
+ /// The structure that specifies the portion of the image object to draw.
protected virtual void BeforeImageApply(Image source, Rectangle sourceRectangle)
{
}
@@ -83,31 +81,28 @@ namespace SixLabors.ImageSharp.Processing
/// This method is called before the process is applied to prepare the processor.
///
/// The source image. Cannot be null.
- ///
- /// The structure that specifies the portion of the image object to draw.
- ///
- protected virtual void BeforeApply(ImageFrame source, Rectangle sourceRectangle)
+ /// The structure that specifies the portion of the image object to draw.
+ /// The configuration.
+ protected virtual void BeforeApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
}
///
- /// Applies the process to the specified portion of the specified at the specified location
+ /// Applies the process to the specified portion of the specified at the specified location
/// and with the specified size.
///
/// The source image. Cannot be null.
- ///
- /// The structure that specifies the portion of the image object to draw.
- ///
- protected abstract void OnApply(ImageFrame source, Rectangle sourceRectangle);
+ /// The structure that specifies the portion of the image object to draw.
+ /// The configuration.
+ protected abstract void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration);
///
/// This method is called after the process is applied to prepare the processor.
///
/// The source image. Cannot be null.
- ///
- /// The structure that specifies the portion of the image object to draw.
- ///
- protected virtual void AfterApply(ImageFrame source, Rectangle sourceRectangle)
+ /// The structure that specifies the portion of the image object to draw.
+ /// The configuration.
+ protected virtual void AfterApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
}
@@ -115,9 +110,7 @@ namespace SixLabors.ImageSharp.Processing
/// This method is called after the process is applied to prepare the processor.
///
/// The source image. Cannot be null.
- ///
- /// The structure that specifies the portion of the image object to draw.
- ///
+ /// The structure that specifies the portion of the image object to draw.
protected virtual void AfterImageApply(Image source, Rectangle sourceRectangle)
{
}
diff --git a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs
index d8a611c0fd..b02585d8fd 100644
--- a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs
@@ -52,7 +52,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public ValueSize Radius { get; set; }
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
int startY = sourceRectangle.Y;
int endY = sourceRectangle.Bottom;
@@ -93,7 +93,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
Parallel.For(
minY,
maxY,
- source.Configuration().ParallelOptions,
+ configuration.ParallelOptions,
y =>
{
using (var amounts = new Buffer(width))
diff --git a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs
index c9bfc27cf0..7b592a6a4d 100644
--- a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs
@@ -71,7 +71,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public ValueSize RadiusY { get; set; }
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
int startY = sourceRectangle.Y;
int endY = sourceRectangle.Bottom;
@@ -114,7 +114,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
Parallel.For(
minY,
maxY,
- source.Configuration().ParallelOptions,
+ configuration.ParallelOptions,
y =>
{
using (var amounts = new Buffer(width))
diff --git a/src/ImageSharp/Processing/Processors/Transforms/AutoOrientProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/AutoOrientProcessor.cs
index f18d775f5e..63ccee982e 100644
--- a/src/ImageSharp/Processing/Processors/Transforms/AutoOrientProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Transforms/AutoOrientProcessor.cs
@@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
}
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
// Nothing required here
}
diff --git a/src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs
index 4228bb34bd..2657daaa8a 100644
--- a/src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs
@@ -32,7 +32,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public Rectangle CropRectangle { get; }
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
if (this.CropRectangle == sourceRectangle)
{
@@ -49,7 +49,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
Parallel.For(
minY,
maxY,
- source.Configuration().ParallelOptions,
+ configuration.ParallelOptions,
y =>
{
Span sourceRow = source.GetPixelRowSpan(y).Slice(minX);
diff --git a/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs
index 7ca7008a30..d2a08daba6 100644
--- a/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs
@@ -34,15 +34,15 @@ namespace SixLabors.ImageSharp.Processing.Processors
public float Threshold { get; }
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
using (ImageFrame temp = source.Clone())
{
// Detect the edges.
- new SobelProcessor().Apply(temp, sourceRectangle);
+ new SobelProcessor().Apply(temp, sourceRectangle, configuration);
// Apply threshold binarization filter.
- new BinaryThresholdProcessor(this.Threshold).Apply(temp, sourceRectangle);
+ new BinaryThresholdProcessor(this.Threshold).Apply(temp, sourceRectangle, configuration);
// Search for the first white pixels
Rectangle rectangle = ImageMaths.GetFilteredBoundingRectangle(temp, 0);
@@ -52,7 +52,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
return;
}
- new CropProcessor(rectangle).Apply(source, sourceRectangle);
+ new CropProcessor(rectangle).Apply(source, sourceRectangle, configuration);
}
}
}
diff --git a/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor.cs
index 17ce08318a..de60177f2f 100644
--- a/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor.cs
@@ -32,16 +32,16 @@ namespace SixLabors.ImageSharp.Processing.Processors
public FlipType FlipType { get; }
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
switch (this.FlipType)
{
// No default needed as we have already set the pixels.
case FlipType.Vertical:
- this.FlipX(source);
+ this.FlipX(source, configuration);
break;
case FlipType.Horizontal:
- this.FlipY(source);
+ this.FlipY(source, configuration);
break;
}
}
@@ -51,7 +51,8 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// at half the height of the image.
///
/// The source image to apply the process to.
- private void FlipX(ImageFrame source)
+ /// The configuration.
+ private void FlipX(ImageFrame source, Configuration configuration)
{
int width = source.Width;
int height = source.Height;
@@ -62,7 +63,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
Parallel.For(
0,
halfHeight,
- source.Configuration().ParallelOptions,
+ configuration.ParallelOptions,
y =>
{
int newY = height - y - 1;
@@ -84,7 +85,8 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// at half of the width of the image.
///
/// The source image to apply the process to.
- private void FlipY(ImageFrame source)
+ /// The configuration.
+ private void FlipY(ImageFrame source, Configuration configuration)
{
int width = source.Width;
int height = source.Height;
@@ -95,7 +97,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
Parallel.For(
0,
height,
- source.Configuration().ParallelOptions,
+ configuration.ParallelOptions,
y =>
{
Span sourceRow = source.GetPixelRowSpan(y);
diff --git a/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.cs
index 708d7a273f..781f3a01c7 100644
--- a/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.cs
@@ -137,7 +137,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
}
///
- protected override void BeforeApply(ImageFrame source, ImageFrame destination, Rectangle sourceRectangle)
+ protected override void BeforeApply(ImageFrame source, ImageFrame destination, Rectangle sourceRectangle, Configuration configuration)
{
if (!(this.Sampler is NearestNeighborResampler))
{
@@ -152,9 +152,9 @@ namespace SixLabors.ImageSharp.Processing.Processors
}
///
- protected override void AfterApply(ImageFrame source, ImageFrame destination, Rectangle sourceRectangle)
+ protected override void AfterApply(ImageFrame source, ImageFrame destination, Rectangle sourceRectangle, Configuration configuration)
{
- base.AfterApply(source, destination, sourceRectangle);
+ base.AfterApply(source, destination, sourceRectangle, configuration);
this.HorizontalWeights?.Dispose();
this.HorizontalWeights = null;
this.VerticalWeights?.Dispose();
diff --git a/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs
index 98b8e12897..5dfa343caa 100644
--- a/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs
@@ -66,7 +66,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
}
///
- protected override unsafe void OnApply(ImageFrame source, ImageFrame cloned, Rectangle sourceRectangle)
+ protected override unsafe void OnApply(ImageFrame source, ImageFrame cloned, Rectangle sourceRectangle, Configuration configuration)
{
// Jump out, we'll deal with that later.
if (source.Width == cloned.Width && source.Height == cloned.Height && sourceRectangle == this.ResizeRectangle)
@@ -99,7 +99,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
Parallel.For(
minY,
maxY,
- source.Configuration().ParallelOptions,
+ configuration.ParallelOptions,
y =>
{
// Y coordinates of source points
@@ -128,7 +128,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
Parallel.For(
0,
sourceRectangle.Bottom,
- source.Configuration().ParallelOptions,
+ configuration.ParallelOptions,
y =>
{
// TODO: Without Parallel.For() this buffer object could be reused:
@@ -161,7 +161,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
Parallel.For(
minY,
maxY,
- source.Configuration().ParallelOptions,
+ configuration.ParallelOptions,
y =>
{
// Ensure offsets are normalised for cropping and padding.
diff --git a/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs
index 43bf19d495..a7fb400acc 100644
--- a/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs
@@ -35,9 +35,9 @@ namespace SixLabors.ImageSharp.Processing.Processors
public bool Expand { get; set; } = true;
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
- if (this.OptimizedApply(source))
+ if (this.OptimizedApply(source, configuration))
{
return;
}
@@ -52,7 +52,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
Parallel.For(
0,
height,
- source.Configuration().ParallelOptions,
+ configuration.ParallelOptions,
y =>
{
Span targetRow = targetPixels.GetRowSpan(y);
@@ -73,7 +73,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
}
///
- protected override void BeforeApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void BeforeApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
if (MathF.Abs(this.Angle) < Constants.Epsilon || MathF.Abs(this.Angle - 90) < Constants.Epsilon || MathF.Abs(this.Angle - 180) < Constants.Epsilon || MathF.Abs(this.Angle - 270) < Constants.Epsilon)
{
@@ -91,8 +91,11 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// Rotates the images with an optimized method when the angle is 90, 180 or 270 degrees.
///
/// The source image.
- /// The
- private bool OptimizedApply(ImageFrame source)
+ /// The configuration.
+ ///
+ /// The
+ ///
+ private bool OptimizedApply(ImageFrame source, Configuration configuration)
{
if (MathF.Abs(this.Angle) < Constants.Epsilon)
{
@@ -102,19 +105,19 @@ namespace SixLabors.ImageSharp.Processing.Processors
if (MathF.Abs(this.Angle - 90) < Constants.Epsilon)
{
- this.Rotate90(source);
+ this.Rotate90(source, configuration);
return true;
}
if (MathF.Abs(this.Angle - 180) < Constants.Epsilon)
{
- this.Rotate180(source);
+ this.Rotate180(source, configuration);
return true;
}
if (MathF.Abs(this.Angle - 270) < Constants.Epsilon)
{
- this.Rotate270(source);
+ this.Rotate270(source, configuration);
return true;
}
@@ -125,7 +128,8 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// Rotates the image 270 degrees clockwise at the centre point.
///
/// The source image.
- private void Rotate270(ImageFrame source)
+ /// The configuration.
+ private void Rotate270(ImageFrame source, Configuration configuration)
{
int width = source.Width;
int height = source.Height;
@@ -137,7 +141,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
Parallel.For(
0,
height,
- source.Configuration().ParallelOptions,
+ configuration.ParallelOptions,
y =>
{
for (int x = 0; x < width; x++)
@@ -158,7 +162,8 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// Rotates the image 180 degrees clockwise at the centre point.
///
/// The source image.
- private void Rotate180(ImageFrame source)
+ /// The configuration.
+ private void Rotate180(ImageFrame source, Configuration configuration)
{
int width = source.Width;
int height = source.Height;
@@ -168,7 +173,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
Parallel.For(
0,
height,
- source.Configuration().ParallelOptions,
+ configuration.ParallelOptions,
y =>
{
Span sourceRow = source.GetPixelRowSpan(y);
@@ -188,7 +193,8 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// Rotates the image 90 degrees clockwise at the centre point.
///
/// The source image.
- private void Rotate90(ImageFrame source)
+ /// The configuration.
+ private void Rotate90(ImageFrame source, Configuration configuration)
{
int width = source.Width;
int height = source.Height;
@@ -198,7 +204,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
Parallel.For(
0,
height,
- source.Configuration().ParallelOptions,
+ configuration.ParallelOptions,
y =>
{
Span sourceRow = source.GetPixelRowSpan(y);
diff --git a/src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs
index bafda41db7..316e2a2af3 100644
--- a/src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs
@@ -40,7 +40,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public bool Expand { get; set; } = true;
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
int height = this.CanvasRectangle.Height;
int width = this.CanvasRectangle.Width;
@@ -52,7 +52,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
Parallel.For(
0,
height,
- source.Configuration().ParallelOptions,
+ configuration.ParallelOptions,
y =>
{
Span targetRow = targetPixels.GetRowSpan(y);
@@ -73,7 +73,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
}
///
- protected override void BeforeApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void BeforeApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
this.processMatrix = Matrix3x2Extensions.CreateSkewDegrees(-this.AngleX, -this.AngleY, new Point(0, 0));
if (this.Expand)
diff --git a/tests/ImageSharp.Benchmarks/Samplers/Glow.cs b/tests/ImageSharp.Benchmarks/Samplers/Glow.cs
index 39a6e92119..884ae35017 100644
--- a/tests/ImageSharp.Benchmarks/Samplers/Glow.cs
+++ b/tests/ImageSharp.Benchmarks/Samplers/Glow.cs
@@ -75,7 +75,7 @@ namespace SixLabors.ImageSharp.Benchmarks
public float Radius { get; set; }
///
- protected override void OnApply(ImageFrame source, Rectangle sourceRectangle)
+ protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration)
{
int startY = sourceRectangle.Y;
int endY = sourceRectangle.Bottom;
@@ -114,7 +114,7 @@ namespace SixLabors.ImageSharp.Benchmarks
Parallel.For(
minY,
maxY,
- source.Configuration().ParallelOptions,
+ configuration.ParallelOptions,
y =>
{
int offsetY = y - startY;
diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs
index 86c5994dbf..dbe2523661 100644
--- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs
+++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs
@@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison
{
public static ExactImageComparer Instance { get; } = new ExactImageComparer();
- public override ImageSimilarityReport CompareImagesOrFrames(
+ public override ImageSimilarityReport CompareImagesOrFrames(
ImageFrame expected,
ImageFrame actual)
{
@@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison
}
}
- return new ImageSimilarityReport(expected, actual, differences);
+ return new ImageSimilarityReport(expected, actual, differences);
}
}
}
\ No newline at end of file
diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs
index 8378db4e3c..829bf3d10a 100644
--- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs
+++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs
@@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison
return new TolerantImageComparer(imageThreshold, perPixelManhattanThreshold);
}
- public abstract ImageSimilarityReport CompareImagesOrFrames(
+ public abstract ImageSimilarityReport CompareImagesOrFrames(
ImageFrame expected,
ImageFrame actual)
where TPixelA : struct, IPixel where TPixelB : struct, IPixel;
@@ -30,7 +30,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison
public static class ImageComparerExtensions
{
- public static ImageSimilarityReport CompareImagesOrFrames(
+ public static ImageSimilarityReport CompareImagesOrFrames(
this ImageComparer comparer,
Image expected,
Image actual)
@@ -39,13 +39,13 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison
return comparer.CompareImagesOrFrames((ImageFrame)expected, (ImageFrame)actual);
}
- public static IEnumerable CompareImages(
+ public static IEnumerable> CompareImages(
this ImageComparer comparer,
Image expected,
Image actual)
where TPixelA : struct, IPixel where TPixelB : struct, IPixel
{
- var result = new List();
+ var result = new List>();
if (expected.Frames.Count != actual.Frames.Count)
{
@@ -53,7 +53,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison
}
for (int i = 0; i < expected.Frames.Count; i++)
{
- ImageSimilarityReport report = comparer.CompareImagesOrFrames(expected.Frames[i], actual.Frames[i]);
+ ImageSimilarityReport report = comparer.CompareImagesOrFrames(expected.Frames[i], actual.Frames[i]);
if (!report.IsEmpty)
{
result.Add(report);
@@ -104,10 +104,10 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison
throw new ImagesSimilarityException("Image frame count does not match!");
}
- IEnumerable reports = comparer.CompareImages(expected, actual);
+ IEnumerable> reports = comparer.CompareImages(expected, actual);
if (reports.Any())
{
- List cleanedReports = new List(reports.Count());
+ List> cleanedReports = new List>(reports.Count());
foreach (var r in reports)
{
var outsideChanges = r.Differences.Where(x => !(
@@ -117,7 +117,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison
x.Position.Y <= ignoredRegion.Bottom));
if (outsideChanges.Any())
{
- cleanedReports.Add(new ImageSimilarityReport(r.ExpectedImage, r.ActualImage, outsideChanges, null));
+ cleanedReports.Add(new ImageSimilarityReport(r.ExpectedImage, r.ActualImage, outsideChanges, null));
}
}
diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageSimilarityReport.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageSimilarityReport.cs
index aa61c7f5ac..78e390bbd2 100644
--- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageSimilarityReport.cs
+++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageSimilarityReport.cs
@@ -4,12 +4,13 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
+ using SixLabors.ImageSharp.PixelFormats;
public class ImageSimilarityReport
{
- public ImageSimilarityReport(
- IImageFrame expectedImage,
- IImageFrame actualImage,
+ protected ImageSimilarityReport(
+ object expectedImage,
+ object actualImage,
IEnumerable differences,
float? totalNormalizedDifference = null)
{
@@ -18,9 +19,9 @@
this.TotalNormalizedDifference = totalNormalizedDifference;
this.Differences = differences.ToArray();
}
+ public object ExpectedImage { get; }
- public static ImageSimilarityReport Empty =>
- new ImageSimilarityReport(null, null, Enumerable.Empty(), 0f);
+ public object ActualImage { get; }
// TODO: This should not be a nullable value!
public float? TotalNormalizedDifference { get; }
@@ -29,10 +30,6 @@
? $"{this.TotalNormalizedDifference.Value * 100:0.0000}%"
: "?";
- public IImageFrame ExpectedImage { get; }
-
- public IImageFrame ActualImage { get; }
-
public PixelDifference[] Differences { get; }
public bool IsEmpty => this.Differences.Length == 0;
@@ -41,7 +38,7 @@
{
return this.IsEmpty ? "[SimilarImages]" : this.PrintDifference();
}
-
+
private string PrintDifference()
{
var sb = new StringBuilder();
@@ -66,4 +63,25 @@
return sb.ToString();
}
}
+
+ public class ImageSimilarityReport : ImageSimilarityReport
+ where TPixelA : struct, IPixel
+ where TPixelB : struct, IPixel
+ {
+ public ImageSimilarityReport(
+ ImageFrame expectedImage,
+ ImageFrame actualImage,
+ IEnumerable differences,
+ float? totalNormalizedDifference = null)
+ : base(expectedImage, actualImage, differences, totalNormalizedDifference)
+ {
+ }
+
+ public static ImageSimilarityReport Empty =>
+ new ImageSimilarityReport(null, null, Enumerable.Empty(), 0f);
+
+ public new ImageFrame ExpectedImage => (ImageFrame)base.ExpectedImage;
+
+ public new ImageFrame ActualImage => (ImageFrame)base.ActualImage;
+ }
}
\ No newline at end of file
diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs
index 828c669d52..d20bd72ac1 100644
--- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs
+++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs
@@ -46,7 +46,7 @@
///
public int PerPixelManhattanThreshold { get; }
- public override ImageSimilarityReport CompareImagesOrFrames(ImageFrame expected, ImageFrame actual)
+ public override ImageSimilarityReport CompareImagesOrFrames(ImageFrame expected, ImageFrame actual)
{
if (expected.Size() != actual.Size())
{
@@ -91,11 +91,11 @@
if (normalizedDifference > this.ImageThreshold)
{
- return new ImageSimilarityReport(expected, actual, differences, normalizedDifference);
+ return new ImageSimilarityReport(expected, actual, differences, normalizedDifference);
}
else
{
- return ImageSimilarityReport.Empty;
+ return ImageSimilarityReport.Empty;
}
}