Browse Source

Merge pull request #1070 from SixLabors/js/custom-configuration-fix-650

Allow passing custom Configuration instances to processors
af/merge-core
James Jackson-South 6 years ago
committed by GitHub
parent
commit
a00bf0f8eb
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs
  2. 4
      src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs
  3. 6
      src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor.cs
  4. 7
      src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor{TPixel}.cs
  5. 6
      src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor.cs
  6. 4
      src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor{TPixel}.cs
  7. 6
      src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor.cs
  8. 4
      src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor{TPixel}.cs
  9. 16
      src/ImageSharp/Processing/DefaultImageProcessorContext{TPixel}.cs
  10. 94
      src/ImageSharp/Processing/Extensions/ProcessingExtensions.cs
  11. 7
      src/ImageSharp/Processing/IImageProcessingContext.cs
  12. 11
      src/ImageSharp/Processing/IImageProcessingContextFactory.cs
  13. 6
      src/ImageSharp/Processing/IInternalImageProcessingContext{TPixel}.cs
  14. 4
      src/ImageSharp/Processing/Processors/Binarization/BinaryErrorDiffusionProcessor.cs
  15. 5
      src/ImageSharp/Processing/Processors/Binarization/BinaryErrorDiffusionProcessor{TPixel}.cs
  16. 4
      src/ImageSharp/Processing/Processors/Binarization/BinaryOrderedDitherProcessor.cs
  17. 5
      src/ImageSharp/Processing/Processors/Binarization/BinaryOrderedDitherProcessor{TPixel}.cs
  18. 4
      src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs
  19. 5
      src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs
  20. 6
      src/ImageSharp/Processing/Processors/CloningImageProcessor.cs
  21. 10
      src/ImageSharp/Processing/Processors/CloningImageProcessor{TPixel}.cs
  22. 6
      src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor.cs
  23. 5
      src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs
  24. 8
      src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs
  25. 10
      src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor{TPixel}.cs
  26. 4
      src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor{TPixel}.cs
  27. 4
      src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor{TPixel}.cs
  28. 4
      src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs
  29. 8
      src/ImageSharp/Processing/Processors/Convolution/EdgeDetector2DProcessor{TPixel}.cs
  30. 11
      src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor{TPixel}.cs
  31. 2
      src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorProcessor.cs
  32. 14
      src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorProcessor{TPixel}.cs
  33. 6
      src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs
  34. 11
      src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor{TPixel}.cs
  35. 8
      src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs
  36. 11
      src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor{TPixel}.cs
  37. 7
      src/ImageSharp/Processing/Processors/Convolution/KayyaliProcessor.cs
  38. 6
      src/ImageSharp/Processing/Processors/Convolution/KirschProcessor.cs
  39. 6
      src/ImageSharp/Processing/Processors/Convolution/Laplacian3x3Processor.cs
  40. 6
      src/ImageSharp/Processing/Processors/Convolution/Laplacian5x5Processor.cs
  41. 6
      src/ImageSharp/Processing/Processors/Convolution/LaplacianOfGaussianProcessor.cs
  42. 12
      src/ImageSharp/Processing/Processors/Convolution/PrewittProcessor.cs
  43. 7
      src/ImageSharp/Processing/Processors/Convolution/RobertsCrossProcessor.cs
  44. 6
      src/ImageSharp/Processing/Processors/Convolution/RobinsonProcessor.cs
  45. 12
      src/ImageSharp/Processing/Processors/Convolution/ScharrProcessor.cs
  46. 12
      src/ImageSharp/Processing/Processors/Convolution/SobelProcessor.cs
  47. 4
      src/ImageSharp/Processing/Processors/Dithering/ErrorDiffusionPaletteProcessor.cs
  48. 5
      src/ImageSharp/Processing/Processors/Dithering/ErrorDiffusionPaletteProcessor{TPixel}.cs
  49. 6
      src/ImageSharp/Processing/Processors/Dithering/OrderedDitherPaletteProcessor.cs
  50. 5
      src/ImageSharp/Processing/Processors/Dithering/OrderedDitherPaletteProcessor{TPixel}.cs
  51. 2
      src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessor.cs
  52. 6
      src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessor{TPixel}.cs
  53. 6
      src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs
  54. 5
      src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs
  55. 6
      src/ImageSharp/Processing/Processors/Effects/PixelShaderProcessor.cs
  56. 5
      src/ImageSharp/Processing/Processors/Effects/PixelShaderProcessorBase.cs
  57. 5
      src/ImageSharp/Processing/Processors/Effects/PixelShaderProcessor{TPixel}.cs
  58. 6
      src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs
  59. 5
      src/ImageSharp/Processing/Processors/Effects/PixelateProcessor{TPixel}.cs
  60. 6
      src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelShaderProcessor.cs
  61. 5
      src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelShaderProcessor{TPixel}.cs
  62. 6
      src/ImageSharp/Processing/Processors/Filters/FilterProcessor.cs
  63. 5
      src/ImageSharp/Processing/Processors/Filters/FilterProcessor{TPixel}.cs
  64. 4
      src/ImageSharp/Processing/Processors/Filters/LomographProcessor.cs
  65. 7
      src/ImageSharp/Processing/Processors/Filters/LomographProcessor{TPixel}.cs
  66. 4
      src/ImageSharp/Processing/Processors/Filters/PolaroidProcessor.cs
  67. 10
      src/ImageSharp/Processing/Processors/Filters/PolaroidProcessor{TPixel}.cs
  68. 3
      src/ImageSharp/Processing/Processors/ICloningImageProcessor.cs
  69. 3
      src/ImageSharp/Processing/Processors/IImageProcessor.cs
  70. 11
      src/ImageSharp/Processing/Processors/ImageProcessorExtensions.cs
  71. 5
      src/ImageSharp/Processing/Processors/ImageProcessor{TPixel}.cs
  72. 3
      src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationProcessor.cs
  73. 4
      src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationProcessor{TPixel}.cs
  74. 7
      src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor.cs
  75. 4
      src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs
  76. 7
      src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor.cs
  77. 4
      src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs
  78. 2
      src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor.cs
  79. 5
      src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor{TPixel}.cs
  80. 6
      src/ImageSharp/Processing/Processors/Overlays/BackgroundColorProcessor.cs
  81. 5
      src/ImageSharp/Processing/Processors/Overlays/BackgroundColorProcessor{TPixel}.cs
  82. 6
      src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs
  83. 6
      src/ImageSharp/Processing/Processors/Overlays/GlowProcessor{TPixel}.cs
  84. 6
      src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs
  85. 5
      src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor{TPixel}.cs
  86. 6
      src/ImageSharp/Processing/Processors/Quantization/QuantizeProcessor.cs
  87. 5
      src/ImageSharp/Processing/Processors/Quantization/QuantizeProcessor{TPixel}.cs
  88. 4
      src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor.cs
  89. 5
      src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor{TPixel}.cs
  90. 6
      src/ImageSharp/Processing/Processors/Transforms/AutoOrientProcessor.cs
  91. 23
      src/ImageSharp/Processing/Processors/Transforms/AutoOrientProcessor{TPixel}.cs
  92. 4
      src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs
  93. 5
      src/ImageSharp/Processing/Processors/Transforms/CropProcessor{TPixel}.cs
  94. 6
      src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs
  95. 11
      src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor{TPixel}.cs
  96. 11
      src/ImageSharp/Processing/Processors/Transforms/FlipProcessor.cs
  97. 5
      src/ImageSharp/Processing/Processors/Transforms/FlipProcessor{TPixel}.cs
  98. 4
      src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor.cs
  99. 5
      src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor{TPixel}.cs
  100. 4
      src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor.cs

9
src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs

@ -60,10 +60,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing
public float Opacity { get; } public float Opacity { get; }
/// <inheritdoc /> /// <inheritdoc />
public IImageProcessor<TPixelBg> CreatePixelSpecificProcessor<TPixelBg>(Image<TPixelBg> source, Rectangle sourceRectangle) public IImageProcessor<TPixelBg> CreatePixelSpecificProcessor<TPixelBg>(Configuration configuration, Image<TPixelBg> source, Rectangle sourceRectangle)
where TPixelBg : struct, IPixel<TPixelBg> where TPixelBg : struct, IPixel<TPixelBg>
{ {
var visitor = new ProcessorFactoryVisitor<TPixelBg>(this, source, sourceRectangle); var visitor = new ProcessorFactoryVisitor<TPixelBg>(configuration, this, source, sourceRectangle);
this.Image.AcceptVisitor(visitor); this.Image.AcceptVisitor(visitor);
return visitor.Result; return visitor.Result;
} }
@ -71,12 +71,14 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing
private class ProcessorFactoryVisitor<TPixelBg> : IImageVisitor private class ProcessorFactoryVisitor<TPixelBg> : IImageVisitor
where TPixelBg : struct, IPixel<TPixelBg> where TPixelBg : struct, IPixel<TPixelBg>
{ {
private readonly Configuration configuration;
private readonly DrawImageProcessor definition; private readonly DrawImageProcessor definition;
private readonly Image<TPixelBg> source; private readonly Image<TPixelBg> source;
private readonly Rectangle sourceRectangle; private readonly Rectangle sourceRectangle;
public ProcessorFactoryVisitor(DrawImageProcessor definition, Image<TPixelBg> source, Rectangle sourceRectangle) public ProcessorFactoryVisitor(Configuration configuration, DrawImageProcessor definition, Image<TPixelBg> source, Rectangle sourceRectangle)
{ {
this.configuration = configuration;
this.definition = definition; this.definition = definition;
this.source = source; this.source = source;
this.sourceRectangle = sourceRectangle; this.sourceRectangle = sourceRectangle;
@ -88,6 +90,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing
where TPixelFg : struct, IPixel<TPixelFg> where TPixelFg : struct, IPixel<TPixelFg>
{ {
this.Result = new DrawImageProcessor<TPixelBg, TPixelFg>( this.Result = new DrawImageProcessor<TPixelBg, TPixelFg>(
this.configuration,
image, image,
this.source, this.source,
this.sourceRectangle, this.sourceRectangle,

4
src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs

@ -22,6 +22,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="DrawImageProcessor{TPixelBg, TPixelFg}"/> class. /// Initializes a new instance of the <see cref="DrawImageProcessor{TPixelBg, TPixelFg}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="image">The foreground <see cref="Image{TPixelFg}"/> to blend with the currently processing image.</param> /// <param name="image">The foreground <see cref="Image{TPixelFg}"/> to blend with the currently processing image.</param>
/// <param name="source">The source <see cref="Image{TPixelBg}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixelBg}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
@ -30,6 +31,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing
/// <param name="alphaCompositionMode">The Alpha blending mode to use when drawing the image.</param> /// <param name="alphaCompositionMode">The Alpha blending mode to use when drawing the image.</param>
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param> /// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
public DrawImageProcessor( public DrawImageProcessor(
Configuration configuration,
Image<TPixelFg> image, Image<TPixelFg> image,
Image<TPixelBg> source, Image<TPixelBg> source,
Rectangle sourceRectangle, Rectangle sourceRectangle,
@ -37,7 +39,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing
PixelColorBlendingMode colorBlendingMode, PixelColorBlendingMode colorBlendingMode,
PixelAlphaCompositionMode alphaCompositionMode, PixelAlphaCompositionMode alphaCompositionMode,
float opacity) float opacity)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ {
Guard.MustBeBetweenOrEqualTo(opacity, 0, 1, nameof(opacity)); Guard.MustBeBetweenOrEqualTo(opacity, 0, 1, nameof(opacity));

6
src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor.cs

@ -34,10 +34,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing
public GraphicsOptions Options { get; } public GraphicsOptions Options { get; }
/// <inheritdoc /> /// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => new FillProcessor<TPixel>(configuration, this, source, sourceRectangle);
return new FillProcessor<TPixel>(this, source, sourceRectangle);
}
} }
} }

7
src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor{TPixel}.cs

@ -6,7 +6,6 @@ using System.Buffers;
using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Advanced.ParallelUtils; using SixLabors.ImageSharp.Advanced.ParallelUtils;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives; using SixLabors.Primitives;
@ -21,8 +20,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing
{ {
private readonly FillProcessor definition; private readonly FillProcessor definition;
public FillProcessor(FillProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) public FillProcessor(Configuration configuration, FillProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ {
this.definition = definition; this.definition = definition;
} }
@ -112,7 +111,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing
{ {
solidBrush = this.definition.Brush as SolidBrush; solidBrush = this.definition.Brush as SolidBrush;
if (solidBrush == null) if (solidBrush is null)
{ {
return false; return false;
} }

6
src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor.cs

@ -42,10 +42,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing
public GraphicsOptions Options { get; } public GraphicsOptions Options { get; }
/// <inheritdoc /> /// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => new FillRegionProcessor<TPixel>(configuration, this, source, sourceRectangle);
return new FillRegionProcessor<TPixel>(this, source, sourceRectangle);
}
} }
} }

4
src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor{TPixel}.cs

@ -23,8 +23,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing
{ {
private readonly FillRegionProcessor definition; private readonly FillRegionProcessor definition;
public FillRegionProcessor(FillRegionProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) public FillRegionProcessor(Configuration configuration, FillRegionProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ {
this.definition = definition; this.definition = definition;
} }

6
src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor.cs

@ -72,10 +72,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Text
public PointF Location { get; } public PointF Location { get; }
/// <inheritdoc /> /// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => new DrawTextProcessor<TPixel>(configuration, this, source, sourceRectangle);
return new DrawTextProcessor<TPixel>(this, source, sourceRectangle);
}
} }
} }

4
src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor{TPixel}.cs

@ -27,8 +27,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Text
private readonly DrawTextProcessor definition; private readonly DrawTextProcessor definition;
public DrawTextProcessor(DrawTextProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) public DrawTextProcessor(Configuration configuration, DrawTextProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ {
this.definition = definition; this.definition = definition;
} }

16
src/ImageSharp/Processing/DefaultImageProcessorContext{TPixel}.cs

@ -1,10 +1,8 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors; using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Memory;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing
@ -23,10 +21,12 @@ namespace SixLabors.ImageSharp.Processing
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="DefaultImageProcessorContext{TPixel}"/> class. /// Initializes a new instance of the <see cref="DefaultImageProcessorContext{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="source">The image.</param> /// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="mutate">The mutate.</param> /// <param name="source">The source image.</param>
public DefaultImageProcessorContext(Image<TPixel> source, bool mutate) /// <param name="mutate">Whether to mutate the image.</param>
public DefaultImageProcessorContext(Configuration configuration, Image<TPixel> source, bool mutate)
{ {
this.Configuration = configuration;
this.mutate = mutate; this.mutate = mutate;
this.source = source; this.source = source;
@ -38,7 +38,7 @@ namespace SixLabors.ImageSharp.Processing
} }
/// <inheritdoc/> /// <inheritdoc/>
public MemoryAllocator MemoryAllocator => this.source.GetConfiguration().MemoryAllocator; public Configuration Configuration { get; }
/// <inheritdoc/> /// <inheritdoc/>
public Image<TPixel> GetResultImage() public Image<TPixel> GetResultImage()
@ -71,7 +71,7 @@ namespace SixLabors.ImageSharp.Processing
// interim clone if the first processor in the pipeline is a cloning processor. // interim clone if the first processor in the pipeline is a cloning processor.
if (processor is ICloningImageProcessor cloningImageProcessor) if (processor is ICloningImageProcessor cloningImageProcessor)
{ {
using (ICloningImageProcessor<TPixel> pixelProcessor = cloningImageProcessor.CreatePixelSpecificCloningProcessor(this.source, rectangle)) using (ICloningImageProcessor<TPixel> pixelProcessor = cloningImageProcessor.CreatePixelSpecificCloningProcessor(this.Configuration, this.source, rectangle))
{ {
this.destination = pixelProcessor.CloneAndExecute(); this.destination = pixelProcessor.CloneAndExecute();
return this; return this;
@ -83,7 +83,7 @@ namespace SixLabors.ImageSharp.Processing
} }
// Standard processing pipeline. // Standard processing pipeline.
using (IImageProcessor<TPixel> specificProcessor = processor.CreatePixelSpecificProcessor(this.destination, rectangle)) using (IImageProcessor<TPixel> specificProcessor = processor.CreatePixelSpecificProcessor(this.Configuration, this.destination, rectangle))
{ {
specificProcessor.Execute(); specificProcessor.Execute();
} }

94
src/ImageSharp/Processing/Extensions/ProcessingExtensions.cs

@ -20,12 +20,22 @@ namespace SixLabors.ImageSharp.Processing
/// <param name="source">The image to mutate.</param> /// <param name="source">The image to mutate.</param>
/// <param name="operation">The operation to perform on the source.</param> /// <param name="operation">The operation to perform on the source.</param>
public static void Mutate(this Image source, Action<IImageProcessingContext> operation) public static void Mutate(this Image source, Action<IImageProcessingContext> operation)
=> Mutate(source, source.GetConfiguration(), operation);
/// <summary>
/// Mutates the source image by applying the image operation to it.
/// </summary>
/// <param name="source">The image to mutate.</param>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="operation">The operation to perform on the source.</param>
public static void Mutate(this Image source, Configuration configuration, Action<IImageProcessingContext> operation)
{ {
Guard.NotNull(configuration, nameof(configuration));
Guard.NotNull(source, nameof(source)); Guard.NotNull(source, nameof(source));
Guard.NotNull(operation, nameof(operation)); Guard.NotNull(operation, nameof(operation));
source.EnsureNotDisposed(); source.EnsureNotDisposed();
source.AcceptVisitor(new ProcessingVisitor(operation, true)); source.AcceptVisitor(new ProcessingVisitor(configuration, operation, true));
} }
/// <summary> /// <summary>
@ -36,14 +46,25 @@ namespace SixLabors.ImageSharp.Processing
/// <param name="operation">The operation to perform on the source.</param> /// <param name="operation">The operation to perform on the source.</param>
public static void Mutate<TPixel>(this Image<TPixel> source, Action<IImageProcessingContext> operation) public static void Mutate<TPixel>(this Image<TPixel> source, Action<IImageProcessingContext> operation)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> Mutate(source, source.GetConfiguration(), operation);
/// <summary>
/// Mutates the source image by applying the image operation to it.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image to mutate.</param>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="operation">The operation to perform on the source.</param>
public static void Mutate<TPixel>(this Image<TPixel> source, Configuration configuration, Action<IImageProcessingContext> operation)
where TPixel : struct, IPixel<TPixel>
{ {
Guard.NotNull(configuration, nameof(configuration));
Guard.NotNull(source, nameof(source)); Guard.NotNull(source, nameof(source));
Guard.NotNull(operation, nameof(operation)); Guard.NotNull(operation, nameof(operation));
source.EnsureNotDisposed(); source.EnsureNotDisposed();
IInternalImageProcessingContext<TPixel> operationsRunner IInternalImageProcessingContext<TPixel> operationsRunner
= source.GetConfiguration() = configuration.ImageOperationsProvider.CreateImageProcessingContext(configuration, source, true);
.ImageOperationsProvider.CreateImageProcessingContext(source, true);
operation(operationsRunner); operation(operationsRunner);
} }
@ -56,14 +77,24 @@ namespace SixLabors.ImageSharp.Processing
/// <param name="operations">The operations to perform on the source.</param> /// <param name="operations">The operations to perform on the source.</param>
public static void Mutate<TPixel>(this Image<TPixel> source, params IImageProcessor[] operations) public static void Mutate<TPixel>(this Image<TPixel> source, params IImageProcessor[] operations)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> Mutate(source, source.GetConfiguration(), operations);
/// <summary>
/// Mutates the source image by applying the operations to it.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image to mutate.</param>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="operations">The operations to perform on the source.</param>
public static void Mutate<TPixel>(this Image<TPixel> source, Configuration configuration, params IImageProcessor[] operations)
where TPixel : struct, IPixel<TPixel>
{ {
Guard.NotNull(source, nameof(source)); Guard.NotNull(source, nameof(source));
Guard.NotNull(operations, nameof(operations)); Guard.NotNull(operations, nameof(operations));
source.EnsureNotDisposed(); source.EnsureNotDisposed();
IInternalImageProcessingContext<TPixel> operationsRunner IInternalImageProcessingContext<TPixel> operationsRunner
= source.GetConfiguration() = configuration.ImageOperationsProvider.CreateImageProcessingContext(configuration, source, true);
.ImageOperationsProvider.CreateImageProcessingContext(source, true);
operationsRunner.ApplyProcessors(operations); operationsRunner.ApplyProcessors(operations);
} }
@ -75,12 +106,23 @@ namespace SixLabors.ImageSharp.Processing
/// <param name="operation">The operation to perform on the clone.</param> /// <param name="operation">The operation to perform on the clone.</param>
/// <returns>The new <see cref="SixLabors.ImageSharp.Image"/>.</returns> /// <returns>The new <see cref="SixLabors.ImageSharp.Image"/>.</returns>
public static Image Clone(this Image source, Action<IImageProcessingContext> operation) public static Image Clone(this Image source, Action<IImageProcessingContext> operation)
=> Clone(source, source.GetConfiguration(), operation);
/// <summary>
/// Creates a deep clone of the current image. The clone is then mutated by the given operation.
/// </summary>
/// <param name="source">The image to clone.</param>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="operation">The operation to perform on the clone.</param>
/// <returns>The new <see cref="SixLabors.ImageSharp.Image"/>.</returns>
public static Image Clone(this Image source, Configuration configuration, Action<IImageProcessingContext> operation)
{ {
Guard.NotNull(configuration, nameof(configuration));
Guard.NotNull(source, nameof(source)); Guard.NotNull(source, nameof(source));
Guard.NotNull(operation, nameof(operation)); Guard.NotNull(operation, nameof(operation));
source.EnsureNotDisposed(); source.EnsureNotDisposed();
var visitor = new ProcessingVisitor(operation, false); var visitor = new ProcessingVisitor(configuration, operation, false);
source.AcceptVisitor(visitor); source.AcceptVisitor(visitor);
return visitor.ResultImage; return visitor.ResultImage;
} }
@ -94,14 +136,26 @@ namespace SixLabors.ImageSharp.Processing
/// <returns>The new <see cref="SixLabors.ImageSharp.Image{TPixel}"/></returns> /// <returns>The new <see cref="SixLabors.ImageSharp.Image{TPixel}"/></returns>
public static Image<TPixel> Clone<TPixel>(this Image<TPixel> source, Action<IImageProcessingContext> operation) public static Image<TPixel> Clone<TPixel>(this Image<TPixel> source, Action<IImageProcessingContext> operation)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> Clone(source, source.GetConfiguration(), operation);
/// <summary>
/// Creates a deep clone of the current image. The clone is then mutated by the given operation.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image to clone.</param>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="operation">The operation to perform on the clone.</param>
/// <returns>The new <see cref="SixLabors.ImageSharp.Image{TPixel}"/></returns>
public static Image<TPixel> Clone<TPixel>(this Image<TPixel> source, Configuration configuration, Action<IImageProcessingContext> operation)
where TPixel : struct, IPixel<TPixel>
{ {
Guard.NotNull(configuration, nameof(configuration));
Guard.NotNull(source, nameof(source)); Guard.NotNull(source, nameof(source));
Guard.NotNull(operation, nameof(operation)); Guard.NotNull(operation, nameof(operation));
source.EnsureNotDisposed(); source.EnsureNotDisposed();
IInternalImageProcessingContext<TPixel> operationsRunner IInternalImageProcessingContext<TPixel> operationsRunner
= source.GetConfiguration() = configuration.ImageOperationsProvider.CreateImageProcessingContext(configuration, source, false);
.ImageOperationsProvider.CreateImageProcessingContext(source, false);
operation(operationsRunner); operation(operationsRunner);
return operationsRunner.GetResultImage(); return operationsRunner.GetResultImage();
@ -116,14 +170,26 @@ namespace SixLabors.ImageSharp.Processing
/// <returns>The new <see cref="SixLabors.ImageSharp.Image{TPixel}"/></returns> /// <returns>The new <see cref="SixLabors.ImageSharp.Image{TPixel}"/></returns>
public static Image<TPixel> Clone<TPixel>(this Image<TPixel> source, params IImageProcessor[] operations) public static Image<TPixel> Clone<TPixel>(this Image<TPixel> source, params IImageProcessor[] operations)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> Clone(source, source.GetConfiguration(), operations);
/// <summary>
/// Creates a deep clone of the current image. The clone is then mutated by the given operations.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image to clone.</param>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="operations">The operations to perform on the clone.</param>
/// <returns>The new <see cref="SixLabors.ImageSharp.Image{TPixel}"/></returns>
public static Image<TPixel> Clone<TPixel>(this Image<TPixel> source, Configuration configuration, params IImageProcessor[] operations)
where TPixel : struct, IPixel<TPixel>
{ {
Guard.NotNull(configuration, nameof(configuration));
Guard.NotNull(source, nameof(source)); Guard.NotNull(source, nameof(source));
Guard.NotNull(operations, nameof(operations)); Guard.NotNull(operations, nameof(operations));
source.EnsureNotDisposed(); source.EnsureNotDisposed();
IInternalImageProcessingContext<TPixel> operationsRunner IInternalImageProcessingContext<TPixel> operationsRunner
= source.GetConfiguration() = configuration.ImageOperationsProvider.CreateImageProcessingContext(configuration, source, false);
.ImageOperationsProvider.CreateImageProcessingContext(source, false);
operationsRunner.ApplyProcessors(operations); operationsRunner.ApplyProcessors(operations);
return operationsRunner.GetResultImage(); return operationsRunner.GetResultImage();
@ -149,12 +215,15 @@ namespace SixLabors.ImageSharp.Processing
private class ProcessingVisitor : IImageVisitor private class ProcessingVisitor : IImageVisitor
{ {
private readonly Configuration configuration;
private readonly Action<IImageProcessingContext> operation; private readonly Action<IImageProcessingContext> operation;
private readonly bool mutate; private readonly bool mutate;
public ProcessingVisitor(Action<IImageProcessingContext> operation, bool mutate) public ProcessingVisitor(Configuration configuration, Action<IImageProcessingContext> operation, bool mutate)
{ {
this.configuration = configuration;
this.operation = operation; this.operation = operation;
this.mutate = mutate; this.mutate = mutate;
} }
@ -165,8 +234,7 @@ namespace SixLabors.ImageSharp.Processing
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
IInternalImageProcessingContext<TPixel> operationsRunner = IInternalImageProcessingContext<TPixel> operationsRunner =
image.GetConfiguration() this.configuration.ImageOperationsProvider.CreateImageProcessingContext(this.configuration, image, this.mutate);
.ImageOperationsProvider.CreateImageProcessingContext(image, this.mutate);
this.operation(operationsRunner); this.operation(operationsRunner);
this.ResultImage = operationsRunner.GetResultImage(); this.ResultImage = operationsRunner.GetResultImage();

7
src/ImageSharp/Processing/IImageProcessingContext.cs

@ -13,10 +13,9 @@ namespace SixLabors.ImageSharp.Processing
public interface IImageProcessingContext public interface IImageProcessingContext
{ {
/// <summary> /// <summary>
/// Gets a reference to the <see cref="MemoryAllocator" /> used to allocate buffers /// Gets the configuration which allows altering default behaviour or extending the library.
/// for this context.
/// </summary> /// </summary>
MemoryAllocator MemoryAllocator { get; } Configuration Configuration { get; }
/// <summary> /// <summary>
/// Gets the image dimensions at the current point in the processing pipeline. /// Gets the image dimensions at the current point in the processing pipeline.
@ -39,4 +38,4 @@ namespace SixLabors.ImageSharp.Processing
/// <returns>The current operations class to allow chaining of operations.</returns> /// <returns>The current operations class to allow chaining of operations.</returns>
IImageProcessingContext ApplyProcessor(IImageProcessor processor); IImageProcessingContext ApplyProcessor(IImageProcessor processor);
} }
} }

11
src/ImageSharp/Processing/IImageProcessingContextFactory.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. // Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
@ -14,10 +14,11 @@ namespace SixLabors.ImageSharp.Processing
/// Called during mutate operations to generate the image operations provider. /// Called during mutate operations to generate the image operations provider.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format</typeparam> /// <typeparam name="TPixel">The pixel format</typeparam>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="source">The source image.</param> /// <param name="source">The source image.</param>
/// <param name="mutate">A flag to determine whether image operations are allowed to mutate the source image.</param> /// <param name="mutate">A flag to determine whether image operations are allowed to mutate the source image.</param>
/// <returns>A new <see cref="IInternalImageProcessingContext{TPixel}"/></returns> /// <returns>A new <see cref="IInternalImageProcessingContext{TPixel}"/></returns>
IInternalImageProcessingContext<TPixel> CreateImageProcessingContext<TPixel>(Image<TPixel> source, bool mutate) IInternalImageProcessingContext<TPixel> CreateImageProcessingContext<TPixel>(Configuration configuration, Image<TPixel> source, bool mutate)
where TPixel : struct, IPixel<TPixel>; where TPixel : struct, IPixel<TPixel>;
} }
@ -27,10 +28,10 @@ namespace SixLabors.ImageSharp.Processing
internal class DefaultImageOperationsProviderFactory : IImageProcessingContextFactory internal class DefaultImageOperationsProviderFactory : IImageProcessingContextFactory
{ {
/// <inheritdoc/> /// <inheritdoc/>
public IInternalImageProcessingContext<TPixel> CreateImageProcessingContext<TPixel>(Image<TPixel> source, bool mutate) public IInternalImageProcessingContext<TPixel> CreateImageProcessingContext<TPixel>(Configuration configuration, Image<TPixel> source, bool mutate)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
return new DefaultImageProcessorContext<TPixel>(source, mutate); return new DefaultImageProcessorContext<TPixel>(configuration, source, mutate);
} }
} }
} }

