diff --git a/src/ImageSharp/Formats/Icon/IconDecoderCore.cs b/src/ImageSharp/Formats/Icon/IconDecoderCore.cs index ce72f15612..caed2dd902 100644 --- a/src/ImageSharp/Formats/Icon/IconDecoderCore.cs +++ b/src/ImageSharp/Formats/Icon/IconDecoderCore.cs @@ -6,24 +6,21 @@ using SixLabors.ImageSharp.Formats.Bmp; using SixLabors.ImageSharp.Formats.Png; using SixLabors.ImageSharp.IO; using SixLabors.ImageSharp.Metadata; -using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Formats.Icon; -internal abstract class IconDecoderCore : IImageDecoderInternals +internal abstract class IconDecoderCore : ImageDecoderCore { private IconDir fileHeader; private IconDirEntry[]? entries; protected IconDecoderCore(DecoderOptions options) - => this.Options = options; - - public DecoderOptions Options { get; } - - public Size Dimensions { get; private set; } + : base(options) + { + } - public Image Decode(BufferedReadStream stream, CancellationToken cancellationToken) - where TPixel : unmanaged, IPixel + /// + protected override Image Decode(BufferedReadStream stream, CancellationToken cancellationToken) { // Stream may not at 0. long basePosition = stream.Position; @@ -61,7 +58,7 @@ internal abstract class IconDecoderCore : IImageDecoderInternals bool isPng = flag.SequenceEqual(PngConstants.HeaderBytes); // Decode the frame into a temp image buffer. This is disposed after the frame is copied to the result. - Image temp = this.GetDecoder(isPng).Decode(stream, cancellationToken); + Image temp = this.GetDecoder(isPng).Decode(this.Options.Configuration, stream, cancellationToken); decodedEntries.Add((temp, isPng ? IconFrameCompression.Png : IconFrameCompression.Bmp, i)); // Since Windows Vista, the size of an image is determined from the BITMAPINFOHEADER structure or PNG image data @@ -133,7 +130,8 @@ internal abstract class IconDecoderCore : IImageDecoderInternals return result; } - public ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken) + /// + protected override ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken) { // Stream may not at 0. long basePosition = stream.Position; @@ -170,7 +168,7 @@ internal abstract class IconDecoderCore : IImageDecoderInternals bool isPng = flag.SequenceEqual(PngConstants.HeaderBytes); // Decode the frame into a temp image buffer. This is disposed after the frame is copied to the result. - ImageInfo frameInfo = this.GetDecoder(isPng).Identify(stream, cancellationToken); + ImageInfo frameInfo = this.GetDecoder(isPng).Identify(this.Options.Configuration, stream, cancellationToken); ImageFrameMetadata frameMetadata = new(); @@ -281,7 +279,7 @@ internal abstract class IconDecoderCore : IImageDecoderInternals this.Dimensions = new(width, height); } - private IImageDecoderInternals GetDecoder(bool isPng) + private ImageDecoderCore GetDecoder(bool isPng) { if (isPng) { diff --git a/src/ImageSharp/Formats/Icon/IconEncoderCore.cs b/src/ImageSharp/Formats/Icon/IconEncoderCore.cs index 509c9f420c..4b973d5115 100644 --- a/src/ImageSharp/Formats/Icon/IconEncoderCore.cs +++ b/src/ImageSharp/Formats/Icon/IconEncoderCore.cs @@ -11,7 +11,7 @@ using SixLabors.ImageSharp.Processing.Processors.Quantization; namespace SixLabors.ImageSharp.Formats.Icon; -internal abstract class IconEncoderCore : IImageEncoderInternals +internal abstract class IconEncoderCore { private readonly QuantizingImageEncoder encoder; private readonly IconFileType iconFileType; @@ -43,6 +43,8 @@ internal abstract class IconEncoderCore : IImageEncoderInternals for (int i = 0; i < image.Frames.Count; i++) { + cancellationToken.ThrowIfCancellationRequested(); + // Since Windows Vista, the size of an image is determined from the BITMAPINFOHEADER structure or PNG image data // which technically allows storing icons with larger than 256 pixels, but such larger sizes are not recommended by Microsoft. ImageFrame frame = image.Frames[i];