From 34add6aebfc0c7d4f5117ab7bbbd6cdf87071b5c Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Tue, 31 Jan 2023 18:00:44 +0100 Subject: [PATCH 1/5] Remove nullable disable from pixelimplementations #2231 --- src/ImageSharp/PixelFormats/PixelImplementations/A8.cs | 3 +-- src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs | 3 +-- src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs | 3 +-- src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs | 3 +-- src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs | 3 +-- src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs | 3 +-- .../PixelFormats/PixelImplementations/Bgra4444.cs | 3 +-- src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs | 3 +-- .../PixelFormats/PixelImplementations/HalfSingle.cs | 3 +-- .../PixelFormats/PixelImplementations/HalfVector2.cs | 3 +-- .../PixelFormats/PixelImplementations/HalfVector4.cs | 3 +-- src/ImageSharp/PixelFormats/PixelImplementations/L16.cs | 3 +-- src/ImageSharp/PixelFormats/PixelImplementations/L8.cs | 3 +-- src/ImageSharp/PixelFormats/PixelImplementations/La16.cs | 3 +-- src/ImageSharp/PixelFormats/PixelImplementations/La32.cs | 3 +-- .../PixelFormats/PixelImplementations/NormalizedByte2.cs | 3 +-- .../PixelFormats/PixelImplementations/NormalizedByte4.cs | 3 +-- .../PixelFormats/PixelImplementations/NormalizedShort2.cs | 3 +-- .../PixelFormats/PixelImplementations/NormalizedShort4.cs | 3 +-- src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs | 3 +-- src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs | 3 +-- src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs | 3 +-- .../PixelFormats/PixelImplementations/Rgba1010102.cs | 3 +-- src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs | 7 +++---- src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs | 3 +-- .../PixelFormats/PixelImplementations/RgbaVector.cs | 3 +-- src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs | 3 +-- src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs | 3 +-- 28 files changed, 30 insertions(+), 58 deletions(-) diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs b/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs index 1da5645835..0256907121 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/A8.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; @@ -140,7 +139,7 @@ public partial struct A8 : IPixel, IPackedVector /// /// The object to compare. /// True if the object is equal to the packed vector. - public override readonly bool Equals(object obj) => obj is A8 other && this.Equals(other); + public override readonly bool Equals(object? obj) => obj is A8 other && this.Equals(other); /// /// Compares another A8 packed vector with the packed vector. diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs index 28b6899b2a..ca68c5aaf9 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.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; @@ -335,7 +334,7 @@ public partial struct Abgr32 : IPixel, IPackedVector } /// - public override readonly bool Equals(object obj) => obj is Abgr32 abgr32 && this.Equals(abgr32); + public override readonly bool Equals(object? obj) => obj is Abgr32 abgr32 && this.Equals(abgr32); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs index 935751afcd..0c99adb52d 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.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; @@ -334,7 +333,7 @@ public partial struct Argb32 : IPixel, IPackedVector } /// - public override readonly bool Equals(object obj) => obj is Argb32 argb32 && this.Equals(argb32); + public override readonly bool Equals(object? obj) => obj is Argb32 argb32 && this.Equals(argb32); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs index 751e0bfe86..65b36059b8 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.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; @@ -232,7 +231,7 @@ public partial struct Bgr24 : IPixel public readonly bool Equals(Bgr24 other) => this.R.Equals(other.R) && this.G.Equals(other.G) && this.B.Equals(other.B); /// - public override readonly bool Equals(object obj) => obj is Bgr24 other && this.Equals(other); + public override readonly bool Equals(object? obj) => obj is Bgr24 other && this.Equals(other); /// public override readonly string ToString() => $"Bgr24({this.B}, {this.G}, {this.R})"; diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs index 21766431cf..ac3b6f8299 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.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; @@ -151,7 +150,7 @@ public partial struct Bgr565 : IPixel, IPackedVector (this.PackedValue & 0x1F) * (1F / 31F)); /// - public override readonly bool Equals(object obj) => obj is Bgr565 other && this.Equals(other); + public override readonly bool Equals(object? obj) => obj is Bgr565 other && this.Equals(other); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs index 204919392d..6b859cda64 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.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; @@ -287,7 +286,7 @@ public partial struct Bgra32 : IPixel, IPackedVector } /// - public override readonly bool Equals(object obj) => obj is Bgra32 other && this.Equals(other); + public override readonly bool Equals(object? obj) => obj is Bgra32 other && this.Equals(other); /// public readonly bool Equals(Bgra32 other) => this.Bgra.Equals(other.Bgra); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs index e342d18455..8ba32c8ac2 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.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; @@ -143,7 +142,7 @@ public partial struct Bgra4444 : IPixel, IPackedVector public void FromRgba64(Rgba64 source) => this.FromScaledVector4(source.ToScaledVector4()); /// - public override readonly bool Equals(object obj) => obj is Bgra4444 other && this.Equals(other); + public override readonly bool Equals(object? obj) => obj is Bgra4444 other && this.Equals(other); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs index 9d9b7c87fc..e699e5fe58 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.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; @@ -141,7 +140,7 @@ public partial struct Byte4 : IPixel, IPackedVector public void FromRgba64(Rgba64 source) => this.FromScaledVector4(source.ToScaledVector4()); /// - public override readonly bool Equals(object obj) => obj is Byte4 byte4 && this.Equals(byte4); + public override readonly bool Equals(object? obj) => obj is Byte4 byte4 && this.Equals(byte4); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs b/src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs index a99462c8b9..db1e02adc2 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.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; @@ -140,7 +139,7 @@ public partial struct HalfSingle : IPixel, IPackedVector public readonly float ToSingle() => HalfTypeHelper.Unpack(this.PackedValue); /// - public override readonly bool Equals(object obj) => obj is HalfSingle other && this.Equals(other); + public override readonly bool Equals(object? obj) => obj is HalfSingle other && this.Equals(other); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs index 2f2117c26f..9caae58c95 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.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; @@ -157,7 +156,7 @@ public partial struct HalfVector2 : IPixel, IPackedVector } /// - public override readonly bool Equals(object obj) => obj is HalfVector2 other && this.Equals(other); + public override readonly bool Equals(object? obj) => obj is HalfVector2 other && this.Equals(other); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs index 859ba7e320..609fec3bd7 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.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; @@ -149,7 +148,7 @@ public partial struct HalfVector4 : IPixel, IPackedVector public void FromRgba64(Rgba64 source) => this.FromScaledVector4(source.ToScaledVector4()); /// - public override readonly bool Equals(object obj) => obj is HalfVector4 other && this.Equals(other); + public override readonly bool Equals(object? obj) => obj is HalfVector4 other && this.Equals(other); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs b/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs index 5d2539ce13..c6ee8744d9 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/L16.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; @@ -153,7 +152,7 @@ public partial struct L16 : IPixel, IPackedVector public void FromRgba64(Rgba64 source) => this.PackedValue = ColorNumerics.Get16BitBT709Luminance(source.R, source.G, source.B); /// - public override readonly bool Equals(object obj) => obj is L16 other && this.Equals(other); + public override readonly bool Equals(object? obj) => obj is L16 other && this.Equals(other); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs b/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs index 25a79e58fc..383e09b270 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/L8.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; @@ -143,7 +142,7 @@ public partial struct L8 : IPixel, IPackedVector ColorNumerics.DownScaleFrom16BitTo8Bit(source.B)); /// - public override readonly bool Equals(object obj) => obj is L8 other && this.Equals(other); + public override readonly bool Equals(object? obj) => obj is L8 other && this.Equals(other); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs b/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs index 21e66ed495..7597677a26 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/La16.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; @@ -80,7 +79,7 @@ public partial struct La16 : IPixel, IPackedVector public readonly bool Equals(La16 other) => this.PackedValue.Equals(other.PackedValue); /// - public override readonly bool Equals(object obj) => obj is La16 other && this.Equals(other); + public override readonly bool Equals(object? obj) => obj is La16 other && this.Equals(other); /// public override readonly string ToString() => $"La16({this.L}, {this.A})"; diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs index cf53d2217b..cb8fad228d 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/La32.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; @@ -82,7 +81,7 @@ public partial struct La32 : IPixel, IPackedVector public readonly bool Equals(La32 other) => this.PackedValue.Equals(other.PackedValue); /// - public override readonly bool Equals(object obj) => obj is La32 other && this.Equals(other); + public override readonly bool Equals(object? obj) => obj is La32 other && this.Equals(other); /// public override readonly string ToString() => $"La32({this.L}, {this.A})"; diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs index d9d0a53bd8..92b9e6148a 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.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; @@ -162,7 +161,7 @@ public partial struct NormalizedByte2 : IPixel, IPackedVector> 8) & 0xFF) / MaxPos); /// - public override readonly bool Equals(object obj) => obj is NormalizedByte2 other && this.Equals(other); + public override readonly bool Equals(object? obj) => obj is NormalizedByte2 other && this.Equals(other); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs index 5a18d00a2d..f87bb5a602 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.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; @@ -154,7 +153,7 @@ public partial struct NormalizedByte4 : IPixel, IPackedVector this.FromScaledVector4(source.ToScaledVector4()); /// - public override readonly bool Equals(object obj) => obj is NormalizedByte4 other && this.Equals(other); + public override readonly bool Equals(object? obj) => obj is NormalizedByte4 other && this.Equals(other); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs index 84e5e43625..f77dd69b71 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.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; @@ -163,7 +162,7 @@ public partial struct NormalizedShort2 : IPixel, IPackedVector (short)(this.PackedValue >> 0x10) / MaxPos); /// - public override readonly bool Equals(object obj) => obj is NormalizedShort2 other && this.Equals(other); + public override readonly bool Equals(object? obj) => obj is NormalizedShort2 other && this.Equals(other); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs index f8139c547b..989edbd2ba 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.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; @@ -155,7 +154,7 @@ public partial struct NormalizedShort4 : IPixel, IPackedVector public void FromRgba64(Rgba64 source) => this.FromScaledVector4(source.ToScaledVector4()); /// - public override readonly bool Equals(object obj) => obj is NormalizedShort4 other && this.Equals(other); + public override readonly bool Equals(object? obj) => obj is NormalizedShort4 other && this.Equals(other); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs index 69f39c8838..0a13a15eda 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rg32.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; @@ -146,7 +145,7 @@ public partial struct Rg32 : IPixel, IPackedVector public readonly Vector2 ToVector2() => new Vector2(this.PackedValue & 0xFFFF, (this.PackedValue >> 16) & 0xFFFF) / Max; /// - public override readonly bool Equals(object obj) => obj is Rg32 other && this.Equals(other); + public override readonly bool Equals(object? obj) => obj is Rg32 other && this.Equals(other); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs index 5f66341571..105618cd96 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.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; @@ -241,7 +240,7 @@ public partial struct Rgb24 : IPixel } /// - public override readonly bool Equals(object obj) => obj is Rgb24 other && this.Equals(other); + public override readonly bool Equals(object? obj) => obj is Rgb24 other && this.Equals(other); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs index 16673fca2f..1cf63eb24c 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.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; @@ -210,7 +209,7 @@ public partial struct Rgb48 : IPixel public void FromRgb48(Rgb48 source) => this = source; /// - public override readonly bool Equals(object obj) => obj is Rgb48 rgb48 && this.Equals(rgb48); + public override readonly bool Equals(object? obj) => obj is Rgb48 rgb48 && this.Equals(rgb48); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs index 2c59741bf4..7bac1d9208 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.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; @@ -141,7 +140,7 @@ public partial struct Rgba1010102 : IPixel, IPackedVector public void FromRgba64(Rgba64 source) => this.FromScaledVector4(source.ToScaledVector4()); /// - public override readonly bool Equals(object obj) => obj is Rgba1010102 other && this.Equals(other); + public override readonly bool Equals(object? obj) => obj is Rgba1010102 other && this.Equals(other); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs index 0d18ac3431..a652c2b339 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs @@ -1,6 +1,5 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -#nullable disable using System.Buffers.Binary; using System.Globalization; @@ -267,7 +266,7 @@ public partial struct Rgba32 : IPixel, IPackedVector /// The . /// [MethodImpl(InliningOptions.ShortMethod)] - public static bool TryParseHex(string hex, out Rgba32 result) + public static bool TryParseHex(string? hex, out Rgba32 result) { result = default; if (string.IsNullOrWhiteSpace(hex)) @@ -437,7 +436,7 @@ public partial struct Rgba32 : IPixel, IPackedVector } /// - public override readonly bool Equals(object obj) => obj is Rgba32 rgba32 && this.Equals(rgba32); + public override readonly bool Equals(object? obj) => obj is Rgba32 rgba32 && this.Equals(rgba32); /// [MethodImpl(InliningOptions.ShortMethod)] @@ -514,7 +513,7 @@ public partial struct Rgba32 : IPixel, IPackedVector /// /// A rrggbbaa hex value. /// - private static string ToRgbaHex(string hex) + private static string? ToRgbaHex(string hex) { if (hex[0] == '#') { diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs index 7560892120..81c9591480 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.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; @@ -444,7 +443,7 @@ public partial struct Rgba64 : IPixel, IPackedVector } /// - public override readonly bool Equals(object obj) => obj is Rgba64 rgba64 && this.Equals(rgba64); + public override readonly bool Equals(object? obj) => obj is Rgba64 rgba64 && this.Equals(rgba64); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs b/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs index 3a0426a8e1..899987b712 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs @@ -1,6 +1,5 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -#nullable disable using System.Globalization; using System.Numerics; @@ -193,7 +192,7 @@ public partial struct RgbaVector : IPixel } /// - public override readonly bool Equals(object obj) => obj is RgbaVector other && this.Equals(other); + public override readonly bool Equals(object? obj) => obj is RgbaVector other && this.Equals(other); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs index 8eb33afd35..832e8c770f 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Short2.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; @@ -164,7 +163,7 @@ public partial struct Short2 : IPixel, IPackedVector public readonly Vector2 ToVector2() => new((short)(this.PackedValue & 0xFFFF), (short)(this.PackedValue >> 0x10)); /// - public override readonly bool Equals(object obj) => obj is Short2 other && this.Equals(other); + public override readonly bool Equals(object? obj) => obj is Short2 other && this.Equals(other); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs index b964c9ec50..c4dc324a13 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Short4.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; @@ -164,7 +163,7 @@ public partial struct Short4 : IPixel, IPackedVector public void FromRgba64(Rgba64 source) => this.FromScaledVector4(source.ToScaledVector4()); /// - public override readonly bool Equals(object obj) => obj is Short4 other && this.Equals(other); + public override readonly bool Equals(object? obj) => obj is Short4 other && this.Equals(other); /// [MethodImpl(InliningOptions.ShortMethod)] From 8504518073a46b8a0fdc1a7c86377c3ef4b80593 Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Tue, 31 Jan 2023 18:50:23 +0100 Subject: [PATCH 2/5] Remove nullable disable from Processing.Processors #2231 --- .../DefaultImageProcessorContext{TPixel}.cs | 7 +++-- .../Convolution/KernelSamplingMap.cs | 9 +++---- .../Processors/Drawing/DrawImageProcessor.cs | 5 ++-- .../Quantization/OctreeQuantizer{TPixel}.cs | 26 +++++++++---------- .../Quantization/PaletteQuantizer{TPixel}.cs | 4 +-- .../Quantization/QuantizerOptions.cs | 2 +- .../Quantization/QuantizerUtilities.cs | 2 +- .../Quantization/WuQuantizer{TPixel}.cs | 10 +++---- .../AffineTransformProcessor{TPixel}.cs | 9 +++---- .../ProjectiveTransformProcessor{TPixel}.cs | 9 +++---- .../Resize/ResizeProcessor{TPixel}.cs | 5 ++-- 11 files changed, 39 insertions(+), 49 deletions(-) diff --git a/src/ImageSharp/Processing/DefaultImageProcessorContext{TPixel}.cs b/src/ImageSharp/Processing/DefaultImageProcessorContext{TPixel}.cs index 208455b902..4d95e060dc 100644 --- a/src/ImageSharp/Processing/DefaultImageProcessorContext{TPixel}.cs +++ b/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 : IInternalImageProcessingCo { private readonly bool mutate; private readonly Image source; - private Image destination; + private Image? destination; /// /// Initializes a new instance of the class. @@ -54,7 +53,7 @@ internal class DefaultImageProcessorContext : IInternalImageProcessingCo this.destination = this.source.Clone(); } - return this.destination; + return this.destination!; } /// @@ -87,7 +86,7 @@ internal class DefaultImageProcessorContext : IInternalImageProcessingCo } // Standard processing pipeline. - using (IImageProcessor specificProcessor = processor.CreatePixelSpecificProcessor(this.Configuration, this.destination, rectangle)) + using (IImageProcessor specificProcessor = processor.CreatePixelSpecificProcessor(this.Configuration, this.destination!, rectangle)) { specificProcessor.Execute(); } diff --git a/src/ImageSharp/Processing/Processors/Convolution/KernelSamplingMap.cs b/src/ImageSharp/Processing/Processors/Convolution/KernelSamplingMap.cs index 4cae2f858e..8128d01196 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/KernelSamplingMap.cs +++ b/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 yOffsets; - private IMemoryOwner xOffsets; + private IMemoryOwner? yOffsets; + private IMemoryOwner? xOffsets; /// /// Initializes a new instance of the class. @@ -65,10 +64,10 @@ internal sealed class KernelSamplingMap : IDisposable } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Span GetRowOffsetSpan() => this.yOffsets.GetSpan(); + public Span GetRowOffsetSpan() => this.yOffsets!.GetSpan(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Span GetColumnOffsetSpan() => this.xOffsets.GetSpan(); + public Span GetColumnOffsetSpan() => this.xOffsets!.GetSpan(); /// public void Dispose() diff --git a/src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor.cs b/src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor.cs index 9de4f862b8..88b59b7dc6 100644 --- a/src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor.cs +++ b/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 visitor = new(configuration, this, source, sourceRectangle); this.Image.AcceptVisitor(visitor); - return visitor.Result; + return visitor.Result!; } private class ProcessorFactoryVisitor : IImageVisitor @@ -84,7 +83,7 @@ public class DrawImageProcessor : IImageProcessor this.sourceRectangle = sourceRectangle; } - public IImageProcessor Result { get; private set; } + public IImageProcessor? Result { get; private set; } public void Visit(Image image) where TPixelFg : unmanaged, IPixel diff --git a/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs index 43d11777db..61ffcc6ccd 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs +++ b/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; @@ -27,9 +26,10 @@ public struct OctreeQuantizer : IQuantizer private readonly int maxColors; private readonly int bitDepth; private readonly Octree octree; - private IMemoryOwner paletteOwner; + [NotNull] + private IMemoryOwner? paletteOwner; private ReadOnlyMemory palette; - private EuclideanPixelMap pixelMap; + private EuclideanPixelMap? pixelMap; private readonly bool isDithering; private bool isDisposed; @@ -143,7 +143,7 @@ public struct OctreeQuantizer : IQuantizer // 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); @@ -183,7 +183,7 @@ public struct OctreeQuantizer : IQuantizer /// /// Store the last node quantized /// - private OctreeNode previousNode; + private OctreeNode? previousNode; /// /// Cache the previous color quantized @@ -221,7 +221,7 @@ public struct OctreeQuantizer : IQuantizer /// /// Gets the array of reducible nodes /// - private OctreeNode[] ReducibleNodes + private OctreeNode?[] ReducibleNodes { [MethodImpl(InliningOptions.ShortMethod)] get; @@ -311,7 +311,7 @@ public struct OctreeQuantizer : IQuantizer } // 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 +330,7 @@ public struct OctreeQuantizer : IQuantizer /// /// Pointers to any child nodes /// - private readonly OctreeNode[] children; + private readonly OctreeNode?[]? children; /// /// Flag indicating that this is a leaf node @@ -395,7 +395,7 @@ public struct OctreeQuantizer : IQuantizer /// /// Gets the next reducible node /// - public OctreeNode NextReducible + public OctreeNode? NextReducible { [MethodImpl(InliningOptions.ShortMethod)] get; @@ -423,7 +423,7 @@ public struct OctreeQuantizer : IQuantizer // 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 +448,7 @@ public struct OctreeQuantizer : IQuantizer // 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 +495,7 @@ public struct OctreeQuantizer : IQuantizer // 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 +517,7 @@ public struct OctreeQuantizer : IQuantizer } int colorIndex = GetColorIndex(ref pixel, level); - OctreeNode child = this.children[colorIndex]; + OctreeNode? child = this.children![colorIndex]; int index = 0; if (child != null) diff --git a/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer{TPixel}.cs index 7b351a61f5..f8f9658a85 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer{TPixel}.cs +++ b/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; @@ -21,7 +20,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization; internal struct PaletteQuantizer : IQuantizer where TPixel : unmanaged, IPixel { - private EuclideanPixelMap pixelMap; + [NotNull] + private EuclideanPixelMap? pixelMap; /// /// Initializes a new instance of the struct. diff --git a/src/ImageSharp/Processing/Processors/Quantization/QuantizerOptions.cs b/src/ImageSharp/Processing/Processors/Quantization/QuantizerOptions.cs index f52cfd6ea7..b3d03d9338 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/QuantizerOptions.cs +++ b/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 ; set to for no dithering. /// - public IDither Dither { get; set; } = QuantizerConstants.DefaultDither; + public IDither? Dither { get; set; } = QuantizerConstants.DefaultDither; /// /// Gets or sets the dithering scale used to adjust the amount of dither. Range 0..1. diff --git a/src/ImageSharp/Processing/Processors/Quantization/QuantizerUtilities.cs b/src/ImageSharp/Processing/Processors/Quantization/QuantizerUtilities.cs index 167cf91282..53203f94a0 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/QuantizerUtilities.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/QuantizerUtilities.cs @@ -146,7 +146,7 @@ public static class QuantizerUtilities where TFrameQuantizer : struct, IQuantizer where TPixel : unmanaged, IPixel { - IDither dither = quantizer.Options.Dither; + IDither? dither = quantizer.Options.Dither; Buffer2D sourceBuffer = source.PixelBuffer; if (dither is null) diff --git a/src/ImageSharp/Processing/Processors/Quantization/WuQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/WuQuantizer{TPixel}.cs index e0aede058a..0119558bff 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/WuQuantizer{TPixel}.cs +++ b/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 : IQuantizer private ReadOnlyMemory palette; private int maxColors; private readonly Box[] colorCube; - private EuclideanPixelMap pixelMap; + private EuclideanPixelMap? pixelMap; private readonly bool isDithering; private bool isDisposed; @@ -175,7 +174,7 @@ internal struct WuQuantizer : IQuantizer { 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 : IQuantizer 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 : IQuantizer public int Volume; /// - public override readonly bool Equals(object obj) + public override readonly bool Equals(object? obj) => obj is Box box && this.Equals(box); diff --git a/src/ImageSharp/Processing/Processors/Transforms/Linear/AffineTransformProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/Linear/AffineTransformProcessor{TPixel}.cs index b9ff551691..c5c2a778eb 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Linear/AffineTransformProcessor{TPixel}.cs +++ b/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 : TransformProcessor, IR private readonly Size destinationSize; private readonly Matrix3x2 transformMatrix; private readonly IResampler resampler; - private ImageFrame source; - private ImageFrame destination; + private ImageFrame? source; + private ImageFrame? destination; /// /// Initializes a new instance of the class. @@ -53,8 +52,8 @@ internal class AffineTransformProcessor : TransformProcessor, IR where TResampler : struct, IResampler { Configuration configuration = this.Configuration; - ImageFrame source = this.source; - ImageFrame destination = this.destination; + ImageFrame source = this.source!; + ImageFrame destination = this.destination!; Matrix3x2 matrix = this.transformMatrix; // Handle transforms that result in output identical to the original. diff --git a/src/ImageSharp/Processing/Processors/Transforms/Linear/ProjectiveTransformProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/Linear/ProjectiveTransformProcessor{TPixel}.cs index 7d1a10926c..b741dc4ee6 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Linear/ProjectiveTransformProcessor{TPixel}.cs +++ b/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 : TransformProcessor private readonly Size destinationSize; private readonly IResampler resampler; private readonly Matrix4x4 transformMatrix; - private ImageFrame source; - private ImageFrame destination; + private ImageFrame? source; + private ImageFrame? destination; /// /// Initializes a new instance of the class. @@ -53,8 +52,8 @@ internal class ProjectiveTransformProcessor : TransformProcessor where TResampler : struct, IResampler { Configuration configuration = this.Configuration; - ImageFrame source = this.source; - ImageFrame destination = this.destination; + ImageFrame source = this.source!; + ImageFrame destination = this.destination!; Matrix4x4 matrix = this.transformMatrix; // Handle transforms that result in output identical to the original. diff --git a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs index ba96e76ae0..98c2523fae 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs +++ b/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 : TransformProcessor, IResampling private readonly int destinationHeight; private readonly IResampler resampler; private readonly Rectangle destinationRectangle; - private Image destination; + private Image? destination; public ResizeProcessor(Configuration configuration, ResizeProcessor definition, Image source, Rectangle sourceRectangle) : base(configuration, source, sourceRectangle) @@ -56,7 +55,7 @@ internal class ResizeProcessor : TransformProcessor, IResampling { Configuration configuration = this.Configuration; Image source = this.Source; - Image destination = this.destination; + Image destination = this.destination!; Rectangle sourceRectangle = this.SourceRectangle; Rectangle destinationRectangle = this.destinationRectangle; bool compand = this.options.Compand; From e7bcc5f13270ce8eed50f8df73274f7a67a2c789 Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Tue, 31 Jan 2023 18:58:49 +0100 Subject: [PATCH 3/5] Fix build Code analysis in rider did not catch that. only the build failed. --- .../Processors/Quantization/OctreeQuantizer{TPixel}.cs | 5 ++--- .../Processors/Quantization/PaletteQuantizer{TPixel}.cs | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs index 61ffcc6ccd..83e0a8b08f 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs @@ -26,7 +26,6 @@ public struct OctreeQuantizer : IQuantizer private readonly int maxColors; private readonly int bitDepth; private readonly Octree octree; - [NotNull] private IMemoryOwner? paletteOwner; private ReadOnlyMemory palette; private EuclideanPixelMap? pixelMap; @@ -99,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. @@ -113,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. diff --git a/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer{TPixel}.cs index f8f9658a85..e73c87896f 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer{TPixel}.cs @@ -20,7 +20,6 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization; internal struct PaletteQuantizer : IQuantizer where TPixel : unmanaged, IPixel { - [NotNull] private EuclideanPixelMap? pixelMap; /// @@ -47,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)] @@ -63,7 +62,7 @@ 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() From 7847fab011b2608f593d8e51b553824ec3a7e4af Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Wed, 1 Feb 2023 06:57:50 +0100 Subject: [PATCH 4/5] Remove ? for pixelMap and paletteOwner --- .../Processors/Quantization/OctreeQuantizer{TPixel}.cs | 9 ++++----- .../Processors/Quantization/PaletteQuantizer{TPixel}.cs | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-) 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(); } } From df803cd34de6284835f751419dd9d2be471431df Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Wed, 1 Feb 2023 07:39:36 +0100 Subject: [PATCH 5/5] Fix nullref the quantizier was initialized with default --> all properties are null. So we need to check that --- src/ImageSharp/Formats/Gif/GifEncoderCore.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs index 9cc045d45e..eaa6852937 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs +++ b/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(