typedef unsigned long  Pixel;
typedef unsigned short Intensity;
typedef unsigned char  byte;

typedef struct rgbmap {
  unsigned int  size;          /* size of map, must be a power of 2 (2^n)   */
  unsigned int  used;          /* number of colors used in RGB map          */
  unsigned char compressed;    /* (internal) image uses colormap fully      */
  unsigned char reserved;      /* Reserved                                  */
  unsigned int  unused16;      /* (internal) color, which will not used     */
  Intensity    *red;           /* color values in range [0..65535]          */
  Intensity    *green;
  Intensity    *blue;
} RGBMap;

typedef struct Scaling {
  unsigned       count : 4;    /* use 1 point (a), or 2 (a,b), or 3 (a,b,c) */
  unsigned       a     : 4;    /* range: 0 (lowest) to 7 (highest) position */
  unsigned       b     : 4;    /* see COLORSCALE-Dialog                     */
  unsigned       c     : 4;
} Scaling;

/* image structure
 */

typedef struct Image {
  char          *title;        /* name of image, set also by new...Image()  */
  unsigned short type;         /* type of image, set by images.new...Image()*/
  unsigned short width;        /* width of image in pixels, set by ...      */
  unsigned short height;       /* height of image in pixels, set by ...     */
  unsigned short depth;        /* depth of image in bits, set by ...        */
  unsigned short unalignwidth; /* (internal) original width after alignment */
  RGBMap         rgb;          /* RGB map of image if IRGB/IGEM type        */
  byte          *data;         /* data rounded to full byte for each row    */
                               /* rounded to full word after alignment      */
  unsigned int   pixlen;       /* length of pixel: Mono/Color:1 ; TC:3      */
  Scaling        scalered;     /* (internal) scaling description for red    */
  Scaling        scalegreen;
  Scaling        scaleblue;
  Scaling        scaleadjust;
  unsigned       alignTo8      : 2; /* image is loaded  8 pixel aligned: 1
                                       image is loaded 16 pixel aligned: 2
                                       width is set to the shown image width*/
  unsigned       fastload      : 1; /* (internal)                           */
  unsigned       loadgdosfonts : 1; /* (internal)                           */
  unsigned       scaleused     : 1; /* (internal)                           */
  unsigned       unused        : 3; /* (internal)                           */
  unsigned       font_point    : 8; /* (internal)                           */
} Image;


#define IBITMAP    0x0011           /* image is a bitmap                    */
#define IATARIMONO 0x0011           /* image is Atari ST Mono BitPlane      */
#define IATARI_RGB 0x0012           /* image is Atari ST Color BitPlane     */
#define IATARI__TC 0x0013           /* image is Atari ST TrueColor          */
#define ITRUEC     0x0013           /* image is TRUE-color                  */
#define IRGB       0x0014           /* image is RGB                         */
                                    /* All values up to 0x03FF reserved!    */

#define BITMAPP(IMAGE)      ((IMAGE)->type == IBITMAP)
#define ATARIMONOP(IMAGE)   ((IMAGE)->type == IATARIMONO)
#define RGBP(IMAGE)         ((IMAGE)->type == IRGB)
#define ATARI_RGBP(IMAGE)   ((IMAGE)->type == IATARI_RGB)
#define TRUECP(IMAGE)       ((IMAGE)->type == ITRUEC)
#define ATARI__TCP(IMAGE)   ((IMAGE)->type == IATARI__TC)

#define ATARIRASTERP(IMAGE) ((IMAGE)->type <= ITRUEC)
#define ALL_RASTERP(IMAGE)  ((IMAGE)->type <= IRGB)
#define MONOCHROMEP(IMAGE)  ((IMAGE)->type == IBITMAP)
#define PALETTEP(IMAGE)     ((IMAGE)->type == IATARI_RGB || (IMAGE)->type == IRGB)
#define TRUECOLORP(IMAGE)   ((IMAGE)->type == ITRUEC)
