Skip to content

Commit 1eeb158

Browse files
committed
wip2
1 parent bd624fe commit 1eeb158

File tree

5 files changed

+79
-160
lines changed

5 files changed

+79
-160
lines changed

tests/ImageSharp.Drawing.Benchmarks/Drawing/FillTiger.cs

Lines changed: 4 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Drawing.Drawing2D;
66
using BenchmarkDotNet.Attributes;
77
using SixLabors.ImageSharp.Drawing.Processing;
8-
using SixLabors.ImageSharp.Drawing.Processing.Backends;
98
using SixLabors.ImageSharp.Drawing.Tests;
109
using SixLabors.ImageSharp.PixelFormats;
1110
using SixLabors.ImageSharp.Processing;
@@ -35,8 +34,6 @@ public class FillTiger
3534
private Image<Rgba32> image;
3635
private List<(IPath Path, Processing.SolidBrush Fill, SolidPen Stroke)> isElements;
3736

38-
private WebGPURenderTarget<Rgba32> webGpuTarget;
39-
4037
[Params(1000, 100)]
4138
public int Dimensions { get; set; }
4239

@@ -64,8 +61,6 @@ public void Setup()
6461

6562
this.image = new Image<Rgba32>(width, height);
6663
this.isElements = SvgBenchmarkHelper.BuildImageSharpElements(elements, scale);
67-
68-
this.webGpuTarget = new WebGPURenderTarget<Rgba32>(width, height);
6964
}
7065

7166
[IterationSetup]
@@ -98,8 +93,6 @@ public void Cleanup()
9893
this.sdBitmap.Dispose();
9994

10095
this.image.Dispose();
101-
102-
this.webGpuTarget.Dispose();
10396
}
10497

10598
[Benchmark(Baseline = true)]
@@ -139,83 +132,19 @@ public void SystemDrawing()
139132

140133
[Benchmark]
141134
public void ImageSharp()
142-
=> this.image.Mutate(c => c.ProcessWithCanvas(canvas =>
143-
{
144-
foreach ((IPath path, Processing.SolidBrush fill, SolidPen stroke) in this.isElements)
145-
{
146-
if (fill is not null)
147-
{
148-
canvas.Fill(fill, path);
149-
}
150-
151-
if (stroke is not null)
152-
{
153-
canvas.Draw(stroke, path);
154-
}
155-
}
156-
}));
157-
158-
[Benchmark]
159-
public void ImageSharp_SingleThreaded()
160-
{
161-
Configuration configuration = this.image.Configuration.Clone();
162-
configuration.MaxDegreeOfParallelism = 1;
163-
this.image.Mutate(configuration, c => c.ProcessWithCanvas(canvas =>
135+
=> this.image.Mutate(c =>
164136
{
165137
foreach ((IPath path, Processing.SolidBrush fill, SolidPen stroke) in this.isElements)
166138
{
167139
if (fill is not null)
168140
{
169-
canvas.Fill(fill, path);
141+
c.Fill(fill, path);
170142
}
171143

172144
if (stroke is not null)
173145
{
174-
canvas.Draw(stroke, path);
146+
c.Draw(stroke, path);
175147
}
176148
}
177-
}));
178-
}
179-
180-
[Benchmark]
181-
public void ImageSharpWebGPU()
182-
{
183-
using DrawingCanvas<Rgba32> canvas = this.webGpuTarget.CreateCanvas();
184-
foreach ((IPath path, Processing.SolidBrush fill, SolidPen stroke) in this.isElements)
185-
{
186-
if (fill is not null)
187-
{
188-
canvas.Fill(fill, path);
189-
}
190-
191-
if (stroke is not null)
192-
{
193-
canvas.Draw(stroke, path);
194-
}
195-
}
196-
197-
canvas.Flush();
198-
}
199-
200-
public static void VerifyOutput()
201-
{
202-
FillTiger bench = new();
203-
bench.Setup();
204-
205-
bench.SkiaSharp();
206-
bench.SystemDrawing();
207-
bench.ImageSharp();
208-
bench.ImageSharpWebGPU();
209-
210-
//SvgBenchmarkHelper.VerifyOutput(
211-
// "tiger",
212-
// Width,
213-
// Height,
214-
// bench.skSurface,
215-
// bench.sdBitmap,
216-
// bench.image,
217-
// bench.webGpuTarget.TextureHandle);
218-
219-
bench.Cleanup();
220-
}
149+
});
221150
}

tests/ImageSharp.Drawing.Benchmarks/ImageSharp.Drawing.Benchmarks.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
</PropertyGroup>
2121
</Otherwise>
2222
</Choose>
23-
23+
2424
<ItemGroup>
2525
<PackageReference Include="BenchmarkDotNet" />
2626
<PackageReference Include="System.Drawing.Common" />
@@ -45,6 +45,9 @@
4545
<Compile Include="..\ImageSharp.Drawing.Tests\TestUtilities\TestEnvironment.cs">
4646
<Link>TestEnvironment.cs</Link>
4747
</Compile>
48+
<Compile Include="..\ImageSharp.Drawing.Tests\TestUtilities\SvgBenchmarkHelper.cs">
49+
<Link>SvgBenchmarkHelper.cs</Link>
50+
</Compile>
4851
</ItemGroup>
4952

5053
</Project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Six Labors Split License.
3+
4+
using SixLabors.ImageSharp.Drawing.Processing;
5+
using SixLabors.ImageSharp.PixelFormats;
6+
using SixLabors.ImageSharp.Processing;
7+
8+
namespace SixLabors.ImageSharp.Drawing.Tests.Drawing;
9+
10+
public class SvgTests
11+
{
12+
[Theory]
13+
[WithBlankImage(200, 200, PixelTypes.Rgba32, 1f)]
14+
public void Tiger<TPixel>(TestImageProvider<TPixel> provider, float scale)
15+
where TPixel : unmanaged, IPixel<TPixel>
16+
{
17+
List<(IPath Path, SolidBrush Fill, SolidPen Stroke)> elements = SvgBenchmarkHelper.BuildImageSharpElements(
18+
SvgBenchmarkHelper.ParseSvg(TestFile.GetInputFileFullPath(TestImages.Svg.GhostscriptTiger)), scale);
19+
Image<TPixel> image = provider.GetImage();
20+
image.Mutate(c =>
21+
{
22+
foreach ((IPath path, SolidBrush fill, SolidPen stroke) in elements)
23+
{
24+
if (fill is not null)
25+
{
26+
c.Fill(fill, path);
27+
}
28+
29+
if (stroke is not null)
30+
{
31+
c.Draw(stroke, path);
32+
}
33+
}
34+
});
35+
}
36+
}

tests/ImageSharp.Drawing.Tests/TestImages.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,4 +394,10 @@ public static class GeoJson
394394
{
395395
public const string States = "GeoJson/States.json";
396396
}
397+
398+
public static class Svg
399+
{
400+
public const string GhostscriptTiger = "Svg/Ghostscript_Tiger.svg";
401+
public const string Paris30k = "Svg/paris-30k.svg";
402+
}
397403
}

0 commit comments

Comments
 (0)