Browse Source

Remove nullable disable

* FormatDetecot
* ImageFormatManager
* DecoderUtilities (Not needed)
pull/2312/head
Stefan Nikolei 3 years ago
parent
commit
e2872c1064
  1. 4
      src/ImageSharp/Advanced/AdvancedImageExtensions.cs
  2. 3
      src/ImageSharp/Formats/Bmp/BmpImageFormatDetector.cs
  3. 3
      src/ImageSharp/Formats/Gif/GifImageFormatDetector.cs
  4. 2
      src/ImageSharp/Formats/IImageFormatDetector.cs
  5. 1
      src/ImageSharp/Formats/ImageDecoderUtilities.cs
  6. 13
      src/ImageSharp/Formats/ImageFormatManager.cs
  7. 3
      src/ImageSharp/Formats/Jpeg/JpegImageFormatDetector.cs
  8. 3
      src/ImageSharp/Formats/Pbm/PbmImageFormatDetector.cs
  9. 3
      src/ImageSharp/Formats/Png/PngImageFormatDetector.cs
  10. 3
      src/ImageSharp/Formats/Tga/TgaImageFormatDetector.cs
  11. 3
      src/ImageSharp/Formats/Tiff/TiffImageFormatDetector.cs
  12. 3
      src/ImageSharp/Formats/Webp/WebpImageFormatDetector.cs
  13. 7
      src/ImageSharp/Image.FromBytes.cs
  14. 4
      src/ImageSharp/Image{TPixel}.cs

4
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)
{

3
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;
/// <inheritdoc/>
public IImageFormat DetectFormat(ReadOnlySpan<byte> header)
public IImageFormat? DetectFormat(ReadOnlySpan<byte> header)
{
return this.IsSupportedFileFormat(header) ? BmpFormat.Instance : null;
}

3
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;
/// <inheritdoc/>
public IImageFormat DetectFormat(ReadOnlySpan<byte> header)
public IImageFormat? DetectFormat(ReadOnlySpan<byte> header)
{
return this.IsSupportedFileFormat(header) ? GifFormat.Instance : null;
}

2
src/ImageSharp/Formats/IImageFormatDetector.cs

@ -19,5 +19,5 @@ public interface IImageFormatDetector
/// </summary>
/// <param name="header">The <see cref="T:byte[]"/> containing the file header.</param>
/// <returns>returns the mime type of detected otherwise returns null</returns>
IImageFormat DetectFormat(ReadOnlySpan<byte> header);
IImageFormat? DetectFormat(ReadOnlySpan<byte> header);
}

1
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;

13
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
/// </summary>
/// <param name="extension">The extension to discover</param>
/// <returns>The <see cref="IImageFormat"/> if found otherwise null</returns>
public IImageFormat FindFormatByFileExtension(string extension)
public IImageFormat? FindFormatByFileExtension(string extension)
{
Guard.NotNullOrWhiteSpace(extension, nameof(extension));
@ -110,7 +109,7 @@ public class ImageFormatManager
/// </summary>
/// <param name="mimeType">The mime-type to discover</param>
/// <returns>The <see cref="IImageFormat"/> if found; otherwise null</returns>
public IImageFormat FindFormatByMimeType(string mimeType)
public IImageFormat? FindFormatByMimeType(string mimeType)
=> this.imageFormats.FirstOrDefault(x => x.MimeTypes.Contains(mimeType, StringComparer.OrdinalIgnoreCase));
/// <summary>
@ -160,11 +159,11 @@ public class ImageFormatManager
/// </summary>
/// <param name="format">The format to discover</param>
/// <returns>The <see cref="IImageDecoder"/> if found otherwise null</returns>
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
/// </summary>
/// <param name="format">The format to discover</param>
/// <returns>The <see cref="IImageEncoder"/> if found otherwise null</returns>
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;
}

3
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;
/// <inheritdoc/>
public IImageFormat DetectFormat(ReadOnlySpan<byte> header)
public IImageFormat? DetectFormat(ReadOnlySpan<byte> header)
=> this.IsSupportedFileFormat(header) ? JpegFormat.Instance : null;
private bool IsSupportedFileFormat(ReadOnlySpan<byte> header)

3
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;
/// <inheritdoc/>
public IImageFormat DetectFormat(ReadOnlySpan<byte> header) => IsSupportedFileFormat(header) ? PbmFormat.Instance : null;
public IImageFormat? DetectFormat(ReadOnlySpan<byte> header) => IsSupportedFileFormat(header) ? PbmFormat.Instance : null;
private static bool IsSupportedFileFormat(ReadOnlySpan<byte> header)
{

3
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;
/// <inheritdoc/>
public IImageFormat DetectFormat(ReadOnlySpan<byte> header)
public IImageFormat? DetectFormat(ReadOnlySpan<byte> header)
{
return this.IsSupportedFileFormat(header) ? PngFormat.Instance : null;
}

3
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;
/// <inheritdoc/>
public IImageFormat DetectFormat(ReadOnlySpan<byte> header)
public IImageFormat? DetectFormat(ReadOnlySpan<byte> header)
{
return this.IsSupportedFileFormat(header) ? TgaFormat.Instance : null;
}

3
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;
/// <inheritdoc/>
public IImageFormat DetectFormat(ReadOnlySpan<byte> header)
public IImageFormat? DetectFormat(ReadOnlySpan<byte> header)
{
if (this.IsSupportedFileFormat(header))
{

3
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;
/// <inheritdoc />
public IImageFormat DetectFormat(ReadOnlySpan<byte> header)
public IImageFormat? DetectFormat(ReadOnlySpan<byte> header)
=> this.IsSupportedFileFormat(header) ? WebpFormat.Instance : null;
private bool IsSupportedFileFormat(ReadOnlySpan<byte> header)

7
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
/// </summary>
/// <param name="data">The byte span containing encoded image data to read the header from.</param>
/// <returns>The format or null if none found.</returns>
public static IImageFormat DetectFormat(ReadOnlySpan<byte> data)
public static IImageFormat? DetectFormat(ReadOnlySpan<byte> data)
=> DetectFormat(DecoderOptions.Default, data);
/// <summary>
@ -27,7 +26,7 @@ public abstract partial class Image
/// <param name="data">The byte span containing encoded image data to read the header from.</param>
/// <exception cref="ArgumentNullException">The options are null.</exception>
/// <returns>The mime type or null if none found.</returns>
public static IImageFormat DetectFormat(DecoderOptions options, ReadOnlySpan<byte> data)
public static IImageFormat? DetectFormat(DecoderOptions options, ReadOnlySpan<byte> 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)
{

4
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<TPixel> : Image
{
Guard.NotNull(frames, nameof(frames));
ImageFrame<TPixel> rootFrame = frames.FirstOrDefault();
ImageFrame<TPixel>? rootFrame = frames.FirstOrDefault();
if (rootFrame == null)
{

Loading…
Cancel
Save