Skip to content

Commit 9055bed

Browse files
committed
Add Unit Test
1 parent aac7d3a commit 9055bed

File tree

5 files changed

+65
-11
lines changed

5 files changed

+65
-11
lines changed

src/ImageSharp/Formats/Ani/AniDecoderCore.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@ public AniDecoderCore(DecoderOptions options)
1616
protected override Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken cancellationToken)
1717
{
1818
this.ReadHeader(stream);
19+
Span<byte> buffer = stackalloc byte[4];
20+
_ = stream.Read(buffer);
21+
uint type = BitConverter.ToUInt32(buffer);
22+
switch (type)
23+
{
24+
case 0x73_65_71_20: // seq
25+
break;
26+
case 0x72_61_74_65: // rate
27+
break;
28+
case 0x4C_49_53_54: // list
29+
break;
30+
default:
31+
break;
32+
}
33+
1934
throw new NotImplementedException();
2035
}
2136

@@ -28,7 +43,7 @@ private void ReadHeader(Stream stream)
2843
{
2944
// Skip the identifier
3045
stream.Skip(12);
31-
Span<byte> buffer = stackalloc byte[AniHeader.Size];
46+
Span<byte> buffer = stackalloc byte[36];
3247
_ = stream.Read(buffer);
3348
AniHeader header = AniHeader.Parse(buffer);
3449
}

src/ImageSharp/Formats/Ani/AniHeader.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,37 @@
55

66
namespace SixLabors.ImageSharp.Formats.Ani;
77

8-
[StructLayout(LayoutKind.Sequential, Pack = 1, Size = Size)]
8+
[StructLayout(LayoutKind.Sequential, Pack = 1, Size = 36)]
99
internal readonly struct AniHeader
1010
{
11-
public const int Size = 36;
11+
public uint Size { get; }
1212

13-
public ushort Frames { get; }
13+
public uint Frames { get; }
1414

15-
public ushort Steps { get; }
15+
public uint Steps { get; }
1616

17-
public ushort Width { get; }
17+
public uint Width { get; }
1818

19-
public ushort Height { get; }
19+
public uint Height { get; }
2020

21-
public ushort BitCount { get; }
21+
public uint BitCount { get; }
2222

23-
public ushort Planes { get; }
23+
public uint Planes { get; }
2424

25-
public ushort DisplayRate { get; }
25+
public uint DisplayRate { get; }
2626

27-
public ushort Flags { get; }
27+
public AniHeaderFlags Flags { get; }
2828

2929
public static AniHeader Parse(in ReadOnlySpan<byte> data)
3030
=> MemoryMarshal.Cast<byte, AniHeader>(data)[0];
3131

3232
public readonly unsafe void WriteTo(in Stream stream)
3333
=> stream.Write(MemoryMarshal.Cast<AniHeader, byte>([this]));
3434
}
35+
36+
[Flags]
37+
public enum AniHeaderFlags : uint
38+
{
39+
IsIcon = 1,
40+
ContainsSeq = 2
41+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Six Labors Split License.
3+
4+
using SixLabors.ImageSharp.Formats.Ani;
5+
using SixLabors.ImageSharp.Formats.Bmp;
6+
using SixLabors.ImageSharp.Formats.Cur;
7+
using SixLabors.ImageSharp.Formats.Icon;
8+
using SixLabors.ImageSharp.PixelFormats;
9+
using static SixLabors.ImageSharp.Tests.TestImages.Ani;
10+
11+
namespace SixLabors.ImageSharp.Tests.Formats.Ani;
12+
13+
[Trait("format", "Ani")]
14+
[ValidateDisposedMemoryAllocations]
15+
public class AniDecoderTests
16+
{
17+
[Theory]
18+
[WithFile(Work, PixelTypes.Rgba32)]
19+
public void CurDecoder_Decode(TestImageProvider<Rgba32> provider)
20+
{
21+
using Image<Rgba32> image = provider.GetImage(AniDecoder.Instance);
22+
}
23+
}

tests/ImageSharp.Tests/TestImages.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,4 +1254,10 @@ public static class Cur
12541254
public const string CurReal = "Icon/cur_real.cur";
12551255
public const string CurFake = "Icon/cur_fake.ico";
12561256
}
1257+
1258+
public static class Ani
1259+
{
1260+
public const string Work = "Ani/Work.ani";
1261+
}
1262+
12571263
}

tests/Images/Input/Ani/Work.ani

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:740353739d3763addddd383614d125918781b8879f7c1ad3c770162a3e143a33
3+
size 1150338

0 commit comments

Comments
 (0)