Internal function used to load the icon.
| 62 | |
| 63 | // Internal function used to load the icon. |
| 64 | ILboolean iLoadIconInternal() |
| 65 | { |
| 66 | ICODIR IconDir; |
| 67 | ICODIRENTRY *DirEntries = NULL; |
| 68 | ICOIMAGE *IconImages = NULL; |
| 69 | ILimage *Image = NULL; |
| 70 | ILint i; |
| 71 | ILuint Size, PadSize, ANDPadSize, j, k, l, m, x, w, CurAndByte, AndBytes; |
| 72 | ILboolean BaseCreated = IL_FALSE; |
| 73 | ILubyte PNGTest[3]; |
| 74 | |
| 75 | if (iCurImage == NULL) { |
| 76 | ilSetError(IL_ILLEGAL_OPERATION); |
| 77 | return IL_FALSE; |
| 78 | } |
| 79 | |
| 80 | IconDir.Reserved = GetLittleShort(); |
| 81 | IconDir.Type = GetLittleShort(); |
| 82 | IconDir.Count = GetLittleShort(); |
| 83 | |
| 84 | if (ieof()) |
| 85 | goto file_read_error; |
| 86 | |
| 87 | DirEntries = (ICODIRENTRY*)ialloc(sizeof(ICODIRENTRY) * IconDir.Count); |
| 88 | IconImages = (ICOIMAGE*)ialloc(sizeof(ICOIMAGE) * IconDir.Count); |
| 89 | if (DirEntries == NULL || IconImages == NULL) { |
| 90 | ifree(DirEntries); |
| 91 | ifree(IconImages); |
| 92 | return IL_FALSE; |
| 93 | } |
| 94 | |
| 95 | // Make it easier for file_read_error. |
| 96 | for (i = 0; i < IconDir.Count; i++) |
| 97 | imemclear(&IconImages[i], sizeof(ICOIMAGE)); |
| 98 | |
| 99 | for (i = 0; i < IconDir.Count; ++i) { |
| 100 | DirEntries[i].Width = (ILubyte)igetc(); |
| 101 | DirEntries[i].Height = (ILubyte)igetc(); |
| 102 | DirEntries[i].NumColours = (ILubyte)igetc(); |
| 103 | DirEntries[i].Reserved = (ILubyte)igetc(); |
| 104 | DirEntries[i].Planes = GetLittleShort(); |
| 105 | DirEntries[i].Bpp = GetLittleShort(); |
| 106 | DirEntries[i].SizeOfData = GetLittleUInt(); |
| 107 | DirEntries[i].Offset = GetLittleUInt(); |
| 108 | |
| 109 | if (ieof()) |
| 110 | goto file_read_error; |
| 111 | } |
| 112 | |
| 113 | for (i = 0; i < IconDir.Count; i++) { |
| 114 | iseek(DirEntries[i].Offset, IL_SEEK_SET); |
| 115 | |
| 116 | // 08-22-2008: Adding test for compressed PNG data |
| 117 | igetc(); // Skip the first character...seems to vary. |
| 118 | iread(PNGTest, 3, 1); |
| 119 | if (!strnicmp((char*)PNGTest, "PNG", 3)) // Characters 'P', 'N', 'G' for PNG header |
| 120 | { |
| 121 | #ifdef IL_NO_PNG |
no test coverage detected