/*----------------------------------------------------------------------
 * header file for color-quantizer
 * by Gary Oberbrunner  1/5/88
 *----------------------------------------------------------------------
 */

#define HIST_QUANT_BITS 5	/* Histogram clump quantization */
#define HIST_SHIFT (8 - HIST_QUANT_BITS)
#define HIST_SIZE (1 << (HIST_QUANT_BITS * 3))

#define RGB_BYTES 4		/* Bytes per rgb pixel (4 for alpha channel) */

/* We need the next definition to reference a variable-size array */
/* NCOLS is the number of columns in the array */
/* Each pixel is stored as an rgb byte triplet */

/* This is the address of the pixel triplet: */
#define RCPIX(array, row, col)	(array + RGB_BYTES * (row * NCOLS + col))
#define PIXPIX(array, pixel)	(array + RGB_BYTES * (pixel))
/* These are the pixel components: */
#define RED(array, row, col)	(*(RCPIX(array, row, col)))
#define GREEN(array, row, col)	(*(RCPIX(array, row, col) + 1))
#define BLUE(array, row, col)	(*(RCPIX(array, row, col) + 2))
#define PIXRED(array, pix)	(*(PIXPIX(array, pix)))
#define PIXGREEN(array, pix)	(*(PIXPIX(array, pix) + 1))
#define PIXBLUE(array, pix)	(*(PIXPIX(array, pix) + 2))

/* Here is the rgb-space distance metric: */
#define DIST(r1,g1,b1,r2,g2,b2) \
       (int) \
       (3 * ((r1)-(r2)) * ((r1)-(r2)) + \
	4 * ((g1)-(g2)) * ((g1)-(g2)) + \
	2 * ((b1)-(b2)) * ((b1)-(b2)))
#define BIG_DISTANCE 1000000	/* bigger than any real distance */

typedef unsigned char cmap_t;
typedef unsigned char rgb_pix_t;
typedef unsigned char out_pix_t;

extern out_pix_t  *quant_image;	/* the quantized image - cmap indices */
extern int debug;