Skip to content

Error saving TIFF #1227

Closed
Closed

Description

@radarhere

In case anyone wants to investigate this, I have a TIFF file that can be loaded without a problem, but generates an error when trying to save.

For the record, it was created by the OS X screencapture program 'Grab'.

Since Github doesn't seem to support TIFF attachments, I'll upload it elsewhere - http://s000.tinyupload.com/download.php?file_id=08240275698144503996&t=0824027569814450399610301

>>> from PIL import Image
>>> x = Image.open('sample.tiff')
>>> x.save('test.tiff')
_TIFFVSetField: test.tiff: Bad value 50048 for "SampleFormat" tag.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PIL/Image.py", line 1693, in save
    save_handler(self, fp, filename)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PIL/TiffImagePlugin.py", line 1191, in _save
    e = Image._getencoder(im.mode, 'libtiff', a, im.encoderconfig)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PIL/Image.py", line 434, in _getencoder
    return encoder(mode, *args + extra)
RuntimeError: Error setting from dictionary

Activity

  1. added
    Bug
    on May 11, 2015
  2. wiredfool commented on May 11, 2015

    @wiredfool
    Member

    There's something screwy going on with that one.

    I'm seeing it come in with ExtraSamples=1, meaning RGBa (with premultiplied alpha), and it's trying to save as RGBA, or plain old alpha. Which makes some sense, because that's the approved mode for general usage in Pillow.

    I'm not sure why it's throwing an error with ExtraSamples ==2, best guess is that it's sending an int and tiff is expecting a short. This may only fail with BigEndian tiffs.

    {256: 57, 257: 54, 258: 8, 259: 5, 262: 2, 274: 1, 338: 2, 339: [1, 1, 1, 1], 277: 4, 284: 1, 317: 2}
    _TIFFVSetField: out.tiff: Bad value 2 for "ExtraSamples" tag.
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "build/bdist.linux-x86_64/egg/PIL/Image.py", line 1694, in save
      File "build/bdist.linux-x86_64/egg/PIL/TiffImagePlugin.py", line 1191, in _save
      File "build/bdist.linux-x86_64/egg/PIL/Image.py", line 434, in _getencoder
    RuntimeError: Error setting from dictionary
    

    So, I'm going to say related to #1059

  3. radarhere commented on Jun 10, 2015

    @radarhere
    MemberAuthor

    Thanks for that info. Starting with that, and looking at documentation, I see the line -

    If SamplesPerPixel is, say, 5 then ExtraSamples will contain 2 values, one for each extra sample.
    

    SamplesPerPixel is in fact, 4 for this image. However, I can't yet see how to specify 2 values.

    I looked at the SampleFormat tag, which has the value - [1, 1, 1, 1] - thinking that would be a good example of multiple values. However, if you remove the SamplesPerPixel tag, the error becomes -

    Bad value 21504 for "SampleFormat" tag.
    

    where 21504 is a number that changes every time, I'm guessing the pointer being mistakenly read as the value. The documentation states that it should be 1-6.


    I've come to the conclusion that yes, #1059 is solving this exact problem. However, what I find discouraging is that when I checkout that branch, it cannot identify this image file.

  4. anntzer commented on Jun 12, 2015

    @anntzer
    Contributor

    Failures to identify image files can usually be debugged by uncommenting the traceback.print_exc() lines in Image.py. Here, the #1059 TiffImagePlugin is correctly reading SampleFormat as (1, 1, 1, 1), but a new entry "just" needs to be created in OPEN_INFO. Can someone look into the correct value for mode and rawmode?

    In fact, it it not clear to me what purpose does rawmode serve.

  5. anntzer commented on Jun 12, 2015

    @anntzer
    Contributor

    OK, I guess rawmode is basically transformed into packing information in Pack.c and Unpack.c.

  6. added a commit that references this issue on Jun 29, 2015
  7. radarhere commented on Sep 20, 2015

    @radarhere
    MemberAuthor

    Resolved by #1419

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugTIFF

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions