diff --git a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs index 19d6334e3..c5abbda61 100644 --- a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs +++ b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs @@ -76,7 +76,7 @@ namespace SixLabors.ImageSharp.Advanced /// The image visitor. /// The token to monitor for cancellation requests. /// A representing the asynchronous operation. - public static Task AcceptVisitorAsync(this Image source, IImageVisitorAsync visitor, CancellationToken cancellationToken) + public static Task AcceptVisitorAsync(this Image source, IImageVisitorAsync visitor, CancellationToken cancellationToken = default) => source.AcceptAsync(visitor, cancellationToken); /// diff --git a/src/ImageSharp/Formats/ImageExtesions.Save.cs b/src/ImageSharp/Formats/ImageExtesions.Save.cs index a48007d4b..075c708b6 100644 --- a/src/ImageSharp/Formats/ImageExtesions.Save.cs +++ b/src/ImageSharp/Formats/ImageExtesions.Save.cs @@ -60,17 +60,6 @@ namespace SixLabors.ImageSharp path, encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(BmpFormat.Instance)); - /// - /// Saves the image to the given stream with the Bmp format. - /// - /// The image this method extends. - /// The file path to save the image to. - /// The encoder to save the image with. - /// Thrown if the path is null. - /// A representing the asynchronous operation. - public static Task SaveAsBmpAsync(this Image source, string path, BmpEncoder encoder) - => SaveAsBmpAsync(source, path, encoder, default); - /// /// Saves the image to the given stream with the Bmp format. /// @@ -80,7 +69,7 @@ namespace SixLabors.ImageSharp /// The token to monitor for cancellation requests. /// Thrown if the path is null. /// A representing the asynchronous operation. - public static Task SaveAsBmpAsync(this Image source, string path, BmpEncoder encoder, CancellationToken cancellationToken) => + public static Task SaveAsBmpAsync(this Image source, string path, BmpEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( path, encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(BmpFormat.Instance), @@ -95,15 +84,6 @@ namespace SixLabors.ImageSharp public static void SaveAsBmp(this Image source, Stream stream) => SaveAsBmp(source, stream, null); - /// - /// Saves the image to the given stream with the Bmp format. - /// - /// The image this method extends. - /// The stream to save the image to. - /// Thrown if the stream is null. - /// A representing the asynchronous operation. - public static Task SaveAsBmpAsync(this Image source, Stream stream) => SaveAsBmpAsync(source, stream, null); - /// /// Saves the image to the given stream with the Bmp format. /// @@ -112,7 +92,7 @@ namespace SixLabors.ImageSharp /// The token to monitor for cancellation requests. /// Thrown if the stream is null. /// A representing the asynchronous operation. - public static Task SaveAsBmpAsync(this Image source, Stream stream, CancellationToken cancellationToken) + public static Task SaveAsBmpAsync(this Image source, Stream stream, CancellationToken cancellationToken = default) => SaveAsBmpAsync(source, stream, null, cancellationToken); /// @@ -128,17 +108,6 @@ namespace SixLabors.ImageSharp stream, encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(BmpFormat.Instance)); - /// - /// Saves the image to the given stream with the Bmp 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. - /// A representing the asynchronous operation. - public static Task SaveAsBmpAsync(this Image source, Stream stream, BmpEncoder encoder) - => SaveAsBmpAsync(source, stream, encoder, default); - /// /// Saves the image to the given stream with the Bmp format. /// @@ -148,7 +117,7 @@ namespace SixLabors.ImageSharp /// The token to monitor for cancellation requests. /// Thrown if the stream is null. /// A representing the asynchronous operation. - public static Task SaveAsBmpAsync(this Image source, Stream stream, BmpEncoder encoder, CancellationToken cancellationToken) => + public static Task SaveAsBmpAsync(this Image source, Stream stream, BmpEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( stream, encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(BmpFormat.Instance), @@ -194,17 +163,6 @@ namespace SixLabors.ImageSharp path, encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(GifFormat.Instance)); - /// - /// Saves the image to the given stream with the Gif format. - /// - /// The image this method extends. - /// The file path to save the image to. - /// The encoder to save the image with. - /// Thrown if the path is null. - /// A representing the asynchronous operation. - public static Task SaveAsGifAsync(this Image source, string path, GifEncoder encoder) - => SaveAsGifAsync(source, path, encoder, default); - /// /// Saves the image to the given stream with the Gif format. /// @@ -214,7 +172,7 @@ namespace SixLabors.ImageSharp /// The token to monitor for cancellation requests. /// Thrown if the path is null. /// A representing the asynchronous operation. - public static Task SaveAsGifAsync(this Image source, string path, GifEncoder encoder, CancellationToken cancellationToken) => + public static Task SaveAsGifAsync(this Image source, string path, GifEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( path, encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(GifFormat.Instance), @@ -229,15 +187,6 @@ namespace SixLabors.ImageSharp public static void SaveAsGif(this Image source, Stream stream) => SaveAsGif(source, stream, null); - /// - /// Saves the image to the given stream with the Gif format. - /// - /// The image this method extends. - /// The stream to save the image to. - /// Thrown if the stream is null. - /// A representing the asynchronous operation. - public static Task SaveAsGifAsync(this Image source, Stream stream) => SaveAsGifAsync(source, stream, null); - /// /// Saves the image to the given stream with the Gif format. /// @@ -246,7 +195,7 @@ namespace SixLabors.ImageSharp /// The token to monitor for cancellation requests. /// Thrown if the stream is null. /// A representing the asynchronous operation. - public static Task SaveAsGifAsync(this Image source, Stream stream, CancellationToken cancellationToken) + public static Task SaveAsGifAsync(this Image source, Stream stream, CancellationToken cancellationToken = default) => SaveAsGifAsync(source, stream, null, cancellationToken); /// @@ -262,17 +211,6 @@ namespace SixLabors.ImageSharp stream, encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(GifFormat.Instance)); - /// - /// Saves the image to the given stream with the Gif 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. - /// A representing the asynchronous operation. - public static Task SaveAsGifAsync(this Image source, Stream stream, GifEncoder encoder) - => SaveAsGifAsync(source, stream, encoder, default); - /// /// Saves the image to the given stream with the Gif format. /// @@ -282,7 +220,7 @@ namespace SixLabors.ImageSharp /// The token to monitor for cancellation requests. /// Thrown if the stream is null. /// A representing the asynchronous operation. - public static Task SaveAsGifAsync(this Image source, Stream stream, GifEncoder encoder, CancellationToken cancellationToken) => + public static Task SaveAsGifAsync(this Image source, Stream stream, GifEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( stream, encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(GifFormat.Instance), @@ -328,17 +266,6 @@ namespace SixLabors.ImageSharp path, encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(JpegFormat.Instance)); - /// - /// Saves the image to the given stream with the Jpeg format. - /// - /// The image this method extends. - /// The file path to save the image to. - /// The encoder to save the image with. - /// Thrown if the path is null. - /// A representing the asynchronous operation. - public static Task SaveAsJpegAsync(this Image source, string path, JpegEncoder encoder) - => SaveAsJpegAsync(source, path, encoder, default); - /// /// Saves the image to the given stream with the Jpeg format. /// @@ -348,7 +275,7 @@ namespace SixLabors.ImageSharp /// The token to monitor for cancellation requests. /// Thrown if the path is null. /// A representing the asynchronous operation. - public static Task SaveAsJpegAsync(this Image source, string path, JpegEncoder encoder, CancellationToken cancellationToken) => + public static Task SaveAsJpegAsync(this Image source, string path, JpegEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( path, encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(JpegFormat.Instance), @@ -363,15 +290,6 @@ namespace SixLabors.ImageSharp 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 image this method extends. - /// The stream to save the image to. - /// Thrown if the stream is null. - /// A representing the asynchronous operation. - public static Task SaveAsJpegAsync(this Image source, Stream stream) => SaveAsJpegAsync(source, stream, null); - /// /// Saves the image to the given stream with the Jpeg format. /// @@ -380,7 +298,7 @@ namespace SixLabors.ImageSharp /// The token to monitor for cancellation requests. /// Thrown if the stream is null. /// A representing the asynchronous operation. - public static Task SaveAsJpegAsync(this Image source, Stream stream, CancellationToken cancellationToken) + public static Task SaveAsJpegAsync(this Image source, Stream stream, CancellationToken cancellationToken = default) => SaveAsJpegAsync(source, stream, null, cancellationToken); /// @@ -396,17 +314,6 @@ namespace SixLabors.ImageSharp stream, encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(JpegFormat.Instance)); - /// - /// Saves the image to the given stream with the Jpeg 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. - /// A representing the asynchronous operation. - public static Task SaveAsJpegAsync(this Image source, Stream stream, JpegEncoder encoder) - => SaveAsJpegAsync(source, stream, encoder, default); - /// /// Saves the image to the given stream with the Jpeg format. /// @@ -416,7 +323,7 @@ namespace SixLabors.ImageSharp /// The token to monitor for cancellation requests. /// Thrown if the stream is null. /// A representing the asynchronous operation. - public static Task SaveAsJpegAsync(this Image source, Stream stream, JpegEncoder encoder, CancellationToken cancellationToken) => + public static Task SaveAsJpegAsync(this Image source, Stream stream, JpegEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( stream, encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(JpegFormat.Instance), @@ -462,17 +369,6 @@ namespace SixLabors.ImageSharp path, encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(PngFormat.Instance)); - /// - /// Saves the image to the given stream with the Png format. - /// - /// The image this method extends. - /// The file path to save the image to. - /// The encoder to save the image with. - /// Thrown if the path is null. - /// A representing the asynchronous operation. - public static Task SaveAsPngAsync(this Image source, string path, PngEncoder encoder) - => SaveAsPngAsync(source, path, encoder, default); - /// /// Saves the image to the given stream with the Png format. /// @@ -482,7 +378,7 @@ namespace SixLabors.ImageSharp /// The token to monitor for cancellation requests. /// Thrown if the path is null. /// A representing the asynchronous operation. - public static Task SaveAsPngAsync(this Image source, string path, PngEncoder encoder, CancellationToken cancellationToken) => + public static Task SaveAsPngAsync(this Image source, string path, PngEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( path, encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(PngFormat.Instance), @@ -497,15 +393,6 @@ namespace SixLabors.ImageSharp 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 image this method extends. - /// The stream to save the image to. - /// Thrown if the stream is null. - /// A representing the asynchronous operation. - public static Task SaveAsPngAsync(this Image source, Stream stream) => SaveAsPngAsync(source, stream, null); - /// /// Saves the image to the given stream with the Png format. /// @@ -514,7 +401,7 @@ namespace SixLabors.ImageSharp /// The token to monitor for cancellation requests. /// Thrown if the stream is null. /// A representing the asynchronous operation. - public static Task SaveAsPngAsync(this Image source, Stream stream, CancellationToken cancellationToken) + public static Task SaveAsPngAsync(this Image source, Stream stream, CancellationToken cancellationToken = default) => SaveAsPngAsync(source, stream, null, cancellationToken); /// @@ -530,17 +417,6 @@ namespace SixLabors.ImageSharp stream, encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(PngFormat.Instance)); - /// - /// Saves the image to the given stream with the Png 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. - /// A representing the asynchronous operation. - public static Task SaveAsPngAsync(this Image source, Stream stream, PngEncoder encoder) - => SaveAsPngAsync(source, stream, encoder, default); - /// /// Saves the image to the given stream with the Png format. /// @@ -550,7 +426,7 @@ namespace SixLabors.ImageSharp /// The token to monitor for cancellation requests. /// Thrown if the stream is null. /// A representing the asynchronous operation. - public static Task SaveAsPngAsync(this Image source, Stream stream, PngEncoder encoder, CancellationToken cancellationToken) => + public static Task SaveAsPngAsync(this Image source, Stream stream, PngEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( stream, encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(PngFormat.Instance), @@ -596,17 +472,6 @@ namespace SixLabors.ImageSharp path, encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(TgaFormat.Instance)); - /// - /// Saves the image to the given stream with the Tga format. - /// - /// The image this method extends. - /// The file path to save the image to. - /// The encoder to save the image with. - /// Thrown if the path is null. - /// A representing the asynchronous operation. - public static Task SaveAsTgaAsync(this Image source, string path, TgaEncoder encoder) - => SaveAsTgaAsync(source, path, encoder, default); - /// /// Saves the image to the given stream with the Tga format. /// @@ -616,7 +481,7 @@ namespace SixLabors.ImageSharp /// The token to monitor for cancellation requests. /// Thrown if the path is null. /// A representing the asynchronous operation. - public static Task SaveAsTgaAsync(this Image source, string path, TgaEncoder encoder, CancellationToken cancellationToken) => + public static Task SaveAsTgaAsync(this Image source, string path, TgaEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( path, encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(TgaFormat.Instance), @@ -631,15 +496,6 @@ namespace SixLabors.ImageSharp public static void SaveAsTga(this Image source, Stream stream) => SaveAsTga(source, stream, null); - /// - /// Saves the image to the given stream with the Tga format. - /// - /// The image this method extends. - /// The stream to save the image to. - /// Thrown if the stream is null. - /// A representing the asynchronous operation. - public static Task SaveAsTgaAsync(this Image source, Stream stream) => SaveAsTgaAsync(source, stream, null); - /// /// Saves the image to the given stream with the Tga format. /// @@ -648,7 +504,7 @@ namespace SixLabors.ImageSharp /// The token to monitor for cancellation requests. /// Thrown if the stream is null. /// A representing the asynchronous operation. - public static Task SaveAsTgaAsync(this Image source, Stream stream, CancellationToken cancellationToken) + public static Task SaveAsTgaAsync(this Image source, Stream stream, CancellationToken cancellationToken = default) => SaveAsTgaAsync(source, stream, null, cancellationToken); /// @@ -664,17 +520,6 @@ namespace SixLabors.ImageSharp stream, encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(TgaFormat.Instance)); - /// - /// Saves the image to the given stream with the Tga 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. - /// A representing the asynchronous operation. - public static Task SaveAsTgaAsync(this Image source, Stream stream, TgaEncoder encoder) - => SaveAsTgaAsync(source, stream, encoder, default); - /// /// Saves the image to the given stream with the Tga format. /// @@ -684,7 +529,7 @@ namespace SixLabors.ImageSharp /// The token to monitor for cancellation requests. /// Thrown if the stream is null. /// A representing the asynchronous operation. - public static Task SaveAsTgaAsync(this Image source, Stream stream, TgaEncoder encoder, CancellationToken cancellationToken) => + public static Task SaveAsTgaAsync(this Image source, Stream stream, TgaEncoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( stream, encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(TgaFormat.Instance), diff --git a/src/ImageSharp/Formats/ImageExtesions.Save.tt b/src/ImageSharp/Formats/ImageExtesions.Save.tt index 69ee4651a..63b404cc4 100644 --- a/src/ImageSharp/Formats/ImageExtesions.Save.tt +++ b/src/ImageSharp/Formats/ImageExtesions.Save.tt @@ -79,17 +79,6 @@ namespace SixLabors.ImageSharp path, encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(<#= fmt #>Format.Instance)); - /// - /// Saves the image to the given stream with the <#= fmt #> format. - /// - /// The image this method extends. - /// The file path to save the image to. - /// The encoder to save the image with. - /// Thrown if the path is null. - /// A representing the asynchronous operation. - public static Task SaveAs<#= fmt #>Async(this Image source, string path, <#= fmt #>Encoder encoder) - => SaveAs<#= fmt #>Async(source, path, encoder, default); - /// /// Saves the image to the given stream with the <#= fmt #> format. /// @@ -99,7 +88,7 @@ namespace SixLabors.ImageSharp /// The token to monitor for cancellation requests. /// Thrown if the path is null. /// A representing the asynchronous operation. - public static Task SaveAs<#= fmt #>Async(this Image source, string path, <#= fmt #>Encoder encoder, CancellationToken cancellationToken) => + public static Task SaveAs<#= fmt #>Async(this Image source, string path, <#= fmt #>Encoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( path, encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(<#= fmt #>Format.Instance), @@ -114,15 +103,6 @@ namespace SixLabors.ImageSharp public static void SaveAs<#= fmt #>(this Image source, Stream stream) => SaveAs<#= fmt #>(source, stream, null); - /// - /// Saves the image to the given stream with the <#= fmt #> format. - /// - /// The image this method extends. - /// The stream to save the image to. - /// Thrown if the stream is null. - /// A representing the asynchronous operation. - public static Task SaveAs<#= fmt #>Async(this Image source, Stream stream) => SaveAs<#= fmt #>Async(source, stream, null); - /// /// Saves the image to the given stream with the <#= fmt #> format. /// @@ -131,7 +111,7 @@ namespace SixLabors.ImageSharp /// The token to monitor for cancellation requests. /// Thrown if the stream is null. /// A representing the asynchronous operation. - public static Task SaveAs<#= fmt #>Async(this Image source, Stream stream, CancellationToken cancellationToken) + public static Task SaveAs<#= fmt #>Async(this Image source, Stream stream, CancellationToken cancellationToken = default) => SaveAs<#= fmt #>Async(source, stream, null, cancellationToken); /// @@ -147,17 +127,6 @@ namespace SixLabors.ImageSharp stream, encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(<#= fmt #>Format.Instance)); - /// - /// Saves the image to the given stream with the <#= fmt #> 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. - /// A representing the asynchronous operation. - public static Task SaveAs<#= fmt #>Async(this Image source, Stream stream, <#= fmt #>Encoder encoder) - => SaveAs<#= fmt #>Async(source, stream, encoder, default); - /// /// Saves the image to the given stream with the <#= fmt #> format. /// @@ -167,7 +136,7 @@ namespace SixLabors.ImageSharp /// The token to monitor for cancellation requests. /// Thrown if the stream is null. /// A representing the asynchronous operation. - public static Task SaveAs<#= fmt #>Async(this Image source, Stream stream, <#= fmt #>Encoder encoder, CancellationToken cancellationToken) => + public static Task SaveAs<#= fmt #>Async(this Image source, Stream stream, <#= fmt #>Encoder encoder, CancellationToken cancellationToken = default) => source.SaveAsync( stream, encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(<#= fmt #>Format.Instance), diff --git a/src/ImageSharp/Image.Decode.cs b/src/ImageSharp/Image.Decode.cs index ff4886a10..da23fb47d 100644 --- a/src/ImageSharp/Image.Decode.cs +++ b/src/ImageSharp/Image.Decode.cs @@ -160,7 +160,10 @@ namespace SixLabors.ImageSharp /// The token to monitor for cancellation requests. /// The pixel format. /// A representing the asynchronous operation. - private static async Task<(Image Image, IImageFormat Format)> DecodeAsync(Stream stream, Configuration config, CancellationToken cancellationToken) + private static async Task<(Image Image, IImageFormat Format)> DecodeAsync( + Stream stream, + Configuration config, + CancellationToken cancellationToken) where TPixel : unmanaged, IPixel { (IImageDecoder decoder, IImageFormat format) = await DiscoverDecoderAsync(stream, config) diff --git a/src/ImageSharp/Image.FromFile.cs b/src/ImageSharp/Image.FromFile.cs index eeb15e2ae..bf239c3e9 100644 --- a/src/ImageSharp/Image.FromFile.cs +++ b/src/ImageSharp/Image.FromFile.cs @@ -80,31 +80,6 @@ namespace SixLabors.ImageSharp } } - /// - /// Reads the raw image information from the specified stream without fully decoding it. - /// - /// The image file to open and to read the header from. - /// The configuration is null. - /// - /// The representing the asynchronous operation with the parameter type - /// property set to null if suitable info detector is not found. - /// - public static Task IdentifyAsync(string filePath) - => IdentifyAsync(Configuration.Default, filePath, default); - - /// - /// Reads the raw image information from the specified stream without fully decoding it. - /// - /// The configuration. - /// The image file to open and to read the header from. - /// The configuration is null. - /// - /// The representing the asynchronous operation with the parameter type - /// property set to null if suitable info detector is not found. - /// - public static Task IdentifyAsync(Configuration configuration, string filePath) - => IdentifyAsync(configuration, filePath, default); - /// /// Reads the raw image information from the specified stream without fully decoding it. /// @@ -115,7 +90,7 @@ namespace SixLabors.ImageSharp /// The representing the asynchronous operation with the parameter type /// property set to null if suitable info detector is not found. /// - public static Task IdentifyAsync(string filePath, CancellationToken cancellationToken) + public static Task IdentifyAsync(string filePath, CancellationToken cancellationToken = default) => IdentifyAsync(Configuration.Default, filePath, cancellationToken); /// @@ -129,25 +104,16 @@ namespace SixLabors.ImageSharp /// The representing the asynchronous operation with the parameter type /// property set to null if suitable info detector is not found. /// - public static async Task IdentifyAsync(Configuration configuration, string filePath, CancellationToken cancellationToken) + public static async Task IdentifyAsync( + Configuration configuration, + string filePath, + CancellationToken cancellationToken = default) { (IImageInfo ImageInfo, IImageFormat Format) res = await IdentifyWithFormatAsync(configuration, filePath, cancellationToken) .ConfigureAwait(false); return res.ImageInfo; } - /// - /// Reads the raw image information from the specified stream without fully decoding it. - /// - /// The image file to open and to read the header from. - /// The configuration is null. - /// - /// The representing the asynchronous operation with the parameter type - /// property set to null if suitable info detector is not found. - /// - public static Task<(IImageInfo ImageInfo, IImageFormat Format)> IdentifyWithFormatAsync(string filePath) - => IdentifyWithFormatAsync(Configuration.Default, filePath, default); - /// /// Reads the raw image information from the specified stream without fully decoding it. /// @@ -160,24 +126,9 @@ namespace SixLabors.ImageSharp /// public static Task<(IImageInfo ImageInfo, IImageFormat Format)> IdentifyWithFormatAsync( string filePath, - CancellationToken cancellationToken) + CancellationToken cancellationToken = default) => IdentifyWithFormatAsync(Configuration.Default, filePath, cancellationToken); - /// - /// Reads the raw image information from the specified stream without fully decoding it. - /// - /// The configuration. - /// The image file to open and to read the header from. - /// The configuration is null. - /// - /// The representing the asynchronous operation with the parameter type - /// property set to null if suitable info detector is not found. - /// - public static Task<(IImageInfo ImageInfo, IImageFormat Format)> IdentifyWithFormatAsync( - Configuration configuration, - string filePath) - => IdentifyWithFormatAsync(configuration, filePath, default); - /// /// Reads the raw image information from the specified stream without fully decoding it. /// @@ -192,7 +143,7 @@ namespace SixLabors.ImageSharp public static async Task<(IImageInfo ImageInfo, IImageFormat Format)> IdentifyWithFormatAsync( Configuration configuration, string filePath, - CancellationToken cancellationToken) + CancellationToken cancellationToken = default) { Guard.NotNull(configuration, nameof(configuration)); using Stream stream = configuration.FileSystem.OpenRead(filePath); @@ -211,17 +162,6 @@ namespace SixLabors.ImageSharp public static Image Load(string path) => Load(Configuration.Default, path); - /// - /// 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 representing the asynchronous operation. - public static Task LoadAsync(string path) - => LoadAsync(Configuration.Default, path); - /// /// Create a new instance of the class from the given file. /// @@ -247,19 +187,6 @@ namespace SixLabors.ImageSharp public static Image Load(Configuration configuration, string path) => Load(configuration, path, out _); - /// - /// Create a new instance of the class from the given file. - /// - /// The configuration for the decoder. - /// The file path to the image. - /// The configuration is null. - /// The path is null. - /// Image format not recognised. - /// Image contains invalid content. - /// A representing the asynchronous operation. - public static Task LoadAsync(Configuration configuration, string path) - => LoadAsync(configuration, path, default(CancellationToken)); - /// /// Create a new instance of the class from the given file. /// @@ -271,7 +198,10 @@ namespace SixLabors.ImageSharp /// Image format not recognised. /// Image contains invalid content. /// A representing the asynchronous operation. - public static async Task LoadAsync(Configuration configuration, string path, CancellationToken cancellationToken) + public static async Task LoadAsync( + Configuration configuration, + string path, + CancellationToken cancellationToken = default) { using Stream stream = configuration.FileSystem.OpenRead(path); (Image img, _) = await LoadWithFormatAsync(configuration, stream, cancellationToken) @@ -313,7 +243,7 @@ namespace SixLabors.ImageSharp /// Image format not recognised. /// Image contains invalid content. /// A representing the asynchronous operation. - public static Task LoadAsync(string path, CancellationToken cancellationToken) + public static Task LoadAsync(string path, CancellationToken cancellationToken = default) => LoadAsync(Configuration.Default, path, cancellationToken); /// @@ -330,21 +260,6 @@ namespace SixLabors.ImageSharp public static Task LoadAsync(string path, IImageDecoder decoder) => LoadAsync(Configuration.Default, path, decoder, default); - /// - /// Create a new instance of the class from the given file. - /// - /// The Configuration. - /// The file path to the image. - /// The decoder. - /// The configuration is null. - /// The path is null. - /// The decoder is null. - /// Image format not recognised. - /// Image contains invalid content. - /// A representing the asynchronous operation. - public static Task LoadAsync(Configuration configuration, string path, IImageDecoder decoder) - => LoadAsync(configuration, path, decoder, default); - /// /// Create a new instance of the class from the given file. /// @@ -361,23 +276,6 @@ namespace SixLabors.ImageSharp where TPixel : unmanaged, IPixel => LoadAsync(Configuration.Default, path, decoder, default); - /// - /// Create a new instance of the class from the given file. - /// - /// The Configuration. - /// The file path to the image. - /// The decoder. - /// The configuration is null. - /// The path is null. - /// The decoder is null. - /// Image format not recognised. - /// Image contains invalid content. - /// The pixel format. - /// A representing the asynchronous operation. - public static Task> LoadAsync(Configuration configuration, string path, IImageDecoder decoder) - where TPixel : unmanaged, IPixel - => LoadAsync(configuration, path, decoder, default); - /// /// Create a new instance of the class from the given file. /// @@ -391,7 +289,11 @@ namespace SixLabors.ImageSharp /// Image format not recognised. /// Image contains invalid content. /// A representing the asynchronous operation. - public static Task LoadAsync(Configuration configuration, string path, IImageDecoder decoder, CancellationToken cancellationToken) + public static Task LoadAsync( + Configuration configuration, + string path, + IImageDecoder decoder, + CancellationToken cancellationToken = default) { Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(path, nameof(path)); @@ -414,7 +316,11 @@ namespace SixLabors.ImageSharp /// Image contains invalid content. /// The pixel format. /// A representing the asynchronous operation. - public static Task> LoadAsync(Configuration configuration, string path, IImageDecoder decoder, CancellationToken cancellationToken) + public static Task> LoadAsync( + Configuration configuration, + string path, + IImageDecoder decoder, + CancellationToken cancellationToken = default) where TPixel : unmanaged, IPixel { Guard.NotNull(configuration, nameof(configuration)); @@ -438,21 +344,6 @@ namespace SixLabors.ImageSharp where TPixel : unmanaged, IPixel => LoadAsync(Configuration.Default, path, default(CancellationToken)); - /// - /// Create a new instance of the class from the given file. - /// - /// The configuration for the decoder. - /// The file path to the image. - /// The configuration is null. - /// The path is null. - /// Image format not recognised. - /// Image contains invalid content. - /// The pixel format. - /// A representing the asynchronous operation. - public static Task> LoadAsync(Configuration configuration, string path) - where TPixel : unmanaged, IPixel - => LoadAsync(configuration, path, default(CancellationToken)); - /// /// Create a new instance of the class from the given file. /// @@ -465,7 +356,10 @@ namespace SixLabors.ImageSharp /// Image contains invalid content. /// The pixel format. /// A representing the asynchronous operation. - public static async Task> LoadAsync(Configuration configuration, string path, CancellationToken cancellationToken) + public static async Task> LoadAsync( + Configuration configuration, + string path, + CancellationToken cancellationToken = default) where TPixel : unmanaged, IPixel { using Stream stream = configuration.FileSystem.OpenRead(path); diff --git a/src/ImageSharp/Image.FromStream.cs b/src/ImageSharp/Image.FromStream.cs index ac6eec282..ee148cd25 100644 --- a/src/ImageSharp/Image.FromStream.cs +++ b/src/ImageSharp/Image.FromStream.cs @@ -122,22 +122,6 @@ namespace SixLabors.ImageSharp public static IImageInfo Identify(Configuration configuration, Stream stream) => Identify(configuration, stream, out _); - /// - /// Reads the raw image information from the specified stream without fully decoding it. - /// - /// The configuration. - /// The image stream to read the information from. - /// The configuration is null. - /// The stream is null. - /// The stream is not readable. - /// Image contains invalid content. - /// - /// A representing the asynchronous operation or null if - /// a suitable detector is not found. - /// - public static Task IdentifyAsync(Configuration configuration, Stream stream) - => IdentifyAsync(configuration, stream, default); - /// /// Reads the raw image information from the specified stream without fully decoding it. /// @@ -152,7 +136,10 @@ namespace SixLabors.ImageSharp /// A representing the asynchronous operation or null if /// a suitable detector is not found. /// - public static async Task IdentifyAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken) + public static async Task IdentifyAsync( + Configuration configuration, + Stream stream, + CancellationToken cancellationToken = default) { (IImageInfo ImageInfo, IImageFormat Format) res = await IdentifyWithFormatAsync(configuration, stream, cancellationToken).ConfigureAwait(false); return res.ImageInfo; @@ -179,41 +166,6 @@ namespace SixLabors.ImageSharp return data.ImageInfo; } - /// - /// Reads the raw image information from the specified stream without fully decoding it. - /// - /// The image stream to read the information from. - /// The configuration is null. - /// The stream is null. - /// The stream is not readable. - /// Image contains invalid content. - /// - /// A representing the asynchronous operation or null if - /// a suitable detector is not found. - /// - public static Task<(IImageInfo ImageInfo, IImageFormat Format)> IdentifyWithFormatAsync(Stream stream) - => IdentifyWithFormatAsync(Configuration.Default, stream); - - /// - /// Reads the raw image information from the specified stream without fully decoding it. - /// - /// The configuration. - /// The image stream to read the information from. - /// The configuration is null. - /// The stream is null. - /// The stream is not readable. - /// Image contains invalid content. - /// - /// The representing the asyncronous operation with the parameter type - /// property set to null if suitable info detector is not found. - /// - public static Task<(IImageInfo ImageInfo, IImageFormat Format)> IdentifyWithFormatAsync(Configuration configuration, Stream stream) - => WithSeekableStreamAsync( - configuration, - stream, - (s, ct) => InternalIdentityAsync(s, configuration ?? Configuration.Default, ct), - default); - /// /// Reads the raw image information from the specified stream without fully decoding it. /// @@ -229,7 +181,7 @@ namespace SixLabors.ImageSharp /// public static Task<(IImageInfo ImageInfo, IImageFormat Format)> IdentifyWithFormatAsync( Stream stream, - CancellationToken cancellationToken) + CancellationToken cancellationToken = default) => IdentifyWithFormatAsync(Configuration.Default, stream, cancellationToken); /// @@ -246,7 +198,10 @@ namespace SixLabors.ImageSharp /// The representing the asynchronous operation with the parameter type /// property set to null if suitable info detector is not found. /// - public static Task<(IImageInfo ImageInfo, IImageFormat Format)> IdentifyWithFormatAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken) + public static Task<(IImageInfo ImageInfo, IImageFormat Format)> IdentifyWithFormatAsync( + Configuration configuration, + Stream stream, + CancellationToken cancellationToken = default) => WithSeekableStreamAsync( configuration, stream, @@ -354,23 +309,6 @@ namespace SixLabors.ImageSharp return WithSeekableStream(configuration, stream, s => decoder.Decode(configuration, s)); } - /// - /// Decode a new instance of the class from the given stream. - /// The pixel format is selected by the decoder. - /// - /// The configuration for the decoder. - /// The stream containing image information. - /// The decoder. - /// The configuration is null. - /// The stream is null. - /// The decoder is null. - /// The stream is not readable. - /// Image format not recognised. - /// Image contains invalid content. - /// A representing the asynchronous operation. - public static Task LoadAsync(Configuration configuration, Stream stream, IImageDecoder decoder) - => LoadAsync(configuration, stream, decoder, default); - /// /// Decode a new instance of the class from the given stream. /// The pixel format is selected by the decoder. @@ -386,7 +324,11 @@ namespace SixLabors.ImageSharp /// Image format not recognised. /// Image contains invalid content. /// A representing the asynchronous operation. - public static Task LoadAsync(Configuration configuration, Stream stream, IImageDecoder decoder, CancellationToken cancellationToken) + public static Task LoadAsync( + Configuration configuration, + Stream stream, + IImageDecoder decoder, + CancellationToken cancellationToken = default) { Guard.NotNull(decoder, nameof(decoder)); return WithSeekableStreamAsync( @@ -409,23 +351,6 @@ namespace SixLabors.ImageSharp /// A new . public static Image Load(Configuration configuration, Stream stream) => Load(configuration, stream, out _); - /// - /// Decode a new instance of the class from the given stream. - /// - /// The configuration for the decoder. - /// The stream containing image information. - /// The configuration is null. - /// The stream is null. - /// The stream is not readable. - /// Image format not recognised. - /// Image contains invalid content. - /// A representing the asynchronous operation. - public static async Task LoadAsync(Configuration configuration, Stream stream) - { - (Image Image, IImageFormat Format) fmt = await LoadWithFormatAsync(configuration, stream).ConfigureAwait(false); - return fmt.Image; - } - /// /// Decode a new instance of the class from the given stream. /// @@ -438,7 +363,7 @@ namespace SixLabors.ImageSharp /// Image format not recognised. /// Image contains invalid content. /// A representing the asynchronous operation. - public static async Task LoadAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken) + public static async Task LoadAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken = default) { (Image Image, IImageFormat Format) fmt = await LoadWithFormatAsync(configuration, stream, cancellationToken) .ConfigureAwait(false); @@ -517,21 +442,6 @@ namespace SixLabors.ImageSharp where TPixel : unmanaged, IPixel => WithSeekableStream(Configuration.Default, stream, s => decoder.Decode(Configuration.Default, s)); - /// - /// Create a new instance of the class from the given stream. - /// - /// The stream containing image information. - /// The decoder. - /// The stream is null. - /// The stream is not readable. - /// Image format not recognised. - /// Image contains invalid content. - /// The pixel format. - /// A representing the asynchronous operation. - public static Task> LoadAsync(Stream stream, IImageDecoder decoder) - where TPixel : unmanaged, IPixel - => LoadAsync(stream, decoder, default); - /// /// Create a new instance of the class from the given stream. /// @@ -544,7 +454,7 @@ namespace SixLabors.ImageSharp /// Image contains invalid content. /// The pixel format. /// A representing the asynchronous operation. - public static Task> LoadAsync(Stream stream, IImageDecoder decoder, CancellationToken cancellationToken) + public static Task> LoadAsync(Stream stream, IImageDecoder decoder, CancellationToken cancellationToken = default) where TPixel : unmanaged, IPixel => WithSeekableStreamAsync( Configuration.Default, @@ -569,26 +479,6 @@ namespace SixLabors.ImageSharp where TPixel : unmanaged, IPixel => WithSeekableStream(configuration, stream, s => decoder.Decode(configuration, s)); - /// - /// Create a new instance of the class from the given stream. - /// - /// The Configuration. - /// The stream containing image information. - /// The decoder. - /// The configuration is null. - /// The stream is null. - /// The stream is not readable. - /// Image format not recognised. - /// Image contains invalid content. - /// The pixel format. - /// A representing the asynchronous operation. - public static Task> LoadAsync( - Configuration configuration, - Stream stream, - IImageDecoder decoder) - where TPixel : unmanaged, IPixel - => LoadAsync(configuration, stream, decoder, default); - /// /// Create a new instance of the class from the given stream. /// @@ -607,7 +497,7 @@ namespace SixLabors.ImageSharp Configuration configuration, Stream stream, IImageDecoder decoder, - CancellationToken cancellationToken) + CancellationToken cancellationToken = default) where TPixel : unmanaged, IPixel => WithSeekableStreamAsync( configuration, @@ -667,22 +557,6 @@ namespace SixLabors.ImageSharp throw new UnknownImageFormatException(sb.ToString()); } - /// - /// Create a new instance of the class from the given stream. - /// - /// The configuration options. - /// The stream containing image information. - /// The configuration is null. - /// The stream is null. - /// The stream is not readable. - /// Image format not recognised. - /// Image contains invalid content. - /// A representing the asynchronous operation. - public static Task<(Image Image, IImageFormat Format)> LoadWithFormatAsync( - Configuration configuration, - Stream stream) - => LoadWithFormatAsync(configuration, stream, default); - /// /// Create a new instance of the class from the given stream. /// @@ -695,7 +569,10 @@ namespace SixLabors.ImageSharp /// Image format not recognised. /// Image contains invalid content. /// A representing the asynchronous operation. - public static async Task<(Image Image, IImageFormat Format)> LoadWithFormatAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken) + public static async Task<(Image Image, IImageFormat Format)> LoadWithFormatAsync( + Configuration configuration, + Stream stream, + CancellationToken cancellationToken = default) { (Image Image, IImageFormat Format) data = await WithSeekableStreamAsync( configuration, @@ -720,23 +597,6 @@ namespace SixLabors.ImageSharp throw new UnknownImageFormatException(sb.ToString()); } - /// - /// Create a new instance of the class from the given stream. - /// - /// The configuration options. - /// The stream containing image information. - /// The configuration is null. - /// The stream is null. - /// The stream is not readable. - /// Image format not recognised. - /// Image contains invalid content. - /// The pixel format. - /// A representing the asynchronous operation. - public static Task<(Image Image, IImageFormat Format)> LoadWithFormatAsync( - Configuration configuration, Stream stream) - where TPixel : unmanaged, IPixel - => LoadWithFormatAsync(configuration, stream, default); - /// /// Create a new instance of the class from the given stream. /// @@ -750,7 +610,10 @@ namespace SixLabors.ImageSharp /// Image contains invalid content. /// The pixel format. /// A representing the asynchronous operation. - public static async Task<(Image Image, IImageFormat Format)> LoadWithFormatAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken) + public static async Task<(Image Image, IImageFormat Format)> LoadWithFormatAsync( + Configuration configuration, + Stream stream, + CancellationToken cancellationToken = default) where TPixel : unmanaged, IPixel { (Image Image, IImageFormat Format) data = @@ -777,22 +640,6 @@ namespace SixLabors.ImageSharp throw new UnknownImageFormatException(sb.ToString()); } - /// - /// Create a new instance of the class from the given stream. - /// - /// The configuration options. - /// The stream containing image information. - /// The configuration is null. - /// The stream is null. - /// The stream is not readable. - /// Image format not recognised. - /// Image contains invalid content. - /// The pixel format. - /// A representing the asynchronous operation. - public static Task> LoadAsync(Configuration configuration, Stream stream) - where TPixel : unmanaged, IPixel - => LoadAsync(configuration, stream, default(CancellationToken)); - /// /// Create a new instance of the class from the given stream. /// @@ -806,7 +653,10 @@ namespace SixLabors.ImageSharp /// Image contains invalid content. /// The pixel format. /// A representing the asynchronous operation. - public static async Task> LoadAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken) + public static async Task> LoadAsync( + Configuration configuration, + Stream stream, + CancellationToken cancellationToken = default) where TPixel : unmanaged, IPixel { (Image img, _) = await LoadWithFormatAsync(configuration, stream, cancellationToken) diff --git a/src/ImageSharp/Image.cs b/src/ImageSharp/Image.cs index 3560d9960..fbb3ec206 100644 --- a/src/ImageSharp/Image.cs +++ b/src/ImageSharp/Image.cs @@ -99,16 +99,6 @@ namespace SixLabors.ImageSharp this.AcceptVisitor(new EncodeVisitor(encoder, stream)); } - /// - /// 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. - /// A representing the asynchronous operation. - public Task SaveAsync(Stream stream, IImageEncoder encoder) - => this.SaveAsync(stream, encoder, default); - /// /// Saves the image to the given stream using the given image encoder. /// @@ -117,7 +107,7 @@ namespace SixLabors.ImageSharp /// The token to monitor for cancellation requests. /// Thrown if the stream or encoder is null. /// A representing the asynchronous operation. - public Task SaveAsync(Stream stream, IImageEncoder encoder, CancellationToken cancellationToken) + public Task SaveAsync(Stream stream, IImageEncoder encoder, CancellationToken cancellationToken = default) { Guard.NotNull(stream, nameof(stream)); Guard.NotNull(encoder, nameof(encoder)); diff --git a/src/ImageSharp/ImageExtensions.cs b/src/ImageSharp/ImageExtensions.cs index 5430810b2..ccccf526f 100644 --- a/src/ImageSharp/ImageExtensions.cs +++ b/src/ImageSharp/ImageExtensions.cs @@ -26,16 +26,6 @@ namespace SixLabors.ImageSharp public static void Save(this Image source, string path) => source.Save(path, source.DetectEncoder(path)); - /// - /// Writes the image to the given stream using the currently loaded image format. - /// - /// The source image. - /// The file path to save the image to. - /// The path is null. - /// A representing the asynchronous operation. - public static Task SaveAsync(this Image source, string path) - => source.SaveAsync(path, source.DetectEncoder(path)); - /// /// Writes the image to the given stream using the currently loaded image format. /// @@ -44,7 +34,7 @@ namespace SixLabors.ImageSharp /// The token to monitor for cancellation requests. /// The path is null. /// A representing the asynchronous operation. - public static Task SaveAsync(this Image source, string path, CancellationToken cancellationToken) + public static Task SaveAsync(this Image source, string path, CancellationToken cancellationToken = default) => source.SaveAsync(path, source.DetectEncoder(path), cancellationToken); ///