Browse Source

pass configuration & ensure only single image created

af/merge-core
Scott Williams 9 years ago
parent
commit
cc32d2d398
  1. 5
      src/ImageSharp/Formats/Bmp/BmpDecoder.cs
  2. 14
      src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
  3. 10
      src/ImageSharp/Formats/Gif/GifDecoder.cs
  4. 11
      src/ImageSharp/Formats/Gif/GifDecoderCore.cs
  5. 3
      src/ImageSharp/Formats/IImageDecoder.cs
  6. 4
      src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
  7. 12
      src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
  8. 10
      src/ImageSharp/Formats/Png/PngDecoder.cs
  9. 11
      src/ImageSharp/Formats/Png/PngDecoderCore.cs
  10. 46
      src/ImageSharp/Image.Create.cs
  11. 6
      src/ImageSharp/Image.Decode.cs
  12. 6
      src/ImageSharp/Image.FromFile.cs
  13. 2
      src/ImageSharp/Image.FromStream.cs
  14. 2
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
  15. 128
      tests/ImageSharp.Tests/Image/ImageLoadTests.cs
  16. 23
      tests/ImageSharp.Tests/TestFormat.cs

5
src/ImageSharp/Formats/Bmp/BmpDecoder.cs

@ -26,12 +26,13 @@ namespace ImageSharp.Formats
public class BmpDecoder : IImageDecoder
{
/// <inheritdoc/>
public Image<TColor> Decode<TColor>(Stream stream, IDecoderOptions options)
public Image<TColor> Decode<TColor>(Stream stream, IDecoderOptions options, Configuration configuration)
where TColor : struct, IPixel<TColor>
{
Guard.NotNull(stream, "stream");
return new BmpDecoderCore().Decode<TColor>(stream);
return new BmpDecoderCore(configuration).Decode<TColor>(stream);
}
}
}

14
src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs

@ -43,6 +43,17 @@ namespace ImageSharp.Formats
/// </summary>
private BmpInfoHeader infoHeader;
private Configuration configuration;
/// <summary>
/// Initializes a new instance of the <see cref="BmpDecoderCore"/> class.
/// </summary>
/// <param name="configuration">The configuration.</param>
public BmpDecoderCore(Configuration configuration)
{
this.configuration = configuration;
}
/// <summary>
/// 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<TColor>.MaxWidth}x{Image<TColor>.MaxHeight}'");
}
Image<TColor> image = new Image<TColor>(this.infoHeader.Width, this.infoHeader.Height);
Image<TColor> image = Image.Create<TColor>(this.infoHeader.Width, this.infoHeader.Height, this.configuration);
using (PixelAccessor<TColor> pixels = image.Lock())
{
switch (this.infoHeader.Compression)

10
src/ImageSharp/Formats/Gif/GifDecoder.cs

@ -14,12 +14,13 @@ namespace ImageSharp.Formats
public class GifDecoder : IImageDecoder
{
/// <inheritdoc/>
public Image<TColor> Decode<TColor>(Stream stream, IDecoderOptions options)
public Image<TColor> Decode<TColor>(Stream stream, IDecoderOptions options, Configuration configuration)
where TColor : struct, IPixel<TColor>
{
IGifDecoderOptions gifOptions = GifDecoderOptions.Create(options);
return this.Decode<TColor>(stream, gifOptions);
return this.Decode<TColor>(stream, gifOptions, configuration);
}
/// <summary>
@ -28,11 +29,12 @@ namespace ImageSharp.Formats
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <param name="stream">The <see cref="Stream"/> containing image data.</param>
/// <param name="options">The options for the decoder.</param>
/// <param name="configuration">The configuration.</param>
/// <returns>The image thats been decoded.</returns>
public Image<TColor> Decode<TColor>(Stream stream, IGifDecoderOptions options)
public Image<TColor> Decode<TColor>(Stream stream, IGifDecoderOptions options, Configuration configuration)
where TColor : struct, IPixel<TColor>
{
return new GifDecoderCore<TColor>(options).Decode(stream);
return new GifDecoderCore<TColor>(options, configuration).Decode(stream);
}
}
}

11
src/ImageSharp/Formats/Gif/GifDecoderCore.cs

