LibreOffice Module tools (master) 1
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
Color Class Reference

#include <color.hxx>

Public Member Functions

constexpr Color ()
 
constexpr Color (const sal_uInt32 nColor)
 
constexpr Color (enum ColorTransparencyTag, sal_uInt32 nColor)
 
constexpr Color (enum ColorAlphaTag, sal_uInt32 nColor)
 
constexpr Color (enum ColorTransparencyTag, sal_uInt8 nTransparency, sal_uInt8 nRed, sal_uInt8 nGreen, sal_uInt8 nBlue)
 
constexpr Color (enum ColorAlphaTag, sal_uInt8 nAlpha, sal_uInt8 nRed, sal_uInt8 nGreen, sal_uInt8 nBlue)
 
constexpr Color (sal_uInt8 nRed, sal_uInt8 nGreen, sal_uInt8 nBlue)
 
 Color (const basegfx::BColor &rBColor)
 
constexpr operator sal_uInt32 () const
 Casts the color to corresponding uInt32. More...
 
constexpr operator sal_Int32 () const
 Casts the color to corresponding iInt32. More...
 
sal_uInt8 GetRed () const
 Gets the red value. More...
 
sal_uInt8 GetGreen () const
 Gets the green value. More...
 
sal_uInt8 GetBlue () const
 Gets the blue value. More...
 
sal_uInt8 GetAlpha () const
 Gets the alpha value. More...
 
bool IsTransparent () const
 Is the color transparent? More...
 
bool IsFullyTransparent () const
 Is the color fully transparent i.e. More...
 
void SetRed (sal_uInt8 nRed)
 Sets the red value. More...
 
void SetGreen (sal_uInt8 nGreen)
 Sets the green value. More...
 
void SetBlue (sal_uInt8 nBlue)
 Sets the blue value. More...
 
void SetAlpha (sal_uInt8 nAlpha)
 Sets the alpha value. More...
 
Color GetRGBColor () const
 Returns the same color but ignoring the transparency value. More...
 
bool IsRGBEqual (const Color &rColor) const
 Check if the color RGB value is equal than rColor. More...
 
bool operator< (const Color &aCompareColor) const
 Check if the color value is lower than aCompareColor. More...
 
bool operator> (const Color &aCompareColor) const
 Check if the color value is greater than aCompareColor. More...
 
bool operator== (const Color &rColor) const
 Check if the color value is equal than rColor. More...
 
bool operator!= (const Color &rColor) const
 Check if the color value is unequal than rColor. More...
 
sal_uInt16 GetColorError (const Color &rCompareColor) const
 Gets the color error compared to another. More...
 
sal_uInt8 GetLuminance () const
 Gets the color luminance. More...
 
void IncreaseLuminance (sal_uInt8 cLumInc)
 Increases the color luminance by cLumInc. More...
 
void DecreaseLuminance (sal_uInt8 cLumDec)
 Decreases the color luminance by cLumDec. More...
 
void DecreaseContrast (sal_uInt8 cContDec)
 Decreases color contrast with white by cContDec. More...
 
bool IsDark () const
 Comparison with luminance thresholds. More...
 
bool IsBright () const
 Comparison with luminance thresholds. More...
 
void ApplyTintOrShade (sal_Int16 n100thPercent)
 Apply tint or shade to a color. More...
 
void ApplyLumModOff (sal_Int16 nMod, sal_Int16 nOff)
 Apply luminance offset and/or modulation. More...
 
void Invert ()
 Inverts color. More...
 
void Merge (const Color &rMergeColor, sal_uInt8 cTransparency)
 Merges color with rMergeColor. More...
 
void RGBtoHSB (sal_uInt16 &nHue, sal_uInt16 &nSaturation, sal_uInt16 &nBrightness) const
 Color space conversion tools. More...
 
OUString AsRGBHexString () const
 
OUString AsRGBHEXString () const
 
basegfx::BColor getBColor () const
 

Static Public Member Functions

