From 0680ba025822c20496b747c47b4dd8e1e43405ed Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 28 Aug 2025 14:19:21 +0200 Subject: [PATCH] BitmapEx->Bitmap in MetaBmpExAction now that Bitmap supports transparency Note that the SVM unit test changed because we no longer store some bitmaps as an 8-bit palette color layer and an 8-bit alpha layer. When those pass through Bitmap, they get converted to a 32-bit bitmap. Change-Id: Icbb30e291a7ed5c53319876637ae25e88a97d90d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190330 Reviewed-by: Noel Grandin Tested-by: Jenkins --- cppcanvas/source/mtfrenderer/implrenderer.cxx | 2 +- drawinglayer/source/tools/wmfemfhelper.cxx | 4 +- filter/source/svg/svgwriter.cxx | 6 +- include/vcl/metaact.hxx | 10 +- sd/source/ui/view/sdview3.cxx | 2 +- sfx2/source/doc/SfxRedactionHelper.cxx | 2 +- .../source/engine/shapes/gdimtftools.cxx | 10 +- svx/source/dialog/_bmpmask.cxx | 4 +- svx/source/svdraw/svdfmtf.cxx | 4 +- vcl/qa/cppunit/svm/svmtest.cxx | 20 +-- vcl/source/filter/eps/eps.cxx | 6 +- vcl/source/filter/svm/SvmReader.cxx | 6 +- vcl/source/filter/svm/SvmWriter.cxx | 6 +- vcl/source/filter/wmf/emfwr.cxx | 4 +- vcl/source/filter/wmf/wmfwr.cxx | 4 +- vcl/source/gdi/gdimetafiletools.cxx | 124 +++++++++++++++++- vcl/source/gdi/gdimtf.cxx | 4 +- vcl/source/gdi/metaact.cxx | 6 +- vcl/source/gdi/mtfxmldump.cxx | 4 +- vcl/source/gdi/pdfwriter_impl2.cxx | 8 +- vcl/source/outdev/bitmapex.cxx | 4 +- vcl/source/outdev/transparent.cxx | 4 +- 22 files changed, 179 insertions(+), 65 deletions(-) diff --git a/cppcanvas/source/mtfrenderer/implrenderer.cxx b/cppcanvas/source/mtfrenderer/implrenderer.cxx index 9f5003ba12ce..04b8dec944a8 100644 --- a/cppcanvas/source/mtfrenderer/implrenderer.cxx +++ b/cppcanvas/source/mtfrenderer/implrenderer.cxx @@ -2188,7 +2188,7 @@ namespace cppcanvas::internal std::shared_ptr pBmpAction( internal::BitmapActionFactory::createBitmapAction( - Bitmap(pAct->GetBitmapEx()), + pAct->GetBitmap(), rStates.getState().mapModeTransform * vcl::unotools::b2DPointFromPoint( pAct->GetPoint() ), rCanvas, diff --git a/drawinglayer/source/tools/wmfemfhelper.cxx b/drawinglayer/source/tools/wmfemfhelper.cxx index ec9ba943dc93..9e44dcfecadf 100644 --- a/drawinglayer/source/tools/wmfemfhelper.cxx +++ b/drawinglayer/source/tools/wmfemfhelper.cxx @@ -1952,9 +1952,9 @@ namespace wmfemfhelper { /** CHECKED, WORKS WELL: Simply same as MetaActionType::BMP */ const MetaBmpExAction* pA = static_cast(pAction); - const BitmapEx& rBitmapEx = pA->GetBitmapEx(); + const Bitmap& rBitmap = pA->GetBitmap(); - createBitmapPrimitive(Bitmap(rBitmapEx), pA->GetPoint(), rTargetHolders.Current(), rPropertyHolders.Current()); + createBitmapPrimitive(rBitmap, pA->GetPoint(), rTargetHolders.Current(), rPropertyHolders.Current()); break; } diff --git a/filter/source/svg/svgwriter.cxx b/filter/source/svg/svgwriter.cxx index dc0436422f0e..7b255e5f8c07 100644 --- a/filter/source/svg/svgwriter.cxx +++ b/filter/source/svg/svgwriter.cxx @@ -3909,9 +3909,9 @@ void SVGActionWriter::ImplWriteActions( const GDIMetaFile& rMtf, { const MetaBmpExAction* pA = static_cast(pAction); - ImplWriteBmp( pA->GetBitmapEx(), - pA->GetPoint(), mpVDev->PixelToLogic( pA->GetBitmapEx().GetSizePixel() ), - Point(), pA->GetBitmapEx().GetSizePixel(), pxShape ); + ImplWriteBmp( BitmapEx(pA->GetBitmap()), + pA->GetPoint(), mpVDev->PixelToLogic( pA->GetBitmap().GetSizePixel() ), + Point(), pA->GetBitmap().GetSizePixel(), pxShape ); } } break; diff --git a/include/vcl/metaact.hxx b/include/vcl/metaact.hxx index d9bd66c9db11..ce6c345e4c8e 100644 --- a/include/vcl/metaact.hxx +++ b/include/vcl/metaact.hxx @@ -787,7 +787,7 @@ class VCL_DLLPUBLIC MetaBmpExAction final : public MetaAction { private: - BitmapEx maBmpEx; + Bitmap maBmp; Point maPt; public: @@ -802,16 +802,16 @@ public: SAL_DLLPRIVATE virtual void Execute( OutputDevice* pOut ) override; SAL_DLLPRIVATE virtual rtl::Reference Clone() const override; - MetaBmpExAction( const Point& rPt, const BitmapEx& rBmpEx ); + MetaBmpExAction( const Point& rPt, const Bitmap& rBmp ); SAL_DLLPRIVATE virtual void Move( tools::Long nHorzMove, tools::Long nVertMove ) override; SAL_DLLPRIVATE virtual void Scale( double fScaleX, double fScaleY ) override; - const BitmapEx& GetBitmapEx() const { return maBmpEx; } + const Bitmap& GetBitmap() const { return maBmp; } const Point& GetPoint() const { return maPt; } - void SetBitmapEx(const BitmapEx& rBmpEx) { maBmpEx = rBmpEx; } + void SetBitmap(const Bitmap& rBmp) { maBmp = rBmp; } void SetPoint(const Point& rPt) { maPt = rPt; } - bool IsTransparent() const override { return GetBitmapEx().IsAlpha(); } + bool IsTransparent() const override { return GetBitmap().HasAlpha(); } }; class VCL_DLLPUBLIC MetaBmpExScaleAction final : public MetaAction diff --git a/sd/source/ui/view/sdview3.cxx b/sd/source/ui/view/sdview3.cxx index 5f4f6f5abc9c..da293e013bb8 100644 --- a/sd/source/ui/view/sdview3.cxx +++ b/sd/source/ui/view/sdview3.cxx @@ -214,7 +214,7 @@ bool View::InsertMetaFile( const TransferableDataHelper& rDataHelper, const Poin { MetaBmpExAction* pBmpExAction = dynamic_cast< MetaBmpExAction* >( pAction ); if( pBmpExAction ) - aGraphic = Graphic(Bitmap(pBmpExAction->GetBitmapEx()) ); + aGraphic = Graphic(pBmpExAction->GetBitmap()); } break; case MetaActionType::BMPEXSCALE: diff --git a/sfx2/source/doc/SfxRedactionHelper.cxx b/sfx2/source/doc/SfxRedactionHelper.cxx index 8e9b5f69dce2..4b748bb55e95 100644 --- a/sfx2/source/doc/SfxRedactionHelper.cxx +++ b/sfx2/source/doc/SfxRedactionHelper.cxx @@ -530,7 +530,7 @@ void SfxRedactionHelper::searchImagesInMetaFile( { MetaBmpExAction* pAction = static_cast(pCurrAct); aDestPt = pAction->GetPoint(); - aDestSz = pAction->GetBitmapEx().GetSizePixel(); + aDestSz = pAction->GetBitmap().GetSizePixel(); break; } diff --git a/slideshow/source/engine/shapes/gdimtftools.cxx b/slideshow/source/engine/shapes/gdimtftools.cxx index c476c4f56898..8ecdba8d3b6d 100644 --- a/slideshow/source/engine/shapes/gdimtftools.cxx +++ b/slideshow/source/engine/shapes/gdimtftools.cxx @@ -135,7 +135,7 @@ public: ::Bitmap aBmp( aGraphic.GetBitmap() ); - xMtf->AddAction( new MetaBmpExAction( Point(), BitmapEx(aBmp) ) ); + xMtf->AddAction( new MetaBmpExAction( Point(), aBmp ) ); xMtf->SetPrefSize( aBmp.GetPrefSize() ); xMtf->SetPrefMapMode( aBmp.GetPrefMapMode() ); @@ -375,11 +375,11 @@ bool getAnimationFromGraphic( VectorOfMtfAnimationFrames& o_rFrames, AlphaMask aAlphaMask(pVDevMask->GetBitmap(aEmptyPoint, aAnimSize)); pMtf->AddAction( new MetaBmpExAction( aEmptyPoint, - BitmapEx( + Bitmap(BitmapEx( pVDev->GetBitmap( aEmptyPoint, aAnimSize ), - aAlphaMask))); + aAlphaMask)))); } else { @@ -387,11 +387,11 @@ bool getAnimationFromGraphic( VectorOfMtfAnimationFrames& o_rFrames, aAlphaMask.Invert(); // convert from transparency to alpha pMtf->AddAction( new MetaBmpExAction( aEmptyPoint, - BitmapEx( + Bitmap(BitmapEx( pVDev->GetBitmap( aEmptyPoint, aAnimSize ), - aAlphaMask))); + aAlphaMask)))); } mnLoadedFrames = i+1; } diff --git a/svx/source/dialog/_bmpmask.cxx b/svx/source/dialog/_bmpmask.cxx index fc71042fd3a6..a5110a714324 100644 --- a/svx/source/dialog/_bmpmask.cxx +++ b/svx/source/dialog/_bmpmask.cxx @@ -841,9 +841,9 @@ GDIMetaFile SvxBmpMask::ImpMask( const GDIMetaFile& rMtf ) case MetaActionType::BMPEX: { MetaBmpExAction* pAct = static_cast(pAction); - const BitmapEx aBmpEx( Mask( Bitmap(pAct->GetBitmapEx()) ).GetBitmap() ); + const Bitmap aBmp( Mask( pAct->GetBitmap() ).GetBitmap() ); - pAct = new MetaBmpExAction( pAct->GetPoint(), aBmpEx ); + pAct = new MetaBmpExAction( pAct->GetPoint(), aBmp ); aMtf.AddAction( pAct ); } break; diff --git a/svx/source/svdraw/svdfmtf.cxx b/svx/source/svdraw/svdfmtf.cxx index 5f44de53a7ee..2e90ad200a1e 100644 --- a/svx/source/svdraw/svdfmtf.cxx +++ b/svx/source/svdraw/svdfmtf.cxx @@ -1129,11 +1129,11 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaBmpScaleAction const & rAct) void ImpSdrGDIMetaFileImport::DoAction(MetaBmpExAction const & rAct) { - tools::Rectangle aRect(rAct.GetPoint(),rAct.GetBitmapEx().GetSizePixel()); + tools::Rectangle aRect(rAct.GetPoint(),rAct.GetBitmap().GetSizePixel()); aRect.AdjustRight( 1 ); aRect.AdjustBottom( 1 ); rtl::Reference pGraf = new SdrGrafObj( *mpModel, - Bitmap(rAct.GetBitmapEx()), + rAct.GetBitmap(), aRect); // This action is not creating line and fill, set directly, do not use SetAttributes(..) diff --git a/vcl/qa/cppunit/svm/svmtest.cxx b/vcl/qa/cppunit/svm/svmtest.cxx index fd70153ce485..ba8f4188c76e 100644 --- a/vcl/qa/cppunit/svm/svmtest.cxx +++ b/vcl/qa/cppunit/svm/svmtest.cxx @@ -1067,11 +1067,11 @@ void SvmTest::checkBitmapExs(const GDIMetaFile& rMetaFile, bool bIsSvmFile) #else u"469f0820", // atypical RGBA little-endian config #endif - u"839e8cce", - u"236aaf55", // 1-bit - u"2949ccc7", // 4-bit color bitmap - same as 8-bit color bitmap - u"2949ccc7", - u"e5df8aad", + u"a17eb609", + u"7bd5c66f", // 1-bit + u"ec307070", // 4-bit color bitmap - same as 8-bit color bitmap + u"ec307070", + u"b6d8e2d5", #endif }; @@ -1080,7 +1080,7 @@ void SvmTest::checkBitmapExs(const GDIMetaFile& rMetaFile, bool bIsSvmFile) u"26bdebd04e5b18d685cea04982179e273ee3b659", u"f4f52df6ef965a2f0fbccbe6aca35ba3457cf9d5", u"7c953a06d34bbd38897f950d595df2880dbb0f75", - u"ca3e5cdde1c395e1ee76d339a5bf6e46fbac3249", + u"7b51ea0cc5da3bbaf9b9d3dc1cde8e5fa69dbdf2", u"8a1ebc46f890eb0879464c6e293bffd4ce7fadc0", // 1-bit u"23611fc9f484c23e45bbd457730adb8ab5355509", // 4-bit color bitmap - same as 8-bit color bitmap u"23611fc9f484c23e45bbd457730adb8ab5355509", @@ -1105,7 +1105,7 @@ void SvmTest::checkBitmapExs(const GDIMetaFile& rMetaFile, bool bIsSvmFile) {"x", u"6"}, {"y", u"6"}, {"crc", aExpectedCRC[3]}, {"transparenttype", u"bitmap"}, {"contentchecksum", aExpectedContentChecksum[3]} }); assertXPathAttrs(pDoc, "/metafile/bmpex[3]", { - {"x", u"0"}, {"y", u"6"}, {"transparenttype", u"bitmap"}, {"contentchecksum", aExpectedContentChecksum[4]}, {"pixelformat", u"8BPP"} + {"x", u"0"}, {"y", u"6"}, {"transparenttype", u"bitmap"}, {"contentchecksum", aExpectedContentChecksum[4]}, {"pixelformat", u"24BPP"} }); if (!bIsSvmFile) { @@ -1114,13 +1114,13 @@ void SvmTest::checkBitmapExs(const GDIMetaFile& rMetaFile, bool bIsSvmFile) }); } assertXPathAttrs(pDoc, "/metafile/bmpex[4]", { - {"x", u"2"}, {"y", u"6"}, {"crc", aExpectedCRC[5]}, {"transparenttype", u"bitmap"}, {"contentchecksum", aExpectedContentChecksum[5]}, {"pixelformat", u"8BPP"} + {"x", u"2"}, {"y", u"6"}, {"crc", aExpectedCRC[5]}, {"transparenttype", u"bitmap"}, {"contentchecksum", aExpectedContentChecksum[5]}, {"pixelformat", u"24BPP"} }); assertXPathAttrs(pDoc, "/metafile/bmpex[5]", { - {"x", u"0"}, {"y", u"8"}, {"crc", aExpectedCRC[6]}, {"transparenttype", u"bitmap"}, {"contentchecksum", aExpectedContentChecksum[6]}, {"pixelformat", u"8BPP"} + {"x", u"0"}, {"y", u"8"}, {"crc", aExpectedCRC[6]}, {"transparenttype", u"bitmap"}, {"contentchecksum", aExpectedContentChecksum[6]}, {"pixelformat", u"24BPP"} }); assertXPathAttrs(pDoc, "/metafile/bmpex[6]", { - {"x", u"2"}, {"y", u"8"}, {"crc", aExpectedCRC[7]}, {"transparenttype", u"bitmap"}, {"contentchecksum", aExpectedContentChecksum[7]}, {"pixelformat", u"8BPP"} + {"x", u"2"}, {"y", u"8"}, {"crc", aExpectedCRC[7]}, {"transparenttype", u"bitmap"}, {"contentchecksum", aExpectedContentChecksum[7]}, {"pixelformat", u"24BPP"} }); #else (void)bIsSvmFile; diff --git a/vcl/source/filter/eps/eps.cxx b/vcl/source/filter/eps/eps.cxx index 278ed22635f5..edcdf46fe21a 100644 --- a/vcl/source/filter/eps/eps.cxx +++ b/vcl/source/filter/eps/eps.cxx @@ -815,11 +815,11 @@ void PSWriter::ImplWriteActions( const GDIMetaFile& rMtf, VirtualDevice& rVDev ) case MetaActionType::BMPEX : { - BitmapEx aBitmapEx( static_cast(pMA)->GetBitmapEx() ); - Bitmap aBitmap( aBitmapEx.GetBitmap() ); + Bitmap aBitmapEx( static_cast(pMA)->GetBitmap() ); + Bitmap aBitmap( aBitmapEx.CreateColorBitmap() ); if ( mbGrayScale ) aBitmap.Convert( BmpConversion::N8BitGreys ); - const AlphaMask& aMask( aBitmapEx.GetAlphaMask() ); + const AlphaMask aMask( aBitmapEx.CreateAlphaMask() ); Point aPoint( static_cast(pMA)->GetPoint() ); Size aSize( rVDev.PixelToLogic( aBitmap.GetSizePixel() ) ); ImplBmp( &aBitmap, &aMask, aPoint, aSize.Width(), aSize.Height() ); diff --git a/vcl/source/filter/svm/SvmReader.cxx b/vcl/source/filter/svm/SvmReader.cxx index 01a9dd30d6ea..250b46830e7f 100644 --- a/vcl/source/filter/svm/SvmReader.cxx +++ b/vcl/source/filter/svm/SvmReader.cxx @@ -937,14 +937,14 @@ rtl::Reference SvmReader::BmpExHandler() rtl::Reference pAction(new MetaBmpExAction); VersionCompatRead aCompat(mrStream); - BitmapEx aBmpEx; - ReadDIBBitmapEx(aBmpEx, mrStream); + Bitmap aBmp; + ReadDIBBitmapEx(aBmp, mrStream); TypeSerializer aSerializer(mrStream); Point aPoint; aSerializer.readPoint(aPoint); pAction->SetPoint(aPoint); - pAction->SetBitmapEx(aBmpEx); + pAction->SetBitmap(aBmp); return pAction; } diff --git a/vcl/source/filter/svm/SvmWriter.cxx b/vcl/source/filter/svm/SvmWriter.cxx index 0720d4b27f9c..2e141e2f407c 100644 --- a/vcl/source/filter/svm/SvmWriter.cxx +++ b/vcl/source/filter/svm/SvmWriter.cxx @@ -171,7 +171,7 @@ BitmapChecksum SvmWriter::GetChecksum(const GDIMetaFile& rMetaFile) ShortToSVBT16(static_cast(pAct->GetType()), aBT16); nCrc = rtl_crc32(nCrc, aBT16, 2); - BCToBCOA(pAct->GetBitmapEx().GetChecksum(), aBCOA); + BCToBCOA(pAct->GetBitmap().GetChecksum(), aBCOA); nCrc = rtl_crc32(nCrc, aBCOA, BITMAP_CHECKSUM_SIZE); Int32ToSVBT32(pAct->GetPoint().X(), aBT32); @@ -1103,11 +1103,11 @@ void SvmWriter::BmpScalePartHandler(const MetaBmpScalePartAction* pAction) void SvmWriter::BmpExHandler(const MetaBmpExAction* pAction) { - if (!pAction->GetBitmapEx().GetBitmap().IsEmpty()) + if (!pAction->GetBitmap().CreateColorBitmap().IsEmpty()) { mrStream.WriteUInt16(static_cast(pAction->GetType())); VersionCompatWrite aCompat(mrStream, 1); - WriteDIBBitmapEx(pAction->GetBitmapEx(), mrStream); + WriteDIBBitmapEx(pAction->GetBitmap(), mrStream); TypeSerializer aSerializer(mrStream); aSerializer.writePoint(pAction->GetPoint()); } diff --git a/vcl/source/filter/wmf/emfwr.cxx b/vcl/source/filter/wmf/emfwr.cxx index 3572980f20b5..ce4bd562a565 100644 --- a/vcl/source/filter/wmf/emfwr.cxx +++ b/vcl/source/filter/wmf/emfwr.cxx @@ -1288,8 +1288,8 @@ void EMFWriter::ImplWrite( const GDIMetaFile& rMtf ) case MetaActionType::BMPEX: { const MetaBmpExAction* pA = static_cast(pAction); - Bitmap aBmp( pA->GetBitmapEx().GetBitmap() ); - AlphaMask aMsk( pA->GetBitmapEx().GetAlphaMask() ); + Bitmap aBmp( pA->GetBitmap().CreateColorBitmap() ); + AlphaMask aMsk( pA->GetBitmap().CreateAlphaMask() ); if( !aMsk.IsEmpty() ) { diff --git a/vcl/source/filter/wmf/wmfwr.cxx b/vcl/source/filter/wmf/wmfwr.cxx index 6f42017321ed..3558b60057cb 100644 --- a/vcl/source/filter/wmf/wmfwr.cxx +++ b/vcl/source/filter/wmf/wmfwr.cxx @@ -1244,8 +1244,8 @@ void WMFWriter::WriteRecords( const GDIMetaFile & rMTF ) case MetaActionType::BMPEX: { const MetaBmpExAction* pA = static_cast(pMA); - Bitmap aBmp( pA->GetBitmapEx().GetBitmap() ); - AlphaMask aMsk( pA->GetBitmapEx().GetAlphaMask() ); + Bitmap aBmp( pA->GetBitmap().CreateColorBitmap() ); + AlphaMask aMsk( pA->GetBitmap().CreateAlphaMask() ); if( !aMsk.IsEmpty() ) { diff --git a/vcl/source/gdi/gdimetafiletools.cxx b/vcl/source/gdi/gdimetafiletools.cxx index 40d7817afcb0..998dea176b9a 100644 --- a/vcl/source/gdi/gdimetafiletools.cxx +++ b/vcl/source/gdi/gdimetafiletools.cxx @@ -231,6 +231,120 @@ namespace return true; } + bool handleBitmapContent( + const basegfx::B2DPolyPolygon& rClip, + const Point& rPoint, + const Size& rSize, + const Bitmap& rBitmap, + GDIMetaFile& rTarget) + { + if(!rSize.Width() || !rSize.Height() || rBitmap.IsEmpty()) + { + // bitmap or size is empty + return true; + } + + const basegfx::B2DRange aLogicBitmapRange( + rPoint.X(), rPoint.Y(), + rPoint.X() + rSize.Width(), rPoint.Y() + rSize.Height()); + const basegfx::B2DPolyPolygon aClipOfBitmap( + basegfx::utils::clipPolyPolygonOnRange( + rClip, + aLogicBitmapRange, + true, + false)); // stroke + + if(!aClipOfBitmap.count()) + { + // outside clip region + return true; + } + + // inside or overlapping. Use area to find out if it is completely + // covering (inside) or overlapping + const double fClipArea(basegfx::utils::getArea(aClipOfBitmap)); + const double fBitmapArea( + aLogicBitmapRange.getWidth() * aLogicBitmapRange.getWidth() + + aLogicBitmapRange.getHeight() * aLogicBitmapRange.getHeight()); + const double fFactor(fClipArea / fBitmapArea); + + if(basegfx::fTools::more(fFactor, 1.0 - 0.001)) + { + // completely covering (with 0.1% tolerance) + return false; + } + + // needs clipping (with 0.1% tolerance). Prepare VirtualDevice + // in pixel mode for alpha channel painting (black is transparent, + // white to paint 100% opacity) + const Size aSizePixel(rBitmap.GetSizePixel()); + ScopedVclPtrInstance< VirtualDevice > aVDev; + + aVDev->SetOutputSizePixel(aSizePixel); + aVDev->EnableMapMode(false); + aVDev->SetFillColor( COL_WHITE); + aVDev->SetLineColor(); + + if(rBitmap.HasAlpha()) + { + // use given alpha channel + aVDev->DrawBitmap(Point(0, 0), rBitmap.CreateAlphaMask().GetBitmap()); + } + else + { + // reset alpha channel + aVDev->SetBackground(Wallpaper(COL_BLACK)); + aVDev->Erase(); + } + + // transform polygon from clipping to pixel coordinates + basegfx::B2DPolyPolygon aPixelPoly(aClipOfBitmap); + basegfx::B2DHomMatrix aTransform; + + aTransform.translate(-aLogicBitmapRange.getMinX(), -aLogicBitmapRange.getMinY()); + aTransform.scale( + static_cast< double >(aSizePixel.Width()) / aLogicBitmapRange.getWidth(), + static_cast< double >(aSizePixel.Height()) / aLogicBitmapRange.getHeight()); + aPixelPoly.transform(aTransform); + + // to fill the non-covered parts, use the Xor fill rule of + // tools::PolyPolygon painting. Start with an all-covering polygon and + // add the clip polygon one + basegfx::B2DPolyPolygon aInvertPixelPoly; + + aInvertPixelPoly.append( + basegfx::utils::createPolygonFromRect( + basegfx::B2DRange( + 0.0, 0.0, + aSizePixel.Width(), aSizePixel.Height()))); + aInvertPixelPoly.append(aPixelPoly); + + // paint as alpha + aVDev->DrawPolyPolygon(aInvertPixelPoly); + + // get created alpha mask and set defaults + AlphaMask aAlpha( + aVDev->GetBitmap( + Point(0, 0), + aSizePixel)); + + aAlpha.SetPrefSize(rBitmap.GetPrefSize()); + aAlpha.SetPrefMapMode(rBitmap.GetPrefMapMode()); + + // add new action replacing the old one + rTarget.AddAction( + new MetaBmpExScaleAction( + Point( + basegfx::fround(aLogicBitmapRange.getMinX()), + basegfx::fround(aLogicBitmapRange.getMinY())), + Size( + basegfx::fround(aLogicBitmapRange.getWidth()), + basegfx::fround(aLogicBitmapRange.getHeight())), + BitmapEx(rBitmap.CreateColorBitmap(), aAlpha))); + + return true; + } + void addSvtGraphicStroke(const SvtGraphicStroke& rStroke, GDIMetaFile& rTarget) { // write SvtGraphicFill @@ -705,26 +819,26 @@ void clipMetafileContentAgainstOwnRegions(GDIMetaFile& rSource) case MetaActionType::BMPEX : { const MetaBmpExAction* pA = static_cast< const MetaBmpExAction* >(pAction); - const BitmapEx& rBitmapEx = pA->GetBitmapEx(); + const Bitmap& rBitmap = pA->GetBitmap(); // the logical size depends on the PrefSize of the given bitmap in // combination with the current MapMode - Size aLogicalSize(rBitmapEx.GetPrefSize()); + Size aLogicalSize(rBitmap.GetPrefSize()); - if(MapUnit::MapPixel == rBitmapEx.GetPrefMapMode().GetMapUnit()) + if(MapUnit::MapPixel == rBitmap.GetPrefMapMode().GetMapUnit()) { aLogicalSize = Application::GetDefaultDevice()->PixelToLogic(aLogicalSize, aMapModes.back()); } else { - aLogicalSize = OutputDevice::LogicToLogic(aLogicalSize, rBitmapEx.GetPrefMapMode(), aMapModes.back()); + aLogicalSize = OutputDevice::LogicToLogic(aLogicalSize, rBitmap.GetPrefMapMode(), aMapModes.back()); } bDone = handleBitmapContent( aClips.back(), pA->GetPoint(), aLogicalSize, - rBitmapEx, + rBitmap, aTarget); break; } diff --git a/vcl/source/gdi/gdimtf.cxx b/vcl/source/gdi/gdimtf.cxx index 3a58ce2b6fc6..cea9af4e6c88 100644 --- a/vcl/source/gdi/gdimtf.cxx +++ b/vcl/source/gdi/gdimtf.cxx @@ -1625,7 +1625,7 @@ tools::Rectangle GDIMetaFile::GetBoundRect( OutputDevice& i_rReference ) const case MetaActionType::BMPEX: { MetaBmpExAction* pAct = static_cast(pAction); - tools::Rectangle aRect( pAct->GetPoint(), aMapVDev->PixelToLogic( pAct->GetBitmapEx().GetSizePixel() ) ); + tools::Rectangle aRect( pAct->GetPoint(), aMapVDev->PixelToLogic( pAct->GetBitmap().GetSizePixel() ) ); ImplActionBounds( aBound, OutputDevice::LogicToLogic( aRect, aMapVDev->GetMapMode(), GetPrefMapMode() ), aClipStack ); } break; @@ -2225,7 +2225,7 @@ sal_uLong GDIMetaFile::GetSizeBytes() const case MetaActionType::BMPSCALE: nSizeBytes += static_cast( pAction )->GetBitmap().GetSizeBytes(); break; case MetaActionType::BMPSCALEPART: nSizeBytes += static_cast( pAction )->GetBitmap().GetSizeBytes(); break; - case MetaActionType::BMPEX: nSizeBytes += static_cast( pAction )->GetBitmapEx().GetSizeBytes(); break; + case MetaActionType::BMPEX: nSizeBytes += static_cast( pAction )->GetBitmap().GetSizeBytes(); break; case MetaActionType::BMPEXSCALE: nSizeBytes += static_cast( pAction )->GetBitmapEx().GetSizeBytes(); break; case MetaActionType::BMPEXSCALEPART: nSizeBytes += static_cast( pAction )->GetBitmapEx().GetSizeBytes(); break; diff --git a/vcl/source/gdi/metaact.cxx b/vcl/source/gdi/metaact.cxx index 384817cc0804..e2a75e38b50e 100644 --- a/vcl/source/gdi/metaact.cxx +++ b/vcl/source/gdi/metaact.cxx @@ -1067,15 +1067,15 @@ MetaBmpExAction::MetaBmpExAction() : MetaBmpExAction::~MetaBmpExAction() {} -MetaBmpExAction::MetaBmpExAction( const Point& rPt, const BitmapEx& rBmpEx ) : +MetaBmpExAction::MetaBmpExAction( const Point& rPt, const Bitmap& rBmp ) : MetaAction ( MetaActionType::BMPEX ), - maBmpEx ( rBmpEx ), + maBmp ( rBmp ), maPt ( rPt ) {} void MetaBmpExAction::Execute( OutputDevice* pOut ) { - pOut->DrawBitmapEx( maPt, maBmpEx ); + pOut->DrawBitmapEx( maPt, maBmp ); } rtl::Reference MetaBmpExAction::Clone() const diff --git a/vcl/source/gdi/mtfxmldump.cxx b/vcl/source/gdi/mtfxmldump.cxx index 24cd96ce5964..6c418c0f362b 100644 --- a/vcl/source/gdi/mtfxmldump.cxx +++ b/vcl/source/gdi/mtfxmldump.cxx @@ -1004,8 +1004,8 @@ void MetafileXmlDump::writeXml(const GDIMetaFile& rMetaFile, tools::XmlWriter& r auto pMeta = static_cast(pAction); rWriter.startElement(sCurrentElementTag); writePoint(rWriter, pMeta->GetPoint()); - Bitmap aBitmap = pMeta->GetBitmapEx().GetBitmap(); - rWriter.attribute("transparenttype", convertBitmapExTransparentType(pMeta->GetBitmapEx())); + Bitmap aBitmap = pMeta->GetBitmap().CreateColorBitmap(); + rWriter.attribute("transparenttype", convertBitmapTransparentType(pMeta->GetBitmap())); writeBitmap(rWriter, aBitmap); rWriter.endElement(); } diff --git a/vcl/source/gdi/pdfwriter_impl2.cxx b/vcl/source/gdi/pdfwriter_impl2.cxx index 0c8b6fc19322..40a1a4154c78 100644 --- a/vcl/source/gdi/pdfwriter_impl2.cxx +++ b/vcl/source/gdi/pdfwriter_impl2.cxx @@ -764,11 +764,11 @@ void PDFWriterImpl::playMetafile( const GDIMetaFile& i_rMtf, vcl::PDFExtOutDevDa case MetaActionType::BMPEX: { const MetaBmpExAction* pA = static_cast(pAction); - BitmapEx aBitmapEx( pA->GetBitmapEx() ); - Size aSize( OutputDevice::LogicToLogic( aBitmapEx.GetPrefSize(), - aBitmapEx.GetPrefMapMode(), pDummyVDev->GetMapMode() ) ); + Bitmap aBitmap( pA->GetBitmap() ); + Size aSize( OutputDevice::LogicToLogic( aBitmap.GetPrefSize(), + aBitmap.GetPrefMapMode(), pDummyVDev->GetMapMode() ) ); Graphic aGraphic = i_pOutDevData ? i_pOutDevData->GetCurrentGraphic() : Graphic(); - implWriteBitmapEx( pA->GetPoint(), aSize, Bitmap(aBitmapEx), aGraphic, pDummyVDev, i_rContext ); + implWriteBitmapEx( pA->GetPoint(), aSize, aBitmap, aGraphic, pDummyVDev, i_rContext ); } break; diff --git a/vcl/source/outdev/bitmapex.cxx b/vcl/source/outdev/bitmapex.cxx index fd97b1afe415..305fd442152b 100644 --- a/vcl/source/outdev/bitmapex.cxx +++ b/vcl/source/outdev/bitmapex.cxx @@ -172,7 +172,7 @@ void OutputDevice::DrawBitmapEx( const Point& rDestPt, const Size& rDestSize, switch(nAction) { case MetaActionType::BMPEX: - mpMetaFile->AddAction(new MetaBmpExAction(rDestPt, aBmpEx)); + mpMetaFile->AddAction(new MetaBmpExAction(rDestPt, Bitmap(aBmpEx))); break; case MetaActionType::BMPEXSCALE: @@ -232,7 +232,7 @@ void OutputDevice::DrawBitmapEx( const Point& rDestPt, const Size& rDestSize, switch(nAction) { case MetaActionType::BMPEX: - mpMetaFile->AddAction(new MetaBmpExAction(rDestPt, aBmpEx)); + mpMetaFile->AddAction(new MetaBmpExAction(rDestPt, Bitmap(aBmpEx))); break; case MetaActionType::BMPEXSCALE: diff --git a/vcl/source/outdev/transparent.cxx b/vcl/source/outdev/transparent.cxx index 9310182d611f..0e97fd1edcb1 100644 --- a/vcl/source/outdev/transparent.cxx +++ b/vcl/source/outdev/transparent.cxx @@ -820,7 +820,7 @@ void ImplConvertTransparentAction( GDIMetaFile& o_rMtf, switch (rAct.GetType()) { case MetaActionType::BMPEX: - aBmpEx = static_cast(rAct).GetBitmapEx(); + aBmpEx = static_cast(rAct).GetBitmap(); break; case MetaActionType::BMPEXSCALE: @@ -1088,7 +1088,7 @@ tools::Rectangle ImplCalcActionBounds( const MetaAction& rAct, const OutputDevic case MetaActionType::BMPEX: aActionBounds = tools::Rectangle( static_cast(rAct).GetPoint(), - rOut.PixelToLogic( static_cast(rAct).GetBitmapEx().GetSizePixel() ) ); + rOut.PixelToLogic( static_cast(rAct).GetBitmap().GetSizePixel() ) ); break; case MetaActionType::BMPEXSCALE: