diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoder.cs b/src/ImageSharp/Formats/Bmp/BmpDecoder.cs index 15c213f88..da6556b36 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoder.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoder.cs @@ -20,7 +20,7 @@ public sealed class BmpDecoder : SpecializedImageDecoder public static BmpDecoder Instance { get; } = new(); /// - protected override IImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) + protected override ImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) { Guard.NotNull(options, nameof(options)); Guard.NotNull(stream, nameof(stream)); diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs index 4bdb7257a..fd0497d9a 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs @@ -209,7 +209,7 @@ internal sealed class BmpDecoderCore : IImageDecoderInternals } /// - public IImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken) + public ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken) { this.ReadImageHeaders(stream, out _, out _); return new ImageInfo(new PixelTypeInfo(this.infoHeader.BitsPerPixel), this.infoHeader.Width, this.infoHeader.Height, this.metadata); diff --git a/src/ImageSharp/Formats/Gif/GifDecoder.cs b/src/ImageSharp/Formats/Gif/GifDecoder.cs index e08fc6230..6dbb07a13 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoder.cs +++ b/src/ImageSharp/Formats/Gif/GifDecoder.cs @@ -20,7 +20,7 @@ public sealed class GifDecoder : ImageDecoder public static GifDecoder Instance { get; } = new(); /// - protected override IImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) + protected override ImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) { Guard.NotNull(options, nameof(options)); Guard.NotNull(stream, nameof(stream)); diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs index d67372419..8c5915800 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs @@ -175,7 +175,7 @@ internal sealed class GifDecoderCore : IImageDecoderInternals } /// - public IImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken) + public ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken) { try { diff --git a/src/ImageSharp/Formats/IImageDecoder.cs b/src/ImageSharp/Formats/IImageDecoder.cs index 3729c98d9..eca2939bc 100644 --- a/src/ImageSharp/Formats/IImageDecoder.cs +++ b/src/ImageSharp/Formats/IImageDecoder.cs @@ -15,9 +15,9 @@ public interface IImageDecoder /// /// The general decoder options. /// The containing image data. - /// The object. + /// The object. /// Thrown if the encoded image contains errors. - public IImageInfo Identify(DecoderOptions options, Stream stream); + public ImageInfo Identify(DecoderOptions options, Stream stream); /// /// Reads the raw image information from the specified stream. @@ -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 = default); + public Task IdentifyAsync(DecoderOptions options, 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/IImageDecoderInternals.cs b/src/ImageSharp/Formats/IImageDecoderInternals.cs index d8cb1c662..06fb59764 100644 --- a/src/ImageSharp/Formats/IImageDecoderInternals.cs +++ b/src/ImageSharp/Formats/IImageDecoderInternals.cs @@ -41,10 +41,10 @@ internal interface IImageDecoderInternals /// /// The containing image data. /// The token to monitor for cancellation requests. - /// The . + /// The . /// /// Cancellable synchronous method. In case of cancellation, /// an shall be thrown which will be handled on the call site. /// - IImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken); + ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken); } diff --git a/src/ImageSharp/Formats/ImageDecoder.cs b/src/ImageSharp/Formats/ImageDecoder.cs index 591f85df2..bc2620c7f 100644 --- a/src/ImageSharp/Formats/ImageDecoder.cs +++ b/src/ImageSharp/Formats/ImageDecoder.cs @@ -17,44 +17,74 @@ public abstract class ImageDecoder : IImageDecoder /// public Image Decode(DecoderOptions options, Stream stream) where TPixel : unmanaged, IPixel - => WithSeekableStream( - options, - stream, - s => this.Decode(options, s, default)); + { + Image image = WithSeekableStream( + options, + stream, + s => this.Decode(options, s, default)); + + this.SetDecoderFormat(options.Configuration, image); + + return image; + } /// public Image Decode(DecoderOptions options, Stream stream) - => WithSeekableStream( - options, - stream, - s => this.Decode(options, s, default)); + { + Image image = WithSeekableStream( + options, + stream, + s => this.Decode(options, s, default)); + + this.SetDecoderFormat(options.Configuration, image); + + return image; + } /// - public Task> DecodeAsync(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default) + public async Task> DecodeAsync(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default) where TPixel : unmanaged, IPixel - => WithSeekableMemoryStreamAsync( - options, - stream, - (s, ct) => this.Decode(options, s, ct), - cancellationToken); + { + Image image = await WithSeekableMemoryStreamAsync( + options, + stream, + (s, ct) => this.Decode(options, s, ct), + cancellationToken).ConfigureAwait(false); + + this.SetDecoderFormat(options.Configuration, image); + + return image; + } /// - public Task DecodeAsync(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default) - => WithSeekableMemoryStreamAsync( + public async Task DecodeAsync(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default) + { + Image image = await WithSeekableMemoryStreamAsync( options, stream, (s, ct) => this.Decode(options, s, ct), - cancellationToken); + cancellationToken).ConfigureAwait(false); + + this.SetDecoderFormat(options.Configuration, image); + + return image; + } /// - public IImageInfo Identify(DecoderOptions options, Stream stream) - => WithSeekableStream( - options, - stream, - s => this.Identify(options, s, default)); + public ImageInfo Identify(DecoderOptions options, Stream stream) + { + ImageInfo info = WithSeekableStream( + options, + stream, + s => this.Identify(options, s, default)); + + this.SetDecoderFormat(options.Configuration, info); + + return info; + } /// - public Task IdentifyAsync(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default) + public Task IdentifyAsync(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default) => WithSeekableMemoryStreamAsync( options, stream, @@ -98,9 +128,9 @@ public abstract class ImageDecoder : IImageDecoder /// The general decoder options. /// The containing image data. /// The token to monitor for cancellation requests. - /// The object. + /// The object. /// Thrown if the encoded image contains errors. - protected abstract IImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken); + protected abstract ImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken); /// /// Performs a scaling operation against the decoded image. If the target size is not set, or the image size @@ -252,4 +282,10 @@ public abstract class ImageDecoder : IImageDecoder memoryStream.Position = 0; return await action(memoryStream, position, cancellationToken).ConfigureAwait(false); } + + internal void SetDecoderFormat(Configuration configuration, Image image) + => image.Metadata.DecodedImageFormat = configuration.ImageFormatsManager.FindFormatByDecoder(this); + + internal void SetDecoderFormat(Configuration configuration, ImageInfo info) + => info.Metadata.DecodedImageFormat = configuration.ImageFormatsManager.FindFormatByDecoder(this); } diff --git a/src/ImageSharp/Formats/ImageDecoderUtilities.cs b/src/ImageSharp/Formats/ImageDecoderUtilities.cs index 2a5b91b09..e2c61c8eb 100644 --- a/src/ImageSharp/Formats/ImageDecoderUtilities.cs +++ b/src/ImageSharp/Formats/ImageDecoderUtilities.cs @@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.Formats; /// internal static class ImageDecoderUtilities { - internal static IImageInfo Identify( + internal static ImageInfo Identify( this IImageDecoderInternals decoder, Configuration configuration, Stream stream, diff --git a/src/ImageSharp/Formats/ImageFormatManager.cs b/src/ImageSharp/Formats/ImageFormatManager.cs index d058e80c9..8da897a01 100644 --- a/src/ImageSharp/Formats/ImageFormatManager.cs +++ b/src/ImageSharp/Formats/ImageFormatManager.cs @@ -117,6 +117,9 @@ public class ImageFormatManager public IImageFormat? FindFormatByMimeType(string mimeType) => this.imageFormats.FirstOrDefault(x => x.MimeTypes.Contains(mimeType, StringComparer.OrdinalIgnoreCase)); + internal IImageFormat? FindFormatByDecoder(IImageDecoder decoder) + => this.mimeTypeDecoders.FirstOrDefault(x => x.Value == decoder).Key; + /// /// Sets a specific image encoder as the encoder for a specific image format. /// diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs index b8a142d28..026c542dd 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs @@ -20,7 +20,7 @@ public sealed class JpegDecoder : SpecializedImageDecoder public static JpegDecoder Instance { get; } = new(); /// - protected override IImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) + protected override ImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) { Guard.NotNull(options, nameof(options)); Guard.NotNull(stream, nameof(stream)); diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs index f21ccdb62..511ec1ba1 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs @@ -225,7 +225,7 @@ internal sealed class JpegDecoderCore : IRawJpegData, IImageDecoderInternals } /// - public IImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken) + public ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken) { this.ParseStream(stream, spectralConverter: null, cancellationToken); this.InitExifProfile(); diff --git a/src/ImageSharp/Formats/Pbm/PbmDecoder.cs b/src/ImageSharp/Formats/Pbm/PbmDecoder.cs index f7b32b5fc..a7dd8a0eb 100644 --- a/src/ImageSharp/Formats/Pbm/PbmDecoder.cs +++ b/src/ImageSharp/Formats/Pbm/PbmDecoder.cs @@ -36,7 +36,7 @@ public sealed class PbmDecoder : ImageDecoder public static PbmDecoder Instance { get; } = new(); /// - protected override IImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) + protected override ImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) { Guard.NotNull(options, nameof(options)); Guard.NotNull(stream, nameof(stream)); diff --git a/src/ImageSharp/Formats/Pbm/PbmDecoderCore.cs b/src/ImageSharp/Formats/Pbm/PbmDecoderCore.cs index 139cb2fcc..c5e0b0071 100644 --- a/src/ImageSharp/Formats/Pbm/PbmDecoderCore.cs +++ b/src/ImageSharp/Formats/Pbm/PbmDecoderCore.cs @@ -83,7 +83,7 @@ internal sealed class PbmDecoderCore : IImageDecoderInternals } /// - public IImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken) + public ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken) { this.ProcessHeader(stream); diff --git a/src/ImageSharp/Formats/PixelTypeInfo.cs b/src/ImageSharp/Formats/PixelTypeInfo.cs index 79ea884ce..1328c6528 100644 --- a/src/ImageSharp/Formats/PixelTypeInfo.cs +++ b/src/ImageSharp/Formats/PixelTypeInfo.cs @@ -4,6 +4,9 @@ using System.Runtime.CompilerServices; using SixLabors.ImageSharp.PixelFormats; +// TODO: Review this class as it's used to represent 2 different things. +// 1.The encoded image pixel format. +// 2. The pixel format of the decoded image. namespace SixLabors.ImageSharp.Formats; /// @@ -16,9 +19,7 @@ public class PixelTypeInfo /// /// Color depth, in number of bits per pixel. public PixelTypeInfo(int bitsPerPixel) - { - this.BitsPerPixel = bitsPerPixel; - } + => this.BitsPerPixel = bitsPerPixel; /// /// Initializes a new instance of the class. @@ -43,12 +44,10 @@ public class PixelTypeInfo public PixelAlphaRepresentation? AlphaRepresentation { get; } internal static PixelTypeInfo Create() - where TPixel : unmanaged, IPixel => - new PixelTypeInfo(Unsafe.SizeOf() * 8); + where TPixel : unmanaged, IPixel + => new(Unsafe.SizeOf() * 8); internal static PixelTypeInfo Create(PixelAlphaRepresentation alpha) where TPixel : unmanaged, IPixel - { - return new PixelTypeInfo(Unsafe.SizeOf() * 8, alpha); - } + => new(Unsafe.SizeOf() * 8, alpha); } diff --git a/src/ImageSharp/Formats/Png/PngDecoder.cs b/src/ImageSharp/Formats/Png/PngDecoder.cs index 56e76da10..f273ac2b9 100644 --- a/src/ImageSharp/Formats/Png/PngDecoder.cs +++ b/src/ImageSharp/Formats/Png/PngDecoder.cs @@ -20,7 +20,7 @@ public sealed class PngDecoder : ImageDecoder public static PngDecoder Instance { get; } = new(); /// - protected override IImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) + protected override ImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) { Guard.NotNull(options, nameof(options)); Guard.NotNull(stream, nameof(stream)); @@ -49,7 +49,7 @@ public sealed class PngDecoder : ImageDecoder Guard.NotNull(stream, nameof(stream)); PngDecoderCore decoder = new(options, true); - IImageInfo info = decoder.Identify(options.Configuration, stream, cancellationToken); + ImageInfo info = decoder.Identify(options.Configuration, stream, cancellationToken); stream.Position = 0; PngMetadata meta = info.Metadata.GetPngMetadata(); diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index 37cc8b2f6..3b2f100e0 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -247,7 +247,7 @@ internal sealed class PngDecoderCore : IImageDecoderInternals } /// - public IImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken) + public ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken) { ImageMetadata metadata = new(); PngMetadata pngMetadata = metadata.GetPngMetadata(); diff --git a/src/ImageSharp/Formats/SpecializedImageDecoder{T}.cs b/src/ImageSharp/Formats/SpecializedImageDecoder{T}.cs index fa6461464..59fa59bb9 100644 --- a/src/ImageSharp/Formats/SpecializedImageDecoder{T}.cs +++ b/src/ImageSharp/Formats/SpecializedImageDecoder{T}.cs @@ -17,34 +17,54 @@ public abstract class SpecializedImageDecoder : ImageDecoder, ISpecializedIma /// public Image Decode(T options, Stream stream) where TPixel : unmanaged, IPixel - => WithSeekableStream( + { + Image image = WithSeekableStream( options.GeneralOptions, stream, s => this.Decode(options, s, default)); + this.SetDecoderFormat(options.GeneralOptions.Configuration, image); + return image; + } + /// public Image Decode(T options, Stream stream) - => WithSeekableStream( + { + Image image = WithSeekableStream( options.GeneralOptions, stream, s => this.Decode(options, s, default)); + this.SetDecoderFormat(options.GeneralOptions.Configuration, image); + return image; + } + /// - public Task> DecodeAsync(T options, Stream stream, CancellationToken cancellationToken = default) + public async Task> DecodeAsync(T options, Stream stream, CancellationToken cancellationToken = default) where TPixel : unmanaged, IPixel - => WithSeekableMemoryStreamAsync( + { + Image image = await WithSeekableMemoryStreamAsync( options.GeneralOptions, stream, (s, ct) => this.Decode(options, s, ct), - cancellationToken); + cancellationToken).ConfigureAwait(false); + + this.SetDecoderFormat(options.GeneralOptions.Configuration, image); + return image; + } /// - public Task DecodeAsync(T options, Stream stream, CancellationToken cancellationToken = default) - => WithSeekableMemoryStreamAsync( + public async Task DecodeAsync(T options, Stream stream, CancellationToken cancellationToken = default) + { + Image image = await WithSeekableMemoryStreamAsync( options.GeneralOptions, stream, (s, ct) => this.Decode(options, s, ct), - cancellationToken); + cancellationToken).ConfigureAwait(false); + + this.SetDecoderFormat(options.GeneralOptions.Configuration, image); + return image; + } /// /// Decodes the image from the specified stream to an of a specific pixel type. diff --git a/src/ImageSharp/Formats/Tga/TgaDecoder.cs b/src/ImageSharp/Formats/Tga/TgaDecoder.cs index f6f1e6762..e7ff894da 100644 --- a/src/ImageSharp/Formats/Tga/TgaDecoder.cs +++ b/src/ImageSharp/Formats/Tga/TgaDecoder.cs @@ -20,7 +20,7 @@ public sealed class TgaDecoder : ImageDecoder public static TgaDecoder Instance { get; } = new(); /// - protected override IImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) + protected override ImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) { Guard.NotNull(options, nameof(options)); Guard.NotNull(stream, nameof(stream)); diff --git a/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs b/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs index ebb47b775..9c32471fd 100644 --- a/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs +++ b/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs @@ -647,7 +647,7 @@ internal sealed class TgaDecoderCore : IImageDecoderInternals } /// - public IImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken) + public ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken) { this.ReadFileHeader(stream); return new ImageInfo( diff --git a/src/ImageSharp/Formats/Tiff/TiffDecoder.cs b/src/ImageSharp/Formats/Tiff/TiffDecoder.cs index 3ec9b3d68..e9dee4ee4 100644 --- a/src/ImageSharp/Formats/Tiff/TiffDecoder.cs +++ b/src/ImageSharp/Formats/Tiff/TiffDecoder.cs @@ -20,7 +20,7 @@ public class TiffDecoder : ImageDecoder public static TiffDecoder Instance { get; } = new(); /// - protected override IImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) + protected override ImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) { Guard.NotNull(options, nameof(options)); Guard.NotNull(stream, nameof(stream)); diff --git a/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs b/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs index 887d4eda4..e74c53e22 100644 --- a/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs +++ b/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs @@ -213,7 +213,7 @@ internal class TiffDecoderCore : IImageDecoderInternals } /// - public IImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken) + public ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken) { this.inputStream = stream; DirectoryReader reader = new(stream, this.configuration.MemoryAllocator); diff --git a/src/ImageSharp/Formats/Webp/WebpDecoder.cs b/src/ImageSharp/Formats/Webp/WebpDecoder.cs index 7a97b86a7..daa5eaf4f 100644 --- a/src/ImageSharp/Formats/Webp/WebpDecoder.cs +++ b/src/ImageSharp/Formats/Webp/WebpDecoder.cs @@ -20,7 +20,7 @@ public sealed class WebpDecoder : ImageDecoder public static WebpDecoder Instance { get; } = new(); /// - protected override IImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) + protected override ImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) { Guard.NotNull(options, nameof(options)); Guard.NotNull(stream, nameof(stream)); diff --git a/src/ImageSharp/Formats/Webp/WebpDecoderCore.cs b/src/ImageSharp/Formats/Webp/WebpDecoderCore.cs index d313ebf76..29be86e22 100644 --- a/src/ImageSharp/Formats/Webp/WebpDecoderCore.cs +++ b/src/ImageSharp/Formats/Webp/WebpDecoderCore.cs @@ -145,7 +145,7 @@ internal sealed class WebpDecoderCore : IImageDecoderInternals, IDisposable } /// - public IImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken) + public ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken) { this.currentStream = stream; diff --git a/src/ImageSharp/IImageInfo.cs b/src/ImageSharp/IImageInfo.cs index 32ca9a9a2..411b8f1b0 100644 --- a/src/ImageSharp/IImageInfo.cs +++ b/src/ImageSharp/IImageInfo.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Six Labors Split License. using SixLabors.ImageSharp.Formats; diff --git a/src/ImageSharp/Image.Decode.cs b/src/ImageSharp/Image.Decode.cs index a556cbceb..d549fabee 100644 --- a/src/ImageSharp/Image.Decode.cs +++ b/src/ImageSharp/Image.Decode.cs @@ -179,12 +179,12 @@ public abstract partial class Image /// The general decoder options. /// The stream. /// - /// The or null if a suitable info detector is not found. + /// The or null if a suitable info detector is not found. /// - private static (IImageInfo ImageInfo, IImageFormat Format) InternalIdentify(DecoderOptions options, Stream stream) + private static (ImageInfo ImageInfo, IImageFormat Format) InternalIdentify(DecoderOptions options, Stream stream) { IImageDecoder decoder = DiscoverDecoder(options, stream, out IImageFormat format); - IImageInfo info = decoder?.Identify(options, stream); + ImageInfo info = decoder?.Identify(options, stream); return (info, format); } @@ -195,9 +195,9 @@ public abstract partial class Image /// The stream. /// The token to monitor for cancellation requests. /// - /// The or null if a suitable info detector is not found. + /// The or null if a suitable info detector is not found. /// - private static async Task<(IImageInfo ImageInfo, IImageFormat Format)> InternalIdentifyAsync( + private static async Task<(ImageInfo ImageInfo, IImageFormat Format)> InternalIdentifyAsync( DecoderOptions options, Stream stream, CancellationToken cancellationToken) @@ -209,7 +209,7 @@ public abstract partial class Image return (null, null); } - IImageInfo info = await decoder.IdentifyAsync(options, stream, cancellationToken).ConfigureAwait(false); + ImageInfo info = await decoder.IdentifyAsync(options, stream, cancellationToken).ConfigureAwait(false); return (info, format); } } diff --git a/src/ImageSharp/Image.FromBytes.cs b/src/ImageSharp/Image.FromBytes.cs index 7a2e9d736..a6c73c61e 100644 --- a/src/ImageSharp/Image.FromBytes.cs +++ b/src/ImageSharp/Image.FromBytes.cs @@ -60,9 +60,9 @@ public abstract partial class Image /// The data is null. /// The data is not readable. /// - /// The or null if suitable info detector not found. + /// The or null if suitable info detector not found. /// - public static IImageInfo Identify(ReadOnlySpan data) => Identify(data, out IImageFormat _); + public static ImageInfo Identify(ReadOnlySpan data) => Identify(data, out IImageFormat _); /// /// Reads the raw image information from the specified stream without fully decoding it. @@ -72,9 +72,9 @@ public abstract partial class Image /// The data is null. /// The data is not readable. /// - /// The or null if suitable info detector not found. + /// The or null if suitable info detector not found. /// - public static IImageInfo Identify(ReadOnlySpan data, out IImageFormat format) + public static ImageInfo Identify(ReadOnlySpan data, out IImageFormat format) => Identify(DecoderOptions.Default, data, out format); /// @@ -87,9 +87,9 @@ public abstract partial class Image /// The data is null. /// The data is not readable. /// - /// The or null if suitable info detector is not found. + /// The or null if suitable info detector is not found. /// - public static unsafe IImageInfo Identify(DecoderOptions options, ReadOnlySpan data, out IImageFormat format) + public static unsafe ImageInfo Identify(DecoderOptions options, ReadOnlySpan data, out IImageFormat format) { fixed (byte* ptr = data) { diff --git a/src/ImageSharp/Image.FromFile.cs b/src/ImageSharp/Image.FromFile.cs index cd27e2882..1f17b698d 100644 --- a/src/ImageSharp/Image.FromFile.cs +++ b/src/ImageSharp/Image.FromFile.cs @@ -42,9 +42,9 @@ public abstract partial class Image /// /// The image file to open and to read the header from. /// - /// The or null if suitable info detector not found. + /// The or null if suitable info detector not found. /// - public static IImageInfo Identify(string filePath) + public static ImageInfo Identify(string filePath) => Identify(filePath, out IImageFormat _); /// @@ -53,9 +53,9 @@ public abstract partial class Image /// The image file to open and to read the header from. /// The format type of the decoded image. /// - /// The or null if suitable info detector not found. + /// The or null if suitable info detector not found. /// - public static IImageInfo Identify(string filePath, out IImageFormat format) + public static ImageInfo Identify(string filePath, out IImageFormat format) => Identify(DecoderOptions.Default, filePath, out format); /// @@ -66,9 +66,9 @@ public abstract partial class Image /// The format type of the decoded image. /// The configuration is null. /// - /// The or null if suitable info detector is not found. + /// The or null if suitable info detector is not found. /// - public static IImageInfo Identify(DecoderOptions options, string filePath, out IImageFormat format) + public static ImageInfo Identify(DecoderOptions options, string filePath, out IImageFormat format) { Guard.NotNull(options, nameof(options)); using Stream file = options.Configuration.FileSystem.OpenRead(filePath); @@ -83,9 +83,9 @@ public abstract partial class Image /// The configuration is null. /// /// The representing the asynchronous operation with the parameter type - /// property set to null if suitable info detector is not found. + /// property set to null if suitable info detector is not found. /// - public static Task IdentifyAsync(string filePath, CancellationToken cancellationToken = default) + public static Task IdentifyAsync(string filePath, CancellationToken cancellationToken = default) => IdentifyAsync(DecoderOptions.Default, filePath, cancellationToken); /// @@ -97,14 +97,14 @@ public abstract partial class Image /// The configuration is null. /// /// The representing the asynchronous operation with the parameter type - /// property set to null if suitable info detector is not found. + /// property set to null if suitable info detector is not found. /// - public static async Task IdentifyAsync( + public static async Task IdentifyAsync( DecoderOptions options, string filePath, CancellationToken cancellationToken = default) { - (IImageInfo ImageInfo, IImageFormat Format) res = + (ImageInfo ImageInfo, IImageFormat Format) res = await IdentifyWithFormatAsync(options, filePath, cancellationToken).ConfigureAwait(false); return res.ImageInfo; } @@ -117,9 +117,9 @@ public abstract partial class Image /// The configuration is null. /// /// The representing the asynchronous operation with the parameter type - /// property set to null if suitable info detector is not found. + /// property set to null if suitable info detector is not found. /// - public static Task<(IImageInfo ImageInfo, IImageFormat Format)> IdentifyWithFormatAsync( + public static Task<(ImageInfo ImageInfo, IImageFormat Format)> IdentifyWithFormatAsync( string filePath, CancellationToken cancellationToken = default) => IdentifyWithFormatAsync(DecoderOptions.Default, filePath, cancellationToken); @@ -133,9 +133,9 @@ public abstract partial class Image /// The configuration is null. /// /// The representing the asynchronous operation with the parameter type - /// property set to null if suitable info detector is not found. + /// property set to null if suitable info detector is not found. /// - public static async Task<(IImageInfo ImageInfo, IImageFormat Format)> IdentifyWithFormatAsync( + public static async Task<(ImageInfo ImageInfo, IImageFormat Format)> IdentifyWithFormatAsync( DecoderOptions options, string filePath, CancellationToken cancellationToken = default) diff --git a/src/ImageSharp/Image.FromStream.cs b/src/ImageSharp/Image.FromStream.cs index 63b9b5c1b..fc6e14b2e 100644 --- a/src/ImageSharp/Image.FromStream.cs +++ b/src/ImageSharp/Image.FromStream.cs @@ -78,9 +78,9 @@ public abstract partial class Image /// The stream is not readable. /// Image contains invalid content. /// - /// The or null if a suitable info detector is not found. + /// The or null if a suitable info detector is not found. /// - public static IImageInfo Identify(Stream stream) + public static ImageInfo Identify(Stream stream) => Identify(stream, out IImageFormat _); /// @@ -95,7 +95,7 @@ public abstract partial class Image /// A representing the asynchronous operation or null if /// a suitable detector is not found. /// - public static Task IdentifyAsync(Stream stream, CancellationToken cancellationToken = default) + public static Task IdentifyAsync(Stream stream, CancellationToken cancellationToken = default) => IdentifyAsync(DecoderOptions.Default, stream, cancellationToken); /// @@ -107,9 +107,9 @@ public abstract partial class Image /// The stream is not readable. /// Image contains invalid content. /// - /// The or null if a suitable info detector is not found. + /// The or null if a suitable info detector is not found. /// - public static IImageInfo Identify(Stream stream, out IImageFormat format) + public static ImageInfo Identify(Stream stream, out IImageFormat format) => Identify(DecoderOptions.Default, stream, out format); /// @@ -122,9 +122,9 @@ public abstract partial class Image /// The stream is not readable. /// Image contains invalid content. /// - /// The or null if a suitable info detector is not found. + /// The or null if a suitable info detector is not found. /// - public static IImageInfo Identify(DecoderOptions options, Stream stream) + public static ImageInfo Identify(DecoderOptions options, Stream stream) => Identify(options, stream, out _); /// @@ -141,12 +141,12 @@ public abstract partial class Image /// A representing the asynchronous operation or null if /// a suitable detector is not found. /// - public static async Task IdentifyAsync( + public static async Task IdentifyAsync( DecoderOptions options, Stream stream, CancellationToken cancellationToken = default) { - (IImageInfo ImageInfo, IImageFormat Format) res = await IdentifyWithFormatAsync(options, stream, cancellationToken).ConfigureAwait(false); + (ImageInfo ImageInfo, IImageFormat Format) res = await IdentifyWithFormatAsync(options, stream, cancellationToken).ConfigureAwait(false); return res.ImageInfo; } @@ -161,11 +161,11 @@ public abstract partial class Image /// The stream is not readable. /// Image contains invalid content. /// - /// The or null if a suitable info detector is not found. + /// The or null if a suitable info detector is not found. /// - public static IImageInfo Identify(DecoderOptions options, Stream stream, out IImageFormat format) + public static ImageInfo Identify(DecoderOptions options, Stream stream, out IImageFormat format) { - (IImageInfo ImageInfo, IImageFormat Format) data = WithSeekableStream(options, stream, s => InternalIdentify(options, s)); + (ImageInfo ImageInfo, IImageFormat Format) data = WithSeekableStream(options, stream, s => InternalIdentify(options, s)); format = data.Format; return data.ImageInfo; @@ -182,9 +182,9 @@ public abstract partial class Image /// Image contains invalid content. /// /// The representing the asynchronous operation with the parameter type - /// property set to null if suitable info detector is not found. + /// property set to null if suitable info detector is not found. /// - public static Task<(IImageInfo ImageInfo, IImageFormat Format)> IdentifyWithFormatAsync( + public static Task<(ImageInfo ImageInfo, IImageFormat Format)> IdentifyWithFormatAsync( Stream stream, CancellationToken cancellationToken = default) => IdentifyWithFormatAsync(DecoderOptions.Default, stream, cancellationToken); @@ -201,9 +201,9 @@ public abstract partial class Image /// Image contains invalid content. /// /// The representing the asynchronous operation with the parameter type - /// property set to null if suitable info detector is not found. + /// property set to null if suitable info detector is not found. /// - public static Task<(IImageInfo ImageInfo, IImageFormat Format)> IdentifyWithFormatAsync( + public static Task<(ImageInfo ImageInfo, IImageFormat Format)> IdentifyWithFormatAsync( DecoderOptions options, Stream stream, CancellationToken cancellationToken = default) diff --git a/src/ImageSharp/ImageInfo.cs b/src/ImageSharp/ImageInfo.cs index 5142a91a6..5b10440be 100644 --- a/src/ImageSharp/ImageInfo.cs +++ b/src/ImageSharp/ImageInfo.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Six Labors Split License. using SixLabors.ImageSharp.Formats; @@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp; /// /// Contains information about the image including dimensions, pixel type information and additional metadata /// -internal sealed class ImageInfo : IImageInfo +public sealed class ImageInfo : IImageInfo { /// /// Initializes a new instance of the class. diff --git a/src/ImageSharp/ImageInfoExtensions.cs b/src/ImageSharp/ImageInfoExtensions.cs index 9dfc89289..0f47c8896 100644 --- a/src/ImageSharp/ImageInfoExtensions.cs +++ b/src/ImageSharp/ImageInfoExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Six Labors Split License. namespace SixLabors.ImageSharp; @@ -13,12 +13,12 @@ public static class ImageInfoExtensions /// /// The image info /// The - public static Size Size(this IImageInfo info) => new Size(info.Width, info.Height); + public static Size Size(this IImageInfo info) => new(info.Width, info.Height); /// /// Gets the bounds of the image. /// /// The image info /// The - public static Rectangle Bounds(this IImageInfo info) => new Rectangle(0, 0, info.Width, info.Height); + public static Rectangle Bounds(this IImageInfo info) => new(0, 0, info.Width, info.Height); } diff --git a/src/ImageSharp/Metadata/ImageMetadata.cs b/src/ImageSharp/Metadata/ImageMetadata.cs index 785f38941..f54fc5c7a 100644 --- a/src/ImageSharp/Metadata/ImageMetadata.cs +++ b/src/ImageSharp/Metadata/ImageMetadata.cs @@ -1,6 +1,5 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -#nullable disable using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Metadata.Profiles.Exif; @@ -69,6 +68,10 @@ public sealed class ImageMetadata : IDeepCloneable this.IccProfile = other.IccProfile?.DeepClone(); this.IptcProfile = other.IptcProfile?.DeepClone(); this.XmpProfile = other.XmpProfile?.DeepClone(); + + // NOTE: This clone is actually shallow but we share the same format + // instances for all images in the configuration. + this.DecodedImageFormat = other.DecodedImageFormat; } /// @@ -137,22 +140,27 @@ public sealed class ImageMetadata : IDeepCloneable /// /// Gets or sets the Exif profile. /// - public ExifProfile ExifProfile { get; set; } + public ExifProfile? ExifProfile { get; set; } /// /// Gets or sets the XMP profile. /// - public XmpProfile XmpProfile { get; set; } + public XmpProfile? XmpProfile { get; set; } /// /// Gets or sets the ICC profile. /// - public IccProfile IccProfile { get; set; } + public IccProfile? IccProfile { get; set; } /// /// Gets or sets the IPTC profile. /// - public IptcProfile IptcProfile { get; set; } + public IptcProfile? IptcProfile { get; set; } + + /// + /// Gets the original format, if any, the image was decode from. + /// + public IImageFormat? DecodedImageFormat { get; internal set; } /// /// Gets the metadata value associated with the specified key. @@ -165,7 +173,7 @@ public sealed class ImageMetadata : IDeepCloneable public TFormatMetadata GetFormatMetadata(IImageFormat key) where TFormatMetadata : class, IDeepCloneable { - if (this.formatMetadata.TryGetValue(key, out IDeepCloneable meta)) + if (this.formatMetadata.TryGetValue(key, out IDeepCloneable? meta)) { return (TFormatMetadata)meta; } diff --git a/src/ImageSharp/Processing/Processors/Transforms/Linear/RotateProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/Linear/RotateProcessor{TPixel}.cs index ac50337f6..3ffb1ab51 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Linear/RotateProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Linear/RotateProcessor{TPixel}.cs @@ -43,7 +43,7 @@ internal class RotateProcessor : AffineTransformProcessor /// protected override void AfterImageApply(Image destination) { - ExifProfile profile = destination.Metadata.ExifProfile; + ExifProfile? profile = destination.Metadata.ExifProfile; if (profile is null) { return; diff --git a/src/ImageSharp/Processing/Processors/Transforms/TransformProcessorHelpers.cs b/src/ImageSharp/Processing/Processors/Transforms/TransformProcessorHelpers.cs index 8e7452679..172d7d677 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/TransformProcessorHelpers.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/TransformProcessorHelpers.cs @@ -19,7 +19,7 @@ internal static class TransformProcessorHelpers public static void UpdateDimensionalMetadata(Image image) where TPixel : unmanaged, IPixel { - ExifProfile profile = image.Metadata.ExifProfile; + ExifProfile? profile = image.Metadata.ExifProfile; if (profile is null) { return; diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/IdentifyJpeg.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/IdentifyJpeg.cs index aed3e4c03..d5ad59b00 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/IdentifyJpeg.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/IdentifyJpeg.cs @@ -22,7 +22,7 @@ public class IdentifyJpeg public void ReadImages() => this.jpegBytes ??= File.ReadAllBytes(this.TestImageFullPath); [Benchmark] - public IImageInfo Identify() + public ImageInfo Identify() { using MemoryStream memoryStream = new(this.jpegBytes); return JpegDecoder.Instance.Identify(DecoderOptions.Default, memoryStream); diff --git a/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs index e6eb389be..bfe490efa 100644 --- a/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs @@ -475,7 +475,7 @@ public class BmpDecoderTests { var testFile = TestFile.Create(imagePath); using var stream = new MemoryStream(testFile.Bytes, false); - IImageInfo imageInfo = Image.Identify(stream); + ImageInfo imageInfo = Image.Identify(stream); Assert.NotNull(imageInfo); Assert.Equal(expectedPixelSize, imageInfo.PixelType?.BitsPerPixel); } @@ -493,7 +493,7 @@ public class BmpDecoderTests { var testFile = TestFile.Create(imagePath); using var stream = new MemoryStream(testFile.Bytes, false); - IImageInfo imageInfo = Image.Identify(stream); + ImageInfo imageInfo = Image.Identify(stream); Assert.NotNull(imageInfo); Assert.Equal(expectedWidth, imageInfo.Width); Assert.Equal(expectedHeight, imageInfo.Height); diff --git a/tests/ImageSharp.Tests/Formats/Bmp/BmpMetadataTests.cs b/tests/ImageSharp.Tests/Formats/Bmp/BmpMetadataTests.cs index f4ce54670..712c7d8bf 100644 --- a/tests/ImageSharp.Tests/Formats/Bmp/BmpMetadataTests.cs +++ b/tests/ImageSharp.Tests/Formats/Bmp/BmpMetadataTests.cs @@ -38,7 +38,7 @@ public class BmpMetadataTests var testFile = TestFile.Create(imagePath); using (var stream = new MemoryStream(testFile.Bytes, false)) { - IImageInfo imageInfo = Image.Identify(stream); + ImageInfo imageInfo = Image.Identify(stream); Assert.NotNull(imageInfo); BmpMetadata bitmapMetadata = imageInfo.Metadata.GetBmpMetadata(); Assert.NotNull(bitmapMetadata); diff --git a/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs b/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs index c9e50337e..95040e5d6 100644 --- a/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs +++ b/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs @@ -257,7 +257,7 @@ public class GeneralFormatTests image.Save(memoryStream, format); memoryStream.Position = 0; - IImageInfo imageInfo = Image.Identify(memoryStream); + ImageInfo imageInfo = Image.Identify(memoryStream); Assert.Equal(imageInfo.Width, width); Assert.Equal(imageInfo.Height, height); @@ -274,7 +274,7 @@ public class GeneralFormatTests byte[] invalid = new byte[10]; using MemoryStream memoryStream = new(invalid); - IImageInfo imageInfo = Image.Identify(memoryStream, out IImageFormat format); + ImageInfo imageInfo = Image.Identify(memoryStream, out IImageFormat format); Assert.Null(imageInfo); Assert.Null(format); diff --git a/tests/ImageSharp.Tests/Formats/Gif/GifMetadataTests.cs b/tests/ImageSharp.Tests/Formats/Gif/GifMetadataTests.cs index 24eaa9607..7def2003a 100644 --- a/tests/ImageSharp.Tests/Formats/Gif/GifMetadataTests.cs +++ b/tests/ImageSharp.Tests/Formats/Gif/GifMetadataTests.cs @@ -113,7 +113,7 @@ public class GifMetadataTests { var testFile = TestFile.Create(imagePath); using var stream = new MemoryStream(testFile.Bytes, false); - IImageInfo image = GifDecoder.Instance.Identify(DecoderOptions.Default, stream); + ImageInfo image = GifDecoder.Instance.Identify(DecoderOptions.Default, stream); ImageMetadata meta = image.Metadata; Assert.Equal(xResolution, meta.HorizontalResolution); Assert.Equal(yResolution, meta.VerticalResolution); @@ -126,7 +126,7 @@ public class GifMetadataTests { var testFile = TestFile.Create(imagePath); using var stream = new MemoryStream(testFile.Bytes, false); - IImageInfo image = await GifDecoder.Instance.IdentifyAsync(DecoderOptions.Default, stream); + ImageInfo image = await GifDecoder.Instance.IdentifyAsync(DecoderOptions.Default, stream); ImageMetadata meta = image.Metadata; Assert.Equal(xResolution, meta.HorizontalResolution); Assert.Equal(yResolution, meta.VerticalResolution); @@ -165,7 +165,7 @@ public class GifMetadataTests { var testFile = TestFile.Create(imagePath); using var stream = new MemoryStream(testFile.Bytes, false); - IImageInfo image = GifDecoder.Instance.Identify(DecoderOptions.Default, stream); + ImageInfo image = GifDecoder.Instance.Identify(DecoderOptions.Default, stream); GifMetadata meta = image.Metadata.GetGifMetadata(); Assert.Equal(repeatCount, meta.RepeatCount); } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Metadata.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Metadata.cs index d972f539e..80417653d 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Metadata.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Metadata.cs @@ -90,7 +90,7 @@ public partial class JpegDecoderTests { var testFile = TestFile.Create(imagePath); using var stream = new MemoryStream(testFile.Bytes, false); - IImageInfo image = JpegDecoder.Instance.Identify(DecoderOptions.Default, stream); + ImageInfo image = JpegDecoder.Instance.Identify(DecoderOptions.Default, stream); ImageMetadata meta = image.Metadata; Assert.Equal(xResolution, meta.HorizontalResolution); Assert.Equal(yResolution, meta.VerticalResolution); @@ -103,7 +103,7 @@ public partial class JpegDecoderTests { var testFile = TestFile.Create(imagePath); using var stream = new MemoryStream(testFile.Bytes, false); - IImageInfo image = await JpegDecoder.Instance.IdentifyAsync(DecoderOptions.Default, stream); + ImageInfo image = await JpegDecoder.Instance.IdentifyAsync(DecoderOptions.Default, stream); ImageMetadata meta = image.Metadata; Assert.Equal(xResolution, meta.HorizontalResolution); Assert.Equal(yResolution, meta.VerticalResolution); @@ -116,7 +116,7 @@ public partial class JpegDecoderTests { var testFile = TestFile.Create(imagePath); using var stream = new MemoryStream(testFile.Bytes, false); - IImageInfo image = JpegDecoder.Instance.Identify(DecoderOptions.Default, stream); + ImageInfo image = JpegDecoder.Instance.Identify(DecoderOptions.Default, stream); JpegMetadata meta = image.Metadata.GetJpegMetadata(); Assert.Equal(quality, meta.Quality); } @@ -155,7 +155,7 @@ public partial class JpegDecoderTests { var testFile = TestFile.Create(imagePath); using var stream = new MemoryStream(testFile.Bytes, false); - IImageInfo image = JpegDecoder.Instance.Identify(DecoderOptions.Default, stream); + ImageInfo image = JpegDecoder.Instance.Identify(DecoderOptions.Default, stream); JpegMetadata meta = image.Metadata.GetJpegMetadata(); Assert.Equal(expectedColorType, meta.ColorType); } @@ -180,7 +180,7 @@ public partial class JpegDecoderTests using var stream = new MemoryStream(testFile.Bytes, false); if (useIdentify) { - IImageInfo imageInfo = decoder.Identify(DecoderOptions.Default, stream); + ImageInfo imageInfo = decoder.Identify(DecoderOptions.Default, stream); test(imageInfo); } else diff --git a/tests/ImageSharp.Tests/Formats/Pbm/PbmMetadataTests.cs b/tests/ImageSharp.Tests/Formats/Pbm/PbmMetadataTests.cs index 7c57ee2fb..826d16e74 100644 --- a/tests/ImageSharp.Tests/Formats/Pbm/PbmMetadataTests.cs +++ b/tests/ImageSharp.Tests/Formats/Pbm/PbmMetadataTests.cs @@ -35,7 +35,7 @@ public class PbmMetadataTests { var testFile = TestFile.Create(imagePath); using var stream = new MemoryStream(testFile.Bytes, false); - IImageInfo imageInfo = Image.Identify(stream); + ImageInfo imageInfo = Image.Identify(stream); Assert.NotNull(imageInfo); PbmMetadata bitmapMetadata = imageInfo.Metadata.GetPbmMetadata(); Assert.NotNull(bitmapMetadata); @@ -54,7 +54,7 @@ public class PbmMetadataTests { var testFile = TestFile.Create(imagePath); using var stream = new MemoryStream(testFile.Bytes, false); - IImageInfo imageInfo = Image.Identify(stream); + ImageInfo imageInfo = Image.Identify(stream); Assert.NotNull(imageInfo); PbmMetadata bitmapMetadata = imageInfo.Metadata.GetPbmMetadata(); Assert.NotNull(bitmapMetadata); @@ -73,7 +73,7 @@ public class PbmMetadataTests { var testFile = TestFile.Create(imagePath); using var stream = new MemoryStream(testFile.Bytes, false); - IImageInfo imageInfo = Image.Identify(stream); + ImageInfo imageInfo = Image.Identify(stream); Assert.NotNull(imageInfo); PbmMetadata bitmapMetadata = imageInfo.Metadata.GetPbmMetadata(); Assert.NotNull(bitmapMetadata); diff --git a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs index 2e1785cbb..ea958df37 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs @@ -504,7 +504,7 @@ public partial class PngDecoderTests { var testFile = TestFile.Create(imagePath); using var stream = new MemoryStream(testFile.Bytes, false); - IImageInfo imageInfo = Image.Identify(stream); + ImageInfo imageInfo = Image.Identify(stream); PngMetadata metadata = imageInfo.Metadata.GetPngMetadata(); Assert.True(metadata.HasTransparency); } diff --git a/tests/ImageSharp.Tests/Formats/Png/PngMetadataTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngMetadataTests.cs index d283efc00..03de88a24 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngMetadataTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngMetadataTests.cs @@ -219,7 +219,7 @@ public class PngMetadataTests { var testFile = TestFile.Create(imagePath); using var stream = new MemoryStream(testFile.Bytes, false); - IImageInfo image = PngDecoder.Instance.Identify(DecoderOptions.Default, stream); + ImageInfo image = PngDecoder.Instance.Identify(DecoderOptions.Default, stream); ImageMetadata meta = image.Metadata; Assert.Equal(xResolution, meta.HorizontalResolution); Assert.Equal(yResolution, meta.VerticalResolution); @@ -232,7 +232,7 @@ public class PngMetadataTests { var testFile = TestFile.Create(imagePath); using var stream = new MemoryStream(testFile.Bytes, false); - IImageInfo imageInfo = Image.Identify(stream); + ImageInfo imageInfo = Image.Identify(stream); Assert.NotNull(imageInfo); PngMetadata meta = imageInfo.Metadata.GetFormatMetadata(PngFormat.Instance); VerifyTextDataIsPresent(meta); @@ -244,7 +244,7 @@ public class PngMetadataTests { var testFile = TestFile.Create(imagePath); using var stream = new MemoryStream(testFile.Bytes, false); - IImageInfo imageInfo = Image.Identify(stream); + ImageInfo imageInfo = Image.Identify(stream); Assert.NotNull(imageInfo); Assert.NotNull(imageInfo.Metadata.ExifProfile); ExifProfile exif = imageInfo.Metadata.ExifProfile; @@ -281,7 +281,7 @@ public class PngMetadataTests { var testFile = TestFile.Create(imagePath); using var stream = new MemoryStream(testFile.Bytes, false); - IImageInfo imageInfo = Image.Identify(stream); + ImageInfo imageInfo = Image.Identify(stream); Assert.NotNull(imageInfo); Assert.NotNull(imageInfo.Metadata.ExifProfile); diff --git a/tests/ImageSharp.Tests/Formats/Tga/TgaFileHeaderTests.cs b/tests/ImageSharp.Tests/Formats/Tga/TgaFileHeaderTests.cs index a5997cb01..d34c051f8 100644 --- a/tests/ImageSharp.Tests/Formats/Tga/TgaFileHeaderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Tga/TgaFileHeaderTests.cs @@ -41,7 +41,7 @@ public class TgaFileHeaderTests { using var stream = new MemoryStream(data); - IImageInfo info = Image.Identify(stream); + ImageInfo info = Image.Identify(stream); TgaMetadata tgaData = info.Metadata.GetTgaMetadata(); Assert.Equal(bitsPerPixel, tgaData.BitsPerPixel); Assert.Equal(width, info.Width); diff --git a/tests/ImageSharp.Tests/Formats/Tiff/BigTiffDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/BigTiffDecoderTests.cs index 29017a674..bc8fe35a4 100644 --- a/tests/ImageSharp.Tests/Formats/Tiff/BigTiffDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Tiff/BigTiffDecoderTests.cs @@ -63,7 +63,7 @@ public class BigTiffDecoderTests : TiffDecoderBaseTester var testFile = TestFile.Create(imagePath); using (var stream = new MemoryStream(testFile.Bytes, false)) { - IImageInfo info = Image.Identify(stream); + ImageInfo info = Image.Identify(stream); Assert.Equal(expectedPixelSize, info.PixelType?.BitsPerPixel); Assert.Equal(expectedWidth, info.Width); @@ -87,7 +87,7 @@ public class BigTiffDecoderTests : TiffDecoderBaseTester var testFile = TestFile.Create(imagePath); using (var stream = new MemoryStream(testFile.Bytes, false)) { - IImageInfo info = Image.Identify(stream); + ImageInfo info = Image.Identify(stream); Assert.NotNull(info.Metadata); Assert.Equal(expectedByteOrder, info.Metadata.GetTiffMetadata().ByteOrder); diff --git a/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs index ced8ed6dd..60bc44ded 100644 --- a/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs @@ -33,7 +33,7 @@ public class TiffDecoderTests : TiffDecoderBaseTester var testFile = TestFile.Create(imagePath); using (var stream = new MemoryStream(testFile.Bytes, false)) { - IImageInfo info = Image.Identify(stream); + ImageInfo info = Image.Identify(stream); Assert.Equal(expectedPixelSize, info.PixelType?.BitsPerPixel); Assert.Equal(expectedWidth, info.Width); @@ -53,7 +53,7 @@ public class TiffDecoderTests : TiffDecoderBaseTester TestFile testFile = TestFile.Create(imagePath); using (var stream = new MemoryStream(testFile.Bytes, false)) { - IImageInfo info = Image.Identify(stream); + ImageInfo info = Image.Identify(stream); Assert.NotNull(info.Metadata); Assert.Equal(expectedByteOrder, info.Metadata.GetTiffMetadata().ByteOrder); diff --git a/tests/ImageSharp.Tests/Formats/Tiff/TiffMetadataTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/TiffMetadataTests.cs index f882bf415..6cf1bbc36 100644 --- a/tests/ImageSharp.Tests/Formats/Tiff/TiffMetadataTests.cs +++ b/tests/ImageSharp.Tests/Formats/Tiff/TiffMetadataTests.cs @@ -80,7 +80,7 @@ public class TiffMetadataTests var testFile = TestFile.Create(imagePath); using var stream = new MemoryStream(testFile.Bytes, false); - IImageInfo imageInfo = Image.Identify(stream); + ImageInfo imageInfo = Image.Identify(stream); Assert.NotNull(imageInfo); TiffMetadata tiffMetadata = imageInfo.Metadata.GetTiffMetadata(); @@ -96,7 +96,7 @@ public class TiffMetadataTests var testFile = TestFile.Create(imagePath); using var stream = new MemoryStream(testFile.Bytes, false); - IImageInfo imageInfo = Image.Identify(stream); + ImageInfo imageInfo = Image.Identify(stream); Assert.NotNull(imageInfo); TiffMetadata tiffMetadata = imageInfo.Metadata.GetTiffMetadata(); diff --git a/tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs b/tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs index 694b8c23e..150c67d4f 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs @@ -41,7 +41,7 @@ public class WebpDecoderTests { var testFile = TestFile.Create(imagePath); using var stream = new MemoryStream(testFile.Bytes, false); - IImageInfo imageInfo = Image.Identify(stream); + ImageInfo imageInfo = Image.Identify(stream); Assert.NotNull(imageInfo); Assert.Equal(expectedWidth, imageInfo.Width); Assert.Equal(expectedHeight, imageInfo.Height); diff --git a/tests/ImageSharp.Tests/Image/ImageTests.Identify.cs b/tests/ImageSharp.Tests/Image/ImageTests.Identify.cs index 49c956253..1ff4d796a 100644 --- a/tests/ImageSharp.Tests/Image/ImageTests.Identify.cs +++ b/tests/ImageSharp.Tests/Image/ImageTests.Identify.cs @@ -21,7 +21,7 @@ public partial class ImageTests private static byte[] ActualImageBytes => TestFile.Create(TestImages.Bmp.F).Bytes; - private IImageInfo LocalImageInfo => this.localImageInfoMock.Object; + private ImageInfo LocalImageInfo => this.localImageInfoMock.Object; private IImageFormat LocalImageFormat => this.localImageFormatMock.Object; @@ -38,7 +38,7 @@ public partial class ImageTests [Fact] public void FromBytes_GlobalConfiguration() { - IImageInfo info = Image.Identify(ActualImageBytes, out IImageFormat type); + ImageInfo info = Image.Identify(ActualImageBytes, out IImageFormat type); Assert.Equal(ExpectedImageSize, info.Size()); Assert.Equal(ExpectedGlobalFormat, type); @@ -49,7 +49,7 @@ public partial class ImageTests { DecoderOptions options = new() { Configuration = this.LocalConfiguration }; - IImageInfo info = Image.Identify(options, this.ByteArray, out IImageFormat type); + ImageInfo info = Image.Identify(options, this.ByteArray, out IImageFormat type); Assert.Equal(this.LocalImageInfo, info); Assert.Equal(this.LocalImageFormat, type); @@ -58,7 +58,7 @@ public partial class ImageTests [Fact] public void FromFileSystemPath_GlobalConfiguration() { - IImageInfo info = Image.Identify(ActualImagePath, out IImageFormat type); + ImageInfo info = Image.Identify(ActualImagePath, out IImageFormat type); Assert.NotNull(info); Assert.Equal(ExpectedGlobalFormat, type); @@ -69,7 +69,7 @@ public partial class ImageTests { DecoderOptions options = new() { Configuration = this.LocalConfiguration }; - IImageInfo info = Image.Identify(options, this.MockFilePath, out IImageFormat type); + ImageInfo info = Image.Identify(options, this.MockFilePath, out IImageFormat type); Assert.Equal(this.LocalImageInfo, info); Assert.Equal(this.LocalImageFormat, type); @@ -79,7 +79,7 @@ public partial class ImageTests public void FromStream_GlobalConfiguration() { using var stream = new MemoryStream(ActualImageBytes); - IImageInfo info = Image.Identify(stream, out IImageFormat type); + ImageInfo info = Image.Identify(stream, out IImageFormat type); Assert.NotNull(info); Assert.Equal(ExpectedGlobalFormat, type); @@ -89,7 +89,7 @@ public partial class ImageTests public void FromStream_GlobalConfiguration_NoFormat() { using var stream = new MemoryStream(ActualImageBytes); - IImageInfo info = Image.Identify(stream); + ImageInfo info = Image.Identify(stream); Assert.NotNull(info); } @@ -100,7 +100,7 @@ public partial class ImageTests using var stream = new MemoryStream(ActualImageBytes); using var nonSeekableStream = new NonSeekableStream(stream); - IImageInfo info = Image.Identify(nonSeekableStream, out IImageFormat type); + ImageInfo info = Image.Identify(nonSeekableStream, out IImageFormat type); Assert.NotNull(info); Assert.Equal(ExpectedGlobalFormat, type); @@ -112,7 +112,7 @@ public partial class ImageTests using var stream = new MemoryStream(ActualImageBytes); using var nonSeekableStream = new NonSeekableStream(stream); - IImageInfo info = Image.Identify(nonSeekableStream); + ImageInfo info = Image.Identify(nonSeekableStream); Assert.NotNull(info); } @@ -122,7 +122,7 @@ public partial class ImageTests { DecoderOptions options = new() { Configuration = this.LocalConfiguration }; - IImageInfo info = Image.Identify(options, this.DataStream, out IImageFormat type); + ImageInfo info = Image.Identify(options, this.DataStream, out IImageFormat type); Assert.Equal(this.LocalImageInfo, info); Assert.Equal(this.LocalImageFormat, type); @@ -133,7 +133,7 @@ public partial class ImageTests { DecoderOptions options = new() { Configuration = this.LocalConfiguration }; - IImageInfo info = Image.Identify(options, this.DataStream); + ImageInfo info = Image.Identify(options, this.DataStream); Assert.Equal(this.LocalImageInfo, info); } @@ -143,7 +143,7 @@ public partial class ImageTests { DecoderOptions options = new() { Configuration = new() }; - IImageInfo info = Image.Identify(options, this.DataStream, out IImageFormat type); + ImageInfo info = Image.Identify(options, this.DataStream, out IImageFormat type); Assert.Null(info); Assert.Null(type); @@ -168,7 +168,7 @@ public partial class ImageTests 0x00, 0x00, 0x00, 0x00 })); using Stream stream = zipFile.Entries[0].Open(); - IImageInfo info = Image.Identify(stream); + ImageInfo info = Image.Identify(stream); Assert.Null(info); } @@ -177,7 +177,7 @@ public partial class ImageTests { using var stream = new MemoryStream(ActualImageBytes); var asyncStream = new AsyncStreamWrapper(stream, () => false); - IImageInfo info = await Image.IdentifyAsync(asyncStream); + ImageInfo info = await Image.IdentifyAsync(asyncStream); Assert.NotNull(info); } @@ -187,7 +187,7 @@ public partial class ImageTests { using var stream = new MemoryStream(ActualImageBytes); var asyncStream = new AsyncStreamWrapper(stream, () => false); - (IImageInfo ImageInfo, IImageFormat Format) res = await Image.IdentifyWithFormatAsync(asyncStream); + (ImageInfo ImageInfo, IImageFormat Format) res = await Image.IdentifyWithFormatAsync(asyncStream); Assert.Equal(ExpectedImageSize, res.ImageInfo.Size()); Assert.Equal(ExpectedGlobalFormat, res.Format); @@ -200,7 +200,7 @@ public partial class ImageTests using var nonSeekableStream = new NonSeekableStream(stream); var asyncStream = new AsyncStreamWrapper(nonSeekableStream, () => false); - IImageInfo info = await Image.IdentifyAsync(asyncStream); + ImageInfo info = await Image.IdentifyAsync(asyncStream); Assert.NotNull(info); } @@ -212,7 +212,7 @@ public partial class ImageTests using var nonSeekableStream = new NonSeekableStream(stream); var asyncStream = new AsyncStreamWrapper(nonSeekableStream, () => false); - (IImageInfo ImageInfo, IImageFormat Format) res = await Image.IdentifyWithFormatAsync(asyncStream); + (ImageInfo ImageInfo, IImageFormat Format) res = await Image.IdentifyWithFormatAsync(asyncStream); Assert.Equal(ExpectedImageSize, res.ImageInfo.Size()); Assert.Equal(ExpectedGlobalFormat, res.Format); @@ -237,7 +237,7 @@ public partial class ImageTests 0x00, 0x00, 0x00, 0x00 })); using Stream stream = zipFile.Entries[0].Open(); - IImageInfo info = await Image.IdentifyAsync(stream); + ImageInfo info = await Image.IdentifyAsync(stream); Assert.Null(info); } @@ -246,7 +246,7 @@ public partial class ImageTests { DecoderOptions options = new() { Configuration = this.LocalConfiguration }; - IImageInfo info = await Image.IdentifyAsync(options, this.MockFilePath); + ImageInfo info = await Image.IdentifyAsync(options, this.MockFilePath); Assert.Equal(this.LocalImageInfo, info); } @@ -255,7 +255,7 @@ public partial class ImageTests { DecoderOptions options = new() { Configuration = this.LocalConfiguration }; - (IImageInfo ImageInfo, IImageFormat Format) info = + (ImageInfo ImageInfo, IImageFormat Format) info = await Image.IdentifyWithFormatAsync(options, this.MockFilePath); Assert.NotNull(info.ImageInfo); Assert.Equal(this.LocalImageFormat, info.Format); @@ -264,7 +264,7 @@ public partial class ImageTests [Fact] public async Task IdentifyWithFormatAsync_FromPath_GlobalConfiguration() { - (IImageInfo ImageInfo, IImageFormat Format) res = await Image.IdentifyWithFormatAsync(ActualImagePath); + (ImageInfo ImageInfo, IImageFormat Format) res = await Image.IdentifyWithFormatAsync(ActualImagePath); Assert.Equal(ExpectedImageSize, res.ImageInfo.Size()); Assert.Equal(ExpectedGlobalFormat, res.Format); @@ -273,7 +273,7 @@ public partial class ImageTests [Fact] public async Task FromPathAsync_GlobalConfiguration() { - IImageInfo info = await Image.IdentifyAsync(ActualImagePath); + ImageInfo info = await Image.IdentifyAsync(ActualImagePath); Assert.Equal(ExpectedImageSize, info.Size()); } @@ -284,7 +284,7 @@ public partial class ImageTests DecoderOptions options = new() { Configuration = this.LocalConfiguration }; var asyncStream = new AsyncStreamWrapper(this.DataStream, () => false); - (IImageInfo ImageInfo, IImageFormat Format) + (ImageInfo ImageInfo, IImageFormat Format) info = await Image.IdentifyWithFormatAsync(options, asyncStream); Assert.Equal(this.LocalImageInfo, info.ImageInfo); @@ -297,7 +297,7 @@ public partial class ImageTests DecoderOptions options = new() { Configuration = new() }; var asyncStream = new AsyncStreamWrapper(this.DataStream, () => false); - (IImageInfo ImageInfo, IImageFormat Format) + (ImageInfo ImageInfo, IImageFormat Format) info = await Image.IdentifyWithFormatAsync(options, asyncStream); Assert.Null(info.ImageInfo); diff --git a/tests/ImageSharp.Tests/Image/ImageTests.ImageLoadTestBase.cs b/tests/ImageSharp.Tests/Image/ImageTests.ImageLoadTestBase.cs index 15e57b48a..bbc57b1e3 100644 --- a/tests/ImageSharp.Tests/Image/ImageTests.ImageLoadTestBase.cs +++ b/tests/ImageSharp.Tests/Image/ImageTests.ImageLoadTestBase.cs @@ -25,7 +25,7 @@ public partial class ImageTests protected Mock localImageFormatMock; - protected Mock localImageInfoMock; + protected Mock localImageInfoMock; protected readonly string MockFilePath = Guid.NewGuid().ToString(); @@ -56,7 +56,7 @@ public partial class ImageTests this.localStreamReturnImageRgba32 = new Image(1, 1); this.localStreamReturnImageAgnostic = new Image(1, 1); - this.localImageInfoMock = new Mock(); + this.localImageInfoMock = new Mock(); this.localImageFormatMock = new Mock(); this.localDecoder = new Mock(); diff --git a/tests/ImageSharp.Tests/TestFormat.cs b/tests/ImageSharp.Tests/TestFormat.cs index bfad23194..92dd79132 100644 --- a/tests/ImageSharp.Tests/TestFormat.cs +++ b/tests/ImageSharp.Tests/TestFormat.cs @@ -199,8 +199,12 @@ public class TestFormat : IImageFormatConfigurationModule, IImageFormat public bool IsSupportedFileFormat(Span header) => this.testFormat.IsSupportedFileFormat(header); - protected override IImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) - => this.Decode(this.CreateDefaultSpecializedOptions(options), stream, cancellationToken); + protected override ImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) + { + Image image = + this.Decode(this.CreateDefaultSpecializedOptions(options), stream, cancellationToken); + return new(image.PixelType, image.Width, image.Height, image.Metadata); + } protected override TestDecoderOptions CreateDefaultSpecializedOptions(DecoderOptions options) => new() { GeneralOptions = options }; @@ -208,7 +212,7 @@ public class TestFormat : IImageFormatConfigurationModule, IImageFormat protected override Image Decode(TestDecoderOptions options, Stream stream, CancellationToken cancellationToken) { Configuration configuration = options.GeneralOptions.Configuration; - var ms = new MemoryStream(); + using MemoryStream ms = new(); stream.CopyTo(ms, configuration.StreamProcessingBufferSize); byte[] marker = ms.ToArray().Skip(this.testFormat.header.Length).ToArray(); this.testFormat.DecodeCalls.Add(new DecodeOperation diff --git a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/MagickReferenceDecoder.cs b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/MagickReferenceDecoder.cs index 7203116c9..4bedf2ed9 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/MagickReferenceDecoder.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/MagickReferenceDecoder.cs @@ -72,8 +72,11 @@ public class MagickReferenceDecoder : ImageDecoder protected override Image Decode(DecoderOptions options, Stream stream, CancellationToken cancellationToken) => this.Decode(options, stream, cancellationToken); - protected override IImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) - => this.Decode(options, stream, cancellationToken); + protected override ImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) + { + Image image = this.Decode(options, stream, cancellationToken); + return new(image.PixelType, image.Width, image.Height, image.Metadata); + } private static void FromRgba32Bytes(Configuration configuration, Span rgbaBytes, IMemoryGroup destinationGroup) where TPixel : unmanaged, ImageSharp.PixelFormats.IPixel diff --git a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceDecoder.cs b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceDecoder.cs index 503fd53ce..2deed6d48 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceDecoder.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceDecoder.cs @@ -13,7 +13,7 @@ public class SystemDrawingReferenceDecoder : ImageDecoder { public static SystemDrawingReferenceDecoder Instance { get; } = new SystemDrawingReferenceDecoder(); - protected override IImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) + protected override ImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) { using SDBitmap sourceBitmap = new(stream); PixelTypeInfo pixelType = new(SDImage.GetPixelFormatSize(sourceBitmap.PixelFormat)); diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs index 13edd2a06..3214bebc8 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs @@ -363,8 +363,11 @@ public class TestImageProviderTests } } - protected override IImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) - => this.Decode(this.CreateDefaultSpecializedOptions(options), stream, cancellationToken); + protected override ImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) + { + Image image = this.Decode(this.CreateDefaultSpecializedOptions(options), stream, cancellationToken); + return new(image.PixelType, image.Width, image.Height, image.Metadata); + } protected override Image Decode(TestDecoderOptions options, Stream stream, CancellationToken cancellationToken) { @@ -403,8 +406,11 @@ public class TestImageProviderTests } } - protected override IImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) - => this.Decode(this.CreateDefaultSpecializedOptions(options), stream, cancellationToken); + protected override ImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) + { + Image image = this.Decode(this.CreateDefaultSpecializedOptions(options), stream, cancellationToken); + return new(image.PixelType, image.Width, image.Height, image.Metadata); + } protected override Image Decode(TestDecoderWithParametersOptions options, Stream stream, CancellationToken cancellationToken) {