Browse Source

Fixed errors and warnings

pull/2579/head
舰队的偶像-岛风酱! 2 years ago
parent
commit
746e742183
No known key found for this signature in database GPG Key ID: 71F5B3A2B181950C
  1. 7
      src/ImageSharp/Formats/Cur/CurDecoderCore.cs
  2. 7
      src/ImageSharp/Formats/Ico/IcoDecoderCore.cs
  3. 20
      src/ImageSharp/Formats/Icon/IconDecoderCore.cs
  4. 15
      src/ImageSharp/Formats/Icon/IconDir.cs

7
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();

7
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();

20
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<IconDirEntry>();
protected IconDirEntry[] Entries { get; private set; } = [];
public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel<TPixel>
@ -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
{

15
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<byte> data)
=> MemoryMarshal.Cast<byte, IconDir>(data)[0];
}

Loading…
Cancel
Save