Internal function used to get the .hdr header from the current file.
| 66 | |
| 67 | // Internal function used to get the .hdr header from the current file. |
| 68 | ILboolean iGetHdrHead(HDRHEADER *Header) |
| 69 | { |
| 70 | ILboolean done = IL_FALSE; |
| 71 | char a, b; |
| 72 | char x[3], y[3]; //changed 20050217: added space for the '\0' char |
| 73 | char buff[81]; // 01-19-2009: Added space for the '\0'. |
| 74 | ILuint count = 0; |
| 75 | |
| 76 | iread(Header->Signature, 1, 10); |
| 77 | |
| 78 | //skip lines until an empty line is found. |
| 79 | //this marks the end of header information, |
| 80 | //the next line contains the image's dimension. |
| 81 | |
| 82 | //TODO: read header contents into variables |
| 83 | //(EXPOSURE, orientation, xyz correction, ...) |
| 84 | |
| 85 | if (iread(&a, 1, 1) != 1) |
| 86 | return IL_FALSE; |
| 87 | |
| 88 | while (!done) { |
| 89 | if (iread(&b, 1, 1) != 1) |
| 90 | return IL_FALSE; |
| 91 | if (b == '\n' && a == '\n') |
| 92 | done = IL_TRUE; |
| 93 | else |
| 94 | a = b; |
| 95 | } |
| 96 | |
| 97 | //read dimensions (note that this assumes a somewhat valid image) |
| 98 | if (iread(&a, 1, 1) != 1) |
| 99 | return IL_FALSE; |
| 100 | while (a != '\n') { |
| 101 | if (count >= 80) // Line shouldn't be this long at all. |
| 102 | return IL_FALSE; |
| 103 | buff[count] = a; |
| 104 | if (iread(&a, 1, 1) != 1) |
| 105 | return IL_FALSE; |
| 106 | ++count; |
| 107 | } |
| 108 | buff[count] = '\0'; |
| 109 | |
| 110 | //note that this is not the 100% correct way to load hdr images: |
| 111 | //in a perfect world we would check if there's a +/- X/Y in front |
| 112 | //of width and heigth and mirror + rotate the image after decoding |
| 113 | //according to that. But HDRShop doesn't do that either (and that's |
| 114 | //my reference program :) ) and it's just a rotate and a mirror, |
| 115 | //nothing that really changes the appearance of the loaded image... |
| 116 | //(The code as it is now assumes that y contains "-Y" and x contains |
| 117 | //"+X" after the following line) |
| 118 | |
| 119 | // The 2 has to be in the %s format specifier to prevent buffer overruns. |
| 120 | sscanf(buff, "%2s %d %2s %d", y, &Header->Height, x, &Header->Width); |
| 121 | |
| 122 | return IL_TRUE; |
| 123 | } |
| 124 | |
| 125 |