1 // Created by: NW,JPB,CAL
2 // Copyright (c) 1991-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _Quantity_Color_HeaderFile
17 #define _Quantity_Color_HeaderFile
19 #include <Standard.hxx>
20 #include <Standard_DefineAlloc.hxx>
21 #include <Standard_Handle.hxx>
23 #include <Standard_ShortReal.hxx>
24 #include <Quantity_NameOfColor.hxx>
25 #include <Quantity_Parameter.hxx>
26 #include <Quantity_TypeOfColor.hxx>
27 #include <Quantity_Rate.hxx>
28 #include <Standard_Real.hxx>
29 #include <Standard_Boolean.hxx>
30 #include <Standard_CString.hxx>
31 #include <Standard_Integer.hxx>
32 class Quantity_ColorDefinitionError;
35 //! This class allows the definition of a colour.
36 //! The names of the colours are from the X11 specification.
37 //! color object may be used for numerous applicative purposes.
38 //! A color is defined by:
39 //! - its respective quantities of red, green and blue (R-G-B values), or
40 //! - its hue angle and its values of lightness and saturation (H-L-S values).
41 //! These two color definition systems are equivalent.
42 //! Use this class in conjunction with:
43 //! - the Quantity_TypeOfColor enumeration
44 //! which identifies the color definition system you are using,
45 //! - the Quantity_NameOfColor enumeration
46 //! which lists numerous predefined colors and
47 //! identifies them by their name.
55 //! Creates a colour with the default value of
56 //! Colour name : YELLOW
57 Standard_EXPORT Quantity_Color();
59 //! Creates the colour <AName>.
60 Standard_EXPORT Quantity_Color(const Quantity_NameOfColor AName);
62 //! Creates a colour according to the definition system
64 //! TOC_RGB : <R1> the value of red between 0. and 1.
65 //! <R2> the value of green between 0. and 1.
66 //! <R3> the value of blue between 0. and 1.
68 //! TOC_HLS : <R1> is the hue angle in degrees, 0. being red
69 //! <R2> is the lightness between 0. and 1.
70 //! <R3> is the saturation between 0. and 1.
71 Standard_EXPORT Quantity_Color(const Quantity_Parameter R1, const Quantity_Parameter R2, const Quantity_Parameter R3, const Quantity_TypeOfColor AType);
73 //! Increases or decreases the contrast by <ADelta>.
74 //! <ADelta> is a percentage. Any value greater than zero
75 //! will increase the contrast.
76 //! The variation is expressed as a percentage of the
78 //! It is a variation of the saturation.
79 Standard_EXPORT void ChangeContrast (const Quantity_Rate ADelta);
81 //! Increases or decreases the intensity by <ADelta>.
82 //! <ADelta> is a percentage. Any value greater than zero
83 //! will increase the intensity.
84 //! The variation is expressed as a percentage of the
86 //! It is a variation of the lightness.
87 Standard_EXPORT void ChangeIntensity (const Quantity_Rate ADelta);
89 //! Updates the colour <me> from the definition of the
91 Standard_EXPORT void SetValues (const Quantity_NameOfColor AName);
93 //! Updates a colour according to the mode specified by
95 //! TOC_RGB : <R1> the value of red between 0. and 1.
96 //! <R2> the value of green between 0. and 1.
97 //! <R3> the value of blue between 0. and 1.
99 //! TOC_HLS : <R1> is the hue angle in degrees, 0. being red
100 //! <R2> is the lightness between 0. and 1.
101 //! <R3> is the saturation between 0. and 1.
102 Standard_EXPORT void SetValues (const Quantity_Parameter R1, const Quantity_Parameter R2, const Quantity_Parameter R3, const Quantity_TypeOfColor AType);
104 //! Returns the percentage change of contrast and intensity
105 //! between <me> and <AColor>.
106 //! <DC> and <DI> are percentages, either positive or negative.
107 //! The calculation is with respect to the current value of <me>
108 //! If <DC> is positive then <me> is more contrasty.
109 //! If <DI> is positive then <me> is more intense.
110 Standard_EXPORT void Delta (const Quantity_Color& AColor, Quantity_Parameter& DC, Quantity_Parameter& DI) const;
112 //! Returns the distance between two colours. It's a
113 //! value between 0 and the square root of 3
114 //! (the black/white distance)
115 Standard_EXPORT Standard_Real Distance (const Quantity_Color& AColor) const;
117 //! Returns the square of distance between two colours.
118 Standard_EXPORT Standard_Real SquareDistance (const Quantity_Color& AColor) const;
120 //! Returns the Blue component (quantity of blue) of the
122 Standard_EXPORT Quantity_Parameter Blue() const;
124 //! Returns the Green component (quantity of green) of the
126 Standard_EXPORT Quantity_Parameter Green() const;
128 //! Returns the Hue component (hue angle) of the
130 Standard_EXPORT Quantity_Parameter Hue() const;
132 //! Returns Standard_True if the distance between <me> and
133 //! <Other> is greater than Epsilon ().
134 Standard_EXPORT Standard_Boolean IsDifferent (const Quantity_Color& Other) const;
135 Standard_Boolean operator != (const Quantity_Color& Other) const
137 return IsDifferent(Other);
140 //! Returns true if the Other color is
141 //! - different from, or
142 //! - equal to this color.
143 //! Two colors are considered to be equal if their
144 //! distance is no greater than Epsilon().
145 //! These methods are aliases of operator != and operator ==.
146 Standard_EXPORT Standard_Boolean IsEqual (const Quantity_Color& Other) const;
147 Standard_Boolean operator == (const Quantity_Color& Other) const
149 return IsEqual(Other);
152 //! Returns the Light component (value of the lightness) of the
154 Standard_EXPORT Quantity_Parameter Light() const;
156 //! Returns the name of the color defined by its
157 //! quantities of red R, green G and blue B; more
158 //! precisely this is the nearest color from the
159 //! Quantity_NameOfColor enumeration.
161 //! Standard_OutOfRange if R, G or B is less than 0. or greater than 1.
162 Standard_EXPORT Quantity_NameOfColor Name() const;
164 //! Returns the Red component (quantity of red) of the
166 Standard_EXPORT Quantity_Parameter Red() const;
168 //! Returns the Saturation component (value of the saturation)
169 //! of the color <me>.
170 Standard_EXPORT Quantity_Parameter Saturation() const;
172 //! Returns in R1, R2 and R3 the components of
173 //! this color according to the color system definition AType.
174 //! - if AType is Quantity_TOC_RGB R1 is the
175 //! quantity of red, R2 is the quantity of green and
176 //! R3 is the quantity of blue in this color.
177 //! - if AType is Quantity_TOC_HLS R1 is the
178 //! hue angle in degrees (0 being red), R2 is the
179 //! lightness and R3 is the saturation of this color.
180 Standard_EXPORT void Values (Quantity_Parameter& R1, Quantity_Parameter& R2, Quantity_Parameter& R3, const Quantity_TypeOfColor AType) const;
182 //! Sets the specified value used to compare <me> and
183 //! an other color in IsDifferent and in IsEqual methods.
184 //! Warning: The default value is 0.0001
185 Standard_EXPORT static void SetEpsilon (const Quantity_Parameter AnEpsilon);
187 //! Returns the specified value used to compare <me> and
188 //! an other color in IsDifferent and in IsEqual methods.
189 Standard_EXPORT static Quantity_Parameter Epsilon();
191 //! Returns the name of the colour for which the RGB components
192 //! are nearest to <R>, <G> and <B>.
193 Standard_EXPORT static Quantity_NameOfColor Name (const Quantity_Parameter R, const Quantity_Parameter G, const Quantity_Parameter B);
195 //! Returns the name of the color identified by
196 //! AName in the Quantity_NameOfColor enumeration.
197 //! For example, the name of the color which
198 //! corresponds to Quantity_NOC_BLACK is "BLACK".
200 //! Standard_OutOfRange if AName in not known
201 //! in the Quantity_NameOfColor enumeration.
202 Standard_EXPORT static Standard_CString StringName (const Quantity_NameOfColor AColor);
204 //! Finds color from predefined names.
205 //! For example, the name of the color which
206 //! corresponds to "BLACK" is Quantity_NOC_BLACK.
207 //! Returns false if name is unknown.
208 Standard_EXPORT static Standard_Boolean ColorFromName (const Standard_CString theName, Quantity_NameOfColor& theColor);
210 //! Converts HLS components into RGB ones.
211 Standard_EXPORT static void HlsRgb (const Quantity_Parameter H, const Quantity_Parameter L, const Quantity_Parameter S, Quantity_Parameter& R, Quantity_Parameter& G, Quantity_Parameter& B);
213 //! Converts RGB components into HLS ones.
214 Standard_EXPORT static void RgbHls (const Quantity_Parameter R, const Quantity_Parameter G, const Quantity_Parameter B, Quantity_Parameter& H, Quantity_Parameter& L, Quantity_Parameter& S);
216 //! Convert the Color value to ARGB integer value.
217 //! theARGB has Alpha equal to zero, so the output is
218 //! formatted as 0x00RRGGBB
219 Standard_EXPORT static void Color2argb (const Quantity_Color& theColor, Standard_Integer& theARGB);
221 //! Convert integer ARGB value to Color. Alpha bits are ignored
222 Standard_EXPORT static void Argb2color (const Standard_Integer theARGB, Quantity_Color& theColor);
225 Standard_EXPORT static void Test();
239 //! Converts HLS components into RGB ones.
240 Standard_EXPORT static void hlsrgb (const Standard_ShortReal H, const Standard_ShortReal L, const Standard_ShortReal S, Standard_ShortReal& R, Standard_ShortReal& G, Standard_ShortReal& B);
242 //! Converts RGB components into HLS ones.
243 Standard_EXPORT static void rgbhls (const Standard_ShortReal R, const Standard_ShortReal G, const Standard_ShortReal B, Standard_ShortReal& H, Standard_ShortReal& L, Standard_ShortReal& S);
245 //! Returns the values of a predefined colour according to
246 //! the mode specified by TypeOfColor
247 //! TOC_RGB : <R1> the value of red between 0. and 1.
248 //! <R2> the value of green between 0. and 1.
249 //! <R3> the value of blue between 0. and 1.
251 //! TOC_HLS : <R1> is the hue angle in degrees, 0. being red
252 //! <R2> is the lightness between 0. and 1.
253 //! <R3> is the saturation between 0. and 1.
254 Standard_EXPORT static void ValuesOf (const Quantity_NameOfColor AName, const Quantity_TypeOfColor AType, Standard_ShortReal& R1, Standard_ShortReal& R2, Standard_ShortReal& R3);
257 Standard_ShortReal MyRed;
258 Standard_ShortReal MyGreen;
259 Standard_ShortReal MyBlue;
270 #endif // _Quantity_Color_HeaderFile