Reads an uncompressed .bmp One of the absolute ugliest functions I've ever written!
| 270 | // Reads an uncompressed .bmp |
| 271 | // One of the absolute ugliest functions I've ever written! |
| 272 | ILboolean ilReadUncompBmp(BMPHEAD * Header) |
| 273 | { |
| 274 | ILuint i, j, k, c, Read; |
| 275 | ILubyte Bpp, ByteData, PadSize, Padding[4]; |
| 276 | ILuint rMask, gMask, bMask; //required for bitfields packing |
| 277 | ILuint rShiftR, gShiftR, bShiftR; //required for bitfields packing |
| 278 | ILuint rShiftL, gShiftL, bShiftL; //required for bitfields packing |
| 279 | ILushort Read16; //used for 16bit bmp loading |
| 280 | |
| 281 | if (Header->biBitCount < 8) |
| 282 | Bpp = 1; // We can't have an integral number less than one and greater than 0 |
| 283 | else |
| 284 | Bpp = (ILubyte)(Header->biBitCount >> 3); // Convert to bytes per pixel |
| 285 | |
| 286 | if(Bpp == 2 || Bpp == 4) |
| 287 | Bpp = 3; |
| 288 | |
| 289 | // Update the current image with the new dimensions |
| 290 | if (!ilTexImage(Header->biWidth, abs(Header->biHeight), 1, Bpp, 0, IL_UNSIGNED_BYTE, NULL)) { |
| 291 | return IL_FALSE; |
| 292 | } |
| 293 | iCurImage->Origin = IL_ORIGIN_LOWER_LEFT; |
| 294 | |
| 295 | switch (Header->biBitCount) |
| 296 | { |
| 297 | case 1: |
| 298 | //iCurImage->Format = IL_LUMINANCE; |
| 299 | iCurImage->Format = IL_COLOUR_INDEX; |
| 300 | iCurImage->Pal.PalType = IL_PAL_BGR32; |
| 301 | iCurImage->Pal.PalSize = 2 * 4; |
| 302 | iCurImage->Pal.Palette = (ILubyte*)ialloc(iCurImage->Pal.PalSize); |
| 303 | if (iCurImage->Pal.Palette == NULL) { |
| 304 | return IL_FALSE; |
| 305 | } |
| 306 | break; |
| 307 | |
| 308 | case 4: |
| 309 | case 8: |
| 310 | iCurImage->Format = IL_COLOUR_INDEX; |
| 311 | iCurImage->Pal.PalType = IL_PAL_BGR32; |
| 312 | |
| 313 | // if there are 256 colors biClrUsed is 0 |
| 314 | iCurImage->Pal.PalSize = Header->biClrUsed ? |
| 315 | Header->biClrUsed * 4 : 256 * 4; |
| 316 | |
| 317 | if (Header->biBitCount == 4) // biClrUsed is 0 for 4-bit bitmaps |
| 318 | iCurImage->Pal.PalSize = 16 * 4; |
| 319 | iCurImage->Pal.Palette = (ILubyte*)ialloc(iCurImage->Pal.PalSize); |
| 320 | if (iCurImage->Pal.Palette == NULL) { |
| 321 | return IL_FALSE; |
| 322 | } |
| 323 | break; |
| 324 | |
| 325 | case 16: |
| 326 | case 24: |
| 327 | case 32: |
| 328 | iCurImage->Format = IL_BGR; |
| 329 | break; |
no test coverage detected