Hi Agatha,
Thanks for clarifying your needs regarding this inquiry – there are many non-standard HDR image writers out there. That is partly my fault, as (a) I don’t tend to think about file format adoption outside the Radiance community, and (b) this was one of the first formats I developed, so hadn’t considered all the ramifications.
-
The ‘#’ character is not needed to delineate a comment – literally anything is allowed in the information header, and you can consider every line a type of comment. It’s just that some comments have meaning to some readers, like the “EXPOSURE=” line and other “VAR=” lines, including “FORMAT=”. (Incidentally, most readers should allow white space after the ‘=’ in such lines, but not before.) The information header continues until “\n\n” is encountered.
-
The “#?” at the beginning was added for “file sniffers” that try to figure out a file format without understanding it, like the Unix file program. It has been partially successful in that regard, though the file program can misidentify other Radiance files as HDR images. It is also compatible with files that begin comments with ‘#’ as you point out, and not really definitive – the resolution string is a better indicator you have an HDR file, but still not 100% reliable.
-
My readers don’t require files to start with “#?”, just in case some really old images are encountered. Newer readers should require it, and certainly any writer should write it (preferably as “#?RADIANCE”).
-
If it were entirely up to me, I would make the “FORMAT=32-bit_rle_???e” string the main requirement, but since it follows a header of indeterminant length and comes in two versions, it’s not very sniffer-friendly. Also, there are HDR files out there that fail to include it, so it’s not 100% reliable, either.
-
That is correct. The “EXPOSURE=” line is optional, 1.0 being the assumed value. Also, multiple values should be multiplied together – don’t just take the last one. So, my minimal example isn’t truly minimal in that sense.
My somewhat cavalier approach to reading Radiance HDR files is to accept whatever is in the header as valid, then look for the resolution string immediately following. If that’s there, then I proceed to the decoding stage, failing at that point if something is amiss. Worst case, we get garbage out.
-Greg