1
1
// Copyright (c) Six Labors.
2
2
// Licensed under the Six Labors Split License.
3
- #nullable disable
4
3
5
4
using System . Buffers ;
6
5
using System . Runtime . CompilerServices ;
@@ -93,7 +92,7 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
93
92
bool useGlobalTable = this . colorTableMode == GifColorTableMode . Global ;
94
93
95
94
// Quantize the image returning a palette.
96
- IndexedImageFrame < TPixel > quantized ;
95
+ IndexedImageFrame < TPixel > ? quantized ;
97
96
using ( IQuantizer < TPixel > frameQuantizer = this . quantizer . CreatePixelSpecificQuantizer < TPixel > ( this . configuration ) )
98
97
{
99
98
if ( useGlobalTable )
@@ -129,7 +128,7 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
129
128
this . WriteComments ( gifMetadata , stream ) ;
130
129
131
130
// Write application extensions.
132
- XmpProfile xmpProfile = image . Metadata . XmpProfile ?? image . Frames . RootFrame . Metadata . XmpProfile ;
131
+ XmpProfile ? xmpProfile = image . Metadata . XmpProfile ?? image . Frames . RootFrame . Metadata . XmpProfile ;
133
132
this . WriteApplicationExtensions ( stream , image . Frames . Count , gifMetadata . RepeatCount , xmpProfile ) ;
134
133
}
135
134
@@ -152,8 +151,8 @@ private void EncodeFrames<TPixel>(
152
151
// Gather the metadata for this frame.
153
152
ImageFrame < TPixel > frame = image . Frames [ i ] ;
154
153
ImageFrameMetadata metadata = frame . Metadata ;
155
- bool hasMetadata = metadata . TryGetGifMetadata ( out GifFrameMetadata frameMetadata ) ;
156
- bool useLocal = this . colorTableMode == GifColorTableMode . Local || ( hasMetadata && frameMetadata . ColorTableMode == GifColorTableMode . Local ) ;
154
+ bool hasMetadata = metadata . TryGetGifMetadata ( out GifFrameMetadata ? frameMetadata ) ;
155
+ bool useLocal = this . colorTableMode == GifColorTableMode . Local || ( hasMetadata && frameMetadata ! . ColorTableMode == GifColorTableMode . Local ) ;
157
156
158
157
if ( ! useLocal && ! hasPaletteQuantizer && i > 0 )
159
158
{
@@ -164,11 +163,10 @@ private void EncodeFrames<TPixel>(
164
163
paletteQuantizer = new ( this . configuration , this . quantizer . Options , palette ) ;
165
164
}
166
165
167
- this . EncodeFrame ( stream , frame , i , useLocal , frameMetadata , ref quantized , ref paletteQuantizer ) ;
166
+ this . EncodeFrame ( stream , frame , i , useLocal , frameMetadata , ref quantized ! , ref paletteQuantizer ) ;
168
167
169
168
// Clean up for the next run.
170
169
quantized . Dispose ( ) ;
171
- quantized = null ;
172
170
}
173
171
174
172
if ( hasPaletteQuantizer )
@@ -182,7 +180,7 @@ private void EncodeFrame<TPixel>(
182
180
ImageFrame < TPixel > frame ,
183
181
int frameIndex ,
184
182
bool useLocal ,
185
- GifFrameMetadata metadata ,
183
+ GifFrameMetadata ? metadata ,
186
184
ref IndexedImageFrame < TPixel > quantized ,
187
185
ref PaletteQuantizer < TPixel > paletteQuantizer )
188
186
where TPixel : unmanaged, IPixel < TPixel >
@@ -193,7 +191,7 @@ private void EncodeFrame<TPixel>(
193
191
if ( useLocal )
194
192
{
195
193
// Reassign using the current frame and details.
196
- QuantizerOptions options = null ;
194
+ QuantizerOptions ? options = null ;
197
195
int colorTableLength = metadata ? . ColorTableLength ?? 0 ;
198
196
if ( colorTableLength > 0 )
199
197
{
@@ -338,7 +336,7 @@ private void WriteLogicalScreenDescriptor(
338
336
/// <param name="frameCount">The frame count fo this image.</param>
339
337
/// <param name="repeatCount">The animated image repeat count.</param>
340
338
/// <param name="xmpProfile">The XMP metadata profile. Null if profile is not to be written.</param>
341
- private void WriteApplicationExtensions ( Stream stream , int frameCount , ushort repeatCount , XmpProfile xmpProfile )
339
+ private void WriteApplicationExtensions ( Stream stream , int frameCount , ushort repeatCount , XmpProfile ? xmpProfile )
342
340
{
343
341
// Application Extension: Loop repeat count.
344
342
if ( frameCount > 1 && repeatCount != 1 )
@@ -350,7 +348,7 @@ private void WriteApplicationExtensions(Stream stream, int frameCount, ushort re
350
348
// Application Extension: XMP Profile.
351
349
if ( xmpProfile != null )
352
350
{
353
- GifXmpApplicationExtension xmpExtension = new ( xmpProfile . Data ) ;
351
+ GifXmpApplicationExtension xmpExtension = new ( xmpProfile . Data ! ) ;
354
352
this . WriteExtension ( xmpExtension , stream ) ;
355
353
}
356
354
}
@@ -439,7 +437,7 @@ private void WriteGraphicalControlExtension(GifFrameMetadata metadata, int trans
439
437
private void WriteExtension < TGifExtension > ( TGifExtension extension , Stream stream )
440
438
where TGifExtension : struct , IGifExtension
441
439
{
442
- IMemoryOwner < byte > owner = null ;
440
+ IMemoryOwner < byte > ? owner = null ;
443
441
Span < byte > extensionBuffer ;
444
442
int extensionSize = extension . ContentLength ;
445
443
0 commit comments