summaryrefslogtreecommitdiff
path: root/include/vcl
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2019-05-11 11:49:21 +0000
committerJan-Marek Glogowski <glogow@fbihome.de>2019-05-13 15:43:17 +0200
commitc34bb163c38cfa893d1b5b0124ab9c5929dff16c (patch)
tree8994582e896495c8fe919e7a26c2852f9d120ec2 /include/vcl
parent0725e8a5d9add88b1289f5b1cb90b0b43059a734 (diff)
Make BitmapColor inherit from / merge into Color
BitmapColor itself is kept to distingish the Color usage as part of a color palette, which continues to store the offset in the blue value. The original special mbIndex handling is long gone since commit 1fefdd6f3b41 ("Alpha channel in BitmapColor - change bIndex to alpha"), so there is no data difference. This also results in the following changes: * now has a basic_ostream<charT, traits>& operator<< (that was my actual starting point... for an other bug fix) * there is a minimal difference for GetLiminance BGR(29,151,76) => BGR(28,151,77) * no more return values for Merge and Invert (previously returning *this) * replaces all GetBlueOrIndex with GetIndex This leaves one "problematic" part: the GetColorError handling. At first glance it should probably be virtual. The Color variant is less strict then the BitmapColor one - for whatever reason. BitmapColor is always used to search for the best match in a Palette. Currently I'm simply leaving both variants. Would be nice to have an explict for functions here. Change-Id: I251ba3024a1d60f2a9d9fde9cd0a60f08e8322a7 Reviewed-on: https://gerrit.libreoffice.org/72181 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
Diffstat (limited to 'include/vcl')
-rw-r--r--include/vcl/BitmapColor.hxx167
-rw-r--r--include/vcl/bitmapaccess.hxx2
2 files changed, 19 insertions, 150 deletions
diff --git a/include/vcl/BitmapColor.hxx b/include/vcl/BitmapColor.hxx
index 7df493e7b38d..4344a7bd242f 100644
--- a/include/vcl/BitmapColor.hxx
+++ b/include/vcl/BitmapColor.hxx
@@ -22,203 +22,72 @@
#include <vcl/dllapi.h>
#include <tools/color.hxx>
+#include <cassert>
#include <memory>
-class VCL_DLLPUBLIC BitmapColor final
+class VCL_DLLPUBLIC BitmapColor final : public Color
{
-private:
- sal_uInt8 mcBlueOrIndex;
- sal_uInt8 mcGreen;
- sal_uInt8 mcRed;
- sal_uInt8 mcAlpha;
-
public:
-
inline BitmapColor();
constexpr BitmapColor( sal_uInt8 cRed, sal_uInt8 cGreen, sal_uInt8 cBlue, sal_uInt8 cAlpha = 0 );
inline BitmapColor( const Color& rColor );
explicit inline BitmapColor( sal_uInt8 cIndex );
- inline bool operator==( const BitmapColor& rBitmapColor ) const;
- inline bool operator!=( const BitmapColor& rBitmapColor ) const;
-
- inline sal_uInt8 GetRed() const;
- inline void SetRed( sal_uInt8 cRed );
-
- inline sal_uInt8 GetGreen() const;
- inline void SetGreen( sal_uInt8 cGreen );
-
- inline sal_uInt8 GetBlue() const;
- inline void SetBlue( sal_uInt8 cBlue );
-
inline sal_uInt8 GetIndex() const;
inline void SetIndex( sal_uInt8 cIndex );
- Color GetColor() const;
-
inline sal_uInt8 GetAlpha() const;
inline void SetAlpha( sal_uInt8 cAlpha );
- inline sal_uInt8 GetBlueOrIndex() const;
-
- inline BitmapColor& Invert();
-
- inline sal_uInt8 GetLuminance() const;
-
- inline BitmapColor& Merge( const BitmapColor& rColor, sal_uInt8 cTransparency );
-
- inline sal_uInt16 GetColorError( const BitmapColor& rBitmapColor ) const;
+ inline sal_uInt16 GetColorError( const BitmapColor& rColor ) const;
};
-template<typename charT, typename traits>
-inline std::basic_ostream<charT, traits>& operator <<(std::basic_ostream<charT, traits>& rStream, const BitmapColor& rColor)
-{
- return rStream << "#(" << std::hex << std::setfill ('0') << std::setw(2) << static_cast<int>(rColor.GetRed())
- << std::setw(2) << static_cast<int>(rColor.GetGreen())
- << std::setw(2) << static_cast<int>(rColor.GetBlueOrIndex())
- << std::setw(2) << static_cast<int>(rColor.GetAlpha()) << ")";
-}
-
-inline BitmapColor::BitmapColor() :
- mcBlueOrIndex (0),
- mcGreen (0),
- mcRed (0),
- mcAlpha (0)
-{
-}
-
-constexpr BitmapColor::BitmapColor(sal_uInt8 cRed, sal_uInt8 cGreen, sal_uInt8 cBlue, sal_uInt8 cAlpha) :
- mcBlueOrIndex ( cBlue ),
- mcGreen ( cGreen ),
- mcRed ( cRed ),
- mcAlpha ( cAlpha )
-{
-}
-
-inline BitmapColor::BitmapColor( const Color& rColor ) :
- mcBlueOrIndex ( rColor.GetBlue() ),
- mcGreen ( rColor.GetGreen() ),
- mcRed ( rColor.GetRed() ),
- mcAlpha ( rColor.GetTransparency() )
-{
-}
-
-inline BitmapColor::BitmapColor( sal_uInt8 cIndex ) :
- mcBlueOrIndex ( cIndex ),
- mcGreen ( 0 ),
- mcRed ( 0 ),
- mcAlpha ( 0 )
-{
-}
-
-inline bool BitmapColor::operator==( const BitmapColor& rBitmapColor ) const
-{
- return mcBlueOrIndex == rBitmapColor.mcBlueOrIndex &&
- mcGreen == rBitmapColor.mcGreen &&
- mcRed == rBitmapColor.mcRed &&
- mcAlpha == rBitmapColor.mcAlpha;
-}
-
-inline bool BitmapColor::operator!=( const BitmapColor& rBitmapColor ) const
+inline BitmapColor::BitmapColor()
{
- return !( *this == rBitmapColor );
}
-inline sal_uInt8 BitmapColor::GetRed() const
+inline BitmapColor::BitmapColor( const Color& rColor )
+ : Color(rColor)
{
- return mcRed;
}
-inline void BitmapColor::SetRed( sal_uInt8 cRed )
+constexpr BitmapColor::BitmapColor(sal_uInt8 cRed, sal_uInt8 cGreen, sal_uInt8 cBlue, sal_uInt8 cAlpha)
+ : Color(cAlpha, cRed, cGreen, cBlue)
{
- mcRed = cRed;
}
-inline sal_uInt8 BitmapColor::GetGreen() const
+inline BitmapColor::BitmapColor( sal_uInt8 cIndex )
{
- return mcGreen;
-}
-
-inline void BitmapColor::SetGreen( sal_uInt8 cGreen )
-{
- mcGreen = cGreen;
-}
-
-inline sal_uInt8 BitmapColor::GetBlue() const
-{
- return mcBlueOrIndex;
-}
-
-inline void BitmapColor::SetBlue( sal_uInt8 cBlue )
-{
- mcBlueOrIndex = cBlue;
+ SetIndex(cIndex);
}
inline sal_uInt8 BitmapColor::GetIndex() const
{
- return mcBlueOrIndex;
+ return GetBlue();
}
inline void BitmapColor::SetIndex( sal_uInt8 cIndex )
{
- mcBlueOrIndex = cIndex;
-}
-
-inline Color BitmapColor::GetColor() const
-{
- return Color(mcAlpha, mcRed, mcGreen, mcBlueOrIndex);
+ SetBlue(cIndex);
}
inline sal_uInt8 BitmapColor::GetAlpha() const
{
- return mcAlpha;
+ return GetTransparency();
}
inline void BitmapColor::SetAlpha( sal_uInt8 cAlpha )
{
- mcAlpha = cAlpha;
-}
-
-inline sal_uInt8 BitmapColor::GetBlueOrIndex() const
-{
- // #i47518# Yield a value regardless of mbIndex
- return mcBlueOrIndex;
-}
-
-inline BitmapColor& BitmapColor::Invert()
-{
- mcBlueOrIndex = ~mcBlueOrIndex;
- mcGreen = ~mcGreen;
- mcRed = ~mcRed;
-
- return *this;
-}
-
-inline sal_uInt8 BitmapColor::GetLuminance() const
-{
- return (static_cast<sal_uInt32>(mcBlueOrIndex) * 28
- + static_cast<sal_uInt32>(mcGreen) * 151
- + static_cast<sal_uInt32>(mcRed) * 77) >> 8;
+ SetTransparency(cAlpha);
}
-
-inline BitmapColor& BitmapColor::Merge( const BitmapColor& rBitmapColor, sal_uInt8 cTransparency )
-{
- mcBlueOrIndex = ColorChannelMerge( mcBlueOrIndex, rBitmapColor.mcBlueOrIndex, cTransparency );
- mcGreen = ColorChannelMerge( mcGreen, rBitmapColor.mcGreen, cTransparency );
- mcRed = ColorChannelMerge( mcRed, rBitmapColor.mcRed, cTransparency );
-
- return *this;
-}
-
-
-inline sal_uInt16 BitmapColor::GetColorError( const BitmapColor& rBitmapColor ) const
+inline sal_uInt16 BitmapColor::GetColorError( const BitmapColor& rColor ) const
{
return static_cast<sal_uInt16>(
- abs( static_cast<int>(mcBlueOrIndex) - static_cast<int>(rBitmapColor.mcBlueOrIndex) ) +
- abs( static_cast<int>(mcGreen) - static_cast<int>(rBitmapColor.mcGreen) ) +
- abs( static_cast<int>(mcRed) - static_cast<int>(rBitmapColor.mcRed) ) );
+ abs( static_cast<int>(GetBlue()) - static_cast<int>(rColor.GetBlue()) ) +
+ abs( static_cast<int>(GetGreen()) - static_cast<int>(rColor.GetGreen()) ) +
+ abs( static_cast<int>(GetRed()) - static_cast<int>(rColor.GetRed()) ) );
}
#endif // INCLUDED_VCL_BITMAPCOLOR_HXX
diff --git a/include/vcl/bitmapaccess.hxx b/include/vcl/bitmapaccess.hxx
index db426fa3e4e2..e1adbf10c4c1 100644
--- a/include/vcl/bitmapaccess.hxx
+++ b/include/vcl/bitmapaccess.hxx
@@ -214,7 +214,7 @@ public:
sal_uInt8 GetPixelIndex(long nY, long nX) const
{
- return GetPixel(nY, nX).GetBlueOrIndex();
+ return GetPixel(nY, nX).GetIndex();
}
/** Get the interpolated color at coordinates fY, fX; if outside, return rFallback */