/* wasp - Copyright 1991 by Steven Reiz
 * see COPYING and wasp.c for further info
 * wasp.h, 4/12/90 - 30/1/91, 4/5/91 - 1/6/91,
 * 23/6/91, 30/6/91, 3/7/91, 7/7/91, 22/10/91
 * 8/12/91, 23/12/91, 27/12/91 - 31/12/91
 */

#include <stddef.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>

#ifndef UNIX
typedef unsigned long u_long;
typedef unsigned int u_int;
typedef unsigned char u_char;
typedef unsigned short u_short;
#endif

#undef EXTERN
#ifdef MAIN
#define EXTERN
#else
#define EXTERN extern
#endif

#include "proto.h"
#include "errors.h"

#define error0(a, b, c, d)		errorx((a<<24)|(b<<16)|(c<<8)|d)
#define error1(a, b, c, d, e)		errorx((a<<24)|(b<<16)|(c<<8)|d, e)
#define error2(a, b, c, d, e, f)	errorx((a<<24)|(b<<16)|(c<<8)|d, e, f)
#define assert(c) if (!(c)) errorx((E0_INTERNAL<<24)|__LINE__, sourcefile)

extern char *version;

#undef min
#define min(a, b) ((a)>(b) ? (b) : (a))
#undef max
#define max(a, b) ((a)>(b) ? (a) : (b))
#define Malloc(n) cmalloc((unsigned int)(n))
#define Calloc(n) ccalloc((unsigned int)(n))
#define Realloc(p, n) crealloc(p, (unsigned int)(n))
#define id(a, b, c, d) (((a)<<24)|((b)<<16)|((c)<<8)|(d))

#undef NULL
#define NULL ((void *)0)

#define NRGB 4096

EXTERN short outputformat;
#define IFF  0 
#define SRGR 1
#define PPM  2

EXTERN short directrgb;

EXTERN short compression;
#define COMPR_NONE	0
#define COMPR_RLE	1

EXTERN short scrw, scrh; /* also defined in scrsz.c */
#define DEF_SCRW 352
#define DEF_SCRH 283

EXTERN int hires, ymode, xmode;
#define HIRES_OK    0
#define HIRES_MAYBE 1
#define HIRES_NOT   2
#define UNSET       0
#define LACE        1
#define NOLACE      2
#define HIRES       1
#define LORES       2
#define EHB         3
#define HAM         4

EXTERN int countmeth;
/* should be in same order as cmeths names in wriff.c */
#define COUNTMETH_UNSET		0
#define COUNTMETH_ALL_1         1
#define COUNTMETH_ALL_DIF       2
#define COUNTMETH_ALL_FIXDIF    3
#define COUNTMETH_JUMP_1        4 
#define COUNTMETH_JUMP_21       5 
#define COUNTMETH_JUMP_DIF      6
#define COUNTMETH_JUMP_DIFSH    7
#define COUNTMETH_JUMP_FIXDIF   8
#define COUNTMETH_JUMP_FIXDIFSH 9
#define COUNTMETH_HAMMAP_GS	10
#define COUNTMETH_HAMMAP_CUBIC	11
#define COUNTMETH_HAMMAP	12
#define DEF_COUNTMETH           COUNTMETH_ALL_1
#define DEF_HAM_COUNTMETH	COUNTMETH_JUMP_FIXDIF

EXTERN int distrmeth, distrmeth2, curdistrmeth;
/* should be in same order as dmeths names in wriff.c */
#define DISTRMETH_UNSET       0
#define DISTRMETH_MOSTUSED    1
#define DISTRMETH_WORSTFIRST  2
#define DISTRMETH_EHB         3
#define DISTRMETH_MUE         4
#define DISTRMETH_HAMSHARP    5
#define DISTRMETH_CONTRACTION 6
#define DEF_DISTRMETH         DISTRMETH_WORSTFIRST
#define DEF_EHB_DISTRMETH     DISTRMETH_EHB

EXTERN u_long threshold;

EXTERN int sliced;
#define SLICED_NOT	0
#define SLICED_SHAM	1
#define SLICED_DYN	2
#define SLICED_PCHG	3

#define VM_LACE  0x0004L
#define VM_EHB   0x0080L
#define VM_HAM   0x0800L
#define VM_HIRES 0x8000L

EXTERN u_long xsz, ysz;                /* size of the rgb array */
EXTERN u_short **rgb;                  /* raw rgb picture data, rgb[0..ysz-1][0..xsz-1] */
EXTERN int xa, xb, yc, yd;             /* scaling factors */
EXTERN int asc;
EXTERN char *infilename, *outfilename;
EXTERN int infd, outfd;
EXTERN int inoperation;
EXTERN int gifmaptrunc;

EXTERN int cread_type, cread_result;
#define CREAD_STRICT	1		/* er, eof, varlen -> fatal */
#define CREAD_NONFATAL	2		/* er, eof, varlen -> error */
#define CREAD_VARLEN	3		/* er -> error, eof -> error */
#define CREAD_OPTIONAL	4		/* er -> error */

#ifdef AZTEC_C
#define REG register
#define NON_REG static
#else
#define REG register
#define NON_REG 
#endif
