Add encoding for animated PNGs#3039
Open
RunDevelopment wants to merge 2 commits into
Open
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #1474.
This PR adds a simple APNG encoder and an example showing how to encode animations using PNG and GIF (see below).
The "encoder" is really just two new functions on
PngEncoder:encode_framesandtry_encode_frames. The names and API were inspired byGifEncoder.The code is relatively simple. I just wired up what the
pngcrate already supports. The code converting our delays to PNG delays is a little more complex though. The basic idea is that If the delay fraction cannot be represented exactly, then saturate the numerator or denominator tou16::MAX. This works but doesn't get the best possible approximation in general. IMO, this function should be a method onDelay(e.g. asto_seconds_ratio_u16), but we can talk about that later.The animation created by the new example looks like this btw:
PNG (58 KB) vs GIF (12 KB) with 50 frames of animation
Hidden by default because I find moving things annoying while reading
Gif looks worse because 1-bit alpha. This is also the reason why the PNG is larger. Most of the information of the animation is in the alpha channel.