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
1.8 KiB
59 lines
1.8 KiB
// Copyright (c) Six Labors and contributors.
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using BenchmarkDotNet.Attributes;
|
|
|
|
using SixLabors.ImageSharp.Formats.Jpeg;
|
|
using SixLabors.ImageSharp.PixelFormats;
|
|
using SixLabors.ImageSharp.Tests;
|
|
using CoreSize = SixLabors.Primitives.Size;
|
|
using SDImage = System.Drawing.Image;
|
|
|
|
namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg
|
|
{
|
|
[Config(typeof(Config.ShortClr))]
|
|
public class DecodeJpeg : BenchmarkBase
|
|
{
|
|
private byte[] jpegBytes;
|
|
|
|
private string TestImageFullPath => Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.TestImage);
|
|
|
|
[Params(TestImages.Jpeg.Baseline.Jpeg420Exif, TestImages.Jpeg.Baseline.Calliphora)]
|
|
public string TestImage { get; set; }
|
|
|
|
[GlobalSetup]
|
|
public void ReadImages()
|
|
{
|
|
if (this.jpegBytes == null)
|
|
{
|
|
this.jpegBytes = File.ReadAllBytes(this.TestImageFullPath);
|
|
}
|
|
}
|
|
|
|
[Benchmark(Baseline = true, Description = "Decode Jpeg - System.Drawing")]
|
|
public Size JpegSystemDrawing()
|
|
{
|
|
using (var memoryStream = new MemoryStream(this.jpegBytes))
|
|
{
|
|
using (var image = SDImage.FromStream(memoryStream))
|
|
{
|
|
return image.Size;
|
|
}
|
|
}
|
|
}
|
|
|
|
[Benchmark(Description = "Decode Jpeg - ImageSharp")]
|
|
public CoreSize JpegImageSharp()
|
|
{
|
|
using (var memoryStream = new MemoryStream(this.jpegBytes))
|
|
{
|
|
using (var image = Image.Load<Rgba32>(memoryStream, new JpegDecoder()))
|
|
{
|
|
return new CoreSize(image.Width, image.Height);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|