[Radiance-dev] behavior of 3ds2mgf

Gregory J. Ward gregoryjward at gmail.com
Tue Oct 7 09:38:57 PDT 2008


Hi Erwin,

I'm pretty sure the problem is in 3ds2mgf.c:

float read_float()
{
     dword data;

     data = read_dword();

     return *(float *)&data;
}

which assumes that "unsigned long" is 4-bytes long.  This bit of code  
would actually work on a BigEndian system (I think), but not on  
Intel.  This is not my code, so I'm not 100% confident on this fix,  
but try it:

float read_float()
{
     union { dword i; char c[8]; } u;
     dword data;

     data = read_dword();

     if (sizeof(dword) == sizeof(float))
         return *(float *)&data;

     u.i = 1;
     if (u.c[0] == 0)
         return *(float *)&data; /* assume big-endian */

     if (sizeof(dword) != 2*sizeof(float)) {
         fputs("Unsupported word length\n", stderr);
         exit(1);
     }
     u.i = data;
     return *(float *)&u.c[4];
}

-Greg



More information about the Radiance-dev mailing list