Multimedia GIF Extensions The multimedia GIF extensions do not actually change or extend the current GIF specification -- they only take advantage of the application extension block specified in the GIF 89a specification. The Graphics Interchange Format(sm) Version 89a document should be consulted regarding GIF formats. This document only describes the multimedia application extensions. Multimedia GIF Players A multimedia GIF is a combination of graphical images plus audio data in the form of MIDI and PCM digital samples. Stored within a single Compuserve GIF file are one or more GIF bitmaps, zero or more digital PCM files, and one or more Standard MIDI Files. The MIDI File(s) control the syncronization of all other components. In order to accomplish this, Sequencer Specific Meta-Events are used to trigger events. Events may consist of the display of a GIF bitmap or the playing of a digital PCM file. Format for MIDI Control Block MIDI files can be placed in Application Extension Blocks according to the GIF89A spec. Each such GIF file will have zero or one MIDICTRL (MIDI Control) extensions, followed by one or more MIDISONG extensions. MIDICTRL extension: Authentication code: 74 111 110 ("Jon") This extension is required. It should precede the MIDISONG extension that it refers to. There is always one MIDICTRL block per MIDISONG block. Syntax. 7 6 5 4 3 2 1 0 Field Name Type +---------------+ 0 | | Version Byte +---------------+ 1 | | Sequence Number Byte +---------------+ 2 | | Melodic Polyphony Byte +---------------+ 3 | | Percussive Polyphony Byte +---------------+ 4 | | Channel Usage Bitmap Unsigned +- -+ 5 | | +---------------+ 6 | | Delay Time (1/100s Second) Unsigned +- -+ 7 | | +---------------+ MIDISONG block: Authentication code: 68 109 55 ("Dm7") This is a MIDI song file in Standard MIDI Format, broken into blocks as per the GIF89A spec. The blocks can be any size; there is no requirement to split them on an event or time boundary. It is strongly recommended to have this MFF file in General MIDI Format. The MIDI file data blocks directly follow the MIDISONG extension block. It is possible to have multiple versions of the same song in different MIDISONG extensions. For example, there could be a version for General MIDI and another for sound cards with less polyphony. The MIDICTRL extension preceding each MIDISONG block will specify the polyphony, and it is up to the decoder to determine which version is to be played. Multimedia GIF Meta Events Following is a description of the Standard MIDI File Meta-Events Used by MM-GIF to trigger events. MM-GIF uses the CIS IMA ID: 00H, 00H, 67H. Although it is not required, it is strongly recommended that the final track of the standard MIDI file be reserved for solely GIF oriented meta-event data. Doing this will make it easier to both insert and retrieve the meta-events. Sequencer Specific Codes The Sequencer Specific Meta-Event codes are stored within the Standard MIDI File. When one occurs during playback, the associated event is triggered. The general format of the MMGIF Sequencer Specific Meta-Event is as follows (all codes are in hexadecimal notation): FF Meta-Event Code 7F Sequencer Specific Code nn Length (7 or 13 Bytes - depending on message) 00,00,67 Compuserve Manufacturers' ID 01 Program ID -- MMGIF xx Command ID: 0x11 Display GIF bitmap, 0x21 play PCM sample, ... nn Object Number: internal number of Image or Sample to perform (1..255) ------- EXTENDED DISPLAY MESSAGE (MMGIF Version 2.0+): tt How to display the image (See Transitions) dd How to dispose of the image xlb,xmb Horizontal Origin (Stored as 2 7-bit bytes - LSB first) ylb,ymb Vertical Origin (2 7-bit bytes - LSB first) ------- F7 End of Exclusive Command - although not required by MIDI, this will terminate the Meta-Event for our messages. Command ID Code Meaning (Hex) 10 Prepare GIF bitmap Image (not currently used) 11 Display GIF bitmap Image 12 Display GIF bitmap Image - Extended 20 Prepare PCM digital sample 21 Play PCM digital sample Object Number The single byte object number determines which Image or Sample to operate on. EXTENDED DISPLAY MESSAGE (Added for MMGIF version 2.0) The extended display message (0x12) adds information such as transition, disposal and origin when presenting an image. It overides any conflicting information which may appear in the GIF data stream. Transitions Transition codes tell a decoder how to display the specified image. The following codes are supported: CODE MEANING 00 Nothing special 01 Wipe Top to Bottom 02 Wipe Left to Right 03 Wipe Bottom to Top 04 Wipe Right to Left 05 Wipe Upper Left to Lower Right (diagonal) 06 Wipe Lower Left to Upper Right 07 Wipe Upper Right to Lower Left 08 Wipe Lower Right to Upper Left 09 Horizontal Crush (crush in fromn both left and right) 0A Vertical Crush (crush in from top and bottom) 0B Spiral In (from outer edges to center) 0C Spiral Out 0D Random Block (randomly display blocks untill filled) 0E Horiz Fan (a "Venetian Blind" moving from left to right) 0F Vert Fan (Venetian Blind - top to bottom) Disposal This message instructs the decoder how to dispose of an image when a new one is to be displayed. The codes are identical to the disposal codes specified in GIF89a. An extended display message will overide any control information present in the GIF data stream. CODE MEANING 00 Nothing special 01 KEEP - retain the current image 02 RESTORE BACKGROUND - restore the background color 03 REMOVE - remove the current image, and restore whatever image was beneath it. Origin The origin specification overides any other origin for the image specified in the GIF data stream. It is stored as two 7-bit bytes (LSB first - Intel) which must be combined into a single 14 bit integer (x <= 16383). The resulting integer specifies the screen vertical and horizontal origin location. The special code, 16383 (stored as 0x7F, 0x7F), specifies the use of any origin information stored within the GIF image. The "use default" code (16383) can be specified in either the X and/or Y component, and will cause the default to be used for both. Examples FF 7D 07 00 00 67 01 Upon reception of this code, 11 06 F7 MMGIF will display GIF Image number 6 FF 7D 07 00 00 67 01 Upon reception of this code, 20 03 F7 MMGIF will prepare PCM sample number 3 for playback FF 7D 07 00 00 67 01 Upon reception of this code, 21 03 F7 MMGIF will play PCM sample number 3 FF 7D 0D 00 00 67 01 Upon reception of this code, MMGIF will display GIF Image 12 11 05 00 06 00 09 number 17 with an upper left to lower right transition. 01 F7 The background will first be erased, and the origin will use the X component of 6 ((0 << 7)+6), and a Y component of 137 ((1 << 7)+9). Format for PCM Control Block PCM Sound files can be placed in Application Extension Blocks according to the GIF89A spec. Each such GIF file will have zero or more PCM-CTRL (PCM Control) extensions, each followed by one PCM-DATA extension. 1) PCM-CTRL extension: Authentication code: 0x64, 0x65, 0x6D This extension is required. If it exists, it should immediately precede the PCM-DATA extension that it refers to. There is at most one PCM-CTRL block per PCM-DATA block. Syntax. 7 6 5 4 3 2 1 0 Field Name Type +---------------+ 0 | | PCM-ID Ascii (4 Bytes) +- -+ 1 | | +- -+ 2 | | +- -+ 3 | | +---------------+ 4 | | Sample Number Unsigned +- -+ 5 | | +---------------+ 6 | | Format Unsigned +- -+ 7 | | +---------------+ 8 | | Channels Unsigned +- -+ 9 | | +---------------+ 10 | | Samples Per Second Unsigned Long +- -+ (DoubleWord) 11 | | +- -+ 12 | | +- -+ 13 | | +---------------+ 14 | | +- -+ 15 | | Average Bytes Per Second Unsigned Long +- -+ (DoubleWord) 16 | | +- -+ 17 | | +---------------+ 18 | | Block Alignment Unsigned +- -+ 19 | | +---------------+ 20 | | Bits Per Sample Unsigned +- -+ 21 | | +---------------+ 22 | | Sample Length Unsigned Long +- -+ (DoubleWord) 23 | | +- -+ 24 | | +- -+ 25 | | +---------------+ Name Length Description PCM ID 4 ASCII Identifier of native format Number 2 Integer - the Sample number. Format Type 2 Integer - the format of this PCM sample type. Channels 2 Integer - the number of channels. One is for mono, two for stereo... Samples per Second 4 Long - the number of samples per second. Avg Bytes per Second 4 Long - the average number of bytes played per second. Block Align 2 Integer - the eventual block alignment. Used by a decoder to choose a buffer size. Bits Per Sample 2 Number of bits per sample of mono data. Sample Length 4 Double Word - the total size of the sample data. This is so decoders can get enough memory to contain the sample in advance. The PCM ID determines how the Format Type is interpreted. Initially the only defined PCM ID is "WAVE", and the Format type conforms to one of the defined Microsoft PCM formats. In all instances, the numbers are stored in Intel format (low byte first). The fields from Format Type on form a WAVEFORMAT structure, as defined by Microsoft. All the PCM- CTRL numbers are stored in Intel format (low byte first). 2. PCM-FRMT block: Authentication code: 0x74, 0x65, 0x6C This block is required. For an uncompressed PCM waveform the block will have a zero length. This block must directly follow the PCM-CTRL block. The length of the block is dependent on the PCM ID, Format Type, and actual compression parameters. For MS-ADPCM, the following fields are present: Syntax. 7 6 5 4 3 2 1 0 Field Name Type +---------------+ 0 | | Samples Per Block Unsigned Long +- -+ (DoubleWord) 1 | | +- -+ 2 | | +- -+ 3 | | +---------------+ 4 | | Number of Coefficients (N) Unsigned +- -+ 5 | | +---------------+ 6 | | Coefficient Pair 1 Unsigned +- -+ 7 | | +---------------+ 8 | | +- -+ 9 | | +---------------+ . . . . . . +---------------+ | | Coefficient Pair N Unsigned +- -+ | | +---------------+ | | +- -+ | | +---------------+ Name Length Description Samples per block 4 The block refers to the block alignment field listed above, NOT the GIF blocksize (((BlockAlign - (7 * Channels)) * 8) / (BitsPerSample * nChannels)) + 2 nCoef 2 Integer - the number of compression coefficients supplied. Coefficients nCoef Double Word - An array of Pairs of word size coefficients; used by the compression expander. There are always at least 7 of these for MS-ADPCM. 3. PCM-DATA block: Authentication code: 0x6A, 0x77, 0x6F This block is required. It contains the PCM sound data in the format specified by both the PCM-ID and the Format Type, broken into blocks as per the GIF89A spec. There is always one PCM-DATA block for each PCM-CTRL block. The blocks can be any size (up to 255 bytes); there is no requirement to split them on a block alignment boundary. In the case of "WAVE" data, the numbers are stored in Intel format (low byte first).