6
src/ImageSharp/Processing/IInternalImageProcessingContext{TPixel}.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. // Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
@ -13,10 +13,10 @@ namespace SixLabors.ImageSharp.Processing
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// Returns the result image to return by <see cref="ProcessingExtensions.Clone"/> /// Returns the result image to return by <see cref="ProcessingExtensions.Clone(Image, Configuration, System.Action{IImageProcessingContext})"/>
/// (and other overloads). /// (and other overloads).
/// </summary> /// </summary>
/// <returns>The current image or a new image depending on whether it is requested to mutate the source image.</returns> /// <returns>The current image or a new image depending on whether it is requested to mutate the source image.</returns>
Image<TPixel> GetResultImage(); Image<TPixel> GetResultImage();
} }
} }

4
src/ImageSharp/Processing/Processors/Binarization/BinaryErrorDiffusionProcessor.cs

@ -70,8 +70,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization
public Color LowerColor { get; } public Color LowerColor { get; }
/// <inheritdoc /> /// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> new BinaryErrorDiffusionProcessor<TPixel>(this, source, sourceRectangle); => new BinaryErrorDiffusionProcessor<TPixel>(configuration, this, source, sourceRectangle);
} }
} }

5
src/ImageSharp/Processing/Processors/Binarization/BinaryErrorDiffusionProcessor{TPixel}.cs

@ -22,11 +22,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="BinaryErrorDiffusionProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="BinaryErrorDiffusionProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="definition">The <see cref="BinaryErrorDiffusionProcessor"/> defining the processor parameters.</param> /// <param name="definition">The <see cref="BinaryErrorDiffusionProcessor"/> defining the processor parameters.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public BinaryErrorDiffusionProcessor(BinaryErrorDiffusionProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) public BinaryErrorDiffusionProcessor(Configuration configuration, BinaryErrorDiffusionProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ {
this.definition = definition; this.definition = definition;
} }

4
src/ImageSharp/Processing/Processors/Binarization/BinaryOrderedDitherProcessor.cs

@ -52,8 +52,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization
public Color LowerColor { get; } public Color LowerColor { get; }
/// <inheritdoc /> /// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> new BinaryOrderedDitherProcessor<TPixel>(this, source, sourceRectangle); => new BinaryOrderedDitherProcessor<TPixel>(configuration, this, source, sourceRectangle);
} }
} }

5
src/ImageSharp/Processing/Processors/Binarization/BinaryOrderedDitherProcessor{TPixel}.cs

@ -22,11 +22,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="BinaryOrderedDitherProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="BinaryOrderedDitherProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="definition">The <see cref="BinaryErrorDiffusionProcessor"/> defining the processor parameters.</param> /// <param name="definition">The <see cref="BinaryErrorDiffusionProcessor"/> defining the processor parameters.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public BinaryOrderedDitherProcessor(BinaryOrderedDitherProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) public BinaryOrderedDitherProcessor(Configuration configuration, BinaryOrderedDitherProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ {
this.definition = definition; this.definition = definition;
} }

4
src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs

@ -50,8 +50,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization
public Color LowerColor { get; } public Color LowerColor { get; }
/// <inheritdoc /> /// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> new BinaryThresholdProcessor<TPixel>(this, source, sourceRectangle); => new BinaryThresholdProcessor<TPixel>(configuration, this, source, sourceRectangle);
} }
} }

5
src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs

@ -22,11 +22,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="BinaryThresholdProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="BinaryThresholdProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="definition">The <see cref="BinaryThresholdProcessor"/> defining the processor parameters.</param> /// <param name="definition">The <see cref="BinaryThresholdProcessor"/> defining the processor parameters.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public BinaryThresholdProcessor(BinaryThresholdProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) public BinaryThresholdProcessor(Configuration configuration, BinaryThresholdProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ {
this.definition = definition; this.definition = definition;
} }

6
src/ImageSharp/Processing/Processors/CloningImageProcessor.cs

@ -12,11 +12,11 @@ namespace SixLabors.ImageSharp.Processing.Processors
public abstract class CloningImageProcessor : ICloningImageProcessor public abstract class CloningImageProcessor : ICloningImageProcessor
{ {
/// <inheritdoc/> /// <inheritdoc/>
public abstract ICloningImageProcessor<TPixel> CreatePixelSpecificCloningProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public abstract ICloningImageProcessor<TPixel> CreatePixelSpecificCloningProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel>; where TPixel : struct, IPixel<TPixel>;
/// <inheritdoc/> /// <inheritdoc/>
IImageProcessor<TPixel> IImageProcessor.CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) IImageProcessor<TPixel> IImageProcessor.CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
=> this.CreatePixelSpecificCloningProcessor(source, sourceRectangle); => this.CreatePixelSpecificCloningProcessor(configuration, source, sourceRectangle);
} }
} }

10
src/ImageSharp/Processing/Processors/CloningImageProcessor{TPixel}.cs

@ -4,7 +4,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives; using SixLabors.Primitives;
@ -22,13 +21,14 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="CloningImageProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="CloningImageProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
protected CloningImageProcessor(Image<TPixel> source, Rectangle sourceRectangle) protected CloningImageProcessor(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
{ {
this.Configuration = configuration;
this.Source = source; this.Source = source;
this.SourceRectangle = sourceRectangle; this.SourceRectangle = sourceRectangle;
this.Configuration = this.Source.GetConfiguration();
} }
/// <summary> /// <summary>
@ -54,7 +54,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
Image<TPixel> clone = this.CreateTarget(); Image<TPixel> clone = this.CreateTarget();
this.CheckFrameCount(this.Source, clone); this.CheckFrameCount(this.Source, clone);
Configuration configuration = this.Source.GetConfiguration(); Configuration configuration = this.Configuration;
this.BeforeImageApply(clone); this.BeforeImageApply(clone);
for (int i = 0; i < this.Source.Frames.Count; i++) for (int i = 0; i < this.Source.Frames.Count; i++)
@ -176,7 +176,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
// We will always be creating the clone even for mutate because we may need to resize the canvas // We will always be creating the clone even for mutate because we may need to resize the canvas
IEnumerable<ImageFrame<TPixel>> frames = source.Frames.Select<ImageFrame<TPixel>, ImageFrame<TPixel>>( IEnumerable<ImageFrame<TPixel>> frames = source.Frames.Select<ImageFrame<TPixel>, ImageFrame<TPixel>>(
x => new ImageFrame<TPixel>( x => new ImageFrame<TPixel>(
source.GetConfiguration(), this.Configuration,
targetSize.Width, targetSize.Width,
targetSize.Height, targetSize.Height,
x.Metadata.DeepClone())); x.Metadata.DeepClone()));

6
src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor.cs

@ -71,10 +71,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
public float Gamma { get; } public float Gamma { get; }
/// <inheritdoc /> /// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => new BokehBlurProcessor<TPixel>(configuration, this, source, sourceRectangle);
return new BokehBlurProcessor<TPixel>(this, source, sourceRectangle);
}
} }
} }

