home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / grafik / gif / gif.doc < prev   
Encoding:
Text File  |  1990-11-12  |  30.7 KB  |  1,049 lines

  1.                                 G I F (tm)
  2.  
  3.                      Graphics Interchange Format (tm)
  4.  
  5.                       A standard defining a mechanism
  6.  
  7.                      for the storage and transmission
  8.  
  9.                    of raster-based graphics information
  10.  
  11.                                June 15, 1987
  12.  
  13.                      (c) CompuServe Incorporated, 1987
  14.  
  15.                             All rights reserved
  16.  
  17.             While this document is copyrighted, the information
  18.  
  19.           contained within is made available for use in computer
  20.  
  21.           software without royalties, or licensing restrictions.
  22.  
  23.           GIF and 'Graphics Interchange Format' are trademarks of
  24.  
  25.                          CompuServe, Incorporated.
  26.  
  27.                            an H&R Block Company
  28.  
  29.                         5000 Arlington Centre Blvd.
  30.  
  31.                            Columbus, Ohio 43220
  32.  
  33.                               (614) 457-8600
  34.  
  35.                                                                      Page 2
  36.  
  37.               Graphics Interchange Format (GIF) Specification
  38.  
  39.                              Table of Contents
  40.  
  41.         INTRODUCTION . . . . . . . . . . . . . . . . . page 3
  42.  
  43.         GENERAL FILE FORMAT  . . . . . . . . . . . . . page 3
  44.  
  45.         GIF SIGNATURE  . . . . . . . . . . . . . . . . page 4
  46.  
  47.         SCREEN DESCRIPTOR  . . . . . . . . . . . . . . page 4
  48.  
  49.         GLOBAL COLOR MAP . . . . . . . . . . . . . . . page 5
  50.  
  51.         IMAGE DESCRIPTOR . . . . . . . . . . . . . . . page 6
  52.  
  53.         LOCAL COLOR MAP  . . . . . . . . . . . . . . . page 7
  54.  
  55.         RASTER DATA  . . . . . . . . . . . . . . . . . page 7
  56.  
  57.         GIF TERMINATOR . . . . . . . . . . . . . . . . page 8
  58.  
  59.         GIF EXTENSION BLOCKS . . . . . . . . . . . . . page 8
  60.  
  61.         APPENDIX A - GLOSSARY  . . . . . . . . . . . . page 9
  62.  
  63.         APPENDIX B - INTERACTIVE SEQUENCES . . . . . . page 10
  64.  
  65.         APPENDIX C - IMAGE PACKAGING & COMPRESSION . . page 12
  66.  
  67.         APPENDIX D - MULTIPLE IMAGE PROCESSING . . . . page 15
  68.  
  69. Graphics Interchange Format (GIF)                                    Page 3
  70.  
  71. Specification
  72.  
  73. INTRODUCTION
  74.  
  75.         'GIF' (tm) is CompuServe's standard for defining generalized  color
  76.  
  77.    raster   images.    This   'Graphics  Interchange  Format'  (tm)  allows
  78.  
  79.    high-quality, high-resolution graphics to be displayed on a  variety  of
  80.  
  81.    graphics  hardware  and is intended as an exchange and display mechanism
  82.  
  83.    for graphics images.  The image format described  in  this  document  is
  84.  
  85.    designed  to  support  current  and  future image technology and will in
  86.  
  87.    addition serve as a basis for future CompuServe graphics products.
  88.  
  89.         The main focus  of  this  document  is  to  provide  the  technical
  90.  
  91.    information  necessary  for  a  programmer to implement GIF encoders and
  92.  
  93.    decoders.  As such, some assumptions are made as to terminology relavent
  94.  
  95.    to graphics and programming in general.
  96.  
  97.         The first section of this document describes the  GIF  data  format
  98.  
  99.    and its components and applies to all GIF decoders, either as standalone
  100.  
  101.    programs or as part of  a  communications  package.   Appendix  B  is  a
  102.  
  103.    section  relavent to decoders that are part of a communications software
  104.  
  105.    package and describes the protocol requirements for entering and exiting
  106.  
  107.    GIF mode, and responding to host interrogations.  A glossary in Appendix
  108.  
  109.    A defines some of the terminology used in  this  document.   Appendix  C
  110.  
  111.    gives  a  detailed  explanation  of  how  the  graphics  image itself is
  112.  
  113.    packaged as a series of data bytes.
  114.  
  115.                 Graphics Interchange Format Data Definition
  116.  
  117.  GENERAL FILE FORMAT
  118.  
  119.         +-----------------------+
  120.  
  121.         | +-------------------+ |
  122.  
  123.         | |   GIF Signature   | |
  124.  
  125.         | +-------------------+ |
  126.  
  127.         | +-------------------+ |
  128.  
  129.         | | Screen Descriptor | |
  130.  
  131.         | +-------------------+ |
  132.  
  133.         | +-------------------+ |
  134.  
  135.         | | Global Color Map  | |
  136.  
  137.         | +-------------------+ |
  138.  
  139.         . . .               . . .
  140.  
  141.         | +-------------------+ |    ---+   
  142.  
  143.         | |  Image Descriptor | |       |   
  144.  
  145.         | +-------------------+ |       |   
  146.  
  147.         | +-------------------+ |       |  
  148.  
  149.         | |  Local Color Map  | |       |-   Repeated 1 to n times
  150.  
  151.         | +-------------------+ |       |   
  152.  
  153.         | +-------------------+ |       |   
  154.  
  155.         | |    Raster Data    | |       |   
  156.  
  157.         | +-------------------+ |    ---+   
  158.  
  159.         . . .               . . .   
  160.  
  161.         |-    GIF Terminator   -|   
  162.  
  163.         +-----------------------+
  164.  
  165. Graphics Interchange Format (GIF)                                    Page 4
  166.  
  167. Specification
  168.  
  169.  GIF SIGNATURE
  170.  
  171.         The following GIF Signature identifies  the  data  following  as  a
  172.  
  173.    valid GIF image stream.  It consists of the following six characters:
  174.  
  175.              G I F 8 7 a
  176.  
  177.         The last three characters '87a' may be viewed as a  version  number
  178.  
  179.    for  this  particular  GIF  definition  and will be used in general as a
  180.  
  181.    reference  in  documents  regarding  GIF  that   address   any   version
  182.  
  183.    dependencies.
  184.  
  185.  SCREEN DESCRIPTOR
  186.  
  187.         The Screen Descriptor describes the overall parameters for all  GIF
  188.  
  189.    images  following.  It defines the overall dimensions of the image space
  190.  
  191.    or logical screen required, the existance of color mapping  information,
  192.  
  193.    background  screen color, and color depth information.  This information
  194.  
  195.    is stored in a series of 8-bit bytes as described below.
  196.  
  197.               bits
  198.  
  199.          7 6 5 4 3 2 1 0  Byte #
  200.  
  201.         +---------------+
  202.  
  203.         |               |  1
  204.  
  205.         +-Screen Width -+      Raster width in pixels (LSB first)
  206.  
  207.         |               |  2
  208.  
  209.         +---------------+
  210.  
  211.         |               |  3
  212.  
  213.         +-Screen Height-+      Raster height in pixels (LSB first)
  214.  
  215.         |               |  4
  216.  
  217.         +-+-----+-+-----+      M = 1, Global color map follows Descriptor
  218.  
  219.         |M|  cr |0|pixel|  5   cr+1 = # bits of color resolution
  220.  
  221.         +-+-----+-+-----+      pixel+1 = # bits/pixel in image
  222.  
  223.         |   background  |  6   background=Color index of screen background
  224.  
  225.         +---------------+          (color is defined from the Global color
  226.  
  227.         |0 0 0 0 0 0 0 0|  7        map or default map if none specified)
  228.  
  229.         +---------------+
  230.  
  231.         The logical screen width and height can both  be  larger  than  the
  232.  
  233.    physical  display.   How  images  larger  than  the physical display are
  234.  
  235.    handled is implementation dependent and can take advantage  of  hardware
  236.  
  237.    characteristics  (e.g.   Macintosh scrolling windows).  Otherwise images
  238.  
  239.    can be clipped to the edges of the display.
  240.  
  241.         The value of 'pixel' also defines  the  maximum  number  of  colors
  242.  
  243.    within  an  image.   The  range  of  values  for 'pixel' is 0 to 7 which
  244.  
  245.    represents 1 to 8 bits.  This translates to a range of 2 (B & W) to  256
  246.  
  247.    colors.   Bit  3 of word 5 is reserved for future definition and must be
  248.  
  249.    zero.
  250.  
  251. Graphics Interchange Format (GIF)                                    Page 5
  252.  
  253. Specification
  254.  
  255.  GLOBAL COLOR MAP
  256.  
  257.         The Global Color Map is optional but recommended for  images  where
  258.  
  259.    accurate color rendition is desired.  The existence of this color map is
  260.  
  261.    indicated in the 'M' field of byte 5 of the Screen Descriptor.  A  color
  262.  
  263.    map  can  also  be associated with each image in a GIF file as described
  264.  
  265.    later.  However this  global  map  will  normally  be  used  because  of
  266.  
  267.    hardware  restrictions  in equipment available today.  In the individual
  268.  
  269.    Image Descriptors the 'M' flag will normally be  zero.   If  the  Global
  270.  
  271.    Color  Map  is  present,  it's definition immediately follows the Screen
  272.  
  273.    Descriptor.   The  number  of  color  map  entries  following  a  Screen
  274.  
  275.    Descriptor  is equal to 2**(# bits per pixel), where each entry consists
  276.  
  277.    of three byte values representing the relative intensities of red, green
  278.  
  279.    and blue respectively.  The structure of the Color Map block is:
  280.  
  281.               bits
  282.  
  283.          7 6 5 4 3 2 1 0  Byte #
  284.  
  285.         +---------------+
  286.  
  287.         | red intensity |  1    Red value for color index 0
  288.  
  289.         +---------------+
  290.  
  291.         |green intensity|  2    Green value for color index 0
  292.  
  293.         +---------------+
  294.  
  295.         | blue intensity|  3    Blue value for color index 0
  296.  
  297.         +---------------+
  298.  
  299.         | red intensity |  4    Red value for color index 1
  300.  
  301.         +---------------+
  302.  
  303.         |green intensity|  5    Green value for color index 1
  304.  
  305.         +---------------+
  306.  
  307.         | blue intensity|  6    Blue value for color index 1
  308.  
  309.         +---------------+
  310.  
  311.         :               :       (Continues for remaining colors)
  312.  
  313.         Each image pixel value received will be displayed according to  its
  314.  
  315.    closest match with an available color of the display based on this color
  316.  
  317.    map.  The color components represent a fractional intensity  value  from
  318.  
  319.    none  (0)  to  full (255).  White would be represented as (255,255,255),
  320.  
  321.    black as (0,0,0) and medium yellow as (180,180,0).  For display, if  the
  322.  
  323.    device  supports fewer than 8 bits per color component, the higher order
  324.  
  325.    bits of each component are used.  In the creation of  a  GIF  color  map
  326.  
  327.    entry  with  hardware  supporting  fewer  than 8 bits per component, the
  328.  
  329.    component values for the hardware  should  be  converted  to  the  8-bit
  330.  
  331.    format with the following calculation:
  332.  
  333.         <map_value> = <component_value>*255/(2**<nbits> -1)
  334.  
  335.         This assures accurate translation of colors for all  displays.   In
  336.  
  337.    the  cases  of  creating  GIF images from hardware without color palette
  338.  
  339.    capability, a fixed palette should be created  based  on  the  available
  340.  
  341.    display  colors for that hardware.  If no Global Color Map is indicated,
  342.  
  343.    a default color map is generated internally  which  maps  each  possible
  344.  
  345.    incoming  color  index to the same hardware color index modulo <n> where
  346.  
  347.    <n> is the number of available hardware colors.
  348.  
  349. Graphics Interchange Format (GIF)                                    Page 6
  350.  
  351. Specification
  352.  
  353.  IMAGE DESCRIPTOR
  354.  
  355.         The Image Descriptor defines the actual placement  and  extents  of
  356.  
  357.    the  following  image within the space defined in the Screen Descriptor.
  358.  
  359.    Also defined are flags to indicate the presence of a local color  lookup
  360.  
  361.    map, and to define the pixel display sequence.  Each Image Descriptor is
  362.  
  363.    introduced by an image separator  character.   The  role  of  the  Image
  364.  
  365.    Separator  is simply to provide a synchronization character to introduce
  366.  
  367.    an Image Descriptor.  This is desirable if a GIF file happens to contain
  368.  
  369.    more  than  one  image.   This  character  is defined as 0x2C hex or ','
  370.  
  371.    (comma).  When this character is encountered between images,  the  Image
  372.  
  373.    Descriptor will follow immediately.
  374.  
  375.         Any characters encountered between the end of a previous image  and
  376.  
  377.    the image separator character are to be ignored.  This allows future GIF
  378.  
  379.    enhancements to be present in newer image formats and yet ignored safely
  380.  
  381.    by older software decoders.
  382.  
  383.               bits
  384.  
  385.          7 6 5 4 3 2 1 0  Byte #
  386.  
  387.         +---------------+
  388.  
  389.         |0 0 1 0 1 1 0 0|  1    ',' - Image separator character
  390.  
  391.         +---------------+
  392.  
  393.         |               |  2    Start of image in pixels from the
  394.  
  395.         +-  Image Left -+       left side of the screen (LSB first)
  396.  
  397.         |               |  3
  398.  
  399.         +---------------+
  400.  
  401.         |               |  4
  402.  
  403.         +-  Image Top  -+       Start of image in pixels from the
  404.  
  405.         |               |  5    top of the screen (LSB first)
  406.  
  407.         +---------------+
  408.  
  409.         |               |  6
  410.  
  411.         +- Image Width -+       Width of the image in pixels (LSB first)
  412.  
  413.         |               |  7
  414.  
  415.         +---------------+
  416.  
  417.         |               |  8
  418.  
  419.         +- Image Height-+       Height of the image in pixels (LSB first)
  420.  
  421.         |               |  9
  422.  
  423.         +-+-+-+-+-+-----+       M=0 - Use global color map, ignore 'pixel'
  424.  
  425.         |M|I|0|0|0|pixel| 10    M=1 - Local color map follows, use 'pixel'
  426.  
  427.         +-+-+-+-+-+-----+       I=0 - Image formatted in Sequential order
  428.  
  429.                                 I=1 - Image formatted in Interlaced order
  430.  
  431.                                 pixel+1 - # bits per pixel for this image
  432.  
  433.         The specifications for the image position and size must be confined
  434.  
  435.    to  the  dimensions defined by the Screen Descriptor.  On the other hand
  436.  
  437.    it is not necessary that the image fill the entire screen defined.
  438.  
  439.  LOCAL COLOR MAP
  440.  
  441. Graphics Interchange Format (GIF)                                    Page 7
  442.  
  443. Specification
  444.  
  445.         A Local Color Map is optional and defined here for future use.   If
  446.  
  447.    the  'M' bit of byte 10 of the Image Descriptor is set, then a color map
  448.  
  449.    follows the Image Descriptor that applies only to the  following  image.
  450.  
  451.    At the end of the image, the color map will revert to that defined after
  452.  
  453.    the Screen Descriptor.  Note that the 'pixel' field of byte  10  of  the
  454.  
  455.    Image  Descriptor  is used only if a Local Color Map is indicated.  This
  456.  
  457.    defines the parameters not only for the image pixel size, but determines
  458.  
  459.    the  number  of color map entries that follow.  The bits per pixel value
  460.  
  461.    will also revert to the value specified in the  Screen  Descriptor  when
  462.  
  463.    processing of the image is complete.
  464.  
  465.  RASTER DATA
  466.  
  467.         The format of the actual image is defined as the  series  of  pixel
  468.  
  469.    color  index  values that make up the image.  The pixels are stored left
  470.  
  471.    to right sequentially for an image row.  By default each  image  row  is
  472.  
  473.    written  sequentially, top to bottom.  In the case that the Interlace or
  474.  
  475.    'I' bit is set in byte 10 of the Image Descriptor then the row order  of
  476.  
  477.    the  image  display  follows  a  four-pass process in which the image is
  478.  
  479.    filled in by widely spaced rows.  The first pass writes every  8th  row,
  480.  
  481.    starting  with  the top row of the image window.  The second pass writes
  482.  
  483.    every 8th row starting at the fifth row from the top.   The  third  pass
  484.  
  485.    writes every 4th row starting at the third row from the top.  The fourth
  486.  
  487.    pass completes the image, writing  every  other  row,  starting  at  the
  488.  
  489.    second row from the top.  A graphic description of this process follows:
  490.  
  491.    Image
  492.  
  493.    Row  Pass 1  Pass 2  Pass 3  Pass 4          Result
  494.  
  495.    ---------------------------------------------------
  496.  
  497.      0  **1a**                                  **1a**
  498.  
  499.      1                          **4a**          **4a**
  500.  
  501.      2                  **3a**                  **3a**
  502.  
  503.      3                          **4b**          **4b**
  504.  
  505.      4          **2a**                          **2a**
  506.  
  507.      5                          **4c**          **4c**
  508.  
  509.      6                  **3b**                  **3b**
  510.  
  511.      7                          **4d**          **4d**
  512.  
  513.      8  **1b**                                  **1b**
  514.  
  515.      9                          **4e**          **4e**
  516.  
  517.     10                  **3c**                  **3c**
  518.  
  519.     11                          **4f**          **4f**
  520.  
  521.     12          **2b**                          **2b**
  522.  
  523.    . . . 
  524.  
  525.         The image pixel values are processed as a series of  color  indices
  526.  
  527.    which  map  into the existing color map.  The resulting color value from
  528.  
  529.    the map is what is actually displayed.  This series  of  pixel  indices,
  530.  
  531.    the  number  of  which  is equal to image-width*image-height pixels, are
  532.  
  533.    passed to the GIF image data stream one value per pixel, compressed  and
  534.  
  535.    packaged  according  to  a  version  of the LZW compression algorithm as
  536.  
  537.    defined in Appendix C.
  538.  
  539. Graphics Interchange Format (GIF)                                    Page 8
  540.  
  541. Specification
  542.  
  543.  GIF TERMINATOR
  544.  
  545.         In order to provide a synchronization for the termination of a  GIF
  546.  
  547.    image  file,  a  GIF  decoder  will process the end of GIF mode when the
  548.  
  549.    character 0x3B hex or ';' is found after an image  has  been  processed.
  550.  
  551.    By  convention  the  decoding software will pause and wait for an action
  552.  
  553.    indicating that the user is ready to continue.  This may be  a  carriage
  554.  
  555.    return  entered  at  the  keyboard  or  a  mouse click.  For interactive
  556.  
  557.    applications this user action must  be  passed  on  to  the  host  as  a
  558.  
  559.    carriage  return  character  so  that the host application can continue.
  560.  
  561.    The decoding software will then typically leave graphics mode and resume
  562.  
  563.    any previous process.
  564.  
  565.  GIF EXTENSION BLOCKS
  566.  
  567.         To provide for orderly extension of the GIF definition, a mechanism
  568.  
  569.    for  defining  the  packaging  of extensions within a GIF data stream is
  570.  
  571.    necessary.  Specific GIF extensions are to be defined and documented  by
  572.  
  573.    CompuServe in order to provide a controlled enhancement path.
  574.  
  575.         GIF Extension Blocks are packaged in a manner similar to that  used
  576.  
  577.    by the raster data though not compressed.  The basic structure is:
  578.  
  579.          7 6 5 4 3 2 1 0  Byte #
  580.  
  581.         +---------------+
  582.  
  583.         |0 0 1 0 0 0 0 1|  1       '!' - GIF Extension Block Introducer
  584.  
  585.         +---------------+
  586.  
  587.         | function code |  2       Extension function code (0 to 255)
  588.  
  589.         +---------------+    ---+
  590.  
  591.         |  byte count   |       |
  592.  
  593.         +---------------+       |
  594.  
  595.         :               :       +-- Repeated as many times as necessary
  596.  
  597.         |func data bytes|       |
  598.  
  599.         :               :       |
  600.  
  601.         +---------------+    ---+
  602.  
  603.         . . .       . . .
  604.  
  605.         +---------------+
  606.  
  607.         |0 0 0 0 0 0 0 0|       zero byte count (terminates block)
  608.  
  609.         +---------------+
  610.  
  611.         A GIF Extension Block may immediately preceed any Image  Descriptor
  612.  
  613.    or occur before the GIF Terminator.
  614.  
  615.         All GIF decoders must be able to recognize  the  existence  of  GIF
  616.  
  617.    Extension  Blocks  and  read past them if unable to process the function
  618.  
  619.    code.  This ensures that older decoders will be able to process extended
  620.  
  621.    GIF   image   files   in  the  future,  though  without  the  additional
  622.  
  623.    functionality.
  624.  
  625. Graphics Interchange Format (GIF)                                    Page 9
  626.  
  627. Appendix A - Glossary
  628.  
  629.                                  GLOSSARY
  630.  
  631. Pixel - The smallest picture element of a  graphics  image.   This  usually
  632.  
  633.    corresponds  to  a single dot on a graphics screen.  Image resolution is
  634.  
  635.    typically given in units of  pixels.   For  example  a  fairly  standard
  636.  
  637.    graphics  screen  format  is  one 320 pixels across and 200 pixels high.
  638.  
  639.    Each pixel can  appear  as  one  of  several  colors  depending  on  the
  640.  
  641.    capabilities of the graphics hardware.
  642.  
  643. Raster - A horizontal row of pixels representing one line of an  image.   A
  644.  
  645.    typical method of working with images since most hardware is oriented to
  646.  
  647.    work most efficiently in this manner.
  648.  
  649. LSB - Least Significant Byte.  Refers to a convention for two byte  numeric
  650.  
  651.    values in which the less significant byte of the value preceeds the more
  652.  
  653.    significant byte.  This convention is typical on many microcomputers.
  654.  
  655. Color Map - The list of definitions of each color  used  in  a  GIF  image.
  656.  
  657.    These  desired  colors are converted to available colors through a table
  658.  
  659.    which is derived by assigning an incoming color index (from  the  image)
  660.  
  661.    to  an  output  color  index  (of  the  hardware).   While the color map
  662.  
  663.    definitons are specified in a GIF image, the output  pixel  colors  will
  664.  
  665.    vary  based  on  the  hardware used and its ability to match the defined
  666.  
  667.    color.
  668.  
  669. Interlace - The method of displaying a GIF image in which  multiple  passes
  670.  
  671.    are  made,  outputting  raster  lines  spaced  apart to provide a way of
  672.  
  673.    visualizing the general content of an entire image  before  all  of  the
  674.  
  675.    data has been processed.
  676.  
  677. B Protocol - A CompuServe-developed error-correcting file transfer protocol
  678.  
  679.    available  in  the  public  domain  and implemented in CompuServe VIDTEX
  680.  
  681.    products.  This error checking mechanism will be used  in  transfers  of
  682.  
  683.    GIF images for interactive applications.
  684.  
  685. LZW - A sophisticated data compression algorithm  based  on  work  done  by
  686.  
  687.    Lempel-Ziv  &  Welch  which  has  the feature of very efficient one-pass
  688.  
  689.    encoding and decoding.  This allows the image  to  be  decompressed  and
  690.  
  691.    displayed  at  the  same  time.   The  original  article from which this
  692.  
  693.    technique was adapted is:
  694.  
  695.           Terry  A.   Welch,  "A  Technique  for  High   Performance   Data
  696.  
  697.           Compression", IEEE Computer, vol 17 no 6 (June 1984)
  698.  
  699.         This basic algorithm is also used in the  public  domain  ARC  file
  700.  
  701.    compression  utilities.   The  CompuServe  adaptation  of LZW for GIF is
  702.  
  703.    described in Appendix C.
  704.  
  705. Graphics Interchange Format (GIF)                                   Page 10
  706.  
  707. Appendix B - Interactive Sequences
  708.  
  709.            GIF Sequence Exchanges for an Interactive Environment
  710.  
  711.         The following sequences are defined for use  in  mediating  control
  712.  
  713.    between a GIF sender and GIF receiver over an interactive communications
  714.  
  715.    line.  These  sequences  do  not  apply  to  applications  that  involve
  716.  
  717.    downloading  of  static  GIF  files and are not considered part of a GIF
  718.  
  719.    file.
  720.  
  721.  GIF CAPABILITIES ENQUIRY
  722.  
  723.         The GCE sequence is issued from a host and requests an  interactive
  724.  
  725.    GIF  decoder  to  return  a  response  message that defines the graphics
  726.  
  727.    parameters for the decoder.  This involves returning  information  about
  728.  
  729.    available screen sizes, number of bits/color supported and the amount of
  730.  
  731.    color detail supported.  The escape sequence for the GCE is defined as:
  732.  
  733.         ESC [ > 0 g     (g is lower case, spaces inserted for clarity)
  734.  
  735.                          (0x1B 0x5B 0x3E 0x30 0x67)
  736.  
  737.  GIF CAPABILITIES RESPONSE
  738.  
  739.         The GIF Capabilities Response message is returned by an interactive
  740.  
  741.    GIF  decoder  and  defines  the  decoder's  display capabilities for all
  742.  
  743.    graphics modes that are supported by the software.  Note that  this  can
  744.  
  745.    also include graphics printers as well as a monitor screen.  The general
  746.  
  747.    format of this message is:
  748.  
  749.      #version;protocol{;dev, width, height, color-bits, color-res}... <CR>
  750.  
  751.    '#'          - GCR identifier character (Number Sign)
  752.  
  753.    version      - GIF format version number;  initially '87a'
  754.  
  755.    protocol='0' - No end-to-end protocol supported by decoder
  756.  
  757.                   Transfer as direct 8-bit data stream.
  758.  
  759.    protocol='1' - Can use an error correction protocol to transfer GIF data
  760.  
  761.                interactively from the host directly to the display.
  762.  
  763.    dev = '0'    - Screen parameter set follows
  764.  
  765.    dev = '1'    - Printer parameter set follows
  766.  
  767.    width        - Maximum supported display width in pixels
  768.  
  769.    height       - Maximum supported display height in pixels
  770.  
  771.    color-bits   - Number of  bits  per  pixel  supported.   The  number  of
  772.  
  773.                supported colors is therefore 2**color-bits.
  774.  
  775.    color-res    - Number of bits  per  color  component  supported  in  the
  776.  
  777.                hardware  color  palette.   If  color-res  is  '0'  then  no
  778.  
  779.                hardware palette table is available.
  780.  
  781.         Note that all values in the  GCR  are  returned  as  ASCII  decimal
  782.  
  783.    numbers and the message is terminated by a Carriage Return character.
  784.  
  785. Graphics Interchange Format (GIF)                                   Page 11
  786.  
  787. Appendix B - Interactive Sequences
  788.  
  789.         The  following   GCR   message   describes   three   standard   EGA
  790.  
  791.    configurations  with  no  printer;  the GIF data stream can be processed
  792.  
  793.    within an error correcting protocol:
  794.  
  795.         #87a;1 ;0,320,200,4,0 ;0,640,200,2,2 ;0,640,350,4,2<CR>
  796.  
  797.  ENTER GIF GRAPHICS MODE
  798.  
  799.         Two sequences are currently defined to invoke  an  interactive  GIF
  800.  
  801.    decoder into action.  The only difference between them is that different
  802.  
  803.    output media are selected.  These sequences are:
  804.  
  805.      ESC [ > 1 g   Display GIF image on screen
  806.  
  807.                    (0x1B 0x5B 0x3E 0x31 0x67)
  808.  
  809.      ESC [ > 2 g   Display image directly to an attached graphics  printer.
  810.  
  811.                    The  image  may optionally be displayed on the screen as
  812.  
  813.                    well.
  814.  
  815.                    (0x1B 0x5B 0x3E 0x32 0x67)
  816.  
  817.         Note that the 'g' character terminating each sequence is  in  lower
  818.  
  819.    case.
  820.  
  821.  INTERACTIVE ENVIRONMENT
  822.  
  823.         The assumed environment for the transmission of GIF image data from
  824.  
  825.    an  interactive  application  is  a  full 8-bit data stream from host to
  826.  
  827.    micro.  All 256 character codes must be transferrable.  The establishing
  828.  
  829.    of  an 8-bit data path for communications will normally be taken care of
  830.  
  831.    by the host application programs.  It is however  up  to  the  receiving
  832.  
  833.    communications programs supporting GIF to be able to receive and pass on
  834.  
  835.    all 256 8-bit codes to the GIF decoder software.
  836.  
  837. Graphics Interchange Format (GIF)                                   Page 12
  838.  
  839. Appendix C - Image Packaging & Compression
  840.  
  841.         The Raster Data stream that represents the actual output image  can
  842.  
  843.    be represented as:
  844.  
  845.          7 6 5 4 3 2 1 0
  846.  
  847.         +---------------+
  848.  
  849.         |   code size   | 
  850.  
  851.         +---------------+     ---+
  852.  
  853.         |blok byte count|        |
  854.  
  855.         +---------------+        |
  856.  
  857.         :               :        +-- Repeated as many times as necessary
  858.  
  859.         |  data bytes   |        |
  860.  
  861.         :               :        |
  862.  
  863.         +---------------+     ---+
  864.  
  865.         . . .       . . .
  866.  
  867.         +---------------+
  868.  
  869.         |0 0 0 0 0 0 0 0|       zero byte count (terminates data stream)
  870.  
  871.         +---------------+
  872.  
  873.         The conversion of the image from a series  of  pixel  values  to  a
  874.  
  875.    transmitted or stored character stream involves several steps.  In brief
  876.  
  877.    these steps are:
  878.  
  879.    1.  Establish the Code Size -  Define  the  number  of  bits  needed  to
  880.  
  881.        represent the actual data.
  882.  
  883.    2.  Compress the Data - Compress the series of image pixels to a  series
  884.  
  885.        of compression codes.
  886.  
  887.    3.  Build a Series of Bytes - Take the  set  of  compression  codes  and
  888.  
  889.        convert to a string of 8-bit bytes.
  890.  
  891.    4.  Package the Bytes - Package sets of bytes into blocks  preceeded  by
  892.  
  893.        character counts and output.
  894.  
  895. ESTABLISH CODE SIZE
  896.  
  897.         The first byte of the GIF Raster Data stream is a value  indicating
  898.  
  899.    the minimum number of bits required to represent the set of actual pixel
  900.  
  901.    values.  Normally this will be the same as the  number  of  color  bits.
  902.  
  903.    Because  of  some  algorithmic constraints however, black & white images
  904.  
  905.    which have one color bit must be indicated as having a code size  of  2.
  906.  
  907.    This  code size value also implies that the compression codes must start
  908.  
  909.    out one bit longer.
  910.  
  911. COMPRESSION
  912.  
  913.         The LZW algorithm converts a series of data values into a series of
  914.  
  915.    codes  which may be raw values or a code designating a series of values.
  916.  
  917.    Using text characters as an analogy,  the  output  code  consists  of  a
  918.  
  919.    character or a code representing a string of characters.
  920.  
  921. Graphics Interchange Format (GIF)                                   Page 13
  922.  
  923. Appendix C - Image Packaging & Compression
  924.  
  925.         The LZW algorithm used in  GIF  matches  algorithmically  with  the
  926.  
  927.    standard LZW algorithm with the following differences:
  928.  
  929.    1.  A   special   Clear   code   is    defined    which    resets    all
  930.  
  931.        compression/decompression parameters and tables to a start-up state.
  932.  
  933.        The value of this code is 2**<code size>.  For example if  the  code
  934.  
  935.        size  indicated  was 4 (image was 4 bits/pixel) the Clear code value
  936.  
  937.        would be 16 (10000 binary).  The Clear code can appear at any  point
  938.  
  939.        in the image data stream and therefore requires the LZW algorithm to
  940.  
  941.        process succeeding codes as if  a  new  data  stream  was  starting.
  942.  
  943.        Encoders  should output a Clear code as the first code of each image
  944.  
  945.        data stream.
  946.  
  947.    2.  An End of Information code is defined that explicitly indicates  the
  948.  
  949.        end  of  the image data stream.  LZW processing terminates when this
  950.  
  951.        code is encountered.  It must be the last code output by the encoder
  952.  
  953.        for an image.  The value of this code is <Clear code>+1.
  954.  
  955.    3.  The first available compression code value is <Clear code>+2.
  956.  
  957.    4.  The output codes are of variable length, starting  at  <code size>+1
  958.  
  959.        bits  per code, up to 12 bits per code.  This defines a maximum code
  960.  
  961.        value of 4095 (hex FFF).  Whenever the LZW code value  would  exceed
  962.  
  963.        the  current  code length, the code length is increased by one.  The
  964.  
  965.        packing/unpacking of these codes must then be altered to reflect the
  966.  
  967.        new code length.
  968.  
  969. BUILD 8-BIT BYTES
  970.  
  971.         Because the LZW compression  used  for  GIF  creates  a  series  of
  972.  
  973.    variable  length  codes, of between 3 and 12 bits each, these codes must
  974.  
  975.    be reformed into a series of 8-bit bytes that  will  be  the  characters
  976.  
  977.    actually stored or transmitted.  This provides additional compression of
  978.  
  979.    the image.  The codes are formed into a stream of bits as if  they  were
  980.  
  981.    packed  right to left and then picked off 8 bits at a time to be output.
  982.  
  983.    Assuming a character array of 8 bits per character and using 5 bit codes
  984.  
  985.    to be packed, an example layout would be similar to:
  986.  
  987.          byte n       byte 5   byte 4   byte 3   byte 2   byte 1
  988.  
  989.         +-.....-----+--------+--------+--------+--------+--------+
  990.  
  991.         | and so on |hhhhhggg|ggfffffe|eeeedddd|dcccccbb|bbbaaaaa|
  992.  
  993.         +-.....-----+--------+--------+--------+--------+--------+
  994.  
  995.         Note that the physical  packing  arrangement  will  change  as  the
  996.  
  997.    number  of  bits per compression code change but the concept remains the
  998.  
  999.    same.
  1000.  
  1001. PACKAGE THE BYTES
  1002.  
  1003.         Once the bytes have been created, they are grouped into blocks  for
  1004.  
  1005.    output by preceeding each block of 0 to 255 bytes with a character count
  1006.  
  1007.    byte.  A block with a zero byte count terminates the Raster Data  stream
  1008.  
  1009.    for  a  given  image.  These blocks are what are actually output for the
  1010.  
  1011. Graphics Interchange Format (GIF)                                   Page 14
  1012.  
  1013. Appendix C - Image Packaging & Compression
  1014.  
  1015.    GIF image.  This block format has the side effect of allowing a decoding
  1016.  
  1017.    program  the  ability to read past the actual image data if necessary by
  1018.  
  1019.    reading block counts and then skipping over the data.
  1020.  
  1021. Graphics Interchange Format (GIF)                                   Page 15
  1022.  
  1023. Appendix D - Multiple Image Processing
  1024.  
  1025.         Since a  GIF  data  stream  can  contain  multiple  images,  it  is
  1026.  
  1027.    necessary  to  describe  processing and display of such a file.  Because
  1028.  
  1029.    the image descriptor allows  for  placement  of  the  image  within  the
  1030.  
  1031.    logical  screen,  it is possible to define a sequence of images that may
  1032.  
  1033.    each be a partial screen, but in total  fill  the  entire  screen.   The
  1034.  
  1035.    guidelines for handling the multiple image situation are:
  1036.  
  1037.    1.  There is no pause between images.  Each is processed immediately  as
  1038.  
  1039.        seen by the decoder.
  1040.  
  1041.    2.  Each image explicitly overwrites any image  already  on  the  screen
  1042.  
  1043.        inside  of  its window.  The only screen clears are at the beginning
  1044.  
  1045.        and end of the  GIF  image  process.   See  discussion  on  the  GIF
  1046.  
  1047.        terminator.
  1048.  
  1049.