iff_chunk iff_begin_read_chunk() { chunkDepth++; if (chunkDepth >= CHUNK_STACK_SIZE){ ilSetError(IL_STACK_OVERFLOW); return chunkStack[0]; } if (chunkDepth < 0) { ilSetError(IL_STACK_UNDERFLOW); return chunkStack[0]; } chunkStack[chunkDepth].start = itell(); chunkStack[chunkDepth].tag = GetBigInt(); chunkStack[chunkDepth].size = GetBigInt(); if (chunkStack[chunkDepth].tag == IFF_TAG_FOR4) { // -- We have a form, so read the form type tag as well. chunkStack[chunkDepth].chunkType = GetBigInt(); } else { chunkStack[chunkDepth].chunkType = 0; } return chunkStack[chunkDepth]; }
int XMISong::FindXMIDforms(const BYTE *chunk, int len, TrackInfo *songs) const { int count = 0; for (int p = 0; p <= len - 12; ) { int chunktype = GetNativeInt(chunk + p); int chunklen = GetBigInt(chunk + p + 4); if (chunktype == MAKE_ID('F','O','R','M')) { if (GetNativeInt(chunk + p + 8) == MAKE_ID('X','M','I','D')) { if (songs != NULL) { FoundXMID(chunk + p + 12, chunklen - 4, songs + count); } count++; } } else if (chunktype == MAKE_ID('C','A','T',' ')) { // Recurse to handle CAT chunks. count += FindXMIDforms(chunk + p + 12, chunklen - 4, songs + count); } // IFF chunks are padded to even byte boundaries to avoid // unaligned reads on 68k processors. p += 8 + chunklen + (chunklen & 1); // Avoid crashes from corrupt chunks which indicate a negative size. if (chunklen < 0) p = len; } return count; }
// Internal function used to get the .sgi header from the current file. ILboolean iGetSgiHead(iSgiHeader *Header) { Header->MagicNum = GetBigUShort(); Header->Storage = (ILbyte)igetc(); Header->Bpc = (ILbyte)igetc(); Header->Dim = GetBigUShort(); Header->XSize = GetBigUShort(); Header->YSize = GetBigUShort(); Header->ZSize = GetBigUShort(); Header->PixMin = GetBigInt(); Header->PixMax = GetBigInt(); Header->Dummy1 = GetBigInt(); iread(Header->Name, 1, 80); Header->ColMap = GetBigInt(); iread(Header->Dummy, 1, 404); return IL_TRUE; }
// Internal function used to get the .pic header from the current file. ILboolean iGetPicHead(PIC_HEAD *Header) { Header->Magic = GetBigInt(); Header->Version = GetBigFloat(); iread(Header->Comment, 1, 80); iread(Header->Id, 1, 4); Header->Width = GetBigShort(); Header->Height = GetBigShort(); Header->Ratio = GetBigFloat(); Header->Fields = GetBigShort(); Header->Padding = GetBigShort(); return IL_TRUE; }
void XMISong::FoundXMID(const BYTE *chunk, int len, TrackInfo *song) const { for (int p = 0; p <= len - 8; ) { int chunktype = GetNativeInt(chunk + p); int chunklen = GetBigInt(chunk + p + 4); if (chunktype == MAKE_ID('T','I','M','B')) { song->TimbreChunk = chunk + p + 8; song->TimbreLen = chunklen; } else if (chunktype == MAKE_ID('E','V','N','T')) { song->EventChunk = chunk + p + 8; song->EventLen = chunklen; // EVNT must be the final chunk in the FORM. break; } p += 8 + chunklen + (chunklen & 1); } }
// Internal function used to load the icon. ILboolean iLoadIcnsInternal(ILimage* image) { ICNSHEAD Header; ICNSDATA Entry; ILimage *Image = NULL; ILboolean BaseCreated = IL_FALSE; if (image == NULL) { il2SetError(IL_ILLEGAL_OPERATION); return IL_FALSE; } image->io.read(&image->io, Header.Head, 4, 1); Header.Size = GetBigInt(&image->io); if (strncmp(Header.Head, "icns", 4)) // First 4 bytes have to be 'icns'. return IL_FALSE; while ((ILint)image->io.tell(&image->io) < Header.Size && !image->io.eof(&image->io)) { image->io.read(&image->io, Entry.ID, 4, 1); Entry.Size = GetBigInt(&image->io); if (!strncmp(Entry.ID, "it32", 4)) // 128x128 24-bit { if (iIcnsReadData(image, &BaseCreated, IL_FALSE, 128, &Entry, &Image) == IL_FALSE) goto icns_error; } else if (!strncmp(Entry.ID, "t8mk", 4)) // 128x128 alpha mask { if (iIcnsReadData(image, &BaseCreated, IL_TRUE, 128, &Entry, &Image) == IL_FALSE) goto icns_error; } else if (!strncmp(Entry.ID, "ih32", 4)) // 48x48 24-bit { if (iIcnsReadData(image, &BaseCreated, IL_FALSE, 48, &Entry, &Image) == IL_FALSE) goto icns_error; } else if (!strncmp(Entry.ID, "h8mk", 4)) // 48x48 alpha mask { if (iIcnsReadData(image, &BaseCreated, IL_TRUE, 48, &Entry, &Image) == IL_FALSE) goto icns_error; } else if (!strncmp(Entry.ID, "il32", 4)) // 32x32 24-bit { if (iIcnsReadData(image, &BaseCreated, IL_FALSE, 32, &Entry, &Image) == IL_FALSE) goto icns_error; } else if (!strncmp(Entry.ID, "l8mk", 4)) // 32x32 alpha mask { if (iIcnsReadData(image, &BaseCreated, IL_TRUE, 32, &Entry, &Image) == IL_FALSE) goto icns_error; } else if (!strncmp(Entry.ID, "is32", 4)) // 16x16 24-bit { if (iIcnsReadData(image, &BaseCreated, IL_FALSE, 16, &Entry, &Image) == IL_FALSE) goto icns_error; } else if (!strncmp(Entry.ID, "s8mk", 4)) // 16x16 alpha mask { if (iIcnsReadData(image, &BaseCreated, IL_TRUE, 16, &Entry, &Image) == IL_FALSE) goto icns_error; } #ifndef IL_NO_JP2 else if (!strncmp(Entry.ID, "ic09", 4)) // 512x512 JPEG2000 encoded - Uses JasPer { if (iIcnsReadData(image, &BaseCreated, IL_FALSE, 512, &Entry, &Image) == IL_FALSE) goto icns_error; } else if (!strncmp(Entry.ID, "ic08", 4)) // 256x256 JPEG2000 encoded - Uses JasPer { if (iIcnsReadData(image, &BaseCreated, IL_FALSE, 256, &Entry, &Image) == IL_FALSE) goto icns_error; } #endif//IL_NO_JP2 else // Not a valid format or one that we can use { image->io.seek(&image->io, Entry.Size - 8, IL_SEEK_CUR); } } return il2FixImage(image); icns_error: return IL_FALSE; }