image-rs / image-png

PNG decoding and encoding library in pure Rust
https://docs.rs/png
Apache License 2.0
357 stars 140 forks source link

Drastically improve encoding performance #364

Closed fintelia closed 1 year ago

fintelia commented 1 year ago

The goal of this PR is to achieve faster-than-QOI encoding performance. It adds a custom zlib implementation that leverages assumptions about the patterns in PNG data to get reasonable compression ratios at phenomenal speeds. Takes inspiration from fpng and fpnge.

Builds on #363 and improves performance by several times...

Directory                                     Ratio             Encode                    Decode
---------                                    -------     --------------------      --------------------
Total                                        28.282%     294 mps   0.99 GiB/s       53 mps   0.18 GiB/s

qoibench on the same machine...

# Grand total for qoi_benchmark_suite/images/
        decode ms   encode ms   decode mpps   encode mpps   size kb    rate
libpng:       5.3        69.6         87.49          6.67       398   24.2%
stbi:         4.6        39.7        100.63         11.70       561   34.2%
qoi:          1.5         2.0        308.68        227.88       463   28.2%
Shnatsel commented 1 year ago

https://github.com/image-rs/image-png/pull/370 should come in handy for testing this.

fintelia commented 1 year ago

The core compression logic has also been fuzzed directly here.