diff --git a/src/ImageSharp/Formats/Cur/CurDecoderCore.cs b/src/ImageSharp/Formats/Cur/CurDecoderCore.cs index 4c0224652..538f9a2c6 100644 --- a/src/ImageSharp/Formats/Cur/CurDecoderCore.cs +++ b/src/ImageSharp/Formats/Cur/CurDecoderCore.cs @@ -6,13 +6,8 @@ using SixLabors.ImageSharp.Metadata; namespace SixLabors.ImageSharp.Formats.Cur; -internal sealed class CurDecoderCore : IconDecoderCore +internal sealed class CurDecoderCore(DecoderOptions options) : IconDecoderCore(options) { - public CurDecoderCore(DecoderOptions options) - : base(options) - { - } - protected override void SetFrameMetadata(ImageFrameMetadata metadata, in IconDirEntry entry, IconFrameCompression compression, Bmp.BmpBitsPerPixel bitsPerPixel) { CurFrameMetadata curFrameMetadata = metadata.GetCurMetadata(); diff --git a/src/ImageSharp/Formats/Ico/IcoDecoderCore.cs b/src/ImageSharp/Formats/Ico/IcoDecoderCore.cs index 859340fb4..78cb0d961 100644 --- a/src/ImageSharp/Formats/Ico/IcoDecoderCore.cs +++ b/src/ImageSharp/Formats/Ico/IcoDecoderCore.cs @@ -6,13 +6,8 @@ using SixLabors.ImageSharp.Metadata; namespace SixLabors.ImageSharp.Formats.Ico; -internal sealed class IcoDecoderCore : IconDecoderCore +internal sealed class IcoDecoderCore(DecoderOptions options) : IconDecoderCore(options) { - public IcoDecoderCore(DecoderOptions options) - : base(options) - { - } - protected override void SetFrameMetadata(ImageFrameMetadata metadata, in IconDirEntry entry, IconFrameCompression compression, Bmp.BmpBitsPerPixel bitsPerPixel) { IcoFrameMetadata icoFrameMetadata = metadata.GetIcoMetadata(); diff --git a/src/ImageSharp/Formats/Icon/IconDecoderCore.cs b/src/ImageSharp/Formats/Icon/IconDecoderCore.cs index 6af9553cc..983d4c346 100644 --- a/src/ImageSharp/Formats/Icon/IconDecoderCore.cs +++ b/src/ImageSharp/Formats/Icon/IconDecoderCore.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -using System.Runtime.InteropServices; using SixLabors.ImageSharp.Formats.Bmp; using SixLabors.ImageSharp.Formats.Png; using SixLabors.ImageSharp.IO; @@ -10,19 +9,17 @@ using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Formats.Icon; -internal abstract class IconDecoderCore : IImageDecoderInternals +internal abstract class IconDecoderCore(DecoderOptions options) : IImageDecoderInternals { private IconDir fileHeader; - public IconDecoderCore(DecoderOptions options) => this.Options = options; - - public DecoderOptions Options { get; } + public DecoderOptions Options { get; } = options; public Size Dimensions { get; private set; } protected IconDir FileHeader { get => this.fileHeader; private set => this.fileHeader = value; } - protected IconDirEntry[] Entries { get; private set; } = Array.Empty(); + protected IconDirEntry[] Entries { get; private set; } = []; public Image Decode(BufferedReadStream stream, CancellationToken cancellationToken) where TPixel : unmanaged, IPixel @@ -52,7 +49,7 @@ internal abstract class IconDecoderCore : IImageDecoderInternals } // Reset the stream position. - stream.Seek(-PngConstants.HeaderBytes.Length, SeekOrigin.Current); + _ = stream.Seek(-PngConstants.HeaderBytes.Length, SeekOrigin.Current); bool isPng = flag.SequenceEqual(PngConstants.HeaderBytes); @@ -86,7 +83,7 @@ internal abstract class IconDecoderCore : IImageDecoderInternals } // Bmp does not contain frame specific metadata. - target.Metadata.SetFormatMetadata(PngFormat.Instance, target.Metadata.GetPngFrameMetadata()); + target.Metadata.SetFormatMetadata(PngFormat.Instance, target.Metadata.GetPngMetadata()); } else { @@ -137,7 +134,7 @@ internal abstract class IconDecoderCore : IImageDecoderInternals } // Reset the stream position. - stream.Seek(-PngConstants.HeaderBytes.Length, SeekOrigin.Current); + _ = stream.Seek(-PngConstants.HeaderBytes.Length, SeekOrigin.Current); bool isPng = flag.SequenceEqual(PngConstants.HeaderBytes); @@ -210,7 +207,10 @@ internal abstract class IconDecoderCore : IImageDecoderInternals { if (isPng) { - return new PngDecoderCore(this.Options); + return new PngDecoderCore(new() + { + GeneralOptions = this.Options, + }); } else { diff --git a/src/ImageSharp/Formats/Icon/IconDir.cs b/src/ImageSharp/Formats/Icon/IconDir.cs index 53b87bc9f..390a4de65 100644 --- a/src/ImageSharp/Formats/Icon/IconDir.cs +++ b/src/ImageSharp/Formats/Icon/IconDir.cs @@ -6,12 +6,12 @@ using System.Runtime.InteropServices; namespace SixLabors.ImageSharp.Formats.Icon; [StructLayout(LayoutKind.Sequential, Pack = 1, Size = Size)] -internal struct IconDir +internal struct IconDir(ushort reserved, IconFileType type, ushort count) { public const int Size = 3 * sizeof(ushort); - public ushort Reserved; - public IconFileType Type; - public ushort Count; + public ushort Reserved = reserved; + public IconFileType Type = type; + public ushort Count = count; public IconDir(IconFileType type) : this(type, 0) @@ -23,13 +23,6 @@ internal struct IconDir { } - public IconDir(ushort reserved, IconFileType type, ushort count) - { - this.Reserved = reserved; - this.Type = type; - this.Count = count; - } - public static IconDir Parse(in ReadOnlySpan data) => MemoryMarshal.Cast(data)[0]; }