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 "ByteSwapper.h"
9
10namespace Assimp {
11namespace IFF {
12
13/////////////////////////////////////////////////////////////////////////////////
14//! Describes an IFF chunk header
15/////////////////////////////////////////////////////////////////////////////////
16struct 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/////////////////////////////////////////////////////////////////////////////////
29struct 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#define AI_IFF_FOURCC(a,b,c,d) ((uint32_t) (((uint8_t)a << 24u) | \
40 ((uint8_t)b << 16u) | ((uint8_t)c << 8u) | ((uint8_t)d)))
41
42
43#define AI_IFF_FOURCC_FORM AI_IFF_FOURCC('F','O','R','M')
44
45
46/////////////////////////////////////////////////////////////////////////////////
47//! Load a chunk header
48//! @param outFile Pointer to the file data - points to the chunk data afterwards
49//! @return Copy of the chunk header
50/////////////////////////////////////////////////////////////////////////////////
51inline ChunkHeader LoadChunk(uint8_t*& outFile)
52{
53 ChunkHeader head;
54 ::memcpy(&head.type, outFile, 4);
55 outFile += 4;
56 ::memcpy(&head.length, outFile, 4);
57 outFile += 4;
58 AI_LSWAP4(head.length);
59 AI_LSWAP4(head.type);
60 return head;
61}
62
63/////////////////////////////////////////////////////////////////////////////////
64//! Load a sub chunk header
65//! @param outFile Pointer to the file data - points to the chunk data afterwards
66//! @return Copy of the sub chunk header
67/////////////////////////////////////////////////////////////////////////////////
68inline SubChunkHeader LoadSubChunk(uint8_t*& outFile)
69{
70 SubChunkHeader head;
71 ::memcpy(&head.type, outFile, 4);
72 outFile += 4;
73 ::memcpy(&head.length, outFile, 2);
74 outFile += 2;
75 AI_LSWAP2(head.length);
76 AI_LSWAP4(head.type);
77 return head;
78}
79
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/////////////////////////////////////////////////////////////////////////////////
87inline 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 ::memcpy(&fileType, outFile, 4);
95 AI_LSWAP4(fileType);
96 return 0;
97}
98
99
100}}
101
102#endif // !! AI_IFF_H_INCLUDED
103