shssoichiro / oxipng

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

Enhance processing of 'dirty alpha' #597

Closed ace-dent closed 8 months ago

ace-dent commented 8 months ago

Using oxipng with -a to alter RGB values for fully transparent pixels, may not always yield optimal results. See attached examples.

Original (52,385 bytes): logo

Processed with oxipng (50,264 bytes) ... and alpha stripped to reveal underlying RGB : logo-oxipng logo-oxipng-opaque

Processed with FileOptimizer (49,762 bytes) ... and alpha stripped to reveal underlying RGB : logo-FileOptimizer logo-FileOptimizer-opaque

Is there scope in the current process to evaluate simpler 'dirty alpha' fills?

andrews05 commented 8 months ago

Could you post the options you're using? I'm getting 50,334 with -saZo6.

ace-dent commented 8 months ago

@andrews05 - it has gone through some other software. However, the issue of low -vs- high complexity alpha fill should be repeatable.

andrews05 commented 8 months ago

I tried putting with low complexity one through oxipng with -sZo6 --force (no alpha) and it came out at 50,333, only 1 byte difference. So I'm not sure the alpha is really a factor in the size difference you're seeing above - it may simply come down to better compression or filtering.

ace-dent commented 8 months ago

Thanks @andrews05 for testing and comments. I'm new(ish) to this area of optimization... but more from intuition, the oxipng image seems to introduce higher entropy... I will be testing more in future. :-) Feel free to Close in the meantime.

andrews05 commented 8 months ago

from intuition, the oxipng image seems to introduce higher entropy

It sure does appear that way. However, appearances can be deceiving 😉 The alpha optimisation works by setting all the underlying values to 0 (more or less). As the filter changes for each line it makes for an interesting appearance when the image is decoded.