Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef T_COLORVALUE_INCLUDED
Toshihiro Shimizu 890ddd
#define T_COLORVALUE_INCLUDED
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tpixel.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TCOLOR_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TColorValue
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	double m_r, m_g, m_b, m_m;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TColorValue() : m_r(0), m_g(0), m_b(0), m_m(1){};
Toshihiro Shimizu 890ddd
	TColorValue(const TPixel32 &src) { setPixel(src); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void getHsv(int &h, int &s, int &v) const;
Toshihiro Shimizu 890ddd
	void getHsv(int hsv[3]) const { getHsv(hsv[0], hsv[1], hsv[2]); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void getHls(double hls[3]) const { getHls(hls[0], hls[1], hls[2]); }
Toshihiro Shimizu 890ddd
	void getHls(double &h, double &l, double &s) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setHsv(int h, int s, int v);
Toshihiro Shimizu 890ddd
	void setHsv(int hsv[3]) { setHsv(hsv[0], hsv[1], hsv[2]); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void getRgb(int &r, int &g, int &b) const;
Toshihiro Shimizu 890ddd
	/*Sposto in tcolorvalue.cpp
Toshihiro Shimizu 890ddd
  {
Toshihiro Shimizu 890ddd
    r = (int)(m_r*255+0.5);
Toshihiro Shimizu 890ddd
    g = (int)(m_g*255+0.5);
Toshihiro Shimizu 890ddd
    b = (int)(m_b*255+0.5);
Toshihiro Shimizu 890ddd
  }
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void getRgb(int rgb[3]) const { getRgb(rgb[0], rgb[1], rgb[2]); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPixel32 getPixel() const;
Toshihiro Shimizu 890ddd
	/*Sposto in tcolorvalue.cpp 
Toshihiro Shimizu 890ddd
  {
Toshihiro Shimizu 890ddd
    int r,g,b; getRgb(r,g,b);
Toshihiro Shimizu 890ddd
    return TPixel32(r,g,b,(int)(m_m*255.0+0.5));
Toshihiro Shimizu 890ddd
  }
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setRgb(int r, int g, int b);
Toshihiro Shimizu 890ddd
	/*Sposto in tcolorvalue.cpp  
Toshihiro Shimizu 890ddd
  {
Toshihiro Shimizu 890ddd
    m_r = r/255.0;
Toshihiro Shimizu 890ddd
    m_g = g/255.0;
Toshihiro Shimizu 890ddd
    m_b = b/255.0;
Toshihiro Shimizu 890ddd
  }
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setRgb(int rgb[3]) { setRgb(rgb[0], rgb[1], rgb[2]); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setPixel(const TPixel32 &src);
Toshihiro Shimizu 890ddd
	/*Sposto in tcolorvalue.cpp   
Toshihiro Shimizu 890ddd
  {
Toshihiro Shimizu 890ddd
    setRgb(src.r, src.g,src.b);
Toshihiro Shimizu 890ddd
    m_m = src.m/255.0;
Toshihiro Shimizu 890ddd
  }
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool operator==(const TColorValue &cv) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return cv.m_r == m_r &&
Toshihiro Shimizu 890ddd
			   cv.m_g == m_g &&
Toshihiro Shimizu 890ddd
			   cv.m_b == m_b &&
Toshihiro Shimizu 890ddd
			   cv.m_m == m_m;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool operator!=(const TColorValue &cv) const { return !operator==(cv); }
Toshihiro Shimizu 890ddd
	bool operator<(const TColorValue &cv) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_r < cv.m_r)
Toshihiro Shimizu 890ddd
			return true;
Toshihiro Shimizu 890ddd
		else if (m_r > cv.m_r)
Toshihiro Shimizu 890ddd
			return false;
Toshihiro Shimizu 890ddd
		if (m_g < cv.m_g)
Toshihiro Shimizu 890ddd
			return true;
Toshihiro Shimizu 890ddd
		else if (m_g > cv.m_g)
Toshihiro Shimizu 890ddd
			return false;
Toshihiro Shimizu 890ddd
		if (m_b < cv.m_b)
Toshihiro Shimizu 890ddd
			return true;
Toshihiro Shimizu 890ddd
		else if (m_b > cv.m_b)
Toshihiro Shimizu 890ddd
			return false;
Toshihiro Shimizu 890ddd
		return (m_m < cv.m_m);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	bool operator>=(const TColorValue &cv) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return !(*this < cv);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	inline bool operator>(const TColorValue &cv) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return (cv < *this);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	bool operator<=(const TColorValue &cv) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return (cv >= *this);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif