#include <stdio.h>

#define compressedBE 0x80
#define compressedLE 0x01

#define directColorLE 0x20

#define RED_BITS                     5
#define GREEN_BITS                   6
#define BLUE_BITS                    5
#define MAX_RED                      ( ( 1 << RED_BITS ) - 1 )
#define MAX_GREEN                    ( ( 1 << GREEN_BITS ) - 1 )
#define MAX_BLUE                     ( ( 1 << BLUE_BITS ) - 1 )

typedef enum {
        palmPixelFormatIndexed = 0,
        palmPixelFormat565,
        palmPixelFormat565LE,
        palmPixelFormatIndexedLE,
} PalmPixelFormatType;

/* Currently assumes little endian system */

typedef short Int16;
typedef unsigned short UInt16;
typedef signed char Int8;
typedef unsigned char UInt8;
typedef unsigned long UInt32;
typedef long Int32;
typedef char Boolean;

#define false 0
#define true  1

typedef struct {
       Int16  width;
       Int16  height;
       UInt16 rowBytes;
       UInt8  flags;
       UInt8  reserved0;
       UInt8  pixelSize;
       UInt8  version;
       UInt8  size;
       UInt8  pixelFormat;
       UInt8  unused;
       UInt8  compressionType;
       UInt16 density;
       UInt32 transparentValue;
       UInt32 nextBitmapOffset;
} PalmBitmapTypeV3;

typedef enum {
    palmBitmapCompressionTypeScanLine = 0,
    palmBitmapCompressionTypeRLE,
    palmBitmapCompressionTypePackBits,
    palmBitmapCompressionTypeEnd,
    palmBitmapCompressionTypeBest = 0x64,
    palmBitmapCompressionTypeNone = 0xFF
} PalmBitmapCompressionType;

typedef UInt16 UInt32NP[ 2 ];

typedef struct {
   UInt16 magic;
   UInt32NP fileSize;
   UInt16 res1;
   UInt16 res2;
   UInt32NP offset;

   UInt32NP infoSize;
   UInt32NP  width;
   UInt32NP  height;
   UInt16 planes;
   UInt16 bitsPerPixel;
   UInt32NP compressionType;
   UInt32NP imageSize;
   UInt32NP  xRes;
   UInt32NP  yRes;
   UInt32NP nColors;
   UInt32NP nImpColors;
} BMPHeaderType;