5
src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs

@ -69,11 +69,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="BokehBlurProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="BokehBlurProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="definition">The <see cref="BoxBlurProcessor"/> defining the processor parameters.</param> /// <param name="definition">The <see cref="BoxBlurProcessor"/> defining the processor parameters.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public BokehBlurProcessor(BokehBlurProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) public BokehBlurProcessor(Configuration configuration, BokehBlurProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ {
this.radius = definition.Radius; this.radius = definition.Radius;
this.kernelSize = (this.radius * 2) + 1; this.kernelSize = (this.radius * 2) + 1;

8
src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs

@ -7,7 +7,7 @@ using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors.Convolution namespace SixLabors.ImageSharp.Processing.Processors.Convolution
{ {
/// <summary> /// <summary>
/// Defines a box blur processor of a given Radius. /// Defines a box blur processor of a given radius.
/// </summary> /// </summary>
public sealed class BoxBlurProcessor : IImageProcessor public sealed class BoxBlurProcessor : IImageProcessor
{ {
@ -41,10 +41,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
public int Radius { get; } public int Radius { get; }
/// <inheritdoc /> /// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => new BoxBlurProcessor<TPixel>(configuration, this, source, sourceRectangle);
return new BoxBlurProcessor<TPixel>(this, source, sourceRectangle);
}
} }
} }

10
src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor{TPixel}.cs

@ -14,18 +14,16 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
internal class BoxBlurProcessor<TPixel> : ImageProcessor<TPixel> internal class BoxBlurProcessor<TPixel> : ImageProcessor<TPixel>
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
private readonly BoxBlurProcessor definition;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="BoxBlurProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="BoxBlurProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="definition">The <see cref="BoxBlurProcessor"/> defining the processor parameters.</param> /// <param name="definition">The <see cref="BoxBlurProcessor"/> defining the processor parameters.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public BoxBlurProcessor(BoxBlurProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) public BoxBlurProcessor(Configuration configuration, BoxBlurProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ {
this.definition = definition;
int kernelSize = (definition.Radius * 2) + 1; int kernelSize = (definition.Radius * 2) + 1;
this.KernelX = CreateBoxKernel(kernelSize); this.KernelX = CreateBoxKernel(kernelSize);
this.KernelY = this.KernelX.Transpose(); this.KernelY = this.KernelX.Transpose();
@ -44,7 +42,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnFrameApply(ImageFrame<TPixel> source) protected override void OnFrameApply(ImageFrame<TPixel> source)
{ {
using (var processor = new Convolution2PassProcessor<TPixel>(this.KernelX, this.KernelY, false, this.Source, this.SourceRectangle)) using (var processor = new Convolution2PassProcessor<TPixel>(this.Configuration, this.KernelX, this.KernelY, false, this.Source, this.SourceRectangle))
{ {
processor.Apply(source); processor.Apply(source);
} }

4
src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor{TPixel}.cs

@ -23,18 +23,20 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Convolution2DProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="Convolution2DProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="kernelX">The horizontal gradient operator.</param> /// <param name="kernelX">The horizontal gradient operator.</param>
/// <param name="kernelY">The vertical gradient operator.</param> /// <param name="kernelY">The vertical gradient operator.</param>
/// <param name="preserveAlpha">Whether the convolution filter is applied to alpha as well as the color channels.</param> /// <param name="preserveAlpha">Whether the convolution filter is applied to alpha as well as the color channels.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public Convolution2DProcessor( public Convolution2DProcessor(
Configuration configuration,
in DenseMatrix<float> kernelX, in DenseMatrix<float> kernelX,
in DenseMatrix<float> kernelY, in DenseMatrix<float> kernelY,
bool preserveAlpha, bool preserveAlpha,
Image<TPixel> source, Image<TPixel> source,
Rectangle sourceRectangle) Rectangle sourceRectangle)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ {
Guard.IsTrue(kernelX.Size.Equals(kernelY.Size), $"{nameof(kernelX)} {nameof(kernelY)}", "Kernel sizes must be the same."); Guard.IsTrue(kernelX.Size.Equals(kernelY.Size), $"{nameof(kernelX)} {nameof(kernelY)}", "Kernel sizes must be the same.");
this.KernelX = kernelX; this.KernelX = kernelX;

4
src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor{TPixel}.cs

@ -23,18 +23,20 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Convolution2PassProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="Convolution2PassProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="kernelX">The horizontal gradient operator.</param> /// <param name="kernelX">The horizontal gradient operator.</param>
/// <param name="kernelY">The vertical gradient operator.</param> /// <param name="kernelY">The vertical gradient operator.</param>
/// <param name="preserveAlpha">Whether the convolution filter is applied to alpha as well as the color channels.</param> /// <param name="preserveAlpha">Whether the convolution filter is applied to alpha as well as the color channels.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public Convolution2PassProcessor( public Convolution2PassProcessor(
Configuration configuration,
in DenseMatrix<float> kernelX, in DenseMatrix<float> kernelX,
in DenseMatrix<float> kernelY, in DenseMatrix<float> kernelY,
bool preserveAlpha, bool preserveAlpha,
Image<TPixel> source, Image<TPixel> source,
Rectangle sourceRectangle) Rectangle sourceRectangle)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ {
this.KernelX = kernelX; this.KernelX = kernelX;
this.KernelY = kernelY; this.KernelY = kernelY;

4
src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs

@ -23,16 +23,18 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ConvolutionProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="ConvolutionProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="kernelXY">The 2d gradient operator.</param> /// <param name="kernelXY">The 2d gradient operator.</param>
/// <param name="preserveAlpha">Whether the convolution filter is applied to alpha as well as the color channels.</param> /// <param name="preserveAlpha">Whether the convolution filter is applied to alpha as well as the color channels.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public ConvolutionProcessor( public ConvolutionProcessor(
Configuration configuration,
in DenseMatrix<float> kernelXY, in DenseMatrix<float> kernelXY,
bool preserveAlpha, bool preserveAlpha,
Image<TPixel> source, Image<TPixel> source,
Rectangle sourceRectangle) Rectangle sourceRectangle)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ {
this.KernelXY = kernelXY; this.KernelXY = kernelXY;
this.PreserveAlpha = preserveAlpha; this.PreserveAlpha = preserveAlpha;

8
src/ImageSharp/Processing/Processors/Convolution/EdgeDetector2DProcessor{TPixel}.cs

@ -18,18 +18,20 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="EdgeDetector2DProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="EdgeDetector2DProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="kernelX">The horizontal gradient operator.</param> /// <param name="kernelX">The horizontal gradient operator.</param>
/// <param name="kernelY">The vertical gradient operator.</param> /// <param name="kernelY">The vertical gradient operator.</param>
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param> /// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
internal EdgeDetector2DProcessor( internal EdgeDetector2DProcessor(
Configuration configuration,
in DenseMatrix<float> kernelX, in DenseMatrix<float> kernelX,
in DenseMatrix<float> kernelY, in DenseMatrix<float> kernelY,
bool grayscale, bool grayscale,
Image<TPixel> source, Image<TPixel> source,
Rectangle sourceRectangle) Rectangle sourceRectangle)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ {
Guard.IsTrue(kernelX.Size.Equals(kernelY.Size), $"{nameof(kernelX)} {nameof(kernelY)}", "Kernel sizes must be the same."); Guard.IsTrue(kernelX.Size.Equals(kernelY.Size), $"{nameof(kernelX)} {nameof(kernelY)}", "Kernel sizes must be the same.");
this.KernelX = kernelX; this.KernelX = kernelX;
@ -54,7 +56,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
{ {
if (this.Grayscale) if (this.Grayscale)
{ {
new GrayscaleBt709Processor(1F).Execute(this.Source, this.SourceRectangle); new GrayscaleBt709Processor(1F).Execute(this.Configuration, this.Source, this.SourceRectangle);
} }
base.BeforeImageApply(); base.BeforeImageApply();
@ -63,7 +65,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
/// <inheritdoc /> /// <inheritdoc />
protected override void OnFrameApply(ImageFrame<TPixel> source) protected override void OnFrameApply(ImageFrame<TPixel> source)
{ {
using (var processor = new Convolution2DProcessor<TPixel>(this.KernelX, this.KernelY, true, this.Source, this.SourceRectangle)) using (var processor = new Convolution2DProcessor<TPixel>(this.Configuration, this.KernelX, this.KernelY, true, this.Source, this.SourceRectangle))
{ {
processor.Apply(source); processor.Apply(source);
} }

11
src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor{TPixel}.cs

@ -25,12 +25,13 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="EdgeDetectorCompassProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="EdgeDetectorCompassProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="kernels">Gets the kernels to use.</param> /// <param name="kernels">Gets the kernels to use.</param>
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param> /// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
internal EdgeDetectorCompassProcessor(CompassKernels kernels, bool grayscale, Image<TPixel> source, Rectangle sourceRectangle) internal EdgeDetectorCompassProcessor(Configuration configuration, CompassKernels kernels, bool grayscale, Image<TPixel> source, Rectangle sourceRectangle)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ {
this.Grayscale = grayscale; this.Grayscale = grayscale;
this.Kernels = kernels; this.Kernels = kernels;
@ -45,7 +46,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
{ {
if (this.Grayscale) if (this.Grayscale)
{ {
new GrayscaleBt709Processor(1F).Execute(this.Source, this.SourceRectangle); new GrayscaleBt709Processor(1F).Execute(this.Configuration, this.Source, this.SourceRectangle);
} }
base.BeforeImageApply(); base.BeforeImageApply();
@ -70,7 +71,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
// we need a clean copy for each pass to start from // we need a clean copy for each pass to start from
using (ImageFrame<TPixel> cleanCopy = source.Clone()) using (ImageFrame<TPixel> cleanCopy = source.Clone())
{ {
using (var processor = new ConvolutionProcessor<TPixel>(kernels[0], true, this.Source, this.SourceRectangle)) using (var processor = new ConvolutionProcessor<TPixel>(this.Configuration, kernels[0], true, this.Source, this.SourceRectangle))
{ {
processor.Apply(source); processor.Apply(source);
} }
@ -102,7 +103,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
{ {
using (ImageFrame<TPixel> pass = cleanCopy.Clone()) using (ImageFrame<TPixel> pass = cleanCopy.Clone())
{ {
using (var processor = new ConvolutionProcessor<TPixel>(kernels[i], true, this.Source, this.SourceRectangle)) using (var processor = new ConvolutionProcessor<TPixel>(this.Configuration, kernels[i], true, this.Source, this.SourceRectangle))
{ {
processor.Apply(pass); processor.Apply(pass);
} }

2
src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorProcessor.cs

@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
public bool Grayscale { get; } public bool Grayscale { get; }
/// <inheritdoc /> /// <inheritdoc />
public abstract IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public abstract IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel>; where TPixel : struct, IPixel<TPixel>;
} }
} }

14
src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorProcessor{TPixel}.cs

@ -18,12 +18,18 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="EdgeDetectorProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="EdgeDetectorProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="kernelXY">The 2d gradient operator.</param> /// <param name="kernelXY">The 2d gradient operator.</param>
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param> /// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The target area to process for the current processor instance.</param> /// <param name="sourceRectangle">The target area to process for the current processor instance.</param>
public EdgeDetectorProcessor(in DenseMatrix<float> kernelXY, bool grayscale, Image<TPixel> source, Rectangle sourceRectangle) public EdgeDetectorProcessor(
: base(source, sourceRectangle) Configuration configuration,
in DenseMatrix<float> kernelXY,
bool grayscale,
Image<TPixel> source,
Rectangle sourceRectangle)
: base(configuration, source, sourceRectangle)
{ {
this.KernelXY = kernelXY; this.KernelXY = kernelXY;
this.Grayscale = grayscale; this.Grayscale = grayscale;
@ -41,7 +47,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
{ {
if (this.Grayscale) if (this.Grayscale)
{ {
new GrayscaleBt709Processor(1F).Execute(this.Source, this.SourceRectangle); new GrayscaleBt709Processor(1F).Execute(this.Configuration, this.Source, this.SourceRectangle);
} }
base.BeforeImageApply(); base.BeforeImageApply();
@ -50,7 +56,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnFrameApply(ImageFrame<TPixel> source) protected override void OnFrameApply(ImageFrame<TPixel> source)
{ {
using (var processor = new ConvolutionProcessor<TPixel>(this.KernelXY, true, this.Source, this.SourceRectangle)) using (var processor = new ConvolutionProcessor<TPixel>(this.Configuration, this.KernelXY, true, this.Source, this.SourceRectangle))
{ {
processor.Apply(source); processor.Apply(source);
} }

6
src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs

@ -71,10 +71,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
public int Radius { get; } public int Radius { get; }
/// <inheritdoc /> /// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => new GaussianBlurProcessor<TPixel>(configuration, this, source, sourceRectangle);
return new GaussianBlurProcessor<TPixel>(this, source, sourceRectangle);
}
} }
} }

11
src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor{TPixel}.cs

@ -17,11 +17,16 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="GaussianBlurProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="GaussianBlurProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="definition">The <see cref="GaussianBlurProcessor"/> defining the processor parameters.</param> /// <param name="definition">The <see cref="GaussianBlurProcessor"/> defining the processor parameters.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public GaussianBlurProcessor(GaussianBlurProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) public GaussianBlurProcessor(
: base(source, sourceRectangle) Configuration configuration,
GaussianBlurProcessor definition,
Image<TPixel> source,
Rectangle sourceRectangle)
: base(configuration, source, sourceRectangle)
{ {
int kernelSize = (definition.Radius * 2) + 1; int kernelSize = (definition.Radius * 2) + 1;
this.KernelX = ConvolutionProcessorHelpers.CreateGaussianBlurKernel(kernelSize, definition.Sigma); this.KernelX = ConvolutionProcessorHelpers.CreateGaussianBlurKernel(kernelSize, definition.Sigma);
@ -41,7 +46,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnFrameApply(ImageFrame<TPixel> source) protected override void OnFrameApply(ImageFrame<TPixel> source)
{ {
using (var processor = new Convolution2PassProcessor<TPixel>(this.KernelX, this.KernelY, false, this.Source, this.SourceRectangle)) using (var processor = new Convolution2PassProcessor<TPixel>(this.Configuration, this.KernelX, this.KernelY, false, this.Source, this.SourceRectangle))
{ {
processor.Apply(source); processor.Apply(source);
} }

8
src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs

@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
/// </summary> /// </summary>
public sealed class GaussianSharpenProcessor : IImageProcessor public sealed class GaussianSharpenProcessor : IImageProcessor
{ {
/// <summary> /// <summary>
/// The default value for <see cref="Sigma"/>. /// The default value for <see cref="Sigma"/>.
/// </summary> /// </summary>
public const float DefaultSigma = 3f; public const float DefaultSigma = 3f;
@ -71,10 +71,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
public int Radius { get; } public int Radius { get; }
/// <inheritdoc /> /// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => new GaussianSharpenProcessor<TPixel>(configuration, this, source, sourceRectangle);
return new GaussianSharpenProcessor<TPixel>(this, source, sourceRectangle);
}
} }
} }

11
src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor{TPixel}.cs

@ -17,11 +17,16 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="GaussianSharpenProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="GaussianSharpenProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="definition">The <see cref="GaussianBlurProcessor"/> defining the processor parameters.</param> /// <param name="definition">The <see cref="GaussianBlurProcessor"/> defining the processor parameters.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public GaussianSharpenProcessor(GaussianSharpenProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) public GaussianSharpenProcessor(
: base(source, sourceRectangle) Configuration configuration,
GaussianSharpenProcessor definition,
Image<TPixel> source,
Rectangle sourceRectangle)
: base(configuration, source, sourceRectangle)
{ {
int kernelSize = (definition.Radius * 2) + 1; int kernelSize = (definition.Radius * 2) + 1;
this.KernelX = ConvolutionProcessorHelpers.CreateGaussianSharpenKernel(kernelSize, definition.Sigma); this.KernelX = ConvolutionProcessorHelpers.CreateGaussianSharpenKernel(kernelSize, definition.Sigma);
@ -41,7 +46,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnFrameApply(ImageFrame<TPixel> source) protected override void OnFrameApply(ImageFrame<TPixel> source)
{ {
using (var processor = new Convolution2PassProcessor<TPixel>(this.KernelX, this.KernelY, false, this.Source, this.SourceRectangle)) using (var processor = new Convolution2PassProcessor<TPixel>(this.Configuration, this.KernelX, this.KernelY, false, this.Source, this.SourceRectangle))
{ {
processor.Apply(source); processor.Apply(source);
} }

7
src/ImageSharp/Processing/Processors/Convolution/KayyaliProcessor.cs

@ -21,14 +21,13 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
} }
/// <inheritdoc /> /// <inheritdoc />
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
{ => new EdgeDetector2DProcessor<TPixel>(
return new EdgeDetector2DProcessor<TPixel>( configuration,
KayyaliKernels.KayyaliX, KayyaliKernels.KayyaliX,
KayyaliKernels.KayyaliY, KayyaliKernels.KayyaliY,
this.Grayscale, this.Grayscale,
source, source,
sourceRectangle); sourceRectangle);
}
} }
} }

6
src/ImageSharp/Processing/Processors/Convolution/KirschProcessor.cs

@ -21,9 +21,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
} }
/// <inheritdoc /> /// <inheritdoc />
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
{ => new EdgeDetectorCompassProcessor<TPixel>(configuration, new KirschKernels(), this.Grayscale, source, sourceRectangle);
return new EdgeDetectorCompassProcessor<TPixel>(new KirschKernels(), this.Grayscale, source, sourceRectangle);
}
} }
} }

6
src/ImageSharp/Processing/Processors/Convolution/Laplacian3x3Processor.cs

@ -21,9 +21,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
} }
/// <inheritdoc /> /// <inheritdoc />
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
{ => new EdgeDetectorProcessor<TPixel>(configuration, LaplacianKernels.Laplacian3x3, this.Grayscale, source, sourceRectangle);
return new EdgeDetectorProcessor<TPixel>(LaplacianKernels.Laplacian3x3, this.Grayscale, source, sourceRectangle);
}
} }
} }

