color.h

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

H
1,803
字号
#ifndef _VCF_COLOR_H__#define _VCF_COLOR_H__//Color.h/*Copyright 2000-2004 The VCF Project.Please see License.txt in the top level directorywhere you installed the VCF.*/#if _MSC_VER > 1000#   pragma once#endif/*** Uncomment this to activate the macro VCF_DEBUG_COLORS_COMPARISON_OPERATORS* It is used to check if the comparison operators work right.* This involves a certain performance penalty in debug mode. So by default it is commented !*///#define VCF_DEBUG_COLORS_COMPARISON_OPERATORS#if !defined ( _DEBUG ) && !defined( DEBUG )#	ifdef VCF_DEBUG_COLORS_COMPARISON_OPERATORS#	  undef VCF_DEBUG_COLORS_COMPARISON_OPERATORS#	endif#endif/*** Uses a large map collecting all the standard internet color names,* which are 548. The standard short list has 138 names.* Uncomment the following if you desire to use the large list.*///#define VCF_LARGE_COLOR_LISTnamespace VCF {/***standard system color defines*/#define		SYSCOLOR_SHADOW					0#define		SYSCOLOR_FACE					1#define		SYSCOLOR_HIGHLIGHT				2#define		SYSCOLOR_ACTIVE_CAPTION			3#define		SYSCOLOR_ACTIVE_BORDER			4#define		SYSCOLOR_DESKTOP				5#define		SYSCOLOR_CAPTION_TEXT			6#define		SYSCOLOR_SELECTION				7#define		SYSCOLOR_SELECTION_TEXT			8#define		SYSCOLOR_INACTIVE_BORDER		9#define		SYSCOLOR_INACTIVE_CAPTION		10#define		SYSCOLOR_TOOLTIP				11#define		SYSCOLOR_TOOLTIP_TEXT			12#define		SYSCOLOR_MENU					13#define		SYSCOLOR_MENU_TEXT				14#define		SYSCOLOR_WINDOW					15#define		SYSCOLOR_WINDOW_TEXT			16#define		SYSCOLOR_WINDOW_FRAME			17class Color;/**\class ColorSpace Color.h "vcf/GraphicsKit/Color.h"A class for managing all the color transformations between different color spacesColorSpace interface  Hue Luminosity management		WebPages: 	\li http://www.acm.org/jgt/papers/SmithLyons96/  	\li	http://www.scottandmichelle.net/scott/code/index2.mv?codenum=045	\note		(google search advanced all words: hue saturation source code)Author: Alvy Ray Smith <br>				Microsoft <br>				Redmond, Washington <br>				alvys@microsoft.com <br>				Eric Ray Lyons <br>				Mill Valley, California <br>				lyons@nbn.com <br>Abstract:	The two most common color selector models, other than RGB (Red-Green-Blue),	are the hue-based HSV (Hue-Saturation-Value) and HSL (Hue-Saturation-Lightness) color models.	It is shown that both of these models are flawed.	A closely related model, HWB (Hue-Whiteness-Blackness), is introduced that avoids the flaws,	is slightly faster to compute, and is very easy to teach to new users:	Choose a hue. Lighten it with white. Darken it with black.	We explain that lightening is not the opposite of darkening.Modified, with some fixes to the algorithms, by Marcello PietrobonModified, by Jim Crafton, fixed some errors due to inclusion of Win32 types*/class GRAPHICSKIT_API ColorSpace {public:	/**	 Theoretically, hue 0 (pure red) is identical to hue 6 in these transforms. Pure	 red always maps to 6 in this implementation. Therefore UNDEFINED can be	 defined as 0 in situations where only unsigned numbers are desired.	 */	#define HUE_UNDEFINED	-1	#define HUECRITICALMAX	( 1.0 - 1.0 / 6.0 )	// max r/g/b value is 255 ?	/**	HueCriticalMax is assigned ( 1.0 - 1.0 / 6.0 )	Hue > HueCriticalMax => rgb.R > 1;	*/	static const double HueCriticalMax;	// = ( 1.0 - 1.0 / 6.0 )		enum {		RGBMax   = 0xFF,      // 255  When the max r/g/b value is 255		HSLMax   = 0xF0,      // 240  This is what Windows' Display Properties uses: it is not too much important an exact value: see how GetLuminosity() is used for.		RGBMax16 = 0xFFFF,    // Used when the max r/g/b value is 0xFFFF ( used for more precision )		HSLMax16 = 0xF0F0,    // ( 0xFFFF * 240 / 255 ) 	};	enum {		hue_undefined = HUE_UNDEFINED,	};	/*	enum colormodelType {		colormodel_RGB = 1,		colormodel_HSV = 2,		colormodel_HSL = 3,		colormodel_HWB = 4	};	*/	struct RGBtype {		double R;		double G;		double B;	};	struct RGBrangetype	{		int R;		int G;		int B;	};	struct HWBtype {		double H;		double W;		double B;	};	struct HSVtype {		double H;		double S;		double V;	};	struct HSLtype {		double H;		double S;		double L;	};	struct HSLrangetype{		int H;		int S;		int L;	};	#define MAKE_RGB(rgb, r, g, b) {rgb.R = (r); rgb.G = (g); rgb.B = (b);}	#define MAKE_HSV(hsv, h, s, v) {hsv.H = (h); hsv.S = (s); hsv.V = (v);}	#define MAKE_HSL(hsl, h, s, l) {hsl.H = (h); hsl.S = (s); hsl.L = (l);}	#define MAKE_HWB(hwb, h, w, b) {hwb.H = (h); hwb.W = (w); hwb.B = (b);}	#define SPLIT_RGB(rgb, r, g, b) r = rgb.R; g = rgb.G; b = rgb.B;	#define SPLIT_HSV(hsv, h, s, v) h = hsv.H; s = hsv.S; v = hsv.V;	#define SPLIT_HSL(hsl, h, s, l) h = hsl.H; s = hsl.S; l = hsl.L;	#define SPLIT_HWB(hwb, h, w, b) h = hwb.H; w = hwb.W; b = hwb.B;	/**	compute the luminosity for an RGB color.	@param color	@return int	*/	static int getLuminosity( const Color& color );	/**	set the luminosity of a color.	@param Color& color, the color.	@param const int& luminosity, the desired luminosity	expressed in a [0, ColorSpace::HSLMax] scale.	*/	static void setLuminosity( Color& color, const int& luminosity );	/**	helper function	*/	static double HueToColorValue(const double Hue, const double M1, const double M2);	// the HSV-RGB Transform Pair	static HSVtype RGBToHSV( const RGBtype& RGB );	static RGBtype HSVToRGB( const HSVtype& HSV );	// the HSL-RGB Transform Pair	static RGBtype HSLToRGB (const HSLtype& hsl);	static HSLtype RGBToHSL(const RGBtype& rgb);	// the HWB-RGB Transform Pair	static HWBtype RGBToHWB( const RGBtype& rgb ) ;	static RGBtype HWBToRGB( const HWBtype& HWB ) ;	// conversions	static HSLtype HSLRangeToHSL (const HSLrangetype& hslRange);	static HSLrangetype HSLToHSLRange (const HSLtype& hsl);	static ulong32 RGBToColorLong (const RGBtype& rgb);	static RGBtype ColorLongToRGB (const ulong32 color);	static ulong32 HSLToColorLong (const HSLtype& hsl);	static HSLtype ColorLongToHSL (const ulong32 color);	static RGBrangetype RGBToRGBRange(const RGBtype& rgb);	static RGBtype RGBRangeToRGB(const RGBrangetype& rgbRange);	static RGBtype HSLRangeToRGB (const HSLrangetype& hslRange);	static HSLrangetype RGBToHSLRange (const RGBtype& rgb);	static ulong32 HSLRangeToColorLong (const HSLrangetype& hsl);	static HSLrangetype ColorLongToHSLRange (const ulong32 color);	// the HSV-Color conversion pair	static Color RGBToColor (const RGBtype& rgb);	static RGBtype ColorToRGB (const Color& color);	static ulong32 ColorToColorLong (const Color& color);	// the HSV-Color conversion pair	static Color HSVToColor (const HSVtype& hsl);	static HSVtype ColorToHSV(const Color& rgb);	// the HSV-Color conversion Pair	static Color HSLToColor (const HSLtype& hsl);	static HSLtype ColorToHSL(const Color& rgb);	// the HSV-Color conversion Pair	static Color HWBToColor (const HWBtype& hsl);	static HWBtype ColorToHWB(const Color& rgb);	// usage	static double getChanged( const double& initialVal, const double& percent );	/**		It is suggested to call this function with colors: 0.0/ 0.0 / 0.71428571428571		It is suggested to call this function with grays:  0.0/ 0.0 / 0.33333333333333	*/	static void changeHSV ( HSVtype& hsv, const double& percentH, const double& percentS, const double& percentV );	/**		It is suggested to call this function with colors: 0.0/ 0.0 / -0.71428571428571		It is suggested to call this function with grays:  0.0/ 0.0 / -0.33333333333333	*/	static void changeHSL ( HSLtype& hsl, const double& percentH, const double& percentS, const double& percentL );	/**		It is suggested to call this function with colors: 0.0/ 0.0 / 0.71428571428571		It is suggested to call this function with grays:  0.0/ 0.0 / 0.33333333333333	*/	static void changeHWB ( HWBtype& hsl, const double& percentH, const double& percentW, const double& percentB );	static HSVtype changeHSV ( const HSVtype& hsv, const double& percentH, const double& percentS, const double& percentV );	static HSLtype changeHSL ( const HSLtype& hsl, const double& percentH, const double& percentS, const double& percentL );	static HWBtype changeHWB ( const HWBtype& hwb, const double& percentH, const double& percentW, const double& percentB );	/**	Example: To draw the Titlebars of a window with a color gradient do the following:	\code		Color color_right = color;		// enabled window (color)		Color color_left = changeHSL( color_right, 0.0, 0.0, -0.71428571428571 );		// disable window (gray)		Color color_left = changeHSL( color_right, 0.0, 0.0, -0.33333333333333 );		drawGradientBackground(pc, color_left, color_right);	\endcode	*/	static Color changeHSV ( const Color& color, const double& percentH, const double& percentS, const double& percentV );	static Color changeHSL ( const Color& color, const double& percentH, const double& percentS, const double& percentL );	static Color changeHWB ( const Color& color, const double& percentH, const double& percentW, const double& percentB );	static void		changeHue ( HSLtype& hsl, const double& deltaH );			// this one does the real work	static HSLtype	changeHue ( const HSLtype& hsl, const double& deltaH );	static Color	changeHue ( const Color& color, const double& deltaH );	static RGBtype	changeHue ( const RGBtype& color, const double& deltaH );	static ulong32	changeHue ( const ulong32& color, const double& deltaH );};#define COLOR_CLASSID	"AA34A97B-8294-4697-857D-398FB355EB2D"/**\class Color Color.h "vcf/GraphicsKit/Color.h"Color class documentation*/class GRAPHICSKIT_API Color : public VCF::Object {public:	friend class ColorSpace;	/**	this enum defines the way color is stored when compressed into a	32/64 bit integer value. Sadly not everyone stores this the same way	so this will indicate how the bits are arranged	*/	enum ColorPackScheme {		/**		Alpha value, Red value, Green Value, and Blue value.		Seen in a 32 bit number as 0xAARRGGBB		*/		cpsARGB = 0,		/**		Alpha value, Blue value, Green Value, and Red value.		This is the default in Win32 systems (i.e. inverted).		Seen in a 32 bit number as 0xAABBGGRR		*/		cpsABGR,	};	/**	An enum that indicates the color type of three double values.	*/	enum ColorType {		/**		Assuming three color values, a, b, and c, which represent		red, green, and blue values respectively, with each value		bounded by 0.0 to 1.0 inclusive.		*/

⌨️ 快捷键说明

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