oxipng icon indicating copy to clipboard operation
oxipng copied to clipboard

Implement lossy optimization methods from TruePNG

Open shssoichiro opened this issue 8 years ago • 8 comments

https://css-ig.net/articles/truepng.php

Lossy averaging filter TruePNG significantly reduces PNG size by doing a lossy averaging filter, that consists to modify data for a specific filter. this method works well with the average filter, so perhaps you could try to use with it. it gives nice speed - size ratio, specially for truecolor images.

it is good for images that can not be converted to palette mode because of quality loss. at this time, this feature is still experimental and a better implementation is on the way: combination of image transformation and lossy filter can be used to get an even smaller result.

Color quantization the color quantization consists to reduce the number of colors in an image. you should consider to use the lossy averaging filter instead specially with big images, because color quantization can be very slow on some samples. Also, it should give a lower quality - size ratio. the -cq switch active the quantization, and user have to specify a value for c= which represents the approximative amount of colors there will be in the image. if you use a value below 257, the PNG could be converted to paletted mode.

  • [ ] Implement lossy averaging filter
  • [ ] Implement color quantization

shssoichiro avatar Jul 21 '17 12:07 shssoichiro

See also pngquant https://pngquant.org/, compare algorithms for quality and compression

shssoichiro avatar Jan 02 '19 14:01 shssoichiro

Of interest: https://richg42.blogspot.com/2022/01/lagrangian-rdo-png.html

andrews05 avatar Dec 12 '23 19:12 andrews05

Of interest: https://richg42.blogspot.com/2022/01/lagrangian-rdo-png.html

@andrews05 Forgive me for not following this @ all (that math is way beyond me), but could you clarify whether this is lossy?

TPS avatar Dec 13 '23 01:12 TPS

I don't understand exactly how it works myself, but yes it is lossy. RDO stands for Rate Distortion Optimisation.

andrews05 avatar Dec 13 '23 02:12 andrews05

I think lossy optimizations could belong to OxiPNG, but projects like e.g. pngquant are already pretty good at implementing color quantization in PNGs, and it would probably be more efficient to contribute to them, or make them easier to use in conjunction with OxiPNG, rather than reinventing what they do.

RDO is a very interesting technique I've never heard of before, and indeed that blog post is right that it has been neglected in the PNG scene, thanks for sharing! I have my doubts over what established PNG optimizer could implement it, though: pngquant, as the name suggests, focuses on color quantization, while other optimizers focus on lossless optimizations, and as far as I know there is no PNG optimizer that is lossy but not limited to color quantization (very late edit: other than TruePNG's with its experimental lossy averaging pass, it seems).

Given this apparent focus on the lossy optimizers with color quantization, it can be wise for OxiPNG to offer something new and implement RDO, but in my opinion this is a pretty major decision that we probably should consult Josh on!

AlexTMjugador avatar Dec 13 '23 09:12 AlexTMjugador