11// Copyright (c) Six Labors.
22// Licensed under the Six Labors Split License.
3- #nullable disable
43
5- using System . Runtime . CompilerServices ;
4+ using System . Diagnostics . CodeAnalysis ;
65using SixLabors . ImageSharp . Advanced ;
76using SixLabors . ImageSharp . Formats ;
87using SixLabors . ImageSharp . Metadata . Profiles . Exif ;
@@ -40,14 +39,15 @@ private FormattedImage(Image image, IImageFormat format, bool keepOpen)
4039 {
4140 this . Image = image ;
4241 this . imageFormatsManager = image . GetConfiguration ( ) . ImageFormatsManager ;
43- this . Format = format ;
42+ this . format = format ;
43+ this . encoder = this . imageFormatsManager . GetEncoder ( format ) ;
4444 this . keepOpen = keepOpen ;
4545 }
4646
4747 /// <summary>
4848 /// Gets the decoded image.
4949 /// </summary>
50- public Image Image { get ; private set ; }
50+ public Image Image { get ; }
5151
5252 /// <summary>
5353 /// Gets or sets the format.
@@ -105,7 +105,7 @@ internal static async Task<FormattedImage> LoadAsync<TPixel>(DecoderOptions opti
105105 // For example. If a resize command has been passed with no extra resampling options
106106 // then we should apply those changes on decode. This will allow memory savings and performance improvements.
107107 Image < TPixel > image = await Image . LoadAsync < TPixel > ( options , source ) ;
108- return new FormattedImage ( image , image . Metadata . DecodedImageFormat , false ) ;
108+ return new FormattedImage ( image , image . Metadata . DecodedImageFormat ! , false ) ;
109109 }
110110
111111 /// <summary>
@@ -117,7 +117,7 @@ internal static async Task<FormattedImage> LoadAsync<TPixel>(DecoderOptions opti
117117 internal static async Task < FormattedImage > LoadAsync ( DecoderOptions options , Stream source )
118118 {
119119 Image image = await Image . LoadAsync ( options , source ) ;
120- return new FormattedImage ( image , image . Metadata . DecodedImageFormat , false ) ;
120+ return new FormattedImage ( image , image . Metadata . DecodedImageFormat ! , false ) ;
121121 }
122122
123123 /// <summary>
@@ -143,7 +143,7 @@ public bool TryGetExifOrientation(out ushort value)
143143 value = ExifOrientationMode . Unknown ;
144144 if ( this . Image . Metadata . ExifProfile != null )
145145 {
146- if ( ! this . Image . Metadata . ExifProfile . TryGetValue ( ExifTag . Orientation , out IExifValue < ushort > orientation ) )
146+ if ( ! this . Image . Metadata . ExifProfile . TryGetValue ( ExifTag . Orientation , out IExifValue < ushort > ? orientation ) )
147147 {
148148 return false ;
149149 }
@@ -172,13 +172,12 @@ public void Dispose()
172172 if ( ! this . keepOpen )
173173 {
174174 this . Image ? . Dispose ( ) ;
175- this . Image = null ;
176175 }
177176 }
178177
179- [ MethodImpl ( MethodImplOptions . NoInlining ) ]
178+ [ DoesNotReturn ]
180179 private static void ThrowNull ( string name ) => throw new ArgumentNullException ( name ) ;
181180
182- [ MethodImpl ( MethodImplOptions . NoInlining ) ]
181+ [ DoesNotReturn ]
183182 private static void ThrowInvalid ( string name ) => throw new ArgumentException ( name ) ;
184183}
0 commit comments