1. Fredrik Lundh
  2. pil-2009-raclette
  3. Issues
Issue #15 new

Problem opening sunraster files 8bpp gray

Matthieu Walraet
created an issue

I've an error opening a gray sunrasterfile, with this code:

{{{

!python

from PIL import Image graysun = Image.open("grey.ras") d = graysun.load() }}}

I get: {{{ File "C:\Python27\lib\site-packages\PIL\ImageFile.py", line 148, in load self.mode, self.size, a[1], a[2] IndexError: tuple index out of range }}}

I found a way to patch "SunImagePlugin.py" to correct this issue, line 77 I have replaced:

        self.tile = [("raw", (0,0)+self.size, offset, (rawmode, stride))]

by:

        self.tile = [("raw", (0,0)+self.size, offset, (rawmode, stride, 1))]

The third item of tupple correspond to orientation.

According to http://www.pythonware.com/library/pil/handbook/decoder.htm << When used in a tile descriptor, the parameter field should look like: (raw mode, stride, orientation) (...) orientation: Whether the first line in the image is the top line on the screen (1), or the bottom line (-1). If omitted, the orientation defaults to 1. >>

Seems like the orientation parameter can't be omitted. I'm not sure if problem should be fixed in SunImagePlugin.py to add orientation as I've done, or in ImageFile.py to accept missing orientation.

Regards, Matthieu

Comments (0)

  1. Log in to comment