//
// Tools_ColourMap.h
//
// Copyright (C) 2003 Rebellion, All Rights Reserved.
//

#ifdef ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif

#ifndef _INCLUDED_PCOLMAP_HPP
#define _INCLUDED_PCOLMAP_HPP

#ifndef __cplusplus
#error "requires C++"
#endif

/**************************************************/
/* pcolmap.hpp                                    */
/*                                                */
/* modularized mapping arbitrary RGB colours to   */
/* nearest colour from a palette. Uses Dan's fast */
/* subcube method (with possible improvement),    */
/* having stripped out all the stuff to do with   */
/* files, dithering, actual images, etc. Simply   */
/* set the palette, then request nearest colour.  */
/**************************************************/

#define CM_TREEMETHOD 0

#include "ImageProcessing/Tools_RGBTypes.h"

typedef RGBTriple<unsigned char> CMColour;

namespace CM { class Subcube; }

class Tools_ColourMap
{
	public:
		// construct with palette
		Tools_ColourMap(CMColour const * _paletteA, unsigned _paletteSize);
		// deconstruct
		~Tools_ColourMap();
		
		// get the nearest colour
		unsigned NearestColour(CMColour const & _colourR) const;
		
		// debug purposes - how much memory has been allocated
		unsigned CountMemoryAllocated() const;
		
	private:
		#if CM_TREEMETHOD
		::CM::Subcube * firstLevelP;
		#else
		::CM::Subcube * * firstLevelPA;
		CMColour * paletteA;
		unsigned paletteSize;
		#endif
};

#endif // ! _INCLUDED_PCOLMAP_HPP
