[Contents] [index] [Help] [Retrace] [browse <] [Browse >]

In the case of a form ilbm, certain chunks are defined as being able to
appear in any order.  Among these are the bmhd, cmap, and camg. typically,
BMHD appears first, followed by CMAP and CAMG, but you can't make this
assumption.  The iff and ilbm standards require you to assume these chunks
will appear in any order.  So ideally, what you'd like to do is collect
them as they arrive, but not do anything with them until you actually need
them.

This is where propchunk() comes in.  the syntax for propchunk() is
identical to stopchunk():

    error = PropChunk (iff, ID_ILBM, ID_BMHD);

When you call parseiff(), the parser will look for chunks declared with
propchunk().  when it sees them, the parser will internally copy the
contents of the chunk into memory for you before continuing its parsing.

When you're ready to examine the contents of the chunk, you use the
function findprop():

    StoredProperty = FindProp (iff, ID_ILBM, ID_BMHD);

findprop() returns a pointer to a struct storedproperty, which contains
the chunk size and data.  If the chunk was never encountered, NULL is
returned.  This permits you to process the property chunks in any order
you wish, regardless of how they appeared in the file.  This provides much
better control of data interpretation and also reduces headaches.  The
following fragment shows how ilbm bitmapheader data could be accessed
after using parseiff() with propchunk(iff, id_ilbm, id_bmhd):

    struct StoredProperty *sp;      /* defined in iffparse.h */
    struct BitMapHeader *bmhd;      /* defined in IFF spec   */

    if (sp = FindProp(iff, ID_ILBM, ID_BMHD))
            {
            /* If property is BMHD, sp->sp_Data is ptr to data in BMHD */
            bmhd = (struct BitMapHeader *)sp->sp_Data;
            printf("BMHD: PageWidth      = %ld\n",bmhd->PageWidth);
            }