19#ifndef INCLUDED_TOOLS_COLOR_HXX
20#define INCLUDED_TOOLS_COLOR_HXX
24#include <com/sun/star/uno/Any.hxx>
25#include <config_global.h>
27#include <osl/endian.h>
34 return nColorNumber & 0x00FFFFFF;
39 return sal_uInt8(((sal_Int32(nDst) - nSrc) * nSrcTrans + ((nSrc << 8) | nDst)) >> 8);
84 assert(nColor <= 0xffffff &&
"don't pass transparency to this constructor, use the Color(ColorTransparencyTag,...) or Color(ColorAlphaTag,...) constructor to make it explicit");
93 : mValue((nColor & 0xffffff) | ((255 - (nColor >> 24)) << 24))
98 : mValue(sal_uInt32(nBlue) | (sal_uInt32(nGreen) << 8) | (sal_uInt32(nRed) << 16) | (sal_uInt32(nTransparency) << 24))
121 constexpr explicit operator sal_uInt32()
const
130 constexpr explicit operator sal_Int32()
const
132 return sal_Int32(mValue);
173 return GetAlpha() != 255;
231 return ( mValue & 0x00FFFFFF ) == ( rColor.
mValue & 0x00FFFFFF );
240 return mValue < aCompareColor.
mValue;
249 return mValue > aCompareColor.
mValue;
258 return mValue == rColor.
mValue;
267 return mValue != rColor.
mValue;
278 return static_cast<sal_uInt16
>(
279 abs(
static_cast<int>(GetBlue()) - rCompareColor.
GetBlue()) +
280 abs(
static_cast<int>(GetGreen()) - rCompareColor.
GetGreen()) +
281 abs(
static_cast<int>(GetRed()) - rCompareColor.
GetRed()));
291 return sal_uInt8((
B * 29UL +
G * 151UL +
R * 76UL) >> 8);
297 void IncreaseLuminance(
sal_uInt8 cLumInc);
302 void DecreaseLuminance(
sal_uInt8 cLumDec);
307 void DecreaseContrast(
sal_uInt8 cContDec);
315 return GetLuminance() <= 156;
323 return GetLuminance() >= 245;
336 void ApplyTintOrShade(sal_Int16 n100thPercent);
344 void ApplyLumModOff(sal_Int16 nMod, sal_Int16 nOff);
381 static Color HSBtoRGB(sal_uInt16 nHue, sal_uInt16 nSaturation, sal_uInt16 nBrightness);
394 static Color STRtoRGB(std::u16string_view colorname);
401 void RGBtoHSB(sal_uInt16& nHue, sal_uInt16& nSaturation, sal_uInt16& nBrightness)
const;
407 OUString AsRGBHexString()
const;
413 OUString AsRGBHEXString()
const;
428 if (!(rAny >>= nTmp))
436 rAny <<= sal_Int32(
value);
440 template<>
inline Any::Any(
Color const & value):
Any(sal_Int32(
value)) {}
446static_assert (sal_uInt32(
Color(0x12, 0x34, 0x56)) == 0x00123456);
457inline constexpr ::Color
COL_BLUE ( 0x00, 0x00, 0x80 );
459inline constexpr ::Color
COL_CYAN ( 0x00, 0x80, 0x80 );
460inline constexpr ::Color
COL_RED ( 0x80, 0x00, 0x00 );
463inline constexpr ::Color
COL_GRAY ( 0x80, 0x80, 0x80 );
505template<
typename charT,
typename traits>
506inline std::basic_ostream<charT, traits>&
operator <<(std::basic_ostream<charT, traits>& rStream,
const Color& rColor)
508 std::ios_base::fmtflags nOrigFlags = rStream.flags();
509 rStream <<
"rgba[" << std::hex << std::setfill (
'0')
510 << std::setw(2) <<
static_cast<int>(rColor.
GetRed())
511 << std::setw(2) <<
static_cast<int>(rColor.
GetGreen())
512 << std::setw(2) <<
static_cast<int>(rColor.
GetBlue())
513 << std::setw(2) <<
static_cast<int>(rColor.
GetAlpha()) <<
"]";
514 rStream.setf(nOrigFlags);
Color GetRGBColor() const
Returns the same color but ignoring the transparency value.
sal_uInt8 GetLuminance() const
Gets the color luminance.
constexpr Color(enum ColorAlphaTag, sal_uInt32 nColor)
bool operator<(const Color &aCompareColor) const
Check if the color value is lower than aCompareColor.
sal_uInt8 GetBlue() const
Gets the blue value.
bool IsBright() const
Comparison with luminance thresholds.
bool IsFullyTransparent() const
Is the color fully transparent i.e.
constexpr Color(sal_uInt8 nRed, sal_uInt8 nGreen, sal_uInt8 nBlue)
void SetGreen(sal_uInt8 nGreen)
Sets the green value.
void SetRed(sal_uInt8 nRed)
Sets the red value.
basegfx::BColor getBColor() const
void Merge(const Color &rMergeColor, sal_uInt8 cTransparency)
Merges color with rMergeColor.
bool IsDark() const
Comparison with luminance thresholds.
bool operator==(const Color &rColor) const
Check if the color value is equal than rColor.
constexpr Color(enum ColorTransparencyTag, sal_uInt32 nColor)
bool operator!=(const Color &rColor) const
Check if the color value is unequal than rColor.
sal_uInt8 GetAlpha() const
Gets the alpha value.
void Invert()
Inverts color.
constexpr Color(const sal_uInt32 nColor)
bool operator>(const Color &aCompareColor) const
Check if the color value is greater than aCompareColor.
constexpr Color(enum ColorAlphaTag, sal_uInt8 nAlpha, sal_uInt8 nRed, sal_uInt8 nGreen, sal_uInt8 nBlue)
sal_uInt8 GetRed() const
Gets the red value.
bool IsRGBEqual(const Color &rColor) const
Check if the color RGB value is equal than rColor.
sal_uInt16 GetColorError(const Color &rCompareColor) const
Gets the color error compared to another.
constexpr Color(enum ColorTransparencyTag, sal_uInt8 nTransparency, sal_uInt8 nRed, sal_uInt8 nGreen, sal_uInt8 nBlue)
bool IsTransparent() const
Is the color transparent?
sal_uInt8 GetGreen() const
Gets the green value.
void SetAlpha(sal_uInt8 nAlpha)
Sets the alpha value.
void SetBlue(sal_uInt8 nBlue)
Sets the blue value.
Color(const basegfx::BColor &rBColor)
constexpr ::Color COL_LIGHTRED(0xFF, 0x00, 0x00)
constexpr ::Color COL_GRAY(0x80, 0x80, 0x80)
constexpr ::Color COL_AUTHOR_TABLE_DEL(0xFC, 0xE6, 0xF4)
constexpr ::Color COL_GRAY3(0xCC, 0xCC, 0xCC)
constexpr ::Color COL_AUTHOR9_DARK(0xD1, 0x76, 0x00)
constexpr ::Color COL_AUTHOR7_LIGHT(0xF2, 0xFE, 0xB5)
constexpr ::Color COL_AUTHOR5_LIGHT(0xFF, 0xE3, 0xE5)
constexpr ::Color COL_AUTHOR8_DARK(0x35, 0x55, 0x6B)
constexpr ::Color COL_AUTHOR8_LIGHT(0xE2, 0xEA, 0xF1)
constexpr ::Color COL_AUTHOR7_NORMAL(0xED, 0xFC, 0xA3)
constexpr ::Color COL_AUTHOR_TABLE_INS(0xE1, 0xF2, 0xFA)
constexpr ::Color COL_AUTHOR2_LIGHT(0xE9, 0xF2, 0xFF)
constexpr ::Color COL_AUTHOR8_NORMAL(0xD3, 0xDE, 0xE8)
constexpr ::Color COL_GREEN(0x00, 0x80, 0x00)
constexpr ::Color COL_AUTHOR1_NORMAL(0xFF, 0xFF, 0x9E)
constexpr ::Color COL_AUTHOR9_LIGHT(0xFF, 0xE7, 0xC7)
constexpr ::Color COL_AUTHOR2_DARK(0x06, 0x46, 0xA2)
constexpr ::Color COL_AUTHOR1_LIGHT(0xFF, 0xFF, 0xC3)
constexpr ::Color COL_AUTHOR3_DARK(0x57, 0x9D, 0x1C)
constexpr ::Color COL_AUTHOR6_DARK(0x00, 0x80, 0x80)
constexpr ::Color COL_WHITE(0xFF, 0xFF, 0xFF)
constexpr ::Color COL_GRAY7(0x66, 0x66, 0x66)
constexpr ::Color COL_LIGHTCYAN(0x00, 0xFF, 0xFF)
constexpr ::Color COL_MAGENTA(0x80, 0x00, 0x80)
bool operator>>=(const css::uno::Any &rAny, Color &value)
void operator<<=(css::uno::Any &rAny, Color value)
constexpr ::Color COL_LIGHTMAGENTA(0xFF, 0x00, 0xFF)
constexpr ::Color COL_BROWN(0x80, 0x80, 0x00)
constexpr ::Color COL_YELLOW(0xFF, 0xFF, 0x00)
constexpr ::Color COL_ALPHA_OPAQUE(0xff, 0xff, 0xff)
constexpr ::Color COL_AUTHOR4_NORMAL(0xE4, 0xD2, 0xF5)
constexpr ::Color COL_RED(0x80, 0x00, 0x00)
constexpr ::Color COL_AUTHOR7_DARK(0x8C, 0x84, 0x00)
ColorTransparencyTag
used to deliberately select the right constructor
constexpr ::Color COL_AUTO(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
constexpr ::Color COL_LIGHTGRAY(0xC0, 0xC0, 0xC0)
constexpr ::Color COL_LIGHTGRAYBLUE(0xE0, 0xE0, 0xFF)
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &rStream, const Color &rColor)
constexpr ::Color COL_AUTHOR3_LIGHT(0xE2, 0xFA, 0xCF)
constexpr ::Color COL_AUTHOR5_NORMAL(0xFE, 0xCD, 0xD0)
constexpr ::Color COL_AUTHOR9_NORMAL(0xFF, 0xE2, 0xB9)
constexpr ::Color COL_ALPHA_TRANSPARENT(0x00, 0x00, 0x00)
constexpr ::Color COL_AUTHOR4_LIGHT(0xEF, 0xE4, 0xF8)
constexpr ::Color COL_AUTHOR5_DARK(0xC5, 0x00, 0x0B)
constexpr ::Color COL_LIGHTBLUE(0x00, 0x00, 0xFF)
constexpr ::Color COL_CYAN(0x00, 0x80, 0x80)
constexpr ::Color COL_AUTHOR6_NORMAL(0xD2, 0xF6, 0xF6)
constexpr ::Color COL_LIGHTGREEN(0x00, 0xFF, 0x00)
constexpr ::Color COL_AUTHOR4_DARK(0x69, 0x2B, 0x9D)
constexpr ::Color COL_AUTHOR6_LIGHT(0xE6, 0xFA, 0xFA)
constexpr ::Color COL_AUTHOR2_NORMAL(0xD8, 0xE8, 0xFF)
constexpr ::Color COL_BLUE(0x00, 0x00, 0x80)
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)
constexpr ::Color COL_AUTHOR1_DARK(0xC6, 0x92, 0x00)
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
constexpr ::Color COL_AUTHOR3_NORMAL(0xDA, 0xF8, 0xC1)
Degree100 abs(Degree100 x)
constexpr sal_uInt32 extractRGB(sal_uInt32 nColorNumber)
constexpr sal_uInt8 ColorChannelMerge(sal_uInt8 nDst, sal_uInt8 nSrc, sal_uInt8 nSrcTrans)
sal_uInt8 getRed(IntSRGBA nCol)
sal_uInt8 getBlue(IntSRGBA nCol)
sal_uInt8 getGreen(IntSRGBA nCol)