| 1 | # fdeflate |
| 2 | |
| 3 | [](https://crates.io/crates/fdeflate) |
| 4 | [](https://docs.rs/fdeflate) |
| 5 | [](https://github.com/image-rs/fdeflate/actions) |
| 6 | |
| 7 | A fast and safe deflate implementation for PNG. |
| 8 | |
| 9 | This crate contains an optimized implementation of the [deflate algorithm](https://en.wikipedia.org/wiki/Deflate) tuned for PNG images. |
| 10 | |
| 11 | At least on PNG data, our decoder rivals the performance of `zlib-ng` and `zlib-rs` without using any `unsafe` code. |
| 12 | |
| 13 | When compressing it makes a bunch of simplifying assumptions that |
| 14 | drastically improve encoding speed while still being compatible with zlib: |
| 15 | |
| 16 | - Exactly one block per deflate stream. |
| 17 | - No distance codes except for run length encoding of zeros. |
| 18 | - A single fixed huffman tree trained on a large corpus of PNG images. |
| 19 | - All huffman codes are <= 12 bits. |
| 20 | |
| 21 | ### Inspiration |
| 22 | |
| 23 | The algorithms in this crate take inspiration from multiple sources: |
| 24 | * [fpnge](https://github.com/veluca93/fpnge) |
| 25 | * [zune-inflate](https://github.com/etemesi254/zune-image/tree/main/zune-inflate) |
| 26 | * [RealTime Data Compression blog](https://fastcompression.blogspot.com/2015/10/huffman-revisited-part-4-multi-bytes.html) |