Hi Agatha,
It’s a good question, and you probably won’t like my answer.
Historically, there was no definitive magic number to any Radiance files, and the binary portion would follow whatever text appeared at the beginning up to an empty line that ended the header, i.e., “\n\n”. The length of a Radiance header has no limit. The header portion is traditionally used to contain the commands that created the file, metadata like the image exposure and a FORMAT string (described below).
The “#?” string was prepended at some point to offer assurance to my file readers that a file was really for them. It is used by all of the Radiance portable binary file types in the “#?RADIANCE” incarnation, though the “RADIANCE” string itself is ignored. Image files these days are expected to contain one of the following in their information header, usually at the end:
FORMAT=32-bit_rle_rgbe
or
FORMAT=32-bit_rle_xyze
The latter indicates XYZ rather than an RGB color space. Not all writers adhere to this specification, so there is some leeway in most of the HDR image readers. Following the “\n\n” string at the end of the header, there is a line of the form:
[-+][XY] vres [-+][YX] hres
to indicate the image dimensions and orientation. This is often the most reliable way to tell if a Radiance HDR image follows, though this kind of resolution string is also part of some other binary and even ASCII files in Radiance, but I won’t go into that. The usual English scanline ordering for a 512 wide by 300 high image would be:
-Y 300 +X 512
A single linefeed follows this string, which can have any number of spaces between the letters and first digits in the two dimensions. In all, a minimal header with resolution string for a calibrated image looks like this:
#?(anything)
EXPOSURE= (float value)
FORMAT=32-bit_rle_rgbe
-Y (yres) +X (xres)
(RGBE image data in scanline order)
I hope this helps!
-Greg
P.S. Unlike HDR images, some Radiance binary files, such as octrees and ambient caches, contain an additional magic number as the first (usually) two bytes following the header. This is our way of being confident we have the correct file type, since the “#?” string at the beginning is really generic to all Radiance files.