Skip to content

Commit f047392

Browse files
committed
Remove nullable disable from various files
1 parent 16903fa commit f047392

File tree

8 files changed

+24
-30
lines changed

8 files changed

+24
-30
lines changed

src/ImageSharp/Common/Helpers/Guard.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
3-
#nullable disable
43

54
using System.Runtime.CompilerServices;
65
using SixLabors.ImageSharp;
6+
using SixLabors.ImageSharp.Processing.Processors.Transforms;
77

88
namespace SixLabors;
99

@@ -17,13 +17,14 @@ internal static partial class Guard
1717
/// <typeparam name="TValue">The type of the value.</typeparam>
1818
/// <exception cref="ArgumentException"><paramref name="value"/> is not a value type.</exception>
1919
[MethodImpl(InliningOptions.ShortMethod)]
20-
public static void MustBeValueType<TValue>(TValue value, string parameterName)
20+
public static void SamplerMustBeValueType<TValue>(TValue value, [CallerArgumentExpression("value")] string? parameterName = null)
21+
where TValue : IResampler
2122
{
2223
if (value.GetType().IsValueType)
2324
{
2425
return;
2526
}
2627

27-
ThrowHelper.ThrowArgumentException("Type must be a struct.", parameterName);
28+
ThrowHelper.ThrowArgumentException("Type must be a struct.", parameterName!);
2829
}
2930
}

src/ImageSharp/ImageExtensions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
3-
#nullable disable
43

54
using System.Globalization;
65
using System.Text;
@@ -180,6 +179,6 @@ public static string ToBase64String(this Image source, IImageFormat format)
180179

181180
// Always available.
182181
stream.TryGetBuffer(out ArraySegment<byte> buffer);
183-
return $"data:{format.DefaultMimeType};base64,{Convert.ToBase64String(buffer.Array, 0, (int)stream.Length)}";
182+
return $"data:{format.DefaultMimeType};base64,{Convert.ToBase64String(buffer.Array ?? Array.Empty<byte>(), 0, (int)stream.Length)}";
184183
}
185184
}

src/ImageSharp/ImageFrame{TPixel}.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
3-
#nullable disable
43

54
using System.Runtime.CompilerServices;
65
using System.Runtime.InteropServices;
@@ -183,7 +182,7 @@ public void ProcessPixelRows(PixelAccessorAction<TPixel> processPixels)
183182

184183
try
185184
{
186-
var accessor = new PixelAccessor<TPixel>(this.PixelBuffer);
185+
PixelAccessor<TPixel> accessor = new(this.PixelBuffer);
187186
processPixels(accessor);
188187
}
189188
finally
@@ -211,8 +210,8 @@ public void ProcessPixelRows<TPixel2>(
211210

212211
try
213212
{
214-
var accessor1 = new PixelAccessor<TPixel>(this.PixelBuffer);
215-
var accessor2 = new PixelAccessor<TPixel2>(frame2.PixelBuffer);
213+
PixelAccessor<TPixel> accessor1 = new(this.PixelBuffer);
214+
PixelAccessor<TPixel2> accessor2 = new(frame2.PixelBuffer);
216215
processPixels(accessor1, accessor2);
217216
}
218217
finally
@@ -247,9 +246,9 @@ public void ProcessPixelRows<TPixel2, TPixel3>(
247246

248247
try
249248
{
250-
var accessor1 = new PixelAccessor<TPixel>(this.PixelBuffer);
251-
var accessor2 = new PixelAccessor<TPixel2>(frame2.PixelBuffer);
252-
var accessor3 = new PixelAccessor<TPixel3>(frame3.PixelBuffer);
249+
PixelAccessor<TPixel> accessor1 = new(this.PixelBuffer);
250+
PixelAccessor<TPixel2> accessor2 = new(frame2.PixelBuffer);
251+
PixelAccessor<TPixel3> accessor3 = new(frame3.PixelBuffer);
253252
processPixels(accessor1, accessor2, accessor3);
254253
}
255254
finally
@@ -342,8 +341,7 @@ protected override void Dispose(bool disposing)
342341

343342
if (disposing)
344343
{
345-
this.PixelBuffer?.Dispose();
346-
this.PixelBuffer = null;
344+
this.PixelBuffer.Dispose();
347345
}
348346

349347
this.isDisposed = true;
@@ -379,14 +377,14 @@ internal override void CopyPixelsTo<TDestinationPixel>(MemoryGroup<TDestinationP
379377
/// </summary>
380378
/// <param name="configuration">The configuration providing initialization code which allows extending the library.</param>
381379
/// <returns>The <see cref="ImageFrame{TPixel}"/></returns>
382-
internal ImageFrame<TPixel> Clone(Configuration configuration) => new ImageFrame<TPixel>(configuration, this);
380+
internal ImageFrame<TPixel> Clone(Configuration configuration) => new(configuration, this);
383381

384382
/// <summary>
385383
/// Returns a copy of the image frame in the given pixel format.
386384
/// </summary>
387385
/// <typeparam name="TPixel2">The pixel format.</typeparam>
388386
/// <returns>The <see cref="ImageFrame{TPixel2}"/></returns>
389-
internal ImageFrame<TPixel2> CloneAs<TPixel2>()
387+
internal ImageFrame<TPixel2>? CloneAs<TPixel2>()
390388
where TPixel2 : unmanaged, IPixel<TPixel2> => this.CloneAs<TPixel2>(this.GetConfiguration());
391389

392390
/// <summary>
@@ -400,11 +398,11 @@ internal ImageFrame<TPixel2> CloneAs<TPixel2>(Configuration configuration)
400398
{
401399
if (typeof(TPixel2) == typeof(TPixel))
402400
{
403-
return this.Clone(configuration) as ImageFrame<TPixel2>;
401+
return (this.Clone(configuration) as ImageFrame<TPixel2>)!;
404402
}
405403

406-
var target = new ImageFrame<TPixel2>(configuration, this.Width, this.Height, this.Metadata.DeepClone());
407-
var operation = new RowIntervalOperation<TPixel2>(this.PixelBuffer, target.PixelBuffer, configuration);
404+
ImageFrame<TPixel2> target = new(configuration, this.Width, this.Height, this.Metadata.DeepClone());
405+
RowIntervalOperation<TPixel2> operation = new(this.PixelBuffer, target.PixelBuffer, configuration);
408406

409407
ParallelRowIterator.IterateRowIntervals(
410408
configuration,

src/ImageSharp/IndexedImageFrame{TPixel}.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
3-
#nullable disable
43

54
using System.Buffers;
65
using System.Runtime.CompilerServices;
@@ -109,8 +108,6 @@ public void Dispose()
109108
this.isDisposed = true;
110109
this.pixelBuffer.Dispose();
111110
this.paletteOwner.Dispose();
112-
this.pixelBuffer = null;
113-
this.paletteOwner = null;
114111
}
115112
}
116113
}

src/ImageSharp/Processing/Extensions/ProcessingExtensions.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
3-
#nullable disable
43

54
using SixLabors.ImageSharp.Advanced;
65
using SixLabors.ImageSharp.PixelFormats;
@@ -135,7 +134,7 @@ IInternalImageProcessingContext<TPixel> operationsRunner
135134
/// <exception cref="ArgumentNullException">The operation is null.</exception>
136135
/// <exception cref="ObjectDisposedException">The source has been disposed.</exception>
137136
/// <exception cref="ImageProcessingException">The processing operation failed.</exception>
138-
public static Image Clone(this Image source, Action<IImageProcessingContext> operation)
137+
public static Image? Clone(this Image source, Action<IImageProcessingContext> operation)
139138
=> Clone(source, source.GetConfiguration(), operation);
140139

141140
/// <summary>
@@ -150,14 +149,14 @@ public static Image Clone(this Image source, Action<IImageProcessingContext> ope
150149
/// <exception cref="ObjectDisposedException">The source has been disposed.</exception>
151150
/// <exception cref="ImageProcessingException">The processing operation failed.</exception>
152151
/// <returns>The new <see cref="Image"/>.</returns>
153-
public static Image Clone(this Image source, Configuration configuration, Action<IImageProcessingContext> operation)
152+
public static Image? Clone(this Image source, Configuration configuration, Action<IImageProcessingContext> operation)
154153
{
155154
Guard.NotNull(configuration, nameof(configuration));
156155
Guard.NotNull(source, nameof(source));
157156
Guard.NotNull(operation, nameof(operation));
158157
source.EnsureNotDisposed();
159158

160-
var visitor = new ProcessingVisitor(configuration, operation, false);
159+
ProcessingVisitor visitor = new(configuration, operation, false);
161160
source.AcceptVisitor(visitor);
162161
return visitor.ResultImage;
163162
}
@@ -282,7 +281,7 @@ public ProcessingVisitor(Configuration configuration, Action<IImageProcessingCon
282281
this.mutate = mutate;
283282
}
284283

285-
public Image ResultImage { get; private set; }
284+
public Image? ResultImage { get; private set; }
286285

287286
public void Visit<TPixel>(Image<TPixel> image)
288287
where TPixel : unmanaged, IPixel<TPixel>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class AffineTransformProcessor : CloningImageProcessor
1919
public AffineTransformProcessor(Matrix3x2 matrix, IResampler sampler, Size targetDimensions)
2020
{
2121
Guard.NotNull(sampler, nameof(sampler));
22-
Guard.MustBeValueType(sampler, nameof(sampler));
22+
Guard.SamplerMustBeValueType(sampler);
2323

2424
if (TransformUtils.IsDegenerate(matrix))
2525
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public sealed class ProjectiveTransformProcessor : CloningImageProcessor
1919
public ProjectiveTransformProcessor(Matrix4x4 matrix, IResampler sampler, Size targetDimensions)
2020
{
2121
Guard.NotNull(sampler, nameof(sampler));
22-
Guard.MustBeValueType(sampler, nameof(sampler));
22+
Guard.SamplerMustBeValueType(sampler);
2323

2424
if (TransformUtils.IsDegenerate(matrix))
2525
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public ResizeProcessor(ResizeOptions options, Size sourceSize)
1717
{
1818
Guard.NotNull(options, nameof(options));
1919
Guard.NotNull(options.Sampler, nameof(options.Sampler));
20-
Guard.MustBeValueType(options.Sampler, nameof(options.Sampler));
20+
Guard.SamplerMustBeValueType(options.Sampler);
2121

2222
(Size size, Rectangle rectangle) = ResizeHelper.CalculateTargetLocationAndBounds(sourceSize, options);
2323

0 commit comments

Comments
 (0)