GIF Extension Blocks

To provide for orderly extension of the GIF definition, a mechanism for
defining the packaging of extensions within a GIF data stream is
necessary. Specific GIF extensions are to be defined and documented by
CompuServe in order to provide a controlled enhancement path.

GIF Extension Blocks are packaged in a manner similar to that used by the
raster data though not compressed. The basic structure is:

7 6 5 4 3 2 1 0 Byte #
┌───────────────┐
│0 0 1 0 0 0 0 1│ 1 '!' - GIF Extension Block Introducer
├───────────────┤
│ function code │ 2 Extension function code (0 to 255)
├───────────────┤ ───┐
│ byte count │ │
├───────────────┤ │
│ │ ├── Repeated as many times as necessary
│func data bytes│ │
│ │ │
├───────────────┤ ───┛
| |
├───────────────┤
│0 0 0 0 0 0 0 0│ zero byte count (terminates block)
└───────────────┛

A GIF Extension Block may immediately preceed any Image Descriptor or
occur before the GIF Terminator.

All GIF decoders must be able to recognize the existence of GIF
Extension Blocks and read past them if unable to process the function
code. This ensures that older decoders will be able to process extended
GIF image files in the future, though without the additional
functionality.