/****************************************************************************************


		MCColorRGB214.h


		Copyright: (c) 2001 Eovia Corp. All rights reserved.


		Author:	Mathieu
		Date:	09/03/98

		Revision History

		when		who			what & why
		==========	==========	======================================================
		06/14/99	Yann		Removed include to GCTypes.h
		6/10/99		Ian			Array API changes.
		01/22/99	Nba			added TArrayRGB stuff
		01/22/99	Mathieu		Added ToARGB() for chunky blitting
		12/18/98	Frh			Added == operator
		12/11/98	Mathieu		Removed RGB<->XYZ calls, now use ColorConversionUtilities
		12/01/98	Nba			Added operator [] for ColorRGB214 ; Added Blend
		12/02/98	Mathieu		Added const / non const member accessors
		12/01/98	Del			Added TColorHLS214
		11/18/98	Mathieu		Removed ToXYZ() so the header no longer includes MCXYZColor.h
		10/26/98	Mathieu		Removed dependancy from ColorManager
		10/12/98	Nba			added hsv<->rgb
		09/04/98	tsh			added to and from TMCRGBColor, split off ColorRGB214.cpp
		09/04/98	Mathieu		Added constructor from XYZ

*****************************************************************************************/

#ifndef __COLORRGB214H__
#define __COLORRGB214H__

#if CP_PRAGMA_ONCE
#pragma once
#endif

#include "MCColor16.h"
#include "MCAssert.h"


class TXYZColor;
class TColorRGB214;
class TMCRGBColor;

/// \addtogroup MCImage
/// \{

/// Represents a color in the HLS space
///
class TColorHLS214
{
public:
	TColorHLS214()									{}
	TColorHLS214(TGray16 h, TGray16 l, TGray16 s)	{ fHue=h; fLum=l; fSat=s; }



		  void		ToRGB(TColorRGB214 &rbg) const;

		  TGray16&	Hue()		{ return fHue; }
		  TGray16&	Lum()		{ return fLum; }
		  TGray16&	Sat()		{ return fSat; }
	
	const TGray16&	Hue() const	{ return fHue; }
	const TGray16&	Lum() const	{ return fLum; }
	const TGray16&	Sat() const	{ return fSat; }

private:
	TGray16	fHue;
	TGray16 fLum;
	TGray16 fSat;
	friend class TColorRGB214;
};

/// Represents a color in the HSV space
///
class TColorHSV214
{
public:
	TColorHSV214()									{}
	TColorHSV214(TGray16 h, TGray16 s, TGray16 v)	{ fHue=h; fSat=s; fVal=v; }

		  void ToRGB(TColorRGB214 &rgb) const;

		  TGray16& Hue()		{ return fHue; }
		  TGray16& Sat()		{ return fSat; }
		  TGray16& Val()		{ return fVal; }

	const TGray16& Hue() const	{ return fHue; }
	const TGray16& Sat() const	{ return fSat; }
	const TGray16& Val() const	{ return fVal; }

private:
	TGray16 fHue;
	TGray16 fSat;
	TGray16 fVal;
	friend class TColorRGB214;
};

/// Another RGB color 
///
class TColorRGB214 : public TArrayRGB
{

public :
			 TColorRGB214 ()								{}
			 TColorRGB214 (const TColorRGB214& c) 			{ uint8 i; for(i=0; i < 3; i++) fComps[i] = c[i]; }


			 TColorRGB214 (int32 bl);
			 void test() {}
			 
			 TColorRGB214 (TGray16 r, TGray16 g, TGray16 b)	{ fComps[0]=r; fComps[1]=g; fComps[2]=b; }
	explicit TColorRGB214 (const TMCRGBColor& rgb)			{ FromMCRGB(rgb); };	

	
	uint32		ToARGB		() const;
	TMCRGBColor ToMCRGB		() const;
	TGray16		ToGrayscale	() const { return TGray16 (static_cast<TFixed214>(((int32)fComps[0].ToFixed214() * 15793 + (int32)fComps[1].ToFixed214() * 44798 + (int32)fComps[2].ToFixed214() * 4945)>>16)); }
	void		ToHSV		(TColorHSV214& hsv) const;
	void		ToHLS		(TColorHLS214& hls) const;


	void		FromMCRGB	(const TMCRGBColor& rgb);
	
	TGray16&	Red			() { return fComps[0]; }
	TGray16&	Green		() { return fComps[1]; }
	TGray16&	Blue		() { return fComps[2]; }

	const TGray16& Red		() const { return fComps[0]; }
	const TGray16& Green	() const { return fComps[1]; }
	const TGray16& Blue		() const { return fComps[2]; }

	TGray16*	GetRGB		() { return fComps; } // returns the base pointer to the RGB array

	TColorRGB214& Blend		(const TColorRGB214& val, const TGray16 &alpha) { int8 i; for(i=0; i < 3; i++) { (*this)[i].Blend(val[i], alpha); } return *this; }

	boolean BetweenZeroAndOne (void) const;
	void	SnapToWebsafe	(void);

private :
	friend class TColorHSV214;
	friend class TColorHLS214;
};

/// \}

#endif
