diff --git a/ImageSharp.sln.DotSettings b/ImageSharp.sln.DotSettings
index 8e7b5dd488..5268172429 100644
--- a/ImageSharp.sln.DotSettings
+++ b/ImageSharp.sln.DotSettings
@@ -388,4 +388,5 @@
True
True
True
+ True
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
index 6f5cabb09b..915915f6cc 100644
--- a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
+++ b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
@@ -10,7 +10,9 @@
$(packageversion)
0.0.1
+
netcoreapp2.1;netstandard1.3;netstandard2.0
+
7.3
true
true
diff --git a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs
index bdcb4c10f1..e0d7a4b184 100644
--- a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs
+++ b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs
@@ -18,11 +18,9 @@ namespace SixLabors.ImageSharp.Advanced
///
/// Gets the configuration for the image.
///
- /// The Pixel format.
/// The source image.
/// Returns the configuration.
- public static Configuration GetConfiguration(this Image source)
- where TPixel : struct, IPixel
+ public static Configuration GetConfiguration(this Image source)
=> GetConfiguration((IConfigurable)source);
///
diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoder.cs b/src/ImageSharp/Formats/Bmp/BmpDecoder.cs
index 82af2a671e..ebb7ffdf3c 100644
--- a/src/ImageSharp/Formats/Bmp/BmpDecoder.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpDecoder.cs
@@ -30,6 +30,9 @@ namespace SixLabors.ImageSharp.Formats.Bmp
return new BmpDecoderCore(configuration, this).Decode(stream);
}
+ ///
+ public Image Decode(Configuration configuration, Stream stream) => this.Decode(configuration, stream);
+
///
public IImageInfo Identify(Configuration configuration, Stream stream)
{
diff --git a/src/ImageSharp/Formats/Bmp/ImageExtensions.cs b/src/ImageSharp/Formats/Bmp/ImageExtensions.cs
index aa1c353db2..0c37907c22 100644
--- a/src/ImageSharp/Formats/Bmp/ImageExtensions.cs
+++ b/src/ImageSharp/Formats/Bmp/ImageExtensions.cs
@@ -2,38 +2,35 @@
// Licensed under the Apache License, Version 2.0.
using System.IO;
+
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats.Bmp;
-using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp
{
///
- /// Extension methods for the type.
+ /// Extension methods for the type.
///
public static partial class ImageExtensions
{
///
/// Saves the image to the given stream with the bmp format.
///
- /// The pixel format.
/// The image this method extends.
/// The stream to save the image to.
/// Thrown if the stream is null.
- public static void SaveAsBmp(this Image source, Stream stream)
- where TPixel : struct, IPixel
- => source.SaveAsBmp(stream, null);
+ public static void SaveAsBmp(this Image source, Stream stream) => source.SaveAsBmp(stream, null);
///
/// Saves the image to the given stream with the bmp format.
///
- /// The pixel format.
/// The image this method extends.
/// The stream to save the image to.
/// The encoder to save the image with.
/// Thrown if the stream is null.
- public static void SaveAsBmp(this Image source, Stream stream, BmpEncoder encoder)
- where TPixel : struct, IPixel
- => source.Save(stream, encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(BmpFormat.Instance));
+ public static void SaveAsBmp(this Image source, Stream stream, BmpEncoder encoder) =>
+ source.Save(
+ stream,
+ encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(BmpFormat.Instance));
}
-}
+}
\ No newline at end of file
diff --git a/src/ImageSharp/Formats/Gif/GifDecoder.cs b/src/ImageSharp/Formats/Gif/GifDecoder.cs
index 6af75f2d0f..1addcd0abf 100644
--- a/src/ImageSharp/Formats/Gif/GifDecoder.cs
+++ b/src/ImageSharp/Formats/Gif/GifDecoder.cs
@@ -44,5 +44,8 @@ namespace SixLabors.ImageSharp.Formats.Gif
var decoder = new GifDecoderCore(configuration, this);
return decoder.Identify(stream);
}
+
+ ///
+ public Image Decode(Configuration configuration, Stream stream) => this.Decode(configuration, stream);
}
}
diff --git a/src/ImageSharp/Formats/Gif/ImageExtensions.cs b/src/ImageSharp/Formats/Gif/ImageExtensions.cs
index 8ddd4247e1..c7ac001ff5 100644
--- a/src/ImageSharp/Formats/Gif/ImageExtensions.cs
+++ b/src/ImageSharp/Formats/Gif/ImageExtensions.cs
@@ -2,38 +2,35 @@
// Licensed under the Apache License, Version 2.0.
using System.IO;
+
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats.Gif;
-using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp
{
///
- /// Extension methods for the type.
+ /// Extension methods for the type.
///
public static partial class ImageExtensions
{
///
/// Saves the image to the given stream in the gif format.
///
- /// The pixel format.
/// The image this method extends.
/// The stream to save the image to.
/// Thrown if the stream is null.
- public static void SaveAsGif(this Image source, Stream stream)
- where TPixel : struct, IPixel
- => source.SaveAsGif(stream, null);
+ public static void SaveAsGif(this Image source, Stream stream) => source.SaveAsGif(stream, null);
///
/// Saves the image to the given stream in the gif format.
///
- /// The pixel format.
/// The image this method extends.
/// The stream to save the image to.
/// The options for the encoder.
/// Thrown if the stream is null.
- public static void SaveAsGif(this Image source, Stream stream, GifEncoder encoder)
- where TPixel : struct, IPixel
- => source.Save(stream, encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(GifFormat.Instance));
+ public static void SaveAsGif(this Image source, Stream stream, GifEncoder encoder) =>
+ source.Save(
+ stream,
+ encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(GifFormat.Instance));
}
-}
+}
\ No newline at end of file
diff --git a/src/ImageSharp/Formats/IImageDecoder.cs b/src/ImageSharp/Formats/IImageDecoder.cs
index ffc40314d8..8dafdac795 100644
--- a/src/ImageSharp/Formats/IImageDecoder.cs
+++ b/src/ImageSharp/Formats/IImageDecoder.cs
@@ -12,13 +12,22 @@ namespace SixLabors.ImageSharp.Formats
public interface IImageDecoder
{
///
- /// Decodes the image from the specified stream to the .
+ /// Decodes the image from the specified stream to an of a specific pixel type.
///
/// The pixel format.
/// The configuration for the image.
/// The containing image data.
- /// The decoded image
+ /// The decoded image of a given pixel type.
Image Decode(Configuration configuration, Stream stream)
where TPixel : struct, IPixel;
+
+ ///
+ /// Decodes the image from the specified stream to an .
+ /// The decoder is free to choose the pixel type.
+ ///
+ /// The configuration for the image.
+ /// The containing image data.
+ /// The decoded image of a pixel type chosen by the decoder.
+ Image Decode(Configuration configuration, Stream stream);
}
}
diff --git a/src/ImageSharp/Formats/Jpeg/ImageExtensions.cs b/src/ImageSharp/Formats/Jpeg/ImageExtensions.cs
index cb7fc19446..7fec050b4a 100644
--- a/src/ImageSharp/Formats/Jpeg/ImageExtensions.cs
+++ b/src/ImageSharp/Formats/Jpeg/ImageExtensions.cs
@@ -2,38 +2,35 @@
// Licensed under the Apache License, Version 2.0.
using System.IO;
+
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats.Jpeg;
-using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp
{
///
- /// Extension methods for the type.
+ /// Extension methods for the type.
///
public static partial class ImageExtensions
{
///
/// Saves the image to the given stream with the jpeg format.
///
- /// The pixel format.
/// The image this method extends.
/// The stream to save the image to.
/// Thrown if the stream is null.
- public static void SaveAsJpeg(this Image source, Stream stream)
- where TPixel : struct, IPixel
- => SaveAsJpeg(source, stream, null);
+ public static void SaveAsJpeg(this Image source, Stream stream) => SaveAsJpeg(source, stream, null);
///
/// Saves the image to the given stream with the jpeg format.
///
- /// The pixel format.
/// The image this method extends.
/// The stream to save the image to.
/// The options for the encoder.
/// Thrown if the stream is null.
- public static void SaveAsJpeg(this Image source, Stream stream, JpegEncoder encoder)
- where TPixel : struct, IPixel
- => source.Save(stream, encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(JpegFormat.Instance));
+ public static void SaveAsJpeg(this Image source, Stream stream, JpegEncoder encoder) =>
+ source.Save(
+ stream,
+ encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(JpegFormat.Instance));
}
-}
+}
\ No newline at end of file
diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
index 57b70dd26e..a1bf048521 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
@@ -38,5 +38,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
return decoder.Identify(stream);
}
}
+
+ ///
+ public Image Decode(Configuration configuration, Stream stream) => this.Decode(configuration, stream);
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/Formats/PixelTypeInfo.cs b/src/ImageSharp/Formats/PixelTypeInfo.cs
index ed21b91bfc..66d04f39fd 100644
--- a/src/ImageSharp/Formats/PixelTypeInfo.cs
+++ b/src/ImageSharp/Formats/PixelTypeInfo.cs
@@ -1,6 +1,10 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System.Runtime.CompilerServices;
+
+using SixLabors.ImageSharp.PixelFormats;
+
namespace SixLabors.ImageSharp.Formats
{
///
@@ -21,5 +25,9 @@ namespace SixLabors.ImageSharp.Formats
/// Gets color depth, in number of bits per pixel.
///
public int BitsPerPixel { get; }
+
+ internal static PixelTypeInfo Create()
+ where TPixel : struct, IPixel =>
+ new PixelTypeInfo(Unsafe.SizeOf() * 8);
}
}
diff --git a/src/ImageSharp/Formats/Png/ImageExtensions.cs b/src/ImageSharp/Formats/Png/ImageExtensions.cs
index c73ec6f57e..af56830f42 100644
--- a/src/ImageSharp/Formats/Png/ImageExtensions.cs
+++ b/src/ImageSharp/Formats/Png/ImageExtensions.cs
@@ -2,39 +2,35 @@
// Licensed under the Apache License, Version 2.0.
using System.IO;
+
using SixLabors.ImageSharp.Advanced;
-using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Png;
-using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp
{
///
- /// Extension methods for the type.
+ /// Extension methods for the type.
///
public static partial class ImageExtensions
{
///
/// Saves the image to the given stream with the png format.
///
- /// The pixel format.
/// The image this method extends.
/// The stream to save the image to.
/// Thrown if the stream is null.
- public static void SaveAsPng(this Image source, Stream stream)
- where TPixel : struct, IPixel
- => SaveAsPng(source, stream, null);
+ public static void SaveAsPng(this Image source, Stream stream) => SaveAsPng(source, stream, null);
///
/// Saves the image to the given stream with the png format.
///
- /// The pixel format.
/// The image this method extends.
/// The stream to save the image to.
/// The options for the encoder.
/// Thrown if the stream is null.
- public static void SaveAsPng(this Image source, Stream stream, PngEncoder encoder)
- where TPixel : struct, IPixel
- => source.Save(stream, encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(PngFormat.Instance));
+ public static void SaveAsPng(this Image source, Stream stream, PngEncoder encoder) =>
+ source.Save(
+ stream,
+ encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(PngFormat.Instance));
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/Formats/Png/PngDecoder.cs b/src/ImageSharp/Formats/Png/PngDecoder.cs
index 39dfb1d0bd..040da94737 100644
--- a/src/ImageSharp/Formats/Png/PngDecoder.cs
+++ b/src/ImageSharp/Formats/Png/PngDecoder.cs
@@ -59,5 +59,8 @@ namespace SixLabors.ImageSharp.Formats.Png
var decoder = new PngDecoderCore(configuration, this);
return decoder.Identify(stream);
}
+
+ ///
+ public Image Decode(Configuration configuration, Stream stream) => this.Decode(configuration, stream);
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/IImageVisitor.cs b/src/ImageSharp/IImageVisitor.cs
new file mode 100644
index 0000000000..971c4d37cb
--- /dev/null
+++ b/src/ImageSharp/IImageVisitor.cs
@@ -0,0 +1,22 @@
+// Copyright (c) Six Labors and contributors.
+// Licensed under the Apache License, Version 2.0.
+
+using SixLabors.ImageSharp.PixelFormats;
+
+namespace SixLabors.ImageSharp
+{
+ ///
+ /// A visitor to implement double-dispatch pattern in order to apply pixel-specific operations
+ /// on non-generic instances. The operation is dispatched by .
+ ///
+ internal interface IImageVisitor
+ {
+ ///
+ /// Provides a pixel-specific implementation for a given operation.
+ ///
+ /// The image.
+ /// The pixel type.
+ void Visit(Image image)
+ where TPixel : struct, IPixel;
+ }
+}
\ No newline at end of file
diff --git a/src/ImageSharp/Image.Decode.cs b/src/ImageSharp/Image.Decode.cs
index 9e83d173f2..8d0df599ea 100644
--- a/src/ImageSharp/Image.Decode.cs
+++ b/src/ImageSharp/Image.Decode.cs
@@ -14,7 +14,7 @@ namespace SixLabors.ImageSharp
///
/// Adds static methods allowing the decoding of new images.
///
- public static partial class Image
+ public abstract partial class Image
{
///
/// Creates an instance backed by an uninitialized memory buffer.
@@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp
/// The image might be filled with memory garbage.
///
/// The pixel type
- /// The
+ /// The
/// The width of the image
/// The height of the image
/// The
@@ -103,6 +103,18 @@ namespace SixLabors.ImageSharp
return (img, format);
}
+ private static (Image img, IImageFormat format) Decode(Stream stream, Configuration config)
+ {
+ IImageDecoder decoder = DiscoverDecoder(stream, config, out IImageFormat format);
+ if (decoder is null)
+ {
+ return (null, null);
+ }
+
+ Image img = decoder.Decode(config, stream);
+ return (img, format);
+ }
+
///
/// Reads the raw image information from the specified stream.
///
diff --git a/src/ImageSharp/Image.FromBytes.cs b/src/ImageSharp/Image.FromBytes.cs
index 7ceeea9498..25dc5a1e0e 100644
--- a/src/ImageSharp/Image.FromBytes.cs
+++ b/src/ImageSharp/Image.FromBytes.cs
@@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp
///
/// Adds static methods allowing the creation of new image from a byte array.
///
- public static partial class Image
+ public abstract partial class Image
{
///
/// By reading the header on the provided byte array this calculates the images format.
@@ -44,48 +44,6 @@ namespace SixLabors.ImageSharp
/// A new .
public static Image Load(byte[] data) => Load(Configuration.Default, data);
- ///
- /// Load a new instance of from the given encoded byte array.
- ///
- /// The byte array containing encoded image data.
- /// The mime type of the decoded image.
- /// A new .
- public static Image Load(byte[] data, out IImageFormat format) => Load(Configuration.Default, data, out format);
-
- ///
- /// Load a new instance of from the given encoded byte array.
- ///
- /// The config for the decoder.
- /// The byte array containing encoded image data.
- /// A new .
- public static Image Load(Configuration config, byte[] data) => Load(config, data);
-
- ///
- /// Load a new instance of from the given encoded byte array.
- ///
- /// The config for the decoder.
- /// The byte array containing image data.
- /// The mime type of the decoded image.
- /// A new .
- public static Image Load(Configuration config, byte[] data, out IImageFormat format) => Load(config, data, out format);
-
- ///
- /// Load a new instance of from the given encoded byte array.
- ///
- /// The byte array containing encoded image data.
- /// The decoder.
- /// A new .
- public static Image Load(byte[] data, IImageDecoder decoder) => Load(data, decoder);
-
- ///
- /// Load a new instance of from the given encoded byte array.
- ///
- /// The config for the decoder.
- /// The byte array containing image data.
- /// The decoder.
- /// A new .
- public static Image Load(Configuration config, byte[] data, IImageDecoder decoder) => Load(config, data, decoder);
-
///
/// Load a new instance of from the given encoded byte array.
///
@@ -117,9 +75,9 @@ namespace SixLabors.ImageSharp
public static Image Load(Configuration config, byte[] data)
where TPixel : struct, IPixel
{
- using (var steram = new MemoryStream(data))
+ using (var stream = new MemoryStream(data))
{
- return Load(config, steram);
+ return Load(config, stream);
}
}
@@ -211,29 +169,36 @@ namespace SixLabors.ImageSharp
}
///
- /// Load a new instance of from the given encoded byte span.
+ /// Load a new instance of from the given encoded byte span.
///
- /// The byte span containing image data.
- /// A new .
- public static Image Load(ReadOnlySpan data) => Load(Configuration.Default, data);
+ /// The byte span containing encoded image data.
+ /// The pixel format.
+ /// A new .
+ public static Image Load(ReadOnlySpan data)
+ where TPixel : struct, IPixel
+ => Load(Configuration.Default, data);
///
- /// Load a new instance of from the given encoded byte span.
+ /// Load a new instance of from the given encoded byte array.
///
- /// The config for the decoder.
- /// The byte span containing encoded image data.
- /// A new .
- public static Image Load(Configuration config, ReadOnlySpan data) => Load(config, data);
+ /// The byte span containing image data.
+ /// The mime type of the decoded image.
+ /// The pixel format.
+ /// A new .
+ public static Image Load(ReadOnlySpan data, out IImageFormat format)
+ where TPixel : struct, IPixel
+ => Load(Configuration.Default, data, out format);
///
- /// Load a new instance of from the given encoded byte span.
+ /// Load a new instance of from the given encoded byte array.
///
/// The byte span containing encoded image data.
+ /// The decoder.
/// The pixel format.
/// A new .
- public static Image Load(ReadOnlySpan data)
+ public static Image Load(ReadOnlySpan data, IImageDecoder decoder)
where TPixel : struct, IPixel
- => Load(Configuration.Default, data);
+ => Load(Configuration.Default, data, decoder);
///
/// Load a new instance of from the given encoded byte span.
@@ -299,5 +264,135 @@ namespace SixLabors.ImageSharp
}
}
}
+
+ ///
+ /// Load a new instance of from the given encoded byte array.
+ ///
+ /// The byte array containing image data.
+ /// The detected format.
+ /// A new .
+ public static Image Load(byte[] data, out IImageFormat format) =>
+ Load(Configuration.Default, data, out format);
+
+ ///
+ /// Load a new instance of from the given encoded byte array.
+ ///
+ /// The byte array containing encoded image data.
+ /// The decoder.
+ /// A new .
+ public static Image Load(byte[] data, IImageDecoder decoder) => Load(Configuration.Default, data, decoder);
+
+ ///
+ /// Load a new instance of from the given encoded byte array.
+ ///
+ /// The config for the decoder.
+ /// The byte array containing encoded image data.
+ /// A new .
+ public static Image Load(Configuration config, byte[] data) => Load(config, data, out _);
+
+ ///
+ /// Load a new instance of from the given encoded byte array.
+ ///
+ /// The config for the decoder.
+ /// The byte array containing image data.
+ /// The decoder.
+ /// A new .
+ public static Image Load(Configuration config, byte[] data, IImageDecoder decoder)
+ {
+ using (var stream = new MemoryStream(data))
+ {
+ return Load(config, stream, decoder);
+ }
+ }
+
+ ///
+ /// Load a new instance of from the given encoded byte array.
+ ///
+ /// The config for the decoder.
+ /// The byte array containing image data.
+ /// The mime type of the decoded image.
+ /// A new .
+ public static Image Load(Configuration config, byte[] data, out IImageFormat format)
+ {
+ using (var stream = new MemoryStream(data))
+ {
+ return Load(config, stream, out format);
+ }
+ }
+
+ ///
+ /// Load a new instance of from the given encoded byte span.
+ ///
+ /// The byte span containing image data.
+ /// A new .
+ public static Image Load(ReadOnlySpan data) => Load(Configuration.Default, data);
+
+ ///
+ /// Load a new instance of from the given encoded byte span.
+ ///
+ /// The byte span containing image data.
+ /// The decoder.
+ /// A new .
+ public static Image Load(ReadOnlySpan data, IImageDecoder decoder) =>
+ Load(Configuration.Default, data, decoder);
+
+ ///
+ /// Load a new instance of from the given encoded byte array.
+ ///
+ /// The byte span containing image data.
+ /// The detected format.
+ /// A new .
+ public static Image Load(ReadOnlySpan data, out IImageFormat format) =>
+ Load(Configuration.Default, data, out format);
+
+ ///
+ /// Decodes a new instance of from the given encoded byte span.
+ ///
+ /// The configuration options.
+ /// The byte span containing image data.
+ /// A new .
+ public static unsafe Image Load(Configuration config, ReadOnlySpan data) => Load(config, data, out _);
+
+ ///
+ /// Load a new instance of from the given encoded byte span.
+ ///
+ /// The Configuration.
+ /// The byte span containing image data.
+ /// The decoder.
+ /// A new .
+ public static unsafe Image Load(
+ Configuration config,
+ ReadOnlySpan data,
+ IImageDecoder decoder)
+ {
+ fixed (byte* ptr = &data.GetPinnableReference())
+ {
+ using (var stream = new UnmanagedMemoryStream(ptr, data.Length))
+ {
+ return Load(config, stream, decoder);
+ }
+ }
+ }
+
+ ///
+ /// Load a new instance of from the given encoded byte span.
+ ///
+ /// The configuration options.
+ /// The byte span containing image data.
+ /// The of the decoded image.>
+ /// A new .
+ public static unsafe Image Load(
+ Configuration config,
+ ReadOnlySpan data,
+ out IImageFormat format)
+ {
+ fixed (byte* ptr = &data.GetPinnableReference())
+ {
+ using (var stream = new UnmanagedMemoryStream(ptr, data.Length))
+ {
+ return Load(config, stream, out format);
+ }
+ }
+ }
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/Image.FromFile.cs b/src/ImageSharp/Image.FromFile.cs
index b13cef4824..08ed381c5a 100644
--- a/src/ImageSharp/Image.FromFile.cs
+++ b/src/ImageSharp/Image.FromFile.cs
@@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp
///
/// Adds static methods allowing the creation of new image from a given file.
///
- public static partial class Image
+ public abstract partial class Image
{
///
/// By reading the header on the provided file this calculates the images mime type.
@@ -46,7 +46,7 @@ namespace SixLabors.ImageSharp
/// Thrown if the stream is not readable nor seekable.
///
/// A new .
- public static Image Load(string path) => Load(path);
+ public static Image Load(string path) => Load(Configuration.Default, path);
///
/// Create a new instance of the class from the given file.
@@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp
/// Thrown if the stream is not readable nor seekable.
///
/// A new .
- public static Image Load(string path, out IImageFormat format) => Load(path, out format);
+ public static Image Load(string path, out IImageFormat format) => Load(Configuration.Default, path, out format);
///
/// Create a new instance of the class from the given file.
@@ -68,19 +68,7 @@ namespace SixLabors.ImageSharp
/// Thrown if the stream is not readable nor seekable.
///
/// A new .
- public static Image Load(Configuration config, string path) => Load(config, path);
-
- ///
- /// Create a new instance of the class from the given file.
- ///
- /// The config for the decoder.
- /// The file path to the image.
- /// The mime type of the decoded image.
- ///
- /// Thrown if the stream is not readable nor seekable.
- ///
- /// A new .
- public static Image Load(Configuration config, string path, out IImageFormat format) => Load(config, path, out format);
+ public static Image Load(Configuration config, string path) => Load(config, path, out _);
///
/// Create a new instance of the class from the given file.
@@ -92,7 +80,13 @@ namespace SixLabors.ImageSharp
/// Thrown if the stream is not readable nor seekable.
///
/// A new .
- public static Image Load(Configuration config, string path, IImageDecoder decoder) => Load(config, path, decoder);
+ public static Image Load(Configuration config, string path, IImageDecoder decoder)
+ {
+ using (Stream stream = config.FileSystem.OpenRead(path))
+ {
+ return Load(config, stream, decoder);
+ }
+ }
///
/// Create a new instance of the class from the given file.
@@ -103,7 +97,7 @@ namespace SixLabors.ImageSharp
/// Thrown if the stream is not readable nor seekable.
///
/// A new .
- public static Image Load(string path, IImageDecoder decoder) => Load(path, decoder);
+ public static Image Load(string path, IImageDecoder decoder) => Load(Configuration.Default, path, decoder);
///
/// Create a new instance of the class from the given file.
@@ -175,6 +169,25 @@ namespace SixLabors.ImageSharp
}
}
+ ///
+ /// Create a new instance of the class from the given file.
+ /// The pixel type is selected by the decoder.
+ ///
+ /// The configuration options.
+ /// The file path to the image.
+ /// The mime type of the decoded image.
+ ///
+ /// Thrown if the stream is not readable nor seekable.
+ ///
+ /// A new .
+ public static Image Load(Configuration config, string path, out IImageFormat format)
+ {
+ using (Stream stream = config.FileSystem.OpenRead(path))
+ {
+ return Load(config, stream, out format);
+ }
+ }
+
///
/// Create a new instance of the class from the given file.
///
diff --git a/src/ImageSharp/Image.FromStream.cs b/src/ImageSharp/Image.FromStream.cs
index 3236e00072..74b99dfb3f 100644
--- a/src/ImageSharp/Image.FromStream.cs
+++ b/src/ImageSharp/Image.FromStream.cs
@@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp
///
/// Adds static methods allowing the creation of new image from a given stream.
///
- public static partial class Image
+ public abstract partial class Image
{
///
/// By reading the header on the provided stream this calculates the images mime type.
@@ -56,50 +56,54 @@ namespace SixLabors.ImageSharp
=> WithSeekableStream(config, stream, s => InternalIdentity(s, config ?? Configuration.Default));
///
- /// Create a new instance of the class from the given stream.
+ /// Decode a new instance of the class from the given stream.
+ /// The pixel format is selected by the decoder.
///
/// The stream containing image information.
/// the mime type of the decoded image.
/// Thrown if the stream is not readable.
- /// A new .>
- public static Image Load(Stream stream, out IImageFormat format) => Load(stream, out format);
+ /// A new .>
+ public static Image Load(Stream stream, out IImageFormat format) => Load(Configuration.Default, stream, out format);
///
- /// Create a new instance of the class from the given stream.
+ /// Decode a new instance of the class from the given stream.
+ /// The pixel format is selected by the decoder.
///
/// The stream containing image information.
/// Thrown if the stream is not readable.
- /// A new .>
- public static Image Load(Stream stream) => Load(stream);
+ /// A new .>
+ public static Image Load(Stream stream) => Load(Configuration.Default, stream);
///
- /// Create a new instance of the class from the given stream.
+ /// Decode a new instance of the class from the given stream.
+ /// The pixel format is selected by the decoder.
///
/// The stream containing image information.
/// The decoder.
/// Thrown if the stream is not readable.
- /// A new .>
- public static Image Load(Stream stream, IImageDecoder decoder) => Load(stream, decoder);
+ /// A new .>
+ public static Image Load(Stream stream, IImageDecoder decoder) => Load(Configuration.Default, stream, decoder);
///
- /// Create a new instance of the class from the given stream.
+ /// Decode a new instance of the class from the given stream.
+ /// The pixel format is selected by the decoder.
///
/// The config for the decoder.
/// The stream containing image information.
+ /// The decoder.
/// Thrown if the stream is not readable.
- /// A new .>
- public static Image Load(Configuration config, Stream stream) => Load(config, stream);
+ /// A new .>
+ public static Image Load(Configuration config, Stream stream, IImageDecoder decoder) =>
+ WithSeekableStream(config, stream, s => decoder.Decode(config, s));
///
- /// Create a new instance of the class from the given stream.
+ /// Decode a new instance of the class from the given stream.
///
/// The config for the decoder.
/// The stream containing image information.
- /// the mime type of the decoded image.
/// Thrown if the stream is not readable.
- /// A new .>
- public static Image Load(Configuration config, Stream stream, out IImageFormat format)
- => Load(config, stream, out format);
+ /// A new .>
+ public static Image Load(Configuration config, Stream stream) => Load(config, stream, out _);
///
/// Create a new instance of the class from the given stream.
@@ -194,6 +198,38 @@ namespace SixLabors.ImageSharp
throw new NotSupportedException(sb.ToString());
}
+ ///
+ /// Decode a new instance of the class from the given stream.
+ /// The pixel format is selected by the decoder.
+ ///
+ /// The configuration options.
+ /// The stream containing image information.
+ /// the mime type of the decoded image.
+ /// Thrown if the stream is not readable.
+ /// A new .
+ public static Image Load(Configuration config, Stream stream, out IImageFormat format)
+ {
+ config = config ?? Configuration.Default;
+ (Image img, IImageFormat format) data = WithSeekableStream(config, stream, s => Decode(s, config));
+
+ format = data.format;
+
+ if (data.img != null)
+ {
+ return data.img;
+ }
+
+ var sb = new StringBuilder();
+ sb.AppendLine("Image cannot be loaded. Available decoders:");
+
+ foreach (KeyValuePair val in config.ImageFormatsManager.ImageDecoders)
+ {
+ sb.AppendLine($" - {val.Key.Name} : {val.Value.GetType().Name}");
+ }
+
+ throw new NotSupportedException(sb.ToString());
+ }
+
private static T WithSeekableStream(Configuration config, Stream stream, Func action)
{
if (!stream.CanRead)
diff --git a/src/ImageSharp/Image.LoadPixelData.cs b/src/ImageSharp/Image.LoadPixelData.cs
index 282f980865..eb7ce261f8 100644
--- a/src/ImageSharp/Image.LoadPixelData.cs
+++ b/src/ImageSharp/Image.LoadPixelData.cs
@@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp
///
/// Adds static methods allowing the creation of new image from raw pixel data.
///
- public static partial class Image
+ public abstract partial class Image
{
///
/// Create a new instance of the class from the raw data.
diff --git a/src/ImageSharp/Image.WrapMemory.cs b/src/ImageSharp/Image.WrapMemory.cs
index 3d788bb73a..095991b076 100644
--- a/src/ImageSharp/Image.WrapMemory.cs
+++ b/src/ImageSharp/Image.WrapMemory.cs
@@ -13,14 +13,14 @@ namespace SixLabors.ImageSharp
///
/// Adds static methods allowing wrapping an existing memory area as an image.
///
- public static partial class Image
+ public abstract partial class Image
{
///
/// Wraps an existing contiguous memory area of 'width' x 'height' pixels,
/// allowing to view/manipulate it as an ImageSharp instance.
///
/// The pixel type
- /// The
+ /// The
/// The pixel memory.
/// The width of the memory image.
/// The height of the memory image.
@@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp
/// allowing to view/manipulate it as an ImageSharp instance.
///
/// The pixel type
- /// The
+ /// The
/// The pixel memory.
/// The width of the memory image.
/// The height of the memory image.
@@ -85,7 +85,7 @@ namespace SixLabors.ImageSharp
/// It will be disposed together with the result image.
///
/// The pixel type
- /// The
+ /// The
/// The that is being transferred to the image
/// The width of the memory image.
/// The height of the memory image.
@@ -111,7 +111,7 @@ namespace SixLabors.ImageSharp
/// It will be disposed together with the result image.
///
/// The pixel type.
- /// The
+ /// The
/// The that is being transferred to the image.
/// The width of the memory image.
/// The height of the memory image.
diff --git a/src/ImageSharp/Image.cs b/src/ImageSharp/Image.cs
new file mode 100644
index 0000000000..1566fd0eed
--- /dev/null
+++ b/src/ImageSharp/Image.cs
@@ -0,0 +1,123 @@
+// Copyright (c) Six Labors and contributors.
+// Licensed under the Apache License, Version 2.0.
+
+using System.IO;
+
+using SixLabors.ImageSharp.Advanced;
+using SixLabors.ImageSharp.Formats;
+using SixLabors.ImageSharp.Metadata;
+using SixLabors.ImageSharp.PixelFormats;
+using SixLabors.Primitives;
+
+namespace SixLabors.ImageSharp
+{
+ ///
+ /// Encapsulates an image, which consists of the pixel data for a graphics image and its attributes.
+ /// For the non-generic type, the pixel type is only known at runtime.
+ /// is always implemented by a pixel-specific instance.
+ ///
+ public abstract partial class Image : IImage, IConfigurable
+ {
+ private Size size;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The .
+ /// The .
+ /// The .
+ /// The .
+ protected Image(Configuration configuration, PixelTypeInfo pixelType, ImageMetadata metadata, Size size)
+ {
+ this.Configuration = configuration ?? Configuration.Default;
+ this.PixelType = pixelType;
+ this.size = size;
+ this.Metadata = metadata ?? new ImageMetadata();
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ internal Image(
+ Configuration configuration,
+ PixelTypeInfo pixelType,
+ ImageMetadata metadata,
+ int width,
+ int height)
+ : this(configuration, pixelType, metadata, new Size(width, height))
+ {
+ }
+
+ ///
+ /// Gets the .
+ ///
+ protected Configuration Configuration { get; }
+
+ ///
+ public PixelTypeInfo PixelType { get; }
+
+ ///
+ public int Width => this.size.Width;
+
+ ///
+ public int Height => this.size.Height;
+
+ ///
+ public ImageMetadata Metadata { get; }
+
+ ///
+ /// Gets the pixel buffer.
+ ///
+ Configuration IConfigurable.Configuration => this.Configuration;
+
+ ///
+ public abstract void Dispose();
+
+ ///
+ /// Saves the image to the given stream using the given image encoder.
+ ///
+ /// The stream to save the image to.
+ /// The encoder to save the image with.
+ /// Thrown if the stream or encoder is null.
+ public void Save(Stream stream, IImageEncoder encoder)
+ {
+ Guard.NotNull(stream, nameof(stream));
+ Guard.NotNull(encoder, nameof(encoder));
+
+ EncodeVisitor visitor = new EncodeVisitor(encoder, stream);
+ this.AcceptVisitor(visitor);
+ }
+
+ ///
+ /// Accept a .
+ /// Implemented by invoking
+ /// with the pixel type of the image.
+ ///
+ internal abstract void AcceptVisitor(IImageVisitor visitor);
+
+ ///
+ /// Update the size of the image after mutation.
+ ///
+ /// The .
+ protected void UpdateSize(Size size) => this.size = size;
+
+ private class EncodeVisitor : IImageVisitor
+ {
+ private readonly IImageEncoder encoder;
+
+ private readonly Stream stream;
+
+ public EncodeVisitor(IImageEncoder encoder, Stream stream)
+ {
+ this.encoder = encoder;
+ this.stream = stream;
+ }
+
+ public void Visit(Image image)
+ where TPixel : struct, IPixel
+ {
+ this.encoder.Encode(image, this.stream);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/ImageSharp/ImageExtensions.cs b/src/ImageSharp/ImageExtensions.cs
index 5010451b8e..ec4c364d83 100644
--- a/src/ImageSharp/ImageExtensions.cs
+++ b/src/ImageSharp/ImageExtensions.cs
@@ -19,12 +19,10 @@ namespace SixLabors.ImageSharp
///
/// Writes the image to the given stream using the currently loaded image format.
///
- /// The pixel format.
/// The source image.
/// The file path to save the image to.
/// Thrown if the stream is null.
- public static void Save(this Image source, string filePath)
- where TPixel : struct, IPixel
+ public static void Save(this Image source, string filePath)
{
Guard.NotNullOrWhiteSpace(filePath, nameof(filePath));
@@ -62,13 +60,11 @@ namespace SixLabors.ImageSharp
///
/// Writes the image to the given stream using the currently loaded image format.
///
- /// The pixel format.
/// The source image.
/// The file path to save the image to.
/// The encoder to save the image with.
/// Thrown if the encoder is null.
- public static void Save(this Image source, string filePath, IImageEncoder encoder)
- where TPixel : struct, IPixel
+ public static void Save(this Image source, string filePath, IImageEncoder encoder)
{
Guard.NotNull(encoder, nameof(encoder));
using (Stream fs = source.GetConfiguration().FileSystem.Create(filePath))
@@ -80,13 +76,11 @@ namespace SixLabors.ImageSharp
///
/// Writes the image to the given stream using the currently loaded image format.
///
- /// The Pixel format.
/// The source image.
/// The stream to save the image to.
/// The format to save the image in.
/// Thrown if the stream is null.
- public static void Save(this Image source, Stream stream, IImageFormat format)
- where TPixel : struct, IPixel
+ public static void Save(this Image source, Stream stream, IImageFormat format)
{
Guard.NotNull(format, nameof(format));
IImageEncoder encoder = source.GetConfiguration().ImageFormatsManager.FindEncoder(format);
diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj
index a124ddcacd..d734648f41 100644
--- a/src/ImageSharp/ImageSharp.csproj
+++ b/src/ImageSharp/ImageSharp.csproj
@@ -10,7 +10,9 @@
$(packageversion)
0.0.1
+
netcoreapp2.1;netstandard1.3;netstandard2.0;net472
+
true
true
SixLabors.ImageSharp
diff --git a/src/ImageSharp/ImageSharp.csproj.DotSettings b/src/ImageSharp/ImageSharp.csproj.DotSettings
index a7337240a5..e446893e94 100644
--- a/src/ImageSharp/ImageSharp.csproj.DotSettings
+++ b/src/ImageSharp/ImageSharp.csproj.DotSettings
@@ -6,5 +6,6 @@
True
True
True
+ True
True
True
\ No newline at end of file
diff --git a/src/ImageSharp/Image{TPixel}.cs b/src/ImageSharp/Image{TPixel}.cs
index f2bef78e1a..27e2bc593c 100644
--- a/src/ImageSharp/Image{TPixel}.cs
+++ b/src/ImageSharp/Image{TPixel}.cs
@@ -3,26 +3,24 @@
using System;
using System.Collections.Generic;
-using System.IO;
using System.Linq;
-using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Metadata;
using SixLabors.ImageSharp.PixelFormats;
+using SixLabors.Primitives;
namespace SixLabors.ImageSharp
{
///
/// Encapsulates an image, which consists of the pixel data for a graphics image and its attributes.
+ /// For generic -s the pixel type is known at compile time.
///
/// The pixel format.
- public sealed class Image : IImage, IConfigurable
+ public sealed class Image : Image
where TPixel : struct, IPixel
{
- private readonly Configuration configuration;
-
///
/// Initializes a new instance of the class
/// with the height and the width of the image.
@@ -68,16 +66,14 @@ namespace SixLabors.ImageSharp
/// The height of the image in pixels.
/// The images metadata.
internal Image(Configuration configuration, int width, int height, ImageMetadata metadata)
+ : base(configuration, PixelTypeInfo.Create(), metadata, width, height)
{
- this.configuration = configuration ?? Configuration.Default;
- this.PixelType = new PixelTypeInfo(Unsafe.SizeOf() * 8);
- this.Metadata = metadata ?? new ImageMetadata();
this.Frames = new ImageFrameCollection(this, width, height, default(TPixel));
}
///
/// Initializes a new instance of the class
- /// wrapping an external
+ /// wrapping an external .
///
/// The configuration providing initialization code which allows extending the library.
/// The memory source.
@@ -85,10 +81,8 @@ namespace SixLabors.ImageSharp
/// The height of the image in pixels.
/// The images metadata.
internal Image(Configuration configuration, MemorySource memorySource, int width, int height, ImageMetadata metadata)
+ : base(configuration, PixelTypeInfo.Create(), metadata, width, height)
{
- this.configuration = configuration;
- this.PixelType = new PixelTypeInfo(Unsafe.SizeOf() * 8);
- this.Metadata = metadata;
this.Frames = new ImageFrameCollection(this, width, height, memorySource);
}
@@ -102,10 +96,8 @@ namespace SixLabors.ImageSharp
/// The color to initialize the pixels with.
/// The images metadata.
internal Image(Configuration configuration, int width, int height, TPixel backgroundColor, ImageMetadata metadata)
+ : base(configuration, PixelTypeInfo.Create(), metadata, width, height)
{
- this.configuration = configuration ?? Configuration.Default;
- this.PixelType = new PixelTypeInfo(Unsafe.SizeOf() * 8);
- this.Metadata = metadata ?? new ImageMetadata();
this.Frames = new ImageFrameCollection(this, width, height, backgroundColor);
}
@@ -117,31 +109,11 @@ namespace SixLabors.ImageSharp
/// The images metadata.
/// The frames that will be owned by this image instance.
internal Image(Configuration configuration, ImageMetadata metadata, IEnumerable> frames)
+ : base(configuration, PixelTypeInfo.Create(), metadata, ValidateFramesAndGetSize(frames))
{
- this.configuration = configuration ?? Configuration.Default;
- this.PixelType = new PixelTypeInfo(Unsafe.SizeOf() * 8);
- this.Metadata = metadata ?? new ImageMetadata();
-
this.Frames = new ImageFrameCollection(this, frames);
}
- ///
- /// Gets the pixel buffer.
- ///
- Configuration IConfigurable.Configuration => this.configuration;
-
- ///
- public PixelTypeInfo PixelType { get; }
-
- ///
- public int Width => this.Frames.RootFrame.Width;
-
- ///
- public int Height => this.Frames.RootFrame.Height;
-
- ///
- public ImageMetadata Metadata { get; }
-
///
/// Gets the frames.
///
@@ -161,29 +133,14 @@ namespace SixLabors.ImageSharp
public TPixel this[int x, int y]
{
get => this.PixelSource.PixelBuffer[x, y];
-
set => this.PixelSource.PixelBuffer[x, y] = value;
}
- ///
- /// Saves the image to the given stream using the given image encoder.
- ///
- /// The stream to save the image to.
- /// The encoder to save the image with.
- /// Thrown if the stream or encoder is null.
- public void Save(Stream stream, IImageEncoder encoder)
- {
- Guard.NotNull(stream, nameof(stream));
- Guard.NotNull(encoder, nameof(encoder));
-
- encoder.Encode(this, stream);
- }
-
///
/// Clones the current image
///
/// Returns a new image with all the same metadata as the original.
- public Image Clone() => this.Clone(this.configuration);
+ public Image Clone() => this.Clone(this.Configuration);
///
/// Clones the current image with the given configuration.
@@ -202,14 +159,14 @@ namespace SixLabors.ImageSharp
/// The pixel format.
/// The
public Image CloneAs()
- where TPixel2 : struct, IPixel => this.CloneAs(this.configuration);
+ where TPixel2 : struct, IPixel => this.CloneAs(this.Configuration);
///
/// Returns a copy of the image in the given pixel format.
///
/// The pixel format.
/// The configuration providing initialization code which allows extending the library.
- /// The
+ /// The .
public Image CloneAs(Configuration configuration)
where TPixel2 : struct, IPixel
{
@@ -218,7 +175,13 @@ namespace SixLabors.ImageSharp
}
///
- public void Dispose() => this.Frames.Dispose();
+ public override void Dispose() => this.Frames.Dispose();
+
+ ///
+ internal override void AcceptVisitor(IImageVisitor visitor)
+ {
+ visitor.Visit(this);
+ }
///
public override string ToString() => $"Image<{typeof(TPixel).Name}>: {this.Width}x{this.Height}";
@@ -235,6 +198,29 @@ namespace SixLabors.ImageSharp
{
this.Frames[i].SwapOrCopyPixelsBufferFrom(pixelSource.Frames[i]);
}
+
+ this.UpdateSize(pixelSource.Size());
+ }
+
+ private static Size ValidateFramesAndGetSize(IEnumerable> frames)
+ {
+ Guard.NotNull(frames, nameof(frames));
+
+ ImageFrame rootFrame = frames.FirstOrDefault();
+
+ if (rootFrame == null)
+ {
+ throw new ArgumentException("Must not be empty.", nameof(frames));
+ }
+
+ Size rootSize = rootFrame.Size();
+
+ if (frames.Any(f => f.Size() != rootSize))
+ {
+ throw new ArgumentException("The provided frames must be of the same size.", nameof(frames));
+ }
+
+ return rootSize;
}
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/Processing/AutoOrientExtensions.cs b/src/ImageSharp/Processing/AutoOrientExtensions.cs
index d11fc96237..a831e2d9af 100644
--- a/src/ImageSharp/Processing/AutoOrientExtensions.cs
+++ b/src/ImageSharp/Processing/AutoOrientExtensions.cs
@@ -7,18 +7,17 @@ using SixLabors.ImageSharp.Processing.Processors.Transforms;
namespace SixLabors.ImageSharp.Processing
{
///
- /// Adds extensions that allow the application of auto-orientation operations to the type.
+ /// Defines extensions that allow the application of auto-orientation operations to an
+ /// using Mutate/Clone.
///
public static class AutoOrientExtensions
{
///
/// Adjusts an image so that its orientation is suitable for viewing. Adjustments are based on EXIF metadata embedded in the image.
///
- /// The pixel format.
/// The image to auto rotate.
- /// The
- public static IImageProcessingContext AutoOrient(this IImageProcessingContext source)
- where TPixel : struct, IPixel
- => source.ApplyProcessor(new AutoOrientProcessor());
+ /// The to allow chaining of operations.
+ public static IImageProcessingContext AutoOrient(this IImageProcessingContext source)
+ => source.ApplyProcessor(new AutoOrientProcessor());
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/Processing/BackgroundColorExtensions.cs b/src/ImageSharp/Processing/BackgroundColorExtensions.cs
index 1ad2c92371..3b794e3351 100644
--- a/src/ImageSharp/Processing/BackgroundColorExtensions.cs
+++ b/src/ImageSharp/Processing/BackgroundColorExtensions.cs
@@ -8,7 +8,8 @@ using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing
{
///
- /// Adds extensions that allow the application of a background color to the type.
+ /// Defines extension methods to replace the background color of an
+ /// using Mutate/Clone.
///
public static class BackgroundColorExtensions
{
diff --git a/src/ImageSharp/Processing/BinaryDiffuseExtensions.cs b/src/ImageSharp/Processing/BinaryDiffuseExtensions.cs
index 788942dde4..487b64e1c4 100644
--- a/src/ImageSharp/Processing/BinaryDiffuseExtensions.cs
+++ b/src/ImageSharp/Processing/BinaryDiffuseExtensions.cs
@@ -9,7 +9,8 @@ using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing
{
///
- /// Adds binary diffusion extensions to the type.
+ /// Defines extension methods to apply binary diffusion on an
+ /// using Mutate/Clone.
///
public static class BinaryDiffuseExtensions
{
@@ -20,7 +21,7 @@ namespace SixLabors.ImageSharp.Processing
/// The image this method extends.
/// The diffusion algorithm to apply.
/// The threshold to apply binarization of the image. Must be between 0 and 1.
- /// The .
+ /// The to allow chaining of operations.
public static IImageProcessingContext BinaryDiffuse(this IImageProcessingContext source, IErrorDiffuser diffuser, float threshold)
where TPixel : struct, IPixel
=> source.ApplyProcessor(new BinaryErrorDiffusionProcessor(diffuser, threshold));
@@ -35,7 +36,7 @@ namespace SixLabors.ImageSharp.Processing
///
/// The structure that specifies the portion of the image object to alter.
///
- /// The .
+ /// The to allow chaining of operations.
public static IImageProcessingContext BinaryDiffuse(this IImageProcessingContext source, IErrorDiffuser diffuser, float threshold, Rectangle rectangle)
where TPixel : struct, IPixel
=> source.ApplyProcessor(new BinaryErrorDiffusionProcessor(diffuser, threshold), rectangle);
@@ -49,7 +50,7 @@ namespace SixLabors.ImageSharp.Processing
/// The threshold to apply binarization of the image. Must be between 0 and 1.
/// The color to use for pixels that are above the threshold.
/// The color to use for pixels that are below the threshold
- /// The .
+ /// The to allow chaining of operations.
public static IImageProcessingContext BinaryDiffuse(this IImageProcessingContext source, IErrorDiffuser diffuser, float threshold, TPixel upperColor, TPixel lowerColor)
where TPixel : struct, IPixel
=> source.ApplyProcessor(new BinaryErrorDiffusionProcessor(diffuser, threshold, upperColor, lowerColor));
@@ -66,7 +67,7 @@ namespace SixLabors.ImageSharp.Processing
///
/// The structure that specifies the portion of the image object to alter.
///
- /// The .
+ /// The to allow chaining of operations.
public static IImageProcessingContext BinaryDiffuse(this IImageProcessingContext source, IErrorDiffuser diffuser, float threshold, TPixel upperColor, TPixel lowerColor, Rectangle rectangle)
where TPixel : struct, IPixel
=> source.ApplyProcessor(new BinaryErrorDiffusionProcessor(diffuser, threshold, upperColor, lowerColor), rectangle);
diff --git a/src/ImageSharp/Processing/BinaryDitherExtensions.cs b/src/ImageSharp/Processing/BinaryDitherExtensions.cs
index 6177701964..d8843dafac 100644
--- a/src/ImageSharp/Processing/BinaryDitherExtensions.cs
+++ b/src/ImageSharp/Processing/BinaryDitherExtensions.cs
@@ -9,7 +9,8 @@ using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing
{
///
- /// Adds binary dithering extensions to the type.
+ /// Defines extensions to apply binary dithering on an
+ /// using Mutate/Clone.
///
public static class BinaryDitherExtensions
{
@@ -19,7 +20,7 @@ namespace SixLabors.ImageSharp.Processing
/// The pixel format.
/// The image this method extends.
/// The ordered ditherer.
- /// The .
+ /// The to allow chaining of operations.
public static IImageProcessingContext BinaryDither(this IImageProcessingContext source, IOrderedDither dither)
where TPixel : struct, IPixel
=> source.ApplyProcessor(new BinaryOrderedDitherProcessor(dither));
@@ -32,7 +33,7 @@ namespace SixLabors.ImageSharp.Processing
/// The ordered ditherer.
/// The color to use for pixels that are above the threshold.
/// The color to use for pixels that are below the threshold
- /// The .
+ /// The to allow chaining of operations.
public static IImageProcessingContext BinaryDither(this IImageProcessingContext source, IOrderedDither dither, TPixel upperColor, TPixel lowerColor)
where TPixel : struct, IPixel
=> source.ApplyProcessor(new BinaryOrderedDitherProcessor(dither, upperColor, lowerColor));
@@ -46,7 +47,7 @@ namespace SixLabors.ImageSharp.Processing
///
/// The structure that specifies the portion of the image object to alter.
///
- /// The .
+ /// The to allow chaining of operations.
public static IImageProcessingContext BinaryDither(this IImageProcessingContext source, IOrderedDither dither, Rectangle rectangle)
where TPixel : struct, IPixel
=> source.ApplyProcessor(new BinaryOrderedDitherProcessor(dither), rectangle);
@@ -62,7 +63,7 @@ namespace SixLabors.ImageSharp.Processing
///
/// The structure that specifies the portion of the image object to alter.
///
- /// The .
+ /// The to allow chaining of operations.
public static IImageProcessingContext BinaryDither(this IImageProcessingContext source, IOrderedDither dither, TPixel upperColor, TPixel lowerColor, Rectangle rectangle)
where TPixel : struct, IPixel
=> source.ApplyProcessor(new BinaryOrderedDitherProcessor(dither, upperColor, lowerColor), rectangle);
diff --git a/src/ImageSharp/Processing/BinaryThresholdExtensions.cs b/src/ImageSharp/Processing/BinaryThresholdExtensions.cs
index 31f81ba4b1..aecb784848 100644
--- a/src/ImageSharp/Processing/BinaryThresholdExtensions.cs
+++ b/src/ImageSharp/Processing/BinaryThresholdExtensions.cs
@@ -8,7 +8,8 @@ using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing
{
///
- /// Adds binary thresholding extensions to the type.
+ /// Defines extension methods to apply binary thresholding on an
+ /// using Mutate/Clone.
///
public static class BinaryThresholdExtensions
{
@@ -18,7 +19,7 @@ namespace SixLabors.ImageSharp.Processing
/// The pixel format.
/// The image this method extends.
/// The threshold to apply binarization of the image. Must be between 0 and 1.
- /// The .
+ /// The to allow chaining of operations.
public static IImageProcessingContext BinaryThreshold(this IImageProcessingContext source, float threshold)
where TPixel : struct, IPixel
=> source.ApplyProcessor(new BinaryThresholdProcessor(threshold));
@@ -32,7 +33,7 @@ namespace SixLabors.ImageSharp.Processing
///
/// The structure that specifies the portion of the image object to alter.
///
- /// The .
+ /// The to allow chaining of operations.
public static IImageProcessingContext BinaryThreshold(this IImageProcessingContext source, float threshold, Rectangle rectangle)
where TPixel : struct, IPixel
=> source.ApplyProcessor(new BinaryThresholdProcessor(threshold), rectangle);
@@ -45,7 +46,7 @@ namespace SixLabors.ImageSharp.Processing
/// The threshold to apply binarization of the image. Must be between 0 and 1.
/// The color to use for pixels that are above the threshold.
/// The color to use for pixels that are below the threshold
- /// The .
+ /// The to allow chaining of operations.
public static IImageProcessingContext BinaryThreshold(this IImageProcessingContext source, float threshold, TPixel upperColor, TPixel lowerColor)
where TPixel : struct, IPixel
=> source.ApplyProcessor(new BinaryThresholdProcessor(threshold, upperColor, lowerColor));
@@ -61,7 +62,7 @@ namespace SixLabors.ImageSharp.Processing
///
/// The structure that specifies the portion of the image object to alter.
///
- /// The .
+ /// The to allow chaining of operations.
public static IImageProcessingContext BinaryThreshold(this IImageProcessingContext source, float threshold, TPixel upperColor, TPixel lowerColor, Rectangle rectangle)
where TPixel : struct, IPixel
=> source.ApplyProcessor(new BinaryThresholdProcessor(threshold, upperColor, lowerColor), rectangle);
diff --git a/src/ImageSharp/Processing/BlackWhiteExtensions.cs b/src/ImageSharp/Processing/BlackWhiteExtensions.cs
index 0484fa84e1..ee34cd99e2 100644
--- a/src/ImageSharp/Processing/BlackWhiteExtensions.cs
+++ b/src/ImageSharp/Processing/BlackWhiteExtensions.cs
@@ -8,31 +8,28 @@ using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing
{
///
- /// Adds extensions that allow the application of black and white toning to the type.
+ /// Defines extension methods that allow the application of black and white toning to an
+ /// using Mutate/Clone.
///
public static class BlackWhiteExtensions
{
///
/// Applies black and white toning to the image.
///
- /// The pixel format.
/// The image this method extends.
- /// The .
- public static IImageProcessingContext BlackWhite(this IImageProcessingContext source)
- where TPixel : struct, IPixel
- => source.ApplyProcessor(new BlackWhiteProcessor());
+ /// The to allow chaining of operations.
+ public static IImageProcessingContext BlackWhite(this IImageProcessingContext source)
+ => source.ApplyProcessor(new BlackWhiteProcessor());
///
/// Applies black and white toning to the image.
///
- /// The pixel format.
/// The image this method extends.
///
/// The structure that specifies the portion of the image object to alter.
///
- /// The .
- public static IImageProcessingContext BlackWhite(this IImageProcessingContext source, Rectangle rectangle)
- where TPixel : struct, IPixel
- => source.ApplyProcessor(new BlackWhiteProcessor(), rectangle);
+ /// The to allow chaining of operations.
+ public static IImageProcessingContext BlackWhite(this IImageProcessingContext source, Rectangle rectangle)
+ => source.ApplyProcessor(new BlackWhiteProcessor(), rectangle);
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/Processing/BoxBlurExtensions.cs b/src/ImageSharp/Processing/BoxBlurExtensions.cs
index 624da239bb..f3400c24e6 100644
--- a/src/ImageSharp/Processing/BoxBlurExtensions.cs
+++ b/src/ImageSharp/Processing/BoxBlurExtensions.cs
@@ -8,43 +8,38 @@ using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing
{
///
- /// Adds box blurring extensions to the type.
+ /// Defines extensions methods to apply box blurring to an
+ /// using Mutate/Clone.
///
public static class BoxBlurExtensions
{
///
/// Applies a box blur to the image.
///
- /// The pixel format.
/// The image this method extends.
- /// The .
- public static IImageProcessingContext BoxBlur(this IImageProcessingContext source)
- where TPixel : struct, IPixel
- => source.ApplyProcessor(new BoxBlurProcessor());
+ /// The to allow chaining of operations.
+ public static IImageProcessingContext BoxBlur(this IImageProcessingContext source)
+ => source.ApplyProcessor(new BoxBlurProcessor());
///
/// Applies a box blur to the image.
///
- /// The pixel format.
/// The image this method extends.
/// The 'radius' value representing the size of the area to sample.
- /// The .
- public static IImageProcessingContext BoxBlur(this IImageProcessingContext source, int radius)
- where TPixel : struct, IPixel
- => source.ApplyProcessor(new BoxBlurProcessor(radius));
+ /// The to allow chaining of operations.
+ public static IImageProcessingContext BoxBlur(this IImageProcessingContext source, int radius)
+ => source.ApplyProcessor(new BoxBlurProcessor(radius));
///
/// Applies a box blur to the image.
///
- /// The pixel format.
/// The image this method extends.
/// The 'radius' value representing the size of the area to sample.
///
/// The structure that specifies the portion of the image object to alter.
///
- /// The .
- public static IImageProcessingContext BoxBlur(this IImageProcessingContext source, int radius, Rectangle rectangle)
- where TPixel : struct, IPixel
- => source.ApplyProcessor(new BoxBlurProcessor(radius), rectangle);
+ /// The to allow chaining of operations.
+ public static IImageProcessingContext BoxBlur(this IImageProcessingContext source, int radius, Rectangle rectangle)
+ => source.ApplyProcessor(new BoxBlurProcessor(radius), rectangle);
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/Processing/BrightnessExtensions.cs b/src/ImageSharp/Processing/BrightnessExtensions.cs
index 2f252ad305..db84091763 100644
--- a/src/ImageSharp/Processing/BrightnessExtensions.cs
+++ b/src/ImageSharp/Processing/BrightnessExtensions.cs
@@ -8,7 +8,8 @@ using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing
{
///
- /// Adds extensions that allow the alteration of the brightness component to the type.
+ /// Defines extensions that allow the alteration of the brightness component of an
+ /// using Mutate/Clone.
///
public static class BrightnessExtensions
{
@@ -19,13 +20,11 @@ namespace SixLabors.ImageSharp.Processing
/// A value of 0 will create an image that is completely black. A value of 1 leaves the input unchanged.
/// Other values are linear multipliers on the effect. Values of an amount over 1 are allowed, providing brighter results.
///
- /// The pixel format.
/// The image this method extends.
/// The proportion of the conversion. Must be greater than or equal to 0.
- /// The .
- public static IImageProcessingContext Brightness(this IImageProcessingContext source, float amount)
- where TPixel : struct, IPixel
- => source.ApplyProcessor(new BrightnessProcessor(amount));
+ /// The to allow chaining of operations.
+ public static IImageProcessingContext Brightness(this IImageProcessingContext source, float amount)
+ => source.ApplyProcessor(new BrightnessProcessor(amount));
///
/// Alters the brightness component of the image.
@@ -34,15 +33,13 @@ namespace SixLabors.ImageSharp.Processing
/// A value of 0 will create an image that is completely black. A value of 1 leaves the input unchanged.
/// Other values are linear multipliers on the effect. Values of an amount over 1 are allowed, providing brighter results.
///
- /// The pixel format.
/// The image this method extends.
/// The proportion of the conversion. Must be greater than or equal to 0.
///
/// The structure that specifies the portion of the image object to alter.
///
- /// The .
- public static IImageProcessingContext Brightness(this IImageProcessingContext source, float amount, Rectangle rectangle)
- where TPixel : struct, IPixel
- => source.ApplyProcessor(new BrightnessProcessor