Skip to content

Use ZIP (Deflate) instead of LZW for TIFF exports (#238)#453

Merged
marcinz606 merged 1 commit into
marcinz606:mainfrom
RP2:feat/tiff-default-zip
Jul 12, 2026
Merged

Use ZIP (Deflate) instead of LZW for TIFF exports (#238)#453
marcinz606 merged 1 commit into
marcinz606:mainfrom
RP2:feat/tiff-default-zip

Conversation

@RP2

@RP2 RP2 commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #238 -- 16-bit TIFF exports are needlessly large because LZW compression performs poorly on photographic 16-bit data, often barely beating uncompressed.

Root cause

tifffile.imwrite in the export and scan-capture codepaths hardcoded compression="lzw". LZW is a byte-oriented algorithm designed for 8-bit palette images -- it does not exploit horizontal redundancy in 16-bit continuous-tone data, so 16-bit RGB TIFFs compress poorly.

Fix

Replace compression="lzw" with compression="zlib" + predictor=True in all three TIFF-writing call sites. predictor=True enables horizontal differencing (TIFF Predictor 2), which stores pixel-to-pixel deltas instead of absolute values. Combined with Adobe Deflate (ZIP), this yields ~20-35% smaller files for 16-bit photographic content.

Both tifffile and imagecodecs are already project dependencies -- no new imports needed.

Files changed:

  • negpy/services/rendering/image_processor.py -- export TIFF
  • negpy/services/scanning/writer.py -- scan capture RGB + IR sidecar
  • tests/test_export_service.py -- test helper consistency
  • tests/metadata/test_writer.py -- test helper consistency

Verification

  • Existing round-trip tests pass (all 13 tests green)
  • Written TIFFs carry the correct Compression tag (8 = Adobe Deflate) and Predictor tag (2 = horizontal differencing)
  • Lint and type checks clean

…horizontal predictor

tifffile.imwrite calls in the export and scan-capture paths now use
compression='zlib' + predictor=True. Deflate/ZIP typically yields
15-25% smaller files than LZW for 16-bit image data.

Update test helpers to match the new default — no test assertions
depend on the specific codec, so this is a consistency change.

Closes marcinz606#238
@thetalkingdrum

Copy link
Copy Markdown

Yes please. LZW actually made the tiffs larger than plain uncompressed.

@marcinz606 marcinz606 merged commit fb4b7a7 into marcinz606:main Jul 12, 2026
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.

Exported TIFF often ends up significantly larger than the original

3 participants