/* iff.h; NewZAP support routines; (c) 1986-91 DJH (24-BIT) */

#include <functions.h>
#include <exec/memory.h>
#include <graphics/gfx.h>
#include <graphics/view.h>
#include <intuition/intuition.h>
#include <libraries/dos.h>

#define LOWIDTH  376 /* includes OVERSCAN! */
#define LOHEIGHT 242
#define MAXCOLORS 256	/* enough for VGA */

struct PicMap {
  long ViewModes;
  UWORD colormap[MAXCOLORS];	/* Amiga-ized LoadRGB4() palette */
  UBYTE palette[MAXCOLORS*3];	/* raw RGB palette */
  struct BitMap BitMap;
  PLANEPTR planes[24-8];	/* extra planes for 24-bit apps */
};

typedef enum { DISK_MODE,RAM_MODE } LoadMode;

#define DISK_ERR   1  /* error processing */
#define IFF_ERR    2
#define OUT_OF_MEM 3
#define EXPAND_ERR 4
#define BAD_MODE   5

/* guaranteed to work right with 16 or 32 bit int's */
#define MakeID(a,b,c,d) ( ((long)a)<<24 | ((long)b)<<16 | (c)<<8  | (d) )

#define ID_FORM MakeID('F','O','R','M')
#define ID_ILBM MakeID('I','L','B','M')
#define ID_BMHD MakeID('B','M','H','D')
#define ID_CAMG MakeID('C','A','M','G')
#define ID_CMAP MakeID('C','M','A','P')
#define ID_BODY MakeID('B','O','D','Y')

#define mskNone 0
#define mskHasMask 1
#define cmpByteRun1 1

#define ROUNDODDUP(a) (((a)+1)&(~1L))

typedef struct {
  long ckID,ckSize;
} Chunk;

typedef struct {
  short w,h,x,y;
  char  nPlanes,masking,compression,pad1;
  short transparentColor;
  char  xAspect, yAspect;
  short pageWidth,pageHeight;
} BitMapHeader;


#define SafeRead(a,b,c) if (ReadNEW(a,(char *)b,c)==-1L) \
  { CloseNEW(a); return(DISK_ERR); }

/* function prototypes */

BPTR OpenNEW(unsigned char *name, long accessMode);
long ReadNEW(BPTR file,char *buffer,long length);
long SeekNEW(BPTR file,long position,long tmode);
void CloseNEW(BPTR file);
ReadILBM(char *fspec,LoadMode mode, struct PicMap *picmap);
void FreeBitMap(struct BitMap *bitmap);
Expand(BitMapHeader *bmhd, unsigned char *sourcebuf, struct BitMap *bitmap);
