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