diff --git a/tests/ImageSharp.Benchmarks/Codecs/DecodeWebp.cs b/tests/ImageSharp.Benchmarks/Codecs/DecodeWebp.cs new file mode 100644 index 000000000..ff9386286 --- /dev/null +++ b/tests/ImageSharp.Benchmarks/Codecs/DecodeWebp.cs @@ -0,0 +1,87 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System.IO; +using BenchmarkDotNet.Attributes; + +using ImageMagick; + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests; + +namespace SixLabors.ImageSharp.Benchmarks.Codecs +{ + [Config(typeof(Config.ShortClr))] + public class DecodeWebp : BenchmarkBase + { + private byte[] webpLossyBytes; + private byte[] webpLosslessBytes; + + private string TestImageLossyFullPath => Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.TestImageLossy); + private string TestImageLosslessFullPath => Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.TestImageLossless); + + [Params(TestImages.WebP.Lossy.Bike)] + public string TestImageLossy { get; set; } + + [Params(TestImages.WebP.Lossless.BikeThreeTransforms)] + public string TestImageLossless { get; set; } + + [GlobalSetup] + public void ReadImages() + { + if (this.webpLossyBytes is null) + { + this.webpLossyBytes = File.ReadAllBytes(this.TestImageLossyFullPath); + } + + if (this.webpLosslessBytes is null) + { + this.webpLosslessBytes = File.ReadAllBytes(this.TestImageLosslessFullPath); + } + } + + [Benchmark(Baseline = true, Description = "Magick Lossy WebP")] + public int WebpLossyMagick() + { + var settings = new MagickReadSettings { Format = MagickFormat.WebP }; + using (var image = new MagickImage(new MemoryStream(this.webpLossyBytes), settings)) + { + return image.Width; + } + } + + [Benchmark(Description = "ImageSharp Lossy Webp")] + public int WebpLossy() + { + using (var memoryStream = new MemoryStream(this.webpLossyBytes)) + { + using (var image = Image.Load(memoryStream)) + { + return image.Height; + } + } + } + + [Benchmark(Baseline = true, Description = "Magick Lossless WebP")] + public int WebpLosslessMagick() + { + var settings = new MagickReadSettings { Format = MagickFormat.WebP }; + using (var image = new MagickImage(new MemoryStream(this.webpLosslessBytes), settings)) + { + return image.Width; + } + } + + [Benchmark(Description = "ImageSharp Lossless Webp")] + public int WebpLossless() + { + using (var memoryStream = new MemoryStream(this.webpLosslessBytes)) + { + using (var image = Image.Load(memoryStream)) + { + return image.Height; + } + } + } + } +} diff --git a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj index 14ad5635c..e355ad024 100644 --- a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj +++ b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj @@ -1,4 +1,4 @@ - + @@ -16,6 +16,7 @@ + diff --git a/tests/ImageSharp.Tests/Formats/WebP/WebPDecoderTests.cs b/tests/ImageSharp.Tests/Formats/WebP/WebPDecoderTests.cs index 052188904..fea51bf73 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/WebPDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/WebPDecoderTests.cs @@ -287,7 +287,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP [WithFile(Lossless.ThreeTransforms5, PixelTypes.Rgba32)] [WithFile(Lossless.ThreeTransforms6, PixelTypes.Rgba32)] [WithFile(Lossless.ThreeTransforms7, PixelTypes.Rgba32)] - [WithFile(Lossless.ThreeTransforms8, PixelTypes.Rgba32)] + [WithFile(Lossless.BikeThreeTransforms, PixelTypes.Rgba32)] public void WebpDecoder_CanDecode_Lossless_WithThreeTransforms(TestImageProvider provider) where TPixel : struct, IPixel { diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index 87fdf520a..66c936ad5 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -416,7 +416,7 @@ namespace SixLabors.ImageSharp.Tests public const string ThreeTransforms5 = "Webp/lossless_vec_2_11.webp"; // color_indexing, predictor, cross_color public const string ThreeTransforms6 = "Webp/lossless_vec_2_14.webp"; // substract_green, predictor, cross_color public const string ThreeTransforms7 = "Webp/lossless_vec_2_15.webp"; // color_indexing, predictor, cross_color - public const string ThreeTransforms8 = "Webp/bike_lossless.webp"; // substract_green, predictor, cross_color + public const string BikeThreeTransforms = "Webp/bike_lossless.webp"; // substract_green, predictor, cross_color // Invalid / corrupted images // Below images have errors according to webpinfo. The error message webpinfo gives is "Truncated data detected when parsing RIFF payload."