Skip to content

Commit 52efdbf

Browse files
Merge pull request #2338 from stefannikolei/stefannikolei/nullable/processing
Remove nullable disable from Processing.Processors
2 parents 997884c + df803cd commit 52efdbf

12 files changed

+41
-52
lines changed

src/ImageSharp/Formats/Gif/GifEncoderCore.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ private void EncodeFrames<TPixel>(
171171
quantized = null;
172172
}
173173

174-
paletteQuantizer.Dispose();
174+
if (hasPaletteQuantizer)
175+
{
176+
paletteQuantizer.Dispose();
177+
}
175178
}
176179

177180
private void EncodeFrame<TPixel>(

src/ImageSharp/Processing/DefaultImageProcessorContext{TPixel}.cs

Lines changed: 3 additions & 4 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.Collections.Concurrent;
65
using SixLabors.ImageSharp.PixelFormats;
@@ -17,7 +16,7 @@ internal class DefaultImageProcessorContext<TPixel> : IInternalImageProcessingCo
1716
{
1817
private readonly bool mutate;
1918
private readonly Image<TPixel> source;
20-
private Image<TPixel> destination;
19+
private Image<TPixel>? destination;
2120

2221
/// <summary>
2322
/// Initializes a new instance of the <see cref="DefaultImageProcessorContext{TPixel}"/> class.
@@ -54,7 +53,7 @@ public Image<TPixel> GetResultImage()
5453
this.destination = this.source.Clone();
5554
}
5655

57-
return this.destination;
56+
return this.destination!;
5857
}
5958

6059
/// <inheritdoc/>
@@ -87,7 +86,7 @@ public IImageProcessingContext ApplyProcessor(IImageProcessor processor, Rectang
8786
}
8887

8988
// Standard processing pipeline.
90-
using (IImageProcessor<TPixel> specificProcessor = processor.CreatePixelSpecificProcessor(this.Configuration, this.destination, rectangle))
89+
using (IImageProcessor<TPixel> specificProcessor = processor.CreatePixelSpecificProcessor(this.Configuration, this.destination!, rectangle))
9190
{
9291
specificProcessor.Execute();
9392
}

src/ImageSharp/Processing/Processors/Convolution/KernelSamplingMap.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 System.Buffers;
65
using System.Runtime.CompilerServices;
@@ -16,8 +15,8 @@ internal sealed class KernelSamplingMap : IDisposable
1615
{
1716
private readonly MemoryAllocator allocator;
1817
private bool isDisposed;
19-
private IMemoryOwner<int> yOffsets;
20-
private IMemoryOwner<int> xOffsets;
18+
private IMemoryOwner<int>? yOffsets;
19+
private IMemoryOwner<int>? xOffsets;
2120

2221
/// <summary>
2322
/// Initializes a new instance of the <see cref="KernelSamplingMap"/> class.
@@ -65,10 +64,10 @@ public void BuildSamplingOffsetMap(int kernelHeight, int kernelWidth, Rectangle
6564
}
6665

6766
[MethodImpl(MethodImplOptions.AggressiveInlining)]
68-
public Span<int> GetRowOffsetSpan() => this.yOffsets.GetSpan();
67+
public Span<int> GetRowOffsetSpan() => this.yOffsets!.GetSpan();
6968

7069
[MethodImpl(MethodImplOptions.AggressiveInlining)]
71-
public Span<int> GetColumnOffsetSpan() => this.xOffsets.GetSpan();
70+
public Span<int> GetColumnOffsetSpan() => this.xOffsets!.GetSpan();
7271

7372
/// <inheritdoc/>
7473
public void Dispose()

src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor.cs

Lines changed: 2 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 SixLabors.ImageSharp.Advanced;
65
using SixLabors.ImageSharp.PixelFormats;
@@ -65,7 +64,7 @@ public IImageProcessor<TPixelBg> CreatePixelSpecificProcessor<TPixelBg>(Configur
6564
{
6665
ProcessorFactoryVisitor<TPixelBg> visitor = new(configuration, this, source, sourceRectangle);
6766
this.Image.AcceptVisitor(visitor);
68-
return visitor.Result;
67+
return visitor.Result!;
6968
}
7069

7170
private class ProcessorFactoryVisitor<TPixelBg> : IImageVisitor
@@ -84,7 +83,7 @@ public ProcessorFactoryVisitor(Configuration configuration, DrawImageProcessor d
8483
this.sourceRectangle = sourceRectangle;
8584
}
8685

87-
public IImageProcessor<TPixelBg> Result { get; private set; }
86+
public IImageProcessor<TPixelBg>? Result { get; private set; }
8887

8988
public void Visit<TPixelFg>(Image<TPixelFg> image)
9089
where TPixelFg : unmanaged, IPixel<TPixelFg>

src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{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.Buffers;
65
using System.Diagnostics.CodeAnalysis;
@@ -29,7 +28,7 @@ public struct OctreeQuantizer<TPixel> : IQuantizer<TPixel>
2928
private readonly Octree octree;
3029
private IMemoryOwner<TPixel> paletteOwner;
3130
private ReadOnlyMemory<TPixel> palette;
32-
private EuclideanPixelMap<TPixel> pixelMap;
31+
private EuclideanPixelMap<TPixel>? pixelMap;
3332
private readonly bool isDithering;
3433
private bool isDisposed;
3534

@@ -143,7 +142,7 @@ public readonly byte GetQuantizedColor(TPixel color, out TPixel match)
143142
// pixel and a black one.
144143
if (this.isDithering || color.Equals(default))
145144
{
146-
return (byte)this.pixelMap.GetClosestColor(color, out match);
145+
return (byte)this.pixelMap!.GetClosestColor(color, out match);
147146
}
148147

149148
ref TPixel paletteRef = ref MemoryMarshal.GetReference(this.palette.Span);
@@ -158,8 +157,7 @@ public void Dispose()
158157
if (!this.isDisposed)
159158
{
160159
this.isDisposed = true;
161-
this.paletteOwner?.Dispose();
162-
this.paletteOwner = null;
160+
this.paletteOwner.Dispose();
163161
this.pixelMap?.Dispose();
164162
this.pixelMap = null;
165163
}
@@ -183,7 +181,7 @@ private sealed class Octree
183181
/// <summary>
184182
/// Store the last node quantized
185183
/// </summary>
186-
private OctreeNode previousNode;
184+
private OctreeNode? previousNode;
187185

188186
/// <summary>
189187
/// Cache the previous color quantized
@@ -221,7 +219,7 @@ public int Leaves
221219
/// <summary>
222220
/// Gets the array of reducible nodes
223221
/// </summary>
224-
private OctreeNode[] ReducibleNodes
222+
private OctreeNode?[] ReducibleNodes
225223
{
226224
[MethodImpl(InliningOptions.ShortMethod)]
227225
get;
@@ -311,7 +309,7 @@ private void Reduce()
311309
}
312310

313311
// Reduce the node most recently added to the list at level 'index'
314-
OctreeNode node = this.ReducibleNodes[index];
312+
OctreeNode node = this.ReducibleNodes[index]!;
315313
this.ReducibleNodes[index] = node.NextReducible;
316314

317315
// Decrement the leaf count after reducing the node
@@ -330,7 +328,7 @@ public sealed class OctreeNode
330328
/// <summary>
331329
/// Pointers to any child nodes
332330
/// </summary>
333-
private readonly OctreeNode[] children;
331+
private readonly OctreeNode?[]? children;
334332

335333
/// <summary>
336334
/// Flag indicating that this is a leaf node
@@ -395,7 +393,7 @@ public OctreeNode(int level, int colorBits, Octree octree)
395393
/// <summary>
396394
/// Gets the next reducible node
397395
/// </summary>
398-
public OctreeNode NextReducible
396+
public OctreeNode? NextReducible
399397
{
400398
[MethodImpl(InliningOptions.ShortMethod)]
401399
get;
@@ -423,7 +421,7 @@ public void AddColor(ref Rgba32 color, int colorBits, int level, Octree octree)
423421
// Go to the next level down in the tree
424422
int index = GetColorIndex(ref color, level);
425423

426-
OctreeNode child = this.children[index];
424+
OctreeNode? child = this.children![index];
427425
if (child is null)
428426
{
429427
// Create a new child node and store it in the array
@@ -448,7 +446,7 @@ public int Reduce()
448446
// Loop through all children and add their information to this node
449447
for (int index = 0; index < 8; index++)
450448
{
451-
OctreeNode child = this.children[index];
449+
OctreeNode? child = this.children![index];
452450
if (child != null)
453451
{
454452
this.red += child.red;
@@ -495,7 +493,7 @@ public void ConstructPalette(Span<TPixel> palette, ref int index)
495493
// Loop through children looking for leaves
496494
for (int i = 0; i < 8; i++)
497495
{
498-
this.children[i]?.ConstructPalette(palette, ref index);
496+
this.children![i]?.ConstructPalette(palette, ref index);
499497
}
500498
}
501499
}
@@ -517,7 +515,7 @@ public int GetPaletteIndex(ref Rgba32 pixel, int level)
517515
}
518516

519517
int colorIndex = GetColorIndex(ref pixel, level);
520-
OctreeNode child = this.children[colorIndex];
518+
OctreeNode? child = this.children![colorIndex];
521519

522520
int index = 0;
523521
if (child != null)

src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer{TPixel}.cs

Lines changed: 1 addition & 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.Diagnostics.CodeAnalysis;
65
using System.Runtime.CompilerServices;
@@ -68,7 +67,6 @@ public readonly byte GetQuantizedColor(TPixel color, out TPixel match)
6867
/// <inheritdoc/>
6968
public void Dispose()
7069
{
71-
this.pixelMap?.Dispose();
72-
this.pixelMap = null;
70+
this.pixelMap.Dispose();
7371
}
7472
}

src/ImageSharp/Processing/Processors/Quantization/QuantizerOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class QuantizerOptions
1717
/// Gets or sets the algorithm to apply to the output image.
1818
/// Defaults to <see cref="QuantizerConstants.DefaultDither"/>; set to <see langword="null"/> for no dithering.
1919
/// </summary>
20-
public IDither Dither { get; set; } = QuantizerConstants.DefaultDither;
20+
public IDither? Dither { get; set; } = QuantizerConstants.DefaultDither;
2121

2222
/// <summary>
2323
/// Gets or sets the dithering scale used to adjust the amount of dither. Range 0..1.

src/ImageSharp/Processing/Processors/Quantization/QuantizerUtilities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private static void SecondPass<TFrameQuantizer, TPixel>(
146146
where TFrameQuantizer : struct, IQuantizer<TPixel>
147147
where TPixel : unmanaged, IPixel<TPixel>
148148
{
149-
IDither dither = quantizer.Options.Dither;
149+
IDither? dither = quantizer.Options.Dither;
150150
Buffer2D<TPixel> sourceBuffer = source.PixelBuffer;
151151

152152
if (dither is null)

src/ImageSharp/Processing/Processors/Quantization/WuQuantizer{TPixel}.cs

Lines changed: 3 additions & 7 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.Diagnostics.CodeAnalysis;
@@ -76,7 +75,7 @@ internal struct WuQuantizer<TPixel> : IQuantizer<TPixel>
7675
private ReadOnlyMemory<TPixel> palette;
7776
private int maxColors;
7877
private readonly Box[] colorCube;
79-
private EuclideanPixelMap<TPixel> pixelMap;
78+
private EuclideanPixelMap<TPixel>? pixelMap;
8079
private readonly bool isDithering;
8180
private bool isDisposed;
8281

@@ -175,7 +174,7 @@ public readonly byte GetQuantizedColor(TPixel color, out TPixel match)
175174
{
176175
if (this.isDithering)
177176
{
178-
return (byte)this.pixelMap.GetClosestColor(color, out match);
177+
return (byte)this.pixelMap!.GetClosestColor(color, out match);
179178
}
180179

181180
Rgba32 rgba = default;
@@ -203,9 +202,6 @@ public void Dispose()
203202
this.momentsOwner?.Dispose();
204203
this.tagsOwner?.Dispose();
205204
this.paletteOwner?.Dispose();
206-
this.momentsOwner = null;
207-
this.tagsOwner = null;
208-
this.paletteOwner = null;
209205
this.pixelMap?.Dispose();
210206
this.pixelMap = null;
211207
}
@@ -869,7 +865,7 @@ private struct Box : IEquatable<Box>
869865
public int Volume;
870866

871867
/// <inheritdoc/>
872-
public override readonly bool Equals(object obj)
868+
public override readonly bool Equals(object? obj)
873869
=> obj is Box box
874870
&& this.Equals(box);
875871

src/ImageSharp/Processing/Processors/Transforms/Linear/AffineTransformProcessor{TPixel}.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 System.Numerics;
65
using System.Runtime.CompilerServices;
@@ -20,8 +19,8 @@ internal class AffineTransformProcessor<TPixel> : TransformProcessor<TPixel>, IR
2019
private readonly Size destinationSize;
2120
private readonly Matrix3x2 transformMatrix;
2221
private readonly IResampler resampler;
23-
private ImageFrame<TPixel> source;
24-
private ImageFrame<TPixel> destination;
22+
private ImageFrame<TPixel>? source;
23+
private ImageFrame<TPixel>? destination;
2524

2625
/// <summary>
2726
/// Initializes a new instance of the <see cref="AffineTransformProcessor{TPixel}"/> class.
@@ -53,8 +52,8 @@ public void ApplyTransform<TResampler>(in TResampler sampler)
5352
where TResampler : struct, IResampler
5453
{
5554
Configuration configuration = this.Configuration;
56-
ImageFrame<TPixel> source = this.source;
57-
ImageFrame<TPixel> destination = this.destination;
55+
ImageFrame<TPixel> source = this.source!;
56+
ImageFrame<TPixel> destination = this.destination!;
5857
Matrix3x2 matrix = this.transformMatrix;
5958

6059
// Handle transforms that result in output identical to the original.

0 commit comments

Comments
 (0)