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

Function iLoadBlp1

DevIL/src-IL/src/il_blp.cpp:553–733  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

551
552
553ILboolean iLoadBlp1()
554{
555 BLP1HEAD Header;
556 ILubyte *DataAndAlpha, *Palette;
557 ILuint i;
558 ILimage *Image = iCurImage;
559 ILboolean BaseCreated = IL_FALSE;
560#ifndef IL_NO_JPG
561 ILubyte *JpegHeader, *JpegData;
562 ILuint JpegHeaderSize;
563#endif//IL_NO_JPG
564
565 if (!iGetBlp1Head(&Header))
566 return IL_FALSE;
567 if (!iCheckBlp1(&Header)) {
568 ilSetError(IL_INVALID_FILE_HEADER);
569 return IL_FALSE;
570 }
571
572 //@TODO: Remove this.
573 i = 0;
574
575 switch (Header.Compression)
576 {
577 case BLP_TYPE_JPG:
578#ifdef IL_NO_JPG
579 // We can only do the Jpeg decoding if we do not have IL_NO_JPEG defined.
580 return IL_FALSE;
581#else
582 JpegHeaderSize = GetLittleUInt();
583 JpegHeader = (ILubyte*)ialloc(JpegHeaderSize);
584 if (JpegHeader == NULL)
585 return IL_FALSE;
586 // Read the shared Jpeg header.
587 if (iread(JpegHeader, 1, JpegHeaderSize) != JpegHeaderSize) {
588 ifree(JpegHeader);
589 return IL_FALSE;
590 }
591
592 //for (i = 0; i < 16; i++) { // Possible maximum of 16 mipmaps
593 //@TODO: Check return value?
594 iseek(Header.MipOffsets[i], IL_SEEK_SET);
595 JpegData = (ILubyte*)ialloc(JpegHeaderSize + Header.MipLengths[i]);
596 if (JpegData == NULL) {
597 ifree(JpegHeader);
598 return IL_FALSE;
599 }
600 memcpy(JpegData, JpegHeader, JpegHeaderSize);
601 if (iread(JpegData + JpegHeaderSize, Header.MipLengths[i], 1) != 1)
602 return IL_FALSE;
603
604 // Just send the data straight to the Jpeg loader.
605 if (!ilLoadJpegL(JpegData, JpegHeaderSize + Header.MipLengths[i]))
606 return IL_FALSE;
607
608 // The image data is in BGR(A) order, even though it is Jpeg-compressed.
609 if (Image->Format == IL_RGBA)
610 Image->Format = IL_BGRA;

Callers 1

iLoadBlpInternalFunction · 0.85

Calls 6

iGetBlp1HeadFunction · 0.85
iCheckBlp1Function · 0.85
ilSetErrorFunction · 0.85
GetLittleUIntFunction · 0.85
ilLoadJpegLFunction · 0.85
ilFixImageFunction · 0.85

Tested by

no test coverage detected