From dab682e47a56805a971022d18dd6ee7f52d32c2b Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Fri, 5 May 2017 20:45:44 +1000 Subject: [PATCH] Add Rgba32 specific overloads --- README.md | 4 +- src/ImageSharp/Image/Image.Create.cs | 2 +- src/ImageSharp/Image/Image.Decode.cs | 2 +- src/ImageSharp/Image/Image.FromBytes.cs | 51 +++++++++++++++++- src/ImageSharp/Image/Image.FromFile.cs | 69 +++++++++++++++++++++++- src/ImageSharp/Image/Image.FromStream.cs | 57 +++++++++++++++++++- 6 files changed, 179 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e683fa2524..ca24275469 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,8 @@ Here's an example of the code required to resize an image using the default Bicu On platforms supporting netstandard 1.3+ ```csharp -using (Image image = Image.Load("foo.jpg")) +// Image.Load(string path) is a shortcut for our default type. Other pixel formats use Image.Load(string path)) +using (Image image = Image.Load("foo.jpg")) { image.Resize(image.Width / 2, image.Height / 2) .Grayscale() @@ -94,6 +95,7 @@ using (Image image = Image.Load("foo.jpg")) ``` on netstandard 1.1 - 1.2 ```csharp +// Image.Load(Stream stream) is a shortcut for our default type. Other pixel formats use Image.Load(Stream stream)) using (FileStream stream = File.OpenRead("foo.jpg")) using (FileStream output = File.OpenWrite("bar.jpg")) using (Image image = Image.Load(stream)) diff --git a/src/ImageSharp/Image/Image.Create.cs b/src/ImageSharp/Image/Image.Create.cs index 6a5762cc91..e251167ec7 100644 --- a/src/ImageSharp/Image/Image.Create.cs +++ b/src/ImageSharp/Image/Image.Create.cs @@ -10,7 +10,7 @@ namespace ImageSharp /// /// Adds static methods allowing the creation of new images from given dimensions. /// - public partial class Image + public sealed partial class Image { /// /// Create a new instance of the class with the given height and the width. diff --git a/src/ImageSharp/Image/Image.Decode.cs b/src/ImageSharp/Image/Image.Decode.cs index 2497401186..df839e9fe9 100644 --- a/src/ImageSharp/Image/Image.Decode.cs +++ b/src/ImageSharp/Image/Image.Decode.cs @@ -15,7 +15,7 @@ namespace ImageSharp /// /// Adds static methods allowing the decoding of new images. /// - public partial class Image + public sealed partial class Image { /// /// By reading the header on the provided stream this calculates the images format. diff --git a/src/ImageSharp/Image/Image.FromBytes.cs b/src/ImageSharp/Image/Image.FromBytes.cs index 0cc05c2667..7895429a3b 100644 --- a/src/ImageSharp/Image/Image.FromBytes.cs +++ b/src/ImageSharp/Image/Image.FromBytes.cs @@ -13,8 +13,57 @@ namespace ImageSharp /// /// Adds static methods allowing the creation of new image from a byte array. /// - public partial class Image + public sealed partial class Image { + /// + /// Create a new instance of the class from the given byte array. + /// + /// The byte array containing image data. + /// A new . + public static Image Load(byte[] data) => Load(null, data, null); + + /// + /// Create a new instance of the class from the given byte array. + /// + /// The byte array containing image data. + /// The options for the decoder. + /// A new . + public static Image Load(byte[] data, IDecoderOptions options) => Load(null, data, options); + + /// + /// Create a new instance of the class from the given byte array. + /// + /// The config for the decoder. + /// The byte array containing image data. + /// A new . + public static Image Load(Configuration config, byte[] data) => Load(config, data, null); + + /// + /// Create a new instance of the class from the given byte array. + /// + /// The byte array containing image data. + /// The decoder. + /// A new . + public static Image Load(byte[] data, IImageDecoder decoder) => Load(data, decoder, null); + + /// + /// Create a new instance of the class from the given byte array. + /// + /// The configuration options. + /// The byte array containing image data. + /// The options for the decoder. + /// A new . + public static Image Load(Configuration config, byte[] data, IDecoderOptions options) => Load(config, data, options); + + /// + /// Create a new instance of the class from the given byte array. + /// + /// The byte array containing image data. + /// The decoder. + /// The options for the decoder. + /// A new . + public static Image Load(byte[] data, IImageDecoder decoder, IDecoderOptions options) => Load(data, decoder, options); + /// /// Create a new instance of the class from the given byte array. /// diff --git a/src/ImageSharp/Image/Image.FromFile.cs b/src/ImageSharp/Image/Image.FromFile.cs index 2dcb26bdb0..e7014fe49a 100644 --- a/src/ImageSharp/Image/Image.FromFile.cs +++ b/src/ImageSharp/Image/Image.FromFile.cs @@ -14,8 +14,75 @@ namespace ImageSharp /// /// Adds static methods allowing the creation of new image from a given file. /// - public partial class Image + public sealed partial class Image { + /// + /// Create a new instance of the class from the given file. + /// + /// The file path to the image. + /// + /// Thrown if the stream is not readable nor seekable. + /// + /// A new . + public static Image Load(string path) => Load(path); + + /// + /// Create a new instance of the class from the given file. + /// + /// The file path to the image. + /// The options for the decoder. + /// + /// Thrown if the stream is not readable nor seekable. + /// + /// A new . + public static Image Load(string path, IDecoderOptions options) => Load(path, options); + + /// + /// Create a new instance of the class from the given file. + /// + /// The config for the decoder. + /// The file path to the image. + /// + /// 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 file path to the image. + /// The decoder. + /// + /// Thrown if the stream is not readable nor seekable. + /// + /// A new . + public static Image Load(string path, IImageDecoder decoder) => Load(path, decoder); + + /// + /// Create a new instance of the class from the given file. + /// + /// The configuration options. + /// The file path to the image. + /// The options for the decoder. + /// + /// Thrown if the stream is not readable nor seekable. + /// + /// A new . + public static Image Load(Configuration config, string path, IDecoderOptions options) => Load(config, path, options); + + /// + /// Create a new instance of the class from the given file. + /// + /// The file path to the image. + /// The decoder. + /// The options for the decoder. + /// + /// Thrown if the stream is not readable nor seekable. + /// + /// A new . + public static Image Load(string path, IImageDecoder decoder, IDecoderOptions options) => Load(path, decoder, options); + /// /// Create a new instance of the class from the given file. /// diff --git a/src/ImageSharp/Image/Image.FromStream.cs b/src/ImageSharp/Image/Image.FromStream.cs index a120346a12..c27762096f 100644 --- a/src/ImageSharp/Image/Image.FromStream.cs +++ b/src/ImageSharp/Image/Image.FromStream.cs @@ -15,8 +15,63 @@ namespace ImageSharp /// /// Adds static methods allowing the creation of new image from a given stream. /// - public partial class Image + public sealed partial class Image { + /// + /// Create a new instance of the class from the given stream. + /// + /// The stream containing image information. + /// + /// Thrown if the stream is not readable nor seekable. + /// + /// A new .> + public static Image Load(Stream stream) => Load(stream); + + /// + /// Create a new instance of the class from the given stream. + /// + /// The stream containing image information. + /// The options for the decoder. + /// + /// Thrown if the stream is not readable nor seekable. + /// + /// A new .> + public static Image Load(Stream stream, IDecoderOptions options) => Load(stream, options); + + /// + /// Create a new instance of the class from the given stream. + /// + /// The stream containing image information. + /// The decoder. + /// + /// Thrown if the stream is not readable nor seekable. + /// + /// A new .> + public static Image Load(Stream stream, IImageDecoder decoder) => Load(stream, decoder); + + /// + /// Create a new instance of the class from the given stream. + /// + /// The config for the decoder. + /// The stream containing image information. + /// + /// Thrown if the stream is not readable nor seekable. + /// + /// A new .> + public static Image Load(Configuration config, Stream stream) => Load(config, stream); + + /// + /// Create a new instance of the class from the given stream. + /// + /// The stream containing image information. + /// The decoder. + /// The options for the decoder. + /// + /// Thrown if the stream is not readable nor seekable. + /// + /// A new .> + public static Image Load(Stream stream, IImageDecoder decoder, IDecoderOptions options) => Load(stream, decoder, options); + /// /// Create a new instance of the class from the given stream. ///