color.h

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

H
1,803
字号
		ctRGB = 0,		/**		Assuming three color values, a, b, and c, which represent		Hue, Luminance, and Saturation values respectively, with each value		bounded by 0.0 to 1.0 inclusive.		*/		ctHSL,		/**		Assuming three color values, a, b, and c, which represent		Hue, Saturation, and Value values respectively, with each value		bounded by 0.0 to 1.0 inclusive.		*/		ctHSV,		ctHWB,		ctYUV,		ctLab,		ctCMY	};	/**	the factor used when ranging the color components with integers.	*/	enum MaxFactor {		xFF = 0xFF,		xFFFF = 0xFFFF,	};	/**	default ctor	*/	Color();	/**	the copy ctor	*/	Color( const Color& color );	/**	Initializes a color based on the double values (type: double) of its three components 	in a specified color coordinates sytem. The values, in double (4 bytes), are directly translated 	into the internal color components (in double).	Usage: Color color = Color( 1.0, 1.0, 0.5 );  Color color2 = Color( color.getRed(), color.getGreen(), color.getBlue() );	@param ColorType indicates the coordinates used in the color space. By default 	the RGB (red, green, and blue) system is used.	@see ColorType	*/	Color( const double& val1, const double& val2, const double& val3, ColorType type=ctRGB );	/**	Initializes a color based on the integer values (called range values) of its three components 	in a specified color coordinates sytem. The values are divided by 0xFF (255 - 1 byte) before being	translated into the internal color components (in double). This conversion introduces a 'discreteness'	in the color values that can be perceived by the human eye when drawing a a color gradient.	Usage: Color color = Color( (uint8)255, 255, 128 );	@param ColorType indicates the coordinates used in the color space. By default 	the RGB (red, green, and blue) system is used.	@see ColorType	*/	Color( const uint8& val1, const uint8& val2, const uint8& val3, ColorType type=ctRGB );	/**	Initializes a color based on the values (type: unsigned short) of its three components 	in a specified color coordinates sytem. The values are divided by 0xFFFF (65535 - 2 bytes)	before being translated into the internal color components (in double).	Usage: Color color = Color( (uint16)0xFFFF, 0xFFFF, 0x7FFF );	@param ColorType indicates the coordinates system used in the color space. By default 	the RGB (red, green, and blue) system is used.	@see ColorType	*/	Color( const uint16& val1, const uint16& val2, const uint16& val3, ColorType type=ctRGB );	/**	initializes a color from its components in the 4 color space. ( not implemented yet )	*/	Color( const double& c, const double& m, const double& y, const double& k );	/**	this is a constructor helping us in the conversion from an uint32 ( as in COLORREF )	into which the color components have been packed (4 x 8bits).	Under Win32 it is necessary to specify the cpsABGR parameter.	@param the system used to pack the color components.	@see ColorFormat	*/	Color( const uint32& color, const ColorPackScheme& cps=cpsARGB );	/**	this is a constructor halping us in the conversion from an ulong64 ( similarly as in COLORREF)	into which the color components have been packed (4 x 16bits).	Under Win32 it is necessary to specify the cpsABGR parameter.	@param the system used to pack the color components.	@see ColorFormat	*/	Color( const ulong64& color, const ColorPackScheme& cps=cpsARGB );	/**	extract a color from its color name. An internal map is used for this.	*/	Color( const String& colorName );	virtual ~Color(){};	double getRed() const;	double getGreen() const;	double getBlue() const;	void setRed( const double& red );	void setGreen( const double& green );	void setBlue( const double& blue );	/**	gets the color components of a color.	*/	void getRGB(double& r, double& g, double& b) const;	void getRGB8(uint8& r, uint8& g, uint8& b) const;	void getRGB16(uint16& r, uint16& g, uint16& b) const;	/**	packs into a uint32 integer the color components using 8bits for each component.	*/	uint32 getRGBPack8( const ColorPackScheme& cps=cpsARGB ) const;	/**	packs into a ulong64 integer the color components using 16bits for each component.	*/	ulong64 getRGBPack16( const ColorPackScheme& cps=cpsARGB ) const;	/**	same as getRGBPack8, but with the parameter cpsABGR specified.	introduced to make life easier to win32 users and less confusing.	*/	uint32 getColorRef32() const;	/**	same as getRGBPack16, but with the parameter cpsABGR specified.	introduced to make life easier to win32 users and less confusing.	*/	ulong64 getColorRef64() const;	/**	sets the color starting from the known color components.	*/	void setRGB( const double& r, const double& g, const double& b);	void setRGB8( const uint8& r, const uint8& g, const uint8& b);	void setRGB16( const uint16& r, const uint16& g, const uint16& b);	/**	sets the color starting from the known color components 	that have been packed into a single uint32 integer (4 x 8bits).	*/	Color& setRGBPack8( const uint32& rgb, const ColorPackScheme& cps=cpsARGB );	/**	sets the color starting from the known color components	that have been packed into a single ulong64 integer (4 x 16bits).	*/	Color& setRGBPack16( const ulong64& rgb, const ColorPackScheme& cps=cpsARGB );	/**	same as setRGBPack8, but with the parameter cpsABGR specified.	Introduced to make life easier to win32 users and less confusing.	*/	Color& setColorRef32( const uint32& rgb );	/**	same as setRGBPack16, but with the parameter cpsABGR specified.	Introduced to make life easier to win32 users and less confusing.	*/	Color& setColorRef64( const ulong64& rgb );	void getHSV(double& h, double& s, double& v) const;	void setHSV( const double& h, const double& s, const double& v);	void getHSL(double& h, double& l, double& s) const;	void setHSL( const double& h, const double& l, const double& s);	void getCMYK(double& c, double& m, double& y, double& k) const;	void setCMYK( const double& c, const double& m, const double& y, const double& k);	void getLab() const;	void setLab();	void getYUV() const;	void setYUV();	virtual void copyColor( const Color* source );	virtual void copyColor( const Color& source );	virtual void copy( Object* source ) {		copyColor( (Color*) source );	}	Color& operator=( const Color* clr ){		copyColor( clr );		return *this;	};	Color& operator=( const Color& clr ){		copyColor( clr );		return *this;	};	bool operator==( const Color& clr ) const {		return ( (clr.b_ == b_) && (clr.g_ == g_) && (clr.r_ == r_) );	}	bool operator!=( const Color& clr ) const {		return ( (clr.b_ != b_) || (clr.g_ != g_) || (clr.r_ != r_) );	}	// this operator is necessary for Map<Color, something>	bool operator< ( const Color& clr ) const {		/**		windows stores its color format in the following scheme 0x00BBGGRR:		so b is more important (because in the intel architecture the		rightmost byte is the most important)		*/		bool result =	(b_ < clr.b_) ? true :						(clr.b_ < b_) ? false :						(g_ < clr.g_) ? true :						(clr.g_ < g_) ? false :						(r_ < clr.r_) ? true : false;	// whow !		#ifdef VCF_DEBUG_COLORS_COMPARISON_OPERATORS			// this compare is less precise: so we can have rgb1==rgb2			bool result2 = ( getRGB() < clr.getRGB() ) ;			uint8 r, g, b, r2, g2, b2;			getRGB(r, g, b);			clr.getRGB(r2, g2, b2);			VCF_ASSERT2( result2 == result || ( b==b2 || ( g!=g2 || r!=r2) ), L"different result for rounding reasons" );		#endif		return result;	}	bool operator<= ( const Color& clr ) const {		bool result = false;		return ( *this < clr ) || (*this == clr);		return result;	}	bool operator> ( const Color& clr ) const {		/**		windows stores its color format in the following scheme 0x00BBGGRR:		so b is more important (because in the intel architecture the		rightmost byte is the most important)		*/		bool result =	(b_ > clr.b_) ? true :						(clr.b_ > b_) ? false :						(g_ > clr.g_) ? true :						(clr.g_ > g_) ? false :						(r_ > clr.r_) ? true : false;	// whow !		#ifdef VCF_DEBUG_COLORS_COMPARISON_OPERATORS			// this compare is less precise: so we can have rgb1==rgb2			bool result2 = ( getRGB() > clr.getRGB() ) ;			uint8 r, g, b, r2, g2, b2;			getRGB(r, g, b);			clr.getRGB(r2, g2, b2);			VCF_ASSERT2( result2 == result || ( b==b2 || ( g!=g2 || r!=r2) ), L"different result for rounding reasons" );		#endif		return result;	}	bool operator>= ( const Color& clr ) const {		bool result = false;		return ( *this > clr ) || (*this == clr);		return result;	}	virtual bool isEqual( const Color* color ) const {		bool result = false;		if ( NULL != color ){			result = (color->b_ == b_) && (color->g_ == g_) && (color->r_ == r_);		}		return result;	};	/**	overrides the homonimous Object's base class member function.	gives a strings representin the color in a simple format.	*/	virtual String toString(){		return Format(L"#%02X%02X%02X") % (int)(r_*xFF+0.5) % (int)(g_*xFF+0.5) % (int)(b_*xFF+0.5);	};	/**	generates a String with the internal representation of the color 	in hexadecimal format with 8bits per component.	@param const ColorPackScheme& cps. With a value of cpsABGR we use an inverted scheme, 	as it is in the Intel architecture. The default is not inverted.	       Example: the scheme 0x00RRGGBB would appear as BBGGRR00 with Intel architecture.	@param const ColorType& ct. The color space used to extract the components. The default is ctRGB, 	the RGB color space.	*/	String toHexCode8 ( const ColorPackScheme& cps=cpsARGB, const ColorType& ct=ctRGB );	String toHexCode16( const ColorPackScheme& cps=cpsARGB, const ColorType& ct=ctRGB );	void changeHSV ( const double& percentH, const double& percentS, const double& percentV );	void changeHSL ( const double& percentH, const double& percentS, const double& percentL );	void changeHWB ( const double& percentH, const double& percentW, const double& percentB );	void changeHue ( const double& deltaH );	/**	compute the luminosity as an RGB color.	*/	int getLuminosity() const ;	/**	set the luminosity of a color.	@param const int& luminosity, the desired luminosity	expressed in a [0, ColorSpace::HSLMax] scale.	*/	void setLuminosity( const int& luminosity );	/**	change the color to its complement (inverted)	@return Color& the color itself.	*/	Color& invert();	/**	compute the complement of the color	@return Color& the computed color.	*/	Color getInverted() const ;	/**	compute the inverted color of a color, given its components.	*/	void getInvertedRGB(double& r, double& g, double& b) const;	/**	compute the inverted components of a color, given its components in 8 bit.	*/	void getInvertedRGB8(uint8& r, uint8& g, uint8& b) const;	/**	compute the inverted components of a color, given its components in 16 bit.	*/	void getInvertedRGB16(uint16& r, uint16& g, uint16& b) const;	/**	makes the color brighter	@return Color& the color itself.	*/	Color& brighter();	/**

⌨️ 快捷键说明

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