From 205e1b369c68f27a63080e96f3554ab562ce2400 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 13 Dec 2022 09:42:44 +1000 Subject: [PATCH] Make decoder cancellation token default. --- src/ImageSharp/Formats/IImageDecoder.cs | 6 +++--- src/ImageSharp/Formats/ISpecializedImageDecoder{T}.cs | 4 ++-- src/ImageSharp/Formats/SpecializedImageDecoder{T}.cs | 4 ++-- tests/ImageSharp.Tests/Formats/Gif/GifMetadataTests.cs | 4 ++-- .../Formats/Jpg/JpegDecoderTests.Metadata.cs | 4 ++-- .../TestUtilities/ImageProviders/FileProvider.cs | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/ImageSharp/Formats/IImageDecoder.cs b/src/ImageSharp/Formats/IImageDecoder.cs index 86f4f3fa8a..3729c98d9b 100644 --- a/src/ImageSharp/Formats/IImageDecoder.cs +++ b/src/ImageSharp/Formats/IImageDecoder.cs @@ -27,7 +27,7 @@ public interface IImageDecoder /// The token to monitor for cancellation requests. /// The object. /// Thrown if the encoded image contains errors. - public Task IdentifyAsync(DecoderOptions options, Stream stream, CancellationToken cancellationToken); + public Task IdentifyAsync(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default); /// /// Decodes the image from the specified stream to an of a specific pixel type. @@ -58,7 +58,7 @@ public interface IImageDecoder /// The token to monitor for cancellation requests. /// A representing the asynchronous operation. /// Thrown if the encoded image contains errors. - public Task> DecodeAsync(DecoderOptions options, Stream stream, CancellationToken cancellationToken) + public Task> DecodeAsync(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default) where TPixel : unmanaged, IPixel; /// @@ -69,5 +69,5 @@ public interface IImageDecoder /// The token to monitor for cancellation requests. /// A representing the asynchronous operation. /// Thrown if the encoded image contains errors. - public Task DecodeAsync(DecoderOptions options, Stream stream, CancellationToken cancellationToken); + public Task DecodeAsync(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default); } diff --git a/src/ImageSharp/Formats/ISpecializedImageDecoder{T}.cs b/src/ImageSharp/Formats/ISpecializedImageDecoder{T}.cs index 2bda864bc2..e9506795ce 100644 --- a/src/ImageSharp/Formats/ISpecializedImageDecoder{T}.cs +++ b/src/ImageSharp/Formats/ISpecializedImageDecoder{T}.cs @@ -41,7 +41,7 @@ public interface ISpecializedImageDecoder : IImageDecoder /// The token to monitor for cancellation requests. /// A representing the asynchronous operation. /// Thrown if the encoded image contains errors. - public Task> DecodeAsync(T options, Stream stream, CancellationToken cancellationToken) + public Task> DecodeAsync(T options, Stream stream, CancellationToken cancellationToken = default) where TPixel : unmanaged, IPixel; /// @@ -52,5 +52,5 @@ public interface ISpecializedImageDecoder : IImageDecoder /// The token to monitor for cancellation requests. /// A representing the asynchronous operation. /// Thrown if the encoded image contains errors. - public Task DecodeAsync(T options, Stream stream, CancellationToken cancellationToken); + public Task DecodeAsync(T options, Stream stream, CancellationToken cancellationToken = default); } diff --git a/src/ImageSharp/Formats/SpecializedImageDecoder{T}.cs b/src/ImageSharp/Formats/SpecializedImageDecoder{T}.cs index f3e9c99172..fa6461464b 100644 --- a/src/ImageSharp/Formats/SpecializedImageDecoder{T}.cs +++ b/src/ImageSharp/Formats/SpecializedImageDecoder{T}.cs @@ -30,7 +30,7 @@ public abstract class SpecializedImageDecoder : ImageDecoder, ISpecializedIma s => this.Decode(options, s, default)); /// - public Task> DecodeAsync(T options, Stream stream, CancellationToken cancellationToken) + public Task> DecodeAsync(T options, Stream stream, CancellationToken cancellationToken = default) where TPixel : unmanaged, IPixel => WithSeekableMemoryStreamAsync( options.GeneralOptions, @@ -39,7 +39,7 @@ public abstract class SpecializedImageDecoder : ImageDecoder, ISpecializedIma cancellationToken); /// - public Task DecodeAsync(T options, Stream stream, CancellationToken cancellationToken) + public Task DecodeAsync(T options, Stream stream, CancellationToken cancellationToken = default) => WithSeekableMemoryStreamAsync( options.GeneralOptions, stream, diff --git a/tests/ImageSharp.Tests/Formats/Gif/GifMetadataTests.cs b/tests/ImageSharp.Tests/Formats/Gif/GifMetadataTests.cs index 4bd40dbcdf..2d66842e88 100644 --- a/tests/ImageSharp.Tests/Formats/Gif/GifMetadataTests.cs +++ b/tests/ImageSharp.Tests/Formats/Gif/GifMetadataTests.cs @@ -128,7 +128,7 @@ public class GifMetadataTests var testFile = TestFile.Create(imagePath); using var stream = new MemoryStream(testFile.Bytes, false); var decoder = new GifDecoder(); - IImageInfo image = await decoder.IdentifyAsync(DecoderOptions.Default, stream, default); + IImageInfo image = await decoder.IdentifyAsync(DecoderOptions.Default, stream); ImageMetadata meta = image.Metadata; Assert.Equal(xResolution, meta.HorizontalResolution); Assert.Equal(yResolution, meta.VerticalResolution); @@ -156,7 +156,7 @@ public class GifMetadataTests var testFile = TestFile.Create(imagePath); using var stream = new MemoryStream(testFile.Bytes, false); var decoder = new GifDecoder(); - using Image image = await decoder.DecodeAsync(DecoderOptions.Default, stream, default); + using Image image = await decoder.DecodeAsync(DecoderOptions.Default, stream); ImageMetadata meta = image.Metadata; Assert.Equal(xResolution, meta.HorizontalResolution); Assert.Equal(yResolution, meta.VerticalResolution); diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Metadata.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Metadata.cs index ebcf9c8827..593b0f287d 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Metadata.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Metadata.cs @@ -106,7 +106,7 @@ public partial class JpegDecoderTests var testFile = TestFile.Create(imagePath); using var stream = new MemoryStream(testFile.Bytes, false); var decoder = new JpegDecoder(); - IImageInfo image = await decoder.IdentifyAsync(DecoderOptions.Default, stream, default); + IImageInfo image = await decoder.IdentifyAsync(DecoderOptions.Default, stream); ImageMetadata meta = image.Metadata; Assert.Equal(xResolution, meta.HorizontalResolution); Assert.Equal(yResolution, meta.VerticalResolution); @@ -142,7 +142,7 @@ public partial class JpegDecoderTests { var testFile = TestFile.Create(imagePath); using var stream = new MemoryStream(testFile.Bytes, false); - using Image image = await JpegDecoder.DecodeAsync(DecoderOptions.Default, stream, default); + using Image image = await JpegDecoder.DecodeAsync(DecoderOptions.Default, stream); JpegMetadata meta = image.Metadata.GetJpegMetadata(); Assert.Equal(quality, meta.Quality); } diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs index 10126aab73..3285da31b4 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs @@ -213,7 +213,7 @@ public abstract partial class TestImageProvider : IXunitSerializable // TODO: Check Path here. Why combined? string path = Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.FilePath); using Stream stream = System.IO.File.OpenRead(path); - return await decoder.DecodeAsync(options, stream, default); + return await decoder.DecodeAsync(options, stream); } public override Image GetImage(ISpecializedImageDecoder decoder, T options) @@ -250,7 +250,7 @@ public abstract partial class TestImageProvider : IXunitSerializable // TODO: Check Path here. Why combined? string path = Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.FilePath); using Stream stream = System.IO.File.OpenRead(path); - return await decoder.DecodeAsync(options, stream, default); + return await decoder.DecodeAsync(options, stream); } public override void Deserialize(IXunitSerializationInfo info)