| 629 | //deleted ilReadRLE8Bmp() USE_POINTER version |
| 630 | |
| 631 | ILboolean ilReadRLE4Bmp(BMPHEAD *Header) |
| 632 | { |
| 633 | ILubyte Bytes[2]; |
| 634 | ILuint i; |
| 635 | size_t offset = 0, count, endOfLine = Header->biWidth; |
| 636 | |
| 637 | // Update the current image with the new dimensions |
| 638 | if (!ilTexImage(Header->biWidth, abs(Header->biHeight), 1, 1, 0, IL_UNSIGNED_BYTE, NULL)) |
| 639 | return IL_FALSE; |
| 640 | iCurImage->Origin = IL_ORIGIN_LOWER_LEFT; |
| 641 | |
| 642 | // A height of 0 is illegal |
| 643 | if (Header->biHeight == 0) { |
| 644 | ilSetError(IL_ILLEGAL_FILE_VALUE); |
| 645 | return IL_FALSE; |
| 646 | } |
| 647 | |
| 648 | iCurImage->Format = IL_COLOUR_INDEX; |
| 649 | iCurImage->Pal.PalType = IL_PAL_BGR32; |
| 650 | iCurImage->Pal.PalSize = 16 * 4; //Header->biClrUsed * 4; // 16 * 4 for most images |
| 651 | iCurImage->Pal.Palette = (ILubyte*)ialloc(iCurImage->Pal.PalSize); |
| 652 | if (iCurImage->Pal.Palette == NULL) |
| 653 | return IL_FALSE; |
| 654 | |
| 655 | // If the image height is negative, then the image is flipped |
| 656 | // (Normal is IL_ORIGIN_LOWER_LEFT) |
| 657 | iCurImage->Origin = Header->biHeight < 0 ? |
| 658 | IL_ORIGIN_UPPER_LEFT : IL_ORIGIN_LOWER_LEFT; |
| 659 | |
| 660 | // Read the palette |
| 661 | iseek(sizeof(BMPHEAD), IL_SEEK_SET); |
| 662 | |
| 663 | if (iread(iCurImage->Pal.Palette, iCurImage->Pal.PalSize, 1) != 1) |
| 664 | return IL_FALSE; |
| 665 | |
| 666 | // Seek to the data from the "beginning" of the file |
| 667 | iseek(Header->bfDataOff, IL_SEEK_SET); |
| 668 | |
| 669 | while (offset < iCurImage->SizeOfData) { |
| 670 | int align; |
| 671 | if (iread(&Bytes[0], sizeof(Bytes), 1) != 1) |
| 672 | return IL_FALSE; |
| 673 | if (Bytes[0] == 0x0) { // Escape sequence |
| 674 | switch (Bytes[1]) { |
| 675 | case 0x0: // End of line |
| 676 | offset = endOfLine; |
| 677 | endOfLine += iCurImage->Width; |
| 678 | break; |
| 679 | case 0x1: // End of bitmap |
| 680 | offset = iCurImage->SizeOfData; |
| 681 | break; |
| 682 | case 0x2: |
| 683 | if (iread(&Bytes[0], sizeof(Bytes), 1) != 1) |
| 684 | return IL_FALSE; |
| 685 | offset += Bytes[0] + Bytes[1] * iCurImage->Width; |
| 686 | endOfLine += Bytes[1] * iCurImage->Width; |
| 687 | break; |
| 688 | default: // Run of pixels |
no test coverage detected