color.h

来自「这是VCF框架的代码」· C头文件 代码 · 共 1,803 行 · 第 1/5 页

H
1,803
字号
	makes the color brighter	@return Color& the color itself.	*/	Color& darker();	virtual Object* clone( bool deep ) {		return new Color(*this);	}	/**	gets a gray color from the map of internet colors.	@param const int& gray, a gray value between 0 (black) and 255 (white)	@return Color* a pointer to the color in the map.	*/	static Color* getColor( const int& gray );	/**	gets a color from the map of internet colors.	@param const String& colorName the name of the color.	@return Color* a pointer to the color in the map.	*/	static Color* getColor( const String& colorName );	/**	gets a color from the map with the closest match a given color.	@param const Color& color the given color.	@return Color* a pointer to the color in the map.	*/	static Color* getColorMatch( const Color& color );	/**	gets the name of the color from the map with the closest match a given color.	@param const Color& color the given color.	@return const String the name of the matching color in the map. The name	is equal to ColorNames::unknownColorName() if not found.	*/	static const String getColorNameFromMap( const Color& color );	/**	creates the map of internet colors.	*/	static void createColorMap();	/**	computes a color with increased contrast.	@param const Color& color the given color.	@param double deltaL, the assigned fractional increase in luminosity.	@return Color the computed color.	*/	static Color getColorContrast( const Color& color, double deltaL = 0.3 );private:	double r_;	double g_;	double b_;	/**	Some notes for the future programmer.	Note: The choice of using the const  qualifier for s_ makes difficult to add a new color	( it is not a const pointer though ).			To check if a color has a name you need to use some constructor.		Example:	\code	Color( (VCF::uchar)r, (VCF::uchar)g, (VCF::uchar)b) )	\endcode		We have some difficulties only if we have to add a new color. And the only way to	avoid these difficulties is to declare s_ without the 'const' qualifier,	which would cause worse problems though.		Usage : 	To add a new color, check if the color already exists with a name:	\code	Color cTmp = Color( (String*)NULL, (VCF::uchar)r, (VCF::uchar)g, (VCF::uchar)b) );	\endcode	or	\code	Color cTmp = Color( (String*)NULL, (VCF::uchar)r, (VCF::uchar)g, (VCF::uchar)b) );	\endcode	Then:	\code	String* s = getColorNameFromMap(cTmp);	if ( s == ColorNames::unknownColorName() ) {		//allocate the memory for the colorName, then:		String* newColorName = new String("newColorName");		Color color = Color ( newColorName, cTmp );	} else {		//Color color = Color ( s, cTmp ); or		Color color = cTmp;	}	\endcode	Maybe I will think something better if you'll have to continuously add new colors:	but in this case it is probably better to just use:	\code	Color cTmp = Color( (String*)NULL, (VCF::uchar)r, (VCF::uchar)g, (VCF::uchar)b) );	\endcode	*/};///////////////////////////////////////////////////////////////////////////////// inlinesinline Color::Color() {	r_ = 0.0;	g_ = 0.0;	b_ = 0.0;}inline Color::Color( const Color& color ) {	b_ = color.b_;	g_ = color.g_;	r_ = color.r_;}inline Color::Color( const double& val1, const double& val2, const double& val3, ColorType type ) {	switch ( type ) {		case ctRGB : {			r_ = val1;			g_ = val2;			b_ = val3;		}		break;		case ctHSL : {			ColorSpace::HSLtype hsl;			hsl.H = val1;			hsl.L = val2;			hsl.S = val3;			ColorSpace::RGBtype rgb = ColorSpace::HSLToRGB( hsl );			r_ = rgb.R;			g_ = rgb.G;			b_ = rgb.B;		}		break;		case ctHSV : {			ColorSpace::HSVtype hsv;			hsv.H = val1;			hsv.S = val2;			hsv.V = val3;			ColorSpace::RGBtype rgb = ColorSpace::HSVToRGB( hsv );			r_ = rgb.R;			g_ = rgb.G;			b_ = rgb.B;		}		break;	}}inline Color::Color( const uint8& val1, const uint8& val2, const uint8& val3, ColorType type ) {	switch ( type ) {		case ctRGB : {			r_ = (double)val1 / xFF;			g_ = (double)val2 / xFF;			b_ = (double)val3 / xFF;		}		break;		case ctHSL : {			ColorSpace::HSLtype hsl;			hsl.H = (double)val1 / xFF;			hsl.L = (double)val2 / xFF;			hsl.S = (double)val3 / xFF;			ColorSpace::RGBtype rgb = ColorSpace::HSLToRGB( hsl );			r_ = rgb.R;			g_ = rgb.G;			b_ = rgb.B;		}		break;		case ctHSV : {			ColorSpace::HSVtype hsv;			hsv.H = (double)val1 / xFF;			hsv.S = (double)val2 / xFF;			hsv.V = (double)val3 / xFF;			ColorSpace::RGBtype rgb = ColorSpace::HSVToRGB( hsv );			r_ = rgb.R;			g_ = rgb.G;			b_ = rgb.B;		}		break;	}}inline Color::Color( const uint16& val1, const uint16& val2, const uint16& val3, ColorType type ) {	switch ( type ) {		case ctRGB : {			r_ = (double)val1 / xFFFF;			g_ = (double)val2 / xFFFF;			b_ = (double)val3 / xFFFF;		}		break;		case ctHSL : {			ColorSpace::HSLtype hsl;			hsl.H = (double)val1 / xFFFF;			hsl.L = (double)val2 / xFFFF;			hsl.S = (double)val3 / xFFFF;			ColorSpace::RGBtype rgb = ColorSpace::HSLToRGB( hsl );			r_ = rgb.R;			g_ = rgb.G;			b_ = rgb.B;		}		break;		case ctHSV : {			ColorSpace::HSVtype hsv;			hsv.H = (double)val1 / xFFFF;			hsv.S = (double)val2 / xFFFF;			hsv.V = (double)val3 / xFFFF;			ColorSpace::RGBtype rgb = ColorSpace::HSVToRGB( hsv );			r_ = rgb.R;			g_ = rgb.G;			b_ = rgb.B;		}		break;	}}inline Color::Color( const double& c, const double& m, const double& y, const double& k ) {	throw NotImplementedException();}inline Color::Color(const uint32& rgb, const ColorPackScheme& cps ) {	setRGBPack8( rgb, cps );}inline Color::Color(const ulong64& rgb, const ColorPackScheme& cps ) {	setRGBPack16( rgb, cps );}inline double Color::getRed() const {	return r_;}inline double Color::getGreen() const {	return g_;}inline double Color::getBlue() const {	return b_;}inline void Color::setRed( const double& red ) {	r_ = red;}inline void Color::setGreen( const double& green ) {	g_ = green;}inline void Color::setBlue( const double& blue ) {	b_ = blue;}inline void Color::getRGB( double& r, double& g, double& b ) const {	r = r_;	g = g_;	b = b_;}inline void Color::getRGB8( uint8& r, uint8& g, uint8& b ) const {	r = (uint8)(r_ * xFF + 0.5);	g = (uint8)(g_ * xFF + 0.5);	b = (uint8)(b_ * xFF + 0.5);}inline void Color::getRGB16( uint16& r, uint16& g, uint16& b ) const {	r = (uint16)(r_ * xFFFF + 0.5);	g = (uint16)(g_ * xFFFF + 0.5);	b = (uint16)(b_ * xFFFF + 0.5);}inline uint32 Color::getRGBPack8( const ColorPackScheme& cps ) const {	uint32 rgb = 0;	switch ( cps ) {		case cpsARGB : {			((uint8*)(&rgb))[2] = (uint8)(r_ * xFF + 0.5);			((uint8*)(&rgb))[1] = (uint8)(g_ * xFF + 0.5);			((uint8*)(&rgb))[0] = (uint8)(b_ * xFF + 0.5);		}		break;		case cpsABGR : {			((uint8*)(&rgb))[0] = (uint8)(r_ * xFF + 0.5);			((uint8*)(&rgb))[1] = (uint8)(g_ * xFF + 0.5);			((uint8*)(&rgb))[2] = (uint8)(b_ * xFF + 0.5);		}		break;	}	return rgb;}inline ulong64 Color::getRGBPack16( const ColorPackScheme& cps ) const {	ulong64 rgb;	switch ( cps ) {		case cpsARGB : {			((uint16*)(&rgb.data_))[2] = (uint16)(r_ * xFFFF + 0.5);			((uint16*)(&rgb.data_))[1] = (uint16)(g_ * xFFFF + 0.5);			((uint16*)(&rgb.data_))[0] = (uint16)(b_ * xFFFF + 0.5);		}		break;		case cpsABGR : {			((uint16*)(&rgb.data_))[0] = (uint16)(r_ * xFFFF + 0.5);			((uint16*)(&rgb.data_))[1] = (uint16)(g_ * xFFFF + 0.5);			((uint16*)(&rgb.data_))[2] = (uint16)(b_ * xFFFF + 0.5);		}		break;	}	return rgb;}inline uint32 Color::getColorRef32() const {	return getRGBPack8( cpsABGR );}inline ulong64 Color::getColorRef64() const {	return getRGBPack16( cpsABGR );}inline void Color::setRGB( const double& r, const double& g, const double& b) {	r_ = r;	g_ = g;	b_ = b;}inline void Color::setRGB8( const uint8& r, const uint8& g, const uint8& b ) {	r_ = ((double)r) / xFF;	g_ = ((double)g) / xFF;	b_ = ((double)b) / xFF;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?