Browse Source

Make decoder cancellation token default.

pull/2276/head
James Jackson-South 4 years ago
parent
commit
205e1b369c
  1. 6
      src/ImageSharp/Formats/IImageDecoder.cs
  2. 4
      src/ImageSharp/Formats/ISpecializedImageDecoder{T}.cs
  3. 4
      src/ImageSharp/Formats/SpecializedImageDecoder{T}.cs
  4. 4
      tests/ImageSharp.Tests/Formats/Gif/GifMetadataTests.cs
  5. 4
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Metadata.cs
  6. 4
      tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs

6
src/ImageSharp/Formats/IImageDecoder.cs

@ -27,7 +27,7 @@ public interface IImageDecoder
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>The <see cref="Task{IImageInfo}"/> object.</returns>
/// <exception cref="ImageFormatException">Thrown if the encoded image contains errors.</exception>
public Task<IImageInfo> IdentifyAsync(DecoderOptions options, Stream stream, CancellationToken cancellationToken);
public Task<IImageInfo> IdentifyAsync(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default);
/// <summary>
/// Decodes the image from the specified stream to an <see cref="Image{TPixel}"/> of a specific pixel type.
@ -58,7 +58,7 @@ public interface IImageDecoder
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>A <see cref="Task{Image}"/> representing the asynchronous operation.</returns>
/// <exception cref="ImageFormatException">Thrown if the encoded image contains errors.</exception>
public Task<Image<TPixel>> DecodeAsync<TPixel>(DecoderOptions options, Stream stream, CancellationToken cancellationToken)
public Task<Image<TPixel>> DecodeAsync<TPixel>(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default)
where TPixel : unmanaged, IPixel<TPixel>;
/// <summary>
@ -69,5 +69,5 @@ public interface IImageDecoder
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>A <see cref="Task{Image}"/> representing the asynchronous operation.</returns>
/// <exception cref="ImageFormatException">Thrown if the encoded image contains errors.</exception>
public Task<Image> DecodeAsync(DecoderOptions options, Stream stream, CancellationToken cancellationToken);
public Task<Image> DecodeAsync(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default);
}

4
src/ImageSharp/Formats/ISpecializedImageDecoder{T}.cs

@ -41,7 +41,7 @@ public interface ISpecializedImageDecoder<T> : IImageDecoder
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>A <see cref="Task{Image}"/> representing the asynchronous operation.</returns>
/// <exception cref="ImageFormatException">Thrown if the encoded image contains errors.</exception>
public Task<Image<TPixel>> DecodeAsync<TPixel>(T options, Stream stream, CancellationToken cancellationToken)
public Task<Image<TPixel>> DecodeAsync<TPixel>(T options, Stream stream, CancellationToken cancellationToken = default)
where TPixel : unmanaged, IPixel<TPixel>;
/// <summary>
@ -52,5 +52,5 @@ public interface ISpecializedImageDecoder<T> : IImageDecoder
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>A <see cref="Task{Image}"/> representing the asynchronous operation.</returns>
/// <exception cref="ImageFormatException">Thrown if the encoded image contains errors.</exception>
public Task<Image> DecodeAsync(T options, Stream stream, CancellationToken cancellationToken);
public Task<Image> DecodeAsync(T options, Stream stream, CancellationToken cancellationToken = default);
}

4
src/ImageSharp/Formats/SpecializedImageDecoder{T}.cs

@ -30,7 +30,7 @@ public abstract class SpecializedImageDecoder<T> : ImageDecoder, ISpecializedIma
s => this.Decode(options, s, default));
/// <inheritdoc/>
public Task<Image<TPixel>> DecodeAsync<TPixel>(T options, Stream stream, CancellationToken cancellationToken)
public Task<Image<TPixel>> DecodeAsync<TPixel>(T options, Stream stream, CancellationToken cancellationToken = default)
where TPixel : unmanaged, IPixel<TPixel>
=> WithSeekableMemoryStreamAsync(
options.GeneralOptions,
@ -39,7 +39,7 @@ public abstract class SpecializedImageDecoder<T> : ImageDecoder, ISpecializedIma
cancellationToken);
/// <inheritdoc/>
public Task<Image> DecodeAsync(T options, Stream stream, CancellationToken cancellationToken)
public Task<Image> DecodeAsync(T options, Stream stream, CancellationToken cancellationToken = default)
=> WithSeekableMemoryStreamAsync(
options.GeneralOptions,
stream,

4
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<Rgba32> image = await decoder.DecodeAsync<Rgba32>(DecoderOptions.Default, stream, default);
using Image<Rgba32> image = await decoder.DecodeAsync<Rgba32>(DecoderOptions.Default, stream);
ImageMetadata meta = image.Metadata;
Assert.Equal(xResolution, meta.HorizontalResolution);
Assert.Equal(yResolution, meta.VerticalResolution);

4
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);
}

4
tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs

@ -213,7 +213,7 @@ public abstract partial class TestImageProvider<TPixel> : 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<TPixel>(options, stream, default);
return await decoder.DecodeAsync<TPixel>(options, stream);
}
public override Image<TPixel> GetImage<T>(ISpecializedImageDecoder<T> decoder, T options)
@ -250,7 +250,7 @@ public abstract partial class TestImageProvider<TPixel> : 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<TPixel>(options, stream, default);
return await decoder.DecodeAsync<TPixel>(options, stream);
}
public override void Deserialize(IXunitSerializationInfo info)

Loading…
Cancel
Save