diff --git a/src/ImageSharp/Formats/Ani/AniDecoderCore.cs b/src/ImageSharp/Formats/Ani/AniDecoderCore.cs index c60036c465..45fb040a29 100644 --- a/src/ImageSharp/Formats/Ani/AniDecoderCore.cs +++ b/src/ImageSharp/Formats/Ani/AniDecoderCore.cs @@ -16,6 +16,21 @@ internal class AniDecoderCore : ImageDecoderCore protected override Image Decode(BufferedReadStream stream, CancellationToken cancellationToken) { this.ReadHeader(stream); + Span buffer = stackalloc byte[4]; + _ = stream.Read(buffer); + uint type = BitConverter.ToUInt32(buffer); + switch (type) + { + case 0x73_65_71_20: // seq + break; + case 0x72_61_74_65: // rate + break; + case 0x4C_49_53_54: // list + break; + default: + break; + } + throw new NotImplementedException(); } @@ -28,7 +43,7 @@ internal class AniDecoderCore : ImageDecoderCore { // Skip the identifier stream.Skip(12); - Span buffer = stackalloc byte[AniHeader.Size]; + Span buffer = stackalloc byte[36]; _ = stream.Read(buffer); AniHeader header = AniHeader.Parse(buffer); } diff --git a/src/ImageSharp/Formats/Ani/AniHeader.cs b/src/ImageSharp/Formats/Ani/AniHeader.cs index 8f985c4c6e..514ce710d3 100644 --- a/src/ImageSharp/Formats/Ani/AniHeader.cs +++ b/src/ImageSharp/Formats/Ani/AniHeader.cs @@ -5,26 +5,26 @@ using System.Runtime.InteropServices; namespace SixLabors.ImageSharp.Formats.Ani; -[StructLayout(LayoutKind.Sequential, Pack = 1, Size = Size)] +[StructLayout(LayoutKind.Sequential, Pack = 1, Size = 36)] internal readonly struct AniHeader { - public const int Size = 36; + public uint Size { get; } - public ushort Frames { get; } + public uint Frames { get; } - public ushort Steps { get; } + public uint Steps { get; } - public ushort Width { get; } + public uint Width { get; } - public ushort Height { get; } + public uint Height { get; } - public ushort BitCount { get; } + public uint BitCount { get; } - public ushort Planes { get; } + public uint Planes { get; } - public ushort DisplayRate { get; } + public uint DisplayRate { get; } - public ushort Flags { get; } + public AniHeaderFlags Flags { get; } public static AniHeader Parse(in ReadOnlySpan data) => MemoryMarshal.Cast(data)[0]; @@ -32,3 +32,10 @@ internal readonly struct AniHeader public readonly unsafe void WriteTo(in Stream stream) => stream.Write(MemoryMarshal.Cast([this])); } + +[Flags] +public enum AniHeaderFlags : uint +{ + IsIcon = 1, + ContainsSeq = 2 +} diff --git a/tests/ImageSharp.Tests/Formats/Ani/AniDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Ani/AniDecoderTests.cs new file mode 100644 index 0000000000..f79570f22c --- /dev/null +++ b/tests/ImageSharp.Tests/Formats/Ani/AniDecoderTests.cs @@ -0,0 +1,23 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using SixLabors.ImageSharp.Formats.Ani; +using SixLabors.ImageSharp.Formats.Bmp; +using SixLabors.ImageSharp.Formats.Cur; +using SixLabors.ImageSharp.Formats.Icon; +using SixLabors.ImageSharp.PixelFormats; +using static SixLabors.ImageSharp.Tests.TestImages.Ani; + +namespace SixLabors.ImageSharp.Tests.Formats.Ani; + +[Trait("format", "Ani")] +[ValidateDisposedMemoryAllocations] +public class AniDecoderTests +{ + [Theory] + [WithFile(Work, PixelTypes.Rgba32)] + public void CurDecoder_Decode(TestImageProvider provider) + { + using Image image = provider.GetImage(AniDecoder.Instance); + } +} diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index 4130474b58..d928b82b3d 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -1254,4 +1254,10 @@ public static class TestImages public const string CurReal = "Icon/cur_real.cur"; public const string CurFake = "Icon/cur_fake.ico"; } + + public static class Ani + { + public const string Work = "Ani/Work.ani"; + } + } diff --git a/tests/Images/Input/Ani/Work.ani b/tests/Images/Input/Ani/Work.ani new file mode 100644 index 0000000000..d576244bbd --- /dev/null +++ b/tests/Images/Input/Ani/Work.ani @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:740353739d3763addddd383614d125918781b8879f7c1ad3c770162a3e143a33 +size 1150338