static Color HSBtoRGB (sal_uInt16 nHue, sal_uInt16 nSaturation, sal_uInt16 nBrightness)
 Color space conversion tools The range for h/s/b is: More...
 
static Color STRtoRGB (std::u16string_view colorname)
 Converts a string into a color. More...
 

Private Attributes

union {
   sal_uInt32   mValue
 
   struct {
      sal_uInt8   B
 
      sal_uInt8   G
 
      sal_uInt8   R
 
      sal_uInt8   T
 
   } 
 
}; 
 

Detailed Description

Definition at line 50 of file color.hxx.

Constructor & Destructor Documentation

◆ Color() [1/8]

constexpr Color::Color ( )
inlineconstexpr

Definition at line 72 of file color.hxx.

Referenced by HSBtoRGB().

◆ Color() [2/8]

constexpr Color::Color ( const sal_uInt32  nColor)
inlineconstexpr

Definition at line 81 of file color.hxx.

◆ Color() [3/8]

constexpr Color::Color ( enum  ColorTransparencyTag,
sal_uInt32  nColor 
)
inlineconstexpr

Definition at line 87 of file color.hxx.

◆ Color() [4/8]

constexpr Color::Color ( enum  ColorAlphaTag,
sal_uInt32  nColor 
)
inlineconstexpr

Definition at line 92 of file color.hxx.

◆ Color() [5/8]

constexpr Color::Color ( enum  ColorTransparencyTag,
sal_uInt8  nTransparency,
sal_uInt8  nRed,
sal_uInt8  nGreen,
sal_uInt8  nBlue 
)
inlineconstexpr

Definition at line 97 of file color.hxx.

◆ Color() [6/8]

constexpr Color::Color ( enum  ColorAlphaTag,
sal_uInt8  nAlpha,
sal_uInt8  nRed,
sal_uInt8  nGreen,
sal_uInt8  nBlue 
)
inlineconstexpr

Definition at line 101 of file color.hxx.

◆ Color() [7/8]

constexpr Color::Color ( sal_uInt8  nRed,
sal_uInt8  nGreen,
sal_uInt8  nBlue 
)
inlineconstexpr

Definition at line 105 of file color.hxx.

◆ Color() [8/8]

Color::Color ( const basegfx::BColor rBColor)
inlineexplicit

Definition at line 110 of file color.hxx.

References getBlue(), getGreen(), and getRed().

Member Function Documentation

◆ ApplyLumModOff()

void Color::ApplyLumModOff ( sal_Int16  nMod,
sal_Int16  nOff 
)

Apply luminance offset and/or modulation.

The input values are in percentages (in 100th percents). 100% modulation and 0% offset results in no change.

Definition at line 234 of file color.cxx.

References B, G, getBColor(), basegfx::BColor::getBlue(), basegfx::BColor::getGreen(), basegfx::BColor::getRed(), basegfx::utils::hsl2rgb(), R, basegfx::utils::rgb2hsl(), basegfx::BColor::setBlue(), and basegfx::BColor::setGreen().

◆ ApplyTintOrShade()

void Color::ApplyTintOrShade ( sal_Int16  n100thPercent)

Apply tint or shade to a color.

The input value is the percentage (in 100th of percent) of how much the color changes towards the black (shade) or white (tint). If the value is positive, the color is tinted, if the value is negative, the color is shaded.

Definition at line 208 of file color.cxx.

References abs(), B, G, getBColor(), basegfx::BColor::getBlue(), basegfx::BColor::getGreen(), basegfx::BColor::getRed(), basegfx::utils::hsl2rgb(), R, basegfx::utils::rgb2hsl(), and basegfx::BColor::setBlue().

◆ AsRGBHexString()

OUString Color::AsRGBHexString ( ) const

Definition at line 194 of file color.cxx.

References GetRGBColor().

◆ AsRGBHEXString()

OUString Color::AsRGBHEXString ( ) const

Definition at line 201 of file color.cxx.

References GetRGBColor().

◆ DecreaseContrast()

void Color::DecreaseContrast ( sal_uInt8  cContDec)

Decreases color contrast with white by cContDec.

Parameters
cContDec

