@@ -44,27 +44,29 @@ public static IImageFormat DetectFormat(Configuration configuration, Stream stre
44
44
/// By reading the header on the provided stream this calculates the images format type.
45
45
/// </summary>
46
46
/// <param name="stream">The image stream to read the header from.</param>
47
+ /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
47
48
/// <exception cref="ArgumentNullException">The stream is null.</exception>
48
49
/// <exception cref="NotSupportedException">The stream is not readable.</exception>
49
50
/// <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 ) ;
52
53
53
54
/// <summary>
54
55
/// By reading the header on the provided stream this calculates the images format type.
55
56
/// </summary>
56
57
/// <param name="configuration">The configuration.</param>
57
58
/// <param name="stream">The image stream to read the header from.</param>
59
+ /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
58
60
/// <exception cref="ArgumentNullException">The configuration is null.</exception>
59
61
/// <exception cref="ArgumentNullException">The stream is null.</exception>
60
62
/// <exception cref="NotSupportedException">The stream is not readable.</exception>
61
63
/// <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 )
63
65
=> WithSeekableStreamAsync (
64
66
configuration ,
65
67
stream ,
66
68
( s , _ ) => InternalDetectFormatAsync ( s , configuration ) ,
67
- default ) ;
69
+ cancellationToken ) ;
68
70
69
71
/// <summary>
70
72
/// Reads the raw image information from the specified stream without fully decoding it.
@@ -83,15 +85,16 @@ public static IImageInfo Identify(Stream stream)
83
85
/// Reads the raw image information from the specified stream without fully decoding it.
84
86
/// </summary>
85
87
/// <param name="stream">The image stream to read the header from.</param>
88
+ /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
86
89
/// <exception cref="ArgumentNullException">The stream is null.</exception>
87
90
/// <exception cref="NotSupportedException">The stream is not readable.</exception>
88
91
/// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
89
92
/// <returns>
90
93
/// A <see cref="Task{IImageInfo}"/> representing the asynchronous operation or null if
91
94
/// a suitable detector is not found.
92
95
/// </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 ) ;
95
98
96
99
/// <summary>
97
100
/// 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)
227
230
/// The pixel format is selected by the decoder.
228
231
/// </summary>
229
232
/// <param name="stream">The stream containing image information.</param>
233
+ /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
230
234
/// <exception cref="ArgumentNullException">The stream is null.</exception>
231
235
/// <exception cref="NotSupportedException">The stream is not readable or the image format is not supported.</exception>
232
236
/// <exception cref="UnknownImageFormatException">Image format not recognised.</exception>
233
237
/// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
234
238
/// <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 ) ;
237
241
238
242
/// <summary>
239
243
/// 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)
252
256
/// The pixel format is selected by the decoder.
253
257
/// </summary>
254
258
/// <param name="stream">The stream containing image information.</param>
259
+ /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
255
260
/// <exception cref="ArgumentNullException">The stream is null.</exception>
256
261
/// <exception cref="NotSupportedException">The stream is not readable or the image format is not supported.</exception>
257
262
/// <exception cref="UnknownImageFormatException">Image format not recognised.</exception>
258
263
/// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
259
264
/// <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 ) ;
261
267
262
268
/// <summary>
263
269
/// 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)
280
286
/// </summary>
281
287
/// <param name="stream">The stream containing image information.</param>
282
288
/// <param name="decoder">The decoder.</param>
289
+ /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
283
290
/// <exception cref="ArgumentNullException">The stream is null.</exception>
284
291
/// <exception cref="ArgumentNullException">The decoder is null.</exception>
285
292
/// <exception cref="NotSupportedException">The stream is not readable or the image format is not supported.</exception>
286
293
/// <exception cref="UnknownImageFormatException">Image format not recognised.</exception>
287
294
/// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
288
295
/// <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 ) ;
291
298
292
299
/// <summary>
293
300
/// 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)
388
395
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given stream.
389
396
/// </summary>
390
397
/// <param name="stream">The stream containing image information.</param>
398
+ /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
391
399
/// <exception cref="ArgumentNullException">The stream is null.</exception>
392
400
/// <exception cref="NotSupportedException">The stream is not readable or the image format is not supported.</exception>
393
401
/// <exception cref="UnknownImageFormatException">Image format not recognised.</exception>
394
402
/// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
395
403
/// <typeparam name="TPixel">The pixel format.</typeparam>
396
404
/// <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 )
398
406
where TPixel : unmanaged, IPixel < TPixel >
399
- => LoadAsync < TPixel > ( Configuration . Default , stream ) ;
407
+ => LoadAsync < TPixel > ( Configuration . Default , stream , cancellationToken ) ;
400
408
401
409
/// <summary>
402
410
/// 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)
417
425
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given stream.
418
426
/// </summary>
419
427
/// <param name="stream">The stream containing image information.</param>
428
+ /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
420
429
/// <exception cref="ArgumentNullException">The stream is null.</exception>
421
430
/// <exception cref="NotSupportedException">The stream is not readable or the image format is not supported.</exception>
422
431
/// <exception cref="UnknownImageFormatException">Image format not recognised.</exception>
423
432
/// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
424
433
/// <typeparam name="TPixel">The pixel format.</typeparam>
425
434
/// <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 )
427
436
where TPixel : unmanaged, IPixel < TPixel >
428
- => await LoadWithFormatAsync < TPixel > ( Configuration . Default , stream ) . ConfigureAwait ( false ) ;
437
+ => await LoadWithFormatAsync < TPixel > ( Configuration . Default , stream , cancellationToken ) . ConfigureAwait ( false ) ;
429
438
430
439
/// <summary>
431
440
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given stream.
0 commit comments