| 550 | |
| 551 | |
| 552 | ILboolean ilReadRLE8Bmp(BMPHEAD *Header) |
| 553 | { |
| 554 | ILubyte Bytes[2]; |
| 555 | size_t offset = 0, count, endOfLine = Header->biWidth; |
| 556 | |
| 557 | // Update the current image with the new dimensions |
| 558 | if (!ilTexImage(Header->biWidth, abs(Header->biHeight), 1, 1, 0, IL_UNSIGNED_BYTE, NULL)) |
| 559 | return IL_FALSE; |
| 560 | |
| 561 | iCurImage->Origin = IL_ORIGIN_LOWER_LEFT; |
| 562 | |
| 563 | // A height of 0 is illegal |
| 564 | if (Header->biHeight == 0) |
| 565 | return IL_FALSE; |
| 566 | |
| 567 | iCurImage->Format = IL_COLOUR_INDEX; |
| 568 | iCurImage->Pal.PalType = IL_PAL_BGR32; |
| 569 | iCurImage->Pal.PalSize = Header->biClrUsed * 4; // 256 * 4 for most images |
| 570 | if (iCurImage->Pal.PalSize == 0) |
| 571 | iCurImage->Pal.PalSize = 256 * 4; |
| 572 | iCurImage->Pal.Palette = (ILubyte*)ialloc(iCurImage->Pal.PalSize); |
| 573 | if (iCurImage->Pal.Palette == NULL) |
| 574 | return IL_FALSE; |
| 575 | |
| 576 | // If the image height is negative, then the image is flipped |
| 577 | // (Normal is IL_ORIGIN_LOWER_LEFT) |
| 578 | iCurImage->Origin = Header->biHeight < 0 ? |
| 579 | IL_ORIGIN_UPPER_LEFT : IL_ORIGIN_LOWER_LEFT; |
| 580 | |
| 581 | // Read the palette |
| 582 | iseek(sizeof(BMPHEAD), IL_SEEK_SET); |
| 583 | if (iread(iCurImage->Pal.Palette, iCurImage->Pal.PalSize, 1) != 1) |
| 584 | return IL_FALSE; |
| 585 | |
| 586 | // Seek to the data from the "beginning" of the file |
| 587 | iseek(Header->bfDataOff, IL_SEEK_SET); |
| 588 | |
| 589 | while (offset < iCurImage->SizeOfData) { |
| 590 | if (iread(Bytes, sizeof(Bytes), 1) != 1) |
| 591 | return IL_FALSE; |
| 592 | if (Bytes[0] == 0x00) { // Escape sequence |
| 593 | switch (Bytes[1]) |
| 594 | { |
| 595 | case 0x00: // End of line |
| 596 | offset = endOfLine; |
| 597 | endOfLine += iCurImage->Width; |
| 598 | break; |
| 599 | case 0x01: // End of bitmap |
| 600 | offset = iCurImage->SizeOfData; |
| 601 | break; |
| 602 | case 0x2: |
| 603 | if (iread(Bytes, sizeof(Bytes), 1) != 1) |
| 604 | return IL_FALSE; |
| 605 | offset += Bytes[0] + Bytes[1] * iCurImage->Width; |
| 606 | endOfLine += Bytes[1] * iCurImage->Width; |
| 607 | break; |
| 608 | default: |
| 609 | count = IL_MIN(Bytes[1], iCurImage->SizeOfData-offset); |
no outgoing calls
no test coverage detected