The rgbe image file format was invented by Greg Ward to reduce the precision
problems inherent in normal 24bit file formats. Many programs including
photorealistic renderers produce pixels with a wide range of values.
Internally the programs usually handle this by representing colors by
floating point values. However writing out the floating point values
directly would produce very large files (~96 bits/pixel). The rgbe format
works by having all channels (typically red, green, and blue) share a single
exponent. Thus a pixel consists of three 8 bit mantissas and an 8 bit
exponent for 32 bits per pixel. This makes for a compact format which
can handle wide range of pixels values (from 0 to 2^127) with reasonable
precision. See "Real Pixels" by Greg Ward in Graphics Gems II for more
This code was written based on Greg Ward's code (available from the
radiance home page ftp://radsite.lbl.gov/home.html) for reading and
writing rgbe files. I have rewritten the code as ANSI C and tried to
clean up the code and comment it to make it easier to understand. I've
also tried to make the error detection a little more robust. Here's the
minimal code for using these files.
sample minimal writing code:
f = fopen(image_filename,"wb");
For run length encoding instead of RGBE_WritePixels, use
sample minimal reading code:
f = fopen(image_filename,"rb");
image = (float *)malloc(sizeof(float)*3*image_width*image_height);
You can use RGBE_Read_Pixels instead but it will not handle run length
encoded file correctly. For more information see the rgbe.c file.
(Note: these files are available at http://www.graphics.cornell.edu/~bjw/ )
Please note: By definition of the rgbe format, all pixels should be in
units of watts/steradian/meter^2 unless otherwise noted in the header.
If the header contains an exposure field then dividing pixels values by