镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Support greyscale TIFFs with ExtraSamples 0 or 1 - #10140

Merged
radarhere merged 4 commits into
python-pillow:mainfrom
officialpm:fix/tiff-grey-extra-sample
Oct 7, 2026
Merged

radarhere merged 4 commits into
python-pillow:mainfrom
officialpm:fix/tiff-grey-extra-sample

Conversation

@officialpm

@officialpm officialpm commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #10139

  • Add greyscale TIFF support for ExtraSamples 0 (unspecified) and 1 (associated alpha), for both byte orders.
  • ExtraSamples 0 opens as L using the new LX raw mode, which skips the unspecified sample rather than treating it as alpha. ExtraSamples 1 opens as La; value 2 remains LA.

Tested with a source build using libtiff 4.3.0: python -m pytest Tests/test_file_tiff.py -q (87 passed, 2 skipped). Also checked the reporter's four raw/LZW TIFFs and the modes for ExtraSamples 0, 1 and 2. Ruff is clean.

@officialpm

Copy link
Copy Markdown
Contributor Author

A note on ExtraSamples 0 (unspecified): I mapped it to LA, so the extra sample is kept as the second band. Dropping it and opening as L would need a new C raw mode, which seemed too big for this fix. ExtraSamples 1 (associated alpha) opens as La, matching how the existing entries treat it.

Thanks to @street1983nk for the sample files in #10139. They are small (324 bytes LZW, about 6 kB raw), so if you'd like them as fixtures I'm happy to add them to Tests/images and test against them. Right now the test builds the TIFF in memory and patches the tag.

@radarhere

radarhere commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

which seemed too big for this fix

Sounds like it would be ok to me. I've created officialpm#1 with this change.

Read L with unspecified extra samples as L
@officialpm

Copy link
Copy Markdown
Contributor Author

Thanks @radarhere, merged your follow-up into the branch. I rebuilt with libtiff enabled and checked all four reporter files: ExtraSamples 0 opens as L, and ExtraSamples 1 remains La. ExtraSamples 2 still opens as LA. Tests/test_file_tiff.py passes (87 passed, 2 skipped).

@radarhere
radarhere merged commit 52d303a into python-pillow:main Oct 7, 2026
61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TIFF: greyscale with one extra sample fails to open when ExtraSamples is 0 (unspecified) or 1 (associated alpha)

2 participants