From 1e0d1e5dd22ef3fe54f4b1a347bf85b613782016 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Fri, 11 Dec 2020 09:56:59 +0100 Subject: [PATCH] Add helper method to register the webp format --- src/ImageSharp/Configuration.cs | 12 ++++++++++++ .../Formats/WebP/ImageExtensionsTest.cs | 5 +---- .../Formats/WebP/WebPDecoderTests.cs | 4 +--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/ImageSharp/Configuration.cs b/src/ImageSharp/Configuration.cs index 43c7d03f7..4a4074a04 100644 --- a/src/ImageSharp/Configuration.cs +++ b/src/ImageSharp/Configuration.cs @@ -6,6 +6,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Bmp; +using SixLabors.ImageSharp.Formats.Experimental.Webp; using SixLabors.ImageSharp.Formats.Gif; using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.Formats.Png; @@ -173,6 +174,17 @@ namespace SixLabors.ImageSharp }; } + /// + /// Registers the webp format detector, encoder and decoder. + /// + public void AddWebp() + { + this.ImageFormatsManager.AddImageFormat(WebpFormat.Instance); + this.ImageFormatsManager.AddImageFormatDetector(new WebpImageFormatDetector()); + this.ImageFormatsManager.SetDecoder(WebpFormat.Instance, new WebpDecoder()); + this.ImageFormatsManager.SetEncoder(WebpFormat.Instance, new WebpEncoder()); + } + /// /// Creates the default instance with the following s preregistered: /// diff --git a/tests/ImageSharp.Tests/Formats/WebP/ImageExtensionsTest.cs b/tests/ImageSharp.Tests/Formats/WebP/ImageExtensionsTest.cs index 003ca54bb..ac60fc482 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/ImageExtensionsTest.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/ImageExtensionsTest.cs @@ -18,10 +18,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp public ImageExtensionsTest() { this.configuration = new Configuration(); - this.configuration.ImageFormatsManager.AddImageFormat(WebpFormat.Instance); - this.configuration.ImageFormatsManager.AddImageFormatDetector(new WebpImageFormatDetector()); - this.configuration.ImageFormatsManager.SetDecoder(WebpFormat.Instance, new WebpDecoder()); - this.configuration.ImageFormatsManager.SetEncoder(WebpFormat.Instance, new WebpEncoder()); + this.configuration.AddWebp(); } [Fact] diff --git a/tests/ImageSharp.Tests/Formats/WebP/WebPDecoderTests.cs b/tests/ImageSharp.Tests/Formats/WebP/WebPDecoderTests.cs index ec25b2afb..eb16a01b8 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/WebPDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/WebPDecoderTests.cs @@ -26,9 +26,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp public WebpDecoderTests() { this.configuration = new Configuration(); - this.configuration.ImageFormatsManager.AddImageFormat(WebpFormat.Instance); - this.configuration.ImageFormatsManager.AddImageFormatDetector(new WebpImageFormatDetector()); - this.configuration.ImageFormatsManager.SetDecoder(WebpFormat.Instance, new WebpDecoder()); + this.configuration.AddWebp(); } [Theory]