@ -27,6 +27,11 @@ namespace ImageSharp.Formats
/// </summary>
private readonly IGifDecoderOptions options;
/// <summary>
/// The global configuration.
/// </summary>
private readonly Configuration configuration;
/// <summary>
/// The currently loaded stream.
/// </summary>
@ -76,9 +81,11 @@ namespace ImageSharp.Formats
/// Initializes a new instance of the <see cref="GifDecoderCore{TColor}"/> class.
/// </summary>
/// <param name="options">The decoder options.</param>
public GifDecoderCore(IGifDecoderOptions options)
/// <param name="configuration">The configuration.</param>
public GifDecoderCore(IGifDecoderOptions options, Configuration configuration)
{
this.options = options ?? new GifDecoderOptions();
this.configuration = configuration ?? Configuration.Default;
}
/// <summary>
@ -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<TColor>(imageWidth, imageHeight);
this.image = Image.Create<TColor>(imageWidth, imageHeight, this.configuration);
this.image.MetaData.LoadFrom(this.metaData);
this.SetFrameDelay(this.metaData);

3
src/ImageSharp/Formats/IImageDecoder.cs

@ -19,8 +19,9 @@ namespace ImageSharp.Formats
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <param name="stream">The <see cref="Stream"/> containing image data.</param>
/// <param name="options">The options for the decoder.</param>
/// <param name="configuration">The configuration for the image.</param>
/// <returns>The decoded image</returns>
Image<TColor> Decode<TColor>(Stream stream, IDecoderOptions options)
Image<TColor> Decode<TColor>(Stream stream, IDecoderOptions options, Configuration configuration)
where TColor : struct, IPixel<TColor>;
}
}

4
src/ImageSharp/Formats/Jpeg/JpegDecoder.cs

@ -14,12 +14,12 @@ namespace ImageSharp.Formats
public class JpegDecoder : IImageDecoder
{
/// <inheritdoc/>
public Image<TColor> Decode<TColor>(Stream stream, IDecoderOptions options)
public Image<TColor> Decode<TColor>(Stream stream, IDecoderOptions options, Configuration configuration)
where TColor : struct, IPixel<TColor>
{
Guard.NotNull(stream, "stream");
using (JpegDecoderCore decoder = new JpegDecoderCore(options))
using (JpegDecoderCore decoder = new JpegDecoderCore(options, configuration))
{
return decoder.Decode<TColor>(stream);
}

12
src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs

@ -42,6 +42,11 @@ namespace ImageSharp.Formats
/// </summary>
private readonly IDecoderOptions options;
/// <summary>
/// The global configuration
/// </summary>
private readonly Configuration configuration;
/// <summary>
/// The App14 marker color-space
/// </summary>
@ -91,8 +96,10 @@ namespace ImageSharp.Formats
/// Initializes a new instance of the <see cref="JpegDecoderCore" /> class.
/// </summary>
/// <param name="options">The decoder options.</param>
public JpegDecoderCore(IDecoderOptions options)
/// <param name="configuration">The configuration.</param>
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<TColor> ConvertJpegPixelsToImagePixels<TColor>(ImageMetaData metadata)
where TColor : struct, IPixel<TColor>
{
Image<TColor> image = new Image<TColor>(this.ImageWidth, this.ImageHeight);
Image<TColor> image = Image.Create<TColor>(this.ImageWidth, this.ImageHeight, this.configuration);
image.MetaData.LoadFrom(metadata);
if (this.grayImage.IsInitialized)

10
src/ImageSharp/Formats/Png/PngDecoder.cs

@ -31,12 +31,13 @@ namespace ImageSharp.Formats
public class PngDecoder : IImageDecoder
{
/// <inheritdoc/>
public Image<TColor> Decode<TColor>(Stream stream, IDecoderOptions options)
public Image<TColor> Decode<TColor>(Stream stream, IDecoderOptions options, Configuration configuration)
where TColor : struct, IPixel<TColor>
{
IPngDecoderOptions pngOptions = PngDecoderOptions.Create(options);
return this.Decode<TColor>(stream, pngOptions);
return this.Decode<TColor>(stream, pngOptions, configuration);
}
/// <summary>
@ -45,11 +46,12 @@ namespace ImageSharp.Formats
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <param name="stream">The <see cref="Stream"/> containing image data.</param>
/// <param name="options">The options for the decoder.</param>
/// <param name="configuration">The configuration for the image.</param>
/// <returns>The decoded image.</returns>
public Image<TColor> Decode<TColor>(Stream stream, IPngDecoderOptions options)
public Image<TColor> Decode<TColor>(Stream stream, IPngDecoderOptions options, Configuration configuration)
where TColor : struct, IPixel<TColor>
{
return new PngDecoderCore(options).Decode<TColor>(stream);
return new PngDecoderCore(options, configuration).Decode<TColor>(stream);
}
}
}

11
src/ImageSharp/Formats/Png/PngDecoderCore.cs

@ -74,6 +74,11 @@ namespace ImageSharp.Formats
/// </summary>
private readonly Crc32 crc = new Crc32();
/// <summary>
/// The global configuration.
/// </summary>
private readonly Configuration configuration;
/// <summary>
/// The stream to decode from.
/// </summary>
@ -134,8 +139,10 @@ namespace ImageSharp.Formats
/// Initializes a new instance of the <see cref="PngDecoderCore"/> class.
/// </summary>
/// <param name="options">The decoder options.</param>
public PngDecoderCore(IPngDecoderOptions options)
/// <param name="configuration">The configuration.</param>
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<TColor>.MaxWidth}x{Image<TColor>.MaxHeight}'");
}
Image<TColor> image = new Image<TColor>(this.header.Width, this.header.Height);
Image<TColor> image = Image.Create<TColor>(this.header.Width, this.header.Height, this.configuration);
image.MetaData.LoadFrom(metadata);
using (PixelAccessor<TColor> pixels = image.Lock())