6
src/ImageSharp/Processing/Processors/Convolution/Laplacian5x5Processor.cs

@ -21,9 +21,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
} }
/// <inheritdoc /> /// <inheritdoc />
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
{ => new EdgeDetectorProcessor<TPixel>(configuration, LaplacianKernels.Laplacian5x5, this.Grayscale, source, sourceRectangle);
return new EdgeDetectorProcessor<TPixel>(LaplacianKernels.Laplacian5x5, this.Grayscale, source, sourceRectangle);
}
} }
} }

6
src/ImageSharp/Processing/Processors/Convolution/LaplacianOfGaussianProcessor.cs

@ -21,9 +21,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
} }
/// <inheritdoc /> /// <inheritdoc />
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
{ => new EdgeDetectorProcessor<TPixel>(configuration, LaplacianKernels.LaplacianOfGaussianXY, this.Grayscale, source, sourceRectangle);
return new EdgeDetectorProcessor<TPixel>(LaplacianKernels.LaplacianOfGaussianXY, this.Grayscale, source, sourceRectangle);
}
} }
} }

12
src/ImageSharp/Processing/Processors/Convolution/PrewittProcessor.cs

@ -21,9 +21,13 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
} }
/// <inheritdoc /> /// <inheritdoc />
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
{ => new EdgeDetector2DProcessor<TPixel>(
return new EdgeDetector2DProcessor<TPixel>(PrewittKernels.PrewittX, PrewittKernels.PrewittY, this.Grayscale, source, sourceRectangle); configuration,
} PrewittKernels.PrewittX,
PrewittKernels.PrewittY,
this.Grayscale,
source,
sourceRectangle);
} }
} }

7
src/ImageSharp/Processing/Processors/Convolution/RobertsCrossProcessor.cs

@ -21,14 +21,13 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
} }
/// <inheritdoc /> /// <inheritdoc />
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
{ => new EdgeDetector2DProcessor<TPixel>(
return new EdgeDetector2DProcessor<TPixel>( configuration,
RobertsCrossKernels.RobertsCrossX, RobertsCrossKernels.RobertsCrossX,
RobertsCrossKernels.RobertsCrossY, RobertsCrossKernels.RobertsCrossY,
this.Grayscale, this.Grayscale,
source, source,
sourceRectangle); sourceRectangle);
}
} }
} }

6
src/ImageSharp/Processing/Processors/Convolution/RobinsonProcessor.cs

@ -21,9 +21,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
} }
/// <inheritdoc /> /// <inheritdoc />
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
{ => new EdgeDetectorCompassProcessor<TPixel>(configuration, new RobinsonKernels(), this.Grayscale, source, sourceRectangle);
return new EdgeDetectorCompassProcessor<TPixel>(new RobinsonKernels(), this.Grayscale, source, sourceRectangle);
}
} }
} }

12
src/ImageSharp/Processing/Processors/Convolution/ScharrProcessor.cs

@ -21,9 +21,13 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
} }
/// <inheritdoc /> /// <inheritdoc />
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
{ => new EdgeDetector2DProcessor<TPixel>(
return new EdgeDetector2DProcessor<TPixel>(ScharrKernels.ScharrX, ScharrKernels.ScharrY, this.Grayscale, source, sourceRectangle); configuration,
} ScharrKernels.ScharrX,
ScharrKernels.ScharrY,
this.Grayscale,
source,
sourceRectangle);
} }
} }

12
src/ImageSharp/Processing/Processors/Convolution/SobelProcessor.cs

@ -21,9 +21,13 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
} }
/// <inheritdoc /> /// <inheritdoc />
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
{ => new EdgeDetector2DProcessor<TPixel>(
return new EdgeDetector2DProcessor<TPixel>(SobelKernels.SobelX, SobelKernels.SobelY, this.Grayscale, source, sourceRectangle); configuration,
} SobelKernels.SobelX,
SobelKernels.SobelY,
this.Grayscale,
source,
sourceRectangle);
} }
} }

4
src/ImageSharp/Processing/Processors/Dithering/ErrorDiffusionPaletteProcessor.cs

@ -58,9 +58,9 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
public float Threshold { get; } public float Threshold { get; }
/// <inheritdoc /> /// <inheritdoc />
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
{ {
return new ErrorDiffusionPaletteProcessor<TPixel>(this, source, sourceRectangle); return new ErrorDiffusionPaletteProcessor<TPixel>(configuration, this, source, sourceRectangle);
} }
} }
} }

5
src/ImageSharp/Processing/Processors/Dithering/ErrorDiffusionPaletteProcessor{TPixel}.cs

@ -19,11 +19,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ErrorDiffusionPaletteProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="ErrorDiffusionPaletteProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="definition">The <see cref="ErrorDiffusionPaletteProcessor"/> defining the processor parameters.</param> /// <param name="definition">The <see cref="ErrorDiffusionPaletteProcessor"/> defining the processor parameters.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public ErrorDiffusionPaletteProcessor(ErrorDiffusionPaletteProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) public ErrorDiffusionPaletteProcessor(Configuration configuration, ErrorDiffusionPaletteProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(definition, source, sourceRectangle) : base(configuration, definition, source, sourceRectangle)
{ {
} }

6
src/ImageSharp/Processing/Processors/Dithering/OrderedDitherPaletteProcessor.cs

@ -35,9 +35,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
public IOrderedDither Dither { get; } public IOrderedDither Dither { get; }
/// <inheritdoc /> /// <inheritdoc />
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
{ => new OrderedDitherPaletteProcessor<TPixel>(configuration, this, source, sourceRectangle);
return new OrderedDitherPaletteProcessor<TPixel>(this, source, sourceRectangle);
}
} }
} }

5
src/ImageSharp/Processing/Processors/Dithering/OrderedDitherPaletteProcessor{TPixel}.cs

@ -19,11 +19,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="OrderedDitherPaletteProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="OrderedDitherPaletteProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="definition">The <see cref="OrderedDitherPaletteProcessor"/> defining the processor parameters.</param> /// <param name="definition">The <see cref="OrderedDitherPaletteProcessor"/> defining the processor parameters.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public OrderedDitherPaletteProcessor(OrderedDitherPaletteProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) public OrderedDitherPaletteProcessor(Configuration configuration, OrderedDitherPaletteProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(definition, source, sourceRectangle) : base(configuration, definition, source, sourceRectangle)
{ {
} }

