[Image-SIG] Updated ImagePlugin for the SGI file format

Karsten Hiddemann karsten.hiddemann at mathematik.uni-dortmund.de
Thu May 1 01:49:25 CEST 2008

Attached is an updated ImagePlugin for PIL to read (some) RLE-compressed 
SGI images. I needed to load RLE-compressed images for a program of mine 
and didn't like that I had to use PythonMagick for this. William Baxter 
asked about this on the list about half a year ago as well, I believe. 
The former SGI ImagePlugin used the wrong orientation when loading SGI 
images, too.

It took me quite some time to come up with a way to extend the image 
loading mechanism of PIL. What I came up with is possibly quite a hack, 
but the best I could do by reading the source code for ImageFile.py, 
TiffImagePlugin.py and Unpack.c as reference. I didn't find out how to 
implement a custom decoder instead of the default "raw" encoder, as 
there seemed to be a lack of documentation for this?

You'll find a couple of FIXME tags in the code where I didn't know how 
to tell PIL what I wanted to do, for example when it comes to loading 
some 16 bit channel data. Proper options for the tile list are still a 
mystery to me, since Unpack.c has some modes like "xxx;L" and "xxx;16B" 
which don't seem to be supported by the raw decoder yet, or at least I 
couldn't find the right combination of self.mode and "raw" read mode.

I tested this against a couple of *.sgi and *.rgba images that I found 
via filewatcher.com and it worked fine on those that it supported. Some 
nasty unsupported images can be found at Toby Thain's Telegraphics site 
where he keeps a SGI format plugin for Photoshop. For example, only 
"normal" Colormaps are supported at the moment, although things like 
dithered images wouldn't be too hard to add (though obsolete). I didn't 
have the chance to test greyscale images, but they should load okay.

I don't know what the requirements are for using this code, as this is 
just my second program in Python and I have no idea how portable my code 
is towards older versions of Python. I have developed it under Python 
2.4.4 myself and would expect that one would need at least Python 2.0.

Any comments on this, new testdata for monochrome or dithered images, or 
tips for to address some of my FIXME's are highly welcome.

In case this gets added to the official PIL codebase, I have found a 
couple of other ImagePlugins while searching for reference code on the 
net that I'd propose to add:

- Bob Ippolito made plugins for the Mac OS X icns file format and for 
the SoftImage format, however it seems like only the IcnsImagePlugin.py 
was added. The other one can be found at 
If you Google for the filename you'll find that some others have found 
interest in it, too.

- John Wright has code for a plugin online which can read and write 
Nokia operator logos in the OTB and GMS format: 

- Oliver Jowett developed a plugin to read a variety of DDS texture 
files. The original page is gone, but can still be observed in 
archive.org, the code has been picked up and improved by two separate 
parties for some "Dark Age of Camelot" projects. Here are some links:

(archived version of the original site for the code)
http://www.ceejbot.com/DAoC/ (a fixed version of the DAoC Mapper)
http://www.ceejbot.com/DAoC/tools/DdsImageFile.py (download there)
http://nathrach.republicofnewhome.org/mappergui.html#reqs (download 
MapperGUI 2.4)

The two versions of this plugin differ in only six lines, it seems that 
in the original source code some color channels were switched.

Karsten Hiddemann
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: SgiImagePlugin.py
URL: <http://mail.python.org/pipermail/image-sig/attachments/20080501/1c76af88/attachment-0001.txt>

More information about the Image-SIG mailing list