@@ -44,27 +44,29 @@ public static IImageFormat DetectFormat(Configuration configuration, Stream stre
4444 /// By reading the header on the provided stream this calculates the images format type.
4545 /// </summary>
4646 /// <param name="stream">The image stream to read the header from.</param>
47+ /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
4748 /// <exception cref="ArgumentNullException">The stream is null.</exception>
4849 /// <exception cref="NotSupportedException">The stream is not readable.</exception>
4950 /// <returns>A <see cref="Task{IImageFormat}"/> representing the asynchronous operation or null if none is found.</returns>
50- public static Task < IImageFormat > DetectFormatAsync ( Stream stream )
51- => DetectFormatAsync ( Configuration . Default , stream ) ;
51+ public static Task < IImageFormat > DetectFormatAsync ( Stream stream , CancellationToken cancellationToken = default )
52+ => DetectFormatAsync ( Configuration . Default , stream , cancellationToken ) ;
5253
5354 /// <summary>
5455 /// By reading the header on the provided stream this calculates the images format type.
5556 /// </summary>
5657 /// <param name="configuration">The configuration.</param>
5758 /// <param name="stream">The image stream to read the header from.</param>
59+ /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
5860 /// <exception cref="ArgumentNullException">The configuration is null.</exception>
5961 /// <exception cref="ArgumentNullException">The stream is null.</exception>
6062 /// <exception cref="NotSupportedException">The stream is not readable.</exception>
6163 /// <returns>A <see cref="Task{IImageFormat}"/> representing the asynchronous operation.</returns>
62- public static Task < IImageFormat > DetectFormatAsync ( Configuration configuration , Stream stream )
64+ public static Task < IImageFormat > DetectFormatAsync ( Configuration configuration , Stream stream , CancellationToken cancellationToken = default )
6365 => WithSeekableStreamAsync (
6466 configuration ,
6567 stream ,
6668 ( s , _ ) => InternalDetectFormatAsync ( s , configuration ) ,
67- default ) ;
69+ cancellationToken ) ;
6870
6971 /// <summary>
7072 /// Reads the raw image information from the specified stream without fully decoding it.
@@ -83,15 +85,16 @@ public static IImageInfo Identify(Stream stream)
8385 /// Reads the raw image information from the specified stream without fully decoding it.
8486 /// </summary>
8587 /// <param name="stream">The image stream to read the header from.</param>
88+ /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
8689 /// <exception cref="ArgumentNullException">The stream is null.</exception>
8790 /// <exception cref="NotSupportedException">The stream is not readable.</exception>
8891 /// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
8992 /// <returns>
9093 /// A <see cref="Task{IImageInfo}"/> representing the asynchronous operation or null if
9194 /// a suitable detector is not found.
9295 /// </returns>
93- public static Task < IImageInfo > IdentifyAsync ( Stream stream )
94- => IdentifyAsync ( Configuration . Default , stream ) ;
96+ public static Task < IImageInfo > IdentifyAsync ( Stream stream , CancellationToken cancellationToken = default )
97+ => IdentifyAsync ( Configuration . Default , stream , cancellationToken ) ;
9598
9699 /// <summary>
97100 /// Reads the raw image information from the specified stream without fully decoding it.
@@ -227,13 +230,14 @@ public static Image Load(Stream stream, out IImageFormat format)
227230 /// The pixel format is selected by the decoder.
228231 /// </summary>
229232 /// <param name="stream">The stream containing image information.</param>
233+ /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
230234 /// <exception cref="ArgumentNullException">The stream is null.</exception>
231235 /// <exception cref="NotSupportedException">The stream is not readable or the image format is not supported.</exception>
232236 /// <exception cref="UnknownImageFormatException">Image format not recognised.</exception>
233237 /// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
234238 /// <returns>A <see cref="Task{ValueTuple}"/> representing the asynchronous operation.</returns>
235- public static Task < ( Image Image , IImageFormat Format ) > LoadWithFormatAsync ( Stream stream )
236- => LoadWithFormatAsync ( Configuration . Default , stream ) ;
239+ public static Task < ( Image Image , IImageFormat Format ) > LoadWithFormatAsync ( Stream stream , CancellationToken cancellationToken = default )
240+ => LoadWithFormatAsync ( Configuration . Default , stream , cancellationToken ) ;
237241
238242 /// <summary>
239243 /// Decode a new instance of the <see cref="Image"/> class from the given stream.
@@ -252,12 +256,14 @@ public static Image Load(Stream stream, out IImageFormat format)
252256 /// The pixel format is selected by the decoder.
253257 /// </summary>
254258 /// <param name="stream">The stream containing image information.</param>
259+ /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
255260 /// <exception cref="ArgumentNullException">The stream is null.</exception>
256261 /// <exception cref="NotSupportedException">The stream is not readable or the image format is not supported.</exception>
257262 /// <exception cref="UnknownImageFormatException">Image format not recognised.</exception>
258263 /// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
259264 /// <returns>A <see cref="Task{Image}"/> representing the asynchronous operation.</returns>
260- public static Task < Image > LoadAsync ( Stream stream ) => LoadAsync ( Configuration . Default , stream ) ;
265+ public static Task < Image > LoadAsync ( Stream stream , CancellationToken cancellationToken = default )
266+ => LoadAsync ( Configuration . Default , stream , cancellationToken ) ;
261267
262268 /// <summary>
263269 /// Decode a new instance of the <see cref="Image"/> class from the given stream.
@@ -280,14 +286,15 @@ public static Image Load(Stream stream, IImageDecoder decoder)
280286 /// </summary>
281287 /// <param name="stream">The stream containing image information.</param>
282288 /// <param name="decoder">The decoder.</param>
289+ /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
283290 /// <exception cref="ArgumentNullException">The stream is null.</exception>
284291 /// <exception cref="ArgumentNullException">The decoder is null.</exception>
285292 /// <exception cref="NotSupportedException">The stream is not readable or the image format is not supported.</exception>
286293 /// <exception cref="UnknownImageFormatException">Image format not recognised.</exception>
287294 /// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
288295 /// <returns>A <see cref="Task{Image}"/> representing the asynchronous operation.</returns>
289- public static Task < Image > LoadAsync ( Stream stream , IImageDecoder decoder )
290- => LoadAsync ( Configuration . Default , stream , decoder ) ;
296+ public static Task < Image > LoadAsync ( Stream stream , IImageDecoder decoder , CancellationToken cancellationToken = default )
297+ => LoadAsync ( Configuration . Default , stream , decoder , cancellationToken ) ;
291298
292299 /// <summary>
293300 /// Decode a new instance of the <see cref="Image"/> class from the given stream.
@@ -388,15 +395,16 @@ public static Image<TPixel> Load<TPixel>(Stream stream)
388395 /// Create a new instance of the <see cref="Image{TPixel}"/> class from the given stream.
389396 /// </summary>
390397 /// <param name="stream">The stream containing image information.</param>
398+ /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
391399 /// <exception cref="ArgumentNullException">The stream is null.</exception>
392400 /// <exception cref="NotSupportedException">The stream is not readable or the image format is not supported.</exception>
393401 /// <exception cref="UnknownImageFormatException">Image format not recognised.</exception>
394402 /// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
395403 /// <typeparam name="TPixel">The pixel format.</typeparam>
396404 /// <returns>A <see cref="Task{Image}"/> representing the asynchronous operation.</returns>
397- public static Task < Image < TPixel > > LoadAsync < TPixel > ( Stream stream )
405+ public static Task < Image < TPixel > > LoadAsync < TPixel > ( Stream stream , CancellationToken cancellationToken = default )
398406 where TPixel : unmanaged, IPixel < TPixel >
399- => LoadAsync < TPixel > ( Configuration . Default , stream ) ;
407+ => LoadAsync < TPixel > ( Configuration . Default , stream , cancellationToken ) ;
400408
401409 /// <summary>
402410 /// Create a new instance of the <see cref="Image{TPixel}"/> class from the given stream.
@@ -417,15 +425,16 @@ public static Image<TPixel> Load<TPixel>(Stream stream, out IImageFormat format)
417425 /// Create a new instance of the <see cref="Image{TPixel}"/> class from the given stream.
418426 /// </summary>
419427 /// <param name="stream">The stream containing image information.</param>
428+ /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
420429 /// <exception cref="ArgumentNullException">The stream is null.</exception>
421430 /// <exception cref="NotSupportedException">The stream is not readable or the image format is not supported.</exception>
422431 /// <exception cref="UnknownImageFormatException">Image format not recognised.</exception>
423432 /// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
424433 /// <typeparam name="TPixel">The pixel format.</typeparam>
425434 /// <returns>A <see cref="Task{ValueTuple}"/> representing the asynchronous operation.</returns>
426- public static async Task < ( Image < TPixel > Image , IImageFormat Format ) > LoadWithFormatAsync < TPixel > ( Stream stream )
435+ public static async Task < ( Image < TPixel > Image , IImageFormat Format ) > LoadWithFormatAsync < TPixel > ( Stream stream , CancellationToken cancellationToken = default )
427436 where TPixel : unmanaged, IPixel < TPixel >
428- => await LoadWithFormatAsync < TPixel > ( Configuration . Default , stream ) . ConfigureAwait ( false ) ;
437+ => await LoadWithFormatAsync < TPixel > ( Configuration . Default , stream , cancellationToken ) . ConfigureAwait ( false ) ;
429438
430439 /// <summary>
431440 /// Create a new instance of the <see cref="Image{TPixel}"/> class from the given stream.
0 commit comments