/*
 * jquant2.c
 *
 * Copyright (C) 1991, 1992, Thomas G. Lane.
 * This file is part of the Independent JPEG Group's software.
 * For conditions of distribution and use, see the accompanying README file.
 *
 * This file contains 2-pass color quantization (color mapping) routines.
 * These routines are invoked via the methods color_quant_prescan,
 * color_quant_doit, and color_quant_init/term.
 */

#include "jinclude.h"

#ifdef QUANT_2PASS_SUPPORTED


#define Y_SCALE 2		/* scale Y distances up by this much */

#define MAXNUMCOLORS  (MAXJSAMPLE+1) /* maximum size of colormap */


#ifndef HIST_Y_BITS		/* so you can override from Makefile */
#define HIST_Y_BITS  6		/* bits of precision in Y histogram */
#endif
#ifndef HIST_C_BITS		/* so you can override from Makefile */
#define HIST_C_BITS  5		/* bits of precision in Cb/Cr histogram */
#endif

#define HIST_Y_ELEMS  (1<<HIST_Y_BITS) /* # of elements along histogram axes */
#define HIST_C_ELEMS  (1<<HIST_C_BITS)

#define Y_SHIFT  (BITS_IN_JSAMPLE-HIST_Y_BITS)
#define C_SHIFT  (BITS_IN_JSAMPLE-HIST_C_BITS)


#ifndef BOX_Y_LOG		/* so you can override from Makefile */
#define BOX_Y_LOG  (HIST_Y_BITS-3) /* log2(hist cells in update box, Y axis) */
#endif
#ifndef BOX_C_LOG		/* so you can override from Makefile */
#define BOX_C_LOG  (HIST_C_BITS-3) /* log2(hist cells in update box, C axes) */
#endif

#define BOX_Y_ELEMS  (1<<BOX_Y_LOG) /* # of hist cells in update box */
#define BOX_C_ELEMS  (1<<BOX_C_LOG)

#define BOX_Y_SHIFT  (Y_SHIFT + BOX_Y_LOG)
#define BOX_C_SHIFT  (C_SHIFT + BOX_C_LOG)


  /* Nominal steps between cell centers ("x" in Thomas article) */
#define STEP_Y  ((1 << Y_SHIFT) * Y_SCALE)
#define STEP_C  (1 << C_SHIFT)

#ifdef EIGHT_BIT_SAMPLES
typedef INT16 FSERROR;		/* 16 bits should be enough */
#else
typedef INT32 FSERROR;		/* may need more than 16 bits? */
#endif


#endif