Skip to content

Commit a44295b

Browse files
Fix remaining nullability warnings
1 parent b1247ae commit a44295b

16 files changed

+95
-120
lines changed

src/ImageSharp.Drawing/Processing/DrawingOptionsDefaultsExtensions.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4-
#nullable disable
5-
64
using System.Numerics;
75

86
namespace SixLabors.ImageSharp.Drawing.Processing;
@@ -49,7 +47,7 @@ public static void SetDrawingTransform(this Configuration configuration, Matrix3
4947
/// <returns>The matrix.</returns>
5048
public static Matrix3x2 GetDrawingTransform(this IImageProcessingContext context)
5149
{
52-
if (context.Properties.TryGetValue(DrawingTransformMatrixKey, out object options) && options is Matrix3x2 go)
50+
if (context.Properties.TryGetValue(DrawingTransformMatrixKey, out object? options) && options is Matrix3x2 go)
5351
{
5452
return go;
5553
}
@@ -66,7 +64,7 @@ public static Matrix3x2 GetDrawingTransform(this IImageProcessingContext context
6664
/// <returns>The globally configured default matrix.</returns>
6765
public static Matrix3x2 GetDrawingTransform(this Configuration configuration)
6866
{
69-
if (configuration.Properties.TryGetValue(DrawingTransformMatrixKey, out object options) && options is Matrix3x2 go)
67+
if (configuration.Properties.TryGetValue(DrawingTransformMatrixKey, out object? options) && options is Matrix3x2 go)
7068
{
7169
return go;
7270
}

src/ImageSharp.Drawing/Processing/Processors/Drawing/FillPathProcessor{TPixel}.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4-
#nullable disable
5-
64
using System.Buffers;
5+
using System.Diagnostics.CodeAnalysis;
76
using SixLabors.ImageSharp.Drawing.Shapes.Rasterization;
87
using SixLabors.ImageSharp.Memory;
98
using SixLabors.ImageSharp.Processing.Processors;
@@ -47,11 +46,17 @@ protected override void OnFrameApply(ImageFrame<TPixel> source)
4746
ShapeOptions shapeOptions = this.definition.Options.ShapeOptions;
4847
GraphicsOptions graphicsOptions = this.definition.Options.GraphicsOptions;
4948
Brush brush = this.definition.Brush;
50-
bool isSolidBrushWithoutBlending = IsSolidBrushWithoutBlending(graphicsOptions, brush, out SolidBrush solidBrush);
51-
TPixel solidBrushColor = isSolidBrushWithoutBlending ? solidBrush.Color.ToPixel<TPixel>() : default;
49+
50+
TPixel solidBrushColor = default;
51+
bool isSolidBrushWithoutBlending = false;
52+
if (IsSolidBrushWithoutBlending(graphicsOptions, brush, out SolidBrush? solidBrush))
53+
{
54+
isSolidBrushWithoutBlending = true;
55+
solidBrushColor = solidBrush.Color.ToPixel<TPixel>();
56+
}
5257

5358
// Align start/end positions.
54-
var interest = Rectangle.Intersect(this.bounds, source.Bounds());
59+
Rectangle interest = Rectangle.Intersect(this.bounds, source.Bounds());
5560
if (interest.Equals(Rectangle.Empty))
5661
{
5762
return; // No effect inside image;
@@ -74,7 +79,7 @@ protected override void OnFrameApply(ImageFrame<TPixel> source)
7479
MemoryAllocator allocator = this.Configuration.MemoryAllocator;
7580
bool scanlineDirty = true;
7681

77-
var scanner = PolygonScanner.Create(
82+
PolygonScanner scanner = PolygonScanner.Create(
7883
this.path,
7984
interest.Top,
8085
interest.Bottom,
@@ -138,7 +143,7 @@ protected override void OnFrameApply(ImageFrame<TPixel> source)
138143
}
139144
}
140145

141-
private static bool IsSolidBrushWithoutBlending(GraphicsOptions options, Brush inputBrush, out SolidBrush solidBrush)
146+
private static bool IsSolidBrushWithoutBlending(GraphicsOptions options, Brush inputBrush, [NotNullWhen(true)] out SolidBrush? solidBrush)
142147
{
143148
solidBrush = inputBrush as SolidBrush;
144149

src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor{TPixel}.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4-
#nullable disable
5-
64
using System.Buffers;
5+
using System.Diagnostics.CodeAnalysis;
76
using System.Runtime.CompilerServices;
87
using SixLabors.ImageSharp.Advanced;
98
using SixLabors.ImageSharp.Memory;
@@ -27,7 +26,7 @@ public FillProcessor(Configuration configuration, FillProcessor definition, Imag
2726
/// <inheritdoc/>
2827
protected override void OnFrameApply(ImageFrame<TPixel> source)
2928
{
30-
var interest = Rectangle.Intersect(this.SourceRectangle, source.Bounds());
29+
Rectangle interest = Rectangle.Intersect(this.SourceRectangle, source.Bounds());
3130
if (interest.Width == 0 || interest.Height == 0)
3231
{
3332
return;
@@ -38,14 +37,14 @@ protected override void OnFrameApply(ImageFrame<TPixel> source)
3837
GraphicsOptions options = this.definition.Options.GraphicsOptions;
3938

4039
// If there's no reason for blending, then avoid it.
41-
if (this.IsSolidBrushWithoutBlending(out SolidBrush solidBrush))
40+
if (this.IsSolidBrushWithoutBlending(out SolidBrush? solidBrush))
4241
{
4342
ParallelExecutionSettings parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration)
4443
.MultiplyMinimumPixelsPerTask(4);
4544

4645
TPixel colorPixel = solidBrush.Color.ToPixel<TPixel>();
4746

48-
var solidOperation = new SolidBrushRowIntervalOperation(interest, source, colorPixel);
47+
FillProcessor<TPixel>.SolidBrushRowIntervalOperation solidOperation = new(interest, source, colorPixel);
4948
ParallelRowIterator.IterateRowIntervals(
5049
interest,
5150
parallelSettings,
@@ -63,14 +62,14 @@ protected override void OnFrameApply(ImageFrame<TPixel> source)
6362

6463
amount.Memory.Span.Fill(1F);
6564

66-
var operation = new RowIntervalOperation(interest, applicator, amount.Memory);
65+
FillProcessor<TPixel>.RowIntervalOperation operation = new(interest, applicator, amount.Memory);
6766
ParallelRowIterator.IterateRowIntervals(
6867
configuration,
6968
interest,
7069
in operation);
7170
}
7271

73-
private bool IsSolidBrushWithoutBlending(out SolidBrush solidBrush)
72+
private bool IsSolidBrushWithoutBlending([NotNullWhen(true)] out SolidBrush? solidBrush)
7473
{
7574
solidBrush = this.definition.Brush as SolidBrush;
7675

src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor{TPixel}.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ void Draw(IEnumerable<DrawingOperation> operations)
105105
}
106106
}
107107

108-
if (this.textRenderer.DrawingOperations.Count > 0)
108+
// Not null, initialized in earlier event.
109+
if (this.textRenderer!.DrawingOperations.Count > 0)
109110
{
110111
Draw(this.textRenderer.DrawingOperations.OrderBy(x => x.RenderPass));
111112
}

src/ImageSharp.Drawing/Processing/Processors/Text/RichTextGlyphRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public RichTextGlyphRenderer(
6262
this.defaultBrush = brush;
6363
this.DrawingOperations = new List<DrawingOperation>();
6464

65-
IPath path = textOptions.Path;
65+
IPath? path = textOptions.Path;
6666
if (path is not null)
6767
{
6868
// Turn of caching. The chances of a hit are near-zero.

src/ImageSharp.Drawing/Processing/RichTextOptions.cs

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

4-
#nullable disable
5-
64
using SixLabors.Fonts;
75

86
namespace SixLabors.ImageSharp.Drawing.Processing;
@@ -46,5 +44,5 @@ public RichTextOptions(RichTextOptions options)
4644
/// When this property is not <see langword="null"/> the <see cref="TextOptions.Origin"/>
4745
/// property is automatically applied as a translation to a copy of the path for processing.
4846
/// </remarks>
49-
public IPath Path { get; set; }
47+
public IPath? Path { get; set; }
5048
}
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4-
#nullable disable
5-
64
using SixLabors.Fonts;
75

86
namespace SixLabors.ImageSharp.Drawing.Processing;
@@ -15,25 +13,25 @@ public class RichTextRun : TextRun
1513
/// <summary>
1614
/// Gets or sets the brush used for filling this run.
1715
/// </summary>
18-
public Brush Brush { get; set; }
16+
public Brush? Brush { get; set; }
1917

2018
/// <summary>
2119
/// Gets or sets the pen used for outlining this run.
2220
/// </summary>
23-
public Pen Pen { get; set; }
21+
public Pen? Pen { get; set; }
2422

2523
/// <summary>
2624
/// Gets or sets the pen used for drawing strikeout features for this run.
2725
/// </summary>
28-
public Pen StrikeoutPen { get; set; }
26+
public Pen? StrikeoutPen { get; set; }
2927

3028
/// <summary>
3129
/// Gets or sets the pen used for drawing underline features for this run.
3230
/// </summary>
33-
public Pen UnderlinePen { get; set; }
31+
public Pen? UnderlinePen { get; set; }
3432

3533
/// <summary>
3634
/// Gets or sets the pen used for drawing overline features for this run.
3735
/// </summary>
38-
public Pen OverlinePen { get; set; }
36+
public Pen? OverlinePen { get; set; }
3937
}

src/ImageSharp.Drawing/Processing/ShapeGraphicOptionsDefaultsExtensions.cs

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

4-
#nullable disable
5-
64
namespace SixLabors.ImageSharp.Drawing.Processing;
75

86
/// <summary>
@@ -63,16 +61,14 @@ public static void SetShapeOptions(this Configuration configuration, ShapeOption
6361
/// <returns>The globally configured default options.</returns>
6462
public static ShapeOptions GetShapeOptions(this IImageProcessingContext context)
6563
{
66-
if (context.Properties.TryGetValue(typeof(ShapeOptions), out object options) && options is ShapeOptions go)
64+
if (context.Properties.TryGetValue(typeof(ShapeOptions), out object? options) && options is ShapeOptions go)
6765
{
6866
return go;
6967
}
7068

71-
ShapeOptions configOptions = context.Configuration.GetShapeOptions();
72-
7369
// do not cache the fall back to config into the the processing context
7470
// in case someone want to change the value on the config and expects it reflow thru
75-
return configOptions;
71+
return context.Configuration.GetShapeOptions();
7672
}
7773

7874
/// <summary>
@@ -82,12 +78,12 @@ public static ShapeOptions GetShapeOptions(this IImageProcessingContext context)
8278
/// <returns>The globally configured default options.</returns>
8379
public static ShapeOptions GetShapeOptions(this Configuration configuration)
8480
{
85-
if (configuration.Properties.TryGetValue(typeof(ShapeOptions), out object options) && options is ShapeOptions go)
81+
if (configuration.Properties.TryGetValue(typeof(ShapeOptions), out object? options) && options is ShapeOptions go)
8682
{
8783
return go;
8884
}
8985

90-
var configOptions = new ShapeOptions();
86+
ShapeOptions configOptions = new();
9187

9288
// capture the fallback so the same instance will always be returned in case its mutated
9389
configuration.Properties[typeof(ShapeOptions)] = configOptions;

src/ImageSharp.Drawing/Shapes/ComplexPolygon.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4-
#nullable disable
5-
64
using System.Buffers;
7-
using System.Diagnostics.CodeAnalysis;
85
using System.Numerics;
96

107
namespace SixLabors.ImageSharp.Drawing;
@@ -35,7 +32,7 @@ public ComplexPolygon(PointF[] contour, PointF[] hole)
3532
/// </summary>
3633
/// <param name="paths">The paths.</param>
3734
public ComplexPolygon(IEnumerable<IPath> paths)
38-
: this(paths?.ToArray())
35+
: this(paths.ToArray())
3936
{
4037
}
4138

@@ -82,7 +79,7 @@ public ComplexPolygon(params IPath[] paths)
8279

8380
foreach (ISimplePath s in p.Flatten())
8481
{
85-
var ip = new InternalPath(s.Points, s.IsClosed);
82+
InternalPath ip = new(s.Points, s.IsClosed);
8683
length += ip.Length;
8784
this.internalPaths.Add(ip);
8885
}
@@ -120,7 +117,7 @@ public IPath Transform(Matrix3x2 matrix)
120117
return this;
121118
}
122119

123-
var shapes = new IPath[this.paths.Length];
120+
IPath[] shapes = new IPath[this.paths.Length];
124121
int i = 0;
125122
foreach (IPath s in this.Paths)
126123
{
@@ -133,7 +130,7 @@ public IPath Transform(Matrix3x2 matrix)
133130
/// <inheritdoc />
134131
public IEnumerable<ISimplePath> Flatten()
135132
{
136-
var paths = new List<ISimplePath>();
133+
List<ISimplePath> paths = new();
137134
foreach (IPath path in this.Paths)
138135
{
139136
paths.AddRange(path.Flatten());
@@ -150,7 +147,7 @@ public IPath AsClosedPath()
150147
return this;
151148
}
152149

153-
var paths = new IPath[this.paths.Length];
150+
IPath[] paths = new IPath[this.paths.Length];
154151
for (int i = 0; i < this.paths.Length; i++)
155152
{
156153
paths[i] = this.paths[i].AsClosedPath();
@@ -182,6 +179,5 @@ SegmentInfo IPathInternals.PointAlongPath(float distance)
182179
IReadOnlyList<InternalPath> IInternalPathOwner.GetRingsAsInternalPath()
183180
=> this.internalPaths;
184181

185-
[DoesNotReturn]
186182
private static InvalidOperationException ThrowOutOfRange() => new("Should not be possible to reach this line");
187183
}

0 commit comments

Comments
 (0)