Browse Source

Add ability to set custom Bootstrapper.

This allows the setting of custom formats and parallel processing rules.
af/merge-core
James Jackson-South 9 years ago
parent
commit
3718edb6e0
  1. 1
      ImageSharp.sln
  2. 2
      Settings.StyleCop
  3. 80
      src/ImageSharp/Bootstrapper.cs
  4. 1
      src/ImageSharp/Formats/IImageFormat.cs
  5. 6
      src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs
  6. 27
      src/ImageSharp/Image.cs
  7. 20
      src/ImageSharp/Image/ImageBase{TColor}.cs
  8. 10
      src/ImageSharp/Image/ImageFrame{TColor}.cs
  9. 5
      src/ImageSharp/Image/ImageProcessingExtensions.cs
  10. 46
      src/ImageSharp/Image/Image{TColor}.cs
  11. 2
      src/ImageSharp/ImageProcessor.cs
  12. 6
      src/ImageSharp/Quantizers/QuantizedImage.cs
  13. 2
      src/ImageSharp/Quantizers/Wu/WuQuantizer.cs
  14. 2
      tests/ImageSharp.Benchmarks/Image/CopyPixels.cs
  15. 28
      tests/ImageSharp.Tests/BootstrapperTests.cs
  16. 24
      tests/ImageSharp.Tests/TestBase.cs
  17. 2
      tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs

1
ImageSharp.sln

@ -21,6 +21,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionIt
features.md = features.md
global.json = global.json
ImageSharp.ruleset = ImageSharp.ruleset
ImageSharp.sln.DotSettings = ImageSharp.sln.DotSettings
NuGet.config = NuGet.config
build\package.json = build\package.json
README.md = README.md

2
Settings.StyleCop

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

80
src/ImageSharp/Bootstrapper.cs