Definition at line 47 of file color.cxx.

References B, FRound(), G, and R.

◆ DecreaseLuminance()

void Color::DecreaseLuminance ( sal_uInt8  cLumDec)

Decreases the color luminance by cLumDec.

Parameters
cLumDec

Definition at line 40 of file color.cxx.

References B, G, and R.

◆ GetAlpha()

sal_uInt8 Color::GetAlpha ( ) const
inline

Gets the alpha value.

Returns
A

Definition at line 164 of file color.hxx.

◆ getBColor()

basegfx::BColor Color::getBColor ( ) const
inline

Definition at line 418 of file color.hxx.

References B, G, and R.

Referenced by ApplyLumModOff(), and ApplyTintOrShade().

◆ GetBlue()

sal_uInt8 Color::GetBlue ( ) const
inline

Gets the blue value.

Returns
B

Definition at line 156 of file color.hxx.

References B.

Referenced by GetColorError(), and tools::GenericTypeSerializer::writeColor().

◆ GetColorError()

sal_uInt16 Color::GetColorError ( const Color rCompareColor) const
inline

Gets the color error compared to another.

It describes how different they are. It takes the abs of differences in parameters.

Parameters
rCompareColor
Returns
error

Definition at line 276 of file color.hxx.

References abs(), GetBlue(), GetGreen(), and GetRed().

◆ GetGreen()

sal_uInt8 Color::GetGreen ( ) const
inline

Gets the green value.

Returns
G

Definition at line 148 of file color.hxx.

References G.

Referenced by GetColorError(), and tools::GenericTypeSerializer::writeColor().

◆ GetLuminance()

sal_uInt8 Color::GetLuminance ( ) const
inline

Gets the color luminance.

It means perceived brightness.

Returns
luminance

Definition at line 289 of file color.hxx.

References B, G, and R.

◆ GetRed()

sal_uInt8 Color::GetRed ( ) const
inline

Gets the red value.

Returns
R

Definition at line 140 of file color.hxx.

References R.

Referenced by GetColorError(), and tools::GenericTypeSerializer::writeColor().

◆ GetRGBColor()

Color Color::GetRGBColor ( ) const
inline

Returns the same color but ignoring the transparency value.

Returns
RGB version

Definition at line 218 of file color.hxx.

References B, G, and R.

Referenced by AsRGBHexString(), and AsRGBHEXString().

◆ HSBtoRGB()

Color Color::HSBtoRGB ( sal_uInt16  nHue,
sal_uInt16  nSaturation,
sal_uInt16  nBrightness 
)
static

Color space conversion tools The range for h/s/b is:

  • Hue: 0-360 degree
  • Saturation: 0-100%
  • Brightness: 0-100%
    Parameters
    nHue
    nSaturation
    nBrightness
    Returns
    rgb color

Definition at line 121 of file color.cxx.

References a, Color(), and n.

◆ IncreaseLuminance()

void Color::IncreaseLuminance ( sal_uInt8  cLumInc)

Increases the color luminance by cLumInc.

Parameters
cLumInc

Definition at line 33 of file color.cxx.

References B, G, and R.

◆ Invert()

void Color::Invert ( )
inline

Inverts color.

1 and 0 are switched. Note that the result will be the complementary color. For example, if you have red, you will get cyan: FF0000 -> 00FFFF.

Definition at line 350 of file color.hxx.

References B, G, and R.

◆ IsBright()

bool Color::IsBright ( ) const
inline

Comparison with luminance thresholds.

Returns
is dark

Definition at line 321 of file color.hxx.

◆ IsDark()

bool Color::IsDark ( ) const
inline

Comparison with luminance thresholds.

Returns
is dark

Definition at line 312 of file color.hxx.

◆ IsFullyTransparent()

bool Color::IsFullyTransparent ( ) const
inline

Is the color fully transparent i.e.

100% transparency ?

Definition at line 178 of file color.hxx.

◆ IsRGBEqual()

bool Color::IsRGBEqual ( const Color rColor) const
inline

Check if the color RGB value is equal than rColor.

