remove unused DrawModeFlags

DrawModeFlags::BlackBitmap is dead since
  commit e7b460f919
  Author: Noel Grandin <noel.grandin@collabora.co.uk>
  Date:   Sat Aug 30 15:23:11 2025 +0200
  BitmapEx->Bitmap in canvas

DrawModeFlags::WhiteBitmap is dead since
  commit 81994cb2b8
  Author: Noel Grandin <noelgrandin@gmail.com>
  Date:   Fri Apr 16 20:33:10 2021 +0200
  Convert internal vcl bitmap formats transparency->alpha (II)

Change-Id: I933d5416300850e624c3b438d00d986c787e0a05
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190977
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2025-09-15 21:48:14 +02:00
parent d7d9253739
commit 7278030b92
7 changed files with 19 additions and 239 deletions
@@ -1236,33 +1236,16 @@ Bitmap CairoPixelProcessor2D::extractBitmap() const
void CairoPixelProcessor2D::processBitmapPrimitive2D(
const primitive2d::BitmapPrimitive2D& rBitmapCandidate)
{
constexpr DrawModeFlags BITMAP(DrawModeFlags::BlackBitmap | DrawModeFlags::WhiteBitmap
| DrawModeFlags::GrayBitmap);
const DrawModeFlags aDrawModeFlags(getViewInformation2D().getDrawModeFlags());
const bool bDrawModeFlagsUsed(aDrawModeFlags & BITMAP);
const bool bDrawModeFlagsUsed(aDrawModeFlags & DrawModeFlags::GrayBitmap);
if (bDrawModeFlagsUsed)
{
// if DrawModeFlags for Bitmap are used, encapsulate with
// corresponding BColorModifier
if (aDrawModeFlags & DrawModeFlags::BlackBitmap)
{
const basegfx::BColorModifierSharedPtr aBColorModifier(
std::make_shared<basegfx::BColorModifier_replace>(basegfx::BColor(0, 0, 0)));
maBColorModifierStack.push(aBColorModifier);
}
else if (aDrawModeFlags & DrawModeFlags::WhiteBitmap)
{
const basegfx::BColorModifierSharedPtr aBColorModifier(
std::make_shared<basegfx::BColorModifier_replace>(basegfx::BColor(1, 1, 1)));
maBColorModifierStack.push(aBColorModifier);
}
else // DrawModeFlags::GrayBitmap
{
const basegfx::BColorModifierSharedPtr aBColorModifier(
std::make_shared<basegfx::BColorModifier_gray>());
maBColorModifierStack.push(aBColorModifier);
}
const basegfx::BColorModifierSharedPtr aBColorModifier(
std::make_shared<basegfx::BColorModifier_gray>());
maBColorModifierStack.push(aBColorModifier);
}
paintBitmapAlpha(rBitmapCandidate.getBitmap(), rBitmapCandidate.getTransform());
@@ -2085,29 +2068,12 @@ void CairoPixelProcessor2D::processMarkerArrayPrimitive2D(
// prepare Marker's Bitmap
Bitmap aBitmap(rMarkerArrayCandidate.getMarker());
constexpr DrawModeFlags BITMAP(DrawModeFlags::BlackBitmap | DrawModeFlags::WhiteBitmap
| DrawModeFlags::GrayBitmap);
const DrawModeFlags aDrawModeFlags(getViewInformation2D().getDrawModeFlags());
if (aDrawModeFlags & BITMAP)
if (aDrawModeFlags & DrawModeFlags::GrayBitmap)
{
if (aDrawModeFlags & DrawModeFlags::BlackBitmap)
{
const basegfx::BColorModifierSharedPtr aBColorModifier(
std::make_shared<basegfx::BColorModifier_replace>(basegfx::BColor(0, 0, 0)));
maBColorModifierStack.push(aBColorModifier);
}
else if (aDrawModeFlags & DrawModeFlags::WhiteBitmap)
{
const basegfx::BColorModifierSharedPtr aBColorModifier(
std::make_shared<basegfx::BColorModifier_replace>(basegfx::BColor(1, 1, 1)));
maBColorModifierStack.push(aBColorModifier);
}
else // DrawModeFlags::GrayBitmap
{
const basegfx::BColorModifierSharedPtr aBColorModifier(
std::make_shared<basegfx::BColorModifier_gray>());
maBColorModifierStack.push(aBColorModifier);
}
const basegfx::BColorModifierSharedPtr aBColorModifier(
std::make_shared<basegfx::BColorModifier_gray>());
maBColorModifierStack.push(aBColorModifier);
// need to apply ColorModifier to Bitmap data
aBitmap = aBitmap.Modify(maBColorModifierStack);
@@ -2524,30 +2490,15 @@ void CairoPixelProcessor2D::processFillGraphicPrimitive2D(
return;
}
constexpr DrawModeFlags BITMAP(DrawModeFlags::BlackBitmap | DrawModeFlags::WhiteBitmap
| DrawModeFlags::GrayBitmap);
basegfx::BColor aReplacementColor(0, 0, 0);
bool bTemporaryGrayColorModifier(false);
const DrawModeFlags aDrawModeFlags(getViewInformation2D().getDrawModeFlags());
if (aDrawModeFlags & BITMAP)
if (aDrawModeFlags & DrawModeFlags::GrayBitmap)
{
if (aDrawModeFlags & DrawModeFlags::BlackBitmap)
{
// aReplacementColor already set
aPreparedBitmap.SetEmpty();
}
else if (aDrawModeFlags & DrawModeFlags::WhiteBitmap)
{
aReplacementColor = basegfx::BColor(1, 1, 1);
aPreparedBitmap.SetEmpty();
}
else // DrawModeFlags::GrayBitmap
{
bTemporaryGrayColorModifier = true;
const basegfx::BColorModifierSharedPtr aBColorModifier(
std::make_shared<basegfx::BColorModifier_gray>());
maBColorModifierStack.push(aBColorModifier);
}
bTemporaryGrayColorModifier = true;
const basegfx::BColorModifierSharedPtr aBColorModifier(
std::make_shared<basegfx::BColorModifier_gray>());
maBColorModifierStack.push(aBColorModifier);
}
if (!aPreparedBitmap.IsEmpty() && maBColorModifierStack.count())
@@ -3571,31 +3522,14 @@ void CairoPixelProcessor2D::processPolyPolygonAlphaGradientPrimitive2D(
void CairoPixelProcessor2D::processBitmapAlphaPrimitive2D(
const primitive2d::BitmapAlphaPrimitive2D& rBitmapAlphaPrimitive2D)
{
constexpr DrawModeFlags BITMAP(DrawModeFlags::BlackBitmap | DrawModeFlags::WhiteBitmap
| DrawModeFlags::GrayBitmap);
const DrawModeFlags aDrawModeFlags(getViewInformation2D().getDrawModeFlags());
const bool bDrawModeFlagsUsed(aDrawModeFlags & BITMAP);
const bool bDrawModeFlagsUsed(aDrawModeFlags & DrawModeFlags::GrayBitmap);
if (bDrawModeFlagsUsed)
{
if (aDrawModeFlags & DrawModeFlags::BlackBitmap)
{
const basegfx::BColorModifierSharedPtr aBColorModifier(
std::make_shared<basegfx::BColorModifier_replace>(basegfx::BColor(0, 0, 0)));
maBColorModifierStack.push(aBColorModifier);
}
else if (aDrawModeFlags & DrawModeFlags::WhiteBitmap)
{
const basegfx::BColorModifierSharedPtr aBColorModifier(
std::make_shared<basegfx::BColorModifier_replace>(basegfx::BColor(1, 1, 1)));
maBColorModifierStack.push(aBColorModifier);
}
else // DrawModeFlags::GrayBitmap
{
const basegfx::BColorModifierSharedPtr aBColorModifier(
std::make_shared<basegfx::BColorModifier_gray>());
maBColorModifierStack.push(aBColorModifier);
}
const basegfx::BColorModifierSharedPtr aBColorModifier(
std::make_shared<basegfx::BColorModifier_gray>());
maBColorModifierStack.push(aBColorModifier);
}
if (!rBitmapAlphaPrimitive2D.hasTransparency())
+1 -3
View File
@@ -28,7 +28,6 @@ enum class DrawModeFlags : sal_uInt32
BlackLine = 0x00000001,
BlackFill = 0x00000002,
BlackText = 0x00000004,
BlackBitmap = 0x00000008,
BlackGradient = 0x00000010,
GrayLine = 0x00000020,
GrayFill = 0x00000040,
@@ -39,7 +38,6 @@ enum class DrawModeFlags : sal_uInt32
WhiteLine = 0x00000800,
WhiteFill = 0x00001000,
WhiteText = 0x00002000,
WhiteBitmap = 0x00004000,
WhiteGradient = 0x00008000,
SettingsLine = 0x00010000,
SettingsFill = 0x00020000,
@@ -50,7 +48,7 @@ enum class DrawModeFlags : sal_uInt32
};
namespace o3tl
{
template <> struct typed_flags<DrawModeFlags> : is_typed_flags<DrawModeFlags, 0x3fffff>
template <> struct typed_flags<DrawModeFlags> : is_typed_flags<DrawModeFlags, 0x3fbff7>
{
};
}
-16
View File
@@ -97,10 +97,6 @@ void VclDrawModeTest::testDrawModeLineColor()
aColor, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::GrayText, aStyleSettings));
CPPUNIT_ASSERT_EQUAL(
aColor, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::SettingsText, aStyleSettings));
CPPUNIT_ASSERT_EQUAL(
aColor, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::BlackBitmap, aStyleSettings));
CPPUNIT_ASSERT_EQUAL(
aColor, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::WhiteBitmap, aStyleSettings));
CPPUNIT_ASSERT_EQUAL(
aColor, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::GrayBitmap, aStyleSettings));
}
@@ -157,10 +153,6 @@ void VclDrawModeTest::testDrawModeFillColor()
aColor, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::GrayText, aStyleSettings));
CPPUNIT_ASSERT_EQUAL(
aColor, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::SettingsText, aStyleSettings));
CPPUNIT_ASSERT_EQUAL(
aColor, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::BlackBitmap, aStyleSettings));
CPPUNIT_ASSERT_EQUAL(
aColor, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::WhiteBitmap, aStyleSettings));
CPPUNIT_ASSERT_EQUAL(
aColor, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::GrayBitmap, aStyleSettings));
}
@@ -201,10 +193,6 @@ void VclDrawModeTest::testDrawModeHatchColor()
aColor, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::GrayText, aStyleSettings));
CPPUNIT_ASSERT_EQUAL(
aColor, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::SettingsText, aStyleSettings));
CPPUNIT_ASSERT_EQUAL(
aColor, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::BlackBitmap, aStyleSettings));
CPPUNIT_ASSERT_EQUAL(
aColor, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::WhiteBitmap, aStyleSettings));
CPPUNIT_ASSERT_EQUAL(
aColor, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::GrayBitmap, aStyleSettings));
}
@@ -245,10 +233,6 @@ void VclDrawModeTest::testDrawModeTextColor()
aColor, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::GrayFill, aStyleSettings));
CPPUNIT_ASSERT_EQUAL(
aColor, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::SettingsFill, aStyleSettings));
CPPUNIT_ASSERT_EQUAL(
aColor, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::BlackBitmap, aStyleSettings));
CPPUNIT_ASSERT_EQUAL(
aColor, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::WhiteBitmap, aStyleSettings));
CPPUNIT_ASSERT_EQUAL(
aColor, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::GrayBitmap, aStyleSettings));
}
-89
View File
@@ -164,95 +164,6 @@ CPPUNIT_TEST_FIXTURE(VclOutdevTest, testDrawInvertedBitmap)
CPPUNIT_ASSERT_EQUAL(tools::Rectangle(Point(0, 0), Size(10, 10)), pRectAction->GetRect());
}
CPPUNIT_TEST_FIXTURE(VclOutdevTest, testDrawBlackBitmap)
{
ScopedVclPtrInstance<VirtualDevice> pVDev;
Bitmap aBitmap(Size(16, 16), vcl::PixelFormat::N24_BPP);
aBitmap.Erase(COL_RED);
GDIMetaFile aMtf;
aMtf.Record(pVDev.get());
pVDev->SetDrawMode(DrawModeFlags::BlackBitmap);
pVDev->DrawBitmap(Point(0, 0), Size(10, 10), Point(0, 0), Size(10, 10), aBitmap,
MetaActionType::BMP);
MetaAction* pAction = aMtf.GetAction(0);
CPPUNIT_ASSERT_EQUAL(MetaActionType::PUSH, pAction->GetType());
auto pPushAction = static_cast<MetaPushAction*>(pAction);
bool bLineFillFlag
= ((vcl::PushFlags::LINECOLOR | vcl::PushFlags::FILLCOLOR) == pPushAction->GetFlags());
CPPUNIT_ASSERT_MESSAGE("Push flags not LINECOLOR | FILLCOLOR", bLineFillFlag);
pAction = aMtf.GetAction(1);
CPPUNIT_ASSERT_EQUAL(MetaActionType::LINECOLOR, pAction->GetType());
auto pLineColorAction = static_cast<MetaLineColorAction*>(pAction);
CPPUNIT_ASSERT_EQUAL(COL_BLACK, pLineColorAction->GetColor());
pAction = aMtf.GetAction(2);
CPPUNIT_ASSERT_EQUAL(MetaActionType::FILLCOLOR, pAction->GetType());
auto pFillColorAction = static_cast<MetaFillColorAction*>(pAction);
CPPUNIT_ASSERT_EQUAL(COL_BLACK, pFillColorAction->GetColor());
pAction = aMtf.GetAction(3);
CPPUNIT_ASSERT_EQUAL(MetaActionType::RECT, pAction->GetType());
auto pRectAction = static_cast<MetaRectAction*>(pAction);
CPPUNIT_ASSERT_EQUAL(tools::Rectangle(Point(0, 0), Size(10, 10)), pRectAction->GetRect());
pAction = aMtf.GetAction(4);
CPPUNIT_ASSERT_EQUAL(MetaActionType::POP, pAction->GetType());
// test to see if the color is black
Bitmap aBlackBmp(pVDev->GetBitmap(Point(0, 0), Size(10, 10)));
BitmapScopedReadAccess pReadAccess(aBlackBmp);
const BitmapColor aColor = pReadAccess->GetColor(0, 0);
CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_BLACK), aColor);
}
CPPUNIT_TEST_FIXTURE(VclOutdevTest, testDrawWhiteBitmap)
{
ScopedVclPtrInstance<VirtualDevice> pVDev;
Bitmap aBitmap(Size(16, 16), vcl::PixelFormat::N24_BPP);
GDIMetaFile aMtf;
aMtf.Record(pVDev.get());
pVDev->SetDrawMode(DrawModeFlags::WhiteBitmap);
pVDev->DrawBitmap(Point(0, 0), Size(10, 10), Point(0, 0), Size(10, 10), aBitmap,
MetaActionType::BMP);
MetaAction* pAction = aMtf.GetAction(0);
CPPUNIT_ASSERT_EQUAL(MetaActionType::PUSH, pAction->GetType());
auto pPushAction = static_cast<MetaPushAction*>(pAction);
bool bLineFillFlag
= ((vcl::PushFlags::LINECOLOR | vcl::PushFlags::FILLCOLOR) == pPushAction->GetFlags());
CPPUNIT_ASSERT_MESSAGE("Push flags not LINECOLOR | FILLCOLOR", bLineFillFlag);
pAction = aMtf.GetAction(1);
CPPUNIT_ASSERT_EQUAL(MetaActionType::LINECOLOR, pAction->GetType());
auto pLineColorAction = static_cast<MetaLineColorAction*>(pAction);
CPPUNIT_ASSERT_EQUAL(COL_WHITE, pLineColorAction->GetColor());
pAction = aMtf.GetAction(2);
CPPUNIT_ASSERT_EQUAL(MetaActionType::FILLCOLOR, pAction->GetType());
auto pFillColorAction = static_cast<MetaFillColorAction*>(pAction);
CPPUNIT_ASSERT_EQUAL(COL_WHITE, pFillColorAction->GetColor());
pAction = aMtf.GetAction(3);
CPPUNIT_ASSERT_EQUAL(MetaActionType::RECT, pAction->GetType());
auto pRectAction = static_cast<MetaRectAction*>(pAction);
CPPUNIT_ASSERT_EQUAL(tools::Rectangle(Point(0, 0), Size(10, 10)), pRectAction->GetRect());
pAction = aMtf.GetAction(4);
CPPUNIT_ASSERT_EQUAL(MetaActionType::POP, pAction->GetType());
// test to see if the color is white
Bitmap aWhiteBmp(pVDev->GetBitmap(Point(0, 0), Size(10, 10)));
BitmapScopedReadAccess pReadAccess(aWhiteBmp);
const BitmapColor aColor = pReadAccess->GetColor(0, 0);
CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_WHITE), aColor);
}
CPPUNIT_TEST_FIXTURE(VclOutdevTest, testDrawBitmap)
{
ScopedVclPtrInstance<VirtualDevice> pVDev;
-17
View File
@@ -73,23 +73,6 @@ void OutputDevice::DrawBitmap( const Point& rDestPt, const Size& rDestSize,
return;
}
if (mnDrawMode & (DrawModeFlags::BlackBitmap | DrawModeFlags::WhiteBitmap))
{
sal_uInt8 cCmpVal;
if (mnDrawMode & DrawModeFlags::BlackBitmap)
cCmpVal = 0;
else
cCmpVal = 255;
Color aCol(cCmpVal, cCmpVal, cCmpVal);
auto popIt = ScopedPush(vcl::PushFlags::LINECOLOR | vcl::PushFlags::FILLCOLOR);
SetLineColor(aCol);
SetFillColor(aCol);
DrawRect(tools::Rectangle(rDestPt, rDestSize));
return;
}
Bitmap aBmp(rBitmap);
if (mnDrawMode & DrawModeFlags::GrayBitmap && !aBmp.IsEmpty())
+1 -1
View File
@@ -366,7 +366,7 @@ void OutputDevice::DrawTransformedBitmapEx(
Bitmap bitmap = rBitmap;
const bool bInvert(RasterOp::Invert == meRasterOp);
const bool bBitmapChangedColor(mnDrawMode & (DrawModeFlags::BlackBitmap | DrawModeFlags::WhiteBitmap | DrawModeFlags::GrayBitmap ));
const bool bBitmapChangedColor(mnDrawMode & DrawModeFlags::GrayBitmap);
const bool bTryDirectPaint(!bInvert && !bBitmapChangedColor && !bMetafile);
// tdf#130768 CAUTION(!) using GetViewTransformation() is *not* enough here, it may
// be that mnOutOffX/mnOutOffY is used - see AOO bug 75163, mentioned at
-30
View File
@@ -244,36 +244,6 @@ Bitmap GetBitmap(Bitmap const& rBitmap, DrawModeFlags nDrawMode)
{
Bitmap aBmp(rBitmap);
if (nDrawMode & (DrawModeFlags::BlackBitmap | DrawModeFlags::WhiteBitmap))
{
Bitmap aColorBmp(aBmp.GetSizePixel(), vcl::PixelFormat::N8_BPP,
&Bitmap::GetGreyPalette(256));
sal_uInt8 cCmpVal;
if (nDrawMode & DrawModeFlags::BlackBitmap)
cCmpVal = 0;
else
cCmpVal = 255;
aColorBmp.Erase(Color(cCmpVal, cCmpVal, cCmpVal));
if (aBmp.HasAlpha())
{
// Create one-bit mask out of alpha channel, by thresholding it at alpha=0.5. As
// DRAWMODE_BLACK/WHITEBITMAP requires monochrome output, having alpha-induced
// grey levels is not acceptable
Bitmap aMask(aBmp.CreateAlphaMask().GetBitmap());
aMask.Invert(); // convert to transparency
BitmapFilter::Filter(aMask, BitmapMonochromeFilter(129));
aMask.Invert(); // convert to alpha
aBmp = Bitmap(aColorBmp, aMask);
}
else
{
aBmp = std::move(aColorBmp);
}
}
if (nDrawMode & DrawModeFlags::GrayBitmap && !aBmp.IsEmpty())
aBmp.Convert(BmpConversion::N8BitGreys);