-
-
Notifications
You must be signed in to change notification settings - Fork 894
Add ANI decoder support #2899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add ANI decoder support #2899
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
aac7d3a
Add Header
zxbmmmmmmmmm 9055bed
Add Unit Test
zxbmmmmmmmmm 1a51a5c
Add AniChunk
zxbmmmmmmmmm 49cf55c
Merge branch 'SixLabors:main' into feat/ani
Poker-sang e58010a
finish decoder
Poker-sang 33be868
Apply suggestions from code review
Poker-sang a86f533
format
Poker-sang 6490c10
Merge branch 'main' into feat/ani
JimBobSquarePants fc9fdee
fix primary ctor
Poker-sang 7377d3c
fix decoder modifier
Poker-sang c0ad499
use overload ctor
Poker-sang a979b96
rename FrameDelay
Poker-sang 163bdd4
fix DeepClone
Poker-sang 95f13cc
AfterFrameApply
Poker-sang fe95636
Span.IsEmpty
Poker-sang ed0edfe
fix AniMetadata
Poker-sang ceb0d51
apply new metadata layout
Poker-sang 2569343
update AniFrameFormat
Poker-sang 0658aa5
Merge remote-tracking branch 'upstream/main' into feat/ani
JimBobSquarePants 6fcf75c
Fix merge issues
JimBobSquarePants fac4a24
Merge branch 'main' into pr/2899
JimBobSquarePants db5b03d
Complete ANI, ICO, and CUR codec support
JimBobSquarePants e9aa4bf
Address ANI and icon review feedback
JimBobSquarePants eadb2a6
Handle oversized ANI chunks and partial icon masks
JimBobSquarePants File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| // Copyright (c) Six Labors. | ||
| // Licensed under the Six Labors Split License. | ||
|
|
||
| namespace SixLabors.ImageSharp.Formats.Ani; | ||
|
|
||
| /// <summary> | ||
| /// Identifies top-level ANI RIFF chunks. | ||
| /// </summary> | ||
| internal enum AniChunkType : uint | ||
| { | ||
| /// <summary> | ||
| /// The animation header chunk, "anih". | ||
| /// </summary> | ||
| Header = 0x68_69_6E_61, | ||
|
|
||
| /// <summary> | ||
| /// The frame sequence chunk, "seq ". | ||
| /// </summary> | ||
| Sequence = 0x20_71_65_73, | ||
|
|
||
| /// <summary> | ||
| /// The per-step display-rate chunk, "rate". | ||
| /// </summary> | ||
| Rate = 0x65_74_61_72, | ||
|
|
||
| /// <summary> | ||
| /// A RIFF list chunk, "LIST". | ||
| /// </summary> | ||
| List = 0x54_53_49_4C | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Identifies ANI RIFF list types. | ||
| /// </summary> | ||
| internal enum AniListType : uint | ||
| { | ||
| /// <summary> | ||
| /// The information list, "INFO". | ||
| /// </summary> | ||
| Info = 0x4F_46_4E_49, | ||
|
|
||
| /// <summary> | ||
| /// The embedded frame-resource list, "fram". | ||
| /// </summary> | ||
| Frames = 0x6D_61_72_66 | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Identifies chunks stored in an ANI information list. | ||
| /// </summary> | ||
| internal enum AniInfoChunkType : uint | ||
| { | ||
| /// <summary> | ||
| /// The animation name, "INAM". | ||
| /// </summary> | ||
| Name = 0x4D_41_4E_49, | ||
|
|
||
| /// <summary> | ||
| /// The animation artist, "IART". | ||
| /// </summary> | ||
| Artist = 0x54_52_41_49 | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Identifies chunks stored in an ANI frame list. | ||
| /// </summary> | ||
| internal enum AniFrameChunkType : uint | ||
| { | ||
| /// <summary> | ||
| /// An embedded frame resource, "icon". | ||
| /// </summary> | ||
| Icon = 0x6E_6F_63_69 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // Copyright (c) Six Labors. | ||
| // Licensed under the Six Labors Split License. | ||
|
|
||
| namespace SixLabors.ImageSharp.Formats.Ani; | ||
|
|
||
| /// <summary> | ||
| /// Registers the image encoder, decoder, and format detector for the ANI format. | ||
| /// </summary> | ||
| public sealed class AniConfigurationModule : IImageFormatConfigurationModule | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="AniConfigurationModule"/> class. | ||
| /// </summary> | ||
| public AniConfigurationModule() | ||
| { | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public void Configure(Configuration configuration) | ||
| { | ||
| configuration.ImageFormatsManager.SetEncoder(AniFormat.Instance, new AniEncoder()); | ||
| configuration.ImageFormatsManager.SetDecoder(AniFormat.Instance, AniDecoder.Instance); | ||
| configuration.ImageFormatsManager.AddImageFormatDetector(new AniImageFormatDetector()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // Copyright (c) Six Labors. | ||
| // Licensed under the Six Labors Split License. | ||
|
|
||
| namespace SixLabors.ImageSharp.Formats.Ani; | ||
|
|
||
| /// <summary> | ||
| /// Defines constants used by the ANI format. | ||
| /// </summary> | ||
| internal static class AniConstants | ||
| { | ||
| /// <summary> | ||
| /// The number of bytes in the RIFF identifier, size, and form type. | ||
| /// </summary> | ||
| public const int RiffHeaderSize = 12; | ||
|
|
||
| /// <summary> | ||
| /// The number of bytes in a RIFF chunk identifier and size. | ||
| /// </summary> | ||
| public const int ChunkHeaderSize = 8; | ||
|
|
||
| /// <summary> | ||
| /// The number of bytes required to identify an embedded ICO or CUR resource. | ||
| /// </summary> | ||
| public const int IconDirHeaderSize = 6; | ||
|
|
||
| /// <summary> | ||
| /// The maximum number of bytes retained from an ancillary chunk. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Control arrays and information strings come from untrusted input. Bounding them independently of the allocator | ||
| /// prevents a physically large RIFF chunk from consuming an unreasonable amount of memory. | ||
| /// </remarks> | ||
| public const int MaxAncillaryChunkSize = 8 * 1024 * 1024; | ||
|
|
||
| /// <summary> | ||
| /// The list of MIME types that identify ANI data. | ||
| /// </summary> | ||
| public static readonly IEnumerable<string> MimeTypes = ["application/x-navi-animation"]; | ||
|
|
||
| /// <summary> | ||
| /// The list of file extensions that identify ANI data. | ||
| /// </summary> | ||
| public static readonly IEnumerable<string> FileExtensions = ["ani"]; | ||
|
|
||
| /// <summary> | ||
| /// Gets the RIFF container identifier. | ||
| /// </summary> | ||
| public static ReadOnlySpan<byte> RiffFourCc => "RIFF"u8; | ||
|
|
||
| /// <summary> | ||
| /// Gets the ANI RIFF form type. | ||
| /// </summary> | ||
| public static ReadOnlySpan<byte> AniFormTypeFourCc => "ACON"u8; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // Copyright (c) Six Labors. | ||
| // Licensed under the Six Labors Split License. | ||
|
|
||
| using SixLabors.ImageSharp.PixelFormats; | ||
|
|
||
| namespace SixLabors.ImageSharp.Formats.Ani; | ||
|
|
||
| /// <summary> | ||
| /// Decodes Windows animated cursor images. | ||
| /// </summary> | ||
| public sealed class AniDecoder : ImageDecoder | ||
| { | ||
| /// <summary> | ||
| /// Prevents a default instance of the <see cref="AniDecoder"/> class from being created. | ||
| /// </summary> | ||
| private AniDecoder() | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the shared instance. | ||
| /// </summary> | ||
| public static AniDecoder Instance { get; } = new(); | ||
|
|
||
| /// <inheritdoc/> | ||
| protected override Image<TPixel> Decode<TPixel>(DecoderOptions options, Stream stream, CancellationToken cancellationToken) | ||
| { | ||
| Guard.NotNull(options, nameof(options)); | ||
| Guard.NotNull(stream, nameof(stream)); | ||
|
|
||
| using AniDecoderCore decoder = new(options); | ||
| Image<TPixel> image = decoder.Decode<TPixel>(options.Configuration, stream, cancellationToken); | ||
|
|
||
| ScaleToTargetSize(options, image); | ||
|
|
||
| return image; | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| protected override Image Decode(DecoderOptions options, Stream stream, CancellationToken cancellationToken) | ||
| => this.Decode<Rgba32>(options, stream, cancellationToken); | ||
|
|
||
| /// <inheritdoc/> | ||
| protected override ImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) | ||
| { | ||
| Guard.NotNull(options, nameof(options)); | ||
| Guard.NotNull(stream, nameof(stream)); | ||
|
|
||
| using AniDecoderCore decoder = new(options); | ||
| return decoder.Identify(options.Configuration, stream, cancellationToken); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.