2
src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessor.cs

@ -28,7 +28,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
public ReadOnlyMemory<Color> Palette { get; } public ReadOnlyMemory<Color> Palette { get; }
/// <inheritdoc /> /// <inheritdoc />
public abstract IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public abstract IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel>; where TPixel : struct, IPixel<TPixel>;
} }
} }

6
src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessor{TPixel}.cs

@ -8,7 +8,6 @@ using System.Numerics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Memory;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors.Dithering namespace SixLabors.ImageSharp.Processing.Processors.Dithering
@ -29,11 +28,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PaletteDitherProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="PaletteDitherProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="definition">The <see cref="PaletteDitherProcessor"/> defining the processor parameters.</param> /// <param name="definition">The <see cref="PaletteDitherProcessor"/> defining the processor parameters.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
protected PaletteDitherProcessor(PaletteDitherProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) protected PaletteDitherProcessor(Configuration configuration, PaletteDitherProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ {
this.Definition = definition; this.Definition = definition;
this.palette = this.Configuration.MemoryAllocator.Allocate<TPixel>(definition.Palette.Length); this.palette = this.Configuration.MemoryAllocator.Allocate<TPixel>(definition.Palette.Length);

6
src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs

@ -40,10 +40,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
public int BrushSize { get; } public int BrushSize { get; }
/// <inheritdoc /> /// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => new OilPaintingProcessor<TPixel>(configuration, this, source, sourceRectangle);
return new OilPaintingProcessor<TPixel>(this, source, sourceRectangle);
}
} }
} }

5
src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs

@ -25,11 +25,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="OilPaintingProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="OilPaintingProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="definition">The <see cref="OilPaintingProcessor"/> defining the processor parameters.</param> /// <param name="definition">The <see cref="OilPaintingProcessor"/> defining the processor parameters.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public OilPaintingProcessor(OilPaintingProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) public OilPaintingProcessor(Configuration configuration, OilPaintingProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ {
this.definition = definition; this.definition = definition;
} }

6
src/ImageSharp/Processing/Processors/Effects/PixelShaderProcessor.cs

@ -52,10 +52,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
public PixelConversionModifiers Modifiers { get; } public PixelConversionModifiers Modifiers { get; }
/// <inheritdoc /> /// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => new PixelShaderProcessor<TPixel>(configuration, this, source, sourceRectangle);
return new PixelShaderProcessor<TPixel>(this, source, sourceRectangle);
}
} }
} }

5
src/ImageSharp/Processing/Processors/Effects/PixelShaderProcessorBase.cs

@ -26,11 +26,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PixelShaderProcessorBase{TPixel}"/> class. /// Initializes a new instance of the <see cref="PixelShaderProcessorBase{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param> /// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
protected PixelShaderProcessorBase(PixelConversionModifiers modifiers, Image<TPixel> source, Rectangle sourceRectangle) protected PixelShaderProcessorBase(Configuration configuration, PixelConversionModifiers modifiers, Image<TPixel> source, Rectangle sourceRectangle)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ {
this.modifiers = modifiers; this.modifiers = modifiers;
} }

5
src/ImageSharp/Processing/Processors/Effects/PixelShaderProcessor{TPixel}.cs

@ -24,11 +24,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PixelShaderProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="PixelShaderProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="definition">The <see cref="PixelShaderProcessor"/> defining the processor parameters.</param> /// <param name="definition">The <see cref="PixelShaderProcessor"/> defining the processor parameters.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public PixelShaderProcessor(PixelShaderProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) public PixelShaderProcessor(Configuration configuration, PixelShaderProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(definition.Modifiers, source, sourceRectangle) : base(configuration, definition.Modifiers, source, sourceRectangle)
{ {
this.pixelShader = definition.PixelShader; this.pixelShader = definition.PixelShader;
} }

6
src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs

@ -30,10 +30,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
public int Size { get; } public int Size { get; }
/// <inheritdoc /> /// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => new PixelateProcessor<TPixel>(configuration, this, source, sourceRectangle);
return new PixelateProcessor<TPixel>(this, source, sourceRectangle);
}
} }
} }

5
src/ImageSharp/Processing/Processors/Effects/PixelateProcessor{TPixel}.cs

@ -24,11 +24,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PixelateProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="PixelateProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="definition">The <see cref="PixelateProcessor"/>.</param> /// <param name="definition">The <see cref="PixelateProcessor"/>.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public PixelateProcessor(PixelateProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) public PixelateProcessor(Configuration configuration, PixelateProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ {
this.definition = definition; this.definition = definition;
} }

6
src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelShaderProcessor.cs

@ -52,10 +52,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
public PixelConversionModifiers Modifiers { get; } public PixelConversionModifiers Modifiers { get; }
/// <inheritdoc /> /// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => new PositionAwarePixelShaderProcessor<TPixel>(configuration, this, source, sourceRectangle);
return new PositionAwarePixelShaderProcessor<TPixel>(this, source, sourceRectangle);
}
} }
} }

5
src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelShaderProcessor{TPixel}.cs

@ -24,11 +24,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PositionAwarePixelShaderProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="PositionAwarePixelShaderProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="definition">The <see cref="PositionAwarePixelShaderProcessor"/> defining the processor parameters.</param> /// <param name="definition">The <see cref="PositionAwarePixelShaderProcessor"/> defining the processor parameters.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public PositionAwarePixelShaderProcessor(PositionAwarePixelShaderProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) public PositionAwarePixelShaderProcessor(Configuration configuration, PositionAwarePixelShaderProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(definition.Modifiers, source, sourceRectangle) : base(configuration, definition.Modifiers, source, sourceRectangle)
{ {
this.pixelShader = definition.PixelShader; this.pixelShader = definition.PixelShader;
} }

6
src/ImageSharp/Processing/Processors/Filters/FilterProcessor.cs

@ -24,10 +24,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
public ColorMatrix Matrix { get; } public ColorMatrix Matrix { get; }
/// <inheritdoc /> /// <inheritdoc />
public virtual IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public virtual IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => new FilterProcessor<TPixel>(configuration, this, source, sourceRectangle);
return new FilterProcessor<TPixel>(this, source, sourceRectangle);
}
} }
} }

5
src/ImageSharp/Processing/Processors/Filters/FilterProcessor{TPixel}.cs

@ -23,11 +23,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="FilterProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="FilterProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="definition">The <see cref="FilterProcessor"/>.</param> /// <param name="definition">The <see cref="FilterProcessor"/>.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public FilterProcessor(FilterProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) public FilterProcessor(Configuration configuration, FilterProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ {
this.definition = definition; this.definition = definition;
} }

4
src/ImageSharp/Processing/Processors/Filters/LomographProcessor.cs

@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
} }
/// <inheritdoc /> /// <inheritdoc />
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) => public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle) =>
new LomographProcessor<TPixel>(this, source, sourceRectangle); new LomographProcessor<TPixel>(configuration, this, source, sourceRectangle);
} }
} }

7
src/ImageSharp/Processing/Processors/Filters/LomographProcessor{TPixel}.cs

@ -18,18 +18,19 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="LomographProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="LomographProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="definition">The <see cref="LomographProcessor"/> defining the parameters.</param> /// <param name="definition">The <see cref="LomographProcessor"/> defining the parameters.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public LomographProcessor(LomographProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) public LomographProcessor(Configuration configuration, LomographProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(definition, source, sourceRectangle) : base(configuration, definition, source, sourceRectangle)
{ {
} }
/// <inheritdoc/> /// <inheritdoc/>
protected override void AfterImageApply() protected override void AfterImageApply()
{ {
new VignetteProcessor(VeryDarkGreen).Execute(this.Source, this.SourceRectangle); new VignetteProcessor(VeryDarkGreen).Execute(this.Configuration, this.Source, this.SourceRectangle);
base.AfterImageApply(); base.AfterImageApply();
} }
} }

4
src/ImageSharp/Processing/Processors/Filters/PolaroidProcessor.cs

@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
} }
/// <inheritdoc /> /// <inheritdoc />
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) => public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle) =>
new PolaroidProcessor<TPixel>(this, source, sourceRectangle); new PolaroidProcessor<TPixel>(configuration, this, source, sourceRectangle);
} }
} }

10
src/ImageSharp/Processing/Processors/Filters/PolaroidProcessor{TPixel}.cs

@ -14,25 +14,25 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
private static readonly Color LightOrange = Color.FromRgba(255, 153, 102, 128); private static readonly Color LightOrange = Color.FromRgba(255, 153, 102, 128);
private static readonly Color VeryDarkOrange = Color.FromRgb(102, 34, 0); private static readonly Color VeryDarkOrange = Color.FromRgb(102, 34, 0);
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PolaroidProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="PolaroidProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="definition">The <see cref="PolaroidProcessor"/> defining the parameters.</param> /// <param name="definition">The <see cref="PolaroidProcessor"/> defining the parameters.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public PolaroidProcessor(PolaroidProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) public PolaroidProcessor(Configuration configuration, PolaroidProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(definition, source, sourceRectangle) : base(configuration, definition, source, sourceRectangle)
{ {
} }
/// <inheritdoc/> /// <inheritdoc/>
protected override void AfterImageApply() protected override void AfterImageApply()
{ {
new VignetteProcessor(VeryDarkOrange).Execute(this.Source, this.SourceRectangle); new VignetteProcessor(VeryDarkOrange).Execute(this.Configuration, this.Source, this.SourceRectangle);
new GlowProcessor(LightOrange, this.Source.Width / 4F).Execute(this.Source, this.SourceRectangle); new GlowProcessor(LightOrange, this.Source.Width / 4F).Execute(this.Configuration, this.Source, this.SourceRectangle);
base.AfterImageApply(); base.AfterImageApply();
} }
} }

3
src/ImageSharp/Processing/Processors/ICloningImageProcessor.cs

@ -16,12 +16,13 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// the processing algorithm on an <see cref="Image{TPixel}"/>. /// the processing algorithm on an <see cref="Image{TPixel}"/>.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel type.</typeparam> /// <typeparam name="TPixel">The pixel type.</typeparam>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="source">The source image. Cannot be null.</param> /// <param name="source">The source image. Cannot be null.</param>
/// <param name="sourceRectangle"> /// <param name="sourceRectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
/// </param> /// </param>
/// <returns>The <see cref="ICloningImageProcessor{TPixel}"/></returns> /// <returns>The <see cref="ICloningImageProcessor{TPixel}"/></returns>
ICloningImageProcessor<TPixel> CreatePixelSpecificCloningProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) ICloningImageProcessor<TPixel> CreatePixelSpecificCloningProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel>; where TPixel : struct, IPixel<TPixel>;
} }
} }

3
src/ImageSharp/Processing/Processors/IImageProcessor.cs

@ -19,12 +19,13 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// the processing algorithm on an <see cref="Image{TPixel}"/>. /// the processing algorithm on an <see cref="Image{TPixel}"/>.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel type.</typeparam> /// <typeparam name="TPixel">The pixel type.</typeparam>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="source">The source image. Cannot be null.</param> /// <param name="source">The source image. Cannot be null.</param>
/// <param name="sourceRectangle"> /// <param name="sourceRectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
/// </param> /// </param>
/// <returns>The <see cref="IImageProcessor{TPixel}"/></returns> /// <returns>The <see cref="IImageProcessor{TPixel}"/></returns>
IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel>; where TPixel : struct, IPixel<TPixel>;
} }
} }

11
src/ImageSharp/Processing/Processors/ImageProcessorExtensions.cs

@ -13,18 +13,21 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// Executes the processor against the given source image and rectangle bounds. /// Executes the processor against the given source image and rectangle bounds.
/// </summary> /// </summary>
/// <param name="processor">The processor.</param> /// <param name="processor">The processor.</param>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="source">The source image.</param> /// <param name="source">The source image.</param>
/// <param name="sourceRectangle">The source bounds.</param> /// <param name="sourceRectangle">The source bounds.</param>
public static void Execute(this IImageProcessor processor, Image source, Rectangle sourceRectangle) public static void Execute(this IImageProcessor processor, Configuration configuration, Image source, Rectangle sourceRectangle)
=> source.AcceptVisitor(new ExecuteVisitor(processor, sourceRectangle)); => source.AcceptVisitor(new ExecuteVisitor(configuration, processor, sourceRectangle));
private class ExecuteVisitor : IImageVisitor private class ExecuteVisitor : IImageVisitor
{ {
private readonly Configuration configuration;
private readonly IImageProcessor processor; private readonly IImageProcessor processor;
private readonly Rectangle sourceRectangle; private readonly Rectangle sourceRectangle;
public ExecuteVisitor(IImageProcessor processor, Rectangle sourceRectangle) public ExecuteVisitor(Configuration configuration, IImageProcessor processor, Rectangle sourceRectangle)
{ {
this.configuration = configuration;
this.processor = processor; this.processor = processor;
this.sourceRectangle = sourceRectangle; this.sourceRectangle = sourceRectangle;
} }
@ -32,7 +35,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
public void Visit<TPixel>(Image<TPixel> image) public void Visit<TPixel>(Image<TPixel> image)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
using (IImageProcessor<TPixel> processorImpl = this.processor.CreatePixelSpecificProcessor(image, this.sourceRectangle)) using (IImageProcessor<TPixel> processorImpl = this.processor.CreatePixelSpecificProcessor(this.configuration, image, this.sourceRectangle))
{ {
processorImpl.Execute(); processorImpl.Execute();
} }

5
src/ImageSharp/Processing/Processors/ImageProcessor{TPixel}.cs

@ -19,13 +19,14 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ImageProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="ImageProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
protected ImageProcessor(Image<TPixel> source, Rectangle sourceRectangle) protected ImageProcessor(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
{ {
this.Configuration = configuration;
this.Source = source; this.Source = source;
this.SourceRectangle = sourceRectangle; this.SourceRectangle = sourceRectangle;
this.Configuration = this.Source.GetConfiguration();
} }
/// <summary> /// <summary>

3
src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationProcessor.cs

@ -35,9 +35,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization
public int NumberOfTiles { get; } public int NumberOfTiles { get; }
/// <inheritdoc /> /// <inheritdoc />
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
{ {
return new AdaptiveHistogramEqualizationProcessor<TPixel>( return new AdaptiveHistogramEqualizationProcessor<TPixel>(
configuration,
this.LuminanceLevels, this.LuminanceLevels,
this.ClipHistogram, this.ClipHistogram,
this.ClipLimit, this.ClipLimit,

4
src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationProcessor{TPixel}.cs

@ -27,6 +27,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="AdaptiveHistogramEqualizationProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="AdaptiveHistogramEqualizationProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="luminanceLevels">The number of different luminance levels. Typical values are 256 for 8-bit grayscale images /// <param name="luminanceLevels">The number of different luminance levels. Typical values are 256 for 8-bit grayscale images
/// or 65536 for 16-bit grayscale images.</param> /// or 65536 for 16-bit grayscale images.</param>
/// <param name="clipHistogram">Indicating whether to clip the histogram bins at a specific value.</param> /// <param name="clipHistogram">Indicating whether to clip the histogram bins at a specific value.</param>
@ -35,13 +36,14 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public AdaptiveHistogramEqualizationProcessor( public AdaptiveHistogramEqualizationProcessor(
Configuration configuration,
int luminanceLevels, int luminanceLevels,
bool clipHistogram, bool clipHistogram,
int clipLimit, int clipLimit,
int tiles, int tiles,
Image<TPixel> source, Image<TPixel> source,
Rectangle sourceRectangle) Rectangle sourceRectangle)
: base(luminanceLevels, clipHistogram, clipLimit, source, sourceRectangle) : base(configuration, luminanceLevels, clipHistogram, clipLimit, source, sourceRectangle)
{ {
Guard.MustBeGreaterThanOrEqualTo(tiles, 2, nameof(tiles)); Guard.MustBeGreaterThanOrEqualTo(tiles, 2, nameof(tiles));
Guard.MustBeLessThanOrEqualTo(tiles, 100, nameof(tiles)); Guard.MustBeLessThanOrEqualTo(tiles, 100, nameof(tiles));

7
src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor.cs

@ -34,15 +34,14 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization
public int NumberOfTiles { get; } public int NumberOfTiles { get; }
/// <inheritdoc /> /// <inheritdoc />
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
{ => new AdaptiveHistogramEqualizationSlidingWindowProcessor<TPixel>(
return new AdaptiveHistogramEqualizationSlidingWindowProcessor<TPixel>( configuration,
this.LuminanceLevels, this.LuminanceLevels,
this.ClipHistogram, this.ClipHistogram,
this.ClipLimit, this.ClipLimit,
this.NumberOfTiles, this.NumberOfTiles,
source, source,
sourceRectangle); sourceRectangle);
}
} }
} }

4
src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs

@ -26,6 +26,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="luminanceLevels">The number of different luminance levels. Typical values are 256 for 8-bit grayscale images /// <param name="luminanceLevels">The number of different luminance levels. Typical values are 256 for 8-bit grayscale images
/// or 65536 for 16-bit grayscale images.</param> /// or 65536 for 16-bit grayscale images.</param>
/// <param name="clipHistogram">Indicating whether to clip the histogram bins at a specific value.</param> /// <param name="clipHistogram">Indicating whether to clip the histogram bins at a specific value.</param>
@ -34,13 +35,14 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public AdaptiveHistogramEqualizationSlidingWindowProcessor( public AdaptiveHistogramEqualizationSlidingWindowProcessor(
Configuration configuration,
int luminanceLevels, int luminanceLevels,
bool clipHistogram, bool clipHistogram,
int clipLimit, int clipLimit,
int tiles, int tiles,
Image<TPixel> source, Image<TPixel> source,
Rectangle sourceRectangle) Rectangle sourceRectangle)
: base(luminanceLevels, clipHistogram, clipLimit, source, sourceRectangle) : base(configuration, luminanceLevels, clipHistogram, clipLimit, source, sourceRectangle)
{ {
Guard.MustBeGreaterThanOrEqualTo(tiles, 2, nameof(tiles)); Guard.MustBeGreaterThanOrEqualTo(tiles, 2, nameof(tiles));
Guard.MustBeLessThanOrEqualTo(tiles, 100, nameof(tiles)); Guard.MustBeLessThanOrEqualTo(tiles, 100, nameof(tiles));

7
src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor.cs

@ -22,14 +22,13 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization
} }
/// <inheritdoc /> /// <inheritdoc />
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
{ => new GlobalHistogramEqualizationProcessor<TPixel>(
return new GlobalHistogramEqualizationProcessor<TPixel>( configuration,
this.LuminanceLevels, this.LuminanceLevels,
this.ClipHistogram, this.ClipHistogram,
this.ClipLimit, this.ClipLimit,
source, source,
sourceRectangle); sourceRectangle);
}
} }
} }

4
src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs

@ -26,6 +26,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="GlobalHistogramEqualizationProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="GlobalHistogramEqualizationProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="luminanceLevels"> /// <param name="luminanceLevels">
/// The number of different luminance levels. Typical values are 256 for 8-bit grayscale images /// The number of different luminance levels. Typical values are 256 for 8-bit grayscale images
/// or 65536 for 16-bit grayscale images. /// or 65536 for 16-bit grayscale images.
@ -35,12 +36,13 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public GlobalHistogramEqualizationProcessor( public GlobalHistogramEqualizationProcessor(
Configuration configuration,
int luminanceLevels, int luminanceLevels,
bool clipHistogram, bool clipHistogram,
int clipLimit, int clipLimit,
Image<TPixel> source, Image<TPixel> source,
Rectangle sourceRectangle) Rectangle sourceRectangle)
: base(luminanceLevels, clipHistogram, clipLimit, source, sourceRectangle) : base(configuration, luminanceLevels, clipHistogram, clipLimit, source, sourceRectangle)
{ {
} }

2
src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor.cs

@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization
public int ClipLimit { get; } public int ClipLimit { get; }
/// <inheritdoc /> /// <inheritdoc />
public abstract IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public abstract IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel>; where TPixel : struct, IPixel<TPixel>;
/// <summary> /// <summary>

5
src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor{TPixel}.cs

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System; using System;
using System.Numerics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -23,6 +22,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="HistogramEqualizationProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="HistogramEqualizationProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="luminanceLevels">The number of different luminance levels. Typical values are 256 for 8-bit grayscale images /// <param name="luminanceLevels">The number of different luminance levels. Typical values are 256 for 8-bit grayscale images
/// or 65536 for 16-bit grayscale images.</param> /// or 65536 for 16-bit grayscale images.</param>
/// <param name="clipHistogram">Indicates, if histogram bins should be clipped.</param> /// <param name="clipHistogram">Indicates, if histogram bins should be clipped.</param>
@ -30,12 +30,13 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
protected HistogramEqualizationProcessor( protected HistogramEqualizationProcessor(
Configuration configuration,
int luminanceLevels, int luminanceLevels,
bool clipHistogram, bool clipHistogram,
int clipLimit, int clipLimit,
Image<TPixel> source, Image<TPixel> source,
Rectangle sourceRectangle) Rectangle sourceRectangle)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ {
Guard.MustBeGreaterThan(luminanceLevels, 0, nameof(luminanceLevels)); Guard.MustBeGreaterThan(luminanceLevels, 0, nameof(luminanceLevels));
Guard.MustBeGreaterThan(clipLimit, 1, nameof(clipLimit)); Guard.MustBeGreaterThan(clipLimit, 1, nameof(clipLimit));

6
src/ImageSharp/Processing/Processors/Overlays/BackgroundColorProcessor.cs

@ -33,10 +33,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays
public Color Color { get; } public Color Color { get; }
/// <inheritdoc /> /// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => new BackgroundColorProcessor<TPixel>(configuration, this, source, sourceRectangle);
return new BackgroundColorProcessor<TPixel>(this, source, sourceRectangle);
}
} }
} }

5
src/ImageSharp/Processing/Processors/Overlays/BackgroundColorProcessor{TPixel}.cs

@ -24,11 +24,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="BackgroundColorProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="BackgroundColorProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="definition">The <see cref="BackgroundColorProcessor"/> defining the processor parameters.</param> /// <param name="definition">The <see cref="BackgroundColorProcessor"/> defining the processor parameters.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public BackgroundColorProcessor(BackgroundColorProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) public BackgroundColorProcessor(Configuration configuration, BackgroundColorProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ {
this.definition = definition; this.definition = definition;
} }

6
src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs

@ -70,10 +70,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays
internal ValueSize Radius { get; } internal ValueSize Radius { get; }
/// <inheritdoc /> /// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => new GlowProcessor<TPixel>(configuration, this, source, sourceRectangle);
return new GlowProcessor<TPixel>(this, source, sourceRectangle);
}
} }
} }

6
src/ImageSharp/Processing/Processors/Overlays/GlowProcessor{TPixel}.cs

@ -21,17 +21,17 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
private readonly PixelBlender<TPixel> blender; private readonly PixelBlender<TPixel> blender;
private readonly GlowProcessor definition; private readonly GlowProcessor definition;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="GlowProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="GlowProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="definition">The <see cref="GlowProcessor"/> defining the processor parameters.</param> /// <param name="definition">The <see cref="GlowProcessor"/> defining the processor parameters.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public GlowProcessor(GlowProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) public GlowProcessor(Configuration configuration, GlowProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ {
this.definition = definition; this.definition = definition;
this.blender = PixelOperations<TPixel>.Instance.GetPixelBlender(definition.GraphicsOptions); this.blender = PixelOperations<TPixel>.Instance.GetPixelBlender(definition.GraphicsOptions);

6
src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs

@ -68,10 +68,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays
internal ValueSize RadiusY { get; } internal ValueSize RadiusY { get; }
/// <inheritdoc /> /// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => new VignetteProcessor<TPixel>(configuration, this, source, sourceRectangle);
return new VignetteProcessor<TPixel>(this, source, sourceRectangle);
}
} }
} }

5
src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor{TPixel}.cs

@ -27,11 +27,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="VignetteProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="VignetteProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="definition">The <see cref="VignetteProcessor"/> defining the processor parameters.</param> /// <param name="definition">The <see cref="VignetteProcessor"/> defining the processor parameters.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public VignetteProcessor(VignetteProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) public VignetteProcessor(Configuration configuration, VignetteProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ {
this.definition = definition; this.definition = definition;
this.blender = PixelOperations<TPixel>.Instance.GetPixelBlender(definition.GraphicsOptions); this.blender = PixelOperations<TPixel>.Instance.GetPixelBlender(definition.GraphicsOptions);

6
src/ImageSharp/Processing/Processors/Quantization/QuantizeProcessor.cs

@ -26,10 +26,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
public IQuantizer Quantizer { get; } public IQuantizer Quantizer { get; }
/// <inheritdoc /> /// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => new QuantizeProcessor<TPixel>(configuration, this.Quantizer, source, sourceRectangle);
return new QuantizeProcessor<TPixel>(this.Quantizer, source, sourceRectangle);
}
} }
} }

5
src/ImageSharp/Processing/Processors/Quantization/QuantizeProcessor{TPixel}.cs

@ -21,11 +21,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="QuantizeProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="QuantizeProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="quantizer">The quantizer used to reduce the color palette.</param> /// <param name="quantizer">The quantizer used to reduce the color palette.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public QuantizeProcessor(IQuantizer quantizer, Image<TPixel> source, Rectangle sourceRectangle) public QuantizeProcessor(Configuration configuration, IQuantizer quantizer, Image<TPixel> source, Rectangle sourceRectangle)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ {
Guard.NotNull(quantizer, nameof(quantizer)); Guard.NotNull(quantizer, nameof(quantizer));
this.quantizer = quantizer; this.quantizer = quantizer;

4
src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor.cs

@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
public Size TargetDimensions { get; } public Size TargetDimensions { get; }
/// <inheritdoc/> /// <inheritdoc/>
public override ICloningImageProcessor<TPixel> CreatePixelSpecificCloningProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public override ICloningImageProcessor<TPixel> CreatePixelSpecificCloningProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
=> new AffineTransformProcessor<TPixel>(this, source, sourceRectangle); => new AffineTransformProcessor<TPixel>(configuration, this, source, sourceRectangle);
} }
} }

5
src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor{TPixel}.cs

@ -24,11 +24,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="AffineTransformProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="AffineTransformProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="definition">The <see cref="AffineTransformProcessor"/> defining the processor parameters.</param> /// <param name="definition">The <see cref="AffineTransformProcessor"/> defining the processor parameters.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public AffineTransformProcessor(AffineTransformProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) public AffineTransformProcessor(Configuration configuration, AffineTransformProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ {
this.targetSize = definition.TargetDimensions; this.targetSize = definition.TargetDimensions;
this.transformMatrix = definition.TransformMatrix; this.transformMatrix = definition.TransformMatrix;

6
src/ImageSharp/Processing/Processors/Transforms/AutoOrientProcessor.cs

@ -12,10 +12,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
public sealed class AutoOrientProcessor : IImageProcessor public sealed class AutoOrientProcessor : IImageProcessor
{ {
/// <inheritdoc /> /// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => new AutoOrientProcessor<TPixel>(configuration, source, sourceRectangle);
return new AutoOrientProcessor<TPixel>(source, sourceRectangle);
}
} }
} }

23
src/ImageSharp/Processing/Processors/Transforms/AutoOrientProcessor{TPixel}.cs

@ -19,10 +19,11 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="AutoOrientProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="AutoOrientProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public AutoOrientProcessor(Image<TPixel> source, Rectangle sourceRectangle) public AutoOrientProcessor(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ {
} }
@ -34,33 +35,33 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
switch (orientation) switch (orientation)
{ {
case OrientationMode.TopRight: case OrientationMode.TopRight:
new FlipProcessor(FlipMode.Horizontal).Execute(this.Source, this.SourceRectangle); new FlipProcessor(FlipMode.Horizontal).Execute(this.Configuration, this.Source, this.SourceRectangle);
break; break;
case OrientationMode.BottomRight: case OrientationMode.BottomRight:
new RotateProcessor((int)RotateMode.Rotate180, size).Execute(this.Source, this.SourceRectangle); new RotateProcessor((int)RotateMode.Rotate180, size).Execute(this.Configuration, this.Source, this.SourceRectangle);
break; break;
case OrientationMode.BottomLeft: case OrientationMode.BottomLeft:
new FlipProcessor(FlipMode.Vertical).Execute(this.Source, this.SourceRectangle); new FlipProcessor(FlipMode.Vertical).Execute(this.Configuration, this.Source, this.SourceRectangle);
break; break;
case OrientationMode.LeftTop: case OrientationMode.LeftTop:
new RotateProcessor((int)RotateMode.Rotate90, size).Execute(this.Source, this.SourceRectangle); new RotateProcessor((int)RotateMode.Rotate90, size).Execute(this.Configuration, this.Source, this.SourceRectangle);
new FlipProcessor(FlipMode.Horizontal).Execute(this.Source, this.SourceRectangle); new FlipProcessor(FlipMode.Horizontal).Execute(this.Configuration, this.Source, this.SourceRectangle);
break; break;
case OrientationMode.RightTop: case OrientationMode.RightTop:
new RotateProcessor((int)RotateMode.Rotate90, size).Execute(this.Source, this.SourceRectangle); new RotateProcessor((int)RotateMode.Rotate90, size).Execute(this.Configuration, this.Source, this.SourceRectangle);
break; break;
case OrientationMode.RightBottom: case OrientationMode.RightBottom:
new FlipProcessor(FlipMode.Vertical).Execute(this.Source, this.SourceRectangle); new FlipProcessor(FlipMode.Vertical).Execute(this.Configuration, this.Source, this.SourceRectangle);
new RotateProcessor((int)RotateMode.Rotate270, size).Execute(this.Source, this.SourceRectangle); new RotateProcessor((int)RotateMode.Rotate270, size).Execute(this.Configuration, this.Source, this.SourceRectangle);
break; break;
case OrientationMode.LeftBottom: case OrientationMode.LeftBottom:
new RotateProcessor((int)RotateMode.Rotate270, size).Execute(this.Source, this.SourceRectangle); new RotateProcessor((int)RotateMode.Rotate270, size).Execute(this.Configuration, this.Source, this.SourceRectangle);
break; break;
case OrientationMode.Unknown: case OrientationMode.Unknown:

4
src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs

@ -32,7 +32,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
public Rectangle CropRectangle { get; } public Rectangle CropRectangle { get; }
/// <inheritdoc /> /// <inheritdoc />
public override ICloningImageProcessor<TPixel> CreatePixelSpecificCloningProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public override ICloningImageProcessor<TPixel> CreatePixelSpecificCloningProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
=> new CropProcessor<TPixel>(this, source, sourceRectangle); => new CropProcessor<TPixel>(configuration, this, source, sourceRectangle);
} }
} }

5
src/ImageSharp/Processing/Processors/Transforms/CropProcessor{TPixel}.cs

@ -21,11 +21,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="CropProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="CropProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="definition">The <see cref="CropProcessor"/>.</param> /// <param name="definition">The <see cref="CropProcessor"/>.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public CropProcessor(CropProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) public CropProcessor(Configuration configuration, CropProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
=> this.cropRectangle = definition.CropRectangle; => this.cropRectangle = definition.CropRectangle;
/// <inheritdoc/> /// <inheritdoc/>

6
src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs

@ -38,10 +38,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
public float Threshold { get; } public float Threshold { get; }
/// <inheritdoc /> /// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => new EntropyCropProcessor<TPixel>(configuration, this, source, sourceRectangle);
return new EntropyCropProcessor<TPixel>(this, source, sourceRectangle);
}
} }
} }

11
src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor{TPixel}.cs

@ -21,11 +21,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="EntropyCropProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="EntropyCropProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="definition">The <see cref="EntropyCropProcessor"/>.</param> /// <param name="definition">The <see cref="EntropyCropProcessor"/>.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public EntropyCropProcessor(EntropyCropProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) public EntropyCropProcessor(Configuration configuration, EntropyCropProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ {
this.definition = definition; this.definition = definition;
} }
@ -42,16 +43,16 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
Configuration configuration = this.Source.GetConfiguration(); Configuration configuration = this.Source.GetConfiguration();
// Detect the edges. // Detect the edges.
new SobelProcessor(false).Execute(temp, this.SourceRectangle); new SobelProcessor(false).Execute(this.Configuration, temp, this.SourceRectangle);
// Apply threshold binarization filter. // Apply threshold binarization filter.
new BinaryThresholdProcessor(this.definition.Threshold).Execute(temp, this.SourceRectangle); new BinaryThresholdProcessor(this.definition.Threshold).Execute(this.Configuration, temp, this.SourceRectangle);
// Search for the first white pixels // Search for the first white pixels
rectangle = ImageMaths.GetFilteredBoundingRectangle(temp.Frames.RootFrame, 0); rectangle = ImageMaths.GetFilteredBoundingRectangle(temp.Frames.RootFrame, 0);
} }
new CropProcessor(rectangle, this.Source.Size()).Execute(this.Source, this.SourceRectangle); new CropProcessor(rectangle, this.Source.Size()).Execute(this.Configuration, this.Source, this.SourceRectangle);
base.BeforeImageApply(); base.BeforeImageApply();
} }

11
src/ImageSharp/Processing/Processors/Transforms/FlipProcessor.cs

@ -15,10 +15,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
/// Initializes a new instance of the <see cref="FlipProcessor"/> class. /// Initializes a new instance of the <see cref="FlipProcessor"/> class.
/// </summary> /// </summary>
/// <param name="flipMode">The <see cref="FlipMode"/> used to perform flipping.</param> /// <param name="flipMode">The <see cref="FlipMode"/> used to perform flipping.</param>
public FlipProcessor(FlipMode flipMode) public FlipProcessor(FlipMode flipMode) => this.FlipMode = flipMode;
{
this.FlipMode = flipMode;
}
/// <summary> /// <summary>
/// Gets the <see cref="FlipMode"/> used to perform flipping. /// Gets the <see cref="FlipMode"/> used to perform flipping.
@ -26,10 +23,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
public FlipMode FlipMode { get; } public FlipMode FlipMode { get; }
/// <inheritdoc /> /// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ => new FlipProcessor<TPixel>(configuration, this, source, sourceRectangle);
return new FlipProcessor<TPixel>(this, source, sourceRectangle);
}
} }
} }

5
src/ImageSharp/Processing/Processors/Transforms/FlipProcessor{TPixel}.cs

@ -23,11 +23,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="FlipProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="FlipProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="definition">The <see cref="FlipProcessor"/>.</param> /// <param name="definition">The <see cref="FlipProcessor"/>.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public FlipProcessor(FlipProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) public FlipProcessor(Configuration configuration, FlipProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ {
this.definition = definition; this.definition = definition;
} }

4
src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor.cs

@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
public Size TargetDimensions { get; } public Size TargetDimensions { get; }
/// <inheritdoc /> /// <inheritdoc />
public override ICloningImageProcessor<TPixel> CreatePixelSpecificCloningProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public override ICloningImageProcessor<TPixel> CreatePixelSpecificCloningProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
=> new ProjectiveTransformProcessor<TPixel>(this, source, sourceRectangle); => new ProjectiveTransformProcessor<TPixel>(configuration, this, source, sourceRectangle);
} }
} }

5
src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor{TPixel}.cs

@ -25,11 +25,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ProjectiveTransformProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="ProjectiveTransformProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="definition">The <see cref="ProjectiveTransformProcessor"/> defining the processor parameters.</param> /// <param name="definition">The <see cref="ProjectiveTransformProcessor"/> defining the processor parameters.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public ProjectiveTransformProcessor(ProjectiveTransformProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) public ProjectiveTransformProcessor(Configuration configuration, ProjectiveTransformProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ {
this.targetSize = definition.TargetDimensions; this.targetSize = definition.TargetDimensions;
this.transformMatrix = definition.TransformMatrix; this.transformMatrix = definition.TransformMatrix;

4
src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor.cs

@ -55,7 +55,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
public bool Compand { get; } public bool Compand { get; }
/// <inheritdoc /> /// <inheritdoc />
public override ICloningImageProcessor<TPixel> CreatePixelSpecificCloningProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle) public override ICloningImageProcessor<TPixel> CreatePixelSpecificCloningProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
=> new ResizeProcessor<TPixel>(this, source, sourceRectangle); => new ResizeProcessor<TPixel>(configuration, this, source, sourceRectangle);
} }
} }

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save