Skip to content

Updated default value for SAMPLESPERPIXEL TIFF tag#5452

Merged
hugovk merged 1 commit intopython-pillow:masterfrom
radarhere:missing_samplesperpixel
May 14, 2021
Merged

Updated default value for SAMPLESPERPIXEL TIFF tag#5452
hugovk merged 1 commit intopython-pillow:masterfrom
radarhere:missing_samplesperpixel

Conversation

@radarhere
Copy link
Copy Markdown
Member

@radarhere radarhere commented Apr 29, 2021

Resolves #5317

#5372 added this code, to raise an error when opening a TIFF image if the SAMPLESPERPIXEL didn't match the number of bits per sample - or if it were missing and the bits per sample wasn't 1.

samplesPerPixel = self.tag_v2.get(SAMPLESPERPIXEL, 1)
if len(bps_tuple) != samplesPerPixel:
raise SyntaxError("unknown data organization")

This PR relaxes that, to allow through images where SAMPLESPERPIXEL is missing. I created a test image by just commenting out SAMPLESPERPIXEL when saving a TIFF.

Ping @wiredfool in case there was a reason for this that I'm not aware of.

@kkopachev
Copy link
Copy Markdown
Contributor

@radarhere This is from #5364 (comment) (and next comment).
I think this change looks risky.
When forced in python code to self.use_load_libtiff=True, it fails to read.
Trying to open it using TIFFRGBAImageGet from libtiff also fails with Sorry, can not handle RGB image with Color channels=1 coming from https://gitlab.com/libtiff/libtiff/-/blob/master/libtiff/tif_getimage.c#L144

@kkopachev
Copy link
Copy Markdown
Contributor

Perhaps less risky solution would be to handle OJPEG compressed images with special hacks around missing tags like LibTiff does https://gitlab.com/libtiff/libtiff/-/blob/master/libtiff/tif_dirread.c#L4081

@radarhere radarhere force-pushed the missing_samplesperpixel branch from ce87dcc to ea033f4 Compare May 4, 2021 06:39
@radarhere radarhere changed the title Do not raise an error if SAMPLESPERPIXEL is missing when opening TIFF Updated default value for SAMPLESPERPIXEL tag May 4, 2021
@radarhere radarhere changed the title Updated default value for SAMPLESPERPIXEL tag Updated default value for SAMPLESPERPIXEL TIFF tag May 4, 2021
@radarhere
Copy link
Copy Markdown
Member Author

Thanks for reviewing. I've updated the commit with your suggestion.

@radarhere radarhere force-pushed the missing_samplesperpixel branch from ea033f4 to 6fc039a Compare May 4, 2021 06:50
@hugovk hugovk merged commit f027397 into python-pillow:master May 14, 2021
@radarhere radarhere deleted the missing_samplesperpixel branch May 14, 2021 13:21
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.

OSError: -9 at img.show() with a .CR2 image

3 participants