Radiance HDR (.pic, .hdr) file formatWritten by Paul Bourke
The original Radiance picture format (typically ".pic") is the basis for one of the standard HDR (High Dynamic Range image) image formats (".hdr"), supported by most HDR image editors including Adobe PhotoShop (eg: PhotoShop CS2, 2006). Each pixel is stored as 4 bytes, one byte mantissa for each r,g,b and a shared one byte exponent. The pixel data may be stored uncompressed or using a straightforward run length encoding scheme.
A Radiance image file consists of three sections: a header, resolution string, followed by the pixel data.
The first bytes in a legal image file are "#?RADIANCE". This identifies the file as a likely image. Following this are a number of informative lines and assignments. For example it is traditional to include (and maintain) the series of programs/commands that generated the image, each appears on a separate line and a blank line indicates the end of the header. Some of the standard radiance based keywords/assignments are listed below.
The single resolution line consists of 4 values, a X and Y label each followed by a numerical integer value. The X and Y are immediately preceded by a sign which can be used to indicate flipping, the order of the X and Y indicate rotation. The standard coordinate system for Radiance images would have the following resolution string -Y N +X N. This indicates that the vertical axis runs down the file and the X axis is to the right (imagining the image as a rectangular block of data). A -X would indicate a horizontal flip of the image. A +Y would indicate a vertical flip. If the X value appears before the Y value then that indicates that the image is stored in column order rather than row order, that is, it is rotated by 90 degrees. The reader can convince themselves that the 8 combinations cover all the possible image orientations and rotations.
There are three formats the pixel data may appear in, they are: uncompressed, a standard run length encoding where a colour with 255 for all three mantissas indicates a run of the last pixel value (exponent is the run count), and an adaptive run length encoding. For the details of this the reader should consult the Radiance source code as the definitive reference.