Skip to content

Commit 8798c4a

Browse files
committed
fix bug, improve bencmharks
1 parent 55829c1 commit 8798c4a

4 files changed

Lines changed: 22 additions & 12 deletions

File tree

src/ImageSharp.Drawing/Shapes/Rasterization/RasterizerExtensions.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ private static void ScanCurrentSubpixelLineInto(this ref PolygonScanner scanner,
6161
endX = Math.Min(endX, scanline.Length); // reduce to end to the right edge
6262
nextX = Math.Max(nextX, 0);
6363

64-
scanline.Slice(nextX, endX - nextX).AddToAllElements(scanner.SubpixelDistance);
64+
if (endX > nextX)
65+
{
66+
scanline.Slice(nextX, endX - nextX).AddToAllElements(scanner.SubpixelDistance);
67+
scanlineDirty = true;
68+
}
6569
}
6670
}
6771
}

tests/ImageSharp.Drawing.Benchmarks/Drawing/DrawText.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public class DrawText
3939
private Image<Rgba32> image;
4040
private SDBitmap sdBitmap;
4141
private Graphics sdGraphics;
42-
private SKSurface skSurface;
43-
44-
42+
private SKBitmap skBitmap;
43+
private SKCanvas skCanvas;
44+
4545
private SDFont sdFont;
4646
private Fonts.Font font;
4747
private SKTypeface skTypeface;
@@ -56,7 +56,8 @@ public void Setup()
5656
this.sdGraphics.SmoothingMode = SmoothingMode.AntiAlias;
5757
this.sdGraphics.InterpolationMode = InterpolationMode.Default;
5858
this.sdGraphics.SmoothingMode = SmoothingMode.AntiAlias;
59-
this.skSurface = SKSurface.Create(new SKImageInfo(Width, Height));
59+
this.skBitmap = new SKBitmap(Width, Height);
60+
this.skCanvas = new SKCanvas(this.skBitmap);
6061

6162
this.sdFont = new SDFont("Arial", 12, GraphicsUnit.Point);
6263
this.font = Fonts.SystemFonts.CreateFont("Arial", 12);
@@ -69,7 +70,8 @@ public void Cleanup()
6970
this.image.Dispose();
7071
this.sdGraphics.Dispose();
7172
this.sdBitmap.Dispose();
72-
this.skSurface.Dispose();
73+
this.skCanvas.Dispose();
74+
this.skBitmap.Dispose();
7375
this.sdFont.Dispose();
7476
this.skTypeface.Dispose();
7577
}
@@ -108,7 +110,7 @@ public void SkiaSharp()
108110
Typeface = skTypeface
109111
};
110112

111-
this.skSurface.Canvas.DrawText(TextToRender, 10, 10, paint);
113+
this.skCanvas.DrawText(TextToRender, 10, 10, paint);
112114
}
113115
}
114116
}

tests/ImageSharp.Drawing.Benchmarks/Drawing/FillPolygon.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public abstract class FillPolygon
3131
private Image<Rgba32> image;
3232
private SDBitmap sdBitmap;
3333
private Graphics sdGraphics;
34-
private SKSurface skSurface;
34+
private SKBitmap skBitmap;
35+
private SKCanvas skCanvas;
3536

3637
protected abstract int Width { get; }
3738
protected abstract int Height { get; }
@@ -69,7 +70,8 @@ public void Setup()
6970
this.sdGraphics = Graphics.FromImage(this.sdBitmap);
7071
this.sdGraphics.InterpolationMode = InterpolationMode.Default;
7172
this.sdGraphics.SmoothingMode = SmoothingMode.AntiAlias;
72-
this.skSurface = SKSurface.Create(new SKImageInfo(Width, Height));
73+
this.skBitmap = new SKBitmap(Width, Height);
74+
this.skCanvas = new SKCanvas(skBitmap);
7375
}
7476

7577
[GlobalCleanup]
@@ -78,7 +80,8 @@ public void Cleanup()
7880
this.image.Dispose();
7981
this.sdGraphics.Dispose();
8082
this.sdBitmap.Dispose();
81-
this.skSurface.Dispose();
83+
this.skCanvas.Dispose();
84+
this.skBitmap.Dispose();
8285
foreach (SKPath skPath in this.skPaths)
8386
{
8487
skPath.Dispose();
@@ -120,7 +123,7 @@ public void SkiaSharp()
120123
Color = SKColors.White,
121124
IsAntialias = true,
122125
};
123-
this.skSurface.Canvas.DrawPath(path, paint);
126+
this.skCanvas.DrawPath(path, paint);
124127
}
125128
}
126129
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<RootNamespace>SixLabors.ImageSharp.Drawing.Benchmarks</RootNamespace>
6-
<TargetFrameworks>netcoreapp3.1;netcoreapp2.1;net472</TargetFrameworks>
6+
<!-- <TargetFrameworks>netcoreapp3.1;netcoreapp2.1;net472</TargetFrameworks>-->
7+
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
78
<IsPackable>false</IsPackable>
89
<GenerateProgramFile>false</GenerateProgramFile>
910
<!--Used to hide test project from dotnet test-->

0 commit comments

Comments
 (0)