coolbutuseless / foist

Fast Output of Images
MIT License
17 stars 1 forks source link

Support png transparency #2

Open raymondben opened 10 months ago

raymondben commented 10 months ago

Adds support for "cheap alpha" transparency in PNGs - i.e. one or more colours can be designated as fully transparent: http://www.libpng.org/pub/png/book/chapter08.html#png.ch08.div.5.2

It only adds a few tens of bytes per file, and my brief testing showed no significant performance hit. I did not include any formal unit testing because I could not get writePNG or magick::write_image to produce a PNG with this type of transparency (magick does full RGBA by default, couldn't figure out how to coerce it to produce png8).

(My C++ skills are not what you'd call polished, feel free to change the implementation!)

coolbutuseless commented 10 months ago

Thanks for the PR! This looks interesting!

I am in the process of a larger refactor (on a private branch) and will re-visit this PR when its done.

raymondben commented 9 months ago

If you are rewriting, it is perhaps worth considering supporting color type 6 (RGBA) pngs. I have not tried but don't think it's a massive stretch on type 4 RGBs (each pixel just has an additional alpha byte?). Happy to help if you like ...