Browse Source

Cleanup and normalization

pull/2006/head
James Jackson-South 4 years ago
parent
commit
2474aab550
  1. 5
      src/ImageSharp/Formats/Gif/GifDecoder.cs
  2. 8
      src/ImageSharp/Formats/ImageDecoderUtilities.cs
  3. 5
      src/ImageSharp/Formats/Tiff/TiffDecoder.cs
  4. 6
      src/ImageSharp/Formats/Webp/WebpDecoder.cs
  5. 4
      src/ImageSharp/Image.Decode.cs
  6. 4
      src/ImageSharp/Image.FromStream.cs

5
src/ImageSharp/Formats/Gif/GifDecoder.cs

@ -3,7 +3,6 @@
using System.IO;
using System.Threading;
using SixLabors.ImageSharp.IO;
using SixLabors.ImageSharp.Metadata;
using SixLabors.ImageSharp.PixelFormats;
@ -42,9 +41,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
Guard.NotNull(stream, nameof(stream));
var decoder = new GifDecoderCore(configuration, this);
using var bufferedStream = new BufferedReadStream(configuration, stream);
return decoder.Identify(bufferedStream, cancellationToken);
return decoder.Identify(configuration, stream, cancellationToken);
}
}
}

8
src/ImageSharp/Formats/ImageDecoderUtilities.cs

@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Formats
this IImageDecoderInternals decoder,
Configuration configuration,
Stream stream,
CancellationToken cancellationToken = default)
CancellationToken cancellationToken)
{
using var bufferedReadStream = new BufferedReadStream(configuration, stream);
@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp.Formats
this IImageDecoderInternals decoder,
Configuration configuration,
Stream stream,
CancellationToken cancellationToken = default)
CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel<TPixel>
=> decoder.Decode<TPixel>(configuration, stream, DefaultLargeImageExceptionFactory, cancellationToken);
@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Formats
Configuration configuration,
Stream stream,
Func<InvalidMemoryOperationException, Size, InvalidImageContentException> largeImageExceptionFactory,
CancellationToken cancellationToken = default)
CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel<TPixel>
{
using var bufferedReadStream = new BufferedReadStream(configuration, stream);
@ -61,6 +61,6 @@ namespace SixLabors.ImageSharp.Formats
private static InvalidImageContentException DefaultLargeImageExceptionFactory(
InvalidMemoryOperationException memoryOperationException,
Size dimensions) =>
new InvalidImageContentException(dimensions, memoryOperationException);
new(dimensions, memoryOperationException);
}
}

5
src/ImageSharp/Formats/Tiff/TiffDecoder.cs

@ -21,14 +21,15 @@ namespace SixLabors.ImageSharp.Formats.Tiff
public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream, CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel<TPixel>
{
Guard.NotNull(stream, "stream");
Guard.NotNull(stream, nameof(stream));
var decoder = new TiffDecoderCore(configuration, this);
return decoder.Decode<TPixel>(configuration, stream, cancellationToken);
}
/// <inheritdoc/>
public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken) => this.Decode<Rgba32>(configuration, stream, cancellationToken);
public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken)
=> this.Decode<Rgba32>(configuration, stream, cancellationToken);
/// <inheritdoc/>
public IImageInfo Identify(Configuration configuration, Stream stream, CancellationToken cancellationToken)

6
src/ImageSharp/Formats/Webp/WebpDecoder.cs

@ -38,6 +38,10 @@ namespace SixLabors.ImageSharp.Formats.Webp
}
}
/// <inheritdoc />
public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken)
=> this.Decode<Rgba32>(configuration, stream, cancellationToken);
/// <inheritdoc/>
public IImageInfo Identify(Configuration configuration, Stream stream, CancellationToken cancellationToken)
{
@ -46,7 +50,5 @@ namespace SixLabors.ImageSharp.Formats.Webp
return new WebpDecoderCore(configuration, this).Identify(configuration, stream, cancellationToken);
}
/// <inheritdoc />
public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken) => this.Decode<Rgba32>(configuration, stream, cancellationToken);
}
}

4
src/ImageSharp/Image.Decode.cs

@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp
/// The image might be filled with memory garbage.
/// </summary>
/// <typeparam name="TPixel">The pixel type</typeparam>
/// <param name="configuration">The <see cref="ImageSharp.Configuration"/></param>
/// <param name="configuration">The <see cref="Configuration"/></param>
/// <param name="width">The width of the image</param>
/// <param name="height">The height of the image</param>
/// <param name="metadata">The <see cref="ImageMetadata"/></param>
@ -159,7 +159,7 @@ namespace SixLabors.ImageSharp
{
IImageDecoder decoder = DiscoverDecoder(stream, config, out IImageFormat format);
if (!(decoder is IImageInfoDetector detector))
if (decoder is not IImageInfoDetector detector)
{
return (null, null);
}

4
src/ImageSharp/Image.FromStream.cs

@ -432,9 +432,9 @@ namespace SixLabors.ImageSharp
/// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A <see cref="Task{ValueTuple}"/> representing the asynchronous operation.</returns>
public static async Task<(Image<TPixel> Image, IImageFormat Format)> LoadWithFormatAsync<TPixel>(Stream stream, CancellationToken cancellationToken = default)
public static Task<(Image<TPixel> Image, IImageFormat Format)> LoadWithFormatAsync<TPixel>(Stream stream, CancellationToken cancellationToken = default)
where TPixel : unmanaged, IPixel<TPixel>
=> await LoadWithFormatAsync<TPixel>(Configuration.Default, stream, cancellationToken).ConfigureAwait(false);
=> LoadWithFormatAsync<TPixel>(Configuration.Default, stream, cancellationToken);
/// <summary>
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given stream.

Loading…
Cancel
Save