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
