vrshoot

view 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 source
3 // Definitions for the Interchange File Format (IFF)
4 // Alexander Gessler, 2006
5 // Adapted to Assimp August 2008
7 #ifndef AI_IFF_H_INCLUDED
8 #define AI_IFF_H_INCLUDED
10 #include "ByteSwap.h"
12 namespace Assimp {
13 namespace IFF {
15 #include "assimp/Compiler/pushpack1.h"
17 /////////////////////////////////////////////////////////////////////////////////
18 //! Describes an IFF chunk header
19 /////////////////////////////////////////////////////////////////////////////////
20 struct ChunkHeader
21 {
22 //! Type of the chunk header - FourCC
23 uint32_t type;
25 //! Length of the chunk data, in bytes
26 uint32_t length;
27 } PACK_STRUCT;
30 /////////////////////////////////////////////////////////////////////////////////
31 //! Describes an IFF sub chunk header
32 /////////////////////////////////////////////////////////////////////////////////
33 struct SubChunkHeader
34 {
35 //! Type of the chunk header - FourCC
36 uint32_t type;
38 //! Length of the chunk data, in bytes
39 uint16_t length;
40 } PACK_STRUCT;
42 #include "assimp/Compiler/poppack1.h"
45 #define AI_IFF_FOURCC(a,b,c,d) ((uint32_t) (((uint8_t)a << 24u) | \
46 ((uint8_t)b << 16u) | ((uint8_t)c << 8u) | ((uint8_t)d)))
49 #define AI_IFF_FOURCC_FORM AI_IFF_FOURCC('F','O','R','M')
52 /////////////////////////////////////////////////////////////////////////////////
53 //! Load a chunk header
54 //! @param outFile Pointer to the file data - points to the chunk data afterwards
55 //! @return Pointer to the chunk header
56 /////////////////////////////////////////////////////////////////////////////////
57 inline ChunkHeader* LoadChunk(uint8_t*& outFile)
58 {
59 ChunkHeader* head = (ChunkHeader*) outFile;
60 AI_LSWAP4(head->length);
61 AI_LSWAP4(head->type);
62 outFile += sizeof(ChunkHeader);
63 return head;
64 }
66 /////////////////////////////////////////////////////////////////////////////////
67 //! Load a sub chunk header
68 //! @param outFile Pointer to the file data - points to the chunk data afterwards
69 //! @return Pointer to the sub chunk header
70 /////////////////////////////////////////////////////////////////////////////////
71 inline SubChunkHeader* LoadSubChunk(uint8_t*& outFile)
72 {
73 SubChunkHeader* head = (SubChunkHeader*) outFile;
74 AI_LSWAP2(head->length);
75 AI_LSWAP4(head->type);
76 outFile += sizeof(SubChunkHeader);
77 return head;
78 }
80 /////////////////////////////////////////////////////////////////////////////////
81 //! Read the file header and return the type of the file and its size
82 //! @param outFile Pointer to the file data. The buffer must at
83 //! least be 12 bytes large.
84 //! @param fileType Receives the type of the file
85 //! @return 0 if everything was OK, otherwise an error message
86 /////////////////////////////////////////////////////////////////////////////////
87 inline const char* ReadHeader(uint8_t* outFile,uint32_t& fileType)
88 {
89 ChunkHeader* head = LoadChunk(outFile);
90 if(AI_IFF_FOURCC_FORM != head->type)
91 {
92 return "The file is not an IFF file: FORM chunk is missing";
93 }
94 fileType = *((uint32_t*)(head+1));
95 AI_LSWAP4(fileType);
96 return 0;
97 }
100 }}
102 #endif // !! AI_IFF_H_INCLUDED