46
src/ImageSharp/Image.Create.cs

@ -0,0 +1,46 @@
// <copyright file="Image.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
using System;
using System.Diagnostics;
using System.IO;
using Formats;
/// <summary>
/// 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.
/// </summary>
public sealed partial class Image
{
/// <summary>
/// Create a new instance of the <see cref="Image{TColor}"/> class
/// with the height and the width of the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
/// <returns>
/// A new <see cref="Image{TColor}"/> unless <typeparamref name="TColor"/> is <see cref="Color"/> in which case it returns <see cref="Image" />
/// </returns>
internal static Image<TColor> Create<TColor>(int width, int height, Configuration configuration)
where TColor : struct, IPixel<TColor>
{
if (typeof(TColor) == typeof(Color))
{
return new Image(width, height, configuration) as Image<TColor>;
}
else
{
return new Image<TColor>(width, height, configuration);
}
}
}
}

6
src/ImageSharp/Image.Decode.cs

@ -19,7 +19,7 @@ namespace ImageSharp
/// </summary>
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<TColor> Decode<TColor>(Stream stream, IDecoderOptions options, Configuration config)
where TColor : struct, IPixel<TColor>
{
IImageFormat format = DiscoverFormat(stream, options, config);
IImageFormat format = DiscoverFormat(stream, config);
if (format == null)
{
return null;
}
Image<TColor> img = format.Decoder.Decode<TColor>(stream, options);
Image<TColor> img = format.Decoder.Decode<TColor>(stream, options, config);
img.CurrentImageFormat = format;
return img;
}

6
src/ImageSharp/Image.FromFile.cs

@ -102,7 +102,11 @@ namespace ImageSharp
/// <returns>The image</returns>
public static Image Load(string path, IDecoderOptions options, Configuration config)
{
return new Image(Load<Color>(path, options, config));
config = config ?? Configuration.Default;
using (Stream s = config.FileSystem.OpenRead(path))
{
return Load(s, options, config);
}
}
/// <summary>

2
src/ImageSharp/Image.FromStream.cs

@ -181,7 +181,7 @@ namespace ImageSharp
public static Image<TColor> Load<TColor>(Stream stream, IImageDecoder decoder, IDecoderOptions options)
where TColor : struct, IPixel<TColor>
{
return WithSeekableStream(stream, s => decoder.Decode<TColor>(s, options));
return WithSeekableStream(stream, s => decoder.Decode<TColor>(s, options, Configuration.Default));
}
/// <summary>

2
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<TColor> mirror = decoder.Decode<TColor>(ms);

128
tests/ImageSharp.Tests/Image/ImageLoadTests.cs

@ -32,7 +32,7 @@ namespace ImageSharp.Tests
public ImageLoadTests()
{
this.returnImage = new Image<Color>(1, 1);
this.returnImage = new Image(1, 1);
this.localDecoder = new Mock<IImageDecoder>();
this.localFormat = new Mock<IImageFormat>();
@ -43,8 +43,10 @@ namespace ImageSharp.Tests
this.localFormat.Setup(x => x.HeaderSize).Returns(1);
this.localFormat.Setup(x => x.IsSupportedFileFormat(It.IsAny<byte[]>())).Returns(true);
this.localFormat.Setup(x => x.SupportedExtensions).Returns(new string[] { "png", "jpg" });
this.localDecoder.Setup(x => x.Decode<Color>(It.IsAny<Stream>(), It.IsAny<IDecoderOptions>()))
.Callback<Stream, IDecoderOptions>((s, o) => {
this.localDecoder.Setup(x => x.Decode<Color>(It.IsAny<Stream>(), It.IsAny<IDecoderOptions>(), It.IsAny<Configuration>()))
.Callback<Stream, IDecoderOptions, Configuration>((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<Color>(), 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<Color>(), 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<Color>(stream, null));
this.localDecoder.Verify(x => x.Decode<Color>(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<Color>(stream, null));
this.localDecoder.Verify(x => x.Decode<Color>(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<Color>(stream, this.decoderOptions));
this.localDecoder.Verify(x => x.Decode<Color>(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<Color>(stream, this.decoderOptions));
this.localDecoder.Verify(x => x.Decode<Color>(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<Color>(stream, null));
this.localDecoder.Verify(x => x.Decode<Color>(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<Color>(stream, null));
this.localDecoder.Verify(x => x.Decode<Color>(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<Color>(stream, this.decoderOptions));
this.localDecoder.Verify(x => x.Decode<Color>(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<Color>(stream, this.decoderOptions));
this.localDecoder.Verify(x => x.Decode<Color>(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<Color>(), 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<Color>(), 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<Color>(It.IsAny<Stream>(), null));
this.localDecoder.Verify(x => x.Decode<Color>(It.IsAny<Stream>(), 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<Color>(It.IsAny<Stream>(), null));
this.localDecoder.Verify(x => x.Decode<Color>(It.IsAny<Stream>(), 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<Color>(It.IsAny<Stream>(), this.decoderOptions));
this.localDecoder.Verify(x => x.Decode<Color>(It.IsAny<Stream>(), 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<Color>(It.IsAny<Stream>(), this.decoderOptions));
this.localDecoder.Verify(x => x.Decode<Color>(It.IsAny<Stream>(), 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<Color>(It.IsAny<Stream>(), null));
this.localDecoder.Verify(x => x.Decode<Color>(It.IsAny<Stream>(), 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<Color>(It.IsAny<Stream>(), null));
this.localDecoder.Verify(x => x.Decode<Color>(It.IsAny<Stream>(), 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<Color>(It.IsAny<Stream>(), this.decoderOptions));
this.localDecoder.Verify(x => x.Decode<Color>(It.IsAny<Stream>(), 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<Color>(It.IsAny<Stream>(), this.decoderOptions));
this.localDecoder.Verify(x => x.Decode<Color>(It.IsAny<Stream>(), 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<Color>(), 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<Color>(), 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<Color>(this.DataStream, null));
this.localDecoder.Verify(x => x.Decode<Color>(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<Color>(this.DataStream, null));
this.localDecoder.Verify(x => x.Decode<Color>(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<Color>(this.DataStream, this.decoderOptions));
this.localDecoder.Verify(x => x.Decode<Color>(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<Color>(this.DataStream, this.decoderOptions));
this.localDecoder.Verify(x => x.Decode<Color>(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<Color>(this.DataStream, null));
this.localDecoder.Verify(x => x.Decode<Color>(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<Color>(this.DataStream, null));
this.localDecoder.Verify(x => x.Decode<Color>(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<Color>(this.DataStream, this.decoderOptions));
this.localDecoder.Verify(x => x.Decode<Color>(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<Color>(this.DataStream, this.decoderOptions));
this.localDecoder.Verify(x => x.Decode<Color>(this.DataStream, this.decoderOptions, Configuration.Default));
}
public void Dispose()

23
tests/ImageSharp.Tests/TestFormat.cs

@ -55,9 +55,11 @@ namespace ImageSharp.Tests
Dictionary<Type, object> _sampleImages = new Dictionary<Type, object>();
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<TColor> Decode<TColor>(Stream stream, IDecoderOptions options) where TColor : struct, IPixel<TColor>
public Image<TColor> Decode<TColor>(Stream stream, IDecoderOptions options, Configuration config) where TColor : struct, IPixel<TColor>
{
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.

Loading…
Cancel
Save