Skip to content

Commit 92f3ada

Browse files
Merge pull request #1070 from SixLabors/js/custom-configuration-fix-650
Allow passing custom Configuration instances to processors
2 parents a41ba70 + a5ab02c commit 92f3ada

File tree

111 files changed

+450
-362
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+450
-362
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,25 @@ public DrawImageProcessor(
6060
public float Opacity { get; }
6161

6262
/// <inheritdoc />
63-
public IImageProcessor<TPixelBg> CreatePixelSpecificProcessor<TPixelBg>(Image<TPixelBg> source, Rectangle sourceRectangle)
63+
public IImageProcessor<TPixelBg> CreatePixelSpecificProcessor<TPixelBg>(Configuration configuration, Image<TPixelBg> source, Rectangle sourceRectangle)
6464
where TPixelBg : struct, IPixel<TPixelBg>
6565
{
66-
var visitor = new ProcessorFactoryVisitor<TPixelBg>(this, source, sourceRectangle);
66+
var visitor = new ProcessorFactoryVisitor<TPixelBg>(configuration, this, source, sourceRectangle);
6767
this.Image.AcceptVisitor(visitor);
6868
return visitor.Result;
6969
}
7070

7171
private class ProcessorFactoryVisitor<TPixelBg> : IImageVisitor
7272
where TPixelBg : struct, IPixel<TPixelBg>
7373
{
74+
private readonly Configuration configuration;
7475
private readonly DrawImageProcessor definition;
7576
private readonly Image<TPixelBg> source;
7677
private readonly Rectangle sourceRectangle;
7778

78-
public ProcessorFactoryVisitor(DrawImageProcessor definition, Image<TPixelBg> source, Rectangle sourceRectangle)
79+
public ProcessorFactoryVisitor(Configuration configuration, DrawImageProcessor definition, Image<TPixelBg> source, Rectangle sourceRectangle)
7980
{
81+
this.configuration = configuration;
8082
this.definition = definition;
8183
this.source = source;
8284
this.sourceRectangle = sourceRectangle;
@@ -88,6 +90,7 @@ public void Visit<TPixelFg>(Image<TPixelFg> image)
8890
where TPixelFg : struct, IPixel<TPixelFg>
8991
{
9092
this.Result = new DrawImageProcessor<TPixelBg, TPixelFg>(
93+
this.configuration,
9194
image,
9295
this.source,
9396
this.sourceRectangle,

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ internal class DrawImageProcessor<TPixelBg, TPixelFg> : ImageProcessor<TPixelBg>
2222
/// <summary>
2323
/// Initializes a new instance of the <see cref="DrawImageProcessor{TPixelBg, TPixelFg}"/> class.
2424
/// </summary>
25+
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
2526
/// <param name="image">The foreground <see cref="Image{TPixelFg}"/> to blend with the currently processing image.</param>
2627
/// <param name="source">The source <see cref="Image{TPixelBg}"/> for the current processor instance.</param>
2728
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
@@ -30,14 +31,15 @@ internal class DrawImageProcessor<TPixelBg, TPixelFg> : ImageProcessor<TPixelBg>
3031
/// <param name="alphaCompositionMode">The Alpha blending mode to use when drawing the image.</param>
3132
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
3233
public DrawImageProcessor(
34+
Configuration configuration,
3335
Image<TPixelFg> image,
3436
Image<TPixelBg> source,
3537
Rectangle sourceRectangle,
3638
Point location,
3739
PixelColorBlendingMode colorBlendingMode,
3840
PixelAlphaCompositionMode alphaCompositionMode,
3941
float opacity)
40-
: base(source, sourceRectangle)
42+
: base(configuration, source, sourceRectangle)
4143
{
4244
Guard.MustBeBetweenOrEqualTo(opacity, 0, 1, nameof(opacity));
4345

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ public FillProcessor(GraphicsOptions options, IBrush brush)
3434
public GraphicsOptions Options { get; }
3535

3636
/// <inheritdoc />
37-
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle)
37+
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
3838
where TPixel : struct, IPixel<TPixel>
39-
{
40-
return new FillProcessor<TPixel>(this, source, sourceRectangle);
41-
}
39+
=> new FillProcessor<TPixel>(configuration, this, source, sourceRectangle);
4240
}
4341
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
using SixLabors.ImageSharp.Advanced;
88
using SixLabors.ImageSharp.Advanced.ParallelUtils;
9-
using SixLabors.ImageSharp.Memory;
109
using SixLabors.ImageSharp.PixelFormats;
1110
using SixLabors.Primitives;
1211

@@ -21,8 +20,8 @@ internal class FillProcessor<TPixel> : ImageProcessor<TPixel>
2120
{
2221
private readonly FillProcessor definition;
2322

24-
public FillProcessor(FillProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
25-
: base(source, sourceRectangle)
23+
public FillProcessor(Configuration configuration, FillProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
24+
: base(configuration, source, sourceRectangle)
2625
{
2726
this.definition = definition;
2827
}
@@ -112,7 +111,7 @@ private bool IsSolidBrushWithoutBlending(out SolidBrush solidBrush)
112111
{
113112
solidBrush = this.definition.Brush as SolidBrush;
114113

115-
if (solidBrush == null)
114+
if (solidBrush is null)
116115
{
117116
return false;
118117
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ public FillRegionProcessor(GraphicsOptions options, IBrush brush, Region region)
4242
public GraphicsOptions Options { get; }
4343

4444
/// <inheritdoc />
45-
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle)
45+
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
4646
where TPixel : struct, IPixel<TPixel>
47-
{
48-
return new FillRegionProcessor<TPixel>(this, source, sourceRectangle);
49-
}
47+
=> new FillRegionProcessor<TPixel>(configuration, this, source, sourceRectangle);
5048
}
5149
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ internal class FillRegionProcessor<TPixel> : ImageProcessor<TPixel>
2323
{
2424
private readonly FillRegionProcessor definition;
2525

26-
public FillRegionProcessor(FillRegionProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
27-
: base(source, sourceRectangle)
26+
public FillRegionProcessor(Configuration configuration, FillRegionProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
27+
: base(configuration, source, sourceRectangle)
2828
{
2929
this.definition = definition;
3030
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,8 @@ public DrawTextProcessor(TextGraphicsOptions options, string text, Font font, IB
7272
public PointF Location { get; }
7373

7474
/// <inheritdoc />
75-
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Image<TPixel> source, Rectangle sourceRectangle)
75+
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
7676
where TPixel : struct, IPixel<TPixel>
77-
{
78-
return new DrawTextProcessor<TPixel>(this, source, sourceRectangle);
79-
}
77+
=> new DrawTextProcessor<TPixel>(configuration, this, source, sourceRectangle);
8078
}
8179
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ internal class DrawTextProcessor<TPixel> : ImageProcessor<TPixel>
2727

2828
private readonly DrawTextProcessor definition;
2929

30-
public DrawTextProcessor(DrawTextProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
31-
: base(source, sourceRectangle)
30+
public DrawTextProcessor(Configuration configuration, DrawTextProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
31+
: base(configuration, source, sourceRectangle)
3232
{
3333
this.definition = definition;
3434
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
// Copyright (c) Six Labors and contributors.
22
// Licensed under the Apache License, Version 2.0.
33

4-
using SixLabors.ImageSharp.Advanced;
54
using SixLabors.ImageSharp.PixelFormats;
65
using SixLabors.ImageSharp.Processing.Processors;
7-
using SixLabors.Memory;
86
using SixLabors.Primitives;
97

108
namespace SixLabors.ImageSharp.Processing
@@ -23,10 +21,12 @@ internal class DefaultImageProcessorContext<TPixel> : IInternalImageProcessingCo
2321
/// <summary>
2422
/// Initializes a new instance of the <see cref="DefaultImageProcessorContext{TPixel}"/> class.
2523
/// </summary>
26-
/// <param name="source">The image.</param>
27-
/// <param name="mutate">The mutate.</param>
28-
public DefaultImageProcessorContext(Image<TPixel> source, bool mutate)
24+
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
25+
/// <param name="source">The source image.</param>
26+
/// <param name="mutate">Whether to mutate the image.</param>
27+
public DefaultImageProcessorContext(Configuration configuration, Image<TPixel> source, bool mutate)
2928
{
29+
this.Configuration = configuration;
3030
this.mutate = mutate;
3131
this.source = source;
3232

@@ -38,7 +38,7 @@ public DefaultImageProcessorContext(Image<TPixel> source, bool mutate)
3838
}
3939

4040
/// <inheritdoc/>
41-
public MemoryAllocator MemoryAllocator => this.source.GetConfiguration().MemoryAllocator;
41+
public Configuration Configuration { get; }
4242

4343
/// <inheritdoc/>
4444
public Image<TPixel> GetResultImage()
@@ -71,7 +71,7 @@ public IImageProcessingContext ApplyProcessor(IImageProcessor processor, Rectang
7171
// interim clone if the first processor in the pipeline is a cloning processor.
7272
if (processor is ICloningImageProcessor cloningImageProcessor)
7373
{
74-
using (ICloningImageProcessor<TPixel> pixelProcessor = cloningImageProcessor.CreatePixelSpecificCloningProcessor(this.source, rectangle))
74+
using (ICloningImageProcessor<TPixel> pixelProcessor = cloningImageProcessor.CreatePixelSpecificCloningProcessor(this.Configuration, this.source, rectangle))
7575
{
7676
this.destination = pixelProcessor.CloneAndExecute();
7777
return this;
@@ -83,7 +83,7 @@ public IImageProcessingContext ApplyProcessor(IImageProcessor processor, Rectang
8383
}
8484

8585
// Standard processing pipeline.
86-
using (IImageProcessor<TPixel> specificProcessor = processor.CreatePixelSpecificProcessor(this.destination, rectangle))
86+
using (IImageProcessor<TPixel> specificProcessor = processor.CreatePixelSpecificProcessor(this.Configuration, this.destination, rectangle))
8787
{
8888
specificProcessor.Execute();
8989
}

0 commit comments

Comments
 (0)