Skip to content

Commit aac7d3a

Browse files
committed
Add Header
1 parent 1d096b2 commit aac7d3a

File tree

4 files changed

+127
-0
lines changed

4 files changed

+127
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Six Labors Split License.
3+
using SixLabors.ImageSharp.PixelFormats;
4+
5+
namespace SixLabors.ImageSharp.Formats.Ani;
6+
7+
internal sealed class AniDecoder : ImageDecoder
8+
{
9+
private AniDecoder()
10+
{
11+
}
12+
13+
/// <summary>
14+
/// Gets the shared instance.
15+
/// </summary>
16+
public static AniDecoder Instance { get; } = new();
17+
18+
protected override Image<TPixel> Decode<TPixel>(DecoderOptions options, Stream stream, CancellationToken cancellationToken)
19+
{
20+
Guard.NotNull(options, nameof(options));
21+
Guard.NotNull(stream, nameof(stream));
22+
Image<TPixel> image = new AniDecoderCore(options).Decode<TPixel>(options.Configuration, stream, cancellationToken);
23+
ScaleToTargetSize(options, image);
24+
return image;
25+
}
26+
27+
protected override Image Decode(DecoderOptions options, Stream stream, CancellationToken cancellationToken) => this.Decode<Rgba32>(options, stream, cancellationToken);
28+
29+
protected override ImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken)
30+
{
31+
Guard.NotNull(options, nameof(options));
32+
Guard.NotNull(stream, nameof(stream));
33+
return new AniDecoderCore(options).Identify(options.Configuration, stream, cancellationToken);
34+
}
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Six Labors Split License.
3+
4+
using SixLabors.ImageSharp.Formats.Icon;
5+
using SixLabors.ImageSharp.IO;
6+
7+
namespace SixLabors.ImageSharp.Formats.Ani;
8+
9+
internal class AniDecoderCore : ImageDecoderCore
10+
{
11+
public AniDecoderCore(DecoderOptions options)
12+
: base(options)
13+
{
14+
}
15+
16+
protected override Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken cancellationToken)
17+
{
18+
this.ReadHeader(stream);
19+
throw new NotImplementedException();
20+
}
21+
22+
protected override ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken)
23+
{
24+
throw new NotImplementedException();
25+
}
26+
27+
private void ReadHeader(Stream stream)
28+
{
29+
// Skip the identifier
30+
stream.Skip(12);
31+
Span<byte> buffer = stackalloc byte[AniHeader.Size];
32+
_ = stream.Read(buffer);
33+
AniHeader header = AniHeader.Parse(buffer);
34+
}
35+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Six Labors Split License.
3+
4+
using System.Runtime.InteropServices;
5+
6+
namespace SixLabors.ImageSharp.Formats.Ani;
7+
8+
[StructLayout(LayoutKind.Sequential, Pack = 1, Size = Size)]
9+
internal readonly struct AniHeader
10+
{
11+
public const int Size = 36;
12+
13+
public ushort Frames { get; }
14+
15+
public ushort Steps { get; }
16+
17+
public ushort Width { get; }
18+
19+
public ushort Height { get; }
20+
21+
public ushort BitCount { get; }
22+
23+
public ushort Planes { get; }
24+
25+
public ushort DisplayRate { get; }
26+
27+
public ushort Flags { get; }
28+
29+
public static AniHeader Parse(in ReadOnlySpan<byte> data)
30+
=> MemoryMarshal.Cast<byte, AniHeader>(data)[0];
31+
32+
public readonly unsafe void WriteTo(in Stream stream)
33+
=> stream.Write(MemoryMarshal.Cast<AniHeader, byte>([this]));
34+
}
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.PixelFormats;
5+
6+
namespace SixLabors.ImageSharp.Formats.Ani;
7+
8+
internal class AniMetadata : IFormatMetadata<AniMetadata>
9+
{
10+
11+
public static AniMetadata FromFormatConnectingMetadata(FormatConnectingMetadata metadata) => throw new NotImplementedException();
12+
13+
public void AfterImageApply<TPixel>(Image<TPixel> destination)
14+
where TPixel : unmanaged, IPixel<TPixel> => throw new NotImplementedException();
15+
16+
public IDeepCloneable DeepClone() => throw new NotImplementedException();
17+
18+
public PixelTypeInfo GetPixelTypeInfo() => throw new NotImplementedException();
19+
20+
public FormatConnectingMetadata ToFormatConnectingMetadata() => throw new NotImplementedException();
21+
22+
AniMetadata IDeepCloneable<AniMetadata>.DeepClone() => throw new NotImplementedException();
23+
}

0 commit comments

Comments
 (0)