Browse Source

Add Unit Test

pull/2899/head
Betta_Fish 1 year ago
parent
commit
9055bed91b
  1. 17
      src/ImageSharp/Formats/Ani/AniDecoderCore.cs
  2. 27
      src/ImageSharp/Formats/Ani/AniHeader.cs
  3. 23
      tests/ImageSharp.Tests/Formats/Ani/AniDecoderTests.cs
  4. 6
      tests/ImageSharp.Tests/TestImages.cs
  5. 3
      tests/Images/Input/Ani/Work.ani

17
src/ImageSharp/Formats/Ani/AniDecoderCore.cs

@ -16,6 +16,21 @@ internal class AniDecoderCore : ImageDecoderCore
protected override Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken cancellationToken)
{
this.ReadHeader(stream);
Span<byte> 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<byte> buffer = stackalloc byte[AniHeader.Size];
Span<byte> buffer = stackalloc byte[36];
_ = stream.Read(buffer);
AniHeader header = AniHeader.Parse(buffer);
}

27
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<byte> data)
=> MemoryMarshal.Cast<byte, AniHeader>(data)[0];
@ -32,3 +32,10 @@ internal readonly struct AniHeader
public readonly unsafe void WriteTo(in Stream stream)
=> stream.Write(MemoryMarshal.Cast<AniHeader, byte>([this]));
}
[Flags]
public enum AniHeaderFlags : uint
{
IsIcon = 1,
ContainsSeq = 2
}

23
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<Rgba32> provider)
{
using Image<Rgba32> image = provider.GetImage(AniDecoder.Instance);
}
}

6
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";
}
}

3
tests/Images/Input/Ani/Work.ani

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:740353739d3763addddd383614d125918781b8879f7c1ad3c770162a3e143a33
size 1150338
Loading…
Cancel
Save