All of this is experimental and only tested on my Linux system so far (SuSE 6.2). One of the next steps will be to try all this on NT and Solaris. The first step is floating point color support, which is the basis for importing and exporting Radiance format files, and mapping of images from floating point color to other formats (currently only RGB).
All my modifications and extensions to PIL are Copyright © Georg Mischler 1999. License to use and modify and redistribute them for any purpose is hereby given, provided that the copyright information is included in an appropriate way in the redistributed package. Of course, I'd appreciate if you send any enhancements of fixes back to me.
To install, apply all the patches and activate one or several of the related #defines in Image.h.
im->bands = 3; im->pixelsize = 12; im->linesize = xsize * 12; im->type = IMAGING_TYPE_FLOAT32X;and
im->image32f = (FLOAT32 **) im->image;I had to put image32f at the end of ImagingMemoryInstance, since tkImaging.c seems to depend on the layout of that struct - eeek!
After this, you can create floating point color images of type RGBf, and apply a few operations on them. At the moment, those are getpixel(), transpose(Image.FLIP_XXXX_YYYY), and copy(). Allmost everything else is very likely to dump core!
Use of this plugin is straightforward as with most others. Im.info will hold the information from the file header. Images are read from old style chunk encoded format and and new style byte encoded format transparently. Written files are byte encoded, unless they have a width of less than 8 pixels or more than 32767 pixels, in which case they will be stored in plain format without any encoding (ie. uncompressed).
The plugin will currently _accept() all files, although newer files usually have the string "#?RADIANCE" at their beginning. Files created with older versions of Radiance don't have this header, and can't reliably be recognized based on the 16 bytes that Image.py provides for that purpose. I'm not quite sure what to do abou this. The most elegant solution would be to give the _accept() function of each plugin a file object instead of a string, so that they can decide how much data they need locally. RadianceImagePlugin.py would require up to a dozen or more lines of text read from the file to make sure it is valid in a reliable way.
I'm still looking for a good way to support loading partial files, but PIL makes this a little difficult. It reads the file data in chunks and doesn't tell the the decoder if there is more to come or not for each of those chunks. There may be a hack possible, to guess this from the size of the chunk we get in each turn, but I'll have to check out how realiable this approach will work. We want to see the contents of partially rendered files as well, don't we?
The files in the ray/ subdirectory are from the Radiance distribution. Radiance can be downloaded from The Radiance Homepage for free, but you are not allowed to redistribute it to anyone else without a written permission by the Regents of the University of California.
Don't ask me if this makes any sense, but it still keeps me from including those files here, so that you'll have to get them there yourself if you want to try this out. The full package has roughly 10 MB. you only need a few files for this PIL extension here to work, all of which reside in the ray/src/common/ directory of the distribution and go to Imaging-1.0/libImaging/ray/:
color.h color.c spec_rgb.c tmerrmsg.h tmprivat.h tonemap.h tonemap.cSince Radiance images store their values in radiance (sic!) units, instead of "brightness" as other formats, we need some way to convert the radiometric information we got into photometric values first, and then into RGB luma (or whatever) to display on screen. Those who need more information about this radiometry/photometry stuff can check out The Lighting Design Glossary).
This module is very experimental, since I have yet to understand most of what happens in the conversion process. More features probably to come.
The patches and my additional files are available for download (pilray.tgz 82054 bytes). The archive will expand into a directory named "pilray".
The RadianceImagePlugin.py and RadianceImageConvert.py files go into your PIL subdirectory.
The file pyradconv.c goes into the main Imaging directory. It is #included into _imaging.c, which is not very elegant, but turned out to be the simplest way to do it, since it needs much information that is not exported from _imaging.c, while most of it's own contents must be visible there.
The files RadianceConvert.h, RadianceConvert.c, RadianceEncode.c and RadianceDecode.c go into the libImaging directory.
The patch files must be applied to the equally named files throughout the package.
I have included a small example image named "alberta.pic". You will find more example Radiance format images in the ray/lib[/lib] directory of the Radiance distribution, or in the dowload section of The Radiance Homepage.
I'd appreciate any comments on all of the above and whatever I might have forgotten!
All Mongolian Recipes | The Mongolian Yurt | All of Mongolia: Adventure Travel