diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoder.cs b/src/ImageSharp/Formats/Bmp/BmpDecoder.cs
index 129b3a1aa..1417909b4 100644
--- a/src/ImageSharp/Formats/Bmp/BmpDecoder.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpDecoder.cs
@@ -31,18 +31,18 @@ namespace SixLabors.ImageSharp.Formats.Bmp
public RleSkippedPixelHandling RleSkippedPixelHandling { get; set; } = RleSkippedPixelHandling.Black;
///
- public Image Decode(Configuration configuration, Stream stream)
+ public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken = default)
where TPixel : unmanaged, IPixel
{
Guard.NotNull(stream, nameof(stream));
var decoder = new BmpDecoderCore(configuration, this);
- return decoder.Decode(configuration, stream);
+ return decoder.Decode(configuration, stream, cancellationToken);
}
///
- public Image Decode(Configuration configuration, Stream stream)
- => this.Decode(configuration, stream);
+ public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken = default)
+ => this.Decode(configuration, stream, cancellationToken);
///
public Task> DecodeAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken)
@@ -60,11 +60,11 @@ namespace SixLabors.ImageSharp.Formats.Bmp
.ConfigureAwait(false);
///
- public IImageInfo Identify(Configuration configuration, Stream stream)
+ public IImageInfo Identify(Configuration configuration, Stream stream, CancellationToken cancellationToken = default)
{
Guard.NotNull(stream, nameof(stream));
- return new BmpDecoderCore(configuration, this).Identify(configuration, stream);
+ return new BmpDecoderCore(configuration, this).Identify(configuration, stream, cancellationToken);
}
///
diff --git a/src/ImageSharp/Formats/Gif/GifDecoder.cs b/src/ImageSharp/Formats/Gif/GifDecoder.cs
index 196d77ad7..e00c272e1 100644
--- a/src/ImageSharp/Formats/Gif/GifDecoder.cs
+++ b/src/ImageSharp/Formats/Gif/GifDecoder.cs
@@ -27,16 +27,16 @@ namespace SixLabors.ImageSharp.Formats.Gif
public FrameDecodingMode DecodingMode { get; set; } = FrameDecodingMode.All;
///
- public Image Decode(Configuration configuration, Stream stream)
+ public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken = default)
where TPixel : unmanaged, IPixel
{
var decoder = new GifDecoderCore(configuration, this);
- return decoder.Decode(configuration, stream);
+ return decoder.Decode(configuration, stream, cancellationToken);
}
///
- public Image Decode(Configuration configuration, Stream stream)
- => this.Decode(configuration, stream);
+ public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken = default)
+ => this.Decode(configuration, stream, cancellationToken);
///
public Task> DecodeAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken)
@@ -52,14 +52,14 @@ namespace SixLabors.ImageSharp.Formats.Gif
.ConfigureAwait(false);
///
- public IImageInfo Identify(Configuration configuration, Stream stream)
+ public IImageInfo Identify(Configuration configuration, Stream stream, CancellationToken cancellationToken = default)
{
Guard.NotNull(stream, nameof(stream));
var decoder = new GifDecoderCore(configuration, this);
using var bufferedStream = new BufferedReadStream(configuration, stream);
- return decoder.Identify(bufferedStream, default);
+ return decoder.Identify(bufferedStream, cancellationToken);
}
///
diff --git a/src/ImageSharp/Formats/IImageDecoder.cs b/src/ImageSharp/Formats/IImageDecoder.cs
index b55f1119b..1e673b30c 100644
--- a/src/ImageSharp/Formats/IImageDecoder.cs
+++ b/src/ImageSharp/Formats/IImageDecoder.cs
@@ -19,9 +19,10 @@ namespace SixLabors.ImageSharp.Formats
/// The pixel format.
/// The configuration for the image.
/// The containing image data.
+ /// The token to monitor for cancellation requests.
/// The .
// TODO: Document ImageFormatExceptions (https://github.com/SixLabors/ImageSharp/issues/1110)
- Image Decode(Configuration configuration, Stream stream)
+ Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken = default)
where TPixel : unmanaged, IPixel;
///
@@ -29,9 +30,10 @@ namespace SixLabors.ImageSharp.Formats
///
/// The configuration for the image.
/// The containing image data.
+ /// The token to monitor for cancellation requests.
/// The .
// TODO: Document ImageFormatExceptions (https://github.com/SixLabors/ImageSharp/issues/1110)
- Image Decode(Configuration configuration, Stream stream);
+ Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken = default);
///
/// Decodes the image from the specified stream to an of a specific pixel type.
diff --git a/src/ImageSharp/Formats/IImageInfoDetector.cs b/src/ImageSharp/Formats/IImageInfoDetector.cs
index 6f5fc2333..920e31374 100644
--- a/src/ImageSharp/Formats/IImageInfoDetector.cs
+++ b/src/ImageSharp/Formats/IImageInfoDetector.cs
@@ -17,8 +17,9 @@ namespace SixLabors.ImageSharp.Formats
///
/// The configuration for the image.
/// The containing image data.
+ /// The token to monitor for cancellation requests.
/// The object
- IImageInfo Identify(Configuration configuration, Stream stream);
+ IImageInfo Identify(Configuration configuration, Stream stream, CancellationToken cancellationToken = default);
///
/// Reads the raw image information from the specified stream.
diff --git a/src/ImageSharp/Formats/ImageDecoderUtilities.cs b/src/ImageSharp/Formats/ImageDecoderUtilities.cs
index 5d77fb0c8..13363fb64 100644
--- a/src/ImageSharp/Formats/ImageDecoderUtilities.cs
+++ b/src/ImageSharp/Formats/ImageDecoderUtilities.cs
@@ -130,13 +130,14 @@ namespace SixLabors.ImageSharp.Formats
public static IImageInfo Identify(
this IImageDecoderInternals decoder,
Configuration configuration,
- Stream stream)
+ Stream stream,
+ CancellationToken cancellationToken = default)
{
using var bufferedReadStream = new BufferedReadStream(configuration, stream);
try
{
- return decoder.Identify(bufferedReadStream, default);
+ return decoder.Identify(bufferedReadStream, cancellationToken);
}
catch (InvalidMemoryOperationException ex)
{
@@ -144,22 +145,27 @@ namespace SixLabors.ImageSharp.Formats
}
}
- public static Image Decode(this IImageDecoderInternals decoder, Configuration configuration, Stream stream)
+ public static Image Decode(
+ this IImageDecoderInternals decoder,
+ Configuration configuration,
+ Stream stream,
+ CancellationToken cancellationToken = default)
where TPixel : unmanaged, IPixel
- => decoder.Decode(configuration, stream, DefaultLargeImageExceptionFactory);
+ => decoder.Decode(configuration, stream, DefaultLargeImageExceptionFactory, cancellationToken);
public static Image Decode(
this IImageDecoderInternals decoder,
Configuration configuration,
Stream stream,
- Func largeImageExceptionFactory)
+ Func largeImageExceptionFactory,
+ CancellationToken cancellationToken = default)
where TPixel : unmanaged, IPixel
{
using var bufferedReadStream = new BufferedReadStream(configuration, stream);
try
{
- return decoder.Decode(bufferedReadStream, default);
+ return decoder.Decode(bufferedReadStream, cancellationToken);
}
catch (InvalidMemoryOperationException ex)
{
diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
index 18212ffc7..37b8fdd1f 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
@@ -17,18 +17,18 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
public bool IgnoreMetadata { get; set; }
///
- public Image Decode(Configuration configuration, Stream stream)
+ public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken = default)
where TPixel : unmanaged, IPixel
{
Guard.NotNull(stream, nameof(stream));
using var decoder = new JpegDecoderCore(configuration, this);
- return decoder.Decode(configuration, stream);
+ return decoder.Decode(configuration, stream, cancellationToken);
}
///
- public Image Decode(Configuration configuration, Stream stream)
- => this.Decode(configuration, stream);
+ public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken = default)
+ => this.Decode(configuration, stream, cancellationToken);
///
public Task> DecodeAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken)
@@ -46,12 +46,12 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
.ConfigureAwait(false);
///
- public IImageInfo Identify(Configuration configuration, Stream stream)
+ public IImageInfo Identify(Configuration configuration, Stream stream, CancellationToken cancellationToken = default)
{
Guard.NotNull(stream, nameof(stream));
using var decoder = new JpegDecoderCore(configuration, this);
- return decoder.Identify(configuration, stream);
+ return decoder.Identify(configuration, stream, cancellationToken);
}
///
diff --git a/src/ImageSharp/Formats/Pbm/PbmDecoder.cs b/src/ImageSharp/Formats/Pbm/PbmDecoder.cs
index 2eebbb1d9..f227726d1 100644
--- a/src/ImageSharp/Formats/Pbm/PbmDecoder.cs
+++ b/src/ImageSharp/Formats/Pbm/PbmDecoder.cs
@@ -30,18 +30,18 @@ namespace SixLabors.ImageSharp.Formats.Pbm
public sealed class PbmDecoder : IImageDecoder, IImageInfoDetector
{
///
- public Image Decode(Configuration configuration, Stream stream)
+ public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken = default)
where TPixel : unmanaged, IPixel
{
Guard.NotNull(stream, nameof(stream));
var decoder = new PbmDecoderCore(configuration);
- return decoder.Decode(configuration, stream);
+ return decoder.Decode(configuration, stream, cancellationToken);
}
///
- public Image Decode(Configuration configuration, Stream stream)
- => this.Decode(configuration, stream);
+ public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken = default)
+ => this.Decode(configuration, stream, cancellationToken);
///
public Task> DecodeAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken)
@@ -59,12 +59,12 @@ namespace SixLabors.ImageSharp.Formats.Pbm
.ConfigureAwait(false);
///
- public IImageInfo Identify(Configuration configuration, Stream stream)
+ public IImageInfo Identify(Configuration configuration, Stream stream, CancellationToken cancellationToken = default)
{
Guard.NotNull(stream, nameof(stream));
var decoder = new PbmDecoderCore(configuration);
- return decoder.Identify(configuration, stream);
+ return decoder.Identify(configuration, stream, cancellationToken);
}
///
diff --git a/src/ImageSharp/Formats/Png/PngDecoder.cs b/src/ImageSharp/Formats/Png/PngDecoder.cs
index 04e70c51d..b0764e040 100644
--- a/src/ImageSharp/Formats/Png/PngDecoder.cs
+++ b/src/ImageSharp/Formats/Png/PngDecoder.cs
@@ -17,18 +17,18 @@ namespace SixLabors.ImageSharp.Formats.Png
public bool IgnoreMetadata { get; set; }
///
- public Image Decode(Configuration configuration, Stream stream)
+ public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken = default)
where TPixel : unmanaged, IPixel
{
PngDecoderCore decoder = new(configuration, this);
- return decoder.Decode(configuration, stream);
+ return decoder.Decode(configuration, stream, cancellationToken);
}
///
- public Image Decode(Configuration configuration, Stream stream)
+ public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken = default)
{
PngDecoderCore decoder = new(configuration, true);
- IImageInfo info = decoder.Identify(configuration, stream);
+ IImageInfo info = decoder.Identify(configuration, stream, cancellationToken);
stream.Position = 0;
PngMetadata meta = info.Metadata.GetPngMetadata();
@@ -40,41 +40,41 @@ namespace SixLabors.ImageSharp.Formats.Png
if (bits == PngBitDepth.Bit16)
{
return !meta.HasTransparency
- ? this.Decode(configuration, stream)
- : this.Decode(configuration, stream);
+ ? this.Decode(configuration, stream, cancellationToken)
+ : this.Decode(configuration, stream, cancellationToken);
}
return !meta.HasTransparency
- ? this.Decode(configuration, stream)
- : this.Decode(configuration, stream);
+ ? this.Decode(configuration, stream, cancellationToken)
+ : this.Decode(configuration, stream, cancellationToken);
case PngColorType.Rgb:
if (bits == PngBitDepth.Bit16)
{
return !meta.HasTransparency
- ? this.Decode(configuration, stream)
- : this.Decode(configuration, stream);
+ ? this.Decode(configuration, stream, cancellationToken)
+ : this.Decode(configuration, stream, cancellationToken);
}
return !meta.HasTransparency
- ? this.Decode(configuration, stream)
- : this.Decode(configuration, stream);
+ ? this.Decode(configuration, stream, cancellationToken)
+ : this.Decode(configuration, stream, cancellationToken);
case PngColorType.Palette:
- return this.Decode(configuration, stream);
+ return this.Decode(configuration, stream, cancellationToken);
case PngColorType.GrayscaleWithAlpha:
return (bits == PngBitDepth.Bit16)
- ? this.Decode(configuration, stream)
- : this.Decode(configuration, stream);
+ ? this.Decode(configuration, stream, cancellationToken)
+ : this.Decode(configuration, stream, cancellationToken);
case PngColorType.RgbWithAlpha:
return (bits == PngBitDepth.Bit16)
- ? this.Decode(configuration, stream)
- : this.Decode(configuration, stream);
+ ? this.Decode(configuration, stream, cancellationToken)
+ : this.Decode(configuration, stream, cancellationToken);
default:
- return this.Decode(configuration, stream);
+ return this.Decode(configuration, stream, cancellationToken);
}
}
@@ -141,10 +141,10 @@ namespace SixLabors.ImageSharp.Formats.Png
}
///
- public IImageInfo Identify(Configuration configuration, Stream stream)
+ public IImageInfo Identify(Configuration configuration, Stream stream, CancellationToken cancellationToken = default)
{
PngDecoderCore decoder = new(configuration, this);
- return decoder.Identify(configuration, stream);
+ return decoder.Identify(configuration, stream, cancellationToken);
}
///
diff --git a/src/ImageSharp/Formats/Tga/TgaDecoder.cs b/src/ImageSharp/Formats/Tga/TgaDecoder.cs
index e06a0ee88..675faac61 100644
--- a/src/ImageSharp/Formats/Tga/TgaDecoder.cs
+++ b/src/ImageSharp/Formats/Tga/TgaDecoder.cs
@@ -16,18 +16,18 @@ namespace SixLabors.ImageSharp.Formats.Tga
public sealed class TgaDecoder : IImageDecoder, ITgaDecoderOptions, IImageInfoDetector
{
///
- public Image Decode(Configuration configuration, Stream stream)
+ public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken = default)
where TPixel : unmanaged, IPixel
{
Guard.NotNull(stream, nameof(stream));
var decoder = new TgaDecoderCore(configuration, this);
- return decoder.Decode(configuration, stream);
+ return decoder.Decode(configuration, stream, cancellationToken);
}
///
- public Image Decode(Configuration configuration, Stream stream)
- => this.Decode(configuration, stream);
+ public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken = default)
+ => this.Decode(configuration, stream, cancellationToken);
///
public Task> DecodeAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken)
@@ -45,11 +45,11 @@ namespace SixLabors.ImageSharp.Formats.Tga
.ConfigureAwait(false);
///
- public IImageInfo Identify(Configuration configuration, Stream stream)
+ public IImageInfo Identify(Configuration configuration, Stream stream, CancellationToken cancellationToken = default)
{
Guard.NotNull(stream, nameof(stream));
- return new TgaDecoderCore(configuration, this).Identify(configuration, stream);
+ return new TgaDecoderCore(configuration, this).Identify(configuration, stream, cancellationToken);
}
///
diff --git a/src/ImageSharp/Formats/Tiff/TiffDecoder.cs b/src/ImageSharp/Formats/Tiff/TiffDecoder.cs
index 9d52e34df..75485e400 100644
--- a/src/ImageSharp/Formats/Tiff/TiffDecoder.cs
+++ b/src/ImageSharp/Formats/Tiff/TiffDecoder.cs
@@ -19,17 +19,17 @@ namespace SixLabors.ImageSharp.Formats.Tiff
public bool IgnoreMetadata { get; set; }
///
- public Image Decode(Configuration configuration, Stream stream)
+ public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken = default)
where TPixel : unmanaged, IPixel
{
Guard.NotNull(stream, "stream");
var decoder = new TiffDecoderCore(configuration, this);
- return decoder.Decode(configuration, stream);
+ return decoder.Decode(configuration, stream, cancellationToken);
}
///
- public Image Decode(Configuration configuration, Stream stream) => this.Decode(configuration, stream);
+ public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken = default) => this.Decode(configuration, stream, cancellationToken);
///
public Task> DecodeAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken)
@@ -47,12 +47,12 @@ namespace SixLabors.ImageSharp.Formats.Tiff
.ConfigureAwait(false);
///
- public IImageInfo Identify(Configuration configuration, Stream stream)
+ public IImageInfo Identify(Configuration configuration, Stream stream, CancellationToken cancellationToken = default)
{
Guard.NotNull(stream, nameof(stream));
var decoder = new TiffDecoderCore(configuration, this);
- return decoder.Identify(configuration, stream);
+ return decoder.Identify(configuration, stream, cancellationToken);
}
///
diff --git a/src/ImageSharp/Formats/Webp/WebpDecoder.cs b/src/ImageSharp/Formats/Webp/WebpDecoder.cs
index b4e6cecd0..63b0fa505 100644
--- a/src/ImageSharp/Formats/Webp/WebpDecoder.cs
+++ b/src/ImageSharp/Formats/Webp/WebpDecoder.cs
@@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Formats.Webp
public bool IgnoreMetadata { get; set; }
///
- public Image Decode(Configuration configuration, Stream stream)
+ public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken = default)
where TPixel : unmanaged, IPixel
{
Guard.NotNull(stream, nameof(stream));
@@ -30,7 +30,7 @@ namespace SixLabors.ImageSharp.Formats.Webp
try
{
- return decoder.Decode(configuration, stream);
+ return decoder.Decode(configuration, stream, cancellationToken);
}
catch (InvalidMemoryOperationException ex)
{
@@ -41,15 +41,15 @@ namespace SixLabors.ImageSharp.Formats.Webp
}
///
- public IImageInfo Identify(Configuration configuration, Stream stream)
+ public IImageInfo Identify(Configuration configuration, Stream stream, CancellationToken cancellationToken = default)
{
Guard.NotNull(stream, nameof(stream));
- return new WebpDecoderCore(configuration, this).Identify(configuration, stream);
+ return new WebpDecoderCore(configuration, this).Identify(configuration, stream, cancellationToken);
}
///
- public Image Decode(Configuration configuration, Stream stream) => this.Decode(configuration, stream);
+ public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken = default) => this.Decode(configuration, stream, cancellationToken);
///
public Task> DecodeAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken)
diff --git a/src/ImageSharp/Image.Decode.cs b/src/ImageSharp/Image.Decode.cs
index ee340bf86..75dbd6c5c 100644
--- a/src/ImageSharp/Image.Decode.cs
+++ b/src/ImageSharp/Image.Decode.cs
@@ -148,11 +148,12 @@ namespace SixLabors.ImageSharp
///
/// The stream.
/// the configuration.
+ /// The token to monitor for cancellation requests.
/// The pixel format.
///
/// A new .
///
- private static (Image Image, IImageFormat Format) Decode(Stream stream, Configuration config)
+ private static (Image Image, IImageFormat Format) Decode(Stream stream, Configuration config, CancellationToken cancellationToken = default)
where TPixel : unmanaged, IPixel
{
IImageDecoder decoder = DiscoverDecoder(stream, config, out IImageFormat format);
@@ -161,7 +162,7 @@ namespace SixLabors.ImageSharp
return (null, null);
}
- Image img = decoder.Decode(config, stream);
+ Image img = decoder.Decode(config, stream, cancellationToken);
return (img, format);
}
@@ -191,7 +192,7 @@ namespace SixLabors.ImageSharp
return (img, format);
}
- private static (Image Image, IImageFormat Format) Decode(Stream stream, Configuration config)
+ private static (Image Image, IImageFormat Format) Decode(Stream stream, Configuration config, CancellationToken cancellationToken = default)
{
IImageDecoder decoder = DiscoverDecoder(stream, config, out IImageFormat format);
if (decoder is null)
@@ -199,7 +200,7 @@ namespace SixLabors.ImageSharp
return (null, null);
}
- Image img = decoder.Decode(config, stream);
+ Image img = decoder.Decode(config, stream, cancellationToken);
return (img, format);
}
@@ -220,10 +221,11 @@ namespace SixLabors.ImageSharp
///
/// The stream.
/// the configuration.
+ /// The token to monitor for cancellation requests.
///
/// The or null if a suitable info detector is not found.
///
- private static (IImageInfo ImageInfo, IImageFormat Format) InternalIdentity(Stream stream, Configuration config)
+ private static (IImageInfo ImageInfo, IImageFormat Format) InternalIdentity(Stream stream, Configuration config, CancellationToken cancellationToken = default)
{
IImageDecoder decoder = DiscoverDecoder(stream, config, out IImageFormat format);
@@ -232,7 +234,7 @@ namespace SixLabors.ImageSharp
return (null, null);
}
- IImageInfo info = detector?.Identify(config, stream);
+ IImageInfo info = detector?.Identify(config, stream, cancellationToken);
return (info, format);
}
diff --git a/tests/ImageSharp.Tests/Image/ImageTests.ImageLoadTestBase.cs b/tests/ImageSharp.Tests/Image/ImageTests.ImageLoadTestBase.cs
index 44d7daa74..8c4c425b4 100644
--- a/tests/ImageSharp.Tests/Image/ImageTests.ImageLoadTestBase.cs
+++ b/tests/ImageSharp.Tests/Image/ImageTests.ImageLoadTestBase.cs
@@ -63,11 +63,11 @@ namespace SixLabors.ImageSharp.Tests
this.localImageFormatMock = new Mock();
var detector = new Mock();
- detector.Setup(x => x.Identify(It.IsAny(), It.IsAny())).Returns(this.localImageInfoMock.Object);
+ detector.Setup(x => x.Identify(It.IsAny(), It.IsAny(), It.IsAny())).Returns(this.localImageInfoMock.Object);
detector.Setup(x => x.IdentifyAsync(It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(this.localImageInfoMock.Object);
this.localDecoder = detector.As();
- this.localDecoder.Setup(x => x.Decode(It.IsAny(), It.IsAny()))
+ this.localDecoder.Setup(x => x.Decode(It.IsAny(), It.IsAny(), It.IsAny()))
.Callback((c, s) =>
{
using (var ms = new MemoryStream())
@@ -78,7 +78,7 @@ namespace SixLabors.ImageSharp.Tests
})
.Returns(this.localStreamReturnImageRgba32);
- this.localDecoder.Setup(x => x.Decode(It.IsAny(), It.IsAny()))
+ this.localDecoder.Setup(x => x.Decode(It.IsAny(), It.IsAny(), It.IsAny()))
.Callback((c, s) =>
{
using (var ms = new MemoryStream())
diff --git a/tests/ImageSharp.Tests/Image/ImageTests.Load_FileSystemPath_PassLocalConfiguration.cs b/tests/ImageSharp.Tests/Image/ImageTests.Load_FileSystemPath_PassLocalConfiguration.cs
index 72477a832..0d5eead4b 100644
--- a/tests/ImageSharp.Tests/Image/ImageTests.Load_FileSystemPath_PassLocalConfiguration.cs
+++ b/tests/ImageSharp.Tests/Image/ImageTests.Load_FileSystemPath_PassLocalConfiguration.cs
@@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.Tests
var img = Image.Load(this.TopLevelConfiguration, this.MockFilePath, this.localDecoder.Object);
Assert.NotNull(img);
- this.localDecoder.Verify(x => x.Decode(this.TopLevelConfiguration, this.DataStream));
+ this.localDecoder.Verify(x => x.Decode(this.TopLevelConfiguration, this.DataStream, default));
}
[Fact]
@@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.Tests
var img = Image.Load(this.TopLevelConfiguration, this.MockFilePath, this.localDecoder.Object);
Assert.NotNull(img);
- this.localDecoder.Verify(x => x.Decode(this.TopLevelConfiguration, this.DataStream));
+ this.localDecoder.Verify(x => x.Decode(this.TopLevelConfiguration, this.DataStream, default));
}
[Fact]
diff --git a/tests/ImageSharp.Tests/Image/ImageTests.Load_FromStream_PassLocalConfiguration.cs b/tests/ImageSharp.Tests/Image/ImageTests.Load_FromStream_PassLocalConfiguration.cs
index 17b557f83..b08a82523 100644
--- a/tests/ImageSharp.Tests/Image/ImageTests.Load_FromStream_PassLocalConfiguration.cs
+++ b/tests/ImageSharp.Tests/Image/ImageTests.Load_FromStream_PassLocalConfiguration.cs
@@ -65,7 +65,7 @@ namespace SixLabors.ImageSharp.Tests
var img = Image.Load(this.TopLevelConfiguration, stream, this.localDecoder.Object);
Assert.NotNull(img);
- this.localDecoder.Verify(x => x.Decode(this.TopLevelConfiguration, stream));
+ this.localDecoder.Verify(x => x.Decode(this.TopLevelConfiguration, stream, default));
}
[Fact]
@@ -75,7 +75,7 @@ namespace SixLabors.ImageSharp.Tests
var img = Image.Load(this.TopLevelConfiguration, stream, this.localDecoder.Object);
Assert.NotNull(img);
- this.localDecoder.Verify(x => x.Decode(this.TopLevelConfiguration, stream));
+ this.localDecoder.Verify(x => x.Decode(this.TopLevelConfiguration, stream, default));
}
[Fact]
diff --git a/tests/ImageSharp.Tests/TestFormat.cs b/tests/ImageSharp.Tests/TestFormat.cs
index 6c2b97eb6..c879e66da 100644
--- a/tests/ImageSharp.Tests/TestFormat.cs
+++ b/tests/ImageSharp.Tests/TestFormat.cs
@@ -212,9 +212,9 @@ namespace SixLabors.ImageSharp.Tests
public int HeaderSize => this.testFormat.HeaderSize;
- public Image Decode(Configuration configuration, Stream stream)
+ public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel
- => this.DecodeImpl(configuration, stream, default).GetAwaiter().GetResult();
+ => this.DecodeImpl(configuration, stream, cancellationToken).GetAwaiter().GetResult();
public Task> DecodeAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel
@@ -239,13 +239,13 @@ namespace SixLabors.ImageSharp.Tests
public bool IsSupportedFileFormat(Span header) => this.testFormat.IsSupportedFileFormat(header);
- public Image Decode(Configuration configuration, Stream stream) => this.Decode(configuration, stream);
+ public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken) => this.Decode(configuration, stream, cancellationToken);
public async Task DecodeAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken)
=> await this.DecodeAsync(configuration, stream, cancellationToken);
- public IImageInfo Identify(Configuration configuration, Stream stream) =>
- this.IdentifyAsync(configuration, stream, default).GetAwaiter().GetResult();
+ public IImageInfo Identify(Configuration configuration, Stream stream, CancellationToken cancellationToken) =>
+ this.IdentifyAsync(configuration, stream, cancellationToken).GetAwaiter().GetResult();
public async Task IdentifyAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken)
=> await this.DecodeImpl(configuration, stream, cancellationToken);
diff --git a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/MagickReferenceDecoder.cs b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/MagickReferenceDecoder.cs
index f0834dc00..2d1c616c8 100644
--- a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/MagickReferenceDecoder.cs
+++ b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/MagickReferenceDecoder.cs
@@ -61,9 +61,9 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs
public Task> DecodeAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken)
where TPixel : unmanaged, ImageSharp.PixelFormats.IPixel
- => Task.FromResult(this.Decode(configuration, stream));
+ => Task.FromResult(this.Decode(configuration, stream, cancellationToken));
- public Image Decode(Configuration configuration, Stream stream)
+ public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken)
where TPixel : unmanaged, ImageSharp.PixelFormats.IPixel
{
var bmpReadDefines = new BmpReadDefines
@@ -105,7 +105,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs
return new Image(configuration, new ImageMetadata(), framesList);
}
- public Image Decode(Configuration configuration, Stream stream) => this.Decode(configuration, stream);
+ public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken) => this.Decode(configuration, stream, cancellationToken);
public async Task DecodeAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken)
=> await this.DecodeAsync(configuration, stream, cancellationToken);
diff --git a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceDecoder.cs b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceDecoder.cs
index 1eb1328ef..3bc6fef29 100644
--- a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceDecoder.cs
+++ b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceDecoder.cs
@@ -17,9 +17,9 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs
public Task> DecodeAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel
- => Task.FromResult(this.Decode(configuration, stream));
+ => Task.FromResult(this.Decode(configuration, stream, cancellationToken));
- public Image Decode(Configuration configuration, Stream stream)
+ public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel
{
using (var sourceBitmap = new System.Drawing.Bitmap(stream))
@@ -50,9 +50,9 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs
}
public Task IdentifyAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken)
- => Task.FromResult(this.Identify(configuration, stream));
+ => Task.FromResult(this.Identify(configuration, stream, cancellationToken));
- public IImageInfo Identify(Configuration configuration, Stream stream)
+ public IImageInfo Identify(Configuration configuration, Stream stream, CancellationToken cancellationToken)
{
using (var sourceBitmap = new System.Drawing.Bitmap(stream))
{
@@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs
}
}
- public Image Decode(Configuration configuration, Stream stream) => this.Decode(configuration, stream);
+ public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken) => this.Decode(configuration, stream, cancellationToken);
public async Task DecodeAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken)
=> await this.DecodeAsync(configuration, stream, cancellationToken);
diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs
index 129d17f4d..0ed57994d 100644
--- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs
+++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs
@@ -365,7 +365,7 @@ namespace SixLabors.ImageSharp.Tests
}
}
- public Image Decode(Configuration configuration, Stream stream)
+ public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel
{
InvocationCounts[this.callerName]++;
@@ -390,7 +390,7 @@ namespace SixLabors.ImageSharp.Tests
InvocationCountsAsync[name] = 0;
}
- public Image Decode(Configuration configuration, Stream stream) => this.Decode(configuration, stream);
+ public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken) => this.Decode(configuration, stream, cancellationToken);
public async Task DecodeAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken)
=> await this.DecodeAsync(configuration, stream, cancellationToken);
@@ -420,7 +420,7 @@ namespace SixLabors.ImageSharp.Tests
}
}
- public Image Decode(Configuration configuration, Stream stream)
+ public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel
{
InvocationCounts[this.callerName]++;
@@ -445,7 +445,7 @@ namespace SixLabors.ImageSharp.Tests
InvocationCountsAsync[name] = 0;
}
- public Image Decode(Configuration configuration, Stream stream) => this.Decode(configuration, stream);
+ public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken) => this.Decode(configuration, stream, cancellationToken);
public async Task DecodeAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken)
=> await this.DecodeAsync(configuration, stream, cancellationToken);