Browse Source

format

pull/2899/head
Poker 1 year ago
parent
commit
a86f5332ba
No known key found for this signature in database GPG Key ID: C65A6AD457D5C8F8
  1. 21
      src/ImageSharp/Formats/Ani/AniConstants.cs
  2. 15
      src/ImageSharp/Formats/Ani/AniDecoderCore.cs
  3. 17
      src/ImageSharp/Formats/Ani/AniHeader.cs
  4. 21
      src/ImageSharp/Formats/Ani/AniHeaderFlags.cs
  5. 14
      src/ImageSharp/Formats/Ani/AniMetadata.cs
  6. 16
      src/ImageSharp/Formats/Webp/RiffChunkHeader.cs
  7. 28
      src/ImageSharp/Formats/Webp/RiffHelper.cs
  8. 26
      src/ImageSharp/Formats/Webp/RiffOrListChunkHeader.cs
  9. 10
      src/ImageSharp/Formats/Webp/WebpConstants.cs
  10. 5
      src/ImageSharp/IO/BufferedReadStream.cs

21
src/ImageSharp/Formats/Ani/AniConstants.cs

@ -5,6 +5,11 @@ namespace SixLabors.ImageSharp.Formats.Ani;
internal static class AniConstants internal static class AniConstants
{ {
/// <summary>
/// Gets the header bytes identifying an ani.
/// </summary>
public const uint AniFourCc = 0x41_43_4F_4E;
/// <summary> /// <summary>
/// The list of mime types that equate to an ani. /// The list of mime types that equate to an ani.
/// </summary> /// </summary>
@ -19,20 +24,4 @@ internal static class AniConstants
/// Gets the header bytes identifying an ani. /// Gets the header bytes identifying an ani.
/// </summary> /// </summary>
public static ReadOnlySpan<byte> AniFormTypeFourCc => "ACON"u8; 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
src/ImageSharp/Formats/Ani/AniDecoderCore.cs

@ -15,19 +15,11 @@ using SixLabors.ImageSharp.IO;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Memory.Internals; using SixLabors.ImageSharp.Memory.Internals;
using SixLabors.ImageSharp.Metadata; using SixLabors.ImageSharp.Metadata;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Formats.Ani; namespace SixLabors.ImageSharp.Formats.Ani;
internal class AniDecoderCore(DecoderOptions options) : ImageDecoderCore(options) internal class AniDecoderCore(DecoderOptions options) : ImageDecoderCore(options)
{ {
private enum ListIconChunkType : byte
{
Ico = 1,
Cur = 2,
Bmp = 3
}
/// <summary> /// <summary>
/// The general decoder options. /// The general decoder options.
/// </summary> /// </summary>
@ -40,6 +32,13 @@ internal class AniDecoderCore(DecoderOptions options) : ImageDecoderCore(options
private AniHeader header; private AniHeader header;
private enum ListIconChunkType : byte
{
Ico = 1,
Cur,
Bmp
}
protected override Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken cancellationToken) protected override Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken cancellationToken)
{ {
this.currentStream = stream; this.currentStream = stream;

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

@ -30,20 +30,3 @@ internal readonly struct AniHeader
public void WriteTo(Stream stream) => stream.Write(MemoryMarshal.AsBytes(MemoryMarshal.CreateReadOnlySpan(in this, 1))); 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
}

21
src/ImageSharp/Formats/Ani/AniHeaderFlags.cs

@ -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
}

14
src/ImageSharp/Formats/Ani/AniMetadata.cs

@ -11,6 +11,13 @@ namespace SixLabors.ImageSharp.Formats.Ani;
/// </summary> /// </summary>
public class AniMetadata : IFormatMetadata<AniMetadata> public class AniMetadata : IFormatMetadata<AniMetadata>
{ {
/// <summary>
/// Initializes a new instance of the <see cref="AniMetadata"/> class.
/// </summary>
public AniMetadata()
{
}
/// <summary> /// <summary>
/// Gets or sets the width of frames in the animation. /// Gets or sets the width of frames in the animation.
/// </summary> /// </summary>
@ -56,13 +63,6 @@ public class AniMetadata : IFormatMetadata<AniMetadata>
/// </summary> /// </summary>
public IList<ImageFrameMetadata> IconFrames { get; set; } = []; public IList<ImageFrameMetadata> IconFrames { get; set; } = [];
/// <summary>
/// Initializes a new instance of the <see cref="AniMetadata"/> class.
/// </summary>
public AniMetadata()
{
}
/// <inheritdoc/> /// <inheritdoc/>
public static AniMetadata FromFormatConnectingMetadata(FormatConnectingMetadata metadata) => throw new NotImplementedException(); public static AniMetadata FromFormatConnectingMetadata(FormatConnectingMetadata metadata) => throw new NotImplementedException();

16
src/ImageSharp/Formats/Webp/RiffChunkHeader.cs

@ -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));
}

28
src/ImageSharp/Formats/Webp/RiffHelper.cs

@ -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));
}

26
src/ImageSharp/Formats/Webp/RiffOrListChunkHeader.cs

@ -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));
}

10
src/ImageSharp/Formats/Webp/WebpConstants.cs

@ -28,11 +28,6 @@ internal static class WebpConstants
0x2A 0x2A
}; };
/// <summary>
/// Gets the header bytes identifying a Webp.
/// </summary>
public static ReadOnlySpan<byte> WebpFormTypeFourCc => "WEBP"u8;
/// <summary> /// <summary>
/// Gets the header bytes identifying a Webp. /// Gets the header bytes identifying a Webp.
/// </summary> /// </summary>
@ -302,4 +297,9 @@ internal static class WebpConstants
-7, 8, -7, 8,
-8, -9 -8, -9
}; };
/// <summary>
/// Gets the header bytes identifying a Webp.
/// </summary>
public static ReadOnlySpan<byte> WebpFormTypeFourCc => "WEBP"u8;
} }

5
src/ImageSharp/IO/BufferedReadStream.cs

@ -3,12 +3,7 @@
using System.Buffers; using System.Buffers;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats.Ani;
using static System.Runtime.InteropServices.JavaScript.JSType;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System;
using System.Diagnostics.CodeAnalysis;
using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.IO; namespace SixLabors.ImageSharp.IO;

Loading…
Cancel
Save