WRIFF.H 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #ifndef _WRIFF_H_
  2. #define _WRIFF_H_
  3. //////////////////////////////////////////////////////////////////////////////
  4. //////////////////////////////////////////////////////////////////////////////
  5. //
  6. // RIFF.H -- Interface for wrinting RIFF files
  7. //
  8. // By Nitzan Shaked
  9. //
  10. //////////////////////////////////////////////////////////////////////////////
  11. //////////////////////////////////////////////////////////////////////////////
  12. #include <stdio.h>
  13. //#include "avifmt.h"
  14. //////////////////////////////////////////////////////////////////////////////
  15. //////////////////////////////////////////////////////////////////////////////
  16. //////////////////////////////////////////////////////////////////////////////
  17. //
  18. // Chunk types a riff file can contain
  19. //
  20. typedef enum riffSectionType
  21. {
  22. RIFF_SECTION_LIST = 0, // "LIST" (size) "TYPE" (data)
  23. RIFF_SECTION_CHUNK = 1 // "name" (size) (data)
  24. };
  25. //
  26. // Structure used to hold information about a chunk
  27. //
  28. typedef struct _riffSection
  29. {
  30. riffSectionType type; // LIST or CHUNK
  31. long sizeOffset; // Offset in file where size is to be written
  32. long currentSize; // Current size (including subchunks, if any)
  33. } riffSection;
  34. //
  35. // Maximum nesting level for riff files
  36. //
  37. #define MAX_RIFF_NESTING_LEVEL 20
  38. //
  39. // Stack used to hold current structure of riff file
  40. //
  41. typedef riffSection riffStack[MAX_RIFF_NESTING_LEVEL];
  42. //
  43. // Information about one riff file
  44. //
  45. typedef struct _riffFile
  46. {
  47. FILE *f; // The file handler
  48. riffStack stack;
  49. long stackTop; // Stack top (-1 if empty)
  50. } riffFile;
  51. //
  52. // Names and types of lists and chunks
  53. //
  54. typedef char *str4;
  55. //////////////////////////////////////////////////////////////////////////////
  56. //////////////////////////////////////////////////////////////////////////////
  57. //////////////////////////////////////////////////////////////////////////////
  58. //
  59. // Create a new riff file and return a pointer to a "riffFile"
  60. //
  61. // Return NULL if failure
  62. //
  63. riffFile *riffCreate( LPCTSTR filename );
  64. //
  65. // Close a riff file
  66. //
  67. bool riffClose( riffFile *f );
  68. //
  69. // Pads the file to WORD boundry (adds a 0 byte if necessary)
  70. //
  71. bool riffPadWord( riffFile *f );
  72. //
  73. // Pads the file to a given granularity from a given position
  74. //
  75. bool riffPadJunk( riffFile *f,
  76. long granularity,
  77. long from );
  78. //
  79. // Adds a LIST to a riff file
  80. //
  81. bool riffAddList( riffFile *f,
  82. str4 type, // "LIST" or "RIFF"
  83. str4 name );
  84. //
  85. // Adds a CHUNK to a riff file
  86. //
  87. bool riffAddChunk( riffFile *f,
  88. str4 name );
  89. //
  90. // Writes data to the riff file
  91. //
  92. bool riffWriteData( riffFile *f,
  93. void *buf,
  94. long size );
  95. //
  96. // Returns the current position (size) of the riff file
  97. //
  98. long riffSize( riffFile *f );
  99. //
  100. // Closes last section in the riff file
  101. //
  102. bool riffCloseSection( riffFile *f );
  103. bool riffCloseChunk( riffFile *f );
  104. bool riffCloseList( riffFile *f );
  105. //////////////////////////////////////////////////////////////////////////////
  106. //////////////////////////////////////////////////////////////////////////////
  107. //////////////////////////////////////////////////////////////////////////////
  108. #endif _WRIFF_H_