/* Copyright 1990 by Christopher A. Wichura.
   See file GIFMachine.doc for full description of rights.
*/

#include <exec/types.h>
#define DO_ARP_COPIES
#include <libraries/ArpBase.h>
#include <proto/exec.h>
#include <string.h>

/* reference ArpBase so that the #pragma's won't choke */
extern struct ArpBase *ArpBase;

/* some structures to make parsing the gif files a bit easier */
struct GIFdescriptor {
	UWORD gd_Width;
	UWORD gd_Height;
	UBYTE gd_ColInfo;
	UBYTE gd_BackGround;
	UBYTE gd_Reserved;
};

struct ImageDesc {
	UWORD id_Left;
	UWORD id_Top;
	UWORD id_Width;
	UWORD id_Height;
	UBYTE id_Info;
};

#define GIF_IMAGE      0x2C
#define GIF_EXTENSION  0x21
#define GIF_TERMINATOR 0x3B

/* this magic cookie defines the maximum size of the master colour list */
#define MAXCOLOURS 4096

/* convert a GIF colour intensity into an Amiga intensity */
#define CVRTGIF(a) buf[a] >> 4

/* these next macros are used to get the r, g, and b values of a given
   index */
#define GetRed(a)	(UBYTE)(MasterColourTable[a] >> 8)
#define GetGreen(a)	(UBYTE)((MasterColourTable[a] >> 4) & 0xF)
#define GetBlue(a)	(UBYTE)(MasterColourTable[a] & 0xF)

/* determine if pic is too wide to be entirely on a HAM screen */
#define ISTOOBIG (gdesc.gd_Width > 320)

/* whenever we want to abort we will return this as our error code */
#define ABORTEXITVAL 1

/* function prototypes we use */
extern int __regargs main(char *cmdptr, int cmdlen, struct WBStartup *WBMsg);
extern void	XCEXIT(int);
extern void	WarnMustUseCLI(void);
extern void	DoPattern(char *);
extern void	Convert(char *);
extern BOOL	IsDir(char *);
extern void	FlipWord(UWORD *);
extern BOOL	DoImage(BPTR);
extern BOOL	DoExtension(BPTR);
extern UWORD	AddColour(UBYTE *);
extern BOOL	WriteIFF(char *);
extern void	PutValue(UWORD, UWORD, UWORD);
extern UWORD	GetValue(UWORD, UWORD);
extern int	ReadCode(BPTR);
extern void	AddPixel(UBYTE);
extern void	StripBorder(void);
extern BOOL	BorderCheck(UWORD, UWORD);
extern void	DoXComp(void);
extern void	GIFtoSHAM(void);
extern void	GetPalette(ULONG, ULONG);
extern void	InitDiff(void);
extern ULONG	RGBdiff(UBYTE, UBYTE, UBYTE, UBYTE, UBYTE, UBYTE);
extern void	OutDump(int);
extern void	OutRun(int, int);
extern BOOL	PutLong(ULONG);
extern BOOL	PutWord(UWORD);
extern BOOL	PutChar(UBYTE);

/* modules that want to use the Get/PutValue macros should include this
   next macro to externally reference the picture storage array */
#define EXTERNBITPLANE extern UWORD **BitPlane

/* these two macros get and store values in the picture plane */
#define GetValue(a, b)    BitPlane[b][a]
#define PutValue(a, b, c) BitPlane[b][a] = c
