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

Function ReadLayerBlock

DevIL/src-IL/src/il_psp.cpp:304–377  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

302
303
304ILboolean ReadLayerBlock(ILuint BlockLen)
305{
306 BLOCKHEAD Block;
307 LAYERINFO_CHUNK LayerInfo;
308 LAYERBITMAP_CHUNK Bitmap;
309 ILuint ChunkSize, Padding, i, j;
310 ILushort NumChars;
311
312 BlockLen;
313
314 // Layer sub-block header
315 if (iread(&Block, 1, sizeof(Block)) != sizeof(Block))
316 return IL_FALSE;
317 if (Header.MajorVersion == 3)
318 Block.BlockLen = GetLittleUInt();
319 else
320 UInt(&Block.BlockLen);
321
322 if (Block.HeadID[0] != 0x7E || Block.HeadID[1] != 0x42 ||
323 Block.HeadID[2] != 0x4B || Block.HeadID[3] != 0x00) {
324 return IL_FALSE;
325 }
326 if (Block.BlockID != PSP_LAYER_BLOCK)
327 return IL_FALSE;
328
329
330 if (Header.MajorVersion == 3) {
331 iseek(256, IL_SEEK_CUR); // We don't care about the name of the layer.
332 iread(&LayerInfo, sizeof(LayerInfo), 1);
333 if (iread(&Bitmap, sizeof(Bitmap), 1) != 1)
334 return IL_FALSE;
335 }
336 else { // Header.MajorVersion >= 4
337 ChunkSize = GetLittleUInt();
338 NumChars = GetLittleUShort();
339 iseek(NumChars, IL_SEEK_CUR); // We don't care about the layer's name.
340
341 ChunkSize -= (2 + 4 + NumChars);
342
343 if (iread(&LayerInfo, IL_MIN(sizeof(LayerInfo), ChunkSize), 1) != 1)
344 return IL_FALSE;
345
346 // Can have new entries in newer versions of the spec (5.0).
347 Padding = (ChunkSize) - sizeof(LayerInfo);
348 if (Padding > 0)
349 iseek(Padding, IL_SEEK_CUR);
350
351 ChunkSize = GetLittleUInt();
352 if (iread(&Bitmap, sizeof(Bitmap), 1) != 1)
353 return IL_FALSE;
354 Padding = (ChunkSize - 4) - sizeof(Bitmap);
355 if (Padding > 0)
356 iseek(Padding, IL_SEEK_CUR);
357 }
358
359
360 Channels = (ILubyte**)ialloc(sizeof(ILubyte*) * Bitmap.NumChannels);
361 if (Channels == NULL) {

Callers 1

ParseChunksFunction · 0.85

Calls 3

GetLittleUIntFunction · 0.85
GetLittleUShortFunction · 0.85
GetChannelFunction · 0.85

Tested by

no test coverage detected