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