Parameters
rColor
Returns
is equal

Definition at line 229 of file color.hxx.

References mValue.

◆ IsTransparent()

bool Color::IsTransparent ( ) const
inline

Is the color transparent?

Definition at line 171 of file color.hxx.

◆ Merge()

void Color::Merge ( const Color rMergeColor,
sal_uInt8  cTransparency 
)
inline

Merges color with rMergeColor.

Allows to get resulting color when superposing another.

Parameters
rMergeColor
cTransparency

Definition at line 362 of file color.hxx.

References B, B, color::ColorChannelMerge(), G, G, R, and R.

◆ operator sal_Int32()

constexpr Color::operator sal_Int32 ( ) const
inlineexplicitconstexpr

Casts the color to corresponding iInt32.

If there is no transparency, will be positive.

Returns
corresponding sal_Int32

Definition at line 130 of file color.hxx.

◆ operator sal_uInt32()

constexpr Color::operator sal_uInt32 ( ) const
inlineexplicitconstexpr

Casts the color to corresponding uInt32.

Primarily used when passing Color objects to UNO API

Returns
corresponding sal_uInt32

Definition at line 121 of file color.hxx.

◆ operator!=()

bool Color::operator!= ( const Color rColor) const
inline

Check if the color value is unequal than rColor.

Parameters
rColor
Returns
is unequal

Definition at line 265 of file color.hxx.

References mValue.

◆ operator<()

bool Color::operator< ( const Color aCompareColor) const
inline

Check if the color value is lower than aCompareColor.

Parameters
aCompareColor
Returns
is lower

Definition at line 238 of file color.hxx.

References mValue.

◆ operator==()

bool Color::operator== ( const Color rColor) const
inline

Check if the color value is equal than rColor.

Parameters
rColor
Returns
is equal

Definition at line 256 of file color.hxx.

References mValue.

◆ operator>()

bool Color::operator> ( const Color aCompareColor) const
inline

Check if the color value is greater than aCompareColor.

Parameters
aCompareColor
Returns
is greater

Definition at line 247 of file color.hxx.

References mValue.

◆ RGBtoHSB()

void Color::RGBtoHSB ( sal_uInt16 &  nHue,
sal_uInt16 &  nSaturation,
sal_uInt16 &  nBrightness 
) const

Color space conversion tools.

Parameters
nHue
nSaturation
nBrightness

Definition at line 62 of file color.cxx.

References B, G, and R.

◆ SetAlpha()

void Color::SetAlpha ( sal_uInt8  nAlpha)
inline

Sets the alpha value.

Parameters
nAlpha

Definition at line 210 of file color.hxx.

◆ SetBlue()

void Color::SetBlue ( sal_uInt8  nBlue)
inline

Sets the blue value.

Parameters
nBlue

Definition at line 202 of file color.hxx.

References B.

◆ SetGreen()

void Color::SetGreen ( sal_uInt8  nGreen)
inline

Sets the green value.

Parameters
nGreen

Definition at line 194 of file color.hxx.

References G.

◆ SetRed()

void Color::SetRed ( sal_uInt8  nRed)
inline

Sets the red value.

Parameters
nRed

Definition at line 186 of file color.hxx.

References R.

◆ STRtoRGB()

Color Color::STRtoRGB ( std::u16string_view  colorname)
static

Converts a string into a color.

Supports: #RRGGBB #rrggbb RGB #rgb RRGGBB rrggbb RGB rgb If fails returns Color().

Definition at line 162 of file color.cxx.

References col, and o3tl::toUInt32().

Member Data Documentation

◆ 

union { ... } Color::@4

◆ B

sal_uInt8 Color::B

◆ G

sal_uInt8 Color::G

◆ mValue

sal_uInt32 Color::mValue

Definition at line 54 of file color.hxx.

Referenced by IsRGBEqual(), operator!=(), operator<(), operator==(), and operator>().

◆ R

sal_uInt8 Color::R

◆ T

sal_uInt8 Color::T

Definition at line 66 of file color.hxx.


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