google / zopfli

Zopfli Compression Algorithm is a compression library programmed in C to perform very good, but slow, deflate or zlib compression.
Apache License 2.0
3.42k stars 326 forks source link

APNG(Animated Portable Network Graphics) support #118

Open PeterDaveHello opened 8 years ago

PeterDaveHello commented 8 years ago

zopflipng currently will make APNG be a normal png, which we should prevent to, if APNG can not be supported, maybe add some detections to bypass the compress of APNG can be workaround.

APNG spec: https://wiki.mozilla.org/APNG_Specification

APNG is an extension of the PNG format, adding support for animated images. It is intended to be a replacement for simple animated images that have traditionally used the GIF format, while adding support for 24-bit images and 8-bit transparency. APNG is a simpler alternative to MNG, providing a spec suitable for the most common usage of animated images on the Internet. APNG is backwards-compatible with PNG; any PNG decoder should be able to ignore the APNG-specific chunks and display a single image.

APNG on wikipedia:

https://en.wikipedia.org/wiki/APNG

(PNG) specification. It allows for animated PNG files that work similarly to animated GIF files, while supporting 24-bit images and 8-bit transparency not available for GIFs. It also retains backward compatibility with non-animated PNG files. The first frame of an APNG file is stored as a normal PNG stream, so most standard PNG decoders are able to display the first frame of an APNG file. The frame speed data and extra animation frames are stored in extra chunks (as provided for by the original PNG specification).

APNG demo: https://people.mozilla.org/~dolske/apng/demo.html

Note that APNG is not supported in most of the browsers: http://caniuse.com/#feat=apng

CounterPillow commented 8 years ago

zopflipng currently will make APNG be a normal png

Side note: This is a side-effect of Mozilla overloading the PNG mimetype with APNG, and one of the reasons why the libpng folks explicitly told them not to do this. They did it anyway.

ericlaw1979 commented 8 years ago

There are two aspects of fixing this: First, minimally keep the required chunks (this can be worked around by end-users today using the proper command line). Second, enhance the tool to apply Zopfli compression to the additional image data stored in those chunks.

JayXon commented 8 years ago

Actually, it's a little more complicated than that, if the apng is using palette, ZopfliPNG will remove "unused" color if it's not used in the first frame. This will probably need some support for apng from lodepng.