   [c++] reading Radiance (.hdr) files
  Hey! I'm trying to write my own radiance file loader in clean c++. The only example I've found is (http://www.flipcode.com/archives/HDR_Image_Reader.shtml), but it confuses a lot as I'm not familiar with legacy C I/O.  From what I can see in my hex editor, after the magic number there is a lot of room for program comments. All the items are seperated by a (0A)byte. I've typed these out as they show up as a white space just like (20)byte. After the header there is a sequence of "FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 88 00". This sequence is also at the end of the file so i think it acts as the start and delimiter of the actual data.One example I have has this header:#?RADIANCE # Made with 100% pure HDR Shop FORMAT=32-bit_rle_rgbe(0A)EXPOSURE=1.0000000000000(0A)(0A)-Y 4096 +X 3072(0A)(02)(02)(0C)(00)(FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 88 00)// I assume this is all the actual data(FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 88 00)What I want to do is: 1) Check if the file is indeed is a radiance file. I've implemented this as follows:const string   TEXTURE_HDR_HEADER_MAGIC=  "#?RADIANCE";stringstream convertor;for(int i = 0; i < TEXTURE_HDR_HEADER_MAGIC.length(); i++){convertor << file.get();}if(convertor.str() != TEXTURE_HDR_HEADER_MAGIC) return false;2) Read the FORMAT, EXPOSURE and image dimensions. I should just read until I find a (0A)byte and then math the following bytes against the words 'FORMAT', 'EXPOSURE' and '-Y' and '+X', the values are then padded with (20)byte Im adding this later3) Read the image data and convert it to 3-float per pixel. This is where I need help as I don't know how to read the RGBE half floats and then convert them to a nice RGB 32 bit float block.Thanks in advance!   
  First, you are a little off on the data format. Here is a better overview. For more info, you should get the Radiance source, everything is in there. Here is the original file format description by Greg Ward (warning, it's chaotic). Look on page 28, the PIC data format (.PIC == .HDR)Second, RGBE to float goes as follows:/* standard conversion from rgbe to float pixels *//* note: Ward uses ldexp(col+0.5,exp-(128+8)).  However we wanted pixels *//*  in the range [0,1] to map back into the range [0,1].  */static INLINE void rgbe2float(float *red, float *green, float *blue, unsigned char rgbe[4]){  float f;  if (rgbe[3]) {   /*nonzero pixel*/    f = ldexp(1.0,rgbe[3]-(int)(128+8));    *red = rgbe[0] * f;    *green = rgbe[1] * f;    *blue = rgbe[2] * f;  }  else    *red = *green = *blue = 0.0;}Code from Radiance, as far as I remember.Note that .HDR does not contain half float data. It contains a shared exponent representation. You're confusing it with EXR, which contains three 16bit half-float RGB values.;  About the RLE compression... The file format description reads this:FORMATA line indicating the file's format. At most one FORMAT line isallowed, and it must be assigned a value of either"32-bit_rle_rgbe" or "32-bit_rle_xyze"to be a valid Radiance picture.Scanline RecordsRadiance scanlines come in one of three flavors, described below:UncompressedOld run-length encodedNew run-length encodedSo what FORMAT line describes an uncompressed file? they are both named rleAlso I'm uncertain about the RLE compression:Old run-length encodedRepeated pixel values are indicated by an illegal (i.e.,unnormalized) pixel that has 1's for all three mantissas, and anexponent that corresponds to the number of times the previouspixel is repeated. Consecutive repeat indicators contain higherorderbytes of the count.This is not too hard: (example are decimales)(char) 0 64 64 128255 255 255 32 Would mean 32 teal (rgb 0.0f 0.5f 0.5f) pixels (is this correct?)New run-length encodedIn this format, the four scanline components (three primaries andexponent) are separated for better compression using adaptiverun-length encoding (described by Glassner in Chapter II.8 ofGraphics Gems II [Arvo91,p.89]). The record begins with anunnormalized pixel having two bytes equal to 2, followed by theupper byte and the lower byte of the scanline length (which mustbe less than 32768). A run is indicated by a byte with its highorderbit set, corresponding to a count with excess 128. A nonrunis indicated with a byte less than 128. The maximumcompression ratio using this scheme is better than 100:1, buttypical performance for Radiance pictures is more like 2:1.So this means (char)0 64 64 128    2 2 7 255Are 2047 teal pixels?[Edited by - Defeatist on June 7, 2010 12:24:45 PM]