From ef60a6237e084d0609ac784de122fc746987bd05 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Sat, 31 Dec 2016 11:15:50 +1100 Subject: [PATCH] Rename Bootstrapper to Configuration --- Settings.StyleCop | 1 - .../{Bootstrapper.cs => Configuration.cs} | 14 +++---- src/ImageSharp/Formats/IImageFormat.cs | 2 +- src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs | 6 +-- src/ImageSharp/Image.cs | 24 ++++++------ src/ImageSharp/Image/ImageBase{TColor}.cs | 22 +++++------ src/ImageSharp/Image/ImageFrame{TColor}.cs | 12 +++--- src/ImageSharp/Image/Image{TColor}.cs | 38 +++++++++---------- src/ImageSharp/Image/PixelAccessor{TColor}.cs | 4 +- src/ImageSharp/ImageFrame.cs | 8 ++-- src/ImageSharp/ImageProcessor.cs | 2 +- src/ImageSharp/Quantizers/Quantize.cs | 2 +- .../ImageSharp.Benchmarks/Image/CopyPixels.cs | 2 +- ...strapperTests.cs => ConfigurationTests.cs} | 26 ++++++------- tests/ImageSharp.Tests/TestFile.cs | 8 ++-- .../TestUtilities/ImagingTestCaseUtility.cs | 2 +- 16 files changed, 86 insertions(+), 87 deletions(-) rename src/ImageSharp/{Bootstrapper.cs => Configuration.cs} (91%) rename tests/ImageSharp.Tests/{BootstrapperTests.cs => ConfigurationTests.cs} (84%) diff --git a/Settings.StyleCop b/Settings.StyleCop index 737491cb1..2716e8d0a 100644 --- a/Settings.StyleCop +++ b/Settings.StyleCop @@ -39,7 +39,6 @@ desensitivity premultiplied endianness - bootstrapper thresholding diff --git a/src/ImageSharp/Bootstrapper.cs b/src/ImageSharp/Configuration.cs similarity index 91% rename from src/ImageSharp/Bootstrapper.cs rename to src/ImageSharp/Configuration.cs index f44c6568c..013c13495 100644 --- a/src/ImageSharp/Bootstrapper.cs +++ b/src/ImageSharp/Configuration.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -16,15 +16,15 @@ namespace ImageSharp /// /// Provides initialization code which allows extending the library. /// - public class Bootstrapper + public class Configuration { /// - /// A lazily initialized bootstrapper default instance. + /// A lazily initialized configuration default instance. /// - private static readonly Lazy Lazy = new Lazy(() => new Bootstrapper()); + private static readonly Lazy Lazy = new Lazy(() => new Configuration()); /// - /// An object that can be used to synchronize access to the . + /// An object that can be used to synchronize access to the . /// private static readonly object SyncRoot = new object(); @@ -34,9 +34,9 @@ namespace ImageSharp private readonly List imageFormatsList = new List(); /// - /// Gets the default instance. + /// Gets the default instance. /// - public static Bootstrapper Default { get; } = Lazy.Value; + public static Configuration Default { get; } = Lazy.Value; /// /// Gets the collection of supported diff --git a/src/ImageSharp/Formats/IImageFormat.cs b/src/ImageSharp/Formats/IImageFormat.cs index ea2be7b29..de2e400fa 100644 --- a/src/ImageSharp/Formats/IImageFormat.cs +++ b/src/ImageSharp/Formats/IImageFormat.cs @@ -9,7 +9,7 @@ namespace ImageSharp.Formats /// /// Encapsulates a supported image format, providing means to encode and decode an image. - /// Individual formats implements in this interface must be registered in the + /// Individual formats implements in this interface must be registered in the /// public interface IImageFormat { diff --git a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs index 981984333..6fbbc312f 100644 --- a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs @@ -687,7 +687,7 @@ namespace ImageSharp.Formats Parallel.For( 0, height, - image.Bootstrapper.ParallelOptions, + image.Configuration.ParallelOptions, y => { int yoff = this.grayImage.GetRowOffset(y); @@ -723,7 +723,7 @@ namespace ImageSharp.Formats Parallel.For( 0, height, - image.Bootstrapper.ParallelOptions, + image.Configuration.ParallelOptions, y => { // TODO: Simplify + optimize + share duplicate code across converter methods @@ -764,7 +764,7 @@ namespace ImageSharp.Formats Parallel.For( 0, height, - image.Bootstrapper.ParallelOptions, + image.Configuration.ParallelOptions, y => { // TODO: Simplify + optimize + share duplicate code across converter methods diff --git a/src/ImageSharp/Image.cs b/src/ImageSharp/Image.cs index 772cf6dbe..99c24139c 100644 --- a/src/ImageSharp/Image.cs +++ b/src/ImageSharp/Image.cs @@ -21,11 +21,11 @@ namespace ImageSharp /// /// The width of the image in pixels. /// The height of the image in pixels. - /// - /// The bootstrapper providing initialization code which allows extending the library. + /// + /// The configuration providing initialization code which allows extending the library. /// - public Image(int width, int height, Bootstrapper bootstrapper = null) - : base(width, height, bootstrapper) + public Image(int width, int height, Configuration configuration = null) + : base(width, height, configuration) { } @@ -35,12 +35,12 @@ namespace ImageSharp /// /// The stream containing image information. /// - /// - /// The bootstrapper providing initialization code which allows extending the library. + /// + /// The configuration providing initialization code which allows extending the library. /// /// Thrown if the is null. - public Image(Stream stream, Bootstrapper bootstrapper = null) - : base(stream, bootstrapper) + public Image(Stream stream, Configuration configuration = null) + : base(stream, configuration) { } @@ -50,12 +50,12 @@ namespace ImageSharp /// /// The byte array containing image information. /// - /// - /// The bootstrapper providing initialization code which allows extending the library. + /// + /// The configuration providing initialization code which allows extending the library. /// /// Thrown if the is null. - public Image(byte[] bytes, Bootstrapper bootstrapper = null) - : base(bytes, bootstrapper) + public Image(byte[] bytes, Configuration configuration = null) + : base(bytes, configuration) { } diff --git a/src/ImageSharp/Image/ImageBase{TColor}.cs b/src/ImageSharp/Image/ImageBase{TColor}.cs index 4ac847d16..8feaabdab 100644 --- a/src/ImageSharp/Image/ImageBase{TColor}.cs +++ b/src/ImageSharp/Image/ImageBase{TColor}.cs @@ -25,12 +25,12 @@ namespace ImageSharp /// /// Initializes a new instance of the class. /// - /// - /// The bootstrapper providing initialization code which allows extending the library. + /// + /// The configuration providing initialization code which allows extending the library. /// - protected ImageBase(Bootstrapper bootstrapper = null) + protected ImageBase(Configuration configuration = null) { - this.Bootstrapper = bootstrapper ?? Bootstrapper.Default; + this.Configuration = configuration ?? Configuration.Default; } /// @@ -38,15 +38,15 @@ namespace ImageSharp /// /// The width of the image in pixels. /// The height of the image in pixels. - /// - /// The bootstrapper providing initialization code which allows extending the library. + /// + /// The configuration providing initialization code which allows extending the library. /// /// /// Thrown if either or are less than or equal to 0. /// - protected ImageBase(int width, int height, Bootstrapper bootstrapper = null) + protected ImageBase(int width, int height, Configuration configuration = null) { - this.Bootstrapper = bootstrapper ?? Bootstrapper.Default; + this.Configuration = configuration ?? Configuration.Default; this.InitPixels(width, height); } @@ -104,9 +104,9 @@ namespace ImageSharp public int FrameDelay { get; set; } /// - /// Gets the bootstrapper providing initialization code which allows extending the library. + /// Gets the configuration providing initialization code which allows extending the library. /// - public Bootstrapper Bootstrapper { get; private set; } + public Configuration Configuration { get; private set; } /// public void InitPixels(int width, int height) @@ -170,7 +170,7 @@ namespace ImageSharp /// protected void CopyProperties(ImageBase other) { - this.Bootstrapper = other.Bootstrapper; + this.Configuration = other.Configuration; this.Quality = other.Quality; this.FrameDelay = other.FrameDelay; } diff --git a/src/ImageSharp/Image/ImageFrame{TColor}.cs b/src/ImageSharp/Image/ImageFrame{TColor}.cs index aaf775ebb..809eca1a4 100644 --- a/src/ImageSharp/Image/ImageFrame{TColor}.cs +++ b/src/ImageSharp/Image/ImageFrame{TColor}.cs @@ -21,11 +21,11 @@ namespace ImageSharp /// /// The width of the image in pixels. /// The height of the image in pixels. - /// - /// The bootstrapper providing initialization code which allows extending the library. + /// + /// The configuration providing initialization code which allows extending the library. /// - public ImageFrame(int width, int height, Bootstrapper bootstrapper = null) - : base(width, height, bootstrapper) + public ImageFrame(int width, int height, Configuration configuration = null) + : base(width, height, configuration) { } @@ -55,7 +55,7 @@ namespace ImageSharp { scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction(scaleFunc); - ImageFrame target = new ImageFrame(this.Width, this.Height, this.Bootstrapper) + ImageFrame target = new ImageFrame(this.Width, this.Height, this.Configuration) { Quality = this.Quality, FrameDelay = this.FrameDelay @@ -67,7 +67,7 @@ namespace ImageSharp Parallel.For( 0, target.Height, - this.Bootstrapper.ParallelOptions, + this.Configuration.ParallelOptions, y => { for (int x = 0; x < target.Width; x++) diff --git a/src/ImageSharp/Image/Image{TColor}.cs b/src/ImageSharp/Image/Image{TColor}.cs index 84fb39a0c..4d9511835 100644 --- a/src/ImageSharp/Image/Image{TColor}.cs +++ b/src/ImageSharp/Image/Image{TColor}.cs @@ -43,13 +43,13 @@ namespace ImageSharp /// /// The width of the image in pixels. /// The height of the image in pixels. - /// - /// The bootstrapper providing initialization code which allows extending the library. + /// + /// The configuration providing initialization code which allows extending the library. /// - public Image(int width, int height, Bootstrapper bootstrapper = null) - : base(width, height, bootstrapper) + public Image(int width, int height, Configuration configuration = null) + : base(width, height, configuration) { - this.CurrentImageFormat = this.Bootstrapper.ImageFormats.First(); + this.CurrentImageFormat = this.Configuration.ImageFormats.First(); } /// @@ -58,12 +58,12 @@ namespace ImageSharp /// /// The stream containing image information. /// - /// - /// The bootstrapper providing initialization code which allows extending the library. + /// + /// The configuration providing initialization code which allows extending the library. /// /// Thrown if the is null. - public Image(Stream stream, Bootstrapper bootstrapper = null) - : base(bootstrapper) + public Image(Stream stream, Configuration configuration = null) + : base(configuration) { Guard.NotNull(stream, nameof(stream)); this.Load(stream); @@ -75,12 +75,12 @@ namespace ImageSharp /// /// The byte array containing image information. /// - /// - /// The bootstrapper providing initialization code which allows extending the library. + /// + /// The configuration providing initialization code which allows extending the library. /// /// Thrown if the is null. - public Image(byte[] bytes, Bootstrapper bootstrapper = null) - : base(bootstrapper) + public Image(byte[] bytes, Configuration configuration = null) + : base(configuration) { Guard.NotNull(bytes, nameof(bytes)); @@ -296,7 +296,7 @@ namespace ImageSharp { scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction(scaleFunc); - Image target = new Image(this.Width, this.Height, this.Bootstrapper) + Image target = new Image(this.Width, this.Height, this.Configuration) { Quality = this.Quality, FrameDelay = this.FrameDelay, @@ -312,7 +312,7 @@ namespace ImageSharp Parallel.For( 0, target.Height, - this.Bootstrapper.ParallelOptions, + this.Configuration.ParallelOptions, y => { for (int x = 0; x < target.Width; x++) @@ -376,7 +376,7 @@ namespace ImageSharp /// private void Load(Stream stream) { - if (!this.Bootstrapper.ImageFormats.Any()) + if (!this.Configuration.ImageFormats.Any()) { throw new NotSupportedException("No image formats have been configured."); } @@ -411,7 +411,7 @@ namespace ImageSharp StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("Image cannot be loaded. Available formats:"); - foreach (IImageFormat format in this.Bootstrapper.ImageFormats) + foreach (IImageFormat format in this.Configuration.ImageFormats) { stringBuilder.AppendLine("-" + format); } @@ -428,7 +428,7 @@ namespace ImageSharp /// private bool Decode(Stream stream) { - int maxHeaderSize = this.Bootstrapper.MaxHeaderSize; + int maxHeaderSize = this.Configuration.MaxHeaderSize; if (maxHeaderSize <= 0) { return false; @@ -441,7 +441,7 @@ namespace ImageSharp long startPosition = stream.Position; stream.Read(header, 0, maxHeaderSize); stream.Position = startPosition; - format = this.Bootstrapper.ImageFormats.FirstOrDefault(x => x.IsSupportedFileFormat(header)); + format = this.Configuration.ImageFormats.FirstOrDefault(x => x.IsSupportedFileFormat(header)); } finally { diff --git a/src/ImageSharp/Image/PixelAccessor{TColor}.cs b/src/ImageSharp/Image/PixelAccessor{TColor}.cs index dc8c33dbe..b4f02c7be 100644 --- a/src/ImageSharp/Image/PixelAccessor{TColor}.cs +++ b/src/ImageSharp/Image/PixelAccessor{TColor}.cs @@ -61,7 +61,7 @@ namespace ImageSharp this.pixelsBase = (byte*)this.dataPointer.ToPointer(); this.PixelSize = Unsafe.SizeOf(); this.RowStride = this.Width * this.PixelSize; - this.ParallelOptions = image.Bootstrapper.ParallelOptions; + this.ParallelOptions = image.Configuration.ParallelOptions; } /// @@ -88,7 +88,7 @@ namespace ImageSharp this.pixelsBase = (byte*)this.dataPointer.ToPointer(); this.PixelSize = Unsafe.SizeOf(); this.RowStride = this.Width * this.PixelSize; - this.ParallelOptions = Bootstrapper.Default.ParallelOptions; + this.ParallelOptions = Configuration.Default.ParallelOptions; } /// diff --git a/src/ImageSharp/ImageFrame.cs b/src/ImageSharp/ImageFrame.cs index 66a2049e8..89f7b9ad5 100644 --- a/src/ImageSharp/ImageFrame.cs +++ b/src/ImageSharp/ImageFrame.cs @@ -18,11 +18,11 @@ namespace ImageSharp /// /// The width of the image in pixels. /// The height of the image in pixels. - /// - /// The bootstrapper providing initialization code which allows extending the library. + /// + /// The configuration providing initialization code which allows extending the library. /// - public ImageFrame(int width, int height, Bootstrapper bootstrapper = null) - : base(width, height, bootstrapper) + public ImageFrame(int width, int height, Configuration configuration = null) + : base(width, height, configuration) { } diff --git a/src/ImageSharp/ImageProcessor.cs b/src/ImageSharp/ImageProcessor.cs index 57c921893..49b60b678 100644 --- a/src/ImageSharp/ImageProcessor.cs +++ b/src/ImageSharp/ImageProcessor.cs @@ -26,7 +26,7 @@ namespace ImageSharp.Processors { if (this.ParallelOptions == null) { - this.ParallelOptions = source.Bootstrapper.ParallelOptions; + this.ParallelOptions = source.Configuration.ParallelOptions; } try diff --git a/src/ImageSharp/Quantizers/Quantize.cs b/src/ImageSharp/Quantizers/Quantize.cs index b34398448..7a42090c7 100644 --- a/src/ImageSharp/Quantizers/Quantize.cs +++ b/src/ImageSharp/Quantizers/Quantize.cs @@ -65,7 +65,7 @@ namespace ImageSharp Parallel.For( 0, pixelCount, - source.Bootstrapper.ParallelOptions, + source.Configuration.ParallelOptions, i => { TColor color = quantized.Palette[Math.Min(palleteCount, quantized.Pixels[i])]; diff --git a/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs b/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs index b17dc7aaf..cddcc268d 100644 --- a/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs +++ b/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs @@ -25,7 +25,7 @@ namespace ImageSharp.Benchmarks.Image Parallel.For( 0, source.Height, - Bootstrapper.Default.ParallelOptions, + Configuration.Default.ParallelOptions, y => { for (int x = 0; x < source.Width; x++) diff --git a/tests/ImageSharp.Tests/BootstrapperTests.cs b/tests/ImageSharp.Tests/ConfigurationTests.cs similarity index 84% rename from tests/ImageSharp.Tests/BootstrapperTests.cs rename to tests/ImageSharp.Tests/ConfigurationTests.cs index 096b9f0d5..507b835fb 100644 --- a/tests/ImageSharp.Tests/BootstrapperTests.cs +++ b/tests/ImageSharp.Tests/ConfigurationTests.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -11,7 +11,7 @@ namespace ImageSharp.Tests using Xunit; using System.Linq; - public class BootstrapperTests + public class ConfigurationTests { private class TestFormat : IImageFormat { @@ -52,7 +52,7 @@ namespace ImageSharp.Tests exception = Assert.Throws(() => { - Bootstrapper.Default.AddImageFormat(null); + Configuration.Default.AddImageFormat(null); }); var format = new TestFormat(); @@ -60,7 +60,7 @@ namespace ImageSharp.Tests exception = Assert.Throws(() => { - Bootstrapper.Default.AddImageFormat(format); + Configuration.Default.AddImageFormat(format); }); Assert.Contains("decoder", exception.Message); @@ -69,7 +69,7 @@ namespace ImageSharp.Tests exception = Assert.Throws(() => { - Bootstrapper.Default.AddImageFormat(format); + Configuration.Default.AddImageFormat(format); }); Assert.Contains("encoder", exception.Message); @@ -78,7 +78,7 @@ namespace ImageSharp.Tests exception = Assert.Throws(() => { - Bootstrapper.Default.AddImageFormat(format); + Configuration.Default.AddImageFormat(format); }); Assert.Contains("mime type", exception.Message); @@ -87,7 +87,7 @@ namespace ImageSharp.Tests exception = Assert.Throws(() => { - Bootstrapper.Default.AddImageFormat(format); + Configuration.Default.AddImageFormat(format); }); Assert.Contains("mime type", exception.Message); @@ -96,7 +96,7 @@ namespace ImageSharp.Tests exception = Assert.Throws(() => { - Bootstrapper.Default.AddImageFormat(format); + Configuration.Default.AddImageFormat(format); }); Assert.Contains("extension", exception.Message); @@ -105,7 +105,7 @@ namespace ImageSharp.Tests exception = Assert.Throws(() => { - Bootstrapper.Default.AddImageFormat(format); + Configuration.Default.AddImageFormat(format); }); Assert.Contains("extension", exception.Message); @@ -114,7 +114,7 @@ namespace ImageSharp.Tests exception = Assert.Throws(() => { - Bootstrapper.Default.AddImageFormat(format); + Configuration.Default.AddImageFormat(format); }); Assert.Contains("supported extensions", exception.Message); @@ -123,7 +123,7 @@ namespace ImageSharp.Tests exception = Assert.Throws(() => { - Bootstrapper.Default.AddImageFormat(format); + Configuration.Default.AddImageFormat(format); }); Assert.Contains("supported extensions", exception.Message); } @@ -136,14 +136,14 @@ namespace ImageSharp.Tests format.Extension = "test"; var exception = Assert.Throws(() => { - Bootstrapper.Default.AddImageFormat(format); + Configuration.Default.AddImageFormat(format); }); Assert.Contains("should contain", exception.Message); format.SupportedExtensions = new string[] { "test", "" }; exception = Assert.Throws(() => { - Bootstrapper.Default.AddImageFormat(format); + Configuration.Default.AddImageFormat(format); }); Assert.Contains("empty values", exception.Message); } diff --git a/tests/ImageSharp.Tests/TestFile.cs b/tests/ImageSharp.Tests/TestFile.cs index 65f712f72..566796bf8 100644 --- a/tests/ImageSharp.Tests/TestFile.cs +++ b/tests/ImageSharp.Tests/TestFile.cs @@ -42,10 +42,10 @@ namespace ImageSharp.Tests { // Register the individual image formats. // TODO: Is this the best place to do this? - Bootstrapper.Default.AddImageFormat(new PngFormat()); - Bootstrapper.Default.AddImageFormat(new JpegFormat()); - Bootstrapper.Default.AddImageFormat(new BmpFormat()); - Bootstrapper.Default.AddImageFormat(new GifFormat()); + Configuration.Default.AddImageFormat(new PngFormat()); + Configuration.Default.AddImageFormat(new JpegFormat()); + Configuration.Default.AddImageFormat(new BmpFormat()); + Configuration.Default.AddImageFormat(new GifFormat()); } /// diff --git a/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs b/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs index 5fc9f175e..ea3645874 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs @@ -96,7 +96,7 @@ namespace ImageSharp.Tests private static IImageFormat GetImageFormatByExtension(string extension) { extension = extension.ToLower(); - return Bootstrapper.Default.ImageFormats.First(f => f.SupportedExtensions.Contains(extension)); + return Configuration.Default.ImageFormats.First(f => f.SupportedExtensions.Contains(extension)); } private string GetTestOutputDir()