IFF file format

From Atari Wiki
Jump to navigation Jump to search
Interchange File Format    *.IFF
4 bytes         "FORM" (FORM chunk ID)
1 long          length of file that follows
4 bytes         "ILBM" (InterLeaved BitMap file ID)

4 bytes         "BMHD" (BitMap HeaDer chunk ID)
1 long          length of chunk [20]
20 bytes        1 word = image width in pixels
                1 word = image height in lines
                1 word = image x-offset [usually 0]
                1 word = image y-offset [usually 0]
                1 byte = # bitplanes
                1 byte = mask (0=no, 1=impl., 2=transparent, 3=lasso)
                1 byte = uncompressed [0], packbits [1], vertical RLE [2]
                1 byte = unused [0]
                1 word = transparent color (for mask=2)
                1 byte = x-aspect [5=640x200, 10=320x200/640x400, 20=320x400]
                1 byte = y-aspect [11]
                1 word = page width (usually the same as image width)
                1 word = page height (usually the same as image height)

4 bytes         "CMAP" (ColorMAP chunk ID)
1 long          length of chunk [3*n where n is the # colors]
3n bytes        3 bytes per RGB color.  Each color value is a byte
                and the actual color value is left-justified in the
                byte such that the most significant bit of the value
                is the MSB of the byte.  (ie. a color value of 15 ($0F)
                is stored as $F0)  The bytes are stored in R,G,B order.

4 bytes         "CRNG" (Color RaNGe chunk ID)
1 long          length of chunk [8]
8 bytes         1 word = reserved [0]
                1 word = animation speed (16384 = 60 steps per second)
                1 word = active [1] or inactive [0]
                1 byte = left/lower color animation limit
                1 byte = right/upper color animation limit

4 bytes         "CAMG" (Commodore AMiGa viewport mode chunk ID)
1 long          length of chunk [4]
1 long          viewport mode bits:
                  bit  2 = interlaced
                  bit  7 = half-bright
                  bit 11 = HAM
                  bit 15 = high res

4 bytes         "BODY" (BODY chunk ID)
1 long          length of chunk [# bytes of image data that follow]
? bytes         actual image data
NOTES: Some of these chunks may not be present in every IFF file, and may
not be in this order.  You should always look for the ID bytes to find a
certain chunk.  All chunk IDs are followed by a long value that tells the
size of the chunk (note that "ILBM" is not a chunk ID).  This is the number of
bytes that FOLLOW the 4 ID bytes and size longword.  The exception to this is
the FORM chunk.  The size longword that follows the FORM ID is the size of the
remainder of the file.  The FORM chunk must always be the first chunk in an
IFF file.

The R,G,B ranges of AMIGA and ST are different (AMIGA 0...15, ST 0...7),
as is the maximum number of bitplanes (AMIGA: 5, ST: 4).

Format of body data
An expanded picture is simply a bitmap.  The most common packing method is 
PackBits (see below), and is identical to MacPaint and DEGAS Elite compressed.
The (decompressed) body data appears in the following order:
        line 1 plane 0 ... line 1 plane 1 ... ... line 1 plane m
        [line 1 mask (if appropriate)]
        line 2 plane 0 ... line 2 plane 1 ... ... line 2 plane m
        [line 2 mask (if appropriate)]
        line x plane 0 ... line x plane 1 ... ... line x plane m
        [line x mask (if appropriate)]
The FORM chunk identifies the type of data:
        "ILBM" = interleaved bit map
        "8SVX" = 8-bit sample voice
        "SMUS" = simple music score
        "FTXT" = formatted text (Amiga)

The ST version of DPAINT always uses the vertical RLE packing format in the body data. 
Within the BODY chunk there is one VDAT chunk per bit plane (four in total). Every VDAT chunk 
is laid out in columns, similar to the Tiny format. Only the compression scheme is slightly 
different, command 0, and 1 are flipped, and extra count words store in data list.
4 bytes          'VDAT' vertical bitplane data
4 bytes          length of cunk
?? bytes       compressed data

Data compression format:
2 bytes          cmd_cnt command bytes count - 2
? bytes          cmd_cnt - 2 command bytes.
? words         data words

Note that the number of commands is 2 more than actual commands, and that the data 
words may start on an odd address if the number of command bytes are odd.

  1 byte cmd     0: read one data word as count
                    output count literal words from data words.
                 1: read one command word as count, then one data word as data
                    output data count times
                <0: -cmd is count, output count words from data words
                >2: cmd is count, read one data word as data
                    output data count times

See also PackBits Compression Algorithm

Back to ST Picture Formats