Browse Source

Rename Bootstrapper to Configuration

af/merge-core
James Jackson-South 9 years ago
parent
commit
ef60a6237e
  1. 1
      Settings.StyleCop
  2. 14
      src/ImageSharp/Configuration.cs
  3. 2
      src/ImageSharp/Formats/IImageFormat.cs
  4. 6
      src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs
  5. 24
      src/ImageSharp/Image.cs
  6. 22
      src/ImageSharp/Image/ImageBase{TColor}.cs
  7. 12
      src/ImageSharp/Image/ImageFrame{TColor}.cs
  8. 38
      src/ImageSharp/Image/Image{TColor}.cs
  9. 4
      src/ImageSharp/Image/PixelAccessor{TColor}.cs
  10. 8
      src/ImageSharp/ImageFrame.cs
  11. 2
      src/ImageSharp/ImageProcessor.cs
  12. 2
      src/ImageSharp/Quantizers/Quantize.cs
  13. 2
      tests/ImageSharp.Benchmarks/Image/CopyPixels.cs
  14. 26
      tests/ImageSharp.Tests/ConfigurationTests.cs
  15. 8
      tests/ImageSharp.Tests/TestFile.cs
  16. 2
      tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs

1
Settings.StyleCop

@ -39,7 +39,6 @@
<Value>desensitivity</Value>
<Value>premultiplied</Value>
<Value>endianness</Value>
<Value>bootstrapper</Value>
<Value>thresholding</Value>
</CollectionProperty>
</GlobalSettings>

14
src/ImageSharp/Bootstrapper.cs → src/ImageSharp/Configuration.cs

@ -1,4 +1,4 @@
// <copyright file="Bootstrapper.cs" company="James Jackson-South">
// <copyright file="Configuration.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
@ -16,15 +16,15 @@ namespace ImageSharp
/// <summary>
/// Provides initialization code which allows extending the library.
/// </summary>
public class Bootstrapper
public class Configuration
{
/// <summary>
/// A lazily initialized bootstrapper default instance.
/// A lazily initialized configuration default instance.
/// </summary>
private static readonly Lazy<Bootstrapper> Lazy = new Lazy<Bootstrapper>(() => new Bootstrapper());
private static readonly Lazy<Configuration> Lazy = new Lazy<Configuration>(() => new Configuration());
/// <summary>
/// An object that can be used to synchronize access to the <see cref="Bootstrapper"/>.
/// An object that can be used to synchronize access to the <see cref="Configuration"/>.
/// </summary>
private static readonly object SyncRoot = new object();
@ -34,9 +34,9 @@ namespace ImageSharp
private readonly List<IImageFormat> imageFormatsList = new List<IImageFormat>();
/// <summary>
/// Gets the default <see cref="Bootstrapper"/> instance.
/// Gets the default <see cref="Configuration"/> instance.
/// </summary>
public static Bootstrapper Default { get; } = Lazy.Value;
public static Configuration Default { get; } = Lazy.Value;
/// <summary>
/// Gets the collection of supported <see cref="IImageFormat"/>

2
src/ImageSharp/Formats/IImageFormat.cs

@ -9,7 +9,7 @@ namespace ImageSharp.Formats
/// <summary>
/// Encapsulates a supported image format, providing means to encode and decode an image.
/// Individual formats implements in this interface must be registered in the <see cref="Bootstrapper"/>
/// Individual formats implements in this interface must be registered in the <see cref="Configuration"/>
/// </summary>
public interface IImageFormat
{

6
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

24
src/ImageSharp/Image.cs

@ -21,11 +21,11 @@ namespace ImageSharp
/// </summary>
/// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
/// <param name="bootstrapper">
/// The bootstrapper providing initialization code which allows extending the library.
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
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
/// <param name="stream">
/// The stream containing image information.
/// </param>
/// <param name="bootstrapper">
/// The bootstrapper providing initialization code which allows extending the library.
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="stream"/> is null.</exception>
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
/// <param name="bytes">
/// The byte array containing image information.
/// </param>
/// <param name="bootstrapper">
/// The bootstrapper providing initialization code which allows extending the library.
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="bytes"/> is null.</exception>
public Image(byte[] bytes, Bootstrapper bootstrapper = null)
: base(bytes, bootstrapper)
public Image(byte[] bytes, Configuration configuration = null)
: base(bytes, configuration)
{
}

22
src/ImageSharp/Image/ImageBase{TColor}.cs

@ -25,12 +25,12 @@ namespace ImageSharp
/// <summary>
/// Initializes a new instance of the <see cref="ImageBase{TColor}"/> class.
/// </summary>
/// <param name="bootstrapper">
/// The bootstrapper providing initialization code which allows extending the library.
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
protected ImageBase(Bootstrapper bootstrapper = null)
protected ImageBase(Configuration configuration = null)
{
this.Bootstrapper = bootstrapper ?? Bootstrapper.Default;
this.Configuration = configuration ?? Configuration.Default;
}
/// <summary>
@ -38,15 +38,15 @@ namespace ImageSharp
/// </summary>
/// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
/// <param name="bootstrapper">
/// The bootstrapper providing initialization code which allows extending the library.
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
/// <exception cref="System.ArgumentOutOfRangeException">
/// Thrown if either <paramref name="width"/> or <paramref name="height"/> are less than or equal to 0.
/// </exception>
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; }
/// <summary>
/// Gets the bootstrapper providing initialization code which allows extending the library.
/// Gets the configuration providing initialization code which allows extending the library.
/// </summary>
public Bootstrapper Bootstrapper { get; private set; }
public Configuration Configuration { get; private set; }
/// <inheritdoc/>
public void InitPixels(int width, int height)
@ -170,7 +170,7 @@ namespace ImageSharp
/// </param>
protected void CopyProperties(ImageBase<TColor> other)
{
this.Bootstrapper = other.Bootstrapper;
this.Configuration = other.Configuration;
this.Quality = other.Quality;
this.FrameDelay = other.FrameDelay;
}

12
src/ImageSharp/Image/ImageFrame{TColor}.cs

@ -21,11 +21,11 @@ namespace ImageSharp
/// </summary>
/// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
/// <param name="bootstrapper">
/// The bootstrapper providing initialization code which allows extending the library.
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
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<TColor, TColor2>(scaleFunc);
ImageFrame<TColor2> target = new ImageFrame<TColor2>(this.Width, this.Height, this.Bootstrapper)
ImageFrame<TColor2> target = new ImageFrame<TColor2>(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++)

38
src/ImageSharp/Image/Image{TColor}.cs

@ -43,13 +43,13 @@ namespace ImageSharp
/// </summary>
/// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
/// <param name="bootstrapper">
/// The bootstrapper providing initialization code which allows extending the library.
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
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();
}
/// <summary>
@ -58,12 +58,12 @@ namespace ImageSharp
/// <param name="stream">
/// The stream containing image information.
/// </param>
/// <param name="bootstrapper">
/// The bootstrapper providing initialization code which allows extending the library.
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="stream"/> is null.</exception>
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
/// <param name="bytes">
/// The byte array containing image information.
/// </param>
/// <param name="bootstrapper">
/// The bootstrapper providing initialization code which allows extending the library.
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="bytes"/> is null.</exception>
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<TColor, TColor2>(scaleFunc);
Image<TColor2> target = new Image<TColor2>(this.Width, this.Height, this.Bootstrapper)
Image<TColor2> target = new Image<TColor2>(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
/// </exception>
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
/// </returns>
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
{

4
src/ImageSharp/Image/PixelAccessor{TColor}.cs

@ -61,7 +61,7 @@ namespace ImageSharp
this.pixelsBase = (byte*)this.dataPointer.ToPointer();
this.PixelSize = Unsafe.SizeOf<TColor>();
this.RowStride = this.Width * this.PixelSize;
this.ParallelOptions = image.Bootstrapper.ParallelOptions;
this.ParallelOptions = image.Configuration.ParallelOptions;
}
/// <summary>
@ -88,7 +88,7 @@ namespace ImageSharp
this.pixelsBase = (byte*)this.dataPointer.ToPointer();
this.PixelSize = Unsafe.SizeOf<TColor>();
this.RowStride = this.Width * this.PixelSize;
this.ParallelOptions = Bootstrapper.Default.ParallelOptions;
this.ParallelOptions = Configuration.Default.ParallelOptions;
}
/// <summary>

8
src/ImageSharp/ImageFrame.cs

@ -18,11 +18,11 @@ namespace ImageSharp
/// </summary>
/// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
/// <param name="bootstrapper">
/// The bootstrapper providing initialization code which allows extending the library.
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
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)
{
}

2
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

2
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])];

2
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++)

26
tests/ImageSharp.Tests/BootstrapperTests.cs → tests/ImageSharp.Tests/ConfigurationTests.cs

@ -1,4 +1,4 @@
// <copyright file="BootstrapperTests.cs" company="James Jackson-South">
// <copyright file="ConfigurationTests.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
@ -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<ArgumentNullException>(() =>
{
Bootstrapper.Default.AddImageFormat(null);
Configuration.Default.AddImageFormat(null);
});
var format = new TestFormat();
@ -60,7 +60,7 @@ namespace ImageSharp.Tests
exception = Assert.Throws<ArgumentNullException>(() =>
{
Bootstrapper.Default.AddImageFormat(format);
Configuration.Default.AddImageFormat(format);
});
Assert.Contains("decoder", exception.Message);
@ -69,7 +69,7 @@ namespace ImageSharp.Tests
exception = Assert.Throws<ArgumentNullException>(() =>
{
Bootstrapper.Default.AddImageFormat(format);
Configuration.Default.AddImageFormat(format);
});
Assert.Contains("encoder", exception.Message);
@ -78,7 +78,7 @@ namespace ImageSharp.Tests
exception = Assert.Throws<ArgumentNullException>(() =>
{
Bootstrapper.Default.AddImageFormat(format);
Configuration.Default.AddImageFormat(format);
});
Assert.Contains("mime type", exception.Message);
@ -87,7 +87,7 @@ namespace ImageSharp.Tests
exception = Assert.Throws<ArgumentException>(() =>
{
Bootstrapper.Default.AddImageFormat(format);
Configuration.Default.AddImageFormat(format);
});
Assert.Contains("mime type", exception.Message);
@ -96,7 +96,7 @@ namespace ImageSharp.Tests
exception = Assert.Throws<ArgumentNullException>(() =>
{
Bootstrapper.Default.AddImageFormat(format);
Configuration.Default.AddImageFormat(format);
});
Assert.Contains("extension", exception.Message);
@ -105,7 +105,7 @@ namespace ImageSharp.Tests
exception = Assert.Throws<ArgumentException>(() =>
{
Bootstrapper.Default.AddImageFormat(format);
Configuration.Default.AddImageFormat(format);
});
Assert.Contains("extension", exception.Message);
@ -114,7 +114,7 @@ namespace ImageSharp.Tests
exception = Assert.Throws<ArgumentNullException>(() =>
{
Bootstrapper.Default.AddImageFormat(format);
Configuration.Default.AddImageFormat(format);
});
Assert.Contains("supported extensions", exception.Message);
@ -123,7 +123,7 @@ namespace ImageSharp.Tests
exception = Assert.Throws<ArgumentException>(() =>
{
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<ArgumentException>(() =>
{
Bootstrapper.Default.AddImageFormat(format);
Configuration.Default.AddImageFormat(format);
});
Assert.Contains("should contain", exception.Message);
format.SupportedExtensions = new string[] { "test", "" };
exception = Assert.Throws<ArgumentException>(() =>
{
Bootstrapper.Default.AddImageFormat(format);
Configuration.Default.AddImageFormat(format);
});
Assert.Contains("empty values", exception.Message);
}

8
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());
}
/// <summary>

2
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()

Loading…
Cancel
Save