| 197 | |
| 198 | |
| 199 | ILboolean iLoadSunInternal(void) |
| 200 | { |
| 201 | SUNHEAD Header; |
| 202 | BITFILE *File; |
| 203 | ILuint i, j, Padding, Offset, BytesRead; |
| 204 | ILubyte PaddingData[16]; |
| 205 | |
| 206 | if (iCurImage == NULL) { |
| 207 | ilSetError(IL_ILLEGAL_OPERATION); |
| 208 | return IL_FALSE; |
| 209 | } |
| 210 | |
| 211 | //@TODO: Right now, iGetSunHead cannot fail. |
| 212 | if (!iGetSunHead(&Header) || !iCheckSun(&Header)) { |
| 213 | ilSetError(IL_INVALID_FILE_HEADER); |
| 214 | return IL_FALSE; |
| 215 | } |
| 216 | |
| 217 | switch (Header.Depth) |
| 218 | { |
| 219 | case 1: //@TODO: Find a file to test this on. |
| 220 | File = bfile(iGetFile()); |
| 221 | if (File == NULL) |
| 222 | return IL_FALSE; |
| 223 | |
| 224 | if (!ilTexImage(Header.Width, Header.Height, 1, 1, IL_COLOUR_INDEX, IL_UNSIGNED_BYTE, NULL)) |
| 225 | return IL_FALSE; |
| 226 | if (Header.ColorMapLength != 0) { |
| 227 | // Data should be an index into the color map, but the color map should only be RGB (6 bytes, 2 entries). |
| 228 | if (Header.ColorMapLength != 6) { |
| 229 | ilSetError(IL_INVALID_FILE_HEADER); |
| 230 | return IL_FALSE; |
| 231 | } |
| 232 | } |
| 233 | iCurImage->Pal.Palette = (ILubyte*)ialloc(6); // Just need 2 entries in the color map. |
| 234 | if (Header.ColorMapLength == 0) { // Create the color map |
| 235 | iCurImage->Pal.Palette[0] = 0x00; // Entry for black |
| 236 | iCurImage->Pal.Palette[1] = 0x00; |
| 237 | iCurImage->Pal.Palette[2] = 0x00; |
| 238 | iCurImage->Pal.Palette[3] = 0xFF; // Entry for white |
| 239 | iCurImage->Pal.Palette[4] = 0xFF; |
| 240 | iCurImage->Pal.Palette[5] = 0xFF; |
| 241 | } |
| 242 | else { |
| 243 | iread(iCurImage->Pal.Palette, 1, 6); // Read in the color map. |
| 244 | } |
| 245 | iCurImage->Pal.PalSize = 6; |
| 246 | iCurImage->Pal.PalType = IL_PAL_RGB24; |
| 247 | |
| 248 | Padding = (16 - (iCurImage->Width % 16)) % 16; // Has to be aligned on a 16-bit boundary. The rest is padding. |
| 249 | |
| 250 | // Reads the bits |
| 251 | for (i = 0; i < iCurImage->Height; i++) { |
| 252 | bread(&iCurImage->Data[iCurImage->Width * i], 1, iCurImage->Width, File); |
| 253 | //bseek(File, BitPadding, IL_SEEK_CUR); //@TODO: This function does not work correctly. |
| 254 | bread(PaddingData, 1, Padding, File); // Skip padding bits. |
| 255 | } |
| 256 | break; |
no test coverage detected