IMAGE DATABASE FORMAT
---------------------

The images are stored in the databases of type 'BMPF'
with creator ID 'DOB_'.  The data laid out the following way:

The first record contains the header:
/* first record of BX database */
typedef struct _BX_HEADER {
   UInt16 type PACKED;      /* should always be 'BX' */
   UInt8 verMajor PACKED;   /* major version # */
   UInt8 verMinor PACKED;   /* minor version # */
   UInt32 numChunks PACKED; /* number of data chunks */
   BX_CHUNK_INFO chunk[0];  /* 'numChunks' of chunk info records */
} BX_HEADER, *BX_HEADER_PTR;


It is followed by a list of numChunks of chunk information descriptors 
identifying type for the following records of the database. The records 
containing the image data have correspondent descriptors of type 'BM':
typedef struct _BX_CHUNK_INFO {
   UInt16 seq_id PACKED;    /* chunk sequence unique ID */
   UInt16 type PACKED;      /* chunk type */
   UInt32 reserved1 PACKED; /* reserved for future use as length */
} BX_CHUNK_INFO, *BX_CHUNK_INFO_PTR;


The first record of the 'BM' type contains image header and 
palette (if 8-bit color image):
/* bitmap first record */
typedef struct {
   UInt32 size PACKED;              /* Header size in bytes      */
   UInt32 width PACKED;             /* Width of image */
   UInt32 height PACKED;            /* Height of image */
   UInt16 planes PACKED;            /* Number of colour planes   */
   UInt16 bits PACKED;              /* Bits per pixel            */
   UInt32 compression PACKED;       /* Compression type          */
   UInt32 imagesize PACKED;         /* Image size in bytes       */
   UInt32 xresolution PACKED;       /* Pixels per meter          */
   UInt32 yresolution PACKED;       /* Pixels per meter          */
   UInt32 ncolours PACKED;          /* Number of colours         */
   UInt32 importantcolours PACKED;  /* Important colours         */
} BMP_INFOHEADER;


The "compression" field defines what interlacing technique, 
data filter, and compression algorithm were applied to the image data
(there are macros listed down below that show the compression field layout).

Currently there no data filters supported. The compression
algorithm can be ZLIB or none. The interlacing can be P2 or none.

The P2 interlacing allows to start showing scaled down image at the early
stages of loading gradually zooming in when more data become available.
If the normal image bytes layout for let say 8-bit color encoded image
of dimension x,y is as follows:
 (0,0)   (1,0)   ... (x-1,0)
 (0,1)   (1,1)   ... (x-1,1)
           ...
 (0,y-1) (1,y-1) ... (x-1,y-1)

The P2 interlaced layout is like this:
 (0,0)
 (x/2, 0) (x/2, y/2) (0, y/2)
 (x/4, 0) (x/4, y/4) (0, y/4) (x/2+x/4, 0) (x/2+x/4, y/2+y/4) (0, y/2+y/4)
 ...

/* Compression - should match similar definition in Converter project */
/* Interlace */
#define GET_COMP_INT(x)    (((x) & 0xFF000000) >> 24)
#define SET_COMP_INT(x, i) (((x) & 0x00FFFFFF) | ((i) << 24))
#define COMP_INT_TYPE_NONE 0
#define COMP_INT_TYPE_P2   1

/* Image data filter */
#define GET_COMP_FILTER(x)    (((x) & 0x00FFF000) >> 16)
#define SET_COMP_FILTER(x, f) (((x) & 0xFF000FFF) | ((f) << 16))
#define COMP_FILTER_TYPE_NONE 0

/* Compression algorithm */
#define GET_COMP_ALG(x)     ((x) & 0x00000FFF)
#define SET_COMP_ALG(x, a)  (((x) & 0xFFFFF000) | (a))
#define COMP_ALG_TYPE_NONE 0
#define COMP_ALG_TYPE_ZLIB 1 /* Zlib compression */

