kornelski / pngquant

Lossy PNG compressor — pngquant command based on libimagequant library
https://pngquant.org
Other
5.09k stars 476 forks source link

Option to preserve color for fully transparent pixels #404

Closed hoontee closed 11 months ago

hoontee commented 1 year ago

In addition to fixing #402 for the purposes of my project, it's necessary to preserve the color for fully transparent pixels. Currently pngquant ignores this data and replaces it with black:

Source image pngquant output image

Hopefully a new CLI argument can be added for this.

kornelski commented 11 months ago

Unfortunately this is not possible. pngquant internally operates in premultiplied alpha color space, so it's incapable of preserving color of fully-transparent pixels (it's a division by zero).

Additionally, even if the code was changed to operate on uncorrelated RGBA, this would severely degrade color quality of visible pixels. This is because the PNG8 mode doesn't have a separate alpha channel, so it would use palette entries for each RGBA combination.