Browse Source

Revert recent Detect changes and normalize.

pull/2317/head
James Jackson-South 4 years ago
parent
commit
eff9b0a6a5
  1. 38
      src/ImageSharp/Image.FromBytes.cs
  2. 51
      src/ImageSharp/Image.FromFile.cs
  3. 62
      src/ImageSharp/Image.FromStream.cs
  4. 16
      tests/ImageSharp.Tests/Formats/Bmp/ImageExtensionsTest.cs
  5. 16
      tests/ImageSharp.Tests/Formats/Gif/ImageExtensionsTest.cs
  6. 13
      tests/ImageSharp.Tests/Formats/ImageFormatManagerTests.cs
  7. 16
      tests/ImageSharp.Tests/Formats/Jpg/ImageExtensionsTest.cs
  8. 16
      tests/ImageSharp.Tests/Formats/Pbm/ImageExtensionsTest.cs
  9. 16
      tests/ImageSharp.Tests/Formats/Png/ImageExtensionsTest.cs
  10. 16
      tests/ImageSharp.Tests/Formats/Tga/ImageExtensionsTest.cs
  11. 16
      tests/ImageSharp.Tests/Formats/Tiff/ImageExtensionsTest.cs
  12. 16
      tests/ImageSharp.Tests/Formats/WebP/ImageExtensionsTests.cs
  13. 59
      tests/ImageSharp.Tests/Image/ImageTests.DetectFormat.cs
  14. 4
      tests/ImageSharp.Tests/Image/ImageTests.Save.cs
  15. 6
      tests/ImageSharp.Tests/Image/ImageTests.SaveAsync.cs
  16. 1
      tests/ImageSharp.Tests/TestImages.cs

38
src/ImageSharp/Image.FromBytes.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Six Labors Split License. // Licensed under the Six Labors Split License.
using System.Diagnostics.CodeAnalysis;
using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
@ -16,41 +15,32 @@ public abstract partial class Image
/// By reading the header on the provided byte span this calculates the images format. /// By reading the header on the provided byte span this calculates the images format.
/// </summary> /// </summary>
/// <param name="buffer">The byte span containing encoded image data to read the header from.</param> /// <param name="buffer">The byte span containing encoded image data to read the header from.</param>
/// <param name="format">The format or null if none found.</param> /// <returns>The <see cref="IImageFormat"/>.</returns>
/// <returns>returns true when format was detected otherwise false.</returns> /// <exception cref="NotSupportedException">The image format is not supported.</exception>
public static bool TryDetectFormat(ReadOnlySpan<byte> buffer, [NotNullWhen(true)] out IImageFormat? format) /// <exception cref="InvalidImageContentException">The encoded image contains invalid content.</exception>
=> TryDetectFormat(DecoderOptions.Default, buffer, out format); /// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
public static IImageFormat DetectFormat(ReadOnlySpan<byte> buffer)
=> DetectFormat(DecoderOptions.Default, buffer);
/// <summary> /// <summary>
/// By reading the header on the provided byte span this calculates the images format. /// By reading the header on the provided byte span this calculates the images format.
/// </summary> /// </summary>
/// <param name="options">The general decoder options.</param> /// <param name="options">The general decoder options.</param>
/// <param name="buffer">The byte span containing encoded image data to read the header from.</param> /// <param name="buffer">The byte span containing encoded image data to read the header from.</param>
/// <param name="format">The mime type or null if none found.</param> /// <returns>The <see cref="IImageFormat"/>.</returns>
/// <exception cref="ArgumentNullException">The options are null.</exception> /// <exception cref="ArgumentNullException">The options are null.</exception>
/// <returns>returns true when format was detected otherwise false.</returns> /// <exception cref="NotSupportedException">The image format is not supported.</exception>
public static bool TryDetectFormat(DecoderOptions options, ReadOnlySpan<byte> buffer, [NotNullWhen(true)] out IImageFormat? format) /// <exception cref="InvalidImageContentException">The encoded image contains invalid content.</exception>
/// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
public static unsafe IImageFormat DetectFormat(DecoderOptions options, ReadOnlySpan<byte> buffer)
{ {
Guard.NotNull(options, nameof(options.Configuration)); Guard.NotNull(options, nameof(options.Configuration));
Configuration configuration = options.Configuration; fixed (byte* ptr = buffer)
int maxHeaderSize = configuration.MaxHeaderSize;
if (maxHeaderSize <= 0)
{
format = null;
return false;
}
foreach (IImageFormatDetector detector in configuration.ImageFormatsManager.FormatDetectors)
{ {
if (detector.TryDetectFormat(buffer, out format)) using UnmanagedMemoryStream stream = new(ptr, buffer.Length);
{ return DetectFormat(options, stream);
return true;
}
} }
format = default;
return false;
} }
/// <summary> /// <summary>

51
src/ImageSharp/Image.FromFile.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Six Labors Split License. // Licensed under the Six Labors Split License.
using System.Diagnostics.CodeAnalysis;
using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
@ -14,61 +13,59 @@ public abstract partial class Image
{ {
/// <summary> /// <summary>
/// Detects the encoded image format type from the specified file. /// Detects the encoded image format type from the specified file.
/// A return value indicates whether the operation succeeded.
/// </summary> /// </summary>
/// <param name="path">The image file to open and to read the header from.</param> /// <param name="path">The image file to open and to read the header from.</param>
/// <param name="format"> /// <returns>The <see cref="IImageFormat"/>.</returns>
/// When this method returns, contains the format that matches the given file; /// <exception cref="ArgumentNullException">The path is null.</exception>
/// otherwise, the default value for the type of the <paramref name="format"/> parameter. /// <exception cref="NotSupportedException">The file stream is not readable or the image format is not supported.</exception>
/// This parameter is passed uninitialized. /// <exception cref="InvalidImageContentException">The encoded image contains invalid content.</exception>
/// </param> /// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
/// <returns><see langword="true"/> if a match is found; otherwise, <see langword="false"/></returns> public static IImageFormat DetectFormat(string path)
public static bool TryDetectFormat(string path, [NotNullWhen(true)] out IImageFormat? format) => DetectFormat(DecoderOptions.Default, path);
=> TryDetectFormat(DecoderOptions.Default, path, out format);
/// <summary> /// <summary>
/// Detects the encoded image format type from the specified file. /// Detects the encoded image format type from the specified file.
/// A return value indicates whether the operation succeeded.
/// </summary> /// </summary>
/// <param name="options">The general decoder options.</param> /// <param name="options">The general decoder options.</param>
/// <param name="path">The image file to open and to read the header from.</param> /// <param name="path">The image file to open and to read the header from.</param>
/// <param name="format"> /// <returns>The <see cref="IImageFormat"/>.</returns>
/// When this method returns, contains the format that matches the given file;
/// otherwise, the default value for the type of the <paramref name="format"/> parameter.
/// This parameter is passed uninitialized.
/// </param>
/// <returns><see langword="true"/> if a match is found; otherwise, <see langword="false"/></returns>
/// <exception cref="ArgumentNullException">The options are null.</exception> /// <exception cref="ArgumentNullException">The options are null.</exception>
public static bool TryDetectFormat(DecoderOptions options, string path, [NotNullWhen(true)] out IImageFormat? format) /// <exception cref="ArgumentNullException">The path is null.</exception>
/// <exception cref="NotSupportedException">The file stream is not readable or the image format is not supported.</exception>
/// <exception cref="InvalidImageContentException">The encoded image contains invalid content.</exception>
/// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
public static IImageFormat DetectFormat(DecoderOptions options, string path)
{ {
Guard.NotNull(options, nameof(options)); Guard.NotNull(options, nameof(options));
using Stream file = options.Configuration.FileSystem.OpenRead(path); using Stream file = options.Configuration.FileSystem.OpenRead(path);
return TryDetectFormat(options, file, out format); return DetectFormat(options, file);
} }
/// <summary> /// <summary>
/// Detects the encoded image format type from the specified file. /// Detects the encoded image format type from the specified file.
/// A return value indicates whether the operation succeeded.
/// </summary> /// </summary>
/// <param name="path">The image file to open and to read the header from.</param> /// <param name="path">The image file to open and to read the header from.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param> /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>A <see cref="Task{Attempt}"/> representing the asynchronous operation.</returns> /// <returns>A <see cref="Task{IImageFormat}"/> representing the asynchronous operation.</returns>
public static Task<Attempt<IImageFormat>> TryDetectFormatAsync( public static Task<IImageFormat> DetectFormatAsync(
string path, string path,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
=> TryDetectFormatAsync(DecoderOptions.Default, path, cancellationToken); => DetectFormatAsync(DecoderOptions.Default, path, cancellationToken);
/// <summary> /// <summary>
/// Detects the encoded image format type from the specified file. /// Detects the encoded image format type from the specified file.
/// A return value indicates whether the operation succeeded.
/// </summary> /// </summary>
/// <param name="options">The general decoder options.</param> /// <param name="options">The general decoder options.</param>
/// <param name="path">The image file to open and to read the header from.</param> /// <param name="path">The image file to open and to read the header from.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param> /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>A <see cref="Task{IImageFormat}"/> representing the asynchronous operation.</returns>
/// <exception cref="ArgumentNullException">The options are null.</exception> /// <exception cref="ArgumentNullException">The options are null.</exception>
/// <returns>A <see cref="Task{Attempt}"/> representing the asynchronous operation.</returns> /// <exception cref="ArgumentNullException">The path is null.</exception>
public static async Task<Attempt<IImageFormat>> TryDetectFormatAsync( /// <exception cref="NotSupportedException">The file stream is not readable or the image format is not supported.</exception>
/// <exception cref="InvalidImageContentException">The encoded image contains invalid content.</exception>
/// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
public static async Task<IImageFormat> DetectFormatAsync(
DecoderOptions options, DecoderOptions options,
string path, string path,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
@ -76,7 +73,7 @@ public abstract partial class Image
Guard.NotNull(options, nameof(options)); Guard.NotNull(options, nameof(options));
using Stream stream = options.Configuration.FileSystem.OpenRead(path); using Stream stream = options.Configuration.FileSystem.OpenRead(path);
return await TryDetectFormatAsync(options, stream, cancellationToken).ConfigureAwait(false); return await DetectFormatAsync(options, stream, cancellationToken).ConfigureAwait(false);
} }
/// <summary> /// <summary>

62
src/ImageSharp/Image.FromStream.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Six Labors Split License. // Licensed under the Six Labors Split License.
using System.Diagnostics.CodeAnalysis;
using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.IO; using SixLabors.ImageSharp.IO;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
@ -15,79 +14,66 @@ public abstract partial class Image
{ {
/// <summary> /// <summary>
/// Detects the encoded image format type from the specified stream. /// Detects the encoded image format type from the specified stream.
/// A return value indicates whether the operation succeeded.
/// </summary> /// </summary>
/// <param name="stream">The image stream to read the header from.</param> /// <param name="stream">The image stream to read the header from.</param>
/// <param name="format"> /// <returns>The <see cref="IImageFormat"/>.</returns>
/// When this method returns, contains the format that matches the given stream;
/// otherwise, the default value for the type of the <paramref name="format"/> parameter.
/// This parameter is passed uninitialized.
/// </param>
/// <returns><see langword="true"/> if a match is found; otherwise, <see langword="false"/></returns>
/// <exception cref="ArgumentNullException">The stream is null.</exception> /// <exception cref="ArgumentNullException">The stream is null.</exception>
/// <exception cref="NotSupportedException">The stream is not readable.</exception> /// <exception cref="NotSupportedException">The stream is not readable or the image format is not supported.</exception>
public static bool TryDetectFormat(Stream stream, [NotNullWhen(true)] out IImageFormat? format) /// <exception cref="InvalidImageContentException">The encoded image contains invalid content.</exception>
=> TryDetectFormat(DecoderOptions.Default, stream, out format); /// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
public static IImageFormat DetectFormat(Stream stream)
=> DetectFormat(DecoderOptions.Default, stream);
/// <summary> /// <summary>
/// Detects the encoded image format type from the specified stream. /// Detects the encoded image format type from the specified stream.
/// A return value indicates whether the operation succeeded.
/// </summary> /// </summary>
/// <param name="options">The general decoder options.</param> /// <param name="options">The general decoder options.</param>
/// <param name="stream">The image stream to read the header from.</param> /// <param name="stream">The image stream to read the header from.</param>
/// <param name="format">
/// When this method returns, contains the format that matches the given stream;
/// otherwise, the default value for the type of the <paramref name="format"/> parameter.
/// This parameter is passed uninitialized.
/// </param>
/// <returns><see langword="true"/> if a match is found; otherwise, <see langword="false"/></returns> /// <returns><see langword="true"/> if a match is found; otherwise, <see langword="false"/></returns>
/// <exception cref="ArgumentNullException">The options are null.</exception> /// <exception cref="ArgumentNullException">The options are null.</exception>
/// <exception cref="ArgumentNullException">The stream is null.</exception> /// <exception cref="ArgumentNullException">The stream is null.</exception>
/// <exception cref="NotSupportedException">The stream is not readable.</exception> /// <exception cref="NotSupportedException">The stream is not readable or the image format is not supported.</exception>
public static bool TryDetectFormat(DecoderOptions options, Stream stream, [NotNullWhen(true)] out IImageFormat? format) /// <exception cref="InvalidImageContentException">The encoded image contains invalid content.</exception>
{ /// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
format = WithSeekableStream(options, stream, s => InternalDetectFormat(options.Configuration, s)); public static IImageFormat DetectFormat(DecoderOptions options, Stream stream)
return format is not null; => WithSeekableStream(options, stream, s => InternalDetectFormat(options.Configuration, s));
}
/// <summary> /// <summary>
/// Detects the encoded image format type from the specified stream. /// Detects the encoded image format type from the specified stream.
/// A return value indicates whether the operation succeeded.
/// </summary> /// </summary>
/// <param name="stream">The image stream to read the header from.</param> /// <param name="stream">The image stream to read the header from.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param> /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>A <see cref="Task{IImageFormat}"/> representing the asynchronous operation.</returns>
/// <exception cref="ArgumentNullException">The stream is null.</exception> /// <exception cref="ArgumentNullException">The stream is null.</exception>
/// <exception cref="NotSupportedException">The stream is not readable.</exception> /// <exception cref="NotSupportedException">The stream is not readable or the image format is not supported.</exception>
/// <returns>A <see cref="Task{Attempt}"/> representing the asynchronous operation.</returns> /// <exception cref="InvalidImageContentException">The encoded image contains invalid content.</exception>
public static Task<Attempt<IImageFormat>> TryDetectFormatAsync( /// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
public static Task<IImageFormat> DetectFormatAsync(
Stream stream, Stream stream,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
=> TryDetectFormatAsync(DecoderOptions.Default, stream, cancellationToken); => DetectFormatAsync(DecoderOptions.Default, stream, cancellationToken);
/// <summary> /// <summary>
/// Detects the encoded image format type from the specified stream. /// Detects the encoded image format type from the specified stream.
/// A return value indicates whether the operation succeeded.
/// </summary> /// </summary>
/// <param name="options">The general decoder options.</param> /// <param name="options">The general decoder options.</param>
/// <param name="stream">The image stream to read the header from.</param> /// <param name="stream">The image stream to read the header from.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param> /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>A <see cref="Task{IImageFormat}"/> representing the asynchronous operation.</returns>
/// <exception cref="ArgumentNullException">The options are null.</exception> /// <exception cref="ArgumentNullException">The options are null.</exception>
/// <exception cref="ArgumentNullException">The stream is null.</exception> /// <exception cref="ArgumentNullException">The stream is null.</exception>
/// <exception cref="NotSupportedException">The stream is not readable.</exception> /// <exception cref="NotSupportedException">The stream is not readable or the image format is not supported.</exception>
/// <returns>A <see cref="Task{Attempt}"/> representing the asynchronous operation.</returns> /// <exception cref="InvalidImageContentException">The encoded image contains invalid content.</exception>
public static async Task<Attempt<IImageFormat>> TryDetectFormatAsync( /// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
public static Task<IImageFormat> DetectFormatAsync(
DecoderOptions options, DecoderOptions options,
Stream stream, Stream stream,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ => WithSeekableStreamAsync(
IImageFormat? format = await WithSeekableStreamAsync(
options, options,
stream, stream,
(s, _) => Task.FromResult(InternalDetectFormat(options.Configuration, s)), (s, _) => Task.FromResult(InternalDetectFormat(options.Configuration, s)),
cancellationToken).ConfigureAwait(false); cancellationToken);
return new() { Value = format };
}
/// <summary> /// <summary>
/// Reads the raw image information from the specified stream without fully decoding it. /// Reads the raw image information from the specified stream without fully decoding it.

16
tests/ImageSharp.Tests/Formats/Bmp/ImageExtensionsTest.cs

@ -20,7 +20,7 @@ public class ImageExtensionsTest
image.SaveAsBmp(file); image.SaveAsBmp(file);
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is BmpFormat); Assert.True(format is BmpFormat);
} }
@ -35,7 +35,7 @@ public class ImageExtensionsTest
await image.SaveAsBmpAsync(file); await image.SaveAsBmpAsync(file);
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is BmpFormat); Assert.True(format is BmpFormat);
} }
@ -50,7 +50,7 @@ public class ImageExtensionsTest
image.SaveAsBmp(file, new BmpEncoder()); image.SaveAsBmp(file, new BmpEncoder());
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is BmpFormat); Assert.True(format is BmpFormat);
} }
@ -65,7 +65,7 @@ public class ImageExtensionsTest
await image.SaveAsBmpAsync(file, new BmpEncoder()); await image.SaveAsBmpAsync(file, new BmpEncoder());
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is BmpFormat); Assert.True(format is BmpFormat);
} }
@ -81,7 +81,7 @@ public class ImageExtensionsTest
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is BmpFormat); Assert.True(format is BmpFormat);
} }
@ -97,7 +97,7 @@ public class ImageExtensionsTest
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is BmpFormat); Assert.True(format is BmpFormat);
} }
@ -113,7 +113,7 @@ public class ImageExtensionsTest
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is BmpFormat); Assert.True(format is BmpFormat);
} }
@ -129,7 +129,7 @@ public class ImageExtensionsTest
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is BmpFormat); Assert.True(format is BmpFormat);
} }
} }

16
tests/ImageSharp.Tests/Formats/Gif/ImageExtensionsTest.cs

@ -20,7 +20,7 @@ public class ImageExtensionsTest
image.SaveAsGif(file); image.SaveAsGif(file);
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is GifFormat); Assert.True(format is GifFormat);
} }
@ -35,7 +35,7 @@ public class ImageExtensionsTest
await image.SaveAsGifAsync(file); await image.SaveAsGifAsync(file);
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is GifFormat); Assert.True(format is GifFormat);
} }
@ -50,7 +50,7 @@ public class ImageExtensionsTest
image.SaveAsGif(file, new GifEncoder()); image.SaveAsGif(file, new GifEncoder());
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is GifFormat); Assert.True(format is GifFormat);
} }
@ -65,7 +65,7 @@ public class ImageExtensionsTest
await image.SaveAsGifAsync(file, new GifEncoder()); await image.SaveAsGifAsync(file, new GifEncoder());
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is GifFormat); Assert.True(format is GifFormat);
} }
@ -81,7 +81,7 @@ public class ImageExtensionsTest
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is GifFormat); Assert.True(format is GifFormat);
} }
@ -97,7 +97,7 @@ public class ImageExtensionsTest
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is GifFormat); Assert.True(format is GifFormat);
} }
@ -113,7 +113,7 @@ public class ImageExtensionsTest
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is GifFormat); Assert.True(format is GifFormat);
} }
@ -129,7 +129,7 @@ public class ImageExtensionsTest
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is GifFormat); Assert.True(format is GifFormat);
} }
} }

