Browse Source

Remove nullable disable from various files

pull/2353/head
Stefan Nikolei 4 years ago
parent
commit
f047392bf0
  1. 7
      src/ImageSharp/Common/Helpers/Guard.cs
  2. 3
      src/ImageSharp/ImageExtensions.cs
  3. 26
      src/ImageSharp/ImageFrame{TPixel}.cs
  4. 3
      src/ImageSharp/IndexedImageFrame{TPixel}.cs
  5. 9
      src/ImageSharp/Processing/Extensions/ProcessingExtensions.cs
  6. 2
      src/ImageSharp/Processing/Processors/Transforms/Linear/AffineTransformProcessor.cs
  7. 2
      src/ImageSharp/Processing/Processors/Transforms/Linear/ProjectiveTransformProcessor.cs
  8. 2
      src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor.cs

7
src/ImageSharp/Common/Helpers/Guard.cs

@ -1,9 +1,9 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Six Labors Split License. // Licensed under the Six Labors Split License.
#nullable disable
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using SixLabors.ImageSharp; using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Processing.Processors.Transforms;
namespace SixLabors; namespace SixLabors;
@ -17,13 +17,14 @@ internal static partial class Guard
/// <typeparam name="TValue">The type of the value.</typeparam> /// <typeparam name="TValue">The type of the value.</typeparam>
/// <exception cref="ArgumentException"><paramref name="value"/> is not a value type.</exception> /// <exception cref="ArgumentException"><paramref name="value"/> is not a value type.</exception>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public static void MustBeValueType<TValue>(TValue value, string parameterName) public static void SamplerMustBeValueType<TValue>(TValue value, [CallerArgumentExpression("value")] string? parameterName = null)
where TValue : IResampler
{ {
if (value.GetType().IsValueType) if (value.GetType().IsValueType)
{ {
return; return;
} }
ThrowHelper.ThrowArgumentException("Type must be a struct.", parameterName); ThrowHelper.ThrowArgumentException("Type must be a struct.", parameterName!);
} }
} }

3
src/ImageSharp/ImageExtensions.cs

@ -1,6 +1,5 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Six Labors Split License. // Licensed under the Six Labors Split License.
#nullable disable
using System.Globalization; using System.Globalization;
using System.Text; using System.Text;
@ -180,6 +179,6 @@ public static partial class ImageExtensions
// Always available. // Always available.
stream.TryGetBuffer(out ArraySegment<byte> buffer); stream.TryGetBuffer(out ArraySegment<byte> buffer);
return $"data:{format.DefaultMimeType};base64,{Convert.ToBase64String(buffer.Array, 0, (int)stream.Length)}"; return $"data:{format.DefaultMimeType};base64,{Convert.ToBase64String(buffer.Array ?? Array.Empty<byte>(), 0, (int)stream.Length)}";
} }
} }

26
src/ImageSharp/ImageFrame{TPixel}.cs

