summaryrefslogtreecommitdiff
path: root/include/tools
diff options
context:
space:
mode:
authordante <dante19031999@gmail.com>2020-11-08 14:32:57 +0100
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-11-11 06:51:22 +0100
commitf3b52717e85621d3b4ee1c6d69700e2a0cca8efc (patch)
treeaa4df032b1ab661ad19b3ebc2e8e2c59babb4b07 /include/tools
parent3d90997fb6f232d8008df4d166d7b97b869c200f (diff)
Improved starmath color
Color.hxx has now documentation ( even if it is quite obvious if you know RGB standar ). Color.hxx has been reordered in more coherent order, but kept format. Some changes on Color.hxx dynamics. Color.hxx starmath colors list Now colors are managed by starmathdatabse. The path is open for simple addition of colors, there are no more infinite switches with color tokens here and there. To add a color, just put it in Color.hxx and register it in starmathdatabse.cxx. Do not forget to change array size in starmathdatabase.hxx. Now mathml supports RGB colors in #RRGGBB format ( import and export ). New colors have been added. Only the HTML Css1 are available via UI. New colors will be added. I intend to finish Css2 and dvipsnames ( latex colors ) on posterior patches. RGBA command has been unlocked for compatibility reasons. However will be displayed as RGB. Added color #RRGGBB. Improved qa color test on mathml to test RGB on mathml. TODO for someone on the UI team: - Add a color picker. - If it is a color with name: - It will add in the code "color " + starmathdatabase::Identify_Color_DVIPSNAMES( colorvalue ).pIdent +" " - If not: - It will add in the code "color " + starmathdatabase::Identify_Color_DVIPSNAMES( colorvalue ).pIdent +" "+ colorvalue.getRed() +" "+ colorvalue.getGreen() +" "+ colorvalue.getBlue() +" " - Note that those will habe eType with value TRGB or TRGBA. Change-Id: I47af37bd191b3099e8e6e08e7a5fb1a8a227bbf2 Change-Id: If971473ddcc34739439818dba9a62ca3494a4473 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105526 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include/tools')
-rw-r--r--include/tools/color.hxx306
1 files changed, 211 insertions, 95 deletions
diff --git a/include/tools/color.hxx b/include/tools/color.hxx
index afdb30d9e02c..a41a0d454117 100644
--- a/include/tools/color.hxx
+++ b/include/tools/color.hxx
@@ -33,6 +33,11 @@ constexpr sal_uInt32 extractRGB(sal_uInt32 nColorNumber)
return nColorNumber & 0x00FFFFFF;
}
+constexpr sal_uInt8 ColorChannelMerge(sal_uInt8 nDst, sal_uInt8 nSrc, sal_uInt8 nSrcTrans)
+{
+ return sal_uInt8(((sal_Int32(nDst) - nSrc) * nSrcTrans + ((nSrc << 8) | nDst)) >> 8);
+}
+
}
// Color
@@ -74,7 +79,7 @@ public:
{}
constexpr Color(sal_uInt8 nRed, sal_uInt8 nGreen, sal_uInt8 nBlue)
- : Color(0, nRed, nGreen, nBlue)
+ : mValue(sal_uInt32(nBlue) | (sal_uInt32(nGreen) << 8) | (sal_uInt32(nRed) << 16) | (sal_uInt32(0) << 24))
{}
// constructor to create a tools-Color from ::basegfx::BColor
@@ -85,160 +90,270 @@ public:
sal_uInt8(std::lround(rBColor.getBlue() * 255.0)))
{}
- /** Primarily used when passing Color objects to UNO API */
+ /** Casts the color to corresponding uInt32.
+ * Primarily used when passing Color objects to UNO API
+ * @return corresponding sal_uInt32
+ */
constexpr explicit operator sal_uInt32() const
{
return mValue;
}
+ /** Casts the color to corresponding iInt32.
+ * If there is no transparency, will be positive.
+ * @return corresponding sal_Int32
+ */
constexpr explicit operator sal_Int32() const
{
return sal_Int32(mValue);
}
- bool operator<(const Color& aCompareColor) const
- {
- return mValue < aCompareColor.mValue;
- }
+ /* Basic RGBA operations */
- void SetRed(sal_uInt8 nRed);
+ /** Gets the red value.
+ * @return R
+ */
sal_uInt8 GetRed() const
{
return R;
}
- void SetGreen(sal_uInt8 nGreen);
+
+ /** Gets the green value.
+ * @return G
+ */
sal_uInt8 GetGreen() const
{
return G;
}
- void SetBlue(sal_uInt8 nBlue);
+
+ /** Gets the blue value.
+ * @return B
+ */
sal_uInt8 GetBlue() const
{
return B;
}
- void SetTransparency(sal_uInt8 nTransparency);
+
+ /** Gets the transparency value.
+ * @return A
+ */
sal_uInt8 GetTransparency() const
{
return A;
}
- Color GetRGBColor() const
+ /** Sets the red value.
+ * @param nRed
+ */
+ void SetRed(sal_uInt8 nRed)
{
- return color::extractRGB(mValue);
+ R = nRed;
}
- sal_uInt16 GetColorError(const Color& rCompareColor) const;
-
- sal_uInt8 GetLuminance() const;
- void IncreaseLuminance(sal_uInt8 cLumInc);
- void DecreaseLuminance(sal_uInt8 cLumDec);
+ /** Sets the green value.
+ * @param nGreen
+ */
+ void SetGreen(sal_uInt8 nGreen)
+ {
+ G = nGreen;
+ }
- void DecreaseContrast(sal_uInt8 cContDec);
+ /** Sets the blue value.
+ * @param nBlue
+ */
+ void SetBlue(sal_uInt8 nBlue)
+ {
+ B = nBlue;
+ }
- /**
- * 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.
- **/
- void ApplyTintOrShade(sal_Int16 n100thPercent);
+ /** Sets the transparency value.
+ * @param nTransparency
+ */
+ void SetTransparency(sal_uInt8 nTransparency)
+ {
+ A = nTransparency;
+ }
- void Invert();
+ /** Returns the same color but ignoring the transparency value.
+ * @return RGB version
+ */
+ Color GetRGBColor() const
+ {
+ return mValue & 0x00FFFFFF;
+ }
- void Merge(const Color& rMergeColor, sal_uInt8 cTransparency);
+ /* Comparation and operators */
- bool IsRGBEqual(const Color& rColor) const;
+ /** Check if the color RGB value is equal than rColor.
+ * @param rColor
+ * @return is equal
+ */
+ bool IsRGBEqual( const Color& rColor ) const
+ {
+ return ( mValue & 0x00FFFFFF ) == ( rColor.mValue & 0x00FFFFFF );
+ }
- // comparison with luminance thresholds
- bool IsDark() const;
- bool IsBright() const;
+ /** Check if the color value is lower than aCompareColor.
+ * @param aCompareColor
+ * @return is lower
+ */
+ bool operator<(const Color& aCompareColor) const
+ {
+ return mValue < aCompareColor.mValue;
+ }
- // color space conversion tools
- // the range for h/s/b is:
- // Hue: 0-360 degree
- // Saturation: 0-100%
- // Brightness: 0-100%
- static Color HSBtoRGB(sal_uInt16 nHue, sal_uInt16 nSaturation, sal_uInt16 nBrightness);
- void RGBtoHSB(sal_uInt16& nHue, sal_uInt16& nSaturation, sal_uInt16& nBrightness) const;
+ /** Check if the color value is greater than aCompareColor.
+ * @param aCompareColor
+ * @return is greater
+ */
+ bool operator>(const Color& aCompareColor) const
+ {
+ return mValue > aCompareColor.mValue;
+ }
+ /** Check if the color value is equal than rColor.
+ * @param rColor
+ * @return is equal
+ */
bool operator==(const Color& rColor) const
{
return mValue == rColor.mValue;
}
+
+ /** Check if the color value is unequal than rColor.
+ * @param rColor
+ * @return is unequal
+ */
bool operator!=(const Color& rColor) const
{
- return !(Color::operator==(rColor));
+ return mValue != rColor.mValue;
}
- // Return color as RGB hex string
- // for example "00ff00" for green color
- OUString AsRGBHexString() const;
+ /** Gets the color error compared to another.
+ * It describes how different they are.
+ * It takes the abs of differences in parameters.
+ * @param rCompareColor
+ * @return error
+ */
+ sal_uInt16 GetColorError(const Color& rCompareColor) const
+ {
+ return static_cast<sal_uInt16>(
+ abs(static_cast<int>(GetBlue()) - rCompareColor.GetBlue()) +
+ abs(static_cast<int>(GetGreen()) - rCompareColor.GetGreen()) +
+ abs(static_cast<int>(GetRed()) - rCompareColor.GetRed()));
+ }
- // get ::basegfx::BColor from this color
- basegfx::BColor getBColor() const
+ /* Light and contrast */
+
+ /** Gets the color luminance. It means perceived brightness.
+ * @return luminance
+ */
+ sal_uInt8 GetLuminance() const
{
- return basegfx::BColor(GetRed() / 255.0, GetGreen() / 255.0, GetBlue() / 255.0);
+ return sal_uInt8((B * 29UL + G * 151UL + R * 76UL) >> 8);
}
-};
-inline void Color::SetRed( sal_uInt8 nRed )
-{
- R = nRed;
-}
+ /** Increases the color luminance by cLumInc.
+ * @param cLumInc
+ */
+ void IncreaseLuminance(sal_uInt8 cLumInc);
-inline void Color::SetGreen( sal_uInt8 nGreen )
-{
- G = nGreen;
-}
+ /** Decreases the color luminance by cLumDec.
+ * @param cLumDec
+ */
+ void DecreaseLuminance(sal_uInt8 cLumDec);
-inline void Color::SetBlue( sal_uInt8 nBlue )
-{
- B = nBlue;
-}
+ /** Decreases color contrast with white by cContDec.
+ * @param cContDec
+ */
+ void DecreaseContrast(sal_uInt8 cContDec);
-inline void Color::SetTransparency( sal_uInt8 nTransparency )
-{
- A = nTransparency;
-}
+ /** Comparison with luminance thresholds.
+ * @return is dark
+ */
+ bool IsDark() const
+ {
+ return sal_uInt8((B * 29UL + G * 151UL + R * 76UL) >> 8) <= 60;
+ }
-inline bool Color::IsRGBEqual( const Color& rColor ) const
-{
- return color::extractRGB(mValue) == color::extractRGB(rColor.mValue);
-}
+ /** Comparison with luminance thresholds.
+ * @return is dark
+ */
+ bool IsBright() const
+ {
+ return sal_uInt8((B * 29UL + G * 151UL + R * 76UL) >> 8) >= 245;
+ }
-inline sal_uInt8 Color::GetLuminance() const
-{
- return sal_uInt8((B * 29UL + G * 151UL + R * 76UL) >> 8);
-}
+ /* Color filters */
-constexpr sal_uInt8 ColorChannelMerge(sal_uInt8 nDst, sal_uInt8 nSrc, sal_uInt8 nSrcTrans)
-{
- return sal_uInt8(((sal_Int32(nDst) - nSrc) * nSrcTrans + ((nSrc << 8) | nDst)) >> 8);
-}
+ /**
+ * 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.
+ **/
+ void ApplyTintOrShade(sal_Int16 n100thPercent);
-inline void Color::Invert()
-{
- R = ~R;
- G = ~G;
- B = ~B;
-}
+ /** 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.
+ */
+ void Invert()
+ {
+ R = ~R;
+ G = ~G;
+ B = ~B;
+ }
-inline sal_uInt16 Color::GetColorError( const Color& rColor ) const
-{
- return static_cast<sal_uInt16>(
- abs(static_cast<int>(GetBlue()) - rColor.GetBlue()) +
- abs(static_cast<int>(GetGreen()) - rColor.GetGreen()) +
- abs(static_cast<int>(GetRed()) - rColor.GetRed()));
-}
+ /** Merges color with rMergeColor.
+ * Allows to get resulting color when supperposing another.
+ * @param rMergeColor
+ * @param cTransparency
+ */
+ void Merge(const Color& rMergeColor, sal_uInt8 cTransparency)
+ {
+ R = color::ColorChannelMerge(R, rMergeColor.R, cTransparency);
+ G = color::ColorChannelMerge(G, rMergeColor.G, cTransparency);
+ B = color::ColorChannelMerge(B, rMergeColor.B, cTransparency);
+ }
-inline void Color::Merge( const Color& rMergeColor, sal_uInt8 cTransparency )
-{
- R = ColorChannelMerge(R, rMergeColor.R, cTransparency);
- G = ColorChannelMerge(G, rMergeColor.G, cTransparency);
- B = ColorChannelMerge(B, rMergeColor.B, cTransparency);
-}
+ /* Change of format */
+
+ /** Color space conversion tools
+ * The range for h/s/b is:
+ * - Hue: 0-360 degree
+ * - Saturation: 0-100%
+ * - Brightness: 0-100%
+ * @param nHue
+ * @param nSaturation
+ * @param nBrightness
+ * @return rgb color
+ */
+ static Color HSBtoRGB(sal_uInt16 nHue, sal_uInt16 nSaturation, sal_uInt16 nBrightness);
+
+ /** Color space conversion tools
+ * @param nHue
+ * @param nSaturation
+ * @param nBrightness
+ */
+ void RGBtoHSB(sal_uInt16& nHue, sal_uInt16& nSaturation, sal_uInt16& nBrightness) const;
+
+ /* Return color as RGB hex string
+ * for example "00ff00" for green color
+ * @return hex string
+ */
+ OUString AsRGBHexString() const;
+
+ /* get ::basegfx::BColor from this color
+ * @return basegfx color
+ */
+ basegfx::BColor getBColor() const
+ {
+ return basegfx::BColor(R / 255.0, G / 255.0, B / 255.0);
+ }
+};
// to reduce the noise when moving these into and out of Any
inline bool operator >>=( const css::uno::Any & rAny, Color & value )
@@ -254,6 +369,7 @@ inline void operator <<=( css::uno::Any & rAny, Color value )
{
rAny <<= sal_Int32(value);
}
+
namespace com::sun::star::uno {
template<>
inline Any makeAny( Color const & value )