shssoichiro / oxipng

Multithreaded PNG optimizer written in Rust
MIT License
2.94k stars 125 forks source link

Implement lossy optimization methods from TruePNG #76

Open shssoichiro opened 7 years ago

shssoichiro commented 7 years ago

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.

shssoichiro commented 5 years ago

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

andrews05 commented 11 months ago

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

TPS commented 11 months ago

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?

andrews05 commented 11 months ago

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

AlexTMjugador commented 11 months ago

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!