|
3 | 3 |
|
4 | 4 | using System.Buffers.Binary;
|
5 | 5 | using SixLabors.ImageSharp.Formats.Png;
|
| 6 | +using SixLabors.ImageSharp.Formats.Png.Chunks; |
6 | 7 | using SixLabors.ImageSharp.PixelFormats;
|
7 | 8 |
|
8 | 9 | // ReSharper disable InconsistentNaming
|
@@ -59,6 +60,38 @@ public void EndChunk_IsLast()
|
59 | 60 | }
|
60 | 61 | }
|
61 | 62 |
|
| 63 | + [Theory] |
| 64 | + [WithFile(TestImages.Png.DefaultNotAnimated, PixelTypes.Rgba32)] |
| 65 | + [WithFile(TestImages.Png.APng, PixelTypes.Rgba32)] |
| 66 | + public void AcTL_CorrectlyWritten<TPixel>(TestImageProvider<TPixel> provider) |
| 67 | + where TPixel : unmanaged, IPixel<TPixel> |
| 68 | + { |
| 69 | + using Image<TPixel> image = provider.GetImage(PngDecoder.Instance); |
| 70 | + PngMetadata metadata = image.Metadata.GetPngMetadata(); |
| 71 | + int correctFrameCount = image.Frames.Count - (metadata.DefaultImageAnimated ? 0 : 1); |
| 72 | + using MemoryStream memStream = new(); |
| 73 | + image.Save(memStream, PngEncoder); |
| 74 | + memStream.Position = 0; |
| 75 | + Span<byte> bytesSpan = memStream.ToArray().AsSpan(8); // Skip header. |
| 76 | + bool foundAcTl = false; |
| 77 | + while (bytesSpan.Length > 0 && !foundAcTl) |
| 78 | + { |
| 79 | + int length = BinaryPrimitives.ReadInt32BigEndian(bytesSpan[..4]); |
| 80 | + PngChunkType type = (PngChunkType)BinaryPrimitives.ReadInt32BigEndian(bytesSpan.Slice(4, 4)); |
| 81 | + if (type == PngChunkType.AnimationControl) |
| 82 | + { |
| 83 | + AnimationControl control = AnimationControl.Parse(bytesSpan[8..]); |
| 84 | + foundAcTl = true; |
| 85 | + Assert.True(control.NumberFrames == correctFrameCount); |
| 86 | + Assert.True(control.NumberPlays == metadata.RepeatCount); |
| 87 | + } |
| 88 | + |
| 89 | + bytesSpan = bytesSpan[(4 + 4 + length + 4)..]; |
| 90 | + } |
| 91 | + |
| 92 | + Assert.True(foundAcTl); |
| 93 | + } |
| 94 | + |
62 | 95 | [Theory]
|
63 | 96 | [InlineData(PngChunkType.Gamma)]
|
64 | 97 | [InlineData(PngChunkType.Chroma)]
|
|
0 commit comments