[rec.arts.startrek] IFF Format

ewhac@well.UUCP (Leo L. Schwab) (04/07/88)

[ Cross-posted to comp.sys.amiga, and followups directed there. ]

In article <1328@silver.bacs.indiana.edu> sl137223@silver.UUCP, an ST user,
descibes IFF format bitmap files.

	Oy vey, have *you* got it wrong!

	Actually, this isn't totally fair.  You got the basic structure
right, but in the real world, IFF can take an infinite number of forms.
Your article made IFF seem like a very simple storage format, but it isn't.

	In order to correctly read an IFF file, you need to write a
recursive descent parser.  You can get away with a simple scanner/reader for
FORM ILBM's, but the moment you encounter a LIST or CAT file, you'll toss
your cookies (fortunately, there aren't many LISTs or CATs running around).

	The cheap way to do it is to scan the file for the opening longword
which is the ASCII string 'FORM'.  The next longword is the size in bytes.
The next longword will be the ASCII string 'ILBM'.  If you don't get this
right off the bat, your program should give up.

	At this point, *ANYTHING* can happen.  Usually, you will encounter a
chunk describing the characteristics of the bitmap.  This is flagged by the
longword-string 'BMHD' followed by a longword indicating the size of the
header structure, followed by the structure itself.

	After this you can run into nearly *anything*, and you need to know
how to intelligently deal with it.  You can bump into CMAP hunks, CAMG
hunks, DPPV hunks, CRNG hunks, and all sorts of other nonsense.  Or, you may
encounter *NONE* of these things.  In *ALL* cases, you must know how to
handle it.

	The last thing you'll encounter (*usually*) is the 'BODY' hunk,
which is the actual bitmap image, and which may or may not be compressed
using run-length encoding.

	All in all, IFF is a real bitch to do right.

	If you want to get the official IFF documents, complete with Lattice
C source code on an Amiga-format disk, send $20 to:

	Commodore Amiga Technical Support
	ATTN: Lauren Brown
	1200 Wilson Drive
	West Chester, PA   19380

	If you have any more questions pertaining to IFF, you really ought
to post them in comp.sys.amiga, since we have to deal with this mess almost
every day.  (Followups have been directed there.)

Disclaimer: I think IFF is a royal pain, since it's non-trivial to write a
reader program for an IFF file.  This should not be the case.
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
Leo L. Schwab -- The Guy in The Cape  ihnp4!pacbell -\
 \_ -_		Recumbent Bikes:	      dual ---> !{well,unicom}!ewhac
O----^o	      The Only Way To Fly.	      hplabs / (pronounced "AE-wack")
"Work FOR?  I don't work FOR anybody!  I'm just having fun."  -- The Doctor