From 3ca3f5f8764dc45bf1ce2e9a651095bd43f7e769 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sat, 12 Dec 2020 17:40:52 +0100 Subject: [PATCH] Move AddWebp to a extension method --- src/ImageSharp/Configuration.cs | 12 ---------- .../Formats/WebP/ConfigurationExtensions.cs | 23 +++++++++++++++++++ .../Formats/WebP/WebPEncoderTests.cs | 3 +-- 3 files changed, 24 insertions(+), 14 deletions(-) create mode 100644 src/ImageSharp/Formats/WebP/ConfigurationExtensions.cs diff --git a/src/ImageSharp/Configuration.cs b/src/ImageSharp/Configuration.cs index 4a4074a04..43c7d03f7 100644 --- a/src/ImageSharp/Configuration.cs +++ b/src/ImageSharp/Configuration.cs @@ -6,7 +6,6 @@ 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; @@ -174,17 +173,6 @@ 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/src/ImageSharp/Formats/WebP/ConfigurationExtensions.cs b/src/ImageSharp/Formats/WebP/ConfigurationExtensions.cs new file mode 100644 index 000000000..7077bf9a0 --- /dev/null +++ b/src/ImageSharp/Formats/WebP/ConfigurationExtensions.cs @@ -0,0 +1,23 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +namespace SixLabors.ImageSharp.Formats.Experimental.Webp +{ + /// + /// Helper methods for the Configuration. + /// + public static class ConfigurationExtensions + { + /// + /// Registers the webp format detector, encoder and decoder. + /// + /// The configuration. + public static void AddWebp(this Configuration configuration) + { + configuration.ImageFormatsManager.AddImageFormat(WebpFormat.Instance); + configuration.ImageFormatsManager.AddImageFormatDetector(new WebpImageFormatDetector()); + configuration.ImageFormatsManager.SetDecoder(WebpFormat.Instance, new WebpDecoder()); + configuration.ImageFormatsManager.SetEncoder(WebpFormat.Instance, new WebpEncoder()); + } + } +} diff --git a/tests/ImageSharp.Tests/Formats/WebP/WebPEncoderTests.cs b/tests/ImageSharp.Tests/Formats/WebP/WebPEncoderTests.cs index 3f6daa312..ac2fcaae7 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/WebPEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/WebPEncoderTests.cs @@ -5,11 +5,10 @@ using SixLabors.ImageSharp.Formats.Experimental.Webp; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using Xunit; +using static SixLabors.ImageSharp.Tests.TestImages.WebP; namespace SixLabors.ImageSharp.Tests.Formats.Webp { - using static TestImages.WebP; - [Trait("Format", "Webp")] public class WebpEncoderTests {