Open raymondben opened 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.
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 ...
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
write_png(data, ...)
wheredata
is a 3d array), one colour can be designated as transparent by providing its RGB value.data
is a matrix andpal
has been provided) the PNG spec allows for the firstn
colours in the palette to be made fully transparent. Typically this would be just one colour.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
ormagick::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!)