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

Function GetChannel

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

Source from the content-addressed store, hash-verified

452
453
454ILubyte *GetChannel()
455{
456 BLOCKHEAD Block;
457 CHANNEL_CHUNK Channel;
458 ILubyte *CompData, *Data;
459 ILuint ChunkSize, Padding;
460
461 if (iread(&Block, 1, sizeof(Block)) != sizeof(Block))
462 return NULL;
463 if (Header.MajorVersion == 3)
464 Block.BlockLen = GetLittleUInt();
465 else
466 UInt(&Block.BlockLen);
467
468 if (Block.HeadID[0] != 0x7E || Block.HeadID[1] != 0x42 ||
469 Block.HeadID[2] != 0x4B || Block.HeadID[3] != 0x00) {
470 ilSetError(IL_ILLEGAL_FILE_VALUE);
471 return NULL;
472 }
473 if (Block.BlockID != PSP_CHANNEL_BLOCK) {
474 ilSetError(IL_ILLEGAL_FILE_VALUE);
475 return NULL;
476 }
477
478
479 if (Header.MajorVersion >= 4) {
480 ChunkSize = GetLittleUInt();
481 if (iread(&Channel, sizeof(Channel), 1) != 1)
482 return NULL;
483
484 Padding = (ChunkSize - 4) - sizeof(Channel);
485 if (Padding > 0)
486 iseek(Padding, IL_SEEK_CUR);
487 }
488 else {
489 if (iread(&Channel, sizeof(Channel), 1) != 1)
490 return NULL;
491 }
492
493
494 CompData = (ILubyte*)ialloc(Channel.CompLen);
495 Data = (ILubyte*)ialloc(AttChunk.Width * AttChunk.Height);
496 if (CompData == NULL || Data == NULL) {
497 ifree(Data);
498 ifree(CompData);
499 return NULL;
500 }
501
502 if (iread(CompData, 1, Channel.CompLen) != Channel.CompLen) {
503 ifree(CompData);
504 ifree(Data);
505 return NULL;
506 }
507
508 switch (AttChunk.Compression)
509 {
510 case PSP_COMP_NONE:
511 ifree(Data);

Callers 2

ReadLayerBlockFunction · 0.85
ReadAlphaBlockFunction · 0.85

Calls 3

GetLittleUIntFunction · 0.85
ilSetErrorFunction · 0.85
UncompRLEFunction · 0.85

Tested by

no test coverage detected