diff --git a/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs index 83e0a8b08f..d66a38d80d 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs @@ -26,7 +26,7 @@ public struct OctreeQuantizer : IQuantizer private readonly int maxColors; private readonly int bitDepth; private readonly Octree octree; - private IMemoryOwner? paletteOwner; + private IMemoryOwner paletteOwner; private ReadOnlyMemory palette; private EuclideanPixelMap? pixelMap; private readonly bool isDithering; @@ -98,7 +98,7 @@ public struct OctreeQuantizer : IQuantizer } int paletteIndex = 0; - Span paletteSpan = this.paletteOwner!.GetSpan(); + Span paletteSpan = this.paletteOwner.GetSpan(); // On very rare occasions, (blur.png), the quantizer does not preserve a // transparent entry when palletizing the captured colors. @@ -112,7 +112,7 @@ public struct OctreeQuantizer : IQuantizer } this.octree.Palletize(paletteSpan, max, ref paletteIndex); - ReadOnlyMemory result = this.paletteOwner!.Memory[..paletteSpan.Length]; + ReadOnlyMemory result = this.paletteOwner.Memory[..paletteSpan.Length]; // When called multiple times by QuantizerUtilities.BuildPalette // this prevents memory churn caused by reallocation. @@ -157,8 +157,7 @@ public struct OctreeQuantizer : IQuantizer if (!this.isDisposed) { this.isDisposed = true; - this.paletteOwner?.Dispose(); - this.paletteOwner = null; + this.paletteOwner.Dispose(); this.pixelMap?.Dispose(); this.pixelMap = null; } diff --git a/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer{TPixel}.cs index e73c87896f..ea7413aab4 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer{TPixel}.cs @@ -20,7 +20,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization; internal struct PaletteQuantizer : IQuantizer where TPixel : unmanaged, IPixel { - private EuclideanPixelMap? pixelMap; + private EuclideanPixelMap pixelMap; /// /// Initializes a new instance of the struct. @@ -46,7 +46,7 @@ internal struct PaletteQuantizer : IQuantizer public QuantizerOptions Options { get; } /// - public ReadOnlyMemory Palette => this.pixelMap!.Palette; + public ReadOnlyMemory Palette => this.pixelMap.Palette; /// [MethodImpl(InliningOptions.ShortMethod)] @@ -62,12 +62,11 @@ internal struct PaletteQuantizer : IQuantizer /// [MethodImpl(InliningOptions.ShortMethod)] public readonly byte GetQuantizedColor(TPixel color, out TPixel match) - => (byte)this.pixelMap!.GetClosestColor(color, out match); + => (byte)this.pixelMap.GetClosestColor(color, out match); /// public void Dispose() { - this.pixelMap?.Dispose(); - this.pixelMap = null; + this.pixelMap.Dispose(); } }