Browse Source

Merge pull request #2338 from stefannikolei/stefannikolei/nullable/processing

Remove nullable disable from Processing.Processors
pull/2343/head
James Jackson-South 3 years ago
committed by GitHub
parent
commit
52efdbfd72
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      src/ImageSharp/Formats/Gif/GifEncoderCore.cs
  2. 7
      src/ImageSharp/Processing/DefaultImageProcessorContext{TPixel}.cs
  3. 9
      src/ImageSharp/Processing/Processors/Convolution/KernelSamplingMap.cs
  4. 5
      src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor.cs
  5. 26
      src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs
  6. 4
      src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer{TPixel}.cs
  7. 2
      src/ImageSharp/Processing/Processors/Quantization/QuantizerOptions.cs
  8. 2
      src/ImageSharp/Processing/Processors/Quantization/QuantizerUtilities.cs
  9. 10
      src/ImageSharp/Processing/Processors/Quantization/WuQuantizer{TPixel}.cs
  10. 9
      src/ImageSharp/Processing/Processors/Transforms/Linear/AffineTransformProcessor{TPixel}.cs
  11. 9
      src/ImageSharp/Processing/Processors/Transforms/Linear/ProjectiveTransformProcessor{TPixel}.cs
  12. 5
      src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs

5
src/ImageSharp/Formats/Gif/GifEncoderCore.cs

@ -171,7 +171,10 @@ internal sealed class GifEncoderCore : IImageEncoderInternals
quantized = null;
}
paletteQuantizer.Dispose();
if (hasPaletteQuantizer)
{
paletteQuantizer.Dispose();
}
}
private void EncodeFrame<TPixel>(

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

@ -1,6 +1,5 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
#nullable disable
using System.Collections.Concurrent;
using SixLabors.ImageSharp.PixelFormats;
@ -17,7 +16,7 @@ internal class DefaultImageProcessorContext<TPixel> : IInternalImageProcessingCo
{
private readonly bool mutate;
private readonly Image<TPixel> source;
private Image<TPixel> destination;
private Image<TPixel>? destination;
/// <summary>
/// Initializes a new instance of the <see cref="DefaultImageProcessorContext{TPixel}"/> class.
@ -54,7 +53,7 @@ internal class DefaultImageProcessorContext<TPixel> : IInternalImageProcessingCo
this.destination = this.source.Clone();
}
return this.destination;
return this.destination!;
}
/// <inheritdoc/>
@ -87,7 +86,7 @@ internal class DefaultImageProcessorContext<TPixel> : IInternalImageProcessingCo
}
// Standard processing pipeline.
using (IImageProcessor<TPixel> specificProcessor = processor.CreatePixelSpecificProcessor(this.Configuration, this.destination, rectangle))
using (IImageProcessor<TPixel> specificProcessor = processor.CreatePixelSpecificProcessor(this.Configuration, this.destination!, rectangle))
{
specificProcessor.Execute();
}

9
src/ImageSharp/Processing/Processors/Convolution/KernelSamplingMap.cs

