[Libreoffice-commits] core.git: vcl/inc vcl/qa vcl/source
Chris Sherlock (via logerrit)
logerrit at kemper.freedesktop.org
Thu Aug 26 00:16:45 UTC 2021
vcl/inc/drawmode.hxx | 2
vcl/qa/cppunit/drawmode.cxx | 32 ------
vcl/qa/cppunit/outdev.cxx | 167 ++++++++++++++++++++++++++++++++++
vcl/source/outdev/bitmap.cxx | 29 +++++
vcl/source/rendercontext/drawmode.cxx | 13 --
5 files changed, 195 insertions(+), 48 deletions(-)
New commits:
commit 9ea129b49259231565d18f965a57c5fefb4ccc7a
Author: Chris Sherlock <chris.sherlock79 at gmail.com>
AuthorDate: Wed Aug 25 22:40:32 2021 +1000
Commit: Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Thu Aug 26 02:16:11 2021 +0200
vcl: partial revert of drawmode
Partial revert of commit 0901297902c29c041ae944973b369e8247716893:
vcl: create drawmode functions
The GetBitmap() function will not work, as it doesn't add metafile
actions.
I have added a unit test to prevent this from occuring in future.
Change-Id: I8c895e813f378f85ee47f85c3f867e20925bae2f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121039
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/vcl/inc/drawmode.hxx b/vcl/inc/drawmode.hxx
index 9234b180b4c6..4c1647e0e117 100644
--- a/vcl/inc/drawmode.hxx
+++ b/vcl/inc/drawmode.hxx
@@ -44,8 +44,6 @@ VCL_DLLPUBLIC Color GetTextColor(Color const& rColor, DrawModeFlags nDrawMode,
VCL_DLLPUBLIC vcl::Font GetFont(vcl::Font const& rFont, DrawModeFlags nDrawMode,
StyleSettings const& rStyleSettings);
-VCL_DLLPUBLIC Bitmap GetBitmap(Bitmap const& rBitmap, DrawModeFlags nDrawMode);
-
VCL_DLLPUBLIC BitmapEx GetBitmapEx(BitmapEx const& rBitmapEx, DrawModeFlags nDrawMode);
};
diff --git a/vcl/qa/cppunit/drawmode.cxx b/vcl/qa/cppunit/drawmode.cxx
index f3ea1af773f7..a9079af29227 100644
--- a/vcl/qa/cppunit/drawmode.cxx
+++ b/vcl/qa/cppunit/drawmode.cxx
@@ -32,7 +32,6 @@ public:
void testDrawModeHatchColor();
void testDrawModeTextColor();
void testDrawModeFontColor();
- void testDrawModeBitmap();
void testDrawModeBitmapEx();
CPPUNIT_TEST_SUITE(VclDrawModeTest);
@@ -42,7 +41,6 @@ public:
CPPUNIT_TEST(testDrawModeHatchColor);
CPPUNIT_TEST(testDrawModeTextColor);
CPPUNIT_TEST(testDrawModeFontColor);
- CPPUNIT_TEST(testDrawModeBitmap);
CPPUNIT_TEST(testDrawModeBitmapEx);
CPPUNIT_TEST_SUITE_END();
@@ -330,36 +328,6 @@ void VclDrawModeTest::testDrawModeFontColor()
CPPUNIT_ASSERT_EQUAL(COL_RED, aTestFont.GetFillColor());
}
-void VclDrawModeTest::testDrawModeBitmap()
-{
- const StyleSettings aStyleSettings;
-
- Bitmap aBmp(Size(1, 1), vcl::PixelFormat::N24_BPP);
- BitmapWriteAccess aBmpAccess(aBmp);
- aBmpAccess.SetPixel(0, 0, BitmapColor(COL_RED));
-
- {
- Bitmap aResultBitmap(vcl::drawmode::GetBitmap(aBmp, DrawModeFlags::GrayBitmap));
- Bitmap::ScopedReadAccess pReadAccess(aResultBitmap);
-
- const BitmapColor& rColor = pReadAccess->GetColor(0, 0);
- CPPUNIT_ASSERT_EQUAL(sal_Int32(0x26), sal_Int32(rColor.GetRed()));
- CPPUNIT_ASSERT_EQUAL(sal_Int32(0x26), sal_Int32(rColor.GetGreen()));
- CPPUNIT_ASSERT_EQUAL(sal_Int32(0x26), sal_Int32(rColor.GetBlue()));
- }
-
- // any other operation other than DrawModeFlags::GrayBitmap is a noop
- {
- Bitmap aResultBitmap(vcl::drawmode::GetBitmap(aBmp, DrawModeFlags::NoFill));
- Bitmap::ScopedReadAccess pReadAccess(aResultBitmap);
-
- const BitmapColor& rColor = pReadAccess->GetColor(0, 0);
- CPPUNIT_ASSERT_EQUAL(sal_Int32(0x80), sal_Int32(rColor.GetRed()));
- CPPUNIT_ASSERT_EQUAL(sal_Int32(0x00), sal_Int32(rColor.GetGreen()));
- CPPUNIT_ASSERT_EQUAL(sal_Int32(0x00), sal_Int32(rColor.GetBlue()));
- }
-}
-
void VclDrawModeTest::testDrawModeBitmapEx()
{
const StyleSettings aStyleSettings;
diff --git a/vcl/qa/cppunit/outdev.cxx b/vcl/qa/cppunit/outdev.cxx
index efb4d402cda4..e9d9924a2ab8 100644
--- a/vcl/qa/cppunit/outdev.cxx
+++ b/vcl/qa/cppunit/outdev.cxx
@@ -35,6 +35,12 @@ public:
void testWindowBackgroundColor();
void testGetReadableFontColorPrinter();
void testGetReadableFontColorWindow();
+ void testDrawInvertedBitmap();
+ void testDrawBlackBitmap();
+ void testDrawWhiteBitmap();
+ void testDrawBitmap();
+ void testDrawScaleBitmap();
+ void testDrawScalePartBitmap();
void testDrawTransformedBitmapEx();
void testDrawTransformedBitmapExFlip();
void testRTL();
@@ -45,6 +51,12 @@ public:
CPPUNIT_TEST(testUseAfterDispose);
CPPUNIT_TEST(testPrinterBackgroundColor);
CPPUNIT_TEST(testWindowBackgroundColor);
+ CPPUNIT_TEST(testDrawInvertedBitmap);
+ CPPUNIT_TEST(testDrawBlackBitmap);
+ CPPUNIT_TEST(testDrawWhiteBitmap);
+ CPPUNIT_TEST(testDrawBitmap);
+ CPPUNIT_TEST(testDrawScaleBitmap);
+ CPPUNIT_TEST(testDrawScalePartBitmap);
CPPUNIT_TEST(testGetReadableFontColorPrinter);
CPPUNIT_TEST(testGetReadableFontColorWindow);
CPPUNIT_TEST(testDrawTransformedBitmapEx);
@@ -154,6 +166,161 @@ void VclOutdevTest::testUseAfterDispose()
pVDev->GetViewTransformation();
}
+void VclOutdevTest::testDrawInvertedBitmap()
+{
+ ScopedVclPtrInstance<VirtualDevice> pVDev;
+ Bitmap aBitmap(Size(16, 16), vcl::PixelFormat::N24_BPP);
+
+ GDIMetaFile aMtf;
+ aMtf.Record(pVDev.get());
+
+ pVDev->SetRasterOp(RasterOp::Invert);
+ 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::RASTEROP, pAction->GetType());
+ auto pRasterOpAction = static_cast<MetaRasterOpAction*>(pAction);
+ CPPUNIT_ASSERT_EQUAL(RasterOp::Invert, pRasterOpAction->GetRasterOp());
+
+ pAction = aMtf.GetAction(1);
+ 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());
+}
+
+void VclOutdevTest::testDrawBlackBitmap()
+{
+ ScopedVclPtrInstance<VirtualDevice> pVDev;
+ Bitmap aBitmap(Size(16, 16), vcl::PixelFormat::N24_BPP);
+
+ 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 = ((PushFlags::LINECOLOR | 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());
+}
+
+void 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 = ((PushFlags::LINECOLOR | 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());
+}
+
+void VclOutdevTest::testDrawBitmap()
+{
+ ScopedVclPtrInstance<VirtualDevice> pVDev;
+ Bitmap aBitmap(Size(16, 16), vcl::PixelFormat::N24_BPP);
+
+ GDIMetaFile aMtf;
+ aMtf.Record(pVDev.get());
+
+ 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::BMP, pAction->GetType());
+ auto pBmpAction = static_cast<MetaBmpAction*>(pAction);
+ CPPUNIT_ASSERT_EQUAL(Size(16, 16), pBmpAction->GetBitmap().GetSizePixel());
+ CPPUNIT_ASSERT_EQUAL(Point(0, 0), pBmpAction->GetPoint());
+}
+
+void VclOutdevTest::testDrawScaleBitmap()
+{
+ ScopedVclPtrInstance<VirtualDevice> pVDev;
+ Bitmap aBitmap(Size(16, 16), vcl::PixelFormat::N24_BPP);
+
+ GDIMetaFile aMtf;
+ aMtf.Record(pVDev.get());
+
+ pVDev->DrawBitmap(Point(5, 5), Size(10, 10), Point(0, 0), Size(10, 10), aBitmap,
+ MetaActionType::BMPSCALE);
+
+ MetaAction* pAction = aMtf.GetAction(0);
+ CPPUNIT_ASSERT_EQUAL(MetaActionType::BMPSCALE, pAction->GetType());
+ auto pBmpScaleAction = static_cast<MetaBmpScaleAction*>(pAction);
+ CPPUNIT_ASSERT_EQUAL(Size(16, 16), pBmpScaleAction->GetBitmap().GetSizePixel());
+ CPPUNIT_ASSERT_EQUAL(Point(5, 5), pBmpScaleAction->GetPoint());
+ CPPUNIT_ASSERT_EQUAL(Size(10, 10), pBmpScaleAction->GetSize());
+}
+
+void VclOutdevTest::testDrawScalePartBitmap()
+{
+ ScopedVclPtrInstance<VirtualDevice> pVDev;
+ Bitmap aBitmap(Size(16, 16), vcl::PixelFormat::N24_BPP);
+
+ GDIMetaFile aMtf;
+ aMtf.Record(pVDev.get());
+
+ pVDev->DrawBitmap(Point(0, 0), Size(10, 10), Point(5, 5), Size(10, 10), aBitmap,
+ MetaActionType::BMPSCALEPART);
+
+ MetaAction* pAction = aMtf.GetAction(0);
+ CPPUNIT_ASSERT_EQUAL(MetaActionType::BMPSCALEPART, pAction->GetType());
+ auto pBmpScalePartAction = static_cast<MetaBmpScalePartAction*>(pAction);
+ CPPUNIT_ASSERT_EQUAL(Size(16, 16), pBmpScalePartAction->GetBitmap().GetSizePixel());
+ CPPUNIT_ASSERT_EQUAL(Point(5, 5), pBmpScalePartAction->GetSrcPoint());
+ CPPUNIT_ASSERT_EQUAL(Size(10, 10), pBmpScalePartAction->GetSrcSize());
+ CPPUNIT_ASSERT_EQUAL(Point(0, 0), pBmpScalePartAction->GetDestPoint());
+ CPPUNIT_ASSERT_EQUAL(Size(10, 10), pBmpScalePartAction->GetDestSize());
+}
+
void VclOutdevTest::testDrawTransformedBitmapEx()
{
// Create a virtual device, and connect a metafile to it.
diff --git a/vcl/source/outdev/bitmap.cxx b/vcl/source/outdev/bitmap.cxx
index f80ccb0a52bf..bf0b6031afdf 100644
--- a/vcl/source/outdev/bitmap.cxx
+++ b/vcl/source/outdev/bitmap.cxx
@@ -83,7 +83,34 @@ void OutputDevice::DrawBitmap( const Point& rDestPt, const Size& rDestSize,
return;
}
- Bitmap aBmp(vcl::drawmode::GetBitmap(rBitmap, GetDrawMode()));
+ Bitmap aBmp( rBitmap );
+
+ if ( mnDrawMode & ( DrawModeFlags::BlackBitmap | DrawModeFlags::WhiteBitmap |
+ DrawModeFlags::GrayBitmap ) )
+ {
+ if ( mnDrawMode & ( DrawModeFlags::BlackBitmap | DrawModeFlags::WhiteBitmap ) )
+ {
+ sal_uInt8 cCmpVal;
+
+ if ( mnDrawMode & DrawModeFlags::BlackBitmap )
+ cCmpVal = 0;
+ else
+ cCmpVal = 255;
+
+ Color aCol( cCmpVal, cCmpVal, cCmpVal );
+ Push( PushFlags::LINECOLOR | PushFlags::FILLCOLOR );
+ SetLineColor( aCol );
+ SetFillColor( aCol );
+ DrawRect( tools::Rectangle( rDestPt, rDestSize ) );
+ Pop();
+ return;
+ }
+ else if( !aBmp.IsEmpty() )
+ {
+ if ( mnDrawMode & DrawModeFlags::GrayBitmap )
+ aBmp.Convert( BmpConversion::N8BitGreys );
+ }
+ }
if ( mpMetaFile )
{
diff --git a/vcl/source/rendercontext/drawmode.cxx b/vcl/source/rendercontext/drawmode.cxx
index 9b2b9236b92a..b1b85d33f52f 100644
--- a/vcl/source/rendercontext/drawmode.cxx
+++ b/vcl/source/rendercontext/drawmode.cxx
@@ -221,19 +221,6 @@ vcl::Font GetFont(vcl::Font const& rFont, DrawModeFlags nDrawMode,
return aFont;
}
-Bitmap GetBitmap(Bitmap const& rBitmap, DrawModeFlags nDrawMode)
-{
- Bitmap aBmp(rBitmap);
-
- if (nDrawMode & DrawModeFlags::GrayBitmap)
- {
- if (!aBmp.IsEmpty())
- aBmp.Convert(BmpConversion::N8BitGreys);
- }
-
- return aBmp;
-}
-
BitmapEx GetBitmapEx(BitmapEx const& rBitmapEx, DrawModeFlags nDrawMode)
{
BitmapEx aBmpEx(rBitmapEx);
More information about the Libreoffice-commits
mailing list