Skip to content

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

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

Shnatsel wants to merge 14 commits into
image-rs:mainfrom
Shnatsel:tiff-compression

Conversation

@Shnatsel

@Shnatsel Shnatsel commented Feb 25, 2026 •

Copy link
Copy Markdown
Member

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
Copy Markdown
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.

Comment thread src/codecs/tiff.rs Resolved
@Shnatsel

Copy link
Copy Markdown
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

fintelia commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

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

Shnatsel commented Mar 4, 2026

Copy link
Copy Markdown
Member Author

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

@197g

197g commented Mar 4, 2026

Copy link
Copy Markdown
Member

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

Shnatsel commented Mar 5, 2026

Copy link
Copy Markdown
Member Author

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

Shnatsel commented Mar 5, 2026

Copy link
Copy Markdown
Member Author

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

@Shnatsel

Shnatsel commented Mar 6, 2026

Copy link
Copy Markdown
Member Author

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

Shnatsel commented Mar 6, 2026

Copy link
Copy Markdown
Member Author

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

@Shnatsel Shnatsel added this to the 1.0 milestone Apr 9, 2026

This branch has not been deployed

No deployments
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