@@ -101,6 +101,23 @@ private static IImageDecoder DiscoverDecoder(Stream stream, Configuration config
101101 : null ;
102102 }
103103
104+ /// <summary>
105+ /// By reading the header on the provided stream this calculates the images format.
106+ /// </summary>
107+ /// <param name="stream">The image stream to read the header from.</param>
108+ /// <param name="config">The configuration.</param>
109+ /// <returns>The decoder and the image format or null if none found.</returns>
110+ private static async Task < ( IImageDecoder decoder , IImageFormat format ) > DiscoverDecoderAsync ( Stream stream , Configuration config )
111+ {
112+ IImageFormat format = await InternalDetectFormatAsync ( stream , config ) . ConfigureAwait ( false ) ;
113+
114+ IImageDecoder decoder = format != null
115+ ? config . ImageFormatsManager . FindDecoder ( format )
116+ : null ;
117+
118+ return ( decoder , format ) ;
119+ }
120+
104121 /// <summary>
105122 /// Decodes the image stream to the current image.
106123 /// </summary>
@@ -133,7 +150,7 @@ private static (Image<TPixel> Image, IImageFormat Format) Decode<TPixel>(Stream
133150 private static async Task < ( Image < TPixel > Image , IImageFormat Format ) > DecodeAsync < TPixel > ( Stream stream , Configuration config )
134151 where TPixel : unmanaged, IPixel < TPixel >
135152 {
136- IImageDecoder decoder = DiscoverDecoder ( stream , config , out IImageFormat format ) ;
153+ ( IImageDecoder decoder , IImageFormat format ) = await DiscoverDecoderAsync ( stream , config ) . ConfigureAwait ( false ) ;
137154 if ( decoder is null )
138155 {
139156 return ( null , null ) ;
@@ -157,7 +174,7 @@ private static (Image Image, IImageFormat Format) Decode(Stream stream, Configur
157174
158175 private static async Task < ( Image Image , IImageFormat Format ) > DecodeAsync ( Stream stream , Configuration config )
159176 {
160- IImageDecoder decoder = DiscoverDecoder ( stream , config , out IImageFormat format ) ;
177+ ( IImageDecoder decoder , IImageFormat format ) = await DiscoverDecoderAsync ( stream , config ) . ConfigureAwait ( false ) ;
161178 if ( decoder is null )
162179 {
163180 return ( null , null ) ;
@@ -177,7 +194,9 @@ private static (Image Image, IImageFormat Format) Decode(Stream stream, Configur
177194 /// </returns>
178195 private static ( IImageInfo ImageInfo , IImageFormat Format ) InternalIdentity ( Stream stream , Configuration config )
179196 {
180- if ( ! ( DiscoverDecoder ( stream , config , out IImageFormat format ) is IImageInfoDetector detector ) )
197+ IImageDecoder decoder = DiscoverDecoder ( stream , config , out IImageFormat format ) ;
198+
199+ if ( ! ( decoder is IImageInfoDetector detector ) )
181200 {
182201 return ( null , null ) ;
183202 }
@@ -197,7 +216,9 @@ private static (IImageInfo ImageInfo, IImageFormat Format) InternalIdentity(Stre
197216 /// is not found.</returns>
198217 private static async Task < ( IImageInfo ImageInfo , IImageFormat Format ) > InternalIdentityAsync ( Stream stream , Configuration config )
199218 {
200- if ( ! ( DiscoverDecoder ( stream , config , out IImageFormat format ) is IImageInfoDetector detector ) )
219+ ( IImageDecoder decoder , IImageFormat format ) = await DiscoverDecoderAsync ( stream , config ) . ConfigureAwait ( false ) ;
220+
221+ if ( ! ( decoder is IImageInfoDetector detector ) )
201222 {
202223 return ( null , null ) ;
203224 }
0 commit comments