diff --git a/src/ImageSharp/Formats/Bmp/BmpImageFormatDetector.cs b/src/ImageSharp/Formats/Bmp/BmpImageFormatDetector.cs index a10f6b74a9..9917179692 100644 --- a/src/ImageSharp/Formats/Bmp/BmpImageFormatDetector.cs +++ b/src/ImageSharp/Formats/Bmp/BmpImageFormatDetector.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +#nullable enable using System.Buffers.Binary; namespace SixLabors.ImageSharp.Formats.Bmp; @@ -14,7 +15,7 @@ public sealed class BmpImageFormatDetector : IImageFormatDetector public int HeaderSize => 2; /// - public IImageFormat DetectFormat(ReadOnlySpan header) + public IImageFormat? DetectFormat(ReadOnlySpan header) { return this.IsSupportedFileFormat(header) ? BmpFormat.Instance : null; } diff --git a/src/ImageSharp/Formats/Gif/GifImageFormatDetector.cs b/src/ImageSharp/Formats/Gif/GifImageFormatDetector.cs index 3f657610c9..562b146ff1 100644 --- a/src/ImageSharp/Formats/Gif/GifImageFormatDetector.cs +++ b/src/ImageSharp/Formats/Gif/GifImageFormatDetector.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +#nullable enable namespace SixLabors.ImageSharp.Formats.Gif; /// @@ -12,7 +13,7 @@ public sealed class GifImageFormatDetector : IImageFormatDetector public int HeaderSize => 6; /// - public IImageFormat DetectFormat(ReadOnlySpan header) + public IImageFormat? DetectFormat(ReadOnlySpan header) { return this.IsSupportedFileFormat(header) ? GifFormat.Instance : null; } diff --git a/src/ImageSharp/Formats/IImageFormatDetector.cs b/src/ImageSharp/Formats/IImageFormatDetector.cs index 17f565d2b2..a93e398b51 100644 --- a/src/ImageSharp/Formats/IImageFormatDetector.cs +++ b/src/ImageSharp/Formats/IImageFormatDetector.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +#nullable enable namespace SixLabors.ImageSharp.Formats; /// @@ -19,5 +20,5 @@ public interface IImageFormatDetector /// /// The containing the file header. /// returns the mime type of detected otherwise returns null - IImageFormat DetectFormat(ReadOnlySpan header); + IImageFormat? DetectFormat(ReadOnlySpan header); } diff --git a/src/ImageSharp/Formats/ImageFormatManager.cs b/src/ImageSharp/Formats/ImageFormatManager.cs index 9f22c62294..748515bdd8 100644 --- a/src/ImageSharp/Formats/ImageFormatManager.cs +++ b/src/ImageSharp/Formats/ImageFormatManager.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +#nullable enable using System.Collections.Concurrent; namespace SixLabors.ImageSharp.Formats; @@ -92,7 +93,7 @@ public void AddImageFormat(IImageFormat format) /// /// The extension to discover /// The if found otherwise null - public IImageFormat FindFormatByFileExtension(string extension) + public IImageFormat? FindFormatByFileExtension(string extension) { Guard.NotNullOrWhiteSpace(extension, nameof(extension)); @@ -109,7 +110,7 @@ public IImageFormat FindFormatByFileExtension(string extension) /// /// The mime-type to discover /// The if found; otherwise null - public IImageFormat FindFormatByMimeType(string mimeType) + public IImageFormat? FindFormatByMimeType(string mimeType) => this.imageFormats.FirstOrDefault(x => x.MimeTypes.Contains(mimeType, StringComparer.OrdinalIgnoreCase)); /// @@ -159,11 +160,11 @@ public void AddImageFormatDetector(IImageFormatDetector detector) /// /// The format to discover /// The if found otherwise null - public IImageDecoder FindDecoder(IImageFormat format) + public IImageDecoder? FindDecoder(IImageFormat format) { Guard.NotNull(format, nameof(format)); - return this.mimeTypeDecoders.TryGetValue(format, out IImageDecoder decoder) + return this.mimeTypeDecoders.TryGetValue(format, out IImageDecoder? decoder) ? decoder : null; } @@ -173,11 +174,11 @@ public IImageDecoder FindDecoder(IImageFormat format) /// /// The format to discover /// The if found otherwise null - public IImageEncoder FindEncoder(IImageFormat format) + public IImageEncoder? FindEncoder(IImageFormat format) { Guard.NotNull(format, nameof(format)); - return this.mimeTypeEncoders.TryGetValue(format, out IImageEncoder encoder) + return this.mimeTypeEncoders.TryGetValue(format, out IImageEncoder? encoder) ? encoder : null; } diff --git a/src/ImageSharp/Formats/Jpeg/JpegImageFormatDetector.cs b/src/ImageSharp/Formats/Jpeg/JpegImageFormatDetector.cs index f2cc631c53..ad2e011a06 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegImageFormatDetector.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegImageFormatDetector.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +#nullable enable namespace SixLabors.ImageSharp.Formats.Jpeg; /// @@ -12,7 +13,7 @@ public sealed class JpegImageFormatDetector : IImageFormatDetector public int HeaderSize => 11; /// - public IImageFormat DetectFormat(ReadOnlySpan header) + public IImageFormat? DetectFormat(ReadOnlySpan header) => this.IsSupportedFileFormat(header) ? JpegFormat.Instance : null; private bool IsSupportedFileFormat(ReadOnlySpan header) diff --git a/src/ImageSharp/Formats/Pbm/PbmImageFormatDetector.cs b/src/ImageSharp/Formats/Pbm/PbmImageFormatDetector.cs index c982042e02..b249c7ebb8 100644 --- a/src/ImageSharp/Formats/Pbm/PbmImageFormatDetector.cs +++ b/src/ImageSharp/Formats/Pbm/PbmImageFormatDetector.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +#nullable enable namespace SixLabors.ImageSharp.Formats.Pbm; /// @@ -16,7 +17,7 @@ public sealed class PbmImageFormatDetector : IImageFormatDetector public int HeaderSize => 2; /// - public IImageFormat DetectFormat(ReadOnlySpan header) => IsSupportedFileFormat(header) ? PbmFormat.Instance : null; + public IImageFormat? DetectFormat(ReadOnlySpan header) => IsSupportedFileFormat(header) ? PbmFormat.Instance : null; private static bool IsSupportedFileFormat(ReadOnlySpan header) { diff --git a/src/ImageSharp/Formats/Png/PngImageFormatDetector.cs b/src/ImageSharp/Formats/Png/PngImageFormatDetector.cs index 907898e17f..b3a869d411 100644 --- a/src/ImageSharp/Formats/Png/PngImageFormatDetector.cs +++ b/src/ImageSharp/Formats/Png/PngImageFormatDetector.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +#nullable enable using System.Buffers.Binary; namespace SixLabors.ImageSharp.Formats.Png; @@ -14,7 +15,7 @@ public sealed class PngImageFormatDetector : IImageFormatDetector public int HeaderSize => 8; /// - public IImageFormat DetectFormat(ReadOnlySpan header) + public IImageFormat? DetectFormat(ReadOnlySpan header) { return this.IsSupportedFileFormat(header) ? PngFormat.Instance : null; } diff --git a/src/ImageSharp/Formats/Tga/TgaImageFormatDetector.cs b/src/ImageSharp/Formats/Tga/TgaImageFormatDetector.cs index 23f93a8249..9e8af088a8 100644 --- a/src/ImageSharp/Formats/Tga/TgaImageFormatDetector.cs +++ b/src/ImageSharp/Formats/Tga/TgaImageFormatDetector.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +#nullable enable namespace SixLabors.ImageSharp.Formats.Tga; /// @@ -12,7 +13,7 @@ public sealed class TgaImageFormatDetector : IImageFormatDetector public int HeaderSize => 16; /// - public IImageFormat DetectFormat(ReadOnlySpan header) + public IImageFormat? DetectFormat(ReadOnlySpan header) { return this.IsSupportedFileFormat(header) ? TgaFormat.Instance : null; } diff --git a/src/ImageSharp/Formats/Tiff/TiffImageFormatDetector.cs b/src/ImageSharp/Formats/Tiff/TiffImageFormatDetector.cs index 24166f6c0f..fdf2ad383b 100644 --- a/src/ImageSharp/Formats/Tiff/TiffImageFormatDetector.cs +++ b/src/ImageSharp/Formats/Tiff/TiffImageFormatDetector.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +#nullable enable namespace SixLabors.ImageSharp.Formats.Tiff; /// @@ -12,7 +13,7 @@ public sealed class TiffImageFormatDetector : IImageFormatDetector public int HeaderSize => 8; /// - public IImageFormat DetectFormat(ReadOnlySpan header) + public IImageFormat? DetectFormat(ReadOnlySpan header) { if (this.IsSupportedFileFormat(header)) { diff --git a/src/ImageSharp/Formats/Webp/WebpImageFormatDetector.cs b/src/ImageSharp/Formats/Webp/WebpImageFormatDetector.cs index 50820fd61c..b8c86a90c6 100644 --- a/src/ImageSharp/Formats/Webp/WebpImageFormatDetector.cs +++ b/src/ImageSharp/Formats/Webp/WebpImageFormatDetector.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +#nullable enable namespace SixLabors.ImageSharp.Formats.Webp; /// @@ -12,7 +13,7 @@ public sealed class WebpImageFormatDetector : IImageFormatDetector public int HeaderSize => 12; /// - public IImageFormat DetectFormat(ReadOnlySpan header) + public IImageFormat? DetectFormat(ReadOnlySpan header) => this.IsSupportedFileFormat(header) ? WebpFormat.Instance : null; private bool IsSupportedFileFormat(ReadOnlySpan header) diff --git a/src/ImageSharp/Image.Decode.cs b/src/ImageSharp/Image.Decode.cs index 6953da1cea..f95d9fd7ad 100644 --- a/src/ImageSharp/Image.Decode.cs +++ b/src/ImageSharp/Image.Decode.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +#nullable enable using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Metadata; @@ -44,7 +45,7 @@ internal static Image CreateUninitialized( /// The general configuration. /// The image stream to read the header from. /// The mime type or null if none found. - private static IImageFormat InternalDetectFormat(Configuration configuration, Stream stream) + private static IImageFormat? InternalDetectFormat(Configuration configuration, Stream stream) { // We take a minimum of the stream length vs the max header size and always check below // to ensure that only formats that headers fit within the given buffer length are tested. @@ -76,12 +77,12 @@ private static IImageFormat InternalDetectFormat(Configuration configuration, St // Does the given stream contain enough data to fit in the header for the format // and does that data match the format specification? // Individual formats should still check since they are public. - IImageFormat format = null; + IImageFormat? format = null; foreach (IImageFormatDetector formatDetector in configuration.ImageFormatsManager.FormatDetectors) { if (formatDetector.HeaderSize <= headerSize) { - IImageFormat attemptFormat = formatDetector.DetectFormat(headersBuffer); + IImageFormat? attemptFormat = formatDetector.DetectFormat(headersBuffer); if (attemptFormat != null) { format = attemptFormat; @@ -99,7 +100,7 @@ private static IImageFormat InternalDetectFormat(Configuration configuration, St /// The image stream to read the header from. /// The IImageFormat. /// The image format or null if none found. - private static IImageDecoder DiscoverDecoder(DecoderOptions options, Stream stream, out IImageFormat format) + private static IImageDecoder? DiscoverDecoder(DecoderOptions options, Stream stream, out IImageFormat? format) { format = InternalDetectFormat(options.Configuration, stream); @@ -118,10 +119,10 @@ private static IImageDecoder DiscoverDecoder(DecoderOptions options, Stream stre /// /// A new . /// - private static (Image Image, IImageFormat Format) Decode(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default) + private static (Image? Image, IImageFormat? Format) Decode(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default) where TPixel : unmanaged, IPixel { - IImageDecoder decoder = DiscoverDecoder(options, stream, out IImageFormat format); + IImageDecoder? decoder = DiscoverDecoder(options, stream, out IImageFormat? format); if (decoder is null) { return (null, null); @@ -131,9 +132,9 @@ private static (Image Image, IImageFormat Format) Decode(Decoder return (img, format); } - private static (Image Image, IImageFormat Format) Decode(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default) + private static (Image? Image, IImageFormat? Format) Decode(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default) { - IImageDecoder decoder = DiscoverDecoder(options, stream, out IImageFormat format); + IImageDecoder? decoder = DiscoverDecoder(options, stream, out IImageFormat? format); if (decoder is null) { return (null, null); @@ -152,16 +153,16 @@ private static (Image Image, IImageFormat Format) Decode(DecoderOptions options, /// /// The or null if a suitable info detector is not found. /// - private static (IImageInfo ImageInfo, IImageFormat Format) InternalIdentity(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default) + private static (IImageInfo? ImageInfo, IImageFormat? Format) InternalIdentity(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default) { - IImageDecoder decoder = DiscoverDecoder(options, stream, out IImageFormat format); + IImageDecoder? decoder = DiscoverDecoder(options, stream, out IImageFormat? format); if (decoder is not IImageInfoDetector detector) { return (null, null); } - IImageInfo info = detector?.Identify(options, stream, cancellationToken); + IImageInfo? info = detector.Identify(options, stream, cancellationToken); return (info, format); } } diff --git a/src/ImageSharp/Image.FromBytes.cs b/src/ImageSharp/Image.FromBytes.cs index d7d1f26913..0ef6c2854d 100644 --- a/src/ImageSharp/Image.FromBytes.cs +++ b/src/ImageSharp/Image.FromBytes.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +#nullable enable using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.PixelFormats; @@ -16,7 +17,7 @@ public abstract partial class Image /// /// The byte span containing encoded image data to read the header from. /// The format or null if none found. - public static IImageFormat DetectFormat(ReadOnlySpan data) + public static IImageFormat? DetectFormat(ReadOnlySpan data) => DetectFormat(DecoderOptions.Default, data); /// @@ -26,7 +27,7 @@ public static IImageFormat DetectFormat(ReadOnlySpan data) /// The byte span containing encoded image data to read the header from. /// The options are null. /// The mime type or null if none found. - public static IImageFormat DetectFormat(DecoderOptions options, ReadOnlySpan data) + public static IImageFormat? DetectFormat(DecoderOptions options, ReadOnlySpan data) { Guard.NotNull(options, nameof(options.Configuration)); @@ -39,7 +40,7 @@ public static IImageFormat DetectFormat(DecoderOptions options, ReadOnlySpan /// The or null if suitable info detector not found. /// - public static IImageInfo Identify(ReadOnlySpan data) => Identify(data, out IImageFormat _); + public static IImageInfo? Identify(ReadOnlySpan data) => Identify(data, out IImageFormat? _); /// /// Reads the raw image information from the specified stream without fully decoding it. @@ -71,7 +72,7 @@ public static IImageFormat DetectFormat(DecoderOptions options, ReadOnlySpan /// The or null if suitable info detector not found. /// - public static IImageInfo Identify(ReadOnlySpan data, out IImageFormat format) + public static IImageInfo? Identify(ReadOnlySpan data, out IImageFormat? format) => Identify(DecoderOptions.Default, data, out format); /// @@ -86,7 +87,7 @@ public static IImageInfo Identify(ReadOnlySpan data, out IImageFormat form /// /// The or null if suitable info detector is not found. /// - public static unsafe IImageInfo Identify(DecoderOptions options, ReadOnlySpan data, out IImageFormat format) + public static unsafe IImageInfo? Identify(DecoderOptions options, ReadOnlySpan data, out IImageFormat? format) { fixed (byte* ptr = data) { @@ -118,7 +119,7 @@ public static Image Load(ReadOnlySpan data) /// Image contains invalid content. /// Image format is not supported. /// A new . - public static Image Load(ReadOnlySpan data, out IImageFormat format) + public static Image Load(ReadOnlySpan data, out IImageFormat? format) where TPixel : unmanaged, IPixel => Load(DecoderOptions.Default, data, out format); @@ -158,7 +159,7 @@ public static unsafe Image Load(DecoderOptions options, ReadOnly public static unsafe Image Load( DecoderOptions options, ReadOnlySpan data, - out IImageFormat format) + out IImageFormat? format) where TPixel : unmanaged, IPixel { fixed (byte* ptr = data) @@ -189,7 +190,7 @@ public static Image Load(ReadOnlySpan data) /// Image contains invalid content. /// Image format is not supported. /// The . - public static Image Load(ReadOnlySpan data, out IImageFormat format) + public static Image Load(ReadOnlySpan data, out IImageFormat? format) => Load(DecoderOptions.Default, data, out format); /// @@ -215,7 +216,7 @@ public static Image Load(DecoderOptions options, ReadOnlySpan data) public static unsafe Image Load( DecoderOptions options, ReadOnlySpan data, - out IImageFormat format) + out IImageFormat? format) { fixed (byte* ptr = data) { diff --git a/src/ImageSharp/Image.FromFile.cs b/src/ImageSharp/Image.FromFile.cs index 199d450b89..a2c19361dd 100644 --- a/src/ImageSharp/Image.FromFile.cs +++ b/src/ImageSharp/Image.FromFile.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +#nullable enable using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.PixelFormats; @@ -16,7 +17,7 @@ public abstract partial class Image /// /// The image file to open and to read the header from. /// The mime type or null if none found. - public static IImageFormat DetectFormat(string filePath) + public static IImageFormat? DetectFormat(string filePath) => DetectFormat(DecoderOptions.Default, filePath); /// @@ -26,7 +27,7 @@ public static IImageFormat DetectFormat(string filePath) /// The image file to open and to read the header from. /// The configuration is null. /// The mime type or null if none found. - public static IImageFormat DetectFormat(DecoderOptions options, string filePath) + public static IImageFormat? DetectFormat(DecoderOptions options, string filePath) { Guard.NotNull(options, nameof(options)); @@ -41,7 +42,7 @@ public static IImageFormat DetectFormat(DecoderOptions options, string filePath) /// /// The or null if suitable info detector not found. /// - public static IImageInfo Identify(string filePath) + public static IImageInfo? Identify(string filePath) => Identify(filePath, out IImageFormat _); /// @@ -52,7 +53,7 @@ public static IImageInfo Identify(string filePath) /// /// The or null if suitable info detector not found. /// - public static IImageInfo Identify(string filePath, out IImageFormat format) + public static IImageInfo? Identify(string filePath, out IImageFormat? format) => Identify(DecoderOptions.Default, filePath, out format); /// @@ -65,7 +66,7 @@ public static IImageInfo Identify(string filePath, out IImageFormat format) /// /// The or null if suitable info detector is not found. /// - public static IImageInfo Identify(DecoderOptions options, string filePath, out IImageFormat format) + public static IImageInfo? Identify(DecoderOptions options, string filePath, out IImageFormat? format) { Guard.NotNull(options, nameof(options)); using Stream file = options.Configuration.FileSystem.OpenRead(filePath); @@ -82,7 +83,7 @@ public static IImageInfo Identify(DecoderOptions options, string filePath, out I /// 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 = default) + public static Task IdentifyAsync(string filePath, CancellationToken cancellationToken = default) => IdentifyAsync(DecoderOptions.Default, filePath, cancellationToken); /// @@ -96,12 +97,12 @@ public static Task IdentifyAsync(string filePath, CancellationToken /// 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( + public static async Task IdentifyAsync( DecoderOptions options, string filePath, CancellationToken cancellationToken = default) { - (IImageInfo ImageInfo, IImageFormat Format) res = + (IImageInfo? ImageInfo, IImageFormat? Format) res = await IdentifyWithFormatAsync(options, filePath, cancellationToken).ConfigureAwait(false); return res.ImageInfo; } @@ -116,7 +117,7 @@ public static async Task IdentifyAsync( /// 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( + public static Task<(IImageInfo? ImageInfo, IImageFormat? Format)> IdentifyWithFormatAsync( string filePath, CancellationToken cancellationToken = default) => IdentifyWithFormatAsync(DecoderOptions.Default, filePath, cancellationToken); @@ -132,7 +133,7 @@ public static async Task IdentifyAsync( /// The representing the asynchronous operation with the parameter type /// property set to null if suitable info detector is not found. /// - public static async Task<(IImageInfo ImageInfo, IImageFormat Format)> IdentifyWithFormatAsync( + public static async Task<(IImageInfo? ImageInfo, IImageFormat? Format)> IdentifyWithFormatAsync( DecoderOptions options, string filePath, CancellationToken cancellationToken = default) @@ -163,7 +164,7 @@ public static Image Load(string path) /// Thrown if the stream is not readable nor seekable. /// /// A new . - public static Image Load(string path, out IImageFormat format) + public static Image Load(string path, out IImageFormat? format) => Load(DecoderOptions.Default, path, out format); /// @@ -286,7 +287,7 @@ public static Image Load(string path) /// Image format is not supported. /// The pixel format. /// A new . - public static Image Load(string path, out IImageFormat format) + public static Image Load(string path, out IImageFormat? format) where TPixel : unmanaged, IPixel => Load(DecoderOptions.Default, path, out format); @@ -325,7 +326,7 @@ public static Image Load(DecoderOptions options, string path) /// Image contains invalid content. /// The pixel format. /// A new . - public static Image Load(DecoderOptions options, string path, out IImageFormat format) + public static Image Load(DecoderOptions options, string path, out IImageFormat? format) where TPixel : unmanaged, IPixel { Guard.NotNull(options, nameof(options)); @@ -348,7 +349,7 @@ public static Image Load(DecoderOptions options, string path, ou /// Image format is not supported. /// Image contains invalid content. /// A new . - public static Image Load(DecoderOptions options, string path, out IImageFormat format) + public static Image Load(DecoderOptions options, string path, out IImageFormat? format) { Guard.NotNull(options, nameof(options)); Guard.NotNull(path, nameof(path)); diff --git a/src/ImageSharp/Image.FromStream.cs b/src/ImageSharp/Image.FromStream.cs index eefb087764..dc94a54241 100644 --- a/src/ImageSharp/Image.FromStream.cs +++ b/src/ImageSharp/Image.FromStream.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +#nullable enable using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Text; @@ -22,7 +23,7 @@ public abstract partial class Image /// The stream is null. /// The stream is not readable. /// The format type or null if none found. - public static IImageFormat DetectFormat(Stream stream) + public static IImageFormat? DetectFormat(Stream stream) => DetectFormat(DecoderOptions.Default, stream); /// @@ -34,7 +35,7 @@ public static IImageFormat DetectFormat(Stream stream) /// The stream is null. /// The stream is not readable. /// The format type or null if none found. - public static IImageFormat DetectFormat(DecoderOptions options, Stream stream) + public static IImageFormat? DetectFormat(DecoderOptions options, Stream stream) => WithSeekableStream(options, stream, s => InternalDetectFormat(options.Configuration, s)); /// @@ -45,7 +46,7 @@ public static IImageFormat DetectFormat(DecoderOptions options, Stream stream) /// The stream is null. /// The stream is not readable. /// A representing the asynchronous operation or null if none is found. - public static Task DetectFormatAsync(Stream stream, CancellationToken cancellationToken = default) + public static Task DetectFormatAsync(Stream stream, CancellationToken cancellationToken = default) => DetectFormatAsync(DecoderOptions.Default, stream, cancellationToken); /// @@ -58,7 +59,7 @@ public static Task DetectFormatAsync(Stream stream, CancellationTo /// The stream is null. /// The stream is not readable. /// A representing the asynchronous operation. - public static Task DetectFormatAsync(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default) + public static Task DetectFormatAsync(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default) => WithSeekableStreamAsync( options, stream, @@ -75,7 +76,7 @@ public static Task DetectFormatAsync(DecoderOptions options, Strea /// /// The or null if a suitable info detector is not found. /// - public static IImageInfo Identify(Stream stream) + public static IImageInfo? Identify(Stream stream) => Identify(stream, out IImageFormat _); /// @@ -90,7 +91,7 @@ public static IImageInfo Identify(Stream stream) /// A representing the asynchronous operation or null if /// a suitable detector is not found. /// - public static Task IdentifyAsync(Stream stream, CancellationToken cancellationToken = default) + public static Task IdentifyAsync(Stream stream, CancellationToken cancellationToken = default) => IdentifyAsync(DecoderOptions.Default, stream, cancellationToken); /// @@ -104,7 +105,7 @@ public static Task IdentifyAsync(Stream stream, CancellationToken ca /// /// The or null if a suitable info detector is not found. /// - public static IImageInfo Identify(Stream stream, out IImageFormat format) + public static IImageInfo? Identify(Stream stream, out IImageFormat? format) => Identify(DecoderOptions.Default, stream, out format); /// @@ -119,7 +120,7 @@ public static IImageInfo Identify(Stream stream, out IImageFormat format) /// /// The or null if a suitable info detector is not found. /// - public static IImageInfo Identify(DecoderOptions options, Stream stream) + public static IImageInfo? Identify(DecoderOptions options, Stream stream) => Identify(options, stream, out _); /// @@ -136,12 +137,12 @@ public static IImageInfo Identify(DecoderOptions options, Stream stream) /// A representing the asynchronous operation or null if /// a suitable detector is not found. /// - public static async Task IdentifyAsync( + public static async Task IdentifyAsync( DecoderOptions options, Stream stream, CancellationToken cancellationToken = default) { - (IImageInfo ImageInfo, IImageFormat Format) res = await IdentifyWithFormatAsync(options, stream, cancellationToken).ConfigureAwait(false); + (IImageInfo? ImageInfo, IImageFormat? Format) res = await IdentifyWithFormatAsync(options, stream, cancellationToken).ConfigureAwait(false); return res.ImageInfo; } @@ -158,9 +159,9 @@ public static async Task IdentifyAsync( /// /// The or null if a suitable info detector is not found. /// - public static IImageInfo Identify(DecoderOptions options, Stream stream, out IImageFormat format) + public static IImageInfo? Identify(DecoderOptions options, Stream stream, out IImageFormat? format) { - (IImageInfo ImageInfo, IImageFormat Format) data = WithSeekableStream(options, stream, s => InternalIdentity(options, s)); + (IImageInfo? ImageInfo, IImageFormat? Format) data = WithSeekableStream(options, stream, s => InternalIdentity(options, s)); format = data.Format; return data.ImageInfo; @@ -179,7 +180,7 @@ public static IImageInfo Identify(DecoderOptions options, Stream stream, out IIm /// 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( + public static Task<(IImageInfo? ImageInfo, IImageFormat? Format)> IdentifyWithFormatAsync( Stream stream, CancellationToken cancellationToken = default) => IdentifyWithFormatAsync(DecoderOptions.Default, stream, cancellationToken); @@ -198,7 +199,7 @@ public static IImageInfo Identify(DecoderOptions options, Stream stream, out IIm /// 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( + public static Task<(IImageInfo? ImageInfo, IImageFormat? Format)> IdentifyWithFormatAsync( DecoderOptions options, Stream stream, CancellationToken cancellationToken = default) @@ -219,7 +220,7 @@ public static IImageInfo Identify(DecoderOptions options, Stream stream, out IIm /// Image format not recognised. /// Image contains invalid content. /// The . - public static Image Load(Stream stream, out IImageFormat format) + public static Image Load(Stream stream, out IImageFormat? format) => Load(DecoderOptions.Default, stream, out format); /// @@ -335,7 +336,7 @@ public static Task> LoadAsync(Stream stream, CancellationT /// Image contains invalid content. /// The pixel format. /// A new . - public static Image Load(Stream stream, out IImageFormat format) + public static Image Load(Stream stream, out IImageFormat? format) where TPixel : unmanaged, IPixel => Load(DecoderOptions.Default, stream, out format); @@ -383,10 +384,10 @@ public static Image Load(DecoderOptions options, Stream stream) /// Image contains invalid content. /// The pixel format. /// A representing the asynchronous operation. - public static Image Load(DecoderOptions options, Stream stream, out IImageFormat format) + public static Image Load(DecoderOptions options, Stream stream, out IImageFormat? format) where TPixel : unmanaged, IPixel { - (Image Image, IImageFormat Format) data = WithSeekableStream(options, stream, s => Decode(options, s)); + (Image? Image, IImageFormat? Format) data = WithSeekableStream(options, stream, s => Decode(options, s)); format = data.Format; @@ -495,9 +496,9 @@ public static async Task> LoadAsync( /// Image format not recognised. /// Image contains invalid content. /// A new . - public static Image Load(DecoderOptions options, Stream stream, out IImageFormat format) + public static Image Load(DecoderOptions options, Stream stream, out IImageFormat? format) { - (Image img, IImageFormat fmt) = WithSeekableStream(options, stream, s => Decode(options, s)); + (Image? img, IImageFormat? fmt) = WithSeekableStream(options, stream, s => Decode(options, s)); format = fmt;