@ -1,6 +1,5 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
#nullable disable
using System.Buffers;
using System.Runtime.CompilerServices;
@ -16,8 +15,8 @@ internal sealed class KernelSamplingMap : IDisposable
{
private readonly MemoryAllocator allocator;
private bool isDisposed;
private IMemoryOwner<int> yOffsets;
private IMemoryOwner<int> xOffsets;
private IMemoryOwner<int>? yOffsets;
private IMemoryOwner<int>? xOffsets;
/// <summary>
/// Initializes a new instance of the <see cref="KernelSamplingMap"/> class.
@ -65,10 +64,10 @@ internal sealed class KernelSamplingMap : IDisposable
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Span<int> GetRowOffsetSpan() => this.yOffsets.GetSpan();
public Span<int> GetRowOffsetSpan() => this.yOffsets!.GetSpan();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Span<int> GetColumnOffsetSpan() => this.xOffsets.GetSpan();
public Span<int> GetColumnOffsetSpan() => this.xOffsets!.GetSpan();
/// <inheritdoc/>
public void Dispose()

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

@ -1,6 +1,5 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
#nullable disable
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;
@ -65,7 +64,7 @@ public class DrawImageProcessor : IImageProcessor
{
ProcessorFactoryVisitor<TPixelBg> visitor = new(configuration, this, source, sourceRectangle);
this.Image.AcceptVisitor(visitor);
return visitor.Result;
return visitor.Result!;
}
private class ProcessorFactoryVisitor<TPixelBg> : IImageVisitor
@ -84,7 +83,7 @@ public class DrawImageProcessor : IImageProcessor
this.sourceRectangle = sourceRectangle;
}
public IImageProcessor<TPixelBg> Result { get; private set; }
public IImageProcessor<TPixelBg>? Result { get; private set; }
public void Visit<TPixelFg>(Image<TPixelFg> image)
where TPixelFg : unmanaged, IPixel<TPixelFg>

26
src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs

@ -1,6 +1,5 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
#nullable disable
using System.Buffers;
using System.Diagnostics.CodeAnalysis;
@ -29,7 +28,7 @@ public struct OctreeQuantizer<TPixel> : IQuantizer<TPixel>
private readonly Octree octree;
private IMemoryOwner<TPixel> paletteOwner;
private ReadOnlyMemory<TPixel> palette;
private EuclideanPixelMap<TPixel> pixelMap;
private EuclideanPixelMap<TPixel>? pixelMap;
private readonly bool isDithering;
private bool isDisposed;
@ -143,7 +142,7 @@ public struct OctreeQuantizer<TPixel> : IQuantizer<TPixel>
// pixel and a black one.
if (this.isDithering || color.Equals(default))
{
return (byte)this.pixelMap.GetClosestColor(color, out match);
return (byte)this.pixelMap!.GetClosestColor(color, out match);
}
ref TPixel paletteRef = ref MemoryMarshal.GetReference(this.palette.Span);
@ -158,8 +157,7 @@ public struct OctreeQuantizer<TPixel> : IQuantizer<TPixel>
if (!this.isDisposed)
{
this.isDisposed = true;
this.paletteOwner?.Dispose();
this.paletteOwner = null;
this.paletteOwner.Dispose();
this.pixelMap?.Dispose();
this.pixelMap = null;
}
@ -183,7 +181,7 @@ public struct OctreeQuantizer<TPixel> : IQuantizer<TPixel>
/// <summary>
/// Store the last node quantized
/// </summary>
private OctreeNode previousNode;
private OctreeNode? previousNode;
/// <summary>
/// Cache the previous color quantized
@ -221,7 +219,7 @@ public struct OctreeQuantizer<TPixel> : IQuantizer<TPixel>
/// <summary>
/// Gets the array of reducible nodes
/// </summary>
private OctreeNode[] ReducibleNodes
private OctreeNode?[] ReducibleNodes
{
[MethodImpl(InliningOptions.ShortMethod)]
get;
@ -311,7 +309,7 @@ public struct OctreeQuantizer<TPixel> : IQuantizer<TPixel>
}
// Reduce the node most recently added to the list at level 'index'
OctreeNode node = this.ReducibleNodes[index];
OctreeNode node = this.ReducibleNodes[index]!;
this.ReducibleNodes[index] = node.NextReducible;
// Decrement the leaf count after reducing the node
@ -330,7 +328,7 @@ public struct OctreeQuantizer<TPixel> : IQuantizer<TPixel>
/// <summary>
/// Pointers to any child nodes
/// </summary>
private readonly OctreeNode[] children;
private readonly OctreeNode?[]? children;
/// <summary>
/// Flag indicating that this is a leaf node
@ -395,7 +393,7 @@ public struct OctreeQuantizer<TPixel> : IQuantizer<TPixel>
/// <summary>
/// Gets the next reducible node
/// </summary>
public OctreeNode NextReducible
public OctreeNode? NextReducible
{
[MethodImpl(InliningOptions.ShortMethod)]
get;
@ -423,7 +421,7 @@ public struct OctreeQuantizer<TPixel> : IQuantizer<TPixel>
// Go to the next level down in the tree
int index = GetColorIndex(ref color, level);
OctreeNode child = this.children[index];
OctreeNode? child = this.children![index];
if (child is null)
{
// Create a new child node and store it in the array
@ -448,7 +446,7 @@ public struct OctreeQuantizer<TPixel> : IQuantizer<TPixel>
// Loop through all children and add their information to this node
for (int index = 0; index < 8; index++)
{
OctreeNode child = this.children[index];
OctreeNode? child = this.children![index];
if (child != null)
{
this.red += child.red;
@ -495,7 +493,7 @@ public struct OctreeQuantizer<TPixel> : IQuantizer<TPixel>
// Loop through children looking for leaves
for (int i = 0; i < 8; i++)
{
this.children[i]?.ConstructPalette(palette, ref index);
this.children![i]?.ConstructPalette(palette, ref index);
}
}
}
@ -517,7 +515,7 @@ public struct OctreeQuantizer<TPixel> : IQuantizer<TPixel>
}
int colorIndex = GetColorIndex(ref pixel, level);
OctreeNode child = this.children[colorIndex];
OctreeNode? child = this.children![colorIndex];
int index = 0;
if (child != null)

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

@ -1,6 +1,5 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
#nullable disable
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
@ -68,7 +67,6 @@ internal struct PaletteQuantizer<TPixel> : IQuantizer<TPixel>
/// <inheritdoc/>
public void Dispose()
{
this.pixelMap?.Dispose();
this.pixelMap = null;
this.pixelMap.Dispose();
}
}

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

