|
|
|
@ -3,6 +3,7 @@ |
|
|
|
|
|
|
|
using System.Drawing.Imaging; |
|
|
|
using BenchmarkDotNet.Attributes; |
|
|
|
using ImageMagick; |
|
|
|
using SixLabors.ImageSharp.Formats.Gif; |
|
|
|
using SixLabors.ImageSharp.PixelFormats; |
|
|
|
using SixLabors.ImageSharp.Processing; |
|
|
|
@ -18,6 +19,7 @@ public abstract class EncodeGif |
|
|
|
private FileStream bmpStream; |
|
|
|
private SDImage bmpDrawing; |
|
|
|
private Image<Rgba32> bmpCore; |
|
|
|
private MagickImageCollection magickImage; |
|
|
|
|
|
|
|
protected abstract GifEncoder Encoder { get; } |
|
|
|
|
|
|
|
@ -29,10 +31,14 @@ public abstract class EncodeGif |
|
|
|
{ |
|
|
|
if (this.bmpStream == null) |
|
|
|
{ |
|
|
|
this.bmpStream = File.OpenRead(Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.TestImage)); |
|
|
|
string filePath = Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.TestImage); |
|
|
|
this.bmpStream = File.OpenRead(filePath); |
|
|
|
this.bmpCore = Image.Load<Rgba32>(this.bmpStream); |
|
|
|
this.bmpStream.Position = 0; |
|
|
|
this.bmpDrawing = SDImage.FromStream(this.bmpStream); |
|
|
|
|
|
|
|
this.bmpStream.Position = 0; |
|
|
|
this.magickImage = new MagickImageCollection(this.bmpStream); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -43,6 +49,7 @@ public abstract class EncodeGif |
|
|
|
this.bmpStream = null; |
|
|
|
this.bmpCore.Dispose(); |
|
|
|
this.bmpDrawing.Dispose(); |
|
|
|
this.magickImage.Dispose(); |
|
|
|
} |
|
|
|
|
|
|
|
[Benchmark(Baseline = true, Description = "System.Drawing Gif")] |
|
|
|
@ -58,6 +65,13 @@ public abstract class EncodeGif |
|
|
|
using MemoryStream memoryStream = new(); |
|
|
|
this.bmpCore.SaveAsGif(memoryStream, this.Encoder); |
|
|
|
} |
|
|
|
|
|
|
|
[Benchmark(Description = "Magick.NET Gif")] |
|
|
|
public void GifMagickNet() |
|
|
|
{ |
|
|
|
using MemoryStream ms = new(); |
|
|
|
this.magickImage.Write(ms, MagickFormat.Gif); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public class EncodeGif_DefaultEncoder : EncodeGif |
|
|
|
|