@ -16,12 +16,12 @@ namespace ImageSharp
/// <summary>
/// Provides initialization code which allows extending the library.
/// </summary>
public static class Bootstrapper
public class Bootstrapper
{
/// <summary>
/// The list of supported <see cref="IImageFormat"/>.
/// A lazily initialized bootstrapper default instance.
/// </summary>
private static readonly List<IImageFormat> ImageFormatsList;
private static readonly Lazy<Bootstrapper> Lazy = new Lazy<Bootstrapper>(() => new Bootstrapper());
/// <summary>
/// An object that can be used to synchronize access to the <see cref="Bootstrapper"/>.
@ -29,41 +29,35 @@ namespace ImageSharp
private static readonly object SyncRoot = new object();
/// <summary>
/// Initializes static members of the <see cref="Bootstrapper"/> class.
/// The list of supported <see cref="IImageFormat"/>.
/// </summary>
static Bootstrapper()
{
ImageFormatsList = new List<IImageFormat>
{
new BmpFormat(),
new JpegFormat(),
new PngFormat(),
new GifFormat()
};
SetMaxHeaderSize();
ParallelOptions = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount };
}
private readonly List<IImageFormat> imageFormatsList = new List<IImageFormat>();
/// <summary>
/// Gets the default <see cref="Bootstrapper"/> instance.
/// </summary>
public static Bootstrapper Default { get; } = Lazy.Value;
/// <summary>
/// Gets the collection of supported <see cref="IImageFormat"/>
/// </summary>
public static IReadOnlyCollection<IImageFormat> ImageFormats => new ReadOnlyCollection<IImageFormat>(ImageFormatsList);
public IReadOnlyCollection<IImageFormat> ImageFormats => new ReadOnlyCollection<IImageFormat>(this.imageFormatsList);
/// <summary>
/// Gets the global parallel options for processing tasks in parallel.
/// </summary>
public static ParallelOptions ParallelOptions { get; }
public ParallelOptions ParallelOptions { get; } = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount };
/// <summary>
/// Gets the maximum header size of all formats.
/// </summary>
internal static int MaxHeaderSize { get; private set; }
internal int MaxHeaderSize { get; private set; }
/// <summary>
/// Adds a new <see cref="IImageFormat"/> to the collection of supported image formats.
/// </summary>
/// <param name="format">The new format to add.</param>
public static void AddImageFormat(IImageFormat format)
public void AddImageFormat(IImageFormat format)
{
Guard.NotNull(format, nameof(format));
Guard.NotNull(format.Encoder, nameof(format), "The encoder should not be null.");
@ -72,50 +66,72 @@ namespace ImageSharp
Guard.NotNullOrEmpty(format.Extension, nameof(format), "The extension should not be null or empty.");
Guard.NotNullOrEmpty(format.SupportedExtensions, nameof(format), "The supported extensions not be null or empty.");
AddImageFormatLocked(format);
this.AddImageFormatLocked(format);
}
private static void AddImageFormatLocked(IImageFormat format)
/// <summary>
/// Adds image format. The class is locked to make it thread safe.
/// </summary>
/// <param name="format">The image format.</param>
private void AddImageFormatLocked(IImageFormat format)
{
lock (SyncRoot)
{
GuardDuplicate(format);
ImageFormatsList.Add(format);
if (this.GuardDuplicate(format))
{
this.imageFormatsList.Add(format);
SetMaxHeaderSize();
this.SetMaxHeaderSize();
}
}
}
private static void GuardDuplicate(IImageFormat format)
/// <summary>
/// Checks to ensure duplicate image formats are not added.
/// </summary>
/// <param name="format">The image format.</param>
/// <exception cref="ArgumentException">Thrown if a duplicate is added.</exception>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
private bool GuardDuplicate(IImageFormat format)
{
if (!format.SupportedExtensions.Contains(format.Extension, StringComparer.OrdinalIgnoreCase))
{
throw new ArgumentException("The supported extensions should contain the default extension.", nameof(format));
}
// ReSharper disable once ConvertClosureToMethodGroup
// Prevents method group allocation
if (format.SupportedExtensions.Any(e => string.IsNullOrWhiteSpace(e)))
{
throw new ArgumentException("The supported extensions should not contain empty values.", nameof(format));
}
foreach (var imageFormat in ImageFormatsList)
// If there is already a format with the same extension or a format that supports that
// extension return false.
foreach (IImageFormat imageFormat in this.imageFormatsList)
{
if (imageFormat.Extension.Equals(format.Extension, StringComparison.OrdinalIgnoreCase))
{
throw new ArgumentException("There is already a format with the same extension.", nameof(format));
return false;
}
if (imageFormat.SupportedExtensions.Intersect(format.SupportedExtensions, StringComparer.OrdinalIgnoreCase).Any())
{
throw new ArgumentException("There is already a format that supports the same extension.", nameof(format));
return false;
}
}
return true;
}
private static void SetMaxHeaderSize()
/// <summary>
/// Sets max header size.
/// </summary>
private void SetMaxHeaderSize()
{
MaxHeaderSize = ImageFormatsList.Max(x => x.HeaderSize);
this.MaxHeaderSize = this.imageFormatsList.Max(x => x.HeaderSize);
}
}
}

1
src/ImageSharp/Formats/IImageFormat.cs