@ -1,6 +1,5 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Six Labors Split License. // Licensed under the Six Labors Split License.
#nullable disable
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -183,7 +182,7 @@ public sealed class ImageFrame<TPixel> : ImageFrame, IPixelSource<TPixel>
try try
{ {
var accessor = new PixelAccessor<TPixel>(this.PixelBuffer); PixelAccessor<TPixel> accessor = new(this.PixelBuffer);
processPixels(accessor); processPixels(accessor);
} }
finally finally
@ -211,8 +210,8 @@ public sealed class ImageFrame<TPixel> : ImageFrame, IPixelSource<TPixel>
try try
{ {
var accessor1 = new PixelAccessor<TPixel>(this.PixelBuffer); PixelAccessor<TPixel> accessor1 = new(this.PixelBuffer);
var accessor2 = new PixelAccessor<TPixel2>(frame2.PixelBuffer); PixelAccessor<TPixel2> accessor2 = new(frame2.PixelBuffer);
processPixels(accessor1, accessor2); processPixels(accessor1, accessor2);
} }
finally finally
@ -247,9 +246,9 @@ public sealed class ImageFrame<TPixel> : ImageFrame, IPixelSource<TPixel>
try try
{ {
var accessor1 = new PixelAccessor<TPixel>(this.PixelBuffer); PixelAccessor<TPixel> accessor1 = new(this.PixelBuffer);
var accessor2 = new PixelAccessor<TPixel2>(frame2.PixelBuffer); PixelAccessor<TPixel2> accessor2 = new(frame2.PixelBuffer);
var accessor3 = new PixelAccessor<TPixel3>(frame3.PixelBuffer); PixelAccessor<TPixel3> accessor3 = new(frame3.PixelBuffer);
processPixels(accessor1, accessor2, accessor3); processPixels(accessor1, accessor2, accessor3);
} }
finally finally
@ -342,8 +341,7 @@ public sealed class ImageFrame<TPixel> : ImageFrame, IPixelSource<TPixel>
if (disposing) if (disposing)
{ {
this.PixelBuffer?.Dispose(); this.PixelBuffer.Dispose();
this.PixelBuffer = null;
} }
this.isDisposed = true; this.isDisposed = true;
@ -379,14 +377,14 @@ public sealed class ImageFrame<TPixel> : ImageFrame, IPixelSource<TPixel>
/// </summary> /// </summary>
/// <param name="configuration">The configuration providing initialization code which allows extending the library.</param> /// <param name="configuration">The configuration providing initialization code which allows extending the library.</param>
/// <returns>The <see cref="ImageFrame{TPixel}"/></returns> /// <returns>The <see cref="ImageFrame{TPixel}"/></returns>
internal ImageFrame<TPixel> Clone(Configuration configuration) => new ImageFrame<TPixel>(configuration, this); internal ImageFrame<TPixel> Clone(Configuration configuration) => new(configuration, this);
/// <summary> /// <summary>
/// Returns a copy of the image frame in the given pixel format. /// Returns a copy of the image frame in the given pixel format.
/// </summary> /// </summary>
/// <typeparam name="TPixel2">The pixel format.</typeparam> /// <typeparam name="TPixel2">The pixel format.</typeparam>
/// <returns>The <see cref="ImageFrame{TPixel2}"/></returns> /// <returns>The <see cref="ImageFrame{TPixel2}"/></returns>
internal ImageFrame<TPixel2> CloneAs<TPixel2>() internal ImageFrame<TPixel2>? CloneAs<TPixel2>()
where TPixel2 : unmanaged, IPixel<TPixel2> => this.CloneAs<TPixel2>(this.GetConfiguration()); where TPixel2 : unmanaged, IPixel<TPixel2> => this.CloneAs<TPixel2>(this.GetConfiguration());
/// <summary> /// <summary>
@ -400,11 +398,11 @@ public sealed class ImageFrame<TPixel> : ImageFrame, IPixelSource<TPixel>
{ {
if (typeof(TPixel2) == typeof(TPixel)) if (typeof(TPixel2) == typeof(TPixel))
{ {
return this.Clone(configuration) as ImageFrame<TPixel2>; return (this.Clone(configuration) as ImageFrame<TPixel2>)!;
} }
var target = new ImageFrame<TPixel2>(configuration, this.Width, this.Height, this.Metadata.DeepClone()); ImageFrame<TPixel2> target = new(configuration, this.Width, this.Height, this.Metadata.DeepClone());
var operation = new RowIntervalOperation<TPixel2>(this.PixelBuffer, target.PixelBuffer, configuration); RowIntervalOperation<TPixel2> operation = new(this.PixelBuffer, target.PixelBuffer, configuration);
ParallelRowIterator.IterateRowIntervals( ParallelRowIterator.IterateRowIntervals(
configuration, configuration,

3
src/ImageSharp/IndexedImageFrame{TPixel}.cs

@ -1,6 +1,5 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Six Labors Split License. // Licensed under the Six Labors Split License.
#nullable disable
using System.Buffers; using System.Buffers;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
@ -109,8 +108,6 @@ public sealed class IndexedImageFrame<TPixel> : IPixelSource, IDisposable
this.isDisposed = true; this.isDisposed = true;
this.pixelBuffer.Dispose(); this.pixelBuffer.Dispose();
this.paletteOwner.Dispose(); this.paletteOwner.Dispose();
this.pixelBuffer = null;
this.paletteOwner = null;
} }
} }
} }

9
src/ImageSharp/Processing/Extensions/ProcessingExtensions.cs

