diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoder.cs b/src/ImageSharp/Formats/Bmp/BmpDecoder.cs
index 2bc1c8cc3..8414807e0 100644
--- a/src/ImageSharp/Formats/Bmp/BmpDecoder.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpDecoder.cs
@@ -26,12 +26,13 @@ namespace ImageSharp.Formats
public class BmpDecoder : IImageDecoder
{
///
- public Image Decode(Stream stream, IDecoderOptions options)
+ public Image Decode(Stream stream, IDecoderOptions options, Configuration configuration)
+
where TColor : struct, IPixel
{
Guard.NotNull(stream, "stream");
- return new BmpDecoderCore().Decode(stream);
+ return new BmpDecoderCore(configuration).Decode(stream);
}
}
}
diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
index adfa4b6ac..18e4e858b 100644
--- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
@@ -43,6 +43,17 @@ namespace ImageSharp.Formats
///
private BmpInfoHeader infoHeader;
+ private Configuration configuration;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The configuration.
+ public BmpDecoderCore(Configuration configuration)
+ {
+ this.configuration = configuration;
+ }
+
///
/// Decodes the image from the specified this._stream and sets
/// the data to image.
@@ -114,8 +125,7 @@ namespace ImageSharp.Formats
+ $"bigger then the max allowed size '{Image.MaxWidth}x{Image.MaxHeight}'");
}
- Image image = new Image(this.infoHeader.Width, this.infoHeader.Height);
-
+ Image image = Image.Create(this.infoHeader.Width, this.infoHeader.Height, this.configuration);
using (PixelAccessor pixels = image.Lock())
{
switch (this.infoHeader.Compression)
diff --git a/src/ImageSharp/Formats/Gif/GifDecoder.cs b/src/ImageSharp/Formats/Gif/GifDecoder.cs
index 16b036e68..2e56b0bab 100644
--- a/src/ImageSharp/Formats/Gif/GifDecoder.cs
+++ b/src/ImageSharp/Formats/Gif/GifDecoder.cs
@@ -14,12 +14,13 @@ namespace ImageSharp.Formats
public class GifDecoder : IImageDecoder
{
///
- public Image Decode(Stream stream, IDecoderOptions options)
+ public Image Decode(Stream stream, IDecoderOptions options, Configuration configuration)
+
where TColor : struct, IPixel
{
IGifDecoderOptions gifOptions = GifDecoderOptions.Create(options);
- return this.Decode(stream, gifOptions);
+ return this.Decode(stream, gifOptions, configuration);
}
///
@@ -28,11 +29,12 @@ namespace ImageSharp.Formats
/// The pixel format.
/// The containing image data.
/// The options for the decoder.
+ /// The configuration.
/// The image thats been decoded.
- public Image Decode(Stream stream, IGifDecoderOptions options)
+ public Image Decode(Stream stream, IGifDecoderOptions options, Configuration configuration)
where TColor : struct, IPixel
{
- return new GifDecoderCore(options).Decode(stream);
+ return new GifDecoderCore(options, configuration).Decode(stream);
}
}
}
diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs
index 22a26345f..79348a7ab 100644
--- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs
+++ b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs
@@ -27,6 +27,11 @@ namespace ImageSharp.Formats
///
private readonly IGifDecoderOptions options;
+ ///
+ /// The global configuration.
+ ///
+ private readonly Configuration configuration;
+
///
/// The currently loaded stream.
///
@@ -76,9 +81,11 @@ namespace ImageSharp.Formats
/// Initializes a new instance of the class.
///
/// The decoder options.
- public GifDecoderCore(IGifDecoderOptions options)
+ /// The configuration.
+ public GifDecoderCore(IGifDecoderOptions options, Configuration configuration)
{
this.options = options ?? new GifDecoderOptions();
+ this.configuration = configuration ?? Configuration.Default;
}
///
@@ -355,7 +362,7 @@ namespace ImageSharp.Formats
this.metaData.Quality = colorTableLength / 3;
// This initializes the image to become fully transparent because the alpha channel is zero.
- this.image = new Image(imageWidth, imageHeight);
+ this.image = Image.Create(imageWidth, imageHeight, this.configuration);
this.image.MetaData.LoadFrom(this.metaData);
this.SetFrameDelay(this.metaData);
diff --git a/src/ImageSharp/Formats/IImageDecoder.cs b/src/ImageSharp/Formats/IImageDecoder.cs
index c4a9cf8c3..8da23d499 100644
--- a/src/ImageSharp/Formats/IImageDecoder.cs
+++ b/src/ImageSharp/Formats/IImageDecoder.cs
@@ -19,8 +19,9 @@ namespace ImageSharp.Formats
/// The pixel format.
/// The containing image data.
/// The options for the decoder.
+ /// The configuration for the image.
/// The decoded image
- Image Decode(Stream stream, IDecoderOptions options)
+ Image Decode(Stream stream, IDecoderOptions options, Configuration configuration)
where TColor : struct, IPixel;
}
}
diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
index 3a91f8010..254506af0 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
@@ -14,12 +14,12 @@ namespace ImageSharp.Formats
public class JpegDecoder : IImageDecoder
{
///
- public Image Decode(Stream stream, IDecoderOptions options)
+ public Image Decode(Stream stream, IDecoderOptions options, Configuration configuration)
where TColor : struct, IPixel
{
Guard.NotNull(stream, "stream");
- using (JpegDecoderCore decoder = new JpegDecoderCore(options))
+ using (JpegDecoderCore decoder = new JpegDecoderCore(options, configuration))
{
return decoder.Decode(stream);
}
diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
index 3f946fb79..fc9506b54 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
@@ -42,6 +42,11 @@ namespace ImageSharp.Formats
///
private readonly IDecoderOptions options;
+ ///
+ /// The global configuration
+ ///
+ private readonly Configuration configuration;
+
///
/// The App14 marker color-space
///
@@ -91,8 +96,10 @@ namespace ImageSharp.Formats
/// Initializes a new instance of the class.
///
/// The decoder options.
- public JpegDecoderCore(IDecoderOptions options)
+ /// The configuration.
+ public JpegDecoderCore(IDecoderOptions options, Configuration configuration)
{
+ this.configuration = configuration ?? Configuration.Default;
this.options = options ?? new DecoderOptions();
this.HuffmanTrees = HuffmanTree.CreateHuffmanTrees();
this.QuantizationTables = new Block8x8F[MaxTq + 1];
@@ -498,7 +505,8 @@ namespace ImageSharp.Formats
private Image ConvertJpegPixelsToImagePixels(ImageMetaData metadata)
where TColor : struct, IPixel
{
- Image image = new Image(this.ImageWidth, this.ImageHeight);
+ Image image = Image.Create(this.ImageWidth, this.ImageHeight, this.configuration);
+
image.MetaData.LoadFrom(metadata);
if (this.grayImage.IsInitialized)
diff --git a/src/ImageSharp/Formats/Png/PngDecoder.cs b/src/ImageSharp/Formats/Png/PngDecoder.cs
index 5b7d97fc7..bf17ad142 100644
--- a/src/ImageSharp/Formats/Png/PngDecoder.cs
+++ b/src/ImageSharp/Formats/Png/PngDecoder.cs
@@ -31,12 +31,13 @@ namespace ImageSharp.Formats
public class PngDecoder : IImageDecoder
{
///
- public Image Decode(Stream stream, IDecoderOptions options)
+ public Image Decode(Stream stream, IDecoderOptions options, Configuration configuration)
+
where TColor : struct, IPixel
{
IPngDecoderOptions pngOptions = PngDecoderOptions.Create(options);
- return this.Decode(stream, pngOptions);
+ return this.Decode(stream, pngOptions, configuration);
}
///
@@ -45,11 +46,12 @@ namespace ImageSharp.Formats
/// The pixel format.
/// The containing image data.
/// The options for the decoder.
+ /// The configuration for the image.
/// The decoded image.
- public Image Decode(Stream stream, IPngDecoderOptions options)
+ public Image Decode(Stream stream, IPngDecoderOptions options, Configuration configuration)
where TColor : struct, IPixel
{
- return new PngDecoderCore(options).Decode(stream);
+ return new PngDecoderCore(options, configuration).Decode(stream);
}
}
}
diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs
index dadf7ab7d..7705e9549 100644
--- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs
+++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs
@@ -74,6 +74,11 @@ namespace ImageSharp.Formats
///
private readonly Crc32 crc = new Crc32();
+ ///
+ /// The global configuration.
+ ///
+ private readonly Configuration configuration;
+
///
/// The stream to decode from.
///
@@ -134,8 +139,10 @@ namespace ImageSharp.Formats
/// Initializes a new instance of the class.
///
/// The decoder options.
- public PngDecoderCore(IPngDecoderOptions options)
+ /// The configuration.
+ public PngDecoderCore(IPngDecoderOptions options, Configuration configuration)
{
+ this.configuration = configuration ?? Configuration.Default;
this.options = options ?? new PngDecoderOptions();
}
@@ -213,7 +220,7 @@ namespace ImageSharp.Formats
throw new ArgumentOutOfRangeException($"The input png '{this.header.Width}x{this.header.Height}' is bigger than the max allowed size '{Image.MaxWidth}x{Image.MaxHeight}'");
}
- Image image = new Image(this.header.Width, this.header.Height);
+ Image image = Image.Create(this.header.Width, this.header.Height, this.configuration);
image.MetaData.LoadFrom(metadata);
using (PixelAccessor pixels = image.Lock())
diff --git a/src/ImageSharp/Image.Create.cs b/src/ImageSharp/Image.Create.cs
new file mode 100644
index 000000000..bc430724a
--- /dev/null
+++ b/src/ImageSharp/Image.Create.cs
@@ -0,0 +1,46 @@
+//
+// Copyright (c) James Jackson-South and contributors.
+// Licensed under the Apache License, Version 2.0.
+//
+
+namespace ImageSharp
+{
+ using System;
+ using System.Diagnostics;
+ using System.IO;
+
+ using Formats;
+
+ ///
+ /// Represents an image. Each pixel is a made up four 8-bit components red, green, blue, and alpha
+ /// packed into a single unsigned integer value.
+ ///
+ public sealed partial class Image
+ {
+ ///
+ /// Create a new instance of the class
+ /// with the height and the width of the image.
+ ///
+ /// The pixel format.
+ /// The width of the image in pixels.
+ /// The height of the image in pixels.
+ ///
+ /// The configuration providing initialization code which allows extending the library.
+ ///
+ ///
+ /// A new unless is in which case it returns
+ ///
+ internal static Image Create(int width, int height, Configuration configuration)
+ where TColor : struct, IPixel
+ {
+ if (typeof(TColor) == typeof(Color))
+ {
+ return new Image(width, height, configuration) as Image;
+ }
+ else
+ {
+ return new Image(width, height, configuration);
+ }
+ }
+ }
+}
diff --git a/src/ImageSharp/Image.Decode.cs b/src/ImageSharp/Image.Decode.cs
index c95b71b1e..32943ead5 100644
--- a/src/ImageSharp/Image.Decode.cs
+++ b/src/ImageSharp/Image.Decode.cs
@@ -19,7 +19,7 @@ namespace ImageSharp
///
public sealed partial class Image
{
- private static IImageFormat DiscoverFormat(Stream stream, IDecoderOptions options, Configuration config)
+ private static IImageFormat DiscoverFormat(Stream stream, Configuration config)
{
int maxHeaderSize = config.MaxHeaderSize;
if (maxHeaderSize <= 0)
@@ -57,13 +57,13 @@ namespace ImageSharp
private static Image Decode(Stream stream, IDecoderOptions options, Configuration config)
where TColor : struct, IPixel
{
- IImageFormat format = DiscoverFormat(stream, options, config);
+ IImageFormat format = DiscoverFormat(stream, config);
if (format == null)
{
return null;
}
- Image img = format.Decoder.Decode(stream, options);
+ Image img = format.Decoder.Decode(stream, options, config);
img.CurrentImageFormat = format;
return img;
}
diff --git a/src/ImageSharp/Image.FromFile.cs b/src/ImageSharp/Image.FromFile.cs
index e9015eaa9..b7fb0eef5 100644
--- a/src/ImageSharp/Image.FromFile.cs
+++ b/src/ImageSharp/Image.FromFile.cs
@@ -102,7 +102,11 @@ namespace ImageSharp
/// The image
public static Image Load(string path, IDecoderOptions options, Configuration config)
{
- return new Image(Load(path, options, config));
+ config = config ?? Configuration.Default;
+ using (Stream s = config.FileSystem.OpenRead(path))
+ {
+ return Load(s, options, config);
+ }
}
///
diff --git a/src/ImageSharp/Image.FromStream.cs b/src/ImageSharp/Image.FromStream.cs
index b40aa62cd..e995c4799 100644
--- a/src/ImageSharp/Image.FromStream.cs
+++ b/src/ImageSharp/Image.FromStream.cs
@@ -181,7 +181,7 @@ namespace ImageSharp
public static Image Load(Stream stream, IImageDecoder decoder, IDecoderOptions options)
where TColor : struct, IPixel
{
- return WithSeekableStream(stream, s => decoder.Decode(s, options));
+ return WithSeekableStream(stream, s => decoder.Decode(s, options, Configuration.Default));
}
///
diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
index 416c88a50..cdd892dce 100644
--- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
+++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
@@ -90,7 +90,7 @@ namespace ImageSharp.Tests
image.Save(ms, new JpegEncoder());
ms.Seek(0, SeekOrigin.Begin);
- using (JpegDecoderCore decoder = new JpegDecoderCore(null))
+ using (JpegDecoderCore decoder = new JpegDecoderCore(null, null))
{
Image mirror = decoder.Decode(ms);
diff --git a/tests/ImageSharp.Tests/Image/ImageLoadTests.cs b/tests/ImageSharp.Tests/Image/ImageLoadTests.cs
index da3d2fb06..52b8f6ee2 100644
--- a/tests/ImageSharp.Tests/Image/ImageLoadTests.cs
+++ b/tests/ImageSharp.Tests/Image/ImageLoadTests.cs
@@ -32,7 +32,7 @@ namespace ImageSharp.Tests
public ImageLoadTests()
{
- this.returnImage = new Image(1, 1);
+ this.returnImage = new Image(1, 1);
this.localDecoder = new Mock();
this.localFormat = new Mock();
@@ -43,8 +43,10 @@ namespace ImageSharp.Tests
this.localFormat.Setup(x => x.HeaderSize).Returns(1);
this.localFormat.Setup(x => x.IsSupportedFileFormat(It.IsAny())).Returns(true);
this.localFormat.Setup(x => x.SupportedExtensions).Returns(new string[] { "png", "jpg" });
- this.localDecoder.Setup(x => x.Decode(It.IsAny(), It.IsAny()))
- .Callback((s, o) => {
+
+ this.localDecoder.Setup(x => x.Decode(It.IsAny(), It.IsAny(), It.IsAny()))
+
+ .Callback((s, o, c) => {
using (var ms = new MemoryStream())
{
s.CopyTo(ms);
@@ -79,7 +81,9 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat);
- TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, null);
+
+ TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, null, Configuration.Default);
+
}
[Fact]
@@ -90,7 +94,9 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img);
Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat);
- TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, null);
+
+ TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, null, Configuration.Default);
+
}
[Fact]
@@ -100,7 +106,9 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat);
- TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, this.decoderOptions);
+
+ TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, this.decoderOptions, Configuration.Default);
+
}
[Fact]
@@ -111,7 +119,9 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img);
Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat);
- TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, this.decoderOptions);
+
+ TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, this.decoderOptions, Configuration.Default);
+
}
[Fact]
@@ -122,7 +132,9 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(this.localFormat.Object, img.CurrentImageFormat);
- this.localDecoder.Verify(x => x.Decode(stream, null));
+
+ this.localDecoder.Verify(x => x.Decode(stream, null, this.LocalConfiguration));
+
}
[Fact]
@@ -134,7 +146,9 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(this.returnImage, img);
Assert.Equal(this.localFormat.Object, img.CurrentImageFormat);
- this.localDecoder.Verify(x => x.Decode(stream, null));
+
+ this.localDecoder.Verify(x => x.Decode(stream, null, this.LocalConfiguration));
+
}
[Fact]
@@ -145,7 +159,9 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(this.localFormat.Object, img.CurrentImageFormat);
- this.localDecoder.Verify(x => x.Decode(stream, this.decoderOptions));
+
+ this.localDecoder.Verify(x => x.Decode(stream, this.decoderOptions, this.LocalConfiguration));
+
}
[Fact]
@@ -157,7 +173,9 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(this.returnImage, img);
Assert.Equal(this.localFormat.Object, img.CurrentImageFormat);
- this.localDecoder.Verify(x => x.Decode(stream, this.decoderOptions));
+
+ this.localDecoder.Verify(x => x.Decode(stream, this.decoderOptions, this.LocalConfiguration));
+
}
@@ -169,7 +187,7 @@ namespace ImageSharp.Tests
Image img = Image.Load(stream, this.localDecoder.Object);
Assert.NotNull(img);
- this.localDecoder.Verify(x => x.Decode(stream, null));
+ this.localDecoder.Verify(x => x.Decode(stream, null, Configuration.Default));
}
[Fact]
@@ -180,7 +198,7 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(this.returnImage, img);
- this.localDecoder.Verify(x => x.Decode(stream, null));
+ this.localDecoder.Verify(x => x.Decode(stream, null, Configuration.Default));
}
[Fact]
@@ -190,7 +208,7 @@ namespace ImageSharp.Tests
Image img = Image.Load(stream, this.localDecoder.Object, this.decoderOptions);
Assert.NotNull(img);
- this.localDecoder.Verify(x => x.Decode(stream, this.decoderOptions));
+ this.localDecoder.Verify(x => x.Decode(stream, this.decoderOptions, Configuration.Default));
}
[Fact]
@@ -201,7 +219,7 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(this.returnImage, img);
- this.localDecoder.Verify(x => x.Decode(stream, this.decoderOptions));
+ this.localDecoder.Verify(x => x.Decode(stream, this.decoderOptions, Configuration.Default));
}
[Fact]
@@ -212,7 +230,9 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat);
- TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, null);
+
+ TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, null, Configuration.Default);
+
}
[Fact]
@@ -223,7 +243,9 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img);
Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat);
- TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, null);
+
+ TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, null, Configuration.Default);
+
}
[Fact]
@@ -233,7 +255,9 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat);
- TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, this.decoderOptions);
+
+ TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, this.decoderOptions, Configuration.Default);
+
}
[Fact]
@@ -244,7 +268,9 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img);
Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat);
- TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, this.decoderOptions);
+
+ TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, this.decoderOptions, Configuration.Default);
+
}
[Fact]
@@ -254,7 +280,9 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(this.localFormat.Object, img.CurrentImageFormat);
- this.localDecoder.Verify(x => x.Decode(It.IsAny(), null));
+
+ this.localDecoder.Verify(x => x.Decode(It.IsAny(), null, this.LocalConfiguration));
+
Assert.Equal(this.DataStream.ToArray(), this.DecodedData);
}
@@ -267,7 +295,9 @@ namespace ImageSharp.Tests
Assert.Equal(this.returnImage, img);
Assert.Equal(this.localFormat.Object, img.CurrentImageFormat);
- this.localDecoder.Verify(x => x.Decode(It.IsAny(), null));
+
+ this.localDecoder.Verify(x => x.Decode(It.IsAny(), null, this.LocalConfiguration));
+
Assert.Equal(this.DataStream.ToArray(), this.DecodedData);
}
@@ -278,7 +308,9 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(this.localFormat.Object, img.CurrentImageFormat);
- this.localDecoder.Verify(x => x.Decode(It.IsAny(), this.decoderOptions));
+
+ this.localDecoder.Verify(x => x.Decode(It.IsAny(), this.decoderOptions, this.LocalConfiguration));
+
Assert.Equal(this.DataStream.ToArray(), this.DecodedData);
}
@@ -290,7 +322,9 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(this.returnImage, img);
Assert.Equal(this.localFormat.Object, img.CurrentImageFormat);
- this.localDecoder.Verify(x => x.Decode(It.IsAny(), this.decoderOptions));
+
+ this.localDecoder.Verify(x => x.Decode(It.IsAny(), this.decoderOptions, this.LocalConfiguration));
+
Assert.Equal(this.DataStream.ToArray(), this.DecodedData);
}
@@ -301,7 +335,7 @@ namespace ImageSharp.Tests
Image img = Image.Load(this.DataStream.ToArray(), this.localDecoder.Object);
Assert.NotNull(img);
- this.localDecoder.Verify(x => x.Decode(It.IsAny(), null));
+ this.localDecoder.Verify(x => x.Decode(It.IsAny(), null, Configuration.Default));
Assert.Equal(this.DataStream.ToArray(), this.DecodedData);
}
@@ -312,7 +346,7 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(this.returnImage, img);
- this.localDecoder.Verify(x => x.Decode(It.IsAny(), null));
+ this.localDecoder.Verify(x => x.Decode(It.IsAny(), null, Configuration.Default));
Assert.Equal(this.DataStream.ToArray(), this.DecodedData);
}
@@ -322,7 +356,7 @@ namespace ImageSharp.Tests
Image img = Image.Load(this.DataStream.ToArray(), this.localDecoder.Object, this.decoderOptions);
Assert.NotNull(img);
- this.localDecoder.Verify(x => x.Decode(It.IsAny(), this.decoderOptions));
+ this.localDecoder.Verify(x => x.Decode(It.IsAny(), this.decoderOptions, Configuration.Default));
Assert.Equal(this.DataStream.ToArray(), this.DecodedData);
}
@@ -333,7 +367,7 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(this.returnImage, img);
- this.localDecoder.Verify(x => x.Decode(It.IsAny(), this.decoderOptions));
+ this.localDecoder.Verify(x => x.Decode(It.IsAny(), this.decoderOptions, Configuration.Default));
Assert.Equal(this.DataStream.ToArray(), this.DecodedData);
}
@@ -345,7 +379,9 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat);
- TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, null);
+
+ TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, null, Configuration.Default);
+
}
[Fact]
@@ -356,7 +392,9 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img);
Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat);
- TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, null);
+
+ TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, null, Configuration.Default);
+
}
[Fact]
@@ -366,7 +404,9 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat);
- TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, this.decoderOptions);
+
+ TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, this.decoderOptions, Configuration.Default);
+
}
[Fact]
@@ -377,7 +417,9 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img);
Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat);
- TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, this.decoderOptions);
+
+ TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, this.decoderOptions, Configuration.Default);
+
}
[Fact]
@@ -387,7 +429,9 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(this.localFormat.Object, img.CurrentImageFormat);
- this.localDecoder.Verify(x => x.Decode(this.DataStream, null));
+
+ this.localDecoder.Verify(x => x.Decode(this.DataStream, null, this.LocalConfiguration));
+
}
[Fact]
@@ -398,7 +442,9 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(this.returnImage, img);
Assert.Equal(this.localFormat.Object, img.CurrentImageFormat);
- this.localDecoder.Verify(x => x.Decode(this.DataStream, null));
+
+ this.localDecoder.Verify(x => x.Decode(this.DataStream, null, this.LocalConfiguration));
+
}
[Fact]
@@ -408,7 +454,9 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(this.localFormat.Object, img.CurrentImageFormat);
- this.localDecoder.Verify(x => x.Decode(this.DataStream, this.decoderOptions));
+
+ this.localDecoder.Verify(x => x.Decode(this.DataStream, this.decoderOptions, this.LocalConfiguration));
+
}
[Fact]
@@ -419,7 +467,9 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(this.returnImage, img);
Assert.Equal(this.localFormat.Object, img.CurrentImageFormat);
- this.localDecoder.Verify(x => x.Decode(this.DataStream, this.decoderOptions));
+
+ this.localDecoder.Verify(x => x.Decode(this.DataStream, this.decoderOptions, this.LocalConfiguration));
+
}
@@ -429,7 +479,7 @@ namespace ImageSharp.Tests
Image img = Image.Load(this.FilePath, this.localDecoder.Object);
Assert.NotNull(img);
- this.localDecoder.Verify(x => x.Decode(this.DataStream, null));
+ this.localDecoder.Verify(x => x.Decode(this.DataStream, null, Configuration.Default));
}
[Fact]
@@ -439,7 +489,7 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(this.returnImage, img);
- this.localDecoder.Verify(x => x.Decode(this.DataStream, null));
+ this.localDecoder.Verify(x => x.Decode(this.DataStream, null, Configuration.Default));
}
[Fact]
@@ -448,7 +498,7 @@ namespace ImageSharp.Tests
Image img = Image.Load(this.FilePath, this.localDecoder.Object, this.decoderOptions);
Assert.NotNull(img);
- this.localDecoder.Verify(x => x.Decode(this.DataStream, this.decoderOptions));
+ this.localDecoder.Verify(x => x.Decode(this.DataStream, this.decoderOptions, Configuration.Default));
}
[Fact]
@@ -458,7 +508,7 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(this.returnImage, img);
- this.localDecoder.Verify(x => x.Decode(this.DataStream, this.decoderOptions));
+ this.localDecoder.Verify(x => x.Decode(this.DataStream, this.decoderOptions, Configuration.Default));
}
public void Dispose()
diff --git a/tests/ImageSharp.Tests/TestFormat.cs b/tests/ImageSharp.Tests/TestFormat.cs
index 3a40ed420..5894151dc 100644
--- a/tests/ImageSharp.Tests/TestFormat.cs
+++ b/tests/ImageSharp.Tests/TestFormat.cs
@@ -55,9 +55,11 @@ namespace ImageSharp.Tests
Dictionary _sampleImages = new Dictionary();
- public void VerifyDecodeCall(byte[] marker, IDecoderOptions options)
+
+ public void VerifyDecodeCall(byte[] marker, IDecoderOptions options, Configuration config)
{
- DecodeOperation[] discovered = this.DecodeCalls.Where(x => x.IsMatch(marker, options)).ToArray();
+ DecodeOperation[] discovered = this.DecodeCalls.Where(x => x.IsMatch(marker, options, config)).ToArray();
+
Assert.True(discovered.Any(), "No calls to decode on this formate with the proveded options happend");
@@ -107,10 +109,16 @@ namespace ImageSharp.Tests
{
public byte[] marker;
public IDecoderOptions options;
+ internal Configuration config;
- public bool IsMatch(byte[] testMarker, IDecoderOptions testOptions)
+ public bool IsMatch(byte[] testMarker, IDecoderOptions testOptions, Configuration config)
{
- if(this.options != testOptions)
+ if (this.options != testOptions)
+ {
+ return false;
+ }
+
+ if (this.config != config)
{
return false;
}
@@ -140,7 +148,9 @@ namespace ImageSharp.Tests
this.testFormat = testFormat;
}
- public Image Decode(Stream stream, IDecoderOptions options) where TColor : struct, IPixel
+
+ public Image Decode(Stream stream, IDecoderOptions options, Configuration config) where TColor : struct, IPixel
+
{
var ms = new MemoryStream();
stream.CopyTo(ms);
@@ -148,7 +158,8 @@ namespace ImageSharp.Tests
this.testFormat.DecodeCalls.Add(new DecodeOperation
{
marker = marker,
- options = options
+ options = options,
+ config = config
});
// TODO record this happend so we an verify it.