From e2872c1064811e75e772cb818287669505b050f5 Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Sun, 1 Jan 2023 11:40:28 +0100 Subject: [PATCH] Remove nullable disable * FormatDetecot * ImageFormatManager * DecoderUtilities (Not needed) --- src/ImageSharp/Advanced/AdvancedImageExtensions.cs | 4 ++-- .../Formats/Bmp/BmpImageFormatDetector.cs | 3 +-- .../Formats/Gif/GifImageFormatDetector.cs | 3 +-- src/ImageSharp/Formats/IImageFormatDetector.cs | 2 +- src/ImageSharp/Formats/ImageDecoderUtilities.cs | 1 - src/ImageSharp/Formats/ImageFormatManager.cs | 13 ++++++------- .../Formats/Jpeg/JpegImageFormatDetector.cs | 3 +-- .../Formats/Pbm/PbmImageFormatDetector.cs | 3 +-- .../Formats/Png/PngImageFormatDetector.cs | 3 +-- .../Formats/Tga/TgaImageFormatDetector.cs | 3 +-- .../Formats/Tiff/TiffImageFormatDetector.cs | 3 +-- .../Formats/Webp/WebpImageFormatDetector.cs | 3 +-- src/ImageSharp/Image.FromBytes.cs | 7 +++---- src/ImageSharp/Image{TPixel}.cs | 4 +--- 14 files changed, 21 insertions(+), 34 deletions(-) diff --git a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs index 10267c8ef7..da0c7f60cf 100644 --- a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs +++ b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs @@ -27,7 +27,7 @@ public static class AdvancedImageExtensions Guard.NotNull(filePath, nameof(filePath)); string ext = Path.GetExtension(filePath); - IImageFormat format = source.GetConfiguration().ImageFormatsManager.FindFormatByFileExtension(ext); + IImageFormat? format = source.GetConfiguration().ImageFormatsManager.FindFormatByFileExtension(ext); if (format is null) { StringBuilder sb = new(); @@ -40,7 +40,7 @@ public static class AdvancedImageExtensions throw new NotSupportedException(sb.ToString()); } - IImageEncoder encoder = source.GetConfiguration().ImageFormatsManager.FindEncoder(format); + IImageEncoder? encoder = source.GetConfiguration().ImageFormatsManager.FindEncoder(format); if (encoder is null) { diff --git a/src/ImageSharp/Formats/Bmp/BmpImageFormatDetector.cs b/src/ImageSharp/Formats/Bmp/BmpImageFormatDetector.cs index 4957b7ba73..162c8ed399 100644 --- a/src/ImageSharp/Formats/Bmp/BmpImageFormatDetector.cs +++ b/src/ImageSharp/Formats/Bmp/BmpImageFormatDetector.cs @@ -1,6 +1,5 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -#nullable disable using System.Buffers.Binary; @@ -15,7 +14,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 c826765009..db3d429046 100644 --- a/src/ImageSharp/Formats/Gif/GifImageFormatDetector.cs +++ b/src/ImageSharp/Formats/Gif/GifImageFormatDetector.cs @@ -1,6 +1,5 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -#nullable disable namespace SixLabors.ImageSharp.Formats.Gif; @@ -13,7 +12,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..e1bdc41f8f 100644 --- a/src/ImageSharp/Formats/IImageFormatDetector.cs +++ b/src/ImageSharp/Formats/IImageFormatDetector.cs @@ -19,5 +19,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/ImageDecoderUtilities.cs b/src/ImageSharp/Formats/ImageDecoderUtilities.cs index 50635dbefb..2a5b91b094 100644 --- a/src/ImageSharp/Formats/ImageDecoderUtilities.cs +++ b/src/ImageSharp/Formats/ImageDecoderUtilities.cs @@ -1,6 +1,5 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -#nullable disable using SixLabors.ImageSharp.IO; using SixLabors.ImageSharp.Memory; diff --git a/src/ImageSharp/Formats/ImageFormatManager.cs b/src/ImageSharp/Formats/ImageFormatManager.cs index dc09bb6a13..85424e7b8c 100644 --- a/src/ImageSharp/Formats/ImageFormatManager.cs +++ b/src/ImageSharp/Formats/ImageFormatManager.cs @@ -1,6 +1,5 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -#nullable disable using System.Collections.Concurrent; @@ -93,7 +92,7 @@ public class ImageFormatManager /// /// The extension to discover /// The if found otherwise null - public IImageFormat FindFormatByFileExtension(string extension) + public IImageFormat? FindFormatByFileExtension(string extension) { Guard.NotNullOrWhiteSpace(extension, nameof(extension)); @@ -110,7 +109,7 @@ public class ImageFormatManager /// /// 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)); /// @@ -160,11 +159,11 @@ public class ImageFormatManager /// /// 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; } @@ -174,11 +173,11 @@ public class ImageFormatManager /// /// 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 54e1b28ee3..3bf7346ff3 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegImageFormatDetector.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegImageFormatDetector.cs @@ -1,6 +1,5 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -#nullable disable namespace SixLabors.ImageSharp.Formats.Jpeg; @@ -13,7 +12,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 01ad9c62be..021cff2670 100644 --- a/src/ImageSharp/Formats/Pbm/PbmImageFormatDetector.cs +++ b/src/ImageSharp/Formats/Pbm/PbmImageFormatDetector.cs @@ -1,6 +1,5 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -#nullable disable namespace SixLabors.ImageSharp.Formats.Pbm; @@ -17,7 +16,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 a389428070..2e20668248 100644 --- a/src/ImageSharp/Formats/Png/PngImageFormatDetector.cs +++ b/src/ImageSharp/Formats/Png/PngImageFormatDetector.cs @@ -1,6 +1,5 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -#nullable disable using System.Buffers.Binary; @@ -15,7 +14,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 82246f3474..13d4e784c9 100644 --- a/src/ImageSharp/Formats/Tga/TgaImageFormatDetector.cs +++ b/src/ImageSharp/Formats/Tga/TgaImageFormatDetector.cs @@ -1,6 +1,5 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -#nullable disable namespace SixLabors.ImageSharp.Formats.Tga; @@ -13,7 +12,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 c48014024f..9af6a659e3 100644 --- a/src/ImageSharp/Formats/Tiff/TiffImageFormatDetector.cs +++ b/src/ImageSharp/Formats/Tiff/TiffImageFormatDetector.cs @@ -1,6 +1,5 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -#nullable disable namespace SixLabors.ImageSharp.Formats.Tiff; @@ -13,7 +12,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 9b52492aaa..3b30a2cfb5 100644 --- a/src/ImageSharp/Formats/Webp/WebpImageFormatDetector.cs +++ b/src/ImageSharp/Formats/Webp/WebpImageFormatDetector.cs @@ -1,6 +1,5 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -#nullable disable namespace SixLabors.ImageSharp.Formats.Webp; @@ -13,7 +12,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.FromBytes.cs b/src/ImageSharp/Image.FromBytes.cs index 2ea2b9d432..0d36e397c1 100644 --- a/src/ImageSharp/Image.FromBytes.cs +++ b/src/ImageSharp/Image.FromBytes.cs @@ -1,6 +1,5 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -#nullable disable using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.PixelFormats; @@ -17,7 +16,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); /// @@ -27,7 +26,7 @@ public abstract partial class Image /// 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)); @@ -40,7 +39,7 @@ public abstract partial class Image foreach (IImageFormatDetector detector in configuration.ImageFormatsManager.FormatDetectors) { - IImageFormat f = detector.DetectFormat(data); + IImageFormat? f = detector.DetectFormat(data); if (f != null) { diff --git a/src/ImageSharp/Image{TPixel}.cs b/src/ImageSharp/Image{TPixel}.cs index 01dd727fc0..31fd015096 100644 --- a/src/ImageSharp/Image{TPixel}.cs +++ b/src/ImageSharp/Image{TPixel}.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -#nullable disable -using System.Buffers; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using SixLabors.ImageSharp.Advanced; @@ -420,7 +418,7 @@ public sealed class Image : Image { Guard.NotNull(frames, nameof(frames)); - ImageFrame rootFrame = frames.FirstOrDefault(); + ImageFrame? rootFrame = frames.FirstOrDefault(); if (rootFrame == null) {