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

Function iLoadTplInternal

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

Internal function used to load the TPL.

Source from the content-addressed store, hash-verified

186
187// Internal function used to load the TPL.
188ILboolean iLoadTplInternal(void)
189{
190 TPLHEAD Header;
191 ILimage *Image/*, *BaseImage*/;
192 ILuint Pos, TexOff, PalOff, DataFormat, Bpp, DataOff, WrapS, WrapT;
193 ILuint x, y, xBlock, yBlock, i, j, k, n;
194 ILenum Format;
195 ILushort Width, Height, ShortPixel;
196 ILubyte BytePixel, CompData[8];
197 Color8888 colours[4], *col;
198 ILushort color_0, color_1;
199 ILuint bitmask, Select;
200
201 if (iCurImage == NULL) {
202 ilSetError(IL_ILLEGAL_OPERATION);
203 return IL_FALSE;
204 }
205 Image = iCurImage; // Top-level image
206
207 if (!iGetTplHead(&Header))
208 return IL_FALSE;
209 if (!iCheckTpl(&Header)) {
210 ilSetError(IL_INVALID_FILE_HEADER);
211 return IL_FALSE;
212 }
213
214 // Points to the beginning of the texture header directory.
215 Pos = itell();
216
217 for (n = 0; n < Header.nTextures; n++) {
218 // Go back to the texture header directory for texture number n+1.
219 iseek(Pos + n * 8, IL_SEEK_SET);
220 TexOff = GetBigUInt();
221 PalOff = GetBigUInt();
222 // Go to the texture header.
223 if (iseek(TexOff, IL_SEEK_SET))
224 return IL_FALSE;
225
226 Height = GetBigUShort();
227 Width = GetBigUShort();
228 // It looks like files actually have n-1 images, with the nth one having 0 height and width.
229 if (Width == 0 || Height == 0) {
230 // If this is our first image, however, we error out.
231 if (Image == iCurImage) {
232 ilSetError(IL_ILLEGAL_FILE_VALUE);
233 return IL_FALSE;
234 }
235 // Break out of our for loop and run ilFixImage on the images.
236 break;
237 }
238
239 DataFormat = GetBigUInt();
240 TexOff = GetBigUInt();
241 WrapS = GetBigUInt();
242 WrapT = GetBigUInt();
243 if (WrapS == TPL_REPEAT || WrapS == TPL_MIRROR) {
244 // By the specs, repeated and mirrored textures must have dimensions of power of 2.
245 if ((Width != ilNextPower2(Width)) || (Height != ilNextPower2(Height))) {

Callers 2

ilLoadTplFFunction · 0.85
ilLoadTplLFunction · 0.85

Calls 9

ilSetErrorFunction · 0.85
iGetTplHeadFunction · 0.85
iCheckTplFunction · 0.85
GetBigUIntFunction · 0.85
GetBigUShortFunction · 0.85
ilNextPower2Function · 0.85
TplGetIndexImageFunction · 0.85
DxtcReadColorFunction · 0.85
ilFixImageFunction · 0.85

Tested by

no test coverage detected