vrshoot
diff libs/assimp/IFF.h @ 0:b2f14e535253
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 01 Feb 2014 19:58:19 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/assimp/IFF.h Sat Feb 01 19:58:19 2014 +0200 1.3 @@ -0,0 +1,102 @@ 1.4 + 1.5 + 1.6 +// Definitions for the Interchange File Format (IFF) 1.7 +// Alexander Gessler, 2006 1.8 +// Adapted to Assimp August 2008 1.9 + 1.10 +#ifndef AI_IFF_H_INCLUDED 1.11 +#define AI_IFF_H_INCLUDED 1.12 + 1.13 +#include "ByteSwap.h" 1.14 + 1.15 +namespace Assimp { 1.16 +namespace IFF { 1.17 + 1.18 +#include "assimp/Compiler/pushpack1.h" 1.19 + 1.20 +///////////////////////////////////////////////////////////////////////////////// 1.21 +//! Describes an IFF chunk header 1.22 +///////////////////////////////////////////////////////////////////////////////// 1.23 +struct ChunkHeader 1.24 +{ 1.25 + //! Type of the chunk header - FourCC 1.26 + uint32_t type; 1.27 + 1.28 + //! Length of the chunk data, in bytes 1.29 + uint32_t length; 1.30 +} PACK_STRUCT; 1.31 + 1.32 + 1.33 +///////////////////////////////////////////////////////////////////////////////// 1.34 +//! Describes an IFF sub chunk header 1.35 +///////////////////////////////////////////////////////////////////////////////// 1.36 +struct SubChunkHeader 1.37 +{ 1.38 + //! Type of the chunk header - FourCC 1.39 + uint32_t type; 1.40 + 1.41 + //! Length of the chunk data, in bytes 1.42 + uint16_t length; 1.43 +} PACK_STRUCT; 1.44 + 1.45 +#include "assimp/Compiler/poppack1.h" 1.46 + 1.47 + 1.48 +#define AI_IFF_FOURCC(a,b,c,d) ((uint32_t) (((uint8_t)a << 24u) | \ 1.49 + ((uint8_t)b << 16u) | ((uint8_t)c << 8u) | ((uint8_t)d))) 1.50 + 1.51 + 1.52 +#define AI_IFF_FOURCC_FORM AI_IFF_FOURCC('F','O','R','M') 1.53 + 1.54 + 1.55 +///////////////////////////////////////////////////////////////////////////////// 1.56 +//! Load a chunk header 1.57 +//! @param outFile Pointer to the file data - points to the chunk data afterwards 1.58 +//! @return Pointer to the chunk header 1.59 +///////////////////////////////////////////////////////////////////////////////// 1.60 +inline ChunkHeader* LoadChunk(uint8_t*& outFile) 1.61 +{ 1.62 + ChunkHeader* head = (ChunkHeader*) outFile; 1.63 + AI_LSWAP4(head->length); 1.64 + AI_LSWAP4(head->type); 1.65 + outFile += sizeof(ChunkHeader); 1.66 + return head; 1.67 +} 1.68 + 1.69 +///////////////////////////////////////////////////////////////////////////////// 1.70 +//! Load a sub chunk header 1.71 +//! @param outFile Pointer to the file data - points to the chunk data afterwards 1.72 +//! @return Pointer to the sub chunk header 1.73 +///////////////////////////////////////////////////////////////////////////////// 1.74 +inline SubChunkHeader* LoadSubChunk(uint8_t*& outFile) 1.75 +{ 1.76 + SubChunkHeader* head = (SubChunkHeader*) outFile; 1.77 + AI_LSWAP2(head->length); 1.78 + AI_LSWAP4(head->type); 1.79 + outFile += sizeof(SubChunkHeader); 1.80 + return head; 1.81 +} 1.82 + 1.83 +///////////////////////////////////////////////////////////////////////////////// 1.84 +//! Read the file header and return the type of the file and its size 1.85 +//! @param outFile Pointer to the file data. The buffer must at 1.86 +//! least be 12 bytes large. 1.87 +//! @param fileType Receives the type of the file 1.88 +//! @return 0 if everything was OK, otherwise an error message 1.89 +///////////////////////////////////////////////////////////////////////////////// 1.90 +inline const char* ReadHeader(uint8_t* outFile,uint32_t& fileType) 1.91 +{ 1.92 + ChunkHeader* head = LoadChunk(outFile); 1.93 + if(AI_IFF_FOURCC_FORM != head->type) 1.94 + { 1.95 + return "The file is not an IFF file: FORM chunk is missing"; 1.96 + } 1.97 + fileType = *((uint32_t*)(head+1)); 1.98 + AI_LSWAP4(fileType); 1.99 + return 0; 1.100 +} 1.101 + 1.102 + 1.103 +}} 1.104 + 1.105 +#endif // !! AI_IFF_H_INCLUDED