MCPcopy Create free account
hub / github.com/DentonW/DevIL / TplGetIndexImage

Function TplGetIndexImage

DevIL/src-IL/src/il_tpl.cpp:595–781  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

593
594
595ILboolean TplGetIndexImage(ILimage *Image, ILuint TexOff, ILuint DataFormat)
596{
597 ILushort NumPal, ShortPixel;
598 ILubyte LumVal, BytePixel;
599 ILuint PalFormat, PalOff, PalBpp, DataOff;
600 ILuint x, y, xBlock, yBlock, i;
601
602 NumPal = GetBigUShort();
603 iseek(2, IL_SEEK_CUR); // Do we need to do anything with the 'unpacked' entry? I see nothing in the specs about it.
604 PalFormat = GetBigUInt();
605
606 // Now we have to find out where the actual palette data is stored.
607 //@TODO: Do we need to set any errors here?
608 PalOff = GetBigUInt();
609 if (iseek(PalOff, IL_SEEK_SET))
610 return IL_FALSE;
611
612 switch (PalFormat)
613 {
614 case TPL_PAL_IA8:
615 Image->Pal.Palette = (ILubyte*)ialloc(NumPal * 4);
616 if (Image->Pal.Palette == NULL)
617 return IL_FALSE;
618 Image->Pal.PalType = IL_PAL_RGBA32; //@TODO: Use this format natively.
619 Image->Pal.PalSize = NumPal * 4;
620 PalBpp = 4;
621
622 for (i = 0; i < NumPal; i++) {
623 LumVal = igetc();
624 //@TODO: Do proper conversion of luminance, or support this format natively.
625 Image->Pal.Palette[i * 4] = LumVal; // Assign the luminance value.
626 Image->Pal.Palette[i * 4 + 1] = LumVal;
627 Image->Pal.Palette[i * 4 + 2] = LumVal;
628 Image->Pal.Palette[i * 4 + 3] = igetc(); // Get alpha value.
629 }
630 break;
631
632 case TPL_PAL_RGB565:
633 Image->Pal.Palette = (ILubyte*)ialloc(NumPal * 3);
634 if (Image->Pal.Palette == NULL)
635 return IL_FALSE;
636 Image->Pal.PalType = IL_PAL_RGB24;
637 Image->Pal.PalSize = NumPal * 3;
638 PalBpp = 3;
639
640 for (i = 0; i < NumPal; i++) {
641 ShortPixel = GetBigUShort();
642 // This is mostly the same code as in the TPL_RGB565 case.
643 Image->Pal.Palette[i*3] = ((ShortPixel & 0xF800) >> 8) | ((ShortPixel & 0xE000) >> 13); // Red
644 Image->Pal.Palette[i*3+1] = ((ShortPixel & 0x7E0) >> 3) | ((ShortPixel & 0x600) >> 9); // Green
645 Image->Pal.Palette[i*3+2] = ((ShortPixel & 0x1f) << 3) | ((ShortPixel & 0x1C) >> 2); // Blue
646 }
647 break;
648
649 case TPL_PAL_RGB5A3:
650 Image->Pal.Palette = (ILubyte*)ialloc(NumPal * 4);
651 if (Image->Pal.Palette == NULL)
652 return IL_FALSE;

Callers 1

iLoadTplInternalFunction · 0.85

Calls 3

GetBigUShortFunction · 0.85
GetBigUIntFunction · 0.85
ilSetErrorFunction · 0.85

Tested by

no test coverage detected