Poker
1 year ago
No known key found for this signature in database
GPG Key ID: C65A6AD457D5C8F8
10 changed files with
87 additions and
86 deletions
-
src/ImageSharp/Formats/Ani/AniConstants.cs
-
src/ImageSharp/Formats/Ani/AniDecoderCore.cs
-
src/ImageSharp/Formats/Ani/AniHeader.cs
-
src/ImageSharp/Formats/Ani/AniHeaderFlags.cs
-
src/ImageSharp/Formats/Ani/AniMetadata.cs
-
src/ImageSharp/Formats/Webp/RiffChunkHeader.cs
-
src/ImageSharp/Formats/Webp/RiffHelper.cs
-
src/ImageSharp/Formats/Webp/RiffOrListChunkHeader.cs
-
src/ImageSharp/Formats/Webp/WebpConstants.cs
-
src/ImageSharp/IO/BufferedReadStream.cs
|
|
|
@ -5,6 +5,11 @@ namespace SixLabors.ImageSharp.Formats.Ani; |
|
|
|
|
|
|
|
internal static class AniConstants |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// Gets the header bytes identifying an ani.
|
|
|
|
/// </summary>
|
|
|
|
public const uint AniFourCc = 0x41_43_4F_4E; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The list of mime types that equate to an ani.
|
|
|
|
/// </summary>
|
|
|
|
@ -19,20 +24,4 @@ internal static class AniConstants |
|
|
|
/// Gets the header bytes identifying an ani.
|
|
|
|
/// </summary>
|
|
|
|
public static ReadOnlySpan<byte> AniFormTypeFourCc => "ACON"u8; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the header bytes identifying an ani.
|
|
|
|
/// </summary>
|
|
|
|
public const uint AniFourCc = 0x41_43_4F_4E; |
|
|
|
|
|
|
|
public static class ChunkFourCcs |
|
|
|
{ |
|
|
|
public static ReadOnlySpan<byte> AniHeader => "anih"u8; |
|
|
|
|
|
|
|
public static ReadOnlySpan<byte> Seq => "seq "u8; |
|
|
|
|
|
|
|
public static ReadOnlySpan<byte> Rate => "rate"u8; |
|
|
|
|
|
|
|
public static ReadOnlySpan<byte> Icon => "icon"u8; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -15,19 +15,11 @@ using SixLabors.ImageSharp.IO; |
|
|
|
using SixLabors.ImageSharp.Memory; |
|
|
|
using SixLabors.ImageSharp.Memory.Internals; |
|
|
|
using SixLabors.ImageSharp.Metadata; |
|
|
|
using SixLabors.ImageSharp.PixelFormats; |
|
|
|
|
|
|
|
namespace SixLabors.ImageSharp.Formats.Ani; |
|
|
|
|
|
|
|
internal class AniDecoderCore(DecoderOptions options) : ImageDecoderCore(options) |
|
|
|
{ |
|
|
|
private enum ListIconChunkType : byte |
|
|
|
{ |
|
|
|
Ico = 1, |
|
|
|
Cur = 2, |
|
|
|
Bmp = 3 |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The general decoder options.
|
|
|
|
/// </summary>
|
|
|
|
@ -40,6 +32,13 @@ internal class AniDecoderCore(DecoderOptions options) : ImageDecoderCore(options |
|
|
|
|
|
|
|
private AniHeader header; |
|
|
|
|
|
|
|
private enum ListIconChunkType : byte |
|
|
|
{ |
|
|
|
Ico = 1, |
|
|
|
Cur, |
|
|
|
Bmp |
|
|
|
} |
|
|
|
|
|
|
|
protected override Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken cancellationToken) |
|
|
|
{ |
|
|
|
this.currentStream = stream; |
|
|
|
|
|
|
|
@ -30,20 +30,3 @@ internal readonly struct AniHeader |
|
|
|
|
|
|
|
public void WriteTo(Stream stream) => stream.Write(MemoryMarshal.AsBytes(MemoryMarshal.CreateReadOnlySpan(in this, 1))); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Flags for the ANI header.
|
|
|
|
/// </summary>
|
|
|
|
[Flags] |
|
|
|
public enum AniHeaderFlags : uint |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// If set, the ANI file's "icon" chunk contains an ICO or CUR file, otherwise it contains a BMP file.
|
|
|
|
/// </summary>
|
|
|
|
IsIcon = 1, |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// If set, the ANI file contains a "seq " chunk.
|
|
|
|
/// </summary>
|
|
|
|
ContainsSeq = 2 |
|
|
|
} |
|
|
|
|
|
|
|
@ -0,0 +1,21 @@ |
|
|
|
// Copyright (c) Six Labors.
|
|
|
|
// Licensed under the Six Labors Split License.
|
|
|
|
|
|
|
|
namespace SixLabors.ImageSharp.Formats.Ani; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Flags for the ANI header.
|
|
|
|
/// </summary>
|
|
|
|
[Flags] |
|
|
|
public enum AniHeaderFlags : uint |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// If set, the ANI file's "icon" chunk contains an ICO or CUR file, otherwise it contains a BMP file.
|
|
|
|
/// </summary>
|
|
|
|
IsIcon = 1, |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// If set, the ANI file contains a "seq " chunk.
|
|
|
|
/// </summary>
|
|
|
|
ContainsSeq = 2 |
|
|
|
} |
|
|
|
@ -11,6 +11,13 @@ namespace SixLabors.ImageSharp.Formats.Ani; |
|
|
|
/// </summary>
|
|
|
|
public class AniMetadata : IFormatMetadata<AniMetadata> |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="AniMetadata"/> class.
|
|
|
|
/// </summary>
|
|
|
|
public AniMetadata() |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the width of frames in the animation.
|
|
|
|
/// </summary>
|
|
|
|
@ -56,13 +63,6 @@ public class AniMetadata : IFormatMetadata<AniMetadata> |
|
|
|
/// </summary>
|
|
|
|
public IList<ImageFrameMetadata> IconFrames { get; set; } = []; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="AniMetadata"/> class.
|
|
|
|
/// </summary>
|
|
|
|
public AniMetadata() |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public static AniMetadata FromFormatConnectingMetadata(FormatConnectingMetadata metadata) => throw new NotImplementedException(); |
|
|
|
|
|
|
|
|
|
|
|
@ -0,0 +1,16 @@ |
|
|
|
// Copyright (c) Six Labors.
|
|
|
|
// Licensed under the Six Labors Split License.
|
|
|
|
|
|
|
|
using System.Runtime.CompilerServices; |
|
|
|
using System.Runtime.InteropServices; |
|
|
|
|
|
|
|
namespace SixLabors.ImageSharp.Formats.Webp; |
|
|
|
|
|
|
|
internal readonly struct RiffChunkHeader |
|
|
|
{ |
|
|
|
public readonly uint FourCc; |
|
|
|
|
|
|
|
public readonly uint Size; |
|
|
|
|
|
|
|
public ReadOnlySpan<byte> FourCcBytes => MemoryMarshal.CreateReadOnlySpan(ref Unsafe.As<uint, byte>(ref Unsafe.AsRef(in this.FourCc)), sizeof(uint)); |
|
|
|
} |
|
|
|
@ -93,31 +93,3 @@ internal static class RiffHelper |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
internal readonly struct RiffChunkHeader |
|
|
|
{ |
|
|
|
public readonly uint FourCc; |
|
|
|
|
|
|
|
public ReadOnlySpan<byte> FourCcBytes => MemoryMarshal.CreateReadOnlySpan(ref Unsafe.As<uint, byte>(ref Unsafe.AsRef(in this.FourCc)), sizeof(uint)); |
|
|
|
|
|
|
|
public readonly uint Size; |
|
|
|
} |
|
|
|
|
|
|
|
internal readonly struct RiffOrListChunkHeader |
|
|
|
{ |
|
|
|
public const int HeaderSize = 12; |
|
|
|
|
|
|
|
public readonly uint FourCc; |
|
|
|
|
|
|
|
public readonly uint Size; |
|
|
|
|
|
|
|
public readonly uint FormType; |
|
|
|
|
|
|
|
public ReadOnlySpan<byte> FourCcBytes => MemoryMarshal.CreateReadOnlySpan(ref Unsafe.As<uint, byte>(ref Unsafe.AsRef(in this.FourCc)), sizeof(uint)); |
|
|
|
|
|
|
|
public bool IsRiff => this.FourCc is 0x52_49_46_46; // "RIFF"
|
|
|
|
|
|
|
|
public bool IsList => this.FourCc is 0x4C_49_53_54; // "LIST"
|
|
|
|
|
|
|
|
public static ref RiffOrListChunkHeader Parse(ReadOnlySpan<byte> data) => ref Unsafe.As<byte, RiffOrListChunkHeader>(ref MemoryMarshal.GetReference(data)); |
|
|
|
} |
|
|
|
|
|
|
|
@ -0,0 +1,26 @@ |
|
|
|
// Copyright (c) Six Labors.
|
|
|
|
// Licensed under the Six Labors Split License.
|
|
|
|
|
|
|
|
using System.Runtime.CompilerServices; |
|
|
|
using System.Runtime.InteropServices; |
|
|
|
|
|
|
|
namespace SixLabors.ImageSharp.Formats.Webp; |
|
|
|
|
|
|
|
internal readonly struct RiffOrListChunkHeader |
|
|
|
{ |
|
|
|
public const int HeaderSize = 12; |
|
|
|
|
|
|
|
public readonly uint FourCc; |
|
|
|
|
|
|
|
public readonly uint Size; |
|
|
|
|
|
|
|
public readonly uint FormType; |
|
|
|
|
|
|
|
public ReadOnlySpan<byte> FourCcBytes => MemoryMarshal.CreateReadOnlySpan(ref Unsafe.As<uint, byte>(ref Unsafe.AsRef(in this.FourCc)), sizeof(uint)); |
|
|
|
|
|
|
|
public bool IsRiff => this.FourCc is 0x52_49_46_46; // "RIFF"
|
|
|
|
|
|
|
|
public bool IsList => this.FourCc is 0x4C_49_53_54; // "LIST"
|
|
|
|
|
|
|
|
public static ref RiffOrListChunkHeader Parse(ReadOnlySpan<byte> data) => ref Unsafe.As<byte, RiffOrListChunkHeader>(ref MemoryMarshal.GetReference(data)); |
|
|
|
} |
|
|
|
@ -28,11 +28,6 @@ internal static class WebpConstants |
|
|
|
0x2A |
|
|
|
}; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the header bytes identifying a Webp.
|
|
|
|
/// </summary>
|
|
|
|
public static ReadOnlySpan<byte> WebpFormTypeFourCc => "WEBP"u8; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the header bytes identifying a Webp.
|
|
|
|
/// </summary>
|
|
|
|
@ -302,4 +297,9 @@ internal static class WebpConstants |
|
|
|
-7, 8, |
|
|
|
-8, -9 |
|
|
|
}; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the header bytes identifying a Webp.
|
|
|
|
/// </summary>
|
|
|
|
public static ReadOnlySpan<byte> WebpFormTypeFourCc => "WEBP"u8; |
|
|
|
} |
|
|
|
|
|
|
|
@ -3,12 +3,7 @@ |
|
|
|
|
|
|
|
using System.Buffers; |
|
|
|
using System.Runtime.CompilerServices; |
|
|
|
using SixLabors.ImageSharp.Formats.Ani; |
|
|
|
using static System.Runtime.InteropServices.JavaScript.JSType; |
|
|
|
using System.Runtime.InteropServices; |
|
|
|
using System; |
|
|
|
using System.Diagnostics.CodeAnalysis; |
|
|
|
using SixLabors.ImageSharp.Memory; |
|
|
|
|
|
|
|
namespace SixLabors.ImageSharp.IO; |
|
|
|
|
|
|
|
|