Browse Source

decoder configuration argument order

af/merge-core
Scott Williams 9 years ago
parent
commit
15fc34126f
  1. 3
      ImageSharp.sln
  2. 2
      src/ImageSharp/Formats/Bmp/BmpDecoder.cs
  3. 8
      src/ImageSharp/Formats/Gif/GifDecoder.cs
  4. 4
      src/ImageSharp/Formats/IImageDecoder.cs
  5. 2
      src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
  6. 8
      src/ImageSharp/Formats/Png/PngDecoder.cs
  7. 2
      src/ImageSharp/Image.Decode.cs
  8. 2
      src/ImageSharp/Image.FromStream.cs
  9. 7
      src/README.md
  10. 50
      tests/ImageSharp.Tests/Image/ImageLoadTests.cs
  11. 2
      tests/ImageSharp.Tests/TestFormat.cs

3
ImageSharp.sln

@ -22,6 +22,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionIt
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source", "Source", "{815C0625-CD3D-440F-9F80-2D83856AB7AE}"
ProjectSection(SolutionItems) = preProject
src\README.md = src\README.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{56801022-D71A-4FBE-BC5B-CBA08E2284EC}"
EndProject

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

@ -26,7 +26,7 @@ namespace ImageSharp.Formats
public class BmpDecoder : IImageDecoder
{
/// <inheritdoc/>
public Image<TColor> Decode<TColor>(Stream stream, IDecoderOptions options, Configuration configuration)
public Image<TColor> Decode<TColor>(Configuration configuration, Stream stream, IDecoderOptions options)
where TColor : struct, IPixel<TColor>
{

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

@ -14,24 +14,24 @@ namespace ImageSharp.Formats
public class GifDecoder : IImageDecoder
{
/// <inheritdoc/>
public Image<TColor> Decode<TColor>(Stream stream, IDecoderOptions options, Configuration configuration)
public Image<TColor> Decode<TColor>(Configuration configuration, Stream stream, IDecoderOptions options)
where TColor : struct, IPixel<TColor>
{
IGifDecoderOptions gifOptions = GifDecoderOptions.Create(options);
return this.Decode<TColor>(stream, gifOptions, configuration);
return this.Decode<TColor>(configuration, stream, gifOptions);
}
/// <summary>
/// Decodes the image from the specified stream to the <see cref="ImageBase{TColor}"/>.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <param name="configuration">The configuration.</param>
/// <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, Configuration configuration)
public Image<TColor> Decode<TColor>(Configuration configuration, Stream stream, IGifDecoderOptions options)
where TColor : struct, IPixel<TColor>
{
return new GifDecoderCore<TColor>(options, configuration).Decode(stream);

4
src/ImageSharp/Formats/IImageDecoder.cs

@ -17,11 +17,11 @@ namespace ImageSharp.Formats
/// Decodes the image from the specified stream to the <see cref="ImageBase{TColor}"/>.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <param name="configuration">The configuration for the image.</param>
/// <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, Configuration configuration)
Image<TColor> Decode<TColor>(Configuration configuration, Stream stream, IDecoderOptions options)
where TColor : struct, IPixel<TColor>;
}
}

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

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

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

@ -31,24 +31,24 @@ namespace ImageSharp.Formats
public class PngDecoder : IImageDecoder
{
/// <inheritdoc/>
public Image<TColor> Decode<TColor>(Stream stream, IDecoderOptions options, Configuration configuration)
public Image<TColor> Decode<TColor>(Configuration configuration, Stream stream, IDecoderOptions options)
where TColor : struct, IPixel<TColor>
{
IPngDecoderOptions pngOptions = PngDecoderOptions.Create(options);
return this.Decode<TColor>(stream, pngOptions, configuration);
return this.Decode<TColor>(configuration, stream, pngOptions);
}
/// <summary>
/// Decodes the image from the specified stream to the <see cref="ImageBase{TColor}"/>.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <param name="configuration">The configuration for the image.</param>
/// <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, Configuration configuration)
public Image<TColor> Decode<TColor>(Configuration configuration, Stream stream, IPngDecoderOptions options)
where TColor : struct, IPixel<TColor>
{
return new PngDecoderCore(options, configuration).Decode<TColor>(stream);

2
src/ImageSharp/Image.Decode.cs

@ -67,7 +67,7 @@ namespace ImageSharp
return null;
}
Image<TColor> img = format.Decoder.Decode<TColor>(stream, options, config);
Image<TColor> img = format.Decoder.Decode<TColor>(config, stream, options);
img.CurrentImageFormat = format;
return img;
}

2
src/ImageSharp/Image.FromStream.cs

@ -182,7 +182,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, Configuration.Default));
return WithSeekableStream(stream, s => decoder.Decode<TColor>(Configuration.Default, s, options));
}
/// <summary>