13
tests/ImageSharp.Tests/Formats/ImageFormatManagerTests.cs

@ -120,15 +120,10 @@ public class ImageFormatManagerTests
jpegImage = buffer.ToArray(); jpegImage = buffer.ToArray();
} }
byte[] invalidImage = { 1, 2, 3 }; IImageFormat format = Image.DetectFormat(jpegImage);
Assert.IsType<JpegFormat>(format);
bool resultValidImage = Image.TryDetectFormat(jpegImage, out IImageFormat format);
bool resultInvalidImage = Image.TryDetectFormat(invalidImage, out IImageFormat formatInvalid); byte[] invalidImage = { 1, 2, 3 };
Assert.Throws<UnknownImageFormatException>(() => Image.DetectFormat(invalidImage));
Assert.True(resultValidImage);
Assert.Equal(format, JpegFormat.Instance);
Assert.False(resultInvalidImage);
Assert.True(formatInvalid is null);
} }
} }

16
tests/ImageSharp.Tests/Formats/Jpg/ImageExtensionsTest.cs

@ -21,7 +21,7 @@ public class ImageExtensionsTest
image.SaveAsJpeg(file); image.SaveAsJpeg(file);
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is JpegFormat); Assert.True(format is JpegFormat);
} }
@ -36,7 +36,7 @@ public class ImageExtensionsTest
await image.SaveAsJpegAsync(file); await image.SaveAsJpegAsync(file);
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is JpegFormat); Assert.True(format is JpegFormat);
} }
@ -51,7 +51,7 @@ public class ImageExtensionsTest
image.SaveAsJpeg(file, new JpegEncoder()); image.SaveAsJpeg(file, new JpegEncoder());
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is JpegFormat); Assert.True(format is JpegFormat);
} }
@ -66,7 +66,7 @@ public class ImageExtensionsTest
await image.SaveAsJpegAsync(file, new JpegEncoder()); await image.SaveAsJpegAsync(file, new JpegEncoder());
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is JpegFormat); Assert.True(format is JpegFormat);
} }
@ -82,7 +82,7 @@ public class ImageExtensionsTest
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is JpegFormat); Assert.True(format is JpegFormat);
} }
@ -98,7 +98,7 @@ public class ImageExtensionsTest
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is JpegFormat); Assert.True(format is JpegFormat);
} }
@ -114,7 +114,7 @@ public class ImageExtensionsTest
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is JpegFormat); Assert.True(format is JpegFormat);
} }
@ -130,7 +130,7 @@ public class ImageExtensionsTest
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is JpegFormat); Assert.True(format is JpegFormat);
} }
} }

