fix: default SamplesPerPixel to 1 when tag is absent#319
Open
TomNicholas wants to merge 1 commit into
Open
Conversation
The TIFF 6.0 specification defines SamplesPerPixel (tag 277) with a default value of 1. Some single-channel grayscale TIFFs omit the tag entirely (e.g. PerkinElmer/Phenix microscopy images in the Cell Painting Gallery). Previously IFD parsing panicked with 'samples_per_pixel not found' on such files; now it falls back to the spec default of 1.
TomNicholas
force-pushed
the
fix/samples-per-pixel-default
branch
from
July 18, 2026 23:58
54a9195 to
747c08c
Compare
kylebarron
reviewed
Jul 20, 2026
| defines with a default of 1. It is a regression fixture for parsing files that | ||
| omit the tag (e.g. PerkinElmer/Phenix microscopy images), which previously | ||
| panicked with "samples_per_pixel not found". It was generated by hand-writing | ||
| the TIFF header, IFD and pixel bytes with Python's `struct` module. |
Member
There was a problem hiding this comment.
Could we:
- Put this image fixture in https://github.com/developmentseed/geotiff-test-data instead of here
- Make the image creation reproducible. You say you hand-edited the TIFF header, and it would be nice to have a record on how that was done. You can see in the existing
rasterio_generateddirectory how there's a Python script that creates the file.
Comment on lines
+375
to
+377
| // SamplesPerPixel (tag 277) defaults to 1 when the tag is absent. | ||
| // TIFF 6.0 spec, "SamplesPerPixel ... Default = 1": https://download.osgeo.org/libtiff/doc/TIFF6.pdf | ||
| // Many single-channel grayscale TIFFs (e.g. PerkinElmer/Phenix microscopy) omit it. |
Member
There was a problem hiding this comment.
This is verbose; just say
Suggested change
| // SamplesPerPixel (tag 277) defaults to 1 when the tag is absent. | |
| // TIFF 6.0 spec, "SamplesPerPixel ... Default = 1": https://download.osgeo.org/libtiff/doc/TIFF6.pdf | |
| // Many single-channel grayscale TIFFs (e.g. PerkinElmer/Phenix microscopy) omit it. | |
| // Samples per pixel defaults to 1 | |
| // https://web.archive.org/web/20240329145232/https://www.awaresystems.be/imaging/tiff/tifftags/samplesperpixel.html |
Author
|
Sorry yes I can make those changes. For context @ianhi and others are very interested in using VirtualiZarr on a bunch of bioscience data, lots of which is in weird TIFF variants. So this is not GeoTIFF data, and expect to see lots more edges case like this found soon. (I assume that is still within scope for this project?) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #318.
Problem
Parsing a TIFF that omits the
SamplesPerPixeltag (277) panicked withsamples_per_pixel not found, rather than applying the TIFF 6.0 spec default of 1. Single-channel grayscale TIFFs commonly omit the tag — e.g. the PerkinElmer/Phenix microscopy images in the Cell Painting Gallery. Viavirtual_tiff/pyo3-async-runtimesthe.expect()surfaces as an uncatchable Rust panic on the tokio worker.Change
src/ifd.rs: defaultSamplesPerPixelto 1 when the tag is absent, per the spec:The
PlanarConfigurationlogic immediately below already handlessamples_per_pixel == 1, so this is self-contained.Test
Adds
fixtures/other/grayscale_no_samplesperpixel.tif— a hand-built 114-byte 2x2 uint8 grayscale TIFF that omits tag 277 — and a regression test asserting it parses withsamples_per_pixel() == 1. The test panics withsamples_per_pixel not foundwithout the fix and passes with it.