Commit Graph
812 Commits
Author SHA1 Message Date
Lilith River 488da716d7 ci: expand platform coverage, enforce clippy warnings, add MSRV check
- Upgrade actions/checkout from v2/v4 to v6
- Add test-platforms job: ubuntu, ubuntu-arm, macos-arm, macos-intel, windows, windows-arm
- Add MSRV job using cargo-hack check --rust-version
- Replace baptiste0928/cargo-install with taiki-e/install-action@cross for cross-compilation
- Remove unnecessary Docker start step (cross handles container lifecycle)
- Enable clippy -D warnings with --all-targets (was disabled with TODO)
2026-03-23 18:55:24 -06:00
Aurelia Molzer ba7a290ff7 Merge pull request #363 from lilith/feat/non-standard-bit-depths
Support non-standard bit depths (sub-byte and extended) with WhiteIsZero fixes
2026-03-12 02:03:49 +00:00
Lilith River 85215e81e3 Revert "feat: add YCbCr chroma subsampling support for non-JPEG compression"
This reverts commit 83409cbdf3.
2026-03-11 00:39:37 -06:00
Lilith River 617dc6eed8 fix: 32-bit platform failures in chunk_col_stride and LogLuv hash
Fix two CI failures on i686 and powerpc:

1. chunk_col_stride overflow: RowsPerStrip = u32::MAX causes
   data_row_bytes * chunk_height to exceed 32-bit usize. Clamp
   the chunk height to the image height before computing stride
   values, since a chunk never contributes more rows than the
   image contains. Applied to both readout_for_size() and
   set_row_stride().

2. off_luv32.tif hash mismatch: the LogLuv decoder produces
   platform-dependent output (different hashes on x86_64, i686,
   and powerpc), so demote to smoke test.
2026-03-11 00:27:06 -06:00
Lilith River 83409cbdf3 feat: add YCbCr chroma subsampling support for non-JPEG compression
Add YCbCrUpsamplingReader that converts chroma-subsampled YCbCr block
data to full-resolution 3-bytes-per-pixel output. Each block of h×v
pixels stores h*v Y samples plus one shared Cb and Cr sample; the
reader expands these into per-pixel (Y, Cb, Cr) triples.

This enables decoding YCbCr TIFFs with any supported compression
method (uncompressed, LZW, Deflate, etc.), not just JPEG. Two more
libtiffpic test images now decode with verified hashes:
- dscf0013.tif (uncompressed YCbCr 2,1 subsampling)
- ycbcr-cat.tif (LZW-compressed YCbCr 2,2 subsampling)

The remaining two YCbCr test images (smallliz.tif, zackthecat.tif)
use Old JPEG compression (type 6) which is a separate unsupported
feature.
2026-03-10 22:46:59 -06:00
Lilith River 26301fc3f1 feat: add CCITT Group 3 (Fax3) compression and FillOrder support
Add Group3Reader for decoding CCITT Group 3 (T.4) 1D compressed TIFF
images. The fax crate's Group3Decoder has a bug where new() verifies
but doesn't consume the initial EOL marker, causing its lookup tables
to destructively consume bits from the EOL code. We work around this
by using the crate's lower-level white::decode / black::decode
functions and handling EOL markers ourselves.

Also adds FillOrder tag (266) support: FillOrder=2 (LSB-to-MSB,
common in fax images) is handled by reversing bits in each byte
before decoding. This applies to both Group 3 and Group 4 readers.

Both libtiffpic fax test images (fax2d.tif, g3test.tif) now decode
correctly with verified CRC32 hashes.
2026-03-10 22:41:03 -06:00
Lilith River 83dbb750df test: add CRC32 hash verification for all libtiffpic images
Upgrade the libtiffpic test harness from decode-only smoke tests to
full output verification using CRC32 reference hashes. 50 of 61 images
now have hash-verified decoded output; the remaining 11 use unsupported
formats (YCbCr subsampling, Fax3, etc.) and remain as decode-only tests.

Uses read_image_to_buffer (the non-deprecated API) with ByteOrder::convert
for cross-platform LE normalization.

Remove the 13 individual depth tests from decode_images.rs — they tested
the same libtiffpic flower images that are now hash-verified here.
2026-03-10 17:33:12 -06:00
Lilith River 2d6d92e81d refactor: simplify hash computation and remove unused benchmark
Address PR review feedback:

- Remove benches/decode.rs which referenced non-existent gen_bench_tiff.c
- Simplify compute_tiff_hash: replace 66-line match block with
  as_buffer().as_bytes() + ByteOrder::convert for LE normalization
- Use TIFF Type repr(u16) as hash discriminant instead of ad-hoc u8
- Rename all 74 seq test images to match updated hashes
2026-03-10 14:43:07 -06:00
Lilith River 3434d0220b perf: const-generic bit unpacking with wide u64 reads
Specialize extract_bits_msb and unpack_bits via const generics so the
compiler knows BPS at compile time. Replace the byte-by-byte accumulation
loop with a single u64::from_be_bytes read + shift + mask.

Benchmarks (1024x1024 gray, uncompressed):
  10-bit: 1.32ms → 886µs  (1.49x faster)
  12-bit: 1.34ms → 871µs  (1.54x faster)
  14-bit: 1.49ms → 963µs  (1.55x faster)
  24-bit: 1.84ms → 776µs  (2.37x faster)
2026-03-10 08:08:09 -06:00
Lilith River fcdb86ca7f bench: add decode benchmark for extended bit depths
Measures decode throughput for 1024x1024 gray images at various bit
depths (3-24 bit). Requires pre-generated images in /tmp/bench-tiff/
(see stderr instructions for generation).
2026-03-10 08:02:46 -06:00
Lilith River 6fb99107cd fix: cargo fmt 2026-03-10 06:44:58 -06:00
Lilith River 19dcd09e09 fix: panic on unknown ColorType in hash, fix rfind in hash helper
- compute_tiff_hash now panics on unhandled ColorType variants instead
  of silently using a fallback discriminant
- print_seq_hashes correctly identifies existing 8-char hex hash suffix
  vs non-hash filename segments
2026-03-10 06:02:19 -06:00
Lilith River 43cfc5bc3a test: self-verifying seq images with CRC32 hash in filenames
Move 74 seq-*.tiff test images to tests/images/seq/ and embed a CRC32
hash of the full decoded output (dimensions, color type, sample data)
as the last filename segment. Replace 75 individual test functions with
one generic verify_all_seq_images test that decodes each file and
validates its hash against the filename.

This catches byte-order, bit-alignment, stride, padding, and value
errors that sum-based tests would miss (e.g., swapped pixels preserve
the sum but change the hash). Adding new test images only requires
dropping a correctly-named file in seq/ — no test code changes needed.
2026-03-10 06:02:19 -06:00
Lilith River c3977c4513 test: expand test suite to 74 images with libtiff reference decoder
Add 19 new libtiff-generated test images and a reference decoder
(verify_seq_tiff.c) that independently verifies all checksums using
libtiff's own read path, giving three-way agreement:
  libtiff writer → libtiff reader → image-tiff reader

New coverage:
- Standard sub-byte: 1-bit, 2-bit, 4-bit grayscale (BIZ + WIZ)
- Multi-strip: RowsPerStrip=4 (gray 8/16, RGB 8)
- Tiled + compressed: LZW and Deflate tiles
- Float predictor: f32/f64 + Deflate + predictor=3
- Unassociated alpha: RGBA 8-bit with EXTRASAMPLE_UNASSALPHA
- Sub-byte RGB: 5-bit and 7-bit contiguous
- Signed RGB: i8 and i16 (3-channel, decoded as Multiband)
- Float f64 RGB
- Tiled BigTIFF

verify_seq_tiff.c: reads each TIFF with libtiff, computes matching
checksums (handling packed sub-byte, unpacked extended, float, signed),
and verifies 68/68 cases pass.

Total: 74 test images (66.8 KB), 317 tests all passing.
2026-03-10 06:02:19 -06:00
Lilith River a4cbf7bbaf test: add 28 format-variant test images covering compression, tiled, BigTIFF, float, signed, CMYK, palette, RGBA, multi-page, and big-endian
Expand gen_seq_tiff.c with writers for standard-depth formats that exercise
different decoder code paths. All 55 seq-* images are 16x16, libtiff-generated,
and cross-validated against tifffile.

New coverage:
- Compression: LZW, Deflate, PackBits (gray 8/16-bit, RGB 8-bit)
- LZW + horizontal predictor (8-bit gray)
- Tiled layout: gray 8/16-bit, RGB 8-bit (16x16 tiles)
- BigTIFF: gray 8-bit, RGB 16-bit
- Float: gray f32/f64, RGB f32
- Signed integer: i8, i16, i32
- CMYK: 8-bit, 16-bit
- Palette/indexed: 4-bit, 8-bit (with known colormap)
- RGBA with associated alpha: 8-bit, 16-bit
- Multi-page: 3-page gray 8-bit (all pages verified)
- Big-endian byte order: gray 8/16-bit, RGB 8-bit

Total: 298 tests, all passing.
2026-03-10 06:02:19 -06:00
Lilith River 26c32431fa test: regenerate seq-* test images using libtiff C API
Replace Python-generated test TIFFs with libtiff-generated ones to
eliminate circular validation. The C program (gen_seq_tiff.c) uses
libtiff's TIFFWriteScanline with MSB-first packed bit streams.

Cross-validated: tifffile independently confirms all 27 images match
the original Python-generated versions byte-for-byte. tiffinfo validates
all IFD structures. All 27 image-tiff decode tests pass unchanged.
2026-03-10 06:02:19 -06:00
Lilith River 5090003bda test: add 27 sequential-value test images for bit-error detection
Generated by gen_seq_images.py using manual TIFF writer with packed
bit streams matching TIFF spec. Each 16x16 image has cycling 0..max
values so any bit-level decode error changes the checksum.

Test matrix:
- Sub-byte BlackIsZero: 3/5/7-bit
- Sub-byte WhiteIsZero: 3/5/6/7-bit
- Extended BlackIsZero: 10/12/14/24-bit
- Extended WhiteIsZero: 10/12/14/24-bit
- Extended HPredict: 10/12/14/24-bit
- RGB contiguous: 10/12/14/24-bit
- RGB planar: 10/12/14/24-bit (first plane only via read_image)
2026-03-10 06:02:19 -06:00
Lilith River fb1afc81e9 fix: handle WhiteIsZero for non-standard sub-byte depths (3/5/6/7-bit)
For sub-byte depths where samples cross byte boundaries (3, 5, 6, 7-bit),
byte-wise NOT corrupts samples. Added per-sample inversion that extracts
each N-bit sample from the packed stream, computes (max - value), and
writes it back.

Tests cover:
- 3/5/7-bit BlackIsZero (verify basic decoding)
- 3-bit and 6-bit WhiteIsZero (verify per-sample inversion)
2026-03-10 06:02:19 -06:00
Lilith River 29e43d2314 fix: handle WhiteIsZero for extended bit depths, add comprehensive tests
Fix invert_colors to support extended bit depths (9-15 promoted to u16,
17-31 promoted to u32). Byte-wise NOT doesn't work for promoted samples
because it flips unused upper bits; use (max - value) instead.

Add regression tests covering the extended depth matrix:
- Gray 10/14/24-bit (contiguous, BlackIsZero)
- RGB 10/14/24-bit (contiguous)
- RGB 10/12/14/24-bit (planar)
- Gray 12-bit with WhiteIsZero (synthetic 4x2 image)
- Gray 12-bit with horizontal predictor (synthetic 4x2 image)
2026-03-10 06:02:19 -06:00
Lilith River 4ff374990e feat: accept sub-byte bit depths for all color types
Previously, sub-byte bit depths (1-7 bits per sample) were only
accepted for Gray and Multiband color types. This extends the
validation to accept all color types (RGB, RGBA, CMYK, CMYKA, YCbCr)
at sub-byte depths.

The data format is unchanged: sub-byte samples remain packed MSB-first
in the output buffer, exactly as for grayscale. Predictors are still
rejected for sub-byte data.

Tested via libtiffpic flower-rgb-contig-02/04 and flower-rgb-planar-02/04.
2026-03-10 06:02:19 -06:00
Lilith River 3d3c16e26f feat: support packed extended bit depths (9-15, 17-31 bits per sample)
TIFF files can store samples at non-standard bit depths (e.g. 10, 12,
14, 24 bits) packed tightly in a continuous bit stream. Previously
these were rejected as unsupported color types.

This adds:
- MSB-first bit extraction from packed byte streams (unpack_bits,
  extract_bits_msb) to expand N-bit samples to standard-width output
  (9-16 bit → u16, 17-32 bit → u32)
- Output buffer sizing using the promoted sample width instead of the
  packed bit depth (output_bits_per_sample field in ReadoutLayout)
- A new code path in expand_chunk that reads packed rows, unpacks to
  standard-width samples, then applies predictor and color inversion
- Horizontal predictor support for extended depths

Tested with 12-bit grayscale and RGB images (existing test suite),
plus all libtiffpic depth test images (10/12/14/24-bit in gray, RGB
contig, and RGB planar configurations).
2026-03-10 06:01:48 -06:00
Aurelia Molzer 8a5c2da511 Merge pull request #361 from lilith/feat/palette-support
Support palette (ColorMap) image decoding
2026-03-10 04:15:52 +00:00
Lilith River 3b11e2f577 feat: support palette (ColorMap) image decoding
Read the ColorMap tag (320) for RGBPalette images and return raw
palette indices as the decoded data with ColorType::Palette(n).

