Skip to content

Default a missing TIFF BitsPerSample to one bit per sample - #3230

Open
jafin wants to merge 1 commit into
SixLabors:mainfrom
jafin:jf/tiff-default-bitspersample
Open

jafin wants to merge 1 commit into
SixLabors:mainfrom
jafin:jf/tiff-default-bitspersample

Conversation

@jafin

@jafin jafin commented Oct 17, 2026 •

Copy link
Copy Markdown

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

Missing BitsPerSample

  • Problem: TIFF 6.0 says that when BitsPerSample is absent, each sample has 1 bit. Bilevel fax and scanner files often leave the entry out. TiffFrameMetadata.Parse kept the 8-bit RGB default in this case. An uncompressed bilevel file without the entry then failed with "The number of samples in the TIFF BitsPerSample entry is not supported". A CCITT Group 4 file decoded, but its frame metadata reported no valid bits per pixel.
  • Change: when the entry is absent, the decoder now uses 1 bit for each of the SamplesPerPixel samples (SamplesPerPixel defaults to 1, and TiffBitsPerSample holds at most four samples). An entry that is present but invalid keeps its current handling.

Testing

TiffDecoder_CanDecode_BilevelWithoutBitsPerSample encodes a 16x8 bilevel image, uncompressed and with CCITT Group 4. It then moves the BitsPerSample entry to an unused private tag. The test checks that:

  • the pixels match the decode of the unmodified file exactly;
  • the frame metadata reports Bit1;
  • Image.Identify reports 1 bit per pixel.

All 812 tests in the Tiff area pass in Release on net10.0.

Fixes #3242

TIFF 6.0 defines a default of one bit for each sample when the BitsPerSample entry is absent, and bilevel fax
and scanner files often omit it. The decoder assumed 8-bit RGB instead, so such files failed to decode or
reported the wrong bit depth. The default now uses one bit for each of the SamplesPerPixel samples.

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.

TIFF without a BitsPerSample entry fails to decode or reports 0 bits per pixel

1 participant