7
src/README.md

@ -0,0 +1,7 @@
# ImageSharp core libraries
## Coding conventions
### Argument ordering
- When passing a `Configuration` object it should be the first argument

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

@ -44,7 +44,7 @@ namespace ImageSharp.Tests
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>(), It.IsAny<Configuration>()))
this.localDecoder.Setup(x => x.Decode<Color>(It.IsAny<Configuration>(), It.IsAny<Stream>(), It.IsAny<IDecoderOptions>()))
.Callback<Stream, IDecoderOptions, Configuration>((s, o, c) => {
using (var ms = new MemoryStream())
@ -133,7 +133,7 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(this.localFormat.Object, img.CurrentImageFormat);
this.localDecoder.Verify(x => x.Decode<Color>(stream, null, this.LocalConfiguration));
this.localDecoder.Verify(x => x.Decode<Color>(this.LocalConfiguration, stream, null));
}
@ -147,7 +147,7 @@ namespace ImageSharp.Tests
Assert.Equal(this.returnImage, img);
Assert.Equal(this.localFormat.Object, img.CurrentImageFormat);
this.localDecoder.Verify(x => x.Decode<Color>(stream, null, this.LocalConfiguration));
this.localDecoder.Verify(x => x.Decode<Color>(this.LocalConfiguration, stream, null));
}
@ -160,7 +160,7 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(this.localFormat.Object, img.CurrentImageFormat);
this.localDecoder.Verify(x => x.Decode<Color>(stream, this.decoderOptions, this.LocalConfiguration));
this.localDecoder.Verify(x => x.Decode<Color>(this.LocalConfiguration, stream, this.decoderOptions));
}
@ -174,7 +174,7 @@ namespace ImageSharp.Tests
Assert.Equal(this.returnImage, img);
Assert.Equal(this.localFormat.Object, img.CurrentImageFormat);
this.localDecoder.Verify(x => x.Decode<Color>(stream, this.decoderOptions, this.LocalConfiguration));
this.localDecoder.Verify(x => x.Decode<Color>(this.LocalConfiguration, stream, this.decoderOptions));
}
@ -187,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, Configuration.Default));
this.localDecoder.Verify(x => x.Decode<Color>(Configuration.Default, stream, null));
}
[Fact]
@ -198,7 +198,7 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(this.returnImage, img);
this.localDecoder.Verify(x => x.Decode<Color>(stream, null, Configuration.Default));
this.localDecoder.Verify(x => x.Decode<Color>(Configuration.Default, stream, null));
}
[Fact]
@ -208,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, Configuration.Default));
this.localDecoder.Verify(x => x.Decode<Color>(Configuration.Default, stream, this.decoderOptions));
}
[Fact]
@ -219,7 +219,7 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(this.returnImage, img);
this.localDecoder.Verify(x => x.Decode<Color>(stream, this.decoderOptions, Configuration.Default));
this.localDecoder.Verify(x => x.Decode<Color>(Configuration.Default, stream, this.decoderOptions));
}
[Fact]
@ -281,7 +281,7 @@ 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.LocalConfiguration));
this.localDecoder.Verify(x => x.Decode<Color>(this.LocalConfiguration, It.IsAny<Stream>(), null));
Assert.Equal(this.DataStream.ToArray(), this.DecodedData);
}
@ -296,7 +296,7 @@ namespace ImageSharp.Tests
Assert.Equal(this.localFormat.Object, img.CurrentImageFormat);
this.localDecoder.Verify(x => x.Decode<Color>(It.IsAny<Stream>(), null, this.LocalConfiguration));
this.localDecoder.Verify(x => x.Decode<Color>(this.LocalConfiguration, It.IsAny<Stream>(), null));
Assert.Equal(this.DataStream.ToArray(), this.DecodedData);
}
@ -309,7 +309,7 @@ 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.LocalConfiguration));
this.localDecoder.Verify(x => x.Decode<Color>(this.LocalConfiguration, It.IsAny<Stream>(), this.decoderOptions));
Assert.Equal(this.DataStream.ToArray(), this.DecodedData);
}
@ -323,7 +323,7 @@ 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>(), this.decoderOptions, this.LocalConfiguration));
this.localDecoder.Verify(x => x.Decode<Color>(this.LocalConfiguration, It.IsAny<Stream>(), this.decoderOptions));
Assert.Equal(this.DataStream.ToArray(), this.DecodedData);
}
@ -335,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, Configuration.Default));
this.localDecoder.Verify(x => x.Decode<Color>(Configuration.Default, It.IsAny<Stream>(), null));
Assert.Equal(this.DataStream.ToArray(), this.DecodedData);
}
@ -346,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, Configuration.Default));
this.localDecoder.Verify(x => x.Decode<Color>(Configuration.Default, It.IsAny<Stream>(), null));
Assert.Equal(this.DataStream.ToArray(), this.DecodedData);
}
@ -356,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, Configuration.Default));
this.localDecoder.Verify(x => x.Decode<Color>(Configuration.Default, It.IsAny<Stream>(), this.decoderOptions));
Assert.Equal(this.DataStream.ToArray(), this.DecodedData);
}
@ -367,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, Configuration.Default));
this.localDecoder.Verify(x => x.Decode<Color>(Configuration.Default, It.IsAny<Stream>(), this.decoderOptions));
Assert.Equal(this.DataStream.ToArray(), this.DecodedData);
}
@ -430,7 +430,7 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(this.localFormat.Object, img.CurrentImageFormat);
this.localDecoder.Verify(x => x.Decode<Color>(this.DataStream, null, this.LocalConfiguration));
this.localDecoder.Verify(x => x.Decode<Color>(this.LocalConfiguration, this.DataStream, null));
}
@ -443,7 +443,7 @@ namespace ImageSharp.Tests
Assert.Equal(this.returnImage, img);
Assert.Equal(this.localFormat.Object, img.CurrentImageFormat);
this.localDecoder.Verify(x => x.Decode<Color>(this.DataStream, null, this.LocalConfiguration));
this.localDecoder.Verify(x => x.Decode<Color>(this.LocalConfiguration, this.DataStream, null));
}
@ -455,7 +455,7 @@ 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.LocalConfiguration));
this.localDecoder.Verify(x => x.Decode<Color>(this.LocalConfiguration, this.DataStream, this.decoderOptions));
}
@ -468,7 +468,7 @@ namespace ImageSharp.Tests
Assert.Equal(this.returnImage, img);
Assert.Equal(this.localFormat.Object, img.CurrentImageFormat);
this.localDecoder.Verify(x => x.Decode<Color>(this.DataStream, this.decoderOptions, this.LocalConfiguration));
this.localDecoder.Verify(x => x.Decode<Color>(this.LocalConfiguration, this.DataStream, this.decoderOptions));
}
@ -479,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, Configuration.Default));
this.localDecoder.Verify(x => x.Decode<Color>(Configuration.Default, this.DataStream, null));
}
[Fact]
@ -489,7 +489,7 @@ namespace ImageSharp.Tests
Assert.NotNull(img);
Assert.Equal(this.returnImage, img);
this.localDecoder.Verify(x => x.Decode<Color>(this.DataStream, null, Configuration.Default));
this.localDecoder.Verify(x => x.Decode<Color>(Configuration.Default, this.DataStream, null));
}
[Fact]
@ -498,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, Configuration.Default));
this.localDecoder.Verify(x => x.Decode<Color>(Configuration.Default, this.DataStream, this.decoderOptions));
}
[Fact]
@ -508,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, Configuration.Default));
this.localDecoder.Verify(x => x.Decode<Color>(Configuration.Default, this.DataStream, this.decoderOptions));
}
public void Dispose()

2
tests/ImageSharp.Tests/TestFormat.cs

@ -149,7 +149,7 @@ namespace ImageSharp.Tests
}
public Image<TColor> Decode<TColor>(Stream stream, IDecoderOptions options, Configuration config) where TColor : struct, IPixel<TColor>
public Image<TColor> Decode<TColor>(Configuration config, Stream stream, IDecoderOptions options) where TColor : struct, IPixel<TColor>
{
var ms = new MemoryStream();

Loading…
Cancel
Save