Definition of the internal graphical format of GrafX2
Draft revision 0.97.1

  timage = record
    id          : array[0..3] of char; { GfX2                     }
    version     : word;                { 0100h                    }
    { All below must be equal to tsubimage }
    sizex,sizey : longint;
    bpp         : word;                { Bits Per Pixel           }
    bpl         : longint;             { Bytes Per Line           }
    pixel       : longint;             { bytes per Pixel          }
    size        : longint;             { Allocated memory         }
    imagestart  : longint;             { start of image to show   }
    palstart    : longint;             { start of palette         }
    flags       : longint;             { See description          }
    transcol    : longint;             { Transparent color        }
    time        : word;                { if animated: time in ms how long frame should be shown }
    { Hereafter all which is not in tsubimage}
    reserved    : array[0..5] of byte; { Should be all zero       }
    spotx,spoty : longint;             { Needed for cursor images }
    numofimages : word;                { e.g. animated images     }
    data        : tselector;           { Selector to the data     }
  end;

The TImage type sizes exact 64 bytes.
Currently supported bytes  per pixel are 1, 2, 3 and 4. For images with less
than 1 byte per pixel, pixel needs to be 1.

.NumOfImages

  NumOfImages is dedicated  to animated images and icons  with multiple color
  depths and  resolutions. Instead that the  image begins at offset  zero, at
  this point the following header repeats NumOfImages times,
  for each image one:
  tsubimage = record
    sizex,sizey : longint;
    bpp         : word;
    bpl         : longint;
    pixel       : longint;
    size        : longint;
    imagestart  : longint;
    palstart    : longint;
    flags       : longint;
    transcol    : longint;
    time        : word;
    reserved    : array[0..7] of byte;
  end;
  If there's a palette (bpp <= 8), then  the palette follows after the image.
  If bit 16 of the flags of timage is set,  then there's only one palette for
  all images.
  Only the lower part of flags applies to the global image flags in a TImage.

.Flags:

 Bit ³ Property, if set                        ³ must not appear with bit
 ----+-----------------------------------------+--------------------------
  0  ³ Color palette present (if bpp <= 8)     ³ 3,4
     ³ structure:                              ³
     ³ pal : array[0..1 shl bpp-1] of record   ³
     ³ case byte of                            ³
     ³   0 : (r,g,b,d : byte);                 ³
     ³   1 : (col : longint);                  ³
     ³ end;                                    ³
     ³ Position of palette in the memory block ³
     ³ needs to be written into palstart       ³
  1  ³ Image has transparent color/is a sprite ³ 3,4
  2  ³ Image is RLE-compressed                 ³ 3,4
  3  ³ Image has alphachannel (0..255)         ³ 0,1,2,25
  4  ³ RGB data needs to be swapped before put ³ 0,1,2,3,6,7,25
  5  ³ Image is multiple/ is animation         ³
  6  ³ Content of the image shall be added     ³ 0,1,2,3,4,25
     ³ to background when putting it           ³
  7  ³ Content of the image shall be subtracted³ 0,1,2,3,4,25
     ³ from background when putting it         ³
  8  ³ Image is greyscaled                     ³ 2,3,4,6,7,25
  9  ³ Image is a cursor, spotx and spoty are  ³
     ³ valid                                   ³
  24 ³ Image has got object, memory must not   ³
     ³ be released by any other than the object³
  25 ³ Palette is valid for all images         ³ 3,4,6,7
     ³ (numofimages > 1)                       ³

.Structure of the imagedata:

  8 Bit (1 byte per sample)
  array[1..sizey] of array[1..sizex] of byte;

  15/16 bit (2 bytes per sample)
  array[1..sizey] of array[1..sizex] of word;

  24 Bit (3 bytes per sample)
  array[1..sizey] of array[1..sizex] of record r,g,b : byte; end;

  32 Bit (4 bytes per sample)
  array[1..sizey] of array[1..sizex] of record r,g,b,d : byte; end;

  24 Bit with alphachannel (4 bytes per sample)
  array[1..sizey] of array[1..sizex] of record r,g,b,a : byte; end;

  NOTE:
  - allocated memory for any image must be divideable by 4 without
    rest
  - all images need to have at least 4 extra bytes after the image-
    data (needed by converters for memory access without checking)

  Other color depths won't be supported, maybe also YUV for videos or 1/2 bpp
  for printers.  But it's  obvious that there are enough  formats and already
  they need a lot of routines.

.RLE-compressed data:

  This format is mainly  designed for  sprites. It allows a very  fast sprite
  output without checking every time for the transparent color. The format of
  GrafX 2 compresses more efficient than pcx and is even faster decompressable.
  The resulting sprite  will be in most cases smaller than the  image before.
  The integreated RLE works with 2 bits. Allowed color-depths: 8,15,16,32
  The format works like follows:

  Each line is preceded by a word, which contains the size of the line in the
  memory. This allows  to jump to the next line without  decoding the current
  line. The advantage of instead putting  all the line-words as jump-position
  at the start of the image is that the size of an image is not restricted to
  64 Kbytes, which is too few in Truecolor, and we save for each line 2 bytes,
  because the  linestarts are not written  as longints before  the start of a
  line. After each word, the line begins. The first byte is a RLE-byte, which
  is encoded like this:
    Bits
      0..5 : lenght (unsigned, max 63)
      6..7 : RLE-information
    RLE-information:
      0 : overjump LENGTH samples on output (sprite)
      1 : reproduce following sample LENGTH times
      2 : copy LENGTH samples (following) to screen
      3 : checkerboard mode - overjump always one pixel (sprite)
          sample code:
          for i := 0 to lenght do putpixel(x+i*2,y,sample);
    One sample means one pixel in the colordepth. That means e.g.
    with 15/16 bpp one sample sizes 2 bytes.

.Saving images:
  GrafX2  includes  procedures  for saving  and loading  such images  to/from
  media. For  such purposes,  the header includes an ID and  a version number.
  The ID needs to be 'GfX2', otherwise  the image must not be loaded. Current
  version is 1.0,which is coded as  0100 hex. The extension of such files has
  to be 'GX2'.

Copyright (c) 1998-1999 by Stefan Goehler, Germany
