You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For some TIFF images, a simple Image.open(path).save(path) fails with the following:
_TIFFVSetField: /path/to/test.tiff: Bad value 2 for "ExtraSamples" tag.
Traceback (most recent call last):
<elided traceback>
File "/usr/lib/python3.4/site-packages/PIL/Image.py", line 1685, in save
save_handler(self, fp, filename)
File "/usr/lib/python3.4/site-packages/PIL/TiffImagePlugin.py", line 1185, in _save
e = Image._getencoder(im.mode, 'libtiff', a, im.encoderconfig)
File "/usr/lib/python3.4/site-packages/PIL/Image.py", line 430, in _getencoder
return encoder(mode, *args + extra)
RuntimeError: Error setting from dictionary
The image was created using Qt's QImageWriter (from a QImage.Format_RBG32 image), but it is not clear how to reproduce the issue as a simple blank image created in the same way does not trigger the same issue.
Looking at the spec, my earlier interpretation doesn't appear to be correct:
ExtraSamples
Description of extra components.
Tag = 338 (152.H)
Type = SHORT
N = m
Specifies that each pixel has m extra components whose interpretation is defined
by one of the values listed below. When this field is used, the SamplesPerPixel
field has a value greater than the PhotometricInterpretation field suggests.
For example, full-color RGB data normally has SamplesPerPixel=3. If
SamplesPerPixel is greater than 3, then the ExtraSamples field describes the
meaning of the extra samples. If SamplesPerPixel is, say, 5 then ExtraSamples
will contain 2 values, one for each extra sample.
ExtraSamples is typically used to include non-color information, such as opacity,
in an image. The possible values for each item in the field's value are:
0 = Unspecified data
1 = Associated alpha data (with pre-multiplied color)
2 = Unassociated alpha data
By this spec, the values are correct as they currently are. That doesn't explain your original problem in #1039 .
Testing, I find that it fails for Python 2.9.x and works in both Python 3.0.x and master. I'll close this, and anyone can request a re-open if they feel otherwise.
Activity
hugovk commentedon Dec 6, 2014
Please can you share an image that reproduces the problem?
anntzer commentedon Dec 6, 2014
Try this: http://imagebin.ca/v/1jfvXmEIE3Eq (I guess you'll need to rename it as a .tiff).
wiredfool commentedon Dec 6, 2014
The RGBA line here in TiffInfoPlugin looks like the issue:
(though, both of these look wrong. RGBX should have ExtraSamples=1, and RGBA should have 0. I think, I'd have to review the spec to make sure.)
anntzer commentedon Dec 6, 2014
Indeed, monkeypatching the SAVE_INFO dict apparently solves the issue.
hugovk commentedon Dec 28, 2014
Comment by @wiredfool hoisted from #1045:
Looking at the spec, my earlier interpretation doesn't appear to be correct:
By this spec, the values are correct as they currently are. That doesn't explain your original problem in #1039 .
anntzer commentedon Dec 28, 2014
I think I figured it out and my original fix was indeed wrong. I believe it's a nastier bug, specifically
ExtraSamplesshould be a list of values (one per extra sample), rather than a simple value. I fixed this by temporarily addingin
_save(just after choosing to use libtiff), but this should really be fixed at load time rather than save time.PyImaging_LibTiffEncoderNew(encode.c) which callsImagingLibTiffSetFieldincorrectly: to save a tag that is an array of values, one should pass the number of toImagingLibTiffSetFieldboth the array length and a pointer to the first value (cf. http://stackoverflow.com/questions/3451806/getting-error-when-trying-to-apply-extrasamples-tag-to-a-tiff-file-to-be-writt/3674991#3674991 for a similar issue).Creating a new PR now.
radarhere commentedon Oct 28, 2015
Is this resolved now?
radarhere commentedon Oct 28, 2015
Testing, I find that it fails for Python 2.9.x and works in both Python 3.0.x and master. I'll close this, and anyone can request a re-open if they feel otherwise.
wiredfool commentedon Oct 28, 2015
Pillow, I think.
But anyway, this is part of the massive IFD overhaul, so it should be settled.
anntzer commentedon Oct 28, 2015
Yup, I forgot what this was exactly but from my earlier descriptions this must have been fixed by the IFD rewrite.