@ -1,6 +1,5 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Six Labors Split License. // Licensed under the Six Labors Split License.
#nullable disable
using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
@ -135,7 +134,7 @@ public static partial class ProcessingExtensions
/// <exception cref="ArgumentNullException">The operation is null.</exception> /// <exception cref="ArgumentNullException">The operation is null.</exception>
/// <exception cref="ObjectDisposedException">The source has been disposed.</exception> /// <exception cref="ObjectDisposedException">The source has been disposed.</exception>
/// <exception cref="ImageProcessingException">The processing operation failed.</exception> /// <exception cref="ImageProcessingException">The processing operation failed.</exception>
public static Image Clone(this Image source, Action<IImageProcessingContext> operation) public static Image? Clone(this Image source, Action<IImageProcessingContext> operation)
=> Clone(source, source.GetConfiguration(), operation); => Clone(source, source.GetConfiguration(), operation);
/// <summary> /// <summary>
@ -150,14 +149,14 @@ public static partial class ProcessingExtensions
/// <exception cref="ObjectDisposedException">The source has been disposed.</exception> /// <exception cref="ObjectDisposedException">The source has been disposed.</exception>
/// <exception cref="ImageProcessingException">The processing operation failed.</exception> /// <exception cref="ImageProcessingException">The processing operation failed.</exception>
/// <returns>The new <see cref="Image"/>.</returns> /// <returns>The new <see cref="Image"/>.</returns>
public static Image Clone(this Image source, Configuration configuration, Action<IImageProcessingContext> operation) public static Image? Clone(this Image source, Configuration configuration, Action<IImageProcessingContext> operation)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.NotNull(source, nameof(source)); Guard.NotNull(source, nameof(source));
Guard.NotNull(operation, nameof(operation)); Guard.NotNull(operation, nameof(operation));
source.EnsureNotDisposed(); source.EnsureNotDisposed();
var visitor = new ProcessingVisitor(configuration, operation, false); ProcessingVisitor visitor = new(configuration, operation, false);
source.AcceptVisitor(visitor); source.AcceptVisitor(visitor);
return visitor.ResultImage; return visitor.ResultImage;
} }
@ -282,7 +281,7 @@ public static partial class ProcessingExtensions
this.mutate = mutate; this.mutate = mutate;
} }
public Image ResultImage { get; private set; } public Image? ResultImage { get; private set; }
public void Visit<TPixel>(Image<TPixel> image) public void Visit<TPixel>(Image<TPixel> image)
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>

2
src/ImageSharp/Processing/Processors/Transforms/Linear/AffineTransformProcessor.cs

@ -19,7 +19,7 @@ public class AffineTransformProcessor : CloningImageProcessor
public AffineTransformProcessor(Matrix3x2 matrix, IResampler sampler, Size targetDimensions) public AffineTransformProcessor(Matrix3x2 matrix, IResampler sampler, Size targetDimensions)
{ {
Guard.NotNull(sampler, nameof(sampler)); Guard.NotNull(sampler, nameof(sampler));
Guard.MustBeValueType(sampler, nameof(sampler)); Guard.SamplerMustBeValueType(sampler);
if (TransformUtils.IsDegenerate(matrix)) if (TransformUtils.IsDegenerate(matrix))
{ {

2
src/ImageSharp/Processing/Processors/Transforms/Linear/ProjectiveTransformProcessor.cs

@ -19,7 +19,7 @@ public sealed class ProjectiveTransformProcessor : CloningImageProcessor
public ProjectiveTransformProcessor(Matrix4x4 matrix, IResampler sampler, Size targetDimensions) public ProjectiveTransformProcessor(Matrix4x4 matrix, IResampler sampler, Size targetDimensions)
{ {
Guard.NotNull(sampler, nameof(sampler)); Guard.NotNull(sampler, nameof(sampler));
Guard.MustBeValueType(sampler, nameof(sampler)); Guard.SamplerMustBeValueType(sampler);
if (TransformUtils.IsDegenerate(matrix)) if (TransformUtils.IsDegenerate(matrix))
{ {

2
src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor.cs

@ -17,7 +17,7 @@ public class ResizeProcessor : CloningImageProcessor
{ {
Guard.NotNull(options, nameof(options)); Guard.NotNull(options, nameof(options));
Guard.NotNull(options.Sampler, nameof(options.Sampler)); Guard.NotNull(options.Sampler, nameof(options.Sampler));
Guard.MustBeValueType(options.Sampler, nameof(options.Sampler)); Guard.SamplerMustBeValueType(options.Sampler);
(Size size, Rectangle rectangle) = ResizeHelper.CalculateTargetLocationAndBounds(sourceSize, options); (Size size, Rectangle rectangle) = ResizeHelper.CalculateTargetLocationAndBounds(sourceSize, options);

Loading…
Cancel
Save