mirror of https://github.com/SixLabors/ImageSharp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
2.0 KiB
59 lines
2.0 KiB
// Copyright (c) Six Labors and contributors.
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
|
using System.Drawing;
|
|
using System.Drawing.Drawing2D;
|
|
using System.Numerics;
|
|
using BenchmarkDotNet.Attributes;
|
|
|
|
using SixLabors.ImageSharp.PixelFormats;
|
|
using SixLabors.ImageSharp.Processing;
|
|
using CoreRectangle = SixLabors.Primitives.Rectangle;
|
|
using CoreSize = SixLabors.Primitives.Size;
|
|
|
|
namespace SixLabors.ImageSharp.Benchmarks
|
|
{
|
|
public class FillRectangle : BenchmarkBase
|
|
{
|
|
[Benchmark(Baseline = true, Description = "System.Drawing Fill Rectangle")]
|
|
public Size FillRectangleSystemDrawing()
|
|
{
|
|
using (var destination = new Bitmap(800, 800))
|
|
using (var graphics = Graphics.FromImage(destination))
|
|
{
|
|
graphics.InterpolationMode = InterpolationMode.Default;
|
|
graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
|
graphics.FillRectangle(System.Drawing.Brushes.HotPink, new Rectangle(10, 10, 190, 140));
|
|
|
|
return destination.Size;
|
|
}
|
|
}
|
|
|
|
[Benchmark(Description = "ImageSharp Fill Rectangle")]
|
|
public CoreSize FillRectangleCore()
|
|
{
|
|
using (var image = new Image<Rgba32>(800, 800))
|
|
{
|
|
image.Mutate(x => x.Fill(Rgba32.HotPink, new CoreRectangle(10, 10, 190, 140)));
|
|
|
|
return new CoreSize(image.Width, image.Height);
|
|
}
|
|
}
|
|
|
|
[Benchmark(Description = "ImageSharp Fill Rectangle - As Polygon")]
|
|
public CoreSize FillPolygonCore()
|
|
{
|
|
using (var image = new Image<Rgba32>(800, 800))
|
|
{
|
|
image.Mutate(x => x.FillPolygon(
|
|
Rgba32.HotPink,
|
|
new Vector2(10, 10),
|
|
new Vector2(200, 10),
|
|
new Vector2(200, 150),
|
|
new Vector2(10, 150)));
|
|
|
|
return new CoreSize(image.Width, image.Height);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|