-
-
Notifications
You must be signed in to change notification settings - Fork 885
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
Open
Poker-sang
wants to merge
18
commits into
SixLabors:main
Choose a base branch
from
zxbmmmmmmmmm:feat/ani
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add ANI decoder support #2899
Changes from 8 commits
Commits
Show all changes
18 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Six Labors Split License. | ||
|
||
namespace SixLabors.ImageSharp.Formats.Ani; | ||
|
||
internal enum AniChunkType : uint | ||
{ | ||
/// <summary> | ||
/// "anih" | ||
/// </summary> | ||
AniH = 0x68_69_6E_61, | ||
|
||
/// <summary> | ||
/// "seq " | ||
/// </summary> | ||
Seq = 0x20_71_65_73, | ||
|
||
/// <summary> | ||
/// "rate" | ||
/// </summary> | ||
Rate = 0x65_74_61_72, | ||
|
||
/// <summary> | ||
/// "LIST" | ||
/// </summary> | ||
List = 0x54_53_49_4C | ||
} | ||
|
||
/// <summary> | ||
/// ListType | ||
/// </summary> | ||
internal enum AniListType : uint | ||
{ | ||
/// <summary> | ||
/// "INFO" (ListType) | ||
/// </summary> | ||
Info = 0x4F_46_4E_49, | ||
|
||
/// <summary> | ||
/// "fram" | ||
/// </summary> | ||
Fram = 0x6D_61_72_66 | ||
} | ||
|
||
/// <summary> | ||
/// in "INFO" | ||
/// </summary> | ||
internal enum AniListInfoType : uint | ||
{ | ||
/// <summary> | ||
/// "INAM" | ||
/// </summary> | ||
INam = 0x4D_41_4E_49, | ||
|
||
/// <summary> | ||
/// "IART" | ||
/// </summary> | ||
IArt = 0x54_52_41_49 | ||
} | ||
|
||
/// <summary> | ||
/// in "Fram" | ||
/// </summary> | ||
internal enum AniListFrameType : uint | ||
{ | ||
/// <summary> | ||
/// "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,18 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Six Labors Split License. | ||
|
||
namespace SixLabors.ImageSharp.Formats.Ani; | ||
|
||
/// <summary> | ||
/// Registers the image encoders, decoders and mime type detectors for the Ico format. | ||
/// </summary> | ||
public sealed class AniConfigurationModule : IImageFormatConfigurationModule | ||
{ | ||
/// <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,27 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Six Labors Split License. | ||
|
||
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> | ||
public static readonly IEnumerable<string> MimeTypes = ["application/x-navi-animation"]; | ||
|
||
/// <summary> | ||
/// The list of file extensions that equate to an ani. | ||
/// </summary> | ||
public static readonly IEnumerable<string> FileExtensions = ["ani"]; | ||
|
||
/// <summary> | ||
/// Gets the header bytes identifying an ani. | ||
/// </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,35 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Six Labors Split License. | ||
using SixLabors.ImageSharp.PixelFormats; | ||
|
||
namespace SixLabors.ImageSharp.Formats.Ani; | ||
|
||
internal sealed class AniDecoder : ImageDecoder | ||
{ | ||
private AniDecoder() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Gets the shared instance. | ||
/// </summary> | ||
public static AniDecoder Instance { get; } = new(); | ||
|
||
protected override Image<TPixel> Decode<TPixel>(DecoderOptions options, Stream stream, CancellationToken cancellationToken) | ||
{ | ||
Guard.NotNull(options, nameof(options)); | ||
Guard.NotNull(stream, nameof(stream)); | ||
Image<TPixel> image = new AniDecoderCore(options).Decode<TPixel>(options.Configuration, stream, cancellationToken); | ||
ScaleToTargetSize(options, image); | ||
return image; | ||
} | ||
|
||
protected override Image Decode(DecoderOptions options, Stream stream, CancellationToken cancellationToken) => this.Decode<Rgba32>(options, stream, cancellationToken); | ||
|
||
protected override ImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) | ||
{ | ||
Guard.NotNull(options, nameof(options)); | ||
Guard.NotNull(stream, nameof(stream)); | ||
return new AniDecoderCore(options).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.