IFF.h 3.1 KB

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