Open CASCADE Technology  7.4.0
Public Member Functions | Static Public Member Functions
Quantity_Color Class Reference

This class allows the definition of a colour. The names of the colours are from the X11 specification. color object may be used for numerous applicative purposes. A color is defined by: More...

#include <Quantity_Color.hxx>

Public Member Functions

 Quantity_Color ()
 Creates Quantity_NOC_YELLOW color. More...
 
 Quantity_Color (const Quantity_NameOfColor AName)
 Creates the color from enumeration value. More...
 
 Quantity_Color (const Standard_Real theR1, const Standard_Real theR2, const Standard_Real theR3, const Quantity_TypeOfColor theType)
 Creates a color according to the definition system theType. Quantity_TOC_RGB: More...
 
 Quantity_Color (const NCollection_Vec3< float > &theRgb)
 Define color from RGB values. More...
 
void ChangeContrast (const Standard_Real ADelta)
 Increases or decreases the contrast by <ADelta>. <ADelta> is a percentage. Any value greater than zero will increase the contrast. The variation is expressed as a percentage of the current value. It is a variation of the saturation. More...
 
void ChangeIntensity (const Standard_Real ADelta)
 Increases or decreases the intensity by <ADelta>. <ADelta> is a percentage. Any value greater than zero will increase the intensity. The variation is expressed as a percentage of the current value. It is a variation of the lightness. More...
 
void SetValues (const Quantity_NameOfColor AName)
 Updates the colour <me> from the definition of the colour <AName>. More...
 
void SetValues (const Standard_Real theR1, const Standard_Real theR2, const Standard_Real theR3, const Quantity_TypeOfColor theType)
 Updates a color according to the mode specified by theType. Quantity_TOC_RGB: More...
 
void Delta (const Quantity_Color &AColor, Standard_Real &DC, Standard_Real &DI) const
 Returns the percentage change of contrast and intensity between <me> and <AColor>. <DC> and <DI> are percentages, either positive or negative. The calculation is with respect to the current value of <me> If <DC> is positive then <me> is more contrasty. If <DI> is positive then <me> is more intense. More...
 
Standard_Real Distance (const Quantity_Color &AColor) const
 Returns the distance between two colours. It's a value between 0 and the square root of 3 (the black/white distance) More...
 
Standard_Real SquareDistance (const Quantity_Color &AColor) const
 Returns the square of distance between two colours. More...
 
Standard_Real Blue () const
 Returns the Blue component (quantity of blue) of the color within range [0.0; 1.0]. More...
 
Standard_Real Green () const
 Returns the Green component (quantity of green) of the color within range [0.0; 1.0]. More...
 
Standard_Real Hue () const
 Returns the Hue component (hue angle) of the color in degrees within range [0.0; 360.0], 0.0 being Red. -1.0 is a special value reserved for grayscale color (S should be 0.0) More...
 
Standard_Boolean IsDifferent (const Quantity_Color &Other) const
 Returns Standard_True if the distance between <me> and <Other> is greater than Epsilon (). More...
 
Standard_Boolean operator!= (const Quantity_Color &Other) const
 
Standard_Boolean IsEqual (const Quantity_Color &Other) const
 Returns true if the Other color is. More...
 
Standard_Boolean operator== (const Quantity_Color &Other) const
 
Standard_Real Light () const
 Returns the Light component (value of the lightness) of the color within range [0.0; 1.0]. More...
 
Quantity_NameOfColor Name () const
 Returns the name of the color defined by its quantities of red R, green G and blue B; more precisely this is the nearest color from the Quantity_NameOfColor enumeration. Exceptions Standard_OutOfRange if R, G or B is less than 0. or greater than 1. More...
 
Standard_Real Red () const
 Returns the Red component (quantity of red) of the color within range [0.0; 1.0]. More...
 
Standard_Real Saturation () const
 Returns the Saturation component (value of the saturation) of the color within range [0.0; 1.0]. More...
 
 operator const NCollection_Vec3< float > & () const
 Return the color as vector of 3 float elements. More...
 
void Values (Standard_Real &theR1, Standard_Real &theR2, Standard_Real &theR3, const Quantity_TypeOfColor theType) const
 Returns in theR1, theR2 and theR3 the components of this color according to the color system definition theType. If theType is Quantity_TOC_RGB: More...
 
void DumpJson (Standard_OStream &theOStream, const Standard_Integer theDepth=-1) const
 Dumps the content of me into the stream. More...
 

Static Public Member Functions