@ -17,7 +17,7 @@ public class QuantizerOptions
/// Gets or sets the algorithm to apply to the output image.
/// Defaults to <see cref="QuantizerConstants.DefaultDither"/>; set to <see langword="null"/> for no dithering.
/// </summary>
public IDither Dither { get; set; } = QuantizerConstants.DefaultDither;
public IDither? Dither { get; set; } = QuantizerConstants.DefaultDither;
/// <summary>
/// Gets or sets the dithering scale used to adjust the amount of dither. Range 0..1.

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

@ -146,7 +146,7 @@ public static class QuantizerUtilities
where TFrameQuantizer : struct, IQuantizer<TPixel>
where TPixel : unmanaged, IPixel<TPixel>
{
IDither dither = quantizer.Options.Dither;
IDither? dither = quantizer.Options.Dither;
Buffer2D<TPixel> sourceBuffer = source.PixelBuffer;
if (dither is null)

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

@ -1,6 +1,5 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
#nullable disable
using System.Buffers;
using System.Diagnostics.CodeAnalysis;
@ -76,7 +75,7 @@ internal struct WuQuantizer<TPixel> : IQuantizer<TPixel>
private ReadOnlyMemory<TPixel> palette;
private int maxColors;
private readonly Box[] colorCube;
private EuclideanPixelMap<TPixel> pixelMap;
private EuclideanPixelMap<TPixel>? pixelMap;
private readonly bool isDithering;
private bool isDisposed;
@ -175,7 +174,7 @@ internal struct WuQuantizer<TPixel> : IQuantizer<TPixel>
{
if (this.isDithering)
{
return (byte)this.pixelMap.GetClosestColor(color, out match);
return (byte)this.pixelMap!.GetClosestColor(color, out match);
}
Rgba32 rgba = default;
@ -203,9 +202,6 @@ internal struct WuQuantizer<TPixel> : IQuantizer<TPixel>
this.momentsOwner?.Dispose();
this.tagsOwner?.Dispose();
this.paletteOwner?.Dispose();
this.momentsOwner = null;
this.tagsOwner = null;
this.paletteOwner = null;
this.pixelMap?.Dispose();
this.pixelMap = null;
}
@ -869,7 +865,7 @@ internal struct WuQuantizer<TPixel> : IQuantizer<TPixel>
public int Volume;
/// <inheritdoc/>
public override readonly bool Equals(object obj)
public override readonly bool Equals(object? obj)
=> obj is Box box
&& this.Equals(box);

9
src/ImageSharp/Processing/Processors/Transforms/Linear/AffineTransformProcessor{TPixel}.cs

@ -1,6 +1,5 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
#nullable disable
using System.Numerics;
using System.Runtime.CompilerServices;
@ -20,8 +19,8 @@ internal class AffineTransformProcessor<TPixel> : TransformProcessor<TPixel>, IR
private readonly Size destinationSize;
private readonly Matrix3x2 transformMatrix;
private readonly IResampler resampler;
private ImageFrame<TPixel> source;
private ImageFrame<TPixel> destination;
private ImageFrame<TPixel>? source;
private ImageFrame<TPixel>? destination;
/// <summary>
/// Initializes a new instance of the <see cref="AffineTransformProcessor{TPixel}"/> class.
@ -53,8 +52,8 @@ internal class AffineTransformProcessor<TPixel> : TransformProcessor<TPixel>, IR
where TResampler : struct, IResampler
{
Configuration configuration = this.Configuration;
ImageFrame<TPixel> source = this.source;
ImageFrame<TPixel> destination = this.destination;
ImageFrame<TPixel> source = this.source!;
ImageFrame<TPixel> destination = this.destination!;
Matrix3x2 matrix = this.transformMatrix;
// Handle transforms that result in output identical to the original.

9
src/ImageSharp/Processing/Processors/Transforms/Linear/ProjectiveTransformProcessor{TPixel}.cs

@ -1,6 +1,5 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
#nullable disable
using System.Numerics;
using System.Runtime.CompilerServices;
@ -20,8 +19,8 @@ internal class ProjectiveTransformProcessor<TPixel> : TransformProcessor<TPixel>
private readonly Size destinationSize;
private readonly IResampler resampler;
private readonly Matrix4x4 transformMatrix;
private ImageFrame<TPixel> source;
private ImageFrame<TPixel> destination;
private ImageFrame<TPixel>? source;
private ImageFrame<TPixel>? destination;
/// <summary>
/// Initializes a new instance of the <see cref="ProjectiveTransformProcessor{TPixel}"/> class.
@ -53,8 +52,8 @@ internal class ProjectiveTransformProcessor<TPixel> : TransformProcessor<TPixel>
where TResampler : struct, IResampler
{
Configuration configuration = this.Configuration;
ImageFrame<TPixel> source = this.source;
ImageFrame<TPixel> destination = this.destination;
ImageFrame<TPixel> source = this.source!;
ImageFrame<TPixel> destination = this.destination!;
Matrix4x4 matrix = this.transformMatrix;
// Handle transforms that result in output identical to the original.

5
src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs

@ -1,6 +1,5 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
#nullable disable
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Advanced;
@ -21,7 +20,7 @@ internal class ResizeProcessor<TPixel> : TransformProcessor<TPixel>, IResampling
private readonly int destinationHeight;
private readonly IResampler resampler;
private readonly Rectangle destinationRectangle;
private Image<TPixel> destination;
private Image<TPixel>? destination;
public ResizeProcessor(Configuration configuration, ResizeProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(configuration, source, sourceRectangle)
@ -56,7 +55,7 @@ internal class ResizeProcessor<TPixel> : TransformProcessor<TPixel>, IResampling
{
Configuration configuration = this.Configuration;
Image<TPixel> source = this.Source;
Image<TPixel> destination = this.destination;
Image<TPixel> destination = this.destination!;
Rectangle sourceRectangle = this.SourceRectangle;
Rectangle destinationRectangle = this.destinationRectangle;
bool compand = this.options.Compand;

Loading…
Cancel
Save