16
tests/ImageSharp.Tests/Formats/Pbm/ImageExtensionsTest.cs

@ -20,7 +20,7 @@ public class ImageExtensionsTest
image.SaveAsPbm(file); image.SaveAsPbm(file);
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is PbmFormat); Assert.True(format is PbmFormat);
} }
@ -35,7 +35,7 @@ public class ImageExtensionsTest
await image.SaveAsPbmAsync(file); await image.SaveAsPbmAsync(file);
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is PbmFormat); Assert.True(format is PbmFormat);
} }
@ -50,7 +50,7 @@ public class ImageExtensionsTest
image.SaveAsPbm(file, new PbmEncoder()); image.SaveAsPbm(file, new PbmEncoder());
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is PbmFormat); Assert.True(format is PbmFormat);
} }
@ -65,7 +65,7 @@ public class ImageExtensionsTest
await image.SaveAsPbmAsync(file, new PbmEncoder()); await image.SaveAsPbmAsync(file, new PbmEncoder());
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is PbmFormat); Assert.True(format is PbmFormat);
} }
@ -81,7 +81,7 @@ public class ImageExtensionsTest
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is PbmFormat); Assert.True(format is PbmFormat);
} }
@ -97,7 +97,7 @@ public class ImageExtensionsTest
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is PbmFormat); Assert.True(format is PbmFormat);
} }
@ -113,7 +113,7 @@ public class ImageExtensionsTest
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is PbmFormat); Assert.True(format is PbmFormat);
} }
@ -129,7 +129,7 @@ public class ImageExtensionsTest
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is PbmFormat); Assert.True(format is PbmFormat);
} }
} }

16
tests/ImageSharp.Tests/Formats/Png/ImageExtensionsTest.cs

@ -21,7 +21,7 @@ public class ImageExtensionsTest
image.SaveAsPng(file); image.SaveAsPng(file);
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is PngFormat); Assert.True(format is PngFormat);
} }
@ -36,7 +36,7 @@ public class ImageExtensionsTest
await image.SaveAsPngAsync(file); await image.SaveAsPngAsync(file);
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is PngFormat); Assert.True(format is PngFormat);
} }
@ -51,7 +51,7 @@ public class ImageExtensionsTest
image.SaveAsPng(file, new PngEncoder()); image.SaveAsPng(file, new PngEncoder());
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is PngFormat); Assert.True(format is PngFormat);
} }
@ -66,7 +66,7 @@ public class ImageExtensionsTest
await image.SaveAsPngAsync(file, new PngEncoder()); await image.SaveAsPngAsync(file, new PngEncoder());
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is PngFormat); Assert.True(format is PngFormat);
} }
@ -82,7 +82,7 @@ public class ImageExtensionsTest
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is PngFormat); Assert.True(format is PngFormat);
} }
@ -98,7 +98,7 @@ public class ImageExtensionsTest
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is PngFormat); Assert.True(format is PngFormat);
} }
@ -114,7 +114,7 @@ public class ImageExtensionsTest
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is PngFormat); Assert.True(format is PngFormat);
} }
@ -130,7 +130,7 @@ public class ImageExtensionsTest
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is PngFormat); Assert.True(format is PngFormat);
} }
} }

16
tests/ImageSharp.Tests/Formats/Tga/ImageExtensionsTest.cs

@ -20,7 +20,7 @@ public class ImageExtensionsTest
image.SaveAsTga(file); image.SaveAsTga(file);
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is TgaFormat); Assert.True(format is TgaFormat);
} }
@ -35,7 +35,7 @@ public class ImageExtensionsTest
await image.SaveAsTgaAsync(file); await image.SaveAsTgaAsync(file);
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is TgaFormat); Assert.True(format is TgaFormat);
} }
@ -50,7 +50,7 @@ public class ImageExtensionsTest
image.SaveAsTga(file, new TgaEncoder()); image.SaveAsTga(file, new TgaEncoder());
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is TgaFormat); Assert.True(format is TgaFormat);
} }
@ -65,7 +65,7 @@ public class ImageExtensionsTest
await image.SaveAsTgaAsync(file, new TgaEncoder()); await image.SaveAsTgaAsync(file, new TgaEncoder());
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is TgaFormat); Assert.True(format is TgaFormat);
} }
@ -81,7 +81,7 @@ public class ImageExtensionsTest
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is TgaFormat); Assert.True(format is TgaFormat);
} }
@ -97,7 +97,7 @@ public class ImageExtensionsTest
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is TgaFormat); Assert.True(format is TgaFormat);
} }
@ -113,7 +113,7 @@ public class ImageExtensionsTest
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is TgaFormat); Assert.True(format is TgaFormat);
} }
@ -129,7 +129,7 @@ public class ImageExtensionsTest
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is TgaFormat); Assert.True(format is TgaFormat);
} }
} }

16
tests/ImageSharp.Tests/Formats/Tiff/ImageExtensionsTest.cs

@ -21,7 +21,7 @@ public class ImageExtensionsTest
image.SaveAsTiff(file); image.SaveAsTiff(file);
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is TiffFormat); Assert.True(format is TiffFormat);
} }
@ -36,7 +36,7 @@ public class ImageExtensionsTest
await image.SaveAsTiffAsync(file); await image.SaveAsTiffAsync(file);
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is TiffFormat); Assert.True(format is TiffFormat);
} }
@ -51,7 +51,7 @@ public class ImageExtensionsTest
image.SaveAsTiff(file, new TiffEncoder()); image.SaveAsTiff(file, new TiffEncoder());
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is TiffFormat); Assert.True(format is TiffFormat);
} }
@ -66,7 +66,7 @@ public class ImageExtensionsTest
await image.SaveAsTiffAsync(file, new TiffEncoder()); await image.SaveAsTiffAsync(file, new TiffEncoder());
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is TiffFormat); Assert.True(format is TiffFormat);
} }
@ -82,7 +82,7 @@ public class ImageExtensionsTest
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is TiffFormat); Assert.True(format is TiffFormat);
} }
@ -98,7 +98,7 @@ public class ImageExtensionsTest
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is TiffFormat); Assert.True(format is TiffFormat);
} }
@ -114,7 +114,7 @@ public class ImageExtensionsTest
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is TiffFormat); Assert.True(format is TiffFormat);
} }
@ -130,7 +130,7 @@ public class ImageExtensionsTest
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is TiffFormat); Assert.True(format is TiffFormat);
} }
} }

16
tests/ImageSharp.Tests/Formats/WebP/ImageExtensionsTests.cs

@ -21,7 +21,7 @@ public class ImageExtensionsTests
image.SaveAsWebp(file); image.SaveAsWebp(file);
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is WebpFormat); Assert.True(format is WebpFormat);
} }
@ -36,7 +36,7 @@ public class ImageExtensionsTests
await image.SaveAsWebpAsync(file); await image.SaveAsWebpAsync(file);
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is WebpFormat); Assert.True(format is WebpFormat);
} }
@ -51,7 +51,7 @@ public class ImageExtensionsTests
image.SaveAsWebp(file, new WebpEncoder()); image.SaveAsWebp(file, new WebpEncoder());
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is WebpFormat); Assert.True(format is WebpFormat);
} }
@ -66,7 +66,7 @@ public class ImageExtensionsTests
await image.SaveAsWebpAsync(file, new WebpEncoder()); await image.SaveAsWebpAsync(file, new WebpEncoder());
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is WebpFormat); Assert.True(format is WebpFormat);
} }
@ -82,7 +82,7 @@ public class ImageExtensionsTests
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is WebpFormat); Assert.True(format is WebpFormat);
} }
@ -98,7 +98,7 @@ public class ImageExtensionsTests
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is WebpFormat); Assert.True(format is WebpFormat);
} }
@ -114,7 +114,7 @@ public class ImageExtensionsTests
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is WebpFormat); Assert.True(format is WebpFormat);
} }
@ -130,7 +130,7 @@ public class ImageExtensionsTests
memoryStream.Position = 0; memoryStream.Position = 0;
Image.TryDetectFormat(memoryStream, out IImageFormat format); IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is WebpFormat); Assert.True(format is WebpFormat);
} }
} }

59
tests/ImageSharp.Tests/Image/ImageTests.DetectFormat.cs

@ -34,10 +34,8 @@ public partial class ImageTests
[Fact] [Fact]
public void FromBytes_GlobalConfiguration() public void FromBytes_GlobalConfiguration()
{ {
bool result = Image.TryDetectFormat(ActualImageSpan, out IImageFormat type); IImageFormat format = Image.DetectFormat(ActualImageSpan);
Assert.Equal(ExpectedGlobalFormat, format);
Assert.True(result);
Assert.Equal(ExpectedGlobalFormat, type);
} }
[Fact] [Fact]
@ -48,28 +46,22 @@ public partial class ImageTests
Configuration = this.LocalConfiguration Configuration = this.LocalConfiguration
}; };
bool result = Image.TryDetectFormat(options, this.ByteArray, out IImageFormat type); IImageFormat format = Image.DetectFormat(options, this.ByteArray);
Assert.Equal(this.LocalImageFormat, format);
Assert.True(result);
Assert.Equal(this.LocalImageFormat, type);
} }
[Fact] [Fact]
public void FromFileSystemPath_GlobalConfiguration() public void FromFileSystemPath_GlobalConfiguration()
{ {
bool result = Image.TryDetectFormat(ActualImagePath, out IImageFormat type); IImageFormat format = Image.DetectFormat(ActualImagePath);
Assert.Equal(ExpectedGlobalFormat, format);
Assert.True(result);
Assert.Equal(ExpectedGlobalFormat, type);
} }
[Fact] [Fact]
public async Task FromFileSystemPathAsync_GlobalConfiguration() public async Task FromFileSystemPathAsync_GlobalConfiguration()
{ {
Attempt<IImageFormat> attempt = await Image.TryDetectFormatAsync(ActualImagePath); IImageFormat format = await Image.DetectFormatAsync(ActualImagePath);
Assert.Equal(ExpectedGlobalFormat, format);
Assert.True(attempt.Success);
Assert.Equal(ExpectedGlobalFormat, attempt.Value);
} }
[Fact] [Fact]
@ -80,10 +72,8 @@ public partial class ImageTests
Configuration = this.LocalConfiguration Configuration = this.LocalConfiguration
}; };
bool result = Image.TryDetectFormat(options, this.MockFilePath, out IImageFormat type); IImageFormat format = Image.DetectFormat(options, this.MockFilePath);
Assert.Equal(this.LocalImageFormat, format);
Assert.True(result);
Assert.Equal(this.LocalImageFormat, type);
} }
[Fact] [Fact]
@ -94,20 +84,17 @@ public partial class ImageTests
Configuration = this.LocalConfiguration Configuration = this.LocalConfiguration
}; };
Attempt<IImageFormat> attempt = await Image.TryDetectFormatAsync(options, this.MockFilePath); IImageFormat format = await Image.DetectFormatAsync(options, this.MockFilePath);
Assert.Equal(this.LocalImageFormat, format);
Assert.True(attempt.Success);
Assert.Equal(this.LocalImageFormat, attempt.Value);
} }
[Fact] [Fact]
public void FromStream_GlobalConfiguration() public void FromStream_GlobalConfiguration()
{ {
using MemoryStream stream = new(ActualImageBytes); using MemoryStream stream = new(ActualImageBytes);
bool result = Image.TryDetectFormat(stream, out IImageFormat type); IImageFormat format = Image.DetectFormat(stream);
Assert.True(result); Assert.Equal(ExpectedGlobalFormat, format);
Assert.Equal(ExpectedGlobalFormat, type);
} }
[Fact] [Fact]
@ -118,10 +105,8 @@ public partial class ImageTests
Configuration = this.LocalConfiguration Configuration = this.LocalConfiguration
}; };
bool result = Image.TryDetectFormat(options, this.DataStream, out IImageFormat type); IImageFormat format = Image.DetectFormat(options, this.DataStream);
Assert.Equal(this.LocalImageFormat, format);
Assert.True(result);
Assert.Equal(this.LocalImageFormat, type);
} }
[Fact] [Fact]
@ -132,15 +117,15 @@ public partial class ImageTests
Configuration = new() Configuration = new()
}; };
Assert.Throws<UnknownImageFormatException>(() => Image.TryDetectFormat(options, this.DataStream, out IImageFormat type)); Assert.Throws<UnknownImageFormatException>(() => Image.DetectFormat(options, this.DataStream));
} }
[Fact] [Fact]
public async Task FromStreamAsync_GlobalConfiguration() public async Task FromStreamAsync_GlobalConfiguration()
{ {
using MemoryStream stream = new(ActualImageBytes); using MemoryStream stream = new(ActualImageBytes);
Attempt<IImageFormat> attempt = await Image.TryDetectFormatAsync(new AsyncStreamWrapper(stream, () => false)); IImageFormat format = await Image.DetectFormatAsync(new AsyncStreamWrapper(stream, () => false));
Assert.Equal(ExpectedGlobalFormat, attempt.Value); Assert.Equal(ExpectedGlobalFormat, format);
} }
[Fact] [Fact]
@ -151,8 +136,8 @@ public partial class ImageTests
Configuration = this.LocalConfiguration Configuration = this.LocalConfiguration
}; };
Attempt<IImageFormat> attempt = await Image.TryDetectFormatAsync(options, new AsyncStreamWrapper(this.DataStream, () => false)); IImageFormat format = await Image.DetectFormatAsync(options, new AsyncStreamWrapper(this.DataStream, () => false));
Assert.Equal(this.LocalImageFormat, attempt.Value); Assert.Equal(this.LocalImageFormat, format);
} }
[Fact] [Fact]
@ -163,7 +148,7 @@ public partial class ImageTests
Configuration = new() Configuration = new()
}; };
return Assert.ThrowsAsync<UnknownImageFormatException>(async () => await Image.TryDetectFormatAsync(options, new AsyncStreamWrapper(this.DataStream, () => false))); return Assert.ThrowsAsync<UnknownImageFormatException>(async () => await Image.DetectFormatAsync(options, new AsyncStreamWrapper(this.DataStream, () => false)));
} }
} }
} }

4
tests/ImageSharp.Tests/Image/ImageTests.Save.cs

@ -24,7 +24,7 @@ public partial class ImageTests
image.Save(file); image.Save(file);
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is PngFormat); Assert.True(format is PngFormat);
} }
@ -53,7 +53,7 @@ public partial class ImageTests
image.Save(file, new PngEncoder()); image.Save(file, new PngEncoder());
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is PngFormat); Assert.True(format is PngFormat);
} }

6
tests/ImageSharp.Tests/Image/ImageTests.SaveAsync.cs

@ -26,7 +26,7 @@ public partial class ImageTests
await image.SaveAsync(file); await image.SaveAsync(file);
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is PngFormat); Assert.True(format is PngFormat);
} }
@ -55,7 +55,7 @@ public partial class ImageTests
await image.SaveAsync(file, new PngEncoder()); await image.SaveAsync(file, new PngEncoder());
} }
Image.TryDetectFormat(file, out IImageFormat format); IImageFormat format = Image.DetectFormat(file);
Assert.True(format is PngFormat); Assert.True(format is PngFormat);
} }
@ -79,7 +79,7 @@ public partial class ImageTests
stream.Position = 0; stream.Position = 0;
Image.TryDetectFormat(stream, out IImageFormat format2); IImageFormat format2 = Image.DetectFormat(stream);
Assert.Equal(format, format2); Assert.Equal(format, format2);
} }

1
tests/ImageSharp.Tests/TestImages.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Six Labors Split License. // Licensed under the Six Labors Split License.
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
// ReSharper disable MemberHidesStaticFromOuterClass // ReSharper disable MemberHidesStaticFromOuterClass
namespace SixLabors.ImageSharp.Tests; namespace SixLabors.ImageSharp.Tests;

Loading…
Cancel
Save