home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / FAQSYS18.ZIP / FAQS.DAT / IFF.DOC < prev    next >
Text File  |  1995-10-13  |  63KB  |  1,425 lines

  1.  
  2.  
  3. "EA IFF 85" Standard for Interchange Format Files
  4.  
  5. Document Date:        January 14, 1985
  6. From:            Jerry Morrison, Electronic Arts
  7. Status of Standard:    Released and in use
  8.  
  9. 1. Introduction
  10.  
  11. Standards are Good for Software Developers
  12.  
  13. As home computer hardware evolves to better and better media machines, 
  14. the demand increases for higher quality, more detailed data. Data 
  15. development gets more expensive, requires more expertise and better 
  16. tools, and has to be shared across projects. Think about several ports 
  17. of a product on one CD-ROM with 500M Bytes of common data!
  18.  
  19. Development tools need standard interchange file formats. Imagine 
  20. scanning in images of "player" shapes, moving them to a paint program 
  21. for editing, then incorporating them into a game. Or writing a theme 
  22. song with a Macintosh score editor and incorporating it into an Amiga 
  23. game. The data must at times be transformed, clipped, filled out, 
  24. and moved across machine kinds. Media projects will depend on data 
  25. transfer from graphic, music, sound effect, animation, and script 
  26. tools.
  27.  
  28. Standards are Good for Software Users
  29.  
  30. Customers should be able to move their own data between independently 
  31. developed software products. And they should be able to buy data libraries 
  32. usable across many such products. The types of data objects to exchange 
  33. are open-ended and include plain and formatted text, raster and structured 
  34. graphics, fonts, music, sound effects, musical instrument descriptions, 
  35. and animation.
  36.  
  37. The problem with expedient file formats typically memory dumps is 
  38. that they're too provincial. By designing data for one particular 
  39. use (e.g. a screen snapshot), they preclude future expansion (would 
  40. you like a full page picture? a multi-page document?). In neglecting 
  41. the possibility that other programs might read their data, they fail 
  42. to save contextual information (how many bit planes? what resolution?). 
  43. Ignoring that other programs might create such files, they're intolerant 
  44. of extra data (texture palette for a picture editor), missing data 
  45. (no color map), or minor variations (smaller image). In practice, 
  46. a filed representation should rarely mirror an in-memory representation. 
  47. The former should be designed for longevity; the latter to optimize 
  48. the manipulations of a particular program. The same filed data will 
  49. be read into different memory formats by different programs.
  50.  
  51. The IFF philosophy: "A little behind-the-scenes conversion when programs 
  52. read and write files is far better than NxM explicit conversion utilities 
  53. for highly specialized formats."
  54.  
  55. So we need some standardization for data interchange among development 
  56. tools and products. The more developers that adopt a standard, the 
  57. better for all of us and our customers.
  58.  
  59. Here is "EA IFF 1985"
  60.  
  61. Here is our offering: Electronic Arts' IFF standard for Interchange 
  62. File Format. The full name is "EA IFF 1985". Alternatives and justifications 
  63. are included for certain choices. Public domain subroutine packages 
  64. and utility programs are available to make it easy to write and use 
  65. IFF-compatible programs.
  66.  
  67. Part 1 introduces the standard. Part 2 presents its requirements and 
  68. background. Parts 3, 4, and 5 define the primitive data types, FORMs, 
  69. and LISTs, respectively, and how to define new high level types. Part 
  70. 6 specifies the top level file structure. Appendix A is included for 
  71. quick reference and Appendix B names the committee responsible for 
  72. this standard.
  73.  
  74. References
  75.  
  76. American National Standard Additional Control Codes for Use with ASCII, 
  77. ANSI standard 3.64-1979 for an 8-bit character set. See also ISO standard 
  78. 2022 and ISO/DIS standard 6429.2.
  79.  
  80. Amiga[tm] is a trademark of Commodore-Amiga, Inc.
  81.  
  82. C, A Reference Manual, Samuel P. Harbison and Guy L. Steele Jr., Tartan 
  83. Laboratories. Prentice-Hall, Englewood Cliffs, NJ, 1984.
  84.  
  85. Compiler Construction, An Advanced Course, edited by F. L. Bauer and 
  86. J. Eickel (Springer-Verlag, 1976). This book is one of many sources 
  87. for information on recursive descent parsing.
  88.  
  89. DIF Technical Specification (c)1981 by Software Arts, Inc. DIF[tm] is 
  90. the format for spreadsheet data interchange developed by Software 
  91. Arts, Inc.
  92. DIF[tm] is a trademark of Software Arts, Inc.
  93.  
  94. Electronic Arts[tm] is a trademark of Electronic Arts.
  95.  
  96. "FTXT" IFF Formatted Text, from Electronic Arts. IFF supplement document 
  97. for a text format.
  98.  
  99. Inside Macintosh (c) 1982, 1983, 1984, 1985 Apple Computer, Inc., a 
  100. programmer's reference manual.
  101. Apple(R) is a trademark of Apple Computer, Inc.
  102. Macintosh[tm] is a trademark licensed to Apple Computer, Inc.
  103.  
  104. "ILBM" IFF Interleaved Bitmap, from Electronic Arts. IFF supplement 
  105. document for a raster image format.
  106.  
  107. M68000 16/32-Bit Microprocessor Programmer's Reference Manual(c) 1984, 
  108. 1982, 1980, 1979 by Motorola, Inc.
  109.  
  110. PostScript Language Manual (c) 1984 Adobe Systems Incorporated.
  111. PostScript[tm] is a trademark of Adobe Systems, Inc.
  112. Times and Helvetica(R) are trademarks of Allied Corporation.
  113.  
  114. InterScript: A Proposal for a Standard for the Interchange of Editable 
  115. Documents (c)1984 Xerox Corporation.
  116. Introduction to InterScript (c) 1985 Xerox Corporation.
  117.  
  118.  
  119.  
  120. 2. Background for Designers
  121.  
  122. Part 2 is about the background, requirements, and goals for the standard. 
  123. It's geared for people who want to design new types of IFF objects. 
  124. People just interested in using the standard may wish to skip this 
  125. part.
  126.  
  127. What Do We Need?
  128.  
  129. A standard should be long on prescription and short on overhead. It 
  130. should give lots of rules for designing programs and data files for 
  131. synergy. But neither the programs nor the files should cost too much 
  132. more than the expedient variety. While we're looking to a future with 
  133. CD-ROMs and perpendicular recording, the standard must work well on 
  134. floppy disks.
  135.  
  136. For program portability, simplicity, and efficiency, formats should 
  137. be designed with more than one implementation style in mind. (In practice, 
  138. pure stream I/O is adequate although random access makes it easier 
  139. to write files.) It ought to be possible to read one of many objects 
  140. in a file without scanning all the preceding data. Some programs need 
  141. to read and play out their data in real time, so we need good compromises 
  142. between generality and efficiency.
  143.  
  144. As much as we need standards, they can't hold up product schedules. 
  145. So we also need a kind of decentralized extensibility where any software 
  146. developer can define and refine new object types without some "standards 
  147. authority" in the loop. Developers must be able to extend existing 
  148. formats in a forward- and backward-compatible way. A central repository 
  149. for design information and example programs can help us take full 
  150. advantage of the standard.
  151.  
  152. For convenience, data formats should heed the restrictions of various 
  153. processors and environments. E.g. word-alignment greatly helps 68000 
  154. access at insignificant cost to 8088 programs.
  155.  
  156. Other goals include the ability to share common elements over a list 
  157. of objects and the ability to construct composite objects containing 
  158. other data objects with structural information like directories.
  159.  
  160. And finally, "Simple things should be simple and complex things should 
  161. be possible."    Alan Kay.
  162.  
  163. Think Ahead
  164.  
  165. Let's think ahead and build programs that read and write files for 
  166. each other and for programs yet to be designed. Build data formats 
  167. to last for future computers so long as the overhead is acceptable. 
  168. This extends the usefulness and life of today's programs and data.
  169.  
  170. To maximize interconnectivity, the standard file structure and the 
  171. specific object formats must all be general and extensible. Think 
  172. ahead when designing an object. It should serve many purposes and 
  173. allow many programs to store and read back all the information they 
  174. need; even squeeze in custom data. Then a programmer can store the 
  175. available data and is encouraged to include fixed contextual details. 
  176. Recipient programs can read the needed parts, skip unrecognized stuff, 
  177. default missing data, and use the stored context to help transform 
  178. the data as needed.
  179.  
  180. Scope
  181.  
  182. IFF addresses these needs by defining a standard file structure, some 
  183. initial data object types, ways to define new types, and rules for 
  184. accessing these files. We can accomplish a great deal by writing programs 
  185. according to this standard, but don't expect direct compatibility 
  186. with existing software. We'll need conversion programs to bridge the 
  187. gap from the old world.
  188.  
  189. IFF is geared for computers that readily process information in 8-bit 
  190. bytes. It assumes a "physical layer" of data storage and transmission 
  191. that reliably maintains "files" as strings of 8-bit bytes. The standard 
  192. treats a "file" as a container of data bytes and is independent of 
  193. how to find a file and whether it has a byte count.
  194.  
  195. This standard does not by itself implement a clipboard for cutting 
  196. and pasting data between programs. A clipboard needs software to mediate 
  197. access, to maintain a "contents version number" so programs can detect 
  198. updates, and to manage the data in "virtual memory".
  199.  
  200. Data Abstraction
  201.  
  202. The basic problem is how to represent information  in a way that's 
  203. program-independent, compiler- independent, machine-independent, and 
  204. device-independent.
  205.  
  206. The computer science approach is "data abstraction", also known as 
  207. "objects", "actors", and "abstract data types". A data abstraction 
  208. has a "concrete representation" (its storage format), an "abstract 
  209. representation" (its capabilities and uses), and access procedures 
  210. that isolate all the calling software from the concrete representation. 
  211. Only the access procedures touch the data storage. Hiding mutable 
  212. details behind an interface is called "information hiding". What data 
  213. abstraction does is abstract from details of implementing the object, 
  214. namely the selected storage representation and algorithms for manipulating 
  215. it.
  216.  
  217. The power of this approach is modularity. By adjusting the access 
  218. procedures we can extend and restructure the data without impacting 
  219. the interface or its callers. Conversely, we can extend and restructure 
  220. the interface and callers without making existing data obsolete. It's 
  221. great for interchange!
  222.  
  223. But we seem to need the opposite: fixed file formats for all programs 
  224. to access. Actually, we could file data abstractions ("filed objects") 
  225. by storing the data and access procedures together. We'd have to encode 
  226. the access procedures in a standard machine-independent programming 
  227. language   la PostScript. Even still, the interface can't evolve freely 
  228. since we can't update all copies of the access procedures. So we'll 
  229. have to design our abstract representations for limited evolution 
  230. and occasional revolution (conversion).
  231.  
  232. In any case, today's microcomputers can't practically store data abstractions. 
  233. They can do the next best thing: store arbitrary types of data in 
  234. "data chunks", each with a type identifier and a length count. The 
  235. type identifier is a reference by name to the access procedures (any 
  236. local implementation). The length count enables storage-level object 
  237. operations like "copy" and "skip to next" independent of object type.
  238.  
  239. Chunk writing is straightforward. Chunk reading requires a trivial 
  240. parser to scan each chunk and dispatch to the proper access/conversion 
  241. procedure. Reading chunks nested inside other chunks requires recursion, 
  242. but no lookahead or backup.
  243.  
  244. That's the main idea of IFF. There are, of course, a few other detailsI
  245.  
  246. Previous Work
  247.  
  248. Where our needs are similar, we borrow from existing standards.
  249.  
  250. Our basic need to move data between independently developed programs 
  251. is similar to that addressed by the Apple Macintosh desk scrap or 
  252. "clipboard" [Inside Macintosh chapter "Scrap Manager"]. The Scrap 
  253. Manager works closely with the Resource Manager, a handy filer and 
  254. swapper for data objects (text strings, dialog window templates, pictures, 
  255. fontsI) including types yet to be designed [Inside Macintosh chapter 
  256. "Resource Manager"]. The Resource Manager is a kin to Smalltalk's 
  257. object swapper.
  258.  
  259. We will probably write a Macintosh desk accessory that converts IFF 
  260. files to and from the Macintosh clipboard for quick and easy interchange 
  261. with programs like MacPaint and Resource Mover.
  262.  
  263. Macintosh uses a simple and elegant scheme of 4-character "identifiers" 
  264. to identify resource types, clipboard format types, file types, and 
  265. file creator programs. Alternatives are unique ID numbers assigned 
  266. by a central authority or by hierarchical authorities, unique ID numbers 
  267. generated by algorithm, other fixed length character strings, and 
  268. variable length strings. Character string identifiers double as readable 
  269. signposts in data files and programs. The choice of 4 characters is 
  270. a good tradeoff between storage space, fetch/compare/store time, and 
  271. name space size. We'll honor Apple's designers by adopting this scheme.
  272.  
  273. "PICT" is a good example of a standard structured graphics format 
  274. (including raster images) and its many uses [Inside Macintosh chapter 
  275. "QuickDraw"]. Macintosh provides QuickDraw routines in ROM to create, 
  276. manipulate, and display PICTs. Any application can create a PICT by 
  277. simply asking QuickDraw to record a sequence of drawing commands. 
  278. Since it's just as easy to ask QuickDraw to render a PICT to a screen 
  279. or a printer, it's very effective to pass them between programs, say 
  280. from an illustrator to a word processor. An important feature is the 
  281. ability to store "comments" in a PICT which QuickDraw will ignore. 
  282. Actually, it passes them to your optional custom "comment handler".
  283.  
  284. PostScript, Adobe's print file standard, is a more general way to 
  285. represent any print image (which is a specification for putting marks 
  286. on paper) [PostScript Language Manual]. In fact, PostScript is a full-fledged 
  287. programming language. To interpret a PostScript program is to render 
  288. a document on a raster output device. The language is defined in layers: 
  289. a lexical layer of identifiers, constants, and operators; a layer 
  290. of reverse polish semantics including scope rules and a way to define 
  291. new subroutines; and a printing-specific layer of built-in identifiers 
  292. and operators for rendering graphic images. It is clearly a powerful 
  293. (Turing equivalent) image definition language. PICT and a subset of 
  294. PostScript are candidates for structured graphics standards.
  295.  
  296. A PostScript document can be printed on any raster output device (including 
  297. a display) but cannot generally be edited. That's because the original 
  298. flexibility and constraints have been discarded. Besides, a PostScript 
  299. program may use arbitrary computation to supply parameters like placement 
  300. and size to each operator. A QuickDraw PICT, in comparison, is a more 
  301. restricted format of graphic primitives parameterized by constants. 
  302. So a PICT can be edited at the level of the primitives, e.g. move 
  303. or thicken a line. It cannot be edited at the higher level of, say, 
  304. the bar chart data which generated the picture.
  305.  
  306. PostScript has another limitation: Not all kinds of data amount to 
  307. marks on paper. A musical instrument description is one example. PostScript 
  308. is just not geared for such uses.
  309.  
  310. "DIF" is another example of data being stored in a general format 
  311. usable by future programs [DIF Technical Specification]. DIF is a 
  312. format for spreadsheet data interchange. DIF and PostScript are both 
  313. expressed in plain ASCII text files. This is very handy for printing, 
  314. debugging, experimenting, and transmitting across modems. It can have 
  315. substantial cost in compaction and read/write work, depending on use. 
  316. We won't store IFF files this way but we could define an ASCII alternate 
  317. representation with a converter program.
  318.  
  319. InterScript is Xerox' standard for interchange of editable documents 
  320. [Introduction to InterScript]. It approaches a harder problem: How 
  321. to represent editable word processor documents that may contain formatted 
  322. text, pictures, cross-references like figure numbers, and even highly 
  323. specialized objects like mathematical equations? InterScript aims 
  324. to define one standard representation for each kind of information. 
  325. Each InterScript-compatible editor is supposed to preserve the objects 
  326. it doesn't understand and even maintain nested cross-references. So 
  327. a simple word processor would let you edit the text of a fancy document 
  328. without discarding the equations or disrupting the equation numbers.
  329.  
  330. Our task is similarly to store high level information and preserve 
  331. as much content as practical while moving it between programs. But 
  332. we need to span a larger universe of data types and cannot expect 
  333. to centrally define them all. Fortunately, we don't need to make programs 
  334. preserve information that they don't understand. And for better or 
  335. worse, we don't have to tackle general-purpose cross-references yet.
  336.  
  337.  
  338.  
  339. 3. Primitive Data Types
  340.  
  341. Atomic components such as integers and characters that are interpretable 
  342. directly by the CPU are specified in one format for all processors. 
  343. We chose a format that's most convenient for the Motorola MC68000 
  344. processor [M68000 16/32-Bit Microprocessor Programmer's Reference 
  345. Manual].
  346.  
  347. N.B.: Part 3 dictates the format for "primitive" data types where and 
  348. only where used in the overall file structure and standard kinds of 
  349. chunks (Cf. Chunks). The number of such occurrences will be small 
  350. enough that the costs of conversion, storage, and management of processor-
  351. specific files would far exceed the costs of conversion during I/O by "foreign" 
  352. programs. A particular data chunk may be specified with a different 
  353. format for its internal primitive types or with processor- or environment-
  354. speci fic variants if necessary to optimize local usage. Since that hurts 
  355. data interchange, it's not recommended. (Cf. Designing New Data Sections, 
  356. in Part 4.)
  357.  
  358. Alignment
  359.  
  360. All data objects larger than a byte are aligned on even byte addresses 
  361. relative to the start of the file. This may require padding. Pad bytes 
  362. are to be written as zeros, but don't count on that when reading.
  363.  
  364. This means that every odd-length "chunk" (see below) must be padded 
  365. so that the next one will fall on an even boundary. Also, designers 
  366. of structures to be stored in chunks should include pad fields where 
  367. needed to align every field larger than a byte. Zeros should be stored 
  368. in all the pad bytes.
  369.  
  370. Justification: Even-alignment causes a little extra work for files 
  371. that are used only on certain processors but allows 68000 programs 
  372. to construct and scan the data in memory and do block I/O. You just 
  373. add an occasional pad field to data structures that you're going to 
  374. block read/write or else stream read/write an extra byte. And the 
  375. same source code works on all processors. Unspecified alignment, on 
  376. the other hand, would force 68000 programs to (dis)assemble word and 
  377. long-word data one byte at a time. Pretty cumbersome in a high level 
  378. language. And if you don't conditionally compile that out for other 
  379. processors, you won't gain anything.
  380.  
  381. Numbers
  382.  
  383. Numeric types supported are two's complement binary integers in the 
  384. format used by the MC68000 processor high byte first, high word first the 
  385. reverse of 8088 and 6502 format. They could potentially include signed 
  386. and unsigned 8, 16, and 32 bit integers but the standard only uses 
  387. the following:
  388.  
  389. UBYTE     8 bits unsigned
  390. WORD    16 bits signed
  391. UWORD    16 bits unsigned
  392. LONG    32 bits signed
  393.  
  394. The actual type definitions depend on the CPU and the compiler. In 
  395. this document, we'll express data type definitions in the C programming 
  396. language. [See C, A Reference Manual.] In 68000 Lattice C:
  397.  
  398. typedef unsigned char    UBYTE;    /*  8 bits unsigned    */
  399. typedef short    WORD;    /* 16 bits signed    */
  400. typedef unsigned short    UWORD;    /* 16 bits unsigned    */
  401. typedef long    LONG;    /* 32 bits signed    */
  402.  
  403. Characters
  404.  
  405. The following character set is assumed wherever characters are used, 
  406. e.g. in text strings, IDs, and TEXT chunks (see below).
  407.  
  408. Characters are encoded in 8-bit ASCII. Characters in the range NUL 
  409. (hex 0) through DEL (hex 7F) are well defined by the 7-bit ASCII standard. 
  410. IFF uses the graphic group RJS (SP, hex 20) through R~S (hex 7E).
  411.  
  412. Most of the control character group hex 01 through hex 1F have no 
  413. standard meaning in IFF. The control character LF (hex 0A) is defined 
  414. as a "newline" character. It denotes an intentional line break, that 
  415. is, a paragraph or line terminator. (There is no way to store an automatic 
  416. line break. That is strictly a function of the margins in the environment 
  417. the text is placed.) The control character ESC (hex 1B) is a reserved 
  418. escape character under the rules of ANSI standard 3.64-1979 American 
  419. National Standard Additional Control Codes for Use with ASCII, ISO 
  420. standard 2022, and ISO/DIS standard 6429.2.
  421.  
  422. Characters in the range hex 7F through hex FF are not globally defined 
  423. in IFF. They are best left reserved for future standardization. But 
  424. note that the FORM type FTXT (formatted text) defines the meaning 
  425. of these characters within FTXT forms. In particular, character values 
  426. hex 7F through hex 9F are control codes while characters hex A0 through 
  427. hex FF are extended graphic characters like  , as per the ISO and 
  428. ANSI standards cited above. [See the supplementary document "FTXT" 
  429. IFF Formatted Text.]
  430.  
  431. Dates
  432.  
  433. A "creation date" is defined as the date and time a stream of data 
  434. bytes was created. (Some systems call this a "last modified date".) 
  435. Editing some data changes its creation date. Moving the data between 
  436. volumes or machines does not.
  437.  
  438. The IFF standard date format will be one of those used in MS-DOS, 
  439. Macintosh, or Amiga DOS (probably a 32-bit unsigned number of seconds 
  440. since a reference point). Issue: Investigate these three.
  441.  
  442. Type IDs
  443.  
  444. A "type ID", "property name", "FORM type", or any other IFF identifier 
  445. is a 32-bit value: the concatenation of four ASCII characters in the 
  446. range R S (SP, hex 20) through R~S (hex 7E). Spaces (hex 20) should 
  447. not precede printing characters; trailing spaces are ok. Control characters 
  448. are forbidden.
  449.  
  450. typedef CHAR ID[4];
  451.  
  452. IDs are compared using a simple 32-bit case-dependent equality test.
  453.  
  454. Data section type IDs (aka FORM types) are restriced IDs. (Cf. Data 
  455. Sections.) Since they may be stored in filename extensions (Cf. Single 
  456. Purpose Files) lower case letters and punctuation marks are forbidden. 
  457. Trailing spaces are ok.
  458.  
  459. Carefully choose those four characters when you pick a new ID. Make 
  460. them mnemonic so programmers can look at an interchange format file 
  461. and figure out what kind of data it contains. The name space makes 
  462. it possible for developers scattered around the globe to generate 
  463. ID values with minimal collisions so long as they choose specific 
  464. names like "MUS4" instead of general ones like "TYPE" and "FILE". 
  465. EA will "register" new FORM type IDs and format descriptions as they're 
  466. devised, but collisions will be improbable so there will be no pressure 
  467. on this "clearinghouse" process. Appendix A has a list of currently 
  468. defined IDs.
  469.  
  470. Sometimes it's necessary to make data format changes that aren't backward 
  471. compatible. Since IDs are used to denote data formats in IFF, new 
  472. IDs are chosen to denote revised formats. Since programs won't read 
  473. chunks whose IDs they don't recognize (see Chunks, below), the new 
  474. IDs keep old programs from stumbling over new data. The conventional 
  475. way to chose a "revision" ID is to increment the last character if 
  476. it's a digit or else change the last character to a digit. E.g. first 
  477. and second revisions of the ID "XY" would be "XY1" and "XY2". Revisions 
  478. of "CMAP" would be "CMA1" and "CMA2".
  479.  
  480. Chunks
  481.  
  482. Chunks are the building blocks in the IFF structure. The form expressed 
  483. as a C typedef is:
  484.  
  485. typedef struct {
  486.     ID    ckID;
  487.     LONG    ckSize;    /* sizeof(ckData) */
  488.     UBYTE    ckData[/* ckSize */];
  489.     } Chunk;
  490.  
  491. We can diagram an example chunk a "CMAP" chunk containing 12 data 
  492. bytes like this:
  493.             ----------------
  494.         ckID:    |    'CMAP'    |
  495.         ckSize: |      12      |
  496.         ckData: | 0, 0, 0, 32  |   -------- 
  497.             | 0, 0, 64, 0  |    12 bytes
  498.             | 0, 0, 64, 0  |   ---------
  499.             ----------------
  500.  
  501. The fixed header part means "Here's a type ckID chunk with ckSize 
  502. bytes of data."
  503.  
  504. The ckID identifies the format and purpose of the chunk. As a rule, 
  505. a program must recognize ckID to interpret ckData. It should skip 
  506. over all unrecognized chunks. The ckID also serves as a format version 
  507. number as long as we pick new IDs to identify new formats of ckData 
  508. (see above).
  509.  
  510. The following ckIDs are universally reserved to identify chunks with 
  511. particular IFF meanings: "LIST", "FORM", "PROP", "CAT ", and "    
  512. ". The special ID "    " (4 spaces) is a ckID for "filler" chunks, 
  513. that is, chunks that fill space but have no meaningful contents. The 
  514. IDs "LIS1" through "LIS9", "FOR1" through "FOR9", and "CAT1" through 
  515. "CAT9" are reserved for future "version number" variations. All IFF-compatible 
  516. software must account for these 23 chunk IDs. Appendix A has a list 
  517. of predefined IDs.
  518.  
  519. The ckSize is a logical block size how many data bytes are in ckData. 
  520. If ckData is an odd number of bytes long, a 0 pad byte follows which 
  521. is not included in ckSize. (Cf. Alignment.) A chunk's total physical 
  522. size is ckSize rounded up to an even number plus the size of the header. 
  523. So the smallest chunk is 8 bytes long with ckSize = 0. For the sake 
  524. of following chunks, programs must respect every chunk's ckSize as 
  525. a virtual end-of-file for reading its ckData even if that data is 
  526. malformed, e.g. if nested contents are truncated.
  527.  
  528. We can describe the syntax of a chunk as a regular expression with 
  529. "#" representing the ckSize, i.e. the length of the following {braced} 
  530. bytes. The "[0]" represents a sometimes needed pad byte. (The regular 
  531. expressions in this document are collected in Appendix A along with 
  532. an explanation of notation.)
  533.  
  534. Chunk    ::= ID #{ UBYTE* } [0]
  535.  
  536. One chunk output technique is to stream write a chunk header, stream 
  537. write the chunk contents, then random access back to the header to 
  538. fill in the size. Another technique is to make a preliminary pass 
  539. over the data to compute the size, then write it out all at once.
  540.  
  541. Strings, String Chunks, and String Properties
  542.  
  543. In a string of ASCII text, LF denotes a forced line break (paragraph 
  544. or line terminator). Other control characters are not used. (Cf. Characters.)
  545.  
  546. The ckID for a chunk that contains a string of plain, unformatted 
  547. text is "TEXT". As a practical matter, a text string should probably 
  548. not be longer than 32767 bytes. The standard allows up to 231 - 1 
  549. bytes.
  550.  
  551. When used as a data property (see below), a text string chunk may 
  552. be 0 to 255 characters long. Such a string is readily converted to 
  553. a C string or a Pascal STRING[255]. The ckID of a property must be 
  554. the property name, not "TEXT".
  555.  
  556. When used as a part of a chunk or data property, restricted C string 
  557. format is normally used. That means 0 to 255 characters followed by 
  558. a NUL byte (ASCII value 0).
  559.  
  560. Data Properties
  561.  
  562. Data properties specify attributes for following (non-property) chunks. 
  563. A data property essentially says "identifier = value", for example 
  564. "XY = (10, 200)", telling something about following chunks. Properties 
  565. may only appear inside data sections ("FORM" chunks, cf. Data Sections) 
  566. and property sections ("PROP" chunks, cf. Group PROP).
  567.  
  568. The form of a data property is a special case of Chunk. The ckID is 
  569. a property name as well as a property type. The ckSize should be small 
  570. since data properties are intended to be accumulated in RAM when reading 
  571. a file. (256 bytes is a reasonable upper bound.) Syntactically:
  572.  
  573. Property    ::= Chunk
  574.  
  575. When designing a data object, use properties to describe context information 
  576. like the size of an image, even if they don't vary in your program. 
  577. Other programs will need this information.
  578.  
  579. Think of property settings as assignments to variables in a programming 
  580. language. Multiple assignments are redundant and local assignments 
  581. temporarily override global assignments. The order of assignments 
  582. doesn't matter as long as they precede the affected chunks. (Cf. LISTs, 
  583. CATs, and Shared Properties.)
  584.  
  585. Each object type (FORM type) is a local name space for property IDs. 
  586. Think of a "CMAP" property in a "FORM ILBM" as the qualified ID "ILBM.CMAP". 
  587. Property IDs specified when an object type is designed (and therefore 
  588. known to all clients) are called "standard" while specialized ones 
  589. added later are "nonstandard".
  590.  
  591. Links
  592.  
  593. Issue: A standard mechanism for "links" or "cross references" is very 
  594. desirable for things like combining images and sounds into animations. 
  595. Perhaps we'll define "link" chunks within FORMs that refer to other 
  596. FORMs or to specific chunks within the same and other FORMs. This 
  597. needs further work. EA IFF 1985 has no standard link mechanism.
  598.  
  599. For now, it may suffice to read a list of, say, musical instruments, 
  600. and then just refer to them within a musical score by index number.
  601.  
  602. File References
  603.  
  604. Issue: We may need a standard form for references to other files. 
  605. A "file ref" could name a directory and a file in the same type of 
  606. operating system as the ref's originator. Following the reference 
  607. would expect the file to be on some mounted volume. In a network environment, 
  608. a file ref could name a server, too.
  609.  
  610. Issue: How can we express operating-system independent file refs?
  611.  
  612. Issue: What about a means to reference a portion of another file? 
  613. Would this be a "file ref" plus a reference to a "link" within the 
  614. target file?
  615.  
  616.  
  617.  
  618. 4. Data Sections
  619.  
  620. The first thing we need of a file is to check: Does it contain IFF 
  621. data and, if so, does it contain the kind of data we're looking for? 
  622. So we come to the notion of a "data section".
  623.  
  624. A "data section" or IFF "FORM" is one self-contained "data object" 
  625. that might be stored in a file by itself. It is one high level data 
  626. object such as a picture or a sound effect. The IFF structure "FORM" 
  627. makes it self- identifying. It could be a composite object like a 
  628. musical score with nested musical instrument descriptions.
  629.  
  630. Group FORM
  631.  
  632. A data section is a chunk with ckID "FORM" and this arrangement:
  633.  
  634. FORM    ::= "FORM" #{ FormType (LocalChunk | FORM | LIST | CAT)* 
  635. }
  636. FormType    ::= ID
  637. LocalChunk    ::= Property | Chunk
  638.  
  639. The ID "FORM" is a syntactic keyword like "struct" in C. Think of 
  640. a "struct ILBM" containing a field "CMAP". If you see "FORM" you'll 
  641. know to expect a FORM type ID (the structure name, "ILBM" in this 
  642. example) and a particular contents arrangement or "syntax" (local 
  643. chunks, FORMs, LISTs, and CATs). (LISTs and CATs are discussed in 
  644. part 5, below.) A "FORM ILBM", in particular, might contain a local 
  645. chunk "CMAP", an "ILBM.CMAP" (to use a qualified name).
  646.  
  647. So the chunk ID "FORM" indicates a data section. It implies that the 
  648. chunk contains an ID and some number of nested chunks. In reading 
  649. a FORM, like any other chunk, programs must respect its ckSize as 
  650. a virtual end-of-file for reading its contents, even if they're truncated.
  651.  
  652. The FormType (or FORM type) is a restricted ID that may not contain 
  653. lower case letters or punctuation characters. (Cf. Type IDs. Cf. Single 
  654. Purpose Files.)
  655.  
  656. The type-specific information in a FORM is composed of its "local 
  657. chunks": data properties and other chunks. Each FORM type is a local 
  658. name space for local chunk IDs. So "CMAP" local chunks in other FORM 
  659. types may be unrelated to "ILBM.CMAP". More than that, each FORM type 
  660. defines semantic scope. If you know what a FORM ILBM is, you'll know 
  661. what an ILBM.CMAP is.
  662.  
  663. Local chunks defined when the FORM type is designed (and therefore 
  664. known to all clients of this type) are called "standard" while specialized 
  665. ones added later are "nonstandard".
  666.  
  667. Among the local chunks, property chunks give settings for various 
  668. details like text font while the other chunks supply the essential 
  669. information. This distinction is not clear cut. A property setting 
  670. cancelled by a later setting of the same property has effect only 
  671. on data chunks in between. E.g. in the sequence:
  672.  
  673. prop1 = x  (propN = value)*  prop1 = y
  674.  
  675. where the propNs are not prop1, the setting prop1 = x has no effect.
  676.  
  677. The following universal chunk IDs are reserved inside any FORM: "LIST", 
  678. "FORM", "PROP", "CAT ", "JJJJ", "LIS1" through "LIS9", "FOR1" through 
  679. "FOR9", and "CAT1" through "CAT9". (Cf. Chunks. Cf. Group LIST. Cf. 
  680. Group PROP.) For clarity, these universal chunk names may not be FORM 
  681. type IDs, either.
  682.  
  683. Part 5, below, talks about grouping FORMs into LISTs and CATs. They 
  684. let you group a bunch of FORMs but don't impose any particular meaning 
  685. or constraints on the grouping. Read on.
  686.  
  687. Composite FORMs
  688.  
  689. A FORM chunk inside a FORM is a full-fledged data section. This means 
  690. you can build a composite object like a multi-frame animation sequence 
  691. from available picture FORMs and sound effect FORMs. You can insert 
  692. additional chunks with information like frame rate and frame count.
  693.  
  694. Using composite FORMs, you leverage on existing programs that create 
  695. and edit the component FORMs. Those editors may even look into your 
  696. composite object to copy out its type of component, although it'll 
  697. be the rare program that's fancy enough to do that. Such editors are 
  698. not allowed to replace their component objects within your composite 
  699. object. That's because the IFF standard lets you specify consistency 
  700. requirements for the composite FORM such as maintaining a count or 
  701. a directory of the components. Only programs that are written to uphold 
  702. the rules of your FORM type should create or modify such FORMs.
  703.  
  704. Therefore, in designing a program that creates composite objects, 
  705. you are strongly requested to provide a facility for your users to 
  706. import and export the nested FORMs. Import and export could move the 
  707. data through a clipboard or a file.
  708.  
  709. Here are several existing FORM types and rules for defining new ones.
  710.  
  711. FTXT
  712.  
  713. An FTXT data section contains text with character formatting information 
  714. like fonts and faces. It has no paragraph or document formatting information 
  715. like margins and page headers. FORM FTXT is well matched to the text 
  716. representation in Amiga's Intuition environment. See the supplemental 
  717. document "FTXT" IFF Formatted Text.
  718.  
  719. ILBM
  720.  
  721. "ILBM" is an InterLeaved BitMap image with color map; a machine-independent 
  722. format for raster images. FORM ILBM is the standard image file format 
  723. for the Commodore-Amiga computer and is useful in other environments, 
  724. too. See the supplemental document "ILBM" IFF Interleaved Bitmap.
  725.  
  726. PICS
  727.  
  728. The data chunk inside a "PICS" data section has ID "PICT" and holds 
  729. a QuickDraw picture. Issue: Allow more than one PICT in a PICS? See 
  730. Inside Macintosh chapter "QuickDraw" for details on PICTs and how 
  731. to create and display them on the Macintosh computer.
  732.  
  733. The only standard property for PICS is "XY", an optional property 
  734. that indicates the position of the PICT relative to "the big picture". 
  735. The contents of an XY is a QuickDraw Point.
  736.  
  737. Note: PICT may be limited to Macintosh use, in which case there'll 
  738. be another format for structured graphics in other environments.
  739.  
  740. Other Macintosh Resource Types
  741.  
  742. Some other Macintosh resource types could be adopted for use within 
  743. IFF files; perhaps MWRT, ICN, ICN#, and STR#.
  744.  
  745. Issue: Consider the candidates and reserve some more IDs.
  746.  
  747. Designing New Data Sections
  748.  
  749. Supplemental documents will define additional object types. A supplement 
  750. needs to specify the object's purpose, its FORM type ID, the IDs and 
  751. formats of standard local chunks, and rules for generating and interpreting 
  752. the data. It's a good idea to supply typedefs and an example source 
  753. program that accesses the new object. See "ILBM" IFF Interleaved Bitmap 
  754. for a good example.
  755.  
  756. Anyone can pick a new FORM type ID but should reserve it with Electronic 
  757. Arts at their earliest convenience. [Issue: EA contact person? Hand 
  758. this off to another organization?] While decentralized format definitions 
  759. and extensions are possible in IFF, our preference is to get design 
  760. consensus by committee, implement a program to read and write it, 
  761. perhaps tune the format, and then publish the format with example 
  762. code. Some organization should remain in charge of answering questions 
  763. and coordinating extensions to the format.
  764.  
  765. If it becomes necessary to revise the design of some data section, 
  766. its FORM type ID will serve as a version number (Cf. Type IDs). E.g. 
  767. a revised "VDEO" data section could be called "VDE1". But try to get 
  768. by with compatible revisions within the existing FORM type.
  769.  
  770. In a new FORM type, the rules for primitive data types and word-alignment 
  771. (Cf. Primitive Data Types) may be overriden for the contents of its 
  772. local chunks but not for the chunk structure itself if your documentation 
  773. spells out the deviations. If machine-specific type variants are needed, 
  774. e.g. to store vast numbers of integers in reverse bit order, then 
  775. outline the conversion algorithm and indicate the variant inside each 
  776. file, perhaps via different FORM types. Needless to say, variations 
  777. should be minimized.
  778.  
  779. In designing a FORM type, encapsulate all the data that other programs 
  780. will need to interpret your files. E.g. a raster graphics image should 
  781. specify the image size even if your program always uses 320 x 200 
  782. pixels x 3 bitplanes. Receiving programs are then empowered to append 
  783. or clip the image rectangle, to add or drop bitplanes, etc. This enables 
  784. a lot more compatibility.
  785.  
  786. Separate the central data (like musical notes) from more specialized 
  787. information (like note beams) so simpler programs can extract the 
  788. central parts during read-in. Leave room for expansion so other programs 
  789. can squeeze in new kinds of information (like lyrics). And remember 
  790. to keep the property chunks manageably short let's say 2 256 bytes.
  791.  
  792. When designing a data object, try to strike a good tradeoff between 
  793. a super-general format and a highly-specialized one. Fit the details 
  794. to at least one particular need, for example a raster image might 
  795. as well store pixels in the current machine's scan order. But add 
  796. the kind of generality that makes it usable with foreseeable hardware 
  797. and software. E.g. use a whole byte for each red, green, and blue 
  798. color value even if this year's computer has only 4-bit video DACs. 
  799. Think ahead and help other programs so long as the overhead is acceptable. 
  800. E.g. run compress a raster by scan line rather than as a unit so future 
  801. programs can swap images by scan line to and from secondary storage.
  802.  
  803. Try to design a general purpose "least common multiple" format that 
  804. encompasses the needs of many programs without getting too complicated. 
  805. Let's coalesce our uses around a few such formats widely separated 
  806. in the vast design space. Two factors make this flexibility and simplicity 
  807. practical. First, file storage space is getting very plentiful, so 
  808. compaction is not a priority. Second, nearly any locally-performed 
  809. data conversion work during file reading and writing will be cheap 
  810. compared to the I/O time.
  811.  
  812. It must be ok to copy a LIST or FORM or CAT intact, e.g. to incorporate 
  813. it into a composite FORM. So any kind of internal references within 
  814. a FORM must be relative references. They could be relative to the 
  815. start of the containing FORM, relative from the referencing chunk, 
  816. or a sequence number into a collection.
  817.  
  818. With composite FORMs, you leverage on existing programs that create 
  819. and edit the components. If you write a program that creates composite 
  820. objects, please provide a facility for your users to import and export 
  821. the nested FORMs. The import and export functions may move data through 
  822. a separate file or a clipboard.
  823.  
  824. Finally, don't forget to specify all implied rules in detail.
  825.  
  826.  
  827.  
  828. 5. LISTs, CATs, and Shared Properties
  829.  
  830. Data often needs to be grouped together like a list of icons. Sometimes 
  831. a trick like arranging little images into a big raster works, but 
  832. generally they'll need to be structured as a first class group. The 
  833. objects "LIST" and "CAT" are IFF-universal mechanisms for this purpose.
  834.  
  835. Property settings sometimes need to be shared over a list of similar 
  836. objects. E.g. a list of icons may share one color map. LIST provides 
  837. a means called "PROP" to do this. One purpose of a LIST is to define 
  838. the scope of a PROP. A "CAT", on the other hand, is simply a concatenation 
  839. of objects.
  840.  
  841. Simpler programs may skip LISTs and PROPs altogether and just handle 
  842. FORMs and CATs. All "fully-conforming" IFF programs also know about 
  843. "CAT ", "LIST", and "PROP". Any program that reads a FORM inside a 
  844. LIST must process shared PROPs to correctly interpret that FORM.
  845.  
  846. Group CAT
  847.  
  848. A CAT is just an untyped group of data objects.
  849.  
  850. Structurally, a CAT is a chunk with chunk ID "CAT " containing a "contents 
  851. type" ID followed by the nested objects. The ckSize of each contained 
  852. chunk is essentially a relative pointer to the next one.
  853.  
  854. CAT    ::= "CAT " #{ ContentsType (FORM | LIST | CAT)* }
  855. ContentsType    ::= ID    -- a hint or an "abstract data type" ID
  856.  
  857. In reading a CAT, like any other chunk, programs must respect it's 
  858. ckSize as a virtual end-of-file for reading the nested objects even 
  859. if they're malformed or truncated.
  860.  
  861. The "contents type" following the CAT's ckSize indicates what kind 
  862. of FORMs are inside. So a CAT of ILBMs would store "ILBM" there. It's 
  863. just a hint. It may be used to store an "abstract data type". A CAT 
  864. could just have blank contents ID ("JJJJ") if it contains more than 
  865. one kind of FORM.
  866.  
  867. CAT defines only the format of the group. The group's meaning is open 
  868. to interpretation. This is like a list in LISP: the structure of cells 
  869. is predefined but the meaning of the contents as, say, an association 
  870. list depends on use. If you need a group with an enforced meaning 
  871. (an "abstract data type" or Smalltalk "subclass"), some consistency 
  872. constraints, or additional data chunks, use a composite FORM instead 
  873. (Cf. Composite FORMs).
  874.  
  875. Since a CAT just means a concatenation of objects, CATs are rarely 
  876. nested. Programs should really merge CATs rather than nest them.
  877.  
  878. Group LIST
  879.  
  880. A LIST defines a group very much like CAT but it also gives a scope 
  881. for PROPs (see below). And unlike CATs, LISTs should not be merged 
  882. without understanding their contents.
  883.  
  884. Structurally, a LIST is a chunk with ckID "LIST" containing a "contents 
  885. type" ID, optional shared properties, and the nested contents (FORMs, 
  886. LISTs, and CATs), in that order. The ckSize of each contained chunk 
  887. is a relative pointer to the next one. A LIST is not an arbitrary 
  888. linked list the cells are simply concatenated.
  889.  
  890. LIST    ::= "LIST" #{ ContentsType PROP* (FORM | LIST | CAT)* }
  891. ContentsType    ::= ID
  892.  
  893. Group PROP
  894.  
  895. PROP chunks may appear in LISTs (not in FORMs or CATs). They supply 
  896. shared properties for the FORMs in that LIST. This ability to elevate 
  897. some property settings to shared status for a list of forms is useful 
  898. for both indirection and compaction. E.g. a list of images with the 
  899. same size and colors can share one "size" property and one "color 
  900. map" property. Individual FORMs can override the shared settings.
  901.  
  902. The contents of a PROP is like a FORM with no data chunks:
  903.  
  904. PROP    ::= "PROP" #{ FormType Property* }
  905.  
  906. It means, "Here are the shared properties for FORM type <<FormType>."
  907.  
  908. A LIST may have at most one PROP of a FORM type, and all the PROPs 
  909. must appear before any of the FORMs or nested LISTs and CATs. You 
  910. can have subsequences of FORMs sharing properties by making each subsequence 
  911. a LIST.
  912.  
  913. Scoping: Think of property settings as variable bindings in nested 
  914. blocks of a programming language. Where in C you could write:
  915.  
  916. TEXT_FONT text_font = Courier;    /* program's global default    */
  917.  
  918. File(); {
  919.     TEXT_FONT text_font = TimesRoman;    /* shared setting    */
  920.  
  921.         {
  922.         TEXT_FONT text_font = Helvetica;  /* local setting    */
  923.         Print("Hello ");    /* uses font Helvetica    */
  924.         }
  925.  
  926.         {
  927.         Print("there.");    /* uses font TimesRoman    */
  928.         }
  929.     }
  930.  
  931. An IFF file could contain:
  932.  
  933. LIST {
  934.     PROP TEXT {
  935.         FONT {TimesRoman}    /* shared setting    */
  936.         }
  937.  
  938.     FORM TEXT {
  939.         FONT {Helvetica}    /* local setting    */
  940.         CHRS {Hello }        /* uses font Helvetica    */
  941.         }
  942.  
  943.     FORM TEXT {
  944.         CHRS {there.}    /* uses font TimesRoman    */
  945.         }
  946.     }
  947.  
  948. The shared property assignments selectively override the reader's 
  949. global defaults, but only for FORMs within the group. A FORM's own 
  950. property assignments selectively override the global and group-supplied 
  951. values. So when reading an IFF file, keep property settings on a stack. 
  952. They're designed to be small enough to hold in main memory.
  953.  
  954. Shared properties are semantically equivalent to copying those properties 
  955. into each of the nested FORMs right after their FORM type IDs.
  956.  
  957. Properties for LIST
  958.  
  959. Optional "properties for LIST" store the origin of the list's contents 
  960. in a PROP chunk for the fake FORM type "LIST". They are the properties 
  961. originating program "OPGM", processor family "OCPU", computer type 
  962. "OCMP", computer serial number or network address "OSN ", and user 
  963. name "UNAM". In our imperfect world, these could be called upon to 
  964. distinguish between unintended variations of a data format or to work 
  965. around bugs in particular originating/receiving program pairs. Issue: 
  966. Specify the format of these properties.
  967.  
  968. A creation date could also be stored in a property but let's ask that 
  969. file creating, editing, and transporting programs maintain the correct 
  970. date in the local file system. Programs that move files between machine 
  971. types are expected to copy across the creation dates.
  972.  
  973.  
  974.  
  975. 6. Standard File Structure
  976.  
  977. File Structure Overview
  978.  
  979. An IFF file is just a single chunk of type FORM, LIST, or CAT. Therefore 
  980. an IFF file can be recognized by its first 4 bytes: "FORM", "LIST", 
  981. or "CAT ". Any file contents after the chunk's end are to be ignored.
  982.  
  983. Since an IFF file can be a group of objects, programs that read/write 
  984. single objects can communicate to an extent with programs that read/write 
  985. groups. You're encouraged to write programs that handle all the objects 
  986. in a LIST or CAT. A graphics editor, for example, could process a 
  987. list of pictures as a multiple page document, one page at a time.
  988.  
  989. Programs should enforce IFF's syntactic rules when reading and writing 
  990. files. This ensures robust data transfer. The public domain IFF reader/writer 
  991. subroutine package does this for you. A utility program "IFFCheck" 
  992. is available that scans an IFF file and checks it for conformance 
  993. to IFF's syntactic rules. IFFCheck also prints an outline of the chunks 
  994. in the file, showing the ckID and ckSize of each. This is quite handy 
  995. when building IFF programs. Example programs are also available to 
  996. show details of reading and writing IFF files.
  997.  
  998. A merge program "IFFJoin" will be available that logically appends 
  999. IFF files into a single CAT group. It "unwraps" each input file that 
  1000. is a CAT so that the combined file isn't nested CATs.
  1001.  
  1002. If we need to revise the IFF standard, the three anchoring IDs will 
  1003. be used as "version numbers". That's why IDs "FOR1" through "FOR9", 
  1004. "LIS1" through "LIS9", and "CAT1" through "CAT9" are reserved.
  1005.  
  1006. IFF formats are designed for reasonable performance with floppy disks. 
  1007. We achieve considerable simplicity in the formats and programs by 
  1008. relying on the host file system rather than defining universal grouping 
  1009. structures like directories for LIST contents. On huge storage systems, 
  1010. IFF files could be leaf nodes in a file structure like a B-tree. Let's 
  1011. hope the host file system implements that for us!
  1012.  
  1013. Thre are two kinds of IFF files: single purpose files and scrap files. 
  1014. They differ in the interpretation of multiple data objects and in 
  1015. the file's external type.
  1016.  
  1017. Single Purpose Files
  1018.  
  1019. A single purpose IFF file is for normal "document" and "archive" storage. 
  1020. This is in contrast with "scrap files" (see below) and temporary backing 
  1021. storage (non-interchange files).
  1022.  
  1023. The external file type (or filename extension, depending on the host 
  1024. file system) indicates the file's contents. It's generally the FORM 
  1025. type of the data contained, hence the restrictions on FORM type IDs.
  1026.  
  1027. Programmers and users may pick an "intended use" type as the filename 
  1028. extension to make it easy to filter for the relevant files in a filename 
  1029. requestor. This is actually a "subclass" or "subtype" that conveniently 
  1030. separates files of the same FORM type that have different uses. Programs 
  1031. cannot demand conformity to its expected subtypes without overly restricting 
  1032. data interchange since they cannot know about the subtypes to be used 
  1033. by future programs that users will want to exchange data with.
  1034.  
  1035. Issue: How to generate 3-letter MS-DOS extensions from 4-letter FORM 
  1036. type IDs?
  1037.  
  1038. Most single purpose files will be a single FORM (perhaps a composite 
  1039. FORM like a musical score containing nested FORMs like musical instrument 
  1040. descriptions). If it's a LIST or a CAT, programs should skip over 
  1041. unrecognized objects to read the recognized ones or the first recognized 
  1042. one. Then a program that can read a single purpose file can read something 
  1043. out of a "scrap file", too.
  1044.  
  1045. Scrap Files
  1046.  
  1047. A "scrap file" is for maximum interconnectivity in getting data between 
  1048. programs; the core of a clipboard function. Scrap files may have type 
  1049. "IFF " or filename extension ".IFF".
  1050.  
  1051. A scrap file is typically a CAT containing alternate representations 
  1052. of the same basic information. Include as many alternatives as you 
  1053. can readily generate. This redundancy improves interconnectivity in 
  1054. situations where we can't make all programs read and write super-general 
  1055. formats. [Inside Macintosh chapter "Scrap Manager".] E.g. a graphically-
  1056. annotated musical score might be supplemented by a stripped down 4-voice 
  1057. melody and by a text (the lyrics).
  1058.  
  1059. The originating program should write the alternate representations 
  1060. in order of "preference": most preferred (most comprehensive) type 
  1061. to least preferred (least comprehensive) type. A receiving program 
  1062. should either use the first appearing type that it understands or 
  1063. search for its own "preferred" type.
  1064.  
  1065. A scrap file should have at most one alternative of any type. (A LIST 
  1066. of same type objects is ok as one of the alternatives.) But don't 
  1067. count on this when reading; ignore extra sections of a type. Then 
  1068. a program that reads scrap files can read something out of single 
  1069. purpose files.
  1070.  
  1071. Rules for Reader Programs
  1072.  
  1073. Here are some notes on building programs that read IFF files. If you 
  1074. use the standard IFF reader module "IFFR.C", many of these rules and 
  1075. details will be automatically handled. (See "Support Software" in 
  1076. Appendix A.) We recommend that you start from the example program 
  1077. "ShowILBM.C". You should also read up on recursive descent parsers. 
  1078. [See, for example, Compiler Construction, An Advanced Course.]
  1079.  
  1080. %    The standard is very flexible so many programs can exchange 
  1081. data. This implies a program has to scan the file and react to what's 
  1082. actually there in whatever order it appears. An IFF reader program 
  1083. is a parser.
  1084.  
  1085. %    For interchange to really work, programs must be willing to 
  1086. do some conversion during read-in. If the data isn't exactly what 
  1087. you expect, say, the raster is smaller than those created by your 
  1088. program, then adjust it. Similarly, your program could crop a large 
  1089. picture, add or drop bitplanes, and create/discard a mask plane. The 
  1090. program should give up gracefully on data that it can't convert.
  1091.  
  1092. %    If it doesn't start with "FORM", "LIST", or "CAT ", it's not 
  1093. an IFF-85 file.
  1094.  
  1095. %    For any chunk you encounter, you must recognize its type ID 
  1096. to understand its contents.
  1097.  
  1098. %    For any FORM chunk you encounter, you must recognize its FORM 
  1099. type ID to understand the contained "local chunks". Even if you don't 
  1100. recognize the FORM type, you can still scan it for nested FORMs, LISTs, 
  1101. and CATs of interest.
  1102.  
  1103. %    Don't forget to skip the pad byte after every odd-length chunk.
  1104.  
  1105. %    Chunk types LIST, FORM, PROP, and CAT are generic groups. They 
  1106. always contain a subtype ID followed by chunks.
  1107.  
  1108. %    Readers ought to handle a CAT of FORMs in a file. You may treat 
  1109. the FORMs like document pages to sequence through or just use the 
  1110. first FORM.
  1111.  
  1112. %    Simpler IFF readers completely skip LISTs. "Fully IFF-conforming" 
  1113. readers are those that handle LISTs, even if just to read the first 
  1114. FORM from a file. If you do look into a LIST, you must process shared 
  1115. properties (in PROP chunks) properly. The idea is to get the correct 
  1116. data or none at all.
  1117.  
  1118. %    The nicest readers are willing to look into unrecognized FORMs 
  1119. for nested FORM types that they do recognize. For example, a musical 
  1120. score may contain nested instrument descriptions and an animation 
  1121. file may contain still pictures.
  1122.  
  1123. Note to programmers: Processing PROP chunks is not simple! You'll 
  1124. need some background in interpreters with stack frames. If this is 
  1125. foreign to you, build programs that read/write only one FORM per file. 
  1126. For the more intrepid programmers, the next paragraph summarizes how 
  1127. to process LISTs and PROPs. See the general IFF reader module "IFFR.C" 
  1128. and the example program "ShowILBM.C" for details.
  1129.  
  1130. Allocate a stack frame for every LIST and FORM you encounter and initialize 
  1131. it by copying the stack frame of the parent LIST or FORM. At the top 
  1132. level, you'll need a stack frame initialized to your program's global 
  1133. defaults. While reading each LIST or FORM, store all encountered properties 
  1134. into the current stack frame. In the example ShowILBM, each stack 
  1135. frame has a place for a bitmap header property ILBM.BMHD and a color 
  1136. map property ILBM.CMAP. When you finally get to the ILBM's BODY chunk, 
  1137. use the property settings accumulated in the current stack frame.
  1138.  
  1139. An alternate implementation would just remember PROPs encountered, 
  1140. forgetting each on reaching the end of its scope (the end of the containing 
  1141. LIST). When a FORM XXXX is encountered, scan the chunks in all remembered 
  1142. PROPs XXXX, in order, as if they appeared before the chunks actually 
  1143. in the FORM XXXX. This gets trickier if you read FORMs inside of FORMs.
  1144.  
  1145. Rules for Writer Programs
  1146.  
  1147. Here are some notes on building programs that write IFF files, which 
  1148. is much easier than reading them. If you use the standard IFF writer 
  1149. module "IFFW.C" (see "Support Software" in Appendix A), many of these 
  1150. rules and details will automatically be enforced. See the example 
  1151. program "Raw2ILBM.C".
  1152.  
  1153. %    An IFF file is a single FORM, LIST, or CAT chunk.
  1154.  
  1155. %    Any IFF-85 file must start with the 4 characters "FORM", "LIST", 
  1156. or "CAT ", followed by a LONG ckSize. There should be no data after 
  1157. the chunk end.
  1158.  
  1159. %    Chunk types LIST, FORM, PROP, and CAT are generic. They always 
  1160. contain a subtype ID followed by chunks. These three IDs are universally 
  1161. reserved, as are "LIS1" through "LIS9", "FOR1" through "FOR9", "CAT1" 
  1162. through "CAT9", and "    ".
  1163.  
  1164. %    Don't forget to write a 0 pad byte after each odd-length chunk.
  1165.  
  1166. %    Four techniques for writing an IFF group: (1) build the data 
  1167. in a file mapped into virtual memory, (2) build the data in memory 
  1168. blocks and use block I/O, (3) stream write the data piecemeal and 
  1169. (don't forget!) random access back to set the group length count, 
  1170. and (4) make a preliminary pass to compute the length count then stream 
  1171. write the data.
  1172.  
  1173. %    Do not try to edit a file that you don't know how to create. 
  1174. Programs may look into a file and copy out nested FORMs of types that 
  1175. they recognize, but don't edit and replace the nested FORMs and don't 
  1176. add or remove them. That could make the containing structure inconsistent. 
  1177. You may write a new file containing items you copied (or copied and 
  1178. modified) from another IFF file, but don't copy structural parts you 
  1179. don't understand.
  1180.  
  1181. %    You must adhere to the syntax descriptions in Appendex A. E.g. 
  1182. PROPs may only appear inside LISTs.
  1183.  
  1184.  
  1185.  
  1186.  
  1187. Appendix A. Reference
  1188.  
  1189. Type Definitions
  1190.  
  1191. The following C typedefs describe standard IFF structures. Declarations 
  1192. to use in practice will vary with the CPU and compiler. For example, 
  1193. 68000 Lattice C produces efficient comparison code if we define ID 
  1194. as a "LONG". A macro "MakeID" builds these IDs at compile time.
  1195.  
  1196. /* Standard IFF types, expressed in 68000 Lattice C.    */
  1197.  
  1198. typedef unsigned char UBYTE;    /*  8 bits unsigned    */
  1199. typedef short WORD;    /* 16 bits signed    */
  1200. typedef unsigned short UWORD;    /* 16 bits unsigned    */
  1201. typedef long LONG;    /* 32 bits signed    */
  1202.  
  1203. typedef char ID[4];    /* 4 chars in ' ' through '~'    */
  1204.  
  1205. typedef struct {
  1206.     ID    ckID;
  1207.     LONG    ckSize;    /* sizeof(ckData)    */
  1208.     UBYTE    ckData[/* ckSize */];
  1209.     } Chunk;
  1210.  
  1211. /* ID typedef and builder for 68000 Lattice C. */
  1212. typedef LONG ID;     /* 4 chars in ' ' through '~'    */
  1213. #define MakeID(a,b,c,d) ( (a)<<<<24 | (b)<<<<16 | (c)<<<<8 | (d) )
  1214.  
  1215. /* Globally reserved IDs. */
  1216. #define ID_FORM   MakeID('F','O','R','M')
  1217. #define ID_LIST   MakeID('L','I','S','T')
  1218. #define ID_PROP   MakeID('P','R','O','P')
  1219. #define ID_CAT    MakeID('C','A','T',' ')
  1220. #define ID_FILLER MakeID(' ',' ',' ',' ')
  1221.  
  1222. Syntax Definitions
  1223.  
  1224. Here's a collection of the syntax definitions in this document.
  1225.  
  1226. Chunk    ::= ID #{ UBYTE* } [0]
  1227.  
  1228. Property    ::= Chunk
  1229.  
  1230. FORM    ::= "FORM" #{ FormType (LocalChunk | FORM | LIST | CAT)* 
  1231. }
  1232. FormType    ::= ID
  1233. LocalChunk    ::= Property | Chunk
  1234.  
  1235. CAT    ::= "CAT " #{ ContentsType (FORM | LIST | CAT)* }
  1236. ContentsType    ::= ID    -- a hint or an "abstract data type" ID
  1237.  
  1238. LIST    ::= "LIST" #{ ContentsType PROP* (FORM | LIST | CAT)* }
  1239. PROP    ::= "PROP" #{ FormType Property* }
  1240.  
  1241. In this extended regular expression notation, the token "#" represents 
  1242. a ckSize LONG count of the following {braced} data bytes. Literal 
  1243. items are shown in "quotes", [square bracketed items] are optional, 
  1244. and "*" means 0 or more instances. A sometimes-needed pad byte is 
  1245. shown as "[0]".
  1246.  
  1247. Defined Chunk IDs
  1248.  
  1249. This is a table of currently defined chunk IDs. We may also borrow 
  1250. some Macintosh IDs and data formats.
  1251.  
  1252. Group chunk IDs
  1253.     FORM, LIST, PROP, CAT.
  1254. Future revision group chunk IDs
  1255.     FOR1 I FOR9, LIS1 I LIS9, CAT1 I CAT9.
  1256. FORM type IDs
  1257.     (The above group chunk IDs may not be used for FORM type IDs.)
  1258.     (Lower case letters and punctuation marks are forbidden in FORM 
  1259. type IDs.)
  1260.     8SVX 8-bit sampled sound voice, ANBM animated bitmap, FNTR raster 
  1261. font, FNTV vector font, FTXT formatted text, GSCR general-use musical 
  1262. score, ILBM interleaved raster bitmap image, PDEF Deluxe Print page 
  1263. definition, PICS Macintosh picture, PLBM (obsolete), USCR Uhuru Sound 
  1264. Software musical score, UVOX Uhuru Sound Software Macintosh voice, 
  1265. SMUS simple musical score, VDEO Deluxe Video Construction Set video.
  1266. Data chunk IDs
  1267.     "JJJJ", TEXT, PICT.
  1268. PROP LIST property IDs
  1269.     OPGM, OCPU, OCMP, OSN, UNAM.
  1270.  
  1271.  
  1272.  
  1273. Support Software
  1274.  
  1275. These public domain C source programs are available for use in building 
  1276. IFF-compatible programs:
  1277.  
  1278. IFF.H, IFFR.C, IFFW.C    
  1279.  
  1280.         IFF reader and writer package. 
  1281.         These modules handle many of the details of reliably 
  1282.         reading and writing IFF files.
  1283.  
  1284. IFFCheck.C    This handy utility program scans an IFF file, checks 
  1285.         that the contents are well formed, and prints an outline 
  1286.         of the chunks.
  1287.  
  1288. PACKER.H, Packer.C, UnPacker.C    
  1289.  
  1290.         Run encoder and decoder used for ILBM files.
  1291.  
  1292. ILBM.H, ILBMR.C, ILBMW.C    
  1293.  
  1294.         Reader and writer support routines for raster image 
  1295.         FORM ILBM. ILBMR calls IFFR and UnPacker. ILBMW calls 
  1296.         IFFW and Packer.
  1297.  
  1298. ShowILBM.C    
  1299.         Example caller of IFFR and ILBMR modules. This 
  1300.         Commodore-Amiga program reads and displays a FORM ILBM.
  1301. Raw2ILBM.C    
  1302.         Example ILBM writer program. As a demonstration, it 
  1303.         reads a raw raster image file and writes the image 
  1304.         as a FORM ILBM file.
  1305. ILBM2Raw.C    
  1306.         Example ILBM reader program.  Reads a FORM ILBM file
  1307.         and writes it into a raw raster image.
  1308.  
  1309. REMALLOC.H, Remalloc.c
  1310.  
  1311.         Memory allocation routines used in these examples.
  1312.  
  1313. INTUALL.H    generic "include almost everything" include-file
  1314.         with the sequence of includes correctly specified.
  1315.  
  1316. READPICT.H, ReadPict.c    
  1317.  
  1318.         given an ILBM file, read it into a bitmap and 
  1319.         a color map
  1320.  
  1321. PUTPICT.H, PutPict.c     
  1322.  
  1323.         given a bitmap and a color map, save it as
  1324.         an ILBM file.
  1325.  
  1326. GIO.H, Gio.c    generic I/O speedup package.  Attempts to speed
  1327.         disk I/O by buffering writes and reads.
  1328.  
  1329. giocall.c    sample call to gio.
  1330.  
  1331. ilbmdump.c    reads in ILBM file, prints out ascii representation
  1332.         for including in C files.
  1333.  
  1334. bmprintc.c    prints out a C-language representation of data for
  1335.         a bitmap.
  1336.  
  1337.  
  1338.  
  1339. Example Diagrams
  1340.  
  1341. Here's a box diagram for an example IFF file, a raster image FORM 
  1342. ILBM. This FORM contains a bitmap header property chunk BMHD, a color 
  1343. map property chunk CMAP, and a raster data chunk BODY. This particular 
  1344. raster is 320 x 200 pixels x 3 bit planes uncompressed. The "0" after 
  1345. the CMAP chunk represents a zero pad byte; included since the CMAP 
  1346. chunk has an odd length. The text to the right of the diagram shows 
  1347. the outline that would be printed by the IFFCheck utility program 
  1348. for this particular file.
  1349.  
  1350.     +-----------------------------------+
  1351.     |'FORM'        24070            |    FORM 24070 IBLM
  1352.     +-----------------------------------+
  1353.     |'ILBM'                    |
  1354.     +-----------------------------------+
  1355.     | +-------------------------------+ |
  1356.     | | 'BMHD'    20          | |    .BMHD  20
  1357.     | | 320, 200, 0, 0, 3, 0, 0, ...  | |
  1358.     | + ------------------------------+ |
  1359.     | | 'CMAP'    21              | |    .CMAP  21
  1360.     | | 0, 0, 0; 32, 0, 0; 64,0,0; .. | |
  1361.     | +-------------------------------+ |
  1362.     | 0                    |
  1363.     +-----------------------------------+
  1364.     |'BODY'        24000            |    .BODY 24000
  1365.     |0, 0, 0, ...                |
  1366.     +-----------------------------------+
  1367.  
  1368. This second diagram shows a LIST of two FORMs ILBM sharing a common 
  1369. BMHD property and a common CMAP property. Again, the text on the right 
  1370. is an outline  a la IFFCheck.
  1371.  
  1372.  
  1373.      +-----------------------------------------+
  1374.      |'LIST'        48114                      |  LIST  48114  AAAA
  1375.      +-----------------------------------------+
  1376.      |'AAAA'                       |  .PROP  62  ILBM
  1377.      |    +-----------------------------------+  |
  1378.      |  |'PROP'        62            |  |  
  1379.      |  +-----------------------------------+  |
  1380.      |    |'ILBM'                    |  |
  1381.      |    +-----------------------------------+  |
  1382.      |    | +-------------------------------+ |  |
  1383.      |    | | 'BMHD'    20          | |  |  ..BMHD  20
  1384.      |    | | 320, 200, 0, 0, 3, 0, 0, ...  | |  |
  1385.      |    | | ------------------------------+ |  |
  1386.      |    | | 'CMAP'    21              | |  |  ..CMAP  21
  1387.      |    | | 0, 0, 0; 32, 0, 0; 64,0,0; .. | |  |
  1388.      |    | +-------------------------------+ |  |
  1389.      |    | 0                    |  |
  1390.      |    +-----------------------------------+  |
  1391.      |    +-----------------------------------+  |
  1392.      |    |'FORM'        24012            |  |  .FORM  24012  ILBM
  1393.      |    +-----------------------------------+  |
  1394.      |    |'ILBM'                    |  |  
  1395.      |    +-----------------------------------+  |
  1396.      |    |  +-----------------------------+  |  |
  1397.      |    |  |'BODY'        24000    |  |  |  ..BODY  24000
  1398.      |    |  |0, 0, 0, ...         |  |  |
  1399.      |    |  +-----------------------------+  |  |
  1400.      |    +-----------------------------------+  |
  1401.      |    +-----------------------------------+  |
  1402.      |    |'FORM'        24012            |  |  .FORM  24012  ILBM
  1403.      |    +-----------------------------------+  |
  1404.      |    |'ILBM'                    |  |
  1405.      |    +-----------------------------------+  |
  1406.      |    |  +-----------------------------+  |  |
  1407.      |    |  |'BODY'        24000    |  |  |  ..BODY  24000
  1408.      |    |  |0, 0, 0, ...         |  |  |
  1409.      |    |  +-----------------------------+  |  |
  1410.      |    +-----------------------------------+  |
  1411.      +-----------------------------------------+
  1412.  
  1413.  
  1414.  
  1415. Appendix B. Standards Committee
  1416.  
  1417. The following people contributed to the design of this IFF standard:
  1418.  
  1419. Bob "Kodiak" Burns, Commodore-Amiga
  1420. R. J. Mical, Commodore-Amiga
  1421. Jerry Morrison, Electronic Arts
  1422. Greg Riker, Electronic Arts
  1423. Steve Shaw, Electronic Arts
  1424. Barry Walsh, Commodore-Amiga
  1425.