Changes:
- Read and validate ColorMap tag during IFD parsing (3 * 2^bps entries)
- Return ColorType::Palette from colortype() for RGBPalette images
- Accept Palette in expand_chunk validation (standard + sub-byte depths)
- Expose color_map() method on Decoder for palette lookup
- Add tests for 1-bit, 4-bit, 8-bit palette images with checksums
- Add test verifying ColorMap accessibility and structure

The decoder returns raw palette indices; consumers apply the lookup
using the color map returned by Decoder::color_map().
2026-03-09 21:03:30 -06:00
Aurelia Molzer c6f6ff4c95 Merge pull request #359 from image-rs/tile-offset-compatibility
Tile offset compatibility
2026-03-08 02:29:15 +00:00
A. Molzer d7d24d0f7c Changelog entry for tile treatment 2026-03-08 03:00:15 +01:00
A. Molzer 58e93fb8a3 Align tile detection to libtiff 2026-03-08 03:00:15 +01:00
Aurelia Molzer 595e67e5fb Merge pull request #358 from image-rs/open-behavior-documentation
Document `Decoder::open` behavior
2026-03-06 20:15:29 +00:00
A. Molzer 812bc970ba Document Decoder::open behavior 2026-03-06 21:09:32 +01:00
Aurelia Molzer 82b646298d Merge pull request #356 from Shnatsel/better-docs
Improve documentation on compression and predictor
2026-03-06 19:12:56 +00:00
Sergey "Shnatsel" Davidoff 22ff2b5c50 Merge pull request #355 from Shnatsel/drop-exact-level
Drop obsolete Deflate::exact_level()
2026-03-06 18:49:06 +00:00
Sergey "Shnatsel" Davidoff 3a6492f251 More docs on the predictor 2026-03-06 15:46:37 +00:00
Sergey "Shnatsel" Davidoff a03eeccfe5 Document Compression enum variants 2026-03-06 14:47:44 +00:00
Sergey "Shnatsel" Davidoff 287fcb9309 Drop obsolete Deflate::exact_level() 2026-03-06 14:40:37 +00:00
Sergey "Shnatsel" Davidoff ba97bad411 Merge branch 'main' into better-docs 2026-03-06 14:39:37 +00:00
Aurelia Molzer c4ab46ad2c Merge pull request #354 from Shnatsel/derive-debug
Derive useful traits on public types
2026-03-06 11:45:45 +00:00
Sergey "Shnatsel" Davidoff eaf9cc1d6c Merge branch 'main' into better-docs 2026-03-06 11:02:09 +00:00
Sergey "Shnatsel" Davidoff 34191fa9ca Merge branch 'main' into derive-debug 2026-03-06 10:55:44 +00:00
Sergey "Shnatsel" Davidoff b0bd33dbe4 Remove equality from rational types; can be implemented later via cross-multiplication 2026-03-06 10:54:37 +00:00
Sergey "Shnatsel" Davidoff 2ca2427c75 cargo fmt 2026-03-06 10:51:23 +00:00
Aurelia Molzer e8be8656f2 Merge pull request #353 from Shnatsel/non-exhaustive-compression
Make Compression enum non-exhaustive
2026-03-06 10:45:28 +00:00
Sergey "Shnatsel" Davidoff ea949032a2 cargo clippy --fix 2026-03-06 10:43:54 +00:00
Sergey "Shnatsel" Davidoff 87007d85a0 Derive Debug on Compression enum 2026-03-06 10:41:20 +00:00
Sergey "Shnatsel" Davidoff 2119bff354 More derives on TIFF value structs 2026-03-06 10:36:12 +00:00
Sergey "Shnatsel" Davidoff c62a69ec9d Expand predictor docs 2026-03-06 10:07:06 +00:00
Sergey "Shnatsel" Davidoff 79a791b49a Clarify predictor docs 2026-03-06 10:02:24 +00:00
Sergey "Shnatsel" Davidoff e1e9f36c5a Make Compression enum non-exhaustive 2026-03-06 09:49:10 +00:00
Aurelia Molzer 0ad653433a Merge pull request #352 from image-rs/iterate-over-raw-tiff-or-exif
Open a Tiff without interpreting the first directory
2026-03-06 08:34:19 +00:00
A. Molzer bf79af8de4 Add Decoder::open, deprecate new 2026-03-06 09:31:23 +01:00
Aurelia Molzer 54dddc4943 Merge pull request #347 from image-rs/iterate-over-raw-tiff-or-exif
Enable iteration over raw, malformed tiff or exif
2026-03-06 07:31:13 +00:00
A. Molzer be9b3a04b9 Expand documentation with TiffHeader 2026-03-06 06:05:32 +01:00