Skip to content

Add TiffEncoder::set_compression() to allow controlling compression mode#2785

Draft
Shnatsel wants to merge 14 commits intoimage-rs:mainfrom
Shnatsel:tiff-compression
Draft

Add TiffEncoder::set_compression() to allow controlling compression mode#2785
Shnatsel wants to merge 14 commits intoimage-rs:mainfrom
Shnatsel:tiff-compression

Conversation

@Shnatsel
Copy link
Member

@Shnatsel Shnatsel commented Feb 25, 2026

Allow controlling TIFF compression algorithm and predictor in TiffEncoder.

This PR also changes the default from uncompressed to balanced DEFLATE with a horizontal predictor. This is as a more sensible default, and matches imagemagick.

TiffEncoder::set_compression() diverges from the crate's apparent convention of new_with_quality, because I think it's rather silly to call this quality when it's a lossless format. I can change this if you prefer.

I've manually tested the default compression method with wondermagick (which is what I need this for) but I haven't verified the more obscure options like PackBits produce correct results.

…ode. Change the default from uncompressed to balanced DEFLATE with a horizontal predictor, as a more sensible default that matches imagemagick
@RunDevelopment
Copy link
Member

Related: #2251

TiffEncoder::set_compression() diverges from the crate's apparent convention of new_with_quality

Given the way decoders are currently moving towards setters instead of constructor args, I would expect that encoders will move towards setters too. So you're likely just ahead of the trend.

@Shnatsel
Copy link
Member Author

Float compression was implemented in the tiff crate in image-rs/image-tiff#342 but I don't think that should block this PR.

@fintelia
Copy link
Contributor

fintelia commented Mar 4, 2026

I'm now wondering if it would it make sense to land support for deflate levels 1-9 in the tiff crate first, and then just have a single Deflate(u8) variant?

@Shnatsel
Copy link
Member Author

Shnatsel commented Mar 4, 2026

I think it would, but it's an API break for the tiff crate.

@197g
Copy link
Member

197g commented Mar 4, 2026

I'm very much okay with that. There's a bunch of API to clean up there anyways (all the direct tag reads on Decoder). Maybe we could fit some more writer cleanup in; if you have found some more after the immediate pain points resolved recently?

@Shnatsel
Copy link
Member Author

Shnatsel commented Mar 5, 2026

Turns out we can expose precise DEFLATE compression level from tiff crate without an API break: image-rs/image-tiff#348

I'll update this PR once the tiff crate PR is merged.

@Shnatsel
Copy link
Member Author

Shnatsel commented Mar 5, 2026

Ah, sorry, that wasn't sufficient after all. I've opened image-rs/image-tiff#351 for a semver-breaking change instead.

@Shnatsel
Copy link
Member Author

Shnatsel commented Mar 6, 2026

Marking as draft pending upstream work in tiff crate, notably image-rs/image-tiff#357

@Shnatsel Shnatsel marked this pull request as draft March 6, 2026 15:57
@Shnatsel
Copy link
Member Author

Shnatsel commented Mar 6, 2026

This is now done, but I'm keeping it as a draft until the tiff crate with the necessary changes is released to crates.io

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants