image-rs / image-tiff

TIFF decoding and encoding library in pure Rust
MIT License
121 stars 79 forks source link

CCITT Group 4 / T.6 "fax machine" compression handling example #211

Open hotspoons opened 1 year ago

hotspoons commented 1 year ago

The maintainer of the fax crate was gracious enough to help me get CCITT group 4/T.6 compression support working with the tiff crate (see this) and he suggested I offer it as an example here. I'm just taking a guess for how you would want to include an example of this integration, so here it is!

sophie-h commented 1 year ago

This code looks quite clean. Maybe this could just be added as a feature to tiff? That would make the example redundant.

fintelia commented 1 year ago

Yeah, I'd be in favor of adding this as a feature to tiff. This is where we dispatch on which compression to use: https://github.com/image-rs/image-tiff/blob/daa0e3eabf39f7837b470e94454a854fc143f6f0/src/decoder/image.rs#L361-L370

I do think it'll take a bit of effort though. The fax crate seems to sometimes panic if it encounters malformed input and it isn't immediately obvious whether we could handle incremental decompression (which helps both for perf and to avoid OOMs from specially crafted inputs)