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

Feature-complete APNG optimization #551

Open
ctrlcctrlv opened this issue Aug 21, 2023 · 15 comments
Open

Feature-complete APNG optimization #551

ctrlcctrlv opened this issue Aug 21, 2023 · 15 comments
Labels
T-Compression Relates to improving the compression ratio of images T-Feature Requests for a new feature to be added

Comments

@ctrlcctrlv
Copy link

[fred@デブ.狸.agency ~/.config/OpenToonz/stuff/sandbox/outputs]$ oxipng pcr.apng 
Processing: pcr.apng
APNG files are not (yet) supported
@ctrlcctrlv ctrlcctrlv changed the title does not support APNG does not support APNG reduction Aug 21, 2023
@ctrlcctrlv
Copy link
Author

renamed in light of #551; now supports APNG but the support is nearly useless :( [thanks for it anywy tho]

@TPS
Copy link

TPS commented Aug 21, 2023

@ctrlcctrlv I think you meant #79#511

@TPS TPS mentioned this issue Aug 21, 2023
@AlexTMjugador
Copy link
Collaborator

AlexTMjugador commented Aug 21, 2023

Groundwork has been done to support APNGs (see #511), but the changes were not yet published in a release, so you have to build OxiPNG from source to use them.

Do those changes satisfy your needs, @ctrlcctrlv? If not, why do you find that support "nearly useless"?

@ctrlcctrlv
Copy link
Author

ctrlcctrlv commented Aug 21, 2023

fdAT is likewise compressible via the same way* IDAT is compressed so no, probably why @andrews05 wrote they were “not sure if it's something that should actually be added” :-)

* sort of.

@TPS
Copy link

TPS commented Aug 21, 2023

@AlexTMjugador Even in #511, @andrews05 says average savings is <1%, so much room for improvement.

I think the idea here is to meet/best apngopt (last commit 2022) in a modern fashion like, for static PNG, the original goal was against optipng.

@AlexTMjugador AlexTMjugador changed the title does not support APNG reduction Feature-complete APNG optimization Aug 21, 2023
@AlexTMjugador
Copy link
Collaborator

Alright, that's fair. I'm renaming this issue to more clearly state what it asks for 😄

@ctrlcctrlv
Copy link
Author

ctrlcctrlv commented Aug 21, 2023

exactly. i started thinking about how to do it as well. in theory—

Subsequent frames are encoded in fdAT chunks, which have the same structure as IDAT chunks, except preceded by a sequence number. Information for each frame about placement and rendering is stored in fcTL chunks. The full layout of fdAT and fcTL chunks is described below.

in order to make a well-supported APNG, it's quite important to alternate fcTL and fdAT, as earlier versions of the spec said no chunk may come between an fcTL and its fdAT.

what i think this means is we can use the same code as does the main loop just with &fdat[4:].

likely PngData::from_slice is the primary function that needs changes

@andrews05 andrews05 added T-Feature Requests for a new feature to be added T-Compression Relates to improving the compression ratio of images labels Aug 22, 2023
@TPS
Copy link

TPS commented Jan 11, 2025

I was reminded that APNG (unofficially, per the spec, but widely supported) can also use LZMA & Brotli compression, so add'l libraries for those would need to be decided on for (optional) inclusion.

@andrews05
Copy link
Collaborator

andrews05 commented Jan 11, 2025

I’ve tried researching this but have not found anything to suggest this is correct. I suspect there may be some confusion arising from programs that offer to use “7zip” for compression, which may lead people to think it’s using lzma but it actually just means it’s using 7zip’s deflate algorithm.

If you have references to the contrary, I’d be happy to hear.

Also note that since brotli is supported in web browsers, you can do things like compressing the png with the new --zc 0 option and then store it on your web server with brotli compression as image.png.br. With appropriate configuration of the web server, this can be served directly to web browsers - the brotli gets decompressed as part of the transport stream and then the png is rendered as normal.

@IlluminatiWave
Copy link

IlluminatiWave commented Jan 12, 2025

In settings it brings zlib, 7z (lzma) and zopfli (and iteration settings)

https://sourceforge.net/projects/apng/files/APNG_Optimizer/1.4/

Ps: the assembler also includes these compression algorithms.

@andrews05
Copy link
Collaborator

Not sure where you're seeing lzma? It just says "7zip compression" in the read me. Again, this just means it is using the 7zip software to perform the deflate compression. All three options are deflate, they're just different implementations.

@TPS
Copy link

TPS commented Jan 14, 2025

Further improvements via #668. Thanks, @andrews05! 🙇🏾‍♂️

@TPS
Copy link

TPS commented Jan 17, 2025

@andrews05 I (&, I'm sure, others) have been watching developments in #668 w/ great delight. I just wanted to ask, in light of the results tables you've given there, how do the resulting test files there & here, so far, compare to running against apngopt? I saw your note about compression ratio increased to 3.94% from <1% on previous versions, & wondered if you're going for a certain ratio, as well as implementing strategies.

@andrews05
Copy link
Collaborator

There are basically four stages to "feature-complete" optimisation and parity with apngopt:

  1. Support reading and writing apng files, allowing recompression of IDAT without corrupting the file. We achieved this in the v9 release.
  2. Support parsing the frame data, allowing recompression of all frames. The new PR does this.
  3. Support reductions.
  4. Additional APNG-specific optimisations such as cropping and de-duplicating frames.

I've added some comparisons with apngopt to the results in #668 which you can check out.

@TPS
Copy link

TPS commented Jan 18, 2025

I've added some comparisons with apngopt to the results in #668 which you can check out.

@andrews05 Thanks much for those add'l results. The further-increased compression of apngopt + oxipng is very encouraging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-Compression Relates to improving the compression ratio of images T-Feature Requests for a new feature to be added
Projects
None yet
Development

No branches or pull requests

5 participants