static void SetEpsilon (const Standard_Real AnEpsilon)
 Sets the specified value used to compare <me> and an other color in IsDifferent and in IsEqual methods. Warning: The default value is 0.0001. More...
 
static Standard_Real Epsilon ()
 Returns the specified value used to compare <me> and an other color in IsDifferent and in IsEqual methods. More...
 
static Quantity_NameOfColor Name (const Standard_Real R, const Standard_Real G, const Standard_Real B)
 Returns the name of the colour for which the RGB components are nearest to <R>, <G> and . More...
 
static Standard_CString StringName (const Quantity_NameOfColor AColor)
 Returns the name of the color identified by AName in the Quantity_NameOfColor enumeration. For example, the name of the color which corresponds to Quantity_NOC_BLACK is "BLACK". Exceptions Standard_OutOfRange if AName in not known in the Quantity_NameOfColor enumeration. More...
 
static Standard_Boolean ColorFromName (const Standard_CString theName, Quantity_NameOfColor &theColor)
 Finds color from predefined names. For example, the name of the color which corresponds to "BLACK" is Quantity_NOC_BLACK. Returns false if name is unknown. More...
 
static Standard_Boolean ColorFromName (const Standard_CString theColorNameString, Quantity_Color &theColor)
 Finds color from predefined names. For example, the name of the color which corresponds to "BLACK" is Quantity_NOC_BLACK. Returns false if name is unknown. More...
 
static bool ColorFromHex (const Standard_CString theHexColorString, Quantity_Color &theColor)
 Parses the string as a hex color (like "#FF0" for short RGB color, or "#FFFF00" for RGB color) More...
 
static TCollection_AsciiString ColorToHex (const Quantity_Color &theColor, const bool theToPrefixHash=true)
 Returns hex sRGB string in format "#FFAAFF". More...
 
static void HlsRgb (const Standard_Real H, const Standard_Real L, const Standard_Real S, Standard_Real &R, Standard_Real &G, Standard_Real &B)
 Converts HLS components into RGB ones. More...
 
static void RgbHls (const Standard_Real R, const Standard_Real G, const Standard_Real B, Standard_Real &H, Standard_Real &L, Standard_Real &S)
 Converts RGB components into HLS ones. More...
 
static void Color2argb (const Quantity_Color &theColor, Standard_Integer &theARGB)
 Convert the Color value to ARGB integer value. theARGB has Alpha equal to zero, so the output is formatted as 0x00RRGGBB. More...
 
static void Argb2color (const Standard_Integer theARGB, Quantity_Color &theColor)
 Convert integer ARGB value to Color. Alpha bits are ignored. More...
 
static void Test ()
 Internal test. More...
 

Detailed Description

This class allows the definition of a colour. The names of the colours are from the X11 specification. color object may be used for numerous applicative purposes. A color is defined by:

Constructor & Destructor Documentation

◆ Quantity_Color() [1/4]

Quantity_Color::Quantity_Color ( )

Creates Quantity_NOC_YELLOW color.

◆ Quantity_Color() [2/4]

Quantity_Color::Quantity_Color ( const Quantity_NameOfColor  AName)

Creates the color from enumeration value.

◆ Quantity_Color() [3/4]

Quantity_Color::Quantity_Color ( const Standard_Real  theR1,
const Standard_Real  theR2,
const Standard_Real  theR3,
const Quantity_TypeOfColor  theType 
)

Creates a color according to the definition system theType. Quantity_TOC_RGB:

  • theR1 the value of Red within range [0.0; 1.0]
  • theR2 the value of Green within range [0.0; 1.0]
  • theR3 the value of Blue within range [0.0; 1.0]

Quantity_TOC_HLS:

  • theR1 is the Hue (H) angle in degrees within range [0.0; 360.0], 0.0 being Red. Value -1.0 is a special value reserved for grayscale color (S should be 0.0).
  • theR2 is the Lightness (L) within range [0.0; 1.0]
  • theR3 is the Saturation (S) within range [0.0; 1.0]

◆ Quantity_Color() [4/4]

Quantity_Color::Quantity_Color ( const NCollection_Vec3< float > &  theRgb)
explicit

Define color from RGB values.

Member Function Documentation

◆ Argb2color()

static void Quantity_Color::Argb2color ( const Standard_Integer  theARGB,
Quantity_Color theColor 
)
static

Convert integer ARGB value to Color. Alpha bits are ignored.

◆ Blue()

Standard_Real Quantity_Color::Blue ( ) const

Returns the Blue component (quantity of blue) of the color within range [0.0; 1.0].

◆ ChangeContrast()

void Quantity_Color::ChangeContrast ( const Standard_Real  ADelta)

Increases or decreases the contrast by <ADelta>. <ADelta> is a percentage. Any value greater than zero will increase the contrast. The variation is expressed as a percentage of the current value. It is a variation of the saturation.

◆ ChangeIntensity()

void Quantity_Color::ChangeIntensity ( const Standard_Real  ADelta)

Increases or decreases the intensity by <ADelta>. <ADelta> is a percentage. Any value greater than zero will increase the intensity. The variation is expressed as a percentage of the current value. It is a variation of the lightness.

◆ Color2argb()

static void Quantity_Color::Color2argb ( const Quantity_Color theColor,
Standard_Integer theARGB 
)
static

Convert the Color value to ARGB integer value. theARGB has Alpha equal to zero, so the output is formatted as 0x00RRGGBB.

◆ ColorFromHex()

static bool Quantity_Color::ColorFromHex ( const Standard_CString  theHexColorString,
Quantity_Color theColor 
)
static

Parses the string as a hex color (like "#FF0" for short RGB color, or "#FFFF00" for RGB color)

Parameters
theHexColorStringthe string to be parsed
theColora color that is a result of parsing
Returns
true if parsing was successful, or false otherwise

◆ ColorFromName() [1/2]

static Standard_Boolean Quantity_Color::ColorFromName ( const Standard_CString  theName,
Quantity_NameOfColor theColor 
)
static

Finds color from predefined names. For example, the name of the color which corresponds to "BLACK" is Quantity_NOC_BLACK. Returns false if name is unknown.

◆ ColorFromName() [2/2]

static Standard_Boolean Quantity_Color::ColorFromName ( const Standard_CString  theColorNameString,
Quantity_Color theColor 
)
inlinestatic

Finds color from predefined names. For example, the name of the color which corresponds to "BLACK" is Quantity_NOC_BLACK. Returns false if name is unknown.

Parameters
theColorNameStringthe color name
theColora found color
Returns
false if the color name is unknown, or true if the search by color name was successful

◆ ColorToHex()

static TCollection_AsciiString Quantity_Color::ColorToHex ( const Quantity_Color theColor,
const bool  theToPrefixHash = true 
)
inlinestatic

Returns hex sRGB string in format "#FFAAFF".

◆ Delta()

void Quantity_Color::Delta ( const Quantity_Color AColor,
Standard_Real DC,
Standard_Real DI 
) const

Returns the percentage change of contrast and intensity between <me> and <AColor>. <DC> and <DI> are percentages, either positive or negative. The calculation is with respect to the current value of <me> If <DC> is positive then <me> is more contrasty. If <DI> is positive then <me> is more intense.

◆ Distance()

Standard_Real Quantity_Color::Distance ( const Quantity_Color AColor) const

Returns the distance between two colours. It's a value between 0 and the square root of 3 (the black/white distance)

◆ DumpJson()

void Quantity_Color::DumpJson ( Standard_OStream theOStream,
const Standard_Integer  theDepth = -1 
) const

Dumps the content of me into the stream.

◆ Epsilon()

static Standard_Real Quantity_Color::Epsilon ( )
static

Returns the specified value used to compare <me> and an other color in IsDifferent and in IsEqual methods.

◆ Green()

Standard_Real Quantity_Color::Green ( ) const

Returns the Green component (quantity of green) of the color within range [0.0; 1.0].

◆ HlsRgb()

static void Quantity_Color::HlsRgb ( const Standard_Real  H,
const Standard_Real  L,
const Standard_Real  S,
Standard_Real R,
Standard_Real G,
Standard_Real B 
)
static

Converts HLS components into RGB ones.

◆ Hue()

Standard_Real Quantity_Color::Hue ( ) const

Returns the Hue component (hue angle) of the color in degrees within range [0.0; 360.0], 0.0 being Red. -1.0 is a special value reserved for grayscale color (S should be 0.0)

◆ IsDifferent()

Standard_Boolean Quantity_Color::IsDifferent ( const Quantity_Color Other) const

Returns Standard_True if the distance between <me> and <Other> is greater than Epsilon ().

◆ IsEqual()

Standard_Boolean Quantity_Color::IsEqual ( const Quantity_Color Other) const

Returns true if the Other color is.

  • different from, or
  • equal to this color. Two colors are considered to be equal if their distance is no greater than Epsilon(). These methods are aliases of operator != and operator ==.

◆ Light()

Standard_Real Quantity_Color::Light ( ) const

Returns the Light component (value of the lightness) of the color within range [0.0; 1.0].

◆ Name() [1/2]

Quantity_NameOfColor Quantity_Color::Name ( ) const

Returns the name of the color defined by its quantities of red R, green G and blue B; more precisely this is the nearest color from the Quantity_NameOfColor enumeration. Exceptions Standard_OutOfRange if R, G or B is less than 0. or greater than 1.

◆ Name() [2/2]

static Quantity_NameOfColor Quantity_Color::Name ( const Standard_Real  R,
const Standard_Real  G,
const Standard_Real  B 
)
static

Returns the name of the colour for which the RGB components are nearest to <R>, <G> and .

◆ operator const NCollection_Vec3< float > &()

Quantity_Color::operator const NCollection_Vec3< float > & ( ) const
inline

Return the color as vector of 3 float elements.

◆ operator!=()

Standard_Boolean Quantity_Color::operator!= ( const Quantity_Color Other) const
inline

◆ operator==()

Standard_Boolean Quantity_Color::operator== ( const Quantity_Color Other) const
inline

◆ Red()

Standard_Real Quantity_Color::Red ( ) const

Returns the Red component (quantity of red) of the color within range [0.0; 1.0].

◆ RgbHls()

static void Quantity_Color::RgbHls ( const Standard_Real  R,
const Standard_Real  G,
const Standard_Real  B,
Standard_Real H,
Standard_Real L,
Standard_Real S 
)
static

Converts RGB components into HLS ones.

◆ Saturation()

Standard_Real Quantity_Color::Saturation ( ) const

Returns the Saturation component (value of the saturation) of the color within range [0.0; 1.0].

◆ SetEpsilon()

static void Quantity_Color::SetEpsilon ( const Standard_Real  AnEpsilon)
static

Sets the specified value used to compare <me> and an other color in IsDifferent and in IsEqual methods. Warning: The default value is 0.0001.

◆ SetValues() [1/2]

void Quantity_Color::SetValues ( const Quantity_NameOfColor  AName)

Updates the colour <me> from the definition of the colour <AName>.

◆ SetValues() [2/2]

void Quantity_Color::SetValues ( const Standard_Real  theR1,
const Standard_Real  theR2,
const Standard_Real  theR3,
const Quantity_TypeOfColor  theType 
)

Updates a color according to the mode specified by theType. Quantity_TOC_RGB:

  • theR1 the value of Red within range [0.0; 1.0]
  • theR2 the value of Green within range [0.0; 1.0]
  • theR3 the value of Blue within range [0.0; 1.0]

Quantity_TOC_HLS:

  • theR1 is the Hue (H) angle in degrees within range [0.0; 360.0], 0.0 being Red. -1.0 is a special value reserved for grayscale color (S should be 0.0).
  • theR2 is the Lightness (L) within range [0.0; 1.0]
  • theR3 is the Saturation (S) within range [0.0; 1.0]

◆ SquareDistance()

Standard_Real Quantity_Color::SquareDistance ( const Quantity_Color AColor) const

Returns the square of distance between two colours.

◆ StringName()

static Standard_CString Quantity_Color::StringName ( const Quantity_NameOfColor  AColor)
static

Returns the name of the color identified by AName in the Quantity_NameOfColor enumeration. For example, the name of the color which corresponds to Quantity_NOC_BLACK is "BLACK". Exceptions Standard_OutOfRange if AName in not known in the Quantity_NameOfColor enumeration.

◆ Test()

static void Quantity_Color::Test ( )
static

Internal test.

◆ Values()

void Quantity_Color::Values ( Standard_Real theR1,
Standard_Real theR2,
Standard_Real theR3,
const Quantity_TypeOfColor  theType 
) const

Returns in theR1, theR2 and theR3 the components of this color according to the color system definition theType. If theType is Quantity_TOC_RGB:

  • theR1 the value of Red between 0.0 and 1.0
  • theR2 the value of Green between 0.0 and 1.0
  • theR3 the value of Blue between 0.0 and 1.0 If theType is Quantity_TOC_HLS:
  • theR1 is the Hue (H) angle in degrees within range [0.0; 360.0], 0.0 being Red. -1.0 is a special value reserved for grayscale color (S should be 0.0).
  • theR2 is the Lightness (L) within range [0.0; 1.0]
  • theR3 is the Saturation (S) within range [0.0; 1.0]

The documentation for this class was generated from the following file: