Skip to content
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

Improve APNG support #668

Merged
merged 6 commits into from
Jan 25, 2025
Merged

Improve APNG support #668

merged 6 commits into from
Jan 25, 2025

Conversation

andrews05
Copy link
Collaborator

@andrews05 andrews05 commented Jan 14, 2025

Two improvements to APNG support:

  1. fcTL and fdAT chunks are parsed into Frames, allowing us to consolidate multiple fdATs for a frame and re-sequence the chunks. This means we can now recompress all frames, rather than only in the case where there's a single fdAT for the frame.
  2. Following on from this, we can now also re-filter the frames, including alpha optimisation when enabled. We use the same filter that was selected for the IDAT.

Reductions are still disabled.

Results on a set of 32 apngs, optimised with -sao6:

source size
original 20,022,193
master 19,412,724 (3.0% smaller)
with full recompression only 16,494,618 (17.6% smaller)
with refiltering 15,583,118 (22.2% smaller)
apngopt* (default) 13,520,262 (32.5% smaller)
apngopt + oxipng 13,341,852 (33.4% smaller)

(There was a particularly large and poorly compressed file in the set which may be skewing the results a little.)

*Note that apngopt does not guard against writing a larger file than the input. The results here could be slightly smaller if I retained the originals where they were better.

[edit] A second set:

source size
original 165,721,029
master 165,048,775 (0.4% smaller)
with full recompression only 163,422,620 (1.4% smaller)
with refiltering 162,850,831 (1.7% smaller)
apngopt (default) 164,919,387 (0.5% smaller)
apngopt + oxipng 162,474,452 (2.0% smaller)

src/error.rs Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
@ace-dent
Copy link

@andrews05 - exciting to see some effort around APNG. Thanks! 🙏

src/lib.rs Fixed Show fixed Hide fixed
src/lib.rs Fixed Show resolved Hide resolved
Copy link
Collaborator

@AlexTMjugador AlexTMjugador left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I initially thought, this looks great overall! I have just a couple of comments to share 🙂

src/apng.rs Show resolved Hide resolved
src/png/mod.rs Show resolved Hide resolved
@AlexTMjugador AlexTMjugador merged commit 14b8b0e into shssoichiro:master Jan 25, 2025
12 checks passed
@andrews05 andrews05 deleted the frames branch January 25, 2025 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants