nuclear@0: nuclear@0: nuclear@0: // Definitions for the Interchange File Format (IFF) nuclear@0: // Alexander Gessler, 2006 nuclear@0: // Adapted to Assimp August 2008 nuclear@0: nuclear@0: #ifndef AI_IFF_H_INCLUDED nuclear@0: #define AI_IFF_H_INCLUDED nuclear@0: nuclear@0: #include "ByteSwap.h" nuclear@0: nuclear@0: namespace Assimp { nuclear@0: namespace IFF { nuclear@0: nuclear@0: #include "assimp/Compiler/pushpack1.h" nuclear@0: nuclear@0: ///////////////////////////////////////////////////////////////////////////////// nuclear@0: //! Describes an IFF chunk header nuclear@0: ///////////////////////////////////////////////////////////////////////////////// nuclear@0: struct ChunkHeader nuclear@0: { nuclear@0: //! Type of the chunk header - FourCC nuclear@0: uint32_t type; nuclear@0: nuclear@0: //! Length of the chunk data, in bytes nuclear@0: uint32_t length; nuclear@0: } PACK_STRUCT; nuclear@0: nuclear@0: nuclear@0: ///////////////////////////////////////////////////////////////////////////////// nuclear@0: //! Describes an IFF sub chunk header nuclear@0: ///////////////////////////////////////////////////////////////////////////////// nuclear@0: struct SubChunkHeader nuclear@0: { nuclear@0: //! Type of the chunk header - FourCC nuclear@0: uint32_t type; nuclear@0: nuclear@0: //! Length of the chunk data, in bytes nuclear@0: uint16_t length; nuclear@0: } PACK_STRUCT; nuclear@0: nuclear@0: #include "assimp/Compiler/poppack1.h" nuclear@0: nuclear@0: nuclear@0: #define AI_IFF_FOURCC(a,b,c,d) ((uint32_t) (((uint8_t)a << 24u) | \ nuclear@0: ((uint8_t)b << 16u) | ((uint8_t)c << 8u) | ((uint8_t)d))) nuclear@0: nuclear@0: nuclear@0: #define AI_IFF_FOURCC_FORM AI_IFF_FOURCC('F','O','R','M') nuclear@0: nuclear@0: nuclear@0: ///////////////////////////////////////////////////////////////////////////////// nuclear@0: //! Load a chunk header nuclear@0: //! @param outFile Pointer to the file data - points to the chunk data afterwards nuclear@0: //! @return Pointer to the chunk header nuclear@0: ///////////////////////////////////////////////////////////////////////////////// nuclear@0: inline ChunkHeader* LoadChunk(uint8_t*& outFile) nuclear@0: { nuclear@0: ChunkHeader* head = (ChunkHeader*) outFile; nuclear@0: AI_LSWAP4(head->length); nuclear@0: AI_LSWAP4(head->type); nuclear@0: outFile += sizeof(ChunkHeader); nuclear@0: return head; nuclear@0: } nuclear@0: nuclear@0: ///////////////////////////////////////////////////////////////////////////////// nuclear@0: //! Load a sub chunk header nuclear@0: //! @param outFile Pointer to the file data - points to the chunk data afterwards nuclear@0: //! @return Pointer to the sub chunk header nuclear@0: ///////////////////////////////////////////////////////////////////////////////// nuclear@0: inline SubChunkHeader* LoadSubChunk(uint8_t*& outFile) nuclear@0: { nuclear@0: SubChunkHeader* head = (SubChunkHeader*) outFile; nuclear@0: AI_LSWAP2(head->length); nuclear@0: AI_LSWAP4(head->type); nuclear@0: outFile += sizeof(SubChunkHeader); nuclear@0: return head; nuclear@0: } nuclear@0: nuclear@0: ///////////////////////////////////////////////////////////////////////////////// nuclear@0: //! Read the file header and return the type of the file and its size nuclear@0: //! @param outFile Pointer to the file data. The buffer must at nuclear@0: //! least be 12 bytes large. nuclear@0: //! @param fileType Receives the type of the file nuclear@0: //! @return 0 if everything was OK, otherwise an error message nuclear@0: ///////////////////////////////////////////////////////////////////////////////// nuclear@0: inline const char* ReadHeader(uint8_t* outFile,uint32_t& fileType) nuclear@0: { nuclear@0: ChunkHeader* head = LoadChunk(outFile); nuclear@0: if(AI_IFF_FOURCC_FORM != head->type) nuclear@0: { nuclear@0: return "The file is not an IFF file: FORM chunk is missing"; nuclear@0: } nuclear@0: fileType = *((uint32_t*)(head+1)); nuclear@0: AI_LSWAP4(fileType); nuclear@0: return 0; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: }} nuclear@0: nuclear@0: #endif // !! AI_IFF_H_INCLUDED