Skip to content

Commit 3ea7b27

Browse files
Update to match latest ImageSharp build
1 parent dbb84df commit 3ea7b27

32 files changed

Lines changed: 253 additions & 216 deletions

Directory.Build.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
<!--Src Dependencies-->
2626
<PackageReference Update="SixLabors.Fonts" Version="1.0.0-unstable0024" />
27-
<PackageReference Update="SixLabors.ImageSharp" Version="1.0.0-unstable0542" />
27+
<PackageReference Update="SixLabors.ImageSharp" Version="1.0.0-unstable0702" />
2828
</ItemGroup>
2929

3030
</Project>

src/ImageSharp.Drawing/Processing/BrushApplicator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected virtual void Dispose(bool disposing)
8383
/// <remarks>scanlineBuffer will be > scanlineWidth but provide and offset in case we want to share a larger buffer across runs.</remarks>
8484
internal virtual void Apply(Span<float> scanline, int x, int y)
8585
{
86-
MemoryAllocator memoryAllocator = this.Target.MemoryAllocator;
86+
MemoryAllocator memoryAllocator = this.Configuration.MemoryAllocator;
8787

8888
using (IMemoryOwner<float> amountBuffer = memoryAllocator.Allocate<float>(scanline.Length))
8989
using (IMemoryOwner<TPixel> overlay = memoryAllocator.Allocate<TPixel>(scanline.Length))

src/ImageSharp.Drawing/Processing/ImageBrush.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Buffers;
66

77
using SixLabors.ImageSharp.Advanced;
8+
using SixLabors.ImageSharp.Memory;
89
using SixLabors.ImageSharp.PixelFormats;
910

1011
namespace SixLabors.ImageSharp.Processing
@@ -140,8 +141,9 @@ protected override void Dispose(bool disposing)
140141
internal override void Apply(Span<float> scanline, int x, int y)
141142
{
142143
// Create a span for colors
143-
using (IMemoryOwner<float> amountBuffer = this.Target.MemoryAllocator.Allocate<float>(scanline.Length))
144-
using (IMemoryOwner<TPixel> overlay = this.Target.MemoryAllocator.Allocate<TPixel>(scanline.Length))
144+
MemoryAllocator allocator = this.Configuration.MemoryAllocator;
145+
using (IMemoryOwner<float> amountBuffer = allocator.Allocate<float>(scanline.Length))
146+
using (IMemoryOwner<TPixel> overlay = allocator.Allocate<TPixel>(scanline.Length))
145147
{
146148
Span<float> amountSpan = amountBuffer.Memory.Span;
147149
Span<TPixel> overlaySpan = overlay.Memory.Span;

src/ImageSharp.Drawing/Processing/PathGradientBrush.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public PathGradientBrushApplicator(
283283
{
284284
(Edge edge, Intersection? info) closest = default;
285285

286-
MemoryAllocator allocator = this.Target.MemoryAllocator;
286+
MemoryAllocator allocator = this.Configuration.MemoryAllocator;
287287
foreach (Edge edge in this.edges)
288288
{
289289
Intersection? intersection = edge.FindIntersection(start, end, allocator);

src/ImageSharp.Drawing/Processing/PatternBrush.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public PatternBrushApplicator(
145145
internal override void Apply(Span<float> scanline, int x, int y)
146146
{
147147
int patternY = y % this.pattern.Rows;
148-
MemoryAllocator memoryAllocator = this.Target.MemoryAllocator;
148+
MemoryAllocator memoryAllocator = this.Configuration.MemoryAllocator;
149149

150150
using (IMemoryOwner<float> amountBuffer = memoryAllocator.Allocate<float>(scanline.Length))
151151
using (IMemoryOwner<TPixel> overlay = memoryAllocator.Allocate<TPixel>(scanline.Length))

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

Lines changed: 74 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
using System;
55
using System.Buffers;
6-
6+
using System.Runtime.CompilerServices;
77
using SixLabors.ImageSharp.Advanced;
8-
using SixLabors.ImageSharp.Advanced.ParallelUtils;
8+
using SixLabors.ImageSharp.Memory;
99
using SixLabors.ImageSharp.PixelFormats;
1010

1111
namespace SixLabors.ImageSharp.Processing.Processors.Drawing
@@ -28,25 +28,10 @@ public FillProcessor(Configuration configuration, FillProcessor definition, Imag
2828
/// <inheritdoc/>
2929
protected override void OnFrameApply(ImageFrame<TPixel> source)
3030
{
31-
Rectangle sourceRectangle = this.SourceRectangle;
3231
Configuration configuration = this.Configuration;
33-
int startX = sourceRectangle.X;
34-
int endX = sourceRectangle.Right;
35-
int startY = sourceRectangle.Y;
36-
int endY = sourceRectangle.Bottom;
37-
38-
// Align start/end positions.
39-
int minX = Math.Max(0, startX);
40-
int maxX = Math.Min(source.Width, endX);
41-
int minY = Math.Max(0, startY);
42-
int maxY = Math.Min(source.Height, endY);
43-
44-
int width = maxX - minX;
45-
46-
var workingRect = Rectangle.FromLTRB(minX, minY, maxX, maxY);
47-
4832
IBrush brush = this.definition.Brush;
4933
GraphicsOptions options = this.definition.Options;
34+
var interest = Rectangle.Intersect(this.SourceRectangle, source.Bounds());
5035

5136
// If there's no reason for blending, then avoid it.
5237
if (this.IsSolidBrushWithoutBlending(out SolidBrush solidBrush))
@@ -56,54 +41,29 @@ protected override void OnFrameApply(ImageFrame<TPixel> source)
5641

5742
TPixel colorPixel = solidBrush.Color.ToPixel<TPixel>();
5843

59-
ParallelHelper.IterateRows(
60-
workingRect,
44+
var solidOperation = new SolidBrushRowIntervalOperation(interest, source, colorPixel);
45+
ParallelRowIterator.IterateRows(
46+
interest,
6147
parallelSettings,
62-
rows =>
63-
{
64-
for (int y = rows.Min; y < rows.Max; y++)
65-
{
66-
source.GetPixelRowSpan(y).Slice(minX, width).Fill(colorPixel);
67-
}
68-
});
48+
in solidOperation);
49+
50+
return;
6951
}
70-
else
71-
{
72-
// Reset offset if necessary.
73-
if (minX > 0)
74-
{
75-
startX = 0;
76-
}
7752

78-
if (minY > 0)
79-
{
80-
startY = 0;
81-
}
53+
using IMemoryOwner<float> amount = configuration.MemoryAllocator.Allocate<float>(interest.Width);
54+
using BrushApplicator<TPixel> applicator = brush.CreateApplicator(
55+
configuration,
56+
options,
57+
source,
58+
interest);
8259

83-
using (IMemoryOwner<float> amount = source.MemoryAllocator.Allocate<float>(width))
84-
using (BrushApplicator<TPixel> applicator = brush.CreateApplicator(
85-
configuration,
86-
options,
87-
source,
88-
sourceRectangle))
89-
{
90-
amount.Memory.Span.Fill(1F);
91-
92-
ParallelHelper.IterateRows(
93-
workingRect,
94-
configuration,
95-
rows =>
96-
{
97-
for (int y = rows.Min; y < rows.Max; y++)
98-
{
99-
int offsetY = y - startY;
100-
int offsetX = minX - startX;
101-
102-
applicator.Apply(amount.Memory.Span, offsetX, offsetY);
103-
}
104-
});
105-
}
106-
}
60+
amount.Memory.Span.Fill(1F);
61+
62+
var operation = new RowIntervalOperation(interest, applicator, amount.Memory);
63+
ParallelRowIterator.IterateRows(
64+
configuration,
65+
interest,
66+
in operation);
10767
}
10868

10969
private bool IsSolidBrushWithoutBlending(out SolidBrush solidBrush)
@@ -117,5 +77,57 @@ private bool IsSolidBrushWithoutBlending(out SolidBrush solidBrush)
11777

11878
return this.definition.Options.IsOpaqueColorWithoutBlending(solidBrush.Color);
11979
}
80+
81+
private readonly struct SolidBrushRowIntervalOperation : IRowIntervalOperation
82+
{
83+
private readonly Rectangle bounds;
84+
private readonly ImageFrame<TPixel> source;
85+
private readonly TPixel color;
86+
87+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
88+
public SolidBrushRowIntervalOperation(Rectangle bounds, ImageFrame<TPixel> source, TPixel color)
89+
{
90+
this.bounds = bounds;
91+
this.source = source;
92+
this.color = color;
93+
}
94+
95+
/// <inheritdoc/>
96+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
97+
public void Invoke(in RowInterval rows)
98+
{
99+
for (int y = rows.Min; y < rows.Max; y++)
100+
{
101+
this.source.GetPixelRowSpan(y).Slice(this.bounds.X, this.bounds.Width).Fill(this.color);
102+
}
103+
}
104+
}
105+
106+
private readonly struct RowIntervalOperation : IRowIntervalOperation
107+
{
108+
private readonly Memory<float> amount;
109+
private readonly Rectangle bounds;
110+
private readonly BrushApplicator<TPixel> applicator;
111+
112+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
113+
public RowIntervalOperation(Rectangle bounds, BrushApplicator<TPixel> applicator, Memory<float> amount)
114+
{
115+
this.bounds = bounds;
116+
this.applicator = applicator;
117+
this.amount = amount;
118+
}
119+
120+
/// <inheritdoc/>
121+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
122+
public void Invoke(in RowInterval rows)
123+
{
124+
Span<float> amountSpan = this.amount.Span;
125+
int x = this.bounds.X;
126+
for (int y = rows.Min; y < rows.Max; y++)
127+
{
128+
this.applicator.Apply(amountSpan, x, y);
129+
}
130+
}
131+
}
120132
}
121133
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Buffers;
66

77
using SixLabors.ImageSharp.Advanced;
8+
using SixLabors.ImageSharp.Memory;
89
using SixLabors.ImageSharp.PixelFormats;
910

1011
namespace SixLabors.ImageSharp.Processing.Processors.Drawing
@@ -71,8 +72,9 @@ protected override void OnFrameApply(ImageFrame<TPixel> source)
7172
using (BrushApplicator<TPixel> applicator = brush.CreateApplicator(configuration, options, source, rect))
7273
{
7374
int scanlineWidth = maxX - minX;
74-
using (IMemoryOwner<float> bBuffer = source.MemoryAllocator.Allocate<float>(maxIntersections))
75-
using (IMemoryOwner<float> bScanline = source.MemoryAllocator.Allocate<float>(scanlineWidth))
75+
MemoryAllocator allocator = this.Configuration.MemoryAllocator;
76+
using (IMemoryOwner<float> bBuffer = allocator.Allocate<float>(maxIntersections))
77+
using (IMemoryOwner<float> bScanline = allocator.Allocate<float>(scanlineWidth))
7678
{
7779
bool scanlineDirty = true;
7880
float subpixelFraction = 1f / subpixelCount;

src/ImageSharp.Drawing/Processing/RecolorBrush.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public RecolorBrushApplicator(
132132
/// <inheritdoc />
133133
internal override void Apply(Span<float> scanline, int x, int y)
134134
{
135-
MemoryAllocator memoryAllocator = this.Target.MemoryAllocator;
135+
MemoryAllocator memoryAllocator = this.Configuration.MemoryAllocator;
136136

137137
using (IMemoryOwner<float> amountBuffer = memoryAllocator.Allocate<float>(scanline.Length))
138138
using (IMemoryOwner<TPixel> overlay = memoryAllocator.Allocate<TPixel>(scanline.Length))

src/ImageSharp.Drawing/Processing/SolidBrush.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public SolidBrushApplicator(
6262
TPixel color)
6363
: base(configuration, options, source)
6464
{
65-
this.Colors = source.MemoryAllocator.Allocate<TPixel>(source.Width);
65+
this.Colors = configuration.MemoryAllocator.Allocate<TPixel>(source.Width);
6666
this.Colors.Memory.Span.Fill(color);
6767
}
6868

@@ -106,8 +106,8 @@ internal override void Apply(Span<float> scanline, int x, int y)
106106
scanline = scanline.Slice(0, destinationRow.Length);
107107
}
108108

109-
MemoryAllocator memoryAllocator = this.Target.MemoryAllocator;
110109
Configuration configuration = this.Configuration;
110+
MemoryAllocator memoryAllocator = configuration.MemoryAllocator;
111111

112112
if (this.Options.BlendPercentage == 1f)
113113
{

tests/ImageSharp.Drawing.Benchmarks/Drawing/DrawBeziers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void DrawLinesCore()
4444
using (var image = new Image<Rgba32>(800, 800))
4545
{
4646
image.Mutate(x => x.DrawBeziers(
47-
Rgba32.HotPink,
47+
Color.HotPink,
4848
10,
4949
new Vector2(10, 500),
5050
new Vector2(30, 10),

0 commit comments

Comments
 (0)