2008-08-07 22:27:17 +00:00
|
|
|
// Definitions for the Interchange File Format (IFF)
|
|
|
|
// Alexander Gessler, 2006
|
2008-09-20 15:55:51 +00:00
|
|
|
// Adapted to Assimp August 2008
|
2008-08-07 22:27:17 +00:00
|
|
|
|
|
|
|
#ifndef AI_IFF_H_INCLUDED
|
|
|
|
#define AI_IFF_H_INCLUDED
|
|
|
|
|
2015-04-20 22:36:47 +00:00
|
|
|
#include "ByteSwapper.h"
|
2008-08-07 22:27:17 +00:00
|
|
|
|
2008-09-20 15:55:51 +00:00
|
|
|
namespace Assimp {
|
|
|
|
namespace IFF {
|
2008-08-07 22:27:17 +00:00
|
|
|
|
2008-09-20 15:55:51 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
2008-08-07 22:27:17 +00:00
|
|
|
//! Describes an IFF chunk header
|
2008-09-20 15:55:51 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
2008-08-07 22:27:17 +00:00
|
|
|
struct ChunkHeader
|
|
|
|
{
|
|
|
|
//! Type of the chunk header - FourCC
|
|
|
|
uint32_t type;
|
|
|
|
|
|
|
|
//! Length of the chunk data, in bytes
|
|
|
|
uint32_t length;
|
2014-09-05 03:49:48 +00:00
|
|
|
};
|
2008-09-20 15:55:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//! Describes an IFF sub chunk header
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
struct SubChunkHeader
|
|
|
|
{
|
|
|
|
//! Type of the chunk header - FourCC
|
|
|
|
uint32_t type;
|
|
|
|
|
|
|
|
//! Length of the chunk data, in bytes
|
|
|
|
uint16_t length;
|
2014-09-05 03:49:48 +00:00
|
|
|
};
|
2008-08-07 22:27:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define AI_IFF_FOURCC(a,b,c,d) ((uint32_t) (((uint8_t)a << 24u) | \
|
|
|
|
((uint8_t)b << 16u) | ((uint8_t)c << 8u) | ((uint8_t)d)))
|
|
|
|
|
|
|
|
|
|
|
|
#define AI_IFF_FOURCC_FORM AI_IFF_FOURCC('F','O','R','M')
|
|
|
|
|
|
|
|
|
2008-09-20 15:55:51 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//! Load a chunk header
|
|
|
|
//! @param outFile Pointer to the file data - points to the chunk data afterwards
|
2014-09-05 03:49:48 +00:00
|
|
|
//! @return Copy of the chunk header
|
2008-09-20 15:55:51 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
2014-09-05 03:49:48 +00:00
|
|
|
inline ChunkHeader LoadChunk(uint8_t*& outFile)
|
2008-09-20 15:55:51 +00:00
|
|
|
{
|
2014-09-05 03:49:48 +00:00
|
|
|
ChunkHeader head;
|
|
|
|
::memcpy(&head.type, outFile, 4);
|
|
|
|
outFile += 4;
|
|
|
|
::memcpy(&head.length, outFile, 4);
|
|
|
|
outFile += 4;
|
|
|
|
AI_LSWAP4(head.length);
|
|
|
|
AI_LSWAP4(head.type);
|
2008-09-20 15:55:51 +00:00
|
|
|
return head;
|
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//! Load a sub chunk header
|
|
|
|
//! @param outFile Pointer to the file data - points to the chunk data afterwards
|
2014-09-05 03:49:48 +00:00
|
|
|
//! @return Copy of the sub chunk header
|
2008-09-20 15:55:51 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
2014-09-05 03:49:48 +00:00
|
|
|
inline SubChunkHeader LoadSubChunk(uint8_t*& outFile)
|
2008-09-20 15:55:51 +00:00
|
|
|
{
|
2014-09-05 03:49:48 +00:00
|
|
|
SubChunkHeader head;
|
|
|
|
::memcpy(&head.type, outFile, 4);
|
|
|
|
outFile += 4;
|
|
|
|
::memcpy(&head.length, outFile, 2);
|
|
|
|
outFile += 2;
|
|
|
|
AI_LSWAP2(head.length);
|
|
|
|
AI_LSWAP4(head.type);
|
2008-09-20 15:55:51 +00:00
|
|
|
return head;
|
|
|
|
}
|
|
|
|
|
2008-08-07 22:27:17 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//! Read the file header and return the type of the file and its size
|
2015-04-20 22:36:47 +00:00
|
|
|
//! @param outFile Pointer to the file data. The buffer must at
|
2008-08-07 22:27:17 +00:00
|
|
|
//! least be 12 bytes large.
|
|
|
|
//! @param fileType Receives the type of the file
|
|
|
|
//! @return 0 if everything was OK, otherwise an error message
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
2015-04-20 22:36:47 +00:00
|
|
|
inline const char* ReadHeader(uint8_t* outFile, uint32_t& fileType)
|
2008-08-07 22:27:17 +00:00
|
|
|
{
|
2014-09-05 03:49:48 +00:00
|
|
|
ChunkHeader head = LoadChunk(outFile);
|
|
|
|
if(AI_IFF_FOURCC_FORM != head.type)
|
2008-08-07 22:27:17 +00:00
|
|
|
{
|
|
|
|
return "The file is not an IFF file: FORM chunk is missing";
|
|
|
|
}
|
2014-09-05 03:49:48 +00:00
|
|
|
::memcpy(&fileType, outFile, 4);
|
2008-08-07 22:27:17 +00:00
|
|
|
AI_LSWAP4(fileType);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
2008-09-12 20:25:11 +00:00
|
|
|
#endif // !! AI_IFF_H_INCLUDED
|