@ -9,6 +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"/>
/// </summary>
public interface IImageFormat
{

6
src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs

@ -687,7 +687,7 @@ namespace ImageSharp.Formats
Parallel.For(
0,
height,
Bootstrapper.ParallelOptions,
image.Bootstrapper.ParallelOptions,
y =>
{
int yoff = this.grayImage.GetRowOffset(y);
@ -723,7 +723,7 @@ namespace ImageSharp.Formats
Parallel.For(
0,
height,
Bootstrapper.ParallelOptions,
image.Bootstrapper.ParallelOptions,
y =>
{
// TODO: Simplify + optimize + share duplicate code across converter methods
@ -764,7 +764,7 @@ namespace ImageSharp.Formats
Parallel.For(
0,
height,
Bootstrapper.ParallelOptions,
image.Bootstrapper.ParallelOptions,
y =>
{
// TODO: Simplify + optimize + share duplicate code across converter methods

27
src/ImageSharp/Image.cs

@ -18,7 +18,11 @@ namespace ImageSharp
/// <summary>
/// Initializes a new instance of the <see cref="Image"/> class.
/// </summary>
public Image()
/// <param name="bootstrapper">
/// The bootstrapper providing initialization code which allows extending the library.
/// </param>
public Image(Bootstrapper bootstrapper = null)
: base(bootstrapper)
{
}
@ -28,8 +32,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>
public Image(int width, int height)
: base(width, height)
/// <param name="bootstrapper">
/// The bootstrapper providing initialization code which allows extending the library.
/// </param>
public Image(int width, int height, Bootstrapper bootstrapper = null)
: base(width, height, bootstrapper)
{
}
@ -39,9 +46,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>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="stream"/> is null.</exception>
public Image(Stream stream)
: base(stream)
public Image(Stream stream, Bootstrapper bootstrapper = null)
: base(stream, bootstrapper)
{
}
@ -51,9 +61,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>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="bytes"/> is null.</exception>
public Image(byte[] bytes)
: base(bytes)
public Image(byte[] bytes, Bootstrapper bootstrapper = null)
: base(bytes, bootstrapper)
{
}

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

@ -25,8 +25,12 @@ namespace ImageSharp
/// <summary>
/// Initializes a new instance of the <see cref="ImageBase{TColor}"/> class.
/// </summary>
protected ImageBase()
/// <param name="bootstrapper">
/// The bootstrapper providing initialization code which allows extending the library.
/// </param>
protected ImageBase(Bootstrapper bootstrapper = null)
{
this.Bootstrapper = bootstrapper ?? Bootstrapper.Default;
}
/// <summary>
@ -34,11 +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>
/// <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)
protected ImageBase(int width, int height, Bootstrapper bootstrapper = null)
{
this.Bootstrapper = bootstrapper ?? Bootstrapper.Default;
this.InitPixels(width, height);
}
@ -95,6 +103,11 @@ namespace ImageSharp
/// <inheritdoc/>
public int FrameDelay { get; set; }
/// <summary>
/// Gets the bootstrapper providing initialization code which allows extending the library.
/// </summary>
public Bootstrapper Bootstrapper { get; private set; }
/// <inheritdoc/>
public void InitPixels(int width, int height)
{
@ -157,8 +170,9 @@ namespace ImageSharp
/// </param>
protected void CopyProperties(ImageBase<TColor> other)
{
this.Bootstrapper = other.Bootstrapper;
this.Quality = other.Quality;
this.FrameDelay = other.FrameDelay;
}
}
}
}

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

@ -19,7 +19,11 @@ namespace ImageSharp
/// <summary>
/// Initializes a new instance of the <see cref="ImageFrame{TColor}"/> class.
/// </summary>
public ImageFrame()
/// <param name="bootstrapper">
/// The bootstrapper providing initialization code which allows extending the library.
/// </param>
public ImageFrame(Bootstrapper bootstrapper = null)
: base(bootstrapper)
{
}
@ -49,7 +53,7 @@ namespace ImageSharp
{
scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction<TColor, TColor2>(scaleFunc);
ImageFrame<TColor2> target = new ImageFrame<TColor2>
ImageFrame<TColor2> target = new ImageFrame<TColor2>(this.Bootstrapper)
{
Quality = this.Quality,
FrameDelay = this.FrameDelay
@ -63,7 +67,7 @@ namespace ImageSharp
Parallel.For(
0,
target.Height,
Bootstrapper.ParallelOptions,
this.Bootstrapper.ParallelOptions,
y =>
{
for (int x = 0; x < target.Width; x++)

5
src/ImageSharp/Image/ImageProcessingExtensions.cs

@ -41,6 +41,11 @@ namespace ImageSharp
internal static Image<TColor> Process<TColor>(this Image<TColor> source, Rectangle sourceRectangle, IImageFilteringProcessor<TColor> processor)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
if (processor.ParallelOptions == null)
{
processor.ParallelOptions = source.Bootstrapper.ParallelOptions;
}
return PerformAction(source, (sourceImage) => processor.Apply(sourceImage, sourceRectangle));
}

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

@ -40,9 +40,14 @@ namespace ImageSharp
/// <summary>
/// Initializes a new instance of the <see cref="Image{TColor}"/> class.
/// </summary>
public Image()
/// <param name="bootstrapper">
/// The bootstrapper providing initialization code which allows extending the library.
/// </param>
public Image(Bootstrapper bootstrapper = null)
: base(bootstrapper)
{
this.CurrentImageFormat = Bootstrapper.ImageFormats.First(f => f.GetType() == typeof(PngFormat));
// We want to throw here.
this.CurrentImageFormat = this.Bootstrapper.ImageFormats.First();
}
/// <summary>
@ -51,10 +56,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>
public Image(int width, int height)
: base(width, height)
/// <param name="bootstrapper">
/// The bootstrapper providing initialization code which allows extending the library.
/// </param>
public Image(int width, int height, Bootstrapper bootstrapper = null)
: base(width, height, bootstrapper)
{
this.CurrentImageFormat = Bootstrapper.ImageFormats.First(f => f.GetType() == typeof(PngFormat));
this.CurrentImageFormat = this.Bootstrapper.ImageFormats.First();
}
/// <summary>
@ -63,8 +71,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>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="stream"/> is null.</exception>
public Image(Stream stream)
public Image(Stream stream, Bootstrapper bootstrapper = null)
: base(bootstrapper)
{
Guard.NotNull(stream, nameof(stream));
this.Load(stream);
@ -76,8 +88,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>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="bytes"/> is null.</exception>
public Image(byte[] bytes)
public Image(byte[] bytes, Bootstrapper bootstrapper = null)
: base(bootstrapper)
{
Guard.NotNull(bytes, nameof(bytes));
@ -293,7 +309,7 @@ namespace ImageSharp
{
scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction<TColor, TColor2>(scaleFunc);
Image<TColor2> target = new Image<TColor2>(this.Width, this.Height)
Image<TColor2> target = new Image<TColor2>(this.Width, this.Height, this.Bootstrapper)
{
Quality = this.Quality,
FrameDelay = this.FrameDelay,
@ -309,7 +325,7 @@ namespace ImageSharp
Parallel.For(
0,
target.Height,
Bootstrapper.ParallelOptions,
this.Bootstrapper.ParallelOptions,
y =>
{
for (int x = 0; x < target.Width; x++)
@ -373,7 +389,7 @@ namespace ImageSharp
/// </exception>
private void Load(Stream stream)
{
if (!Bootstrapper.ImageFormats.Any())
if (!this.Bootstrapper.ImageFormats.Any())
{
return;
}
@ -408,7 +424,7 @@ namespace ImageSharp
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("Image cannot be loaded. Available formats:");
foreach (IImageFormat format in Bootstrapper.ImageFormats)
foreach (IImageFormat format in this.Bootstrapper.ImageFormats)
{
stringBuilder.AppendLine("-" + format);
}
@ -425,20 +441,20 @@ namespace ImageSharp
/// </returns>
private bool Decode(Stream stream)
{
int maxHeaderSize = Bootstrapper.MaxHeaderSize;
int maxHeaderSize = this.Bootstrapper.MaxHeaderSize;
if (maxHeaderSize <= 0)
{
return false;
}
IImageFormat format = null;
IImageFormat format;
byte[] header = ArrayPool<byte>.Shared.Rent(maxHeaderSize);
try
{
long startPosition = stream.Position;
stream.Read(header, 0, maxHeaderSize);
stream.Position = startPosition;
format = Bootstrapper.ImageFormats.FirstOrDefault(x => x.IsSupportedFileFormat(header));
format = this.Bootstrapper.ImageFormats.FirstOrDefault(x => x.IsSupportedFileFormat(header));
}
finally
{
@ -455,4 +471,4 @@ namespace ImageSharp
return true;
}
}
}
}

2
src/ImageSharp/ImageProcessor.cs

@ -16,7 +16,7 @@ namespace ImageSharp.Processors
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <inheritdoc/>
public virtual ParallelOptions ParallelOptions { get; set; } = Bootstrapper.ParallelOptions;
public virtual ParallelOptions ParallelOptions { get; set; }
/// <inheritdoc/>
public virtual bool Compand { get; set; } = false;

6
src/ImageSharp/Quantizers/QuantizedImage.cs

@ -71,16 +71,16 @@ namespace ImageSharp.Quantizers
Image<TColor> image = new Image<TColor>();
int pixelCount = this.Pixels.Length;
int palletCount = this.Palette.Length - 1;
int palleteCount = this.Palette.Length - 1;
TColor[] pixels = new TColor[pixelCount];
Parallel.For(
0,
pixelCount,
Bootstrapper.ParallelOptions,
image.Bootstrapper.ParallelOptions,
i =>
{
TColor color = this.Palette[Math.Min(palletCount, this.Pixels[i])];
TColor color = this.Palette[Math.Min(palleteCount, this.Pixels[i])];
pixels[i] = color;
});

2
src/ImageSharp/Quantizers/Wu/WuQuantizer.cs

@ -773,7 +773,7 @@ namespace ImageSharp.Quantizers
Parallel.For(
0,
height,
Bootstrapper.ParallelOptions,
Bootstrapper.Default.ParallelOptions,
y =>
{
byte[] rgba = ArrayPool<byte>.Shared.Rent(4);

2
tests/ImageSharp.Benchmarks/Image/CopyPixels.cs

@ -25,7 +25,7 @@ namespace ImageSharp.Benchmarks.Image
Parallel.For(
0,
source.Height,
Bootstrapper.ParallelOptions,
Bootstrapper.Default.ParallelOptions,
y =>
{
for (int x = 0; x < source.Width; x++)

28
tests/ImageSharp.Tests/BootstrapperTests.cs

@ -52,7 +52,7 @@ namespace ImageSharp.Tests
exception = Assert.Throws<ArgumentNullException>(() =>
{
Bootstrapper.AddImageFormat(null);
Bootstrapper.Default.AddImageFormat(null);
});
var format = new TestFormat();
@ -60,7 +60,7 @@ namespace ImageSharp.Tests
exception = Assert.Throws<ArgumentNullException>(() =>
{
Bootstrapper.AddImageFormat(format);
Bootstrapper.Default.AddImageFormat(format);
});
Assert.Contains("decoder", exception.Message);
@ -69,7 +69,7 @@ namespace ImageSharp.Tests
exception = Assert.Throws<ArgumentNullException>(() =>
{
Bootstrapper.AddImageFormat(format);
Bootstrapper.Default.AddImageFormat(format);
});
Assert.Contains("encoder", exception.Message);
@ -78,7 +78,7 @@ namespace ImageSharp.Tests
exception = Assert.Throws<ArgumentNullException>(() =>
{
Bootstrapper.AddImageFormat(format);
Bootstrapper.Default.AddImageFormat(format);
});
Assert.Contains("mime type", exception.Message);
@ -87,7 +87,7 @@ namespace ImageSharp.Tests
exception = Assert.Throws<ArgumentException>(() =>
{
Bootstrapper.AddImageFormat(format);
Bootstrapper.Default.AddImageFormat(format);
});
Assert.Contains("mime type", exception.Message);
@ -96,7 +96,7 @@ namespace ImageSharp.Tests
exception = Assert.Throws<ArgumentNullException>(() =>
{
Bootstrapper.AddImageFormat(format);
Bootstrapper.Default.AddImageFormat(format);
});
Assert.Contains("extension", exception.Message);
@ -105,7 +105,7 @@ namespace ImageSharp.Tests
exception = Assert.Throws<ArgumentException>(() =>
{
Bootstrapper.AddImageFormat(format);
Bootstrapper.Default.AddImageFormat(format);
});
Assert.Contains("extension", exception.Message);
@ -114,7 +114,7 @@ namespace ImageSharp.Tests
exception = Assert.Throws<ArgumentNullException>(() =>
{
Bootstrapper.AddImageFormat(format);
Bootstrapper.Default.AddImageFormat(format);
});
Assert.Contains("supported extensions", exception.Message);
@ -123,7 +123,7 @@ namespace ImageSharp.Tests
exception = Assert.Throws<ArgumentException>(() =>
{
Bootstrapper.AddImageFormat(format);
Bootstrapper.Default.AddImageFormat(format);
});
Assert.Contains("supported extensions", exception.Message);
}
@ -131,32 +131,32 @@ namespace ImageSharp.Tests
[Fact]
public void AddImageFormatChecks()
{
var format = new TestFormat();
TestFormat format = new TestFormat();
var exception = Assert.Throws<ArgumentException>(() =>
{
Bootstrapper.AddImageFormat(format);
Bootstrapper.Default.AddImageFormat(format);
});
Assert.Contains("format with the same", exception.Message);
format.Extension = "test";
exception = Assert.Throws<ArgumentException>(() =>
{
Bootstrapper.AddImageFormat(format);
Bootstrapper.Default.AddImageFormat(format);
});
Assert.Contains("should contain", exception.Message);
format.SupportedExtensions = new string[] { "test", "jpg" };
exception = Assert.Throws<ArgumentException>(() =>
{
Bootstrapper.AddImageFormat(format);
Bootstrapper.Default.AddImageFormat(format);
});
Assert.Contains("supports the same", exception.Message);
format.SupportedExtensions = new string[] { "test", "" };
exception = Assert.Throws<ArgumentException>(() =>
{
Bootstrapper.AddImageFormat(format);
Bootstrapper.Default.AddImageFormat(format);
});
Assert.Contains("empty values", exception.Message);
}

24
tests/ImageSharp.Tests/TestBase.cs

@ -7,11 +7,33 @@ namespace ImageSharp.Tests
{
using System.IO;
using ImageSharp.Formats;
/// <summary>
/// The test base class.
/// The test base class. Inherit from this class for any image manipulation tests.
/// </summary>
public abstract class TestBase
{
/// <summary>
/// Initializes a new instance of the <see cref="TestBase"/> class.
/// </summary>
protected TestBase()
{
// Register the individual image formats.
Bootstrapper.Default.AddImageFormat(new PngFormat());
Bootstrapper.Default.AddImageFormat(new JpegFormat());
Bootstrapper.Default.AddImageFormat(new BmpFormat());
Bootstrapper.Default.AddImageFormat(new GifFormat());
}
/// <summary>
/// Creates the image output directory.
/// </summary>
/// <param name="path">The path.</param>
/// <param name="pathParts">The path parts.</param>
/// <returns>
/// The <see cref="string"/>.
/// </returns>
protected string CreateOutputDirectory(string path, params string[] pathParts)
{
path = Path.Combine("TestOutput", path);

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.ImageFormats.First(f => f.SupportedExtensions.Contains(extension));
return Bootstrapper.Default.ImageFormats.First(f => f.SupportedExtensions.Contains(extension));
}
private string GetTestOutputDir()

Loading…
Cancel
Save