From 282c6ade098478d689bb8c12e1d62ea502c2df24 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Tue, 5 Aug 2025 18:49:40 +0200 Subject: [PATCH] BitmapEx->Bitmap in convertMetafileToBitmap now that Bitmap can handle transparency Change-Id: Iba7fc9164e7dfc0c84a5c13f8336cba0820a3ce7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188967 Tested-by: Jenkins Reviewed-by: Noel Grandin --- include/svx/svdpntv.hxx | 4 +- include/vcl/BitmapTools.hxx | 2 +- svx/source/inc/UnoGraphicExporter.hxx | 4 +- svx/source/svdraw/svdfmtf.cxx | 18 +++--- svx/source/svdraw/svdpntv.cxx | 10 +-- svx/source/unodraw/UnoGraphicExporter.cxx | 4 +- vcl/source/bitmap/BitmapTools.cxx | 77 +++++++++-------------- 7 files changed, 52 insertions(+), 67 deletions(-) diff --git a/include/svx/svdpntv.hxx b/include/svx/svdpntv.hxx index 4d641de4dc60..1a8fe08c8df1 100644 --- a/include/svx/svdpntv.hxx +++ b/include/svx/svdpntv.hxx @@ -65,10 +65,10 @@ public: class SdrPaintWindow; /** - * Helper to convert any GDIMetaFile to a good quality BitmapEx, + * Helper to convert any GDIMetaFile to a good quality Bitmap, * using default parameters and graphic::XPrimitive2DRenderer */ -BitmapEx convertMetafileToBitmapEx( +Bitmap convertMetafileToBitmap( const GDIMetaFile& rMtf, const basegfx::B2DRange& rTargetRange, const sal_uInt32 nMaximumQuadraticPixels); diff --git a/include/vcl/BitmapTools.hxx b/include/vcl/BitmapTools.hxx index b2cbc868d995..dc4d10091700 100644 --- a/include/vcl/BitmapTools.hxx +++ b/include/vcl/BitmapTools.hxx @@ -68,7 +68,7 @@ VCL_DLLPUBLIC ::Bitmap CanvasTransformBitmap( const ::Bitmap& rBitmap, ::basegfx::B2DRectangle const & rDestRect, ::basegfx::B2DHomMatrix const & rLocalTransform ); -VCL_DLLPUBLIC void DrawAlphaBitmapAndAlphaGradient(BitmapEx & rBitmapEx, bool bFixedTransparence, float fTransparence, const AlphaMask & rNewMask); +VCL_DLLPUBLIC void DrawAlphaBitmapAndAlphaGradient(Bitmap & rBitmap, bool bFixedTransparence, float fTransparence, const AlphaMask & rNewMask); VCL_DLLPUBLIC void DrawAndClipBitmap(const Point& rPos, const Size& rSize, const BitmapEx& rBitmap, BitmapEx & aBmpEx, basegfx::B2DPolyPolygon const & rClipPath); diff --git a/svx/source/inc/UnoGraphicExporter.hxx b/svx/source/inc/UnoGraphicExporter.hxx index 65014c4d7290..27930f04c144 100644 --- a/svx/source/inc/UnoGraphicExporter.hxx +++ b/svx/source/inc/UnoGraphicExporter.hxx @@ -21,14 +21,14 @@ #include -#include +#include #include class Size; class GDIMetaFile; class SdrObject; -BitmapEx GetBitmapFromMetaFile(const GDIMetaFile& rMtf, const Size* pSize); +Bitmap GetBitmapFromMetaFile(const GDIMetaFile& rMtf, const Size* pSize); Graphic SvxGetGraphicForShape(SdrObject& rShape); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/svdraw/svdfmtf.cxx b/svx/source/svdraw/svdfmtf.cxx index 3552b8b21525..440548ffc255 100644 --- a/svx/source/svdraw/svdfmtf.cxx +++ b/svx/source/svdraw/svdfmtf.cxx @@ -1513,9 +1513,9 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaFloatTransparentAction const & rAct) const tools::Rectangle aRect(rAct.GetPoint(),rAct.GetSize()); - // convert metafile sub-content to BitmapEx - BitmapEx aBitmapEx( - convertMetafileToBitmapEx( + // convert metafile sub-content to Bitmap + Bitmap aBitmap( + convertMetafileToBitmap( rMtf, vcl::unotools::b2DRectangleFromRectangle(aRect), 125000)); @@ -1569,7 +1569,7 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaFloatTransparentAction const & rAct) // gradient transparence ScopedVclPtrInstance< VirtualDevice > pVDev; - pVDev->SetOutputSizePixel(aBitmapEx.GetBitmap().GetSizePixel()); + pVDev->SetOutputSizePixel(aBitmap.GetSizePixel()); pVDev->DrawGradient(tools::Rectangle(Point(0, 0), pVDev->GetOutputSizePixel()), rGradient); aNewMask = AlphaMask(pVDev->GetBitmap(Point(0, 0), pVDev->GetOutputSizePixel())); @@ -1582,28 +1582,28 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaFloatTransparentAction const & rAct) if(bHasNewMask || bFixedTransparence) { - if(!aBitmapEx.IsAlpha()) + if(!aBitmap.HasAlpha()) { // no transparence yet, apply new one if(bFixedTransparence) { sal_uInt8 nTransparence(basegfx::fround(fTransparence * 255.0)); - aNewMask = AlphaMask(aBitmapEx.GetBitmap().GetSizePixel(), &nTransparence); + aNewMask = AlphaMask(aBitmap.GetSizePixel(), &nTransparence); } - aBitmapEx = BitmapEx(aBitmapEx.GetBitmap(), aNewMask); + aBitmap = Bitmap(BitmapEx(BitmapEx(aBitmap).GetBitmap(), aNewMask)); } else { - vcl::bitmap::DrawAlphaBitmapAndAlphaGradient(aBitmapEx, bFixedTransparence, fTransparence, aNewMask); + vcl::bitmap::DrawAlphaBitmapAndAlphaGradient(aBitmap, bFixedTransparence, fTransparence, aNewMask); } } // create and add object rtl::Reference pGraf = new SdrGrafObj( *mpModel, - aBitmapEx, + aBitmap, aRect); // for MetaFloatTransparentAction, do not use SetAttributes(...) diff --git a/svx/source/svdraw/svdpntv.cxx b/svx/source/svdraw/svdpntv.cxx index 53373de6acee..e2d26bc8c960 100644 --- a/svx/source/svdraw/svdpntv.cxx +++ b/svx/source/svdraw/svdpntv.cxx @@ -104,12 +104,12 @@ SvxViewChangedHint::SvxViewChangedHint() : SfxHint(SfxHintId::SvxViewChanged) } -BitmapEx convertMetafileToBitmapEx( +Bitmap convertMetafileToBitmap( const GDIMetaFile& rMtf, const basegfx::B2DRange& rTargetRange, const sal_uInt32 nMaximumQuadraticPixels) { - BitmapEx aBitmapEx; + Bitmap aBitmap; if(rMtf.GetActionSize()) { @@ -119,13 +119,13 @@ BitmapEx convertMetafileToBitmapEx( rTargetRange.getRange(), rTargetRange.getMinimum()), rMtf)); - aBitmapEx = drawinglayer::convertPrimitive2DContainerToBitmapEx( + aBitmap = Bitmap(drawinglayer::convertPrimitive2DContainerToBitmapEx( drawinglayer::primitive2d::Primitive2DContainer { aMtf }, rTargetRange, - nMaximumQuadraticPixels); + nMaximumQuadraticPixels)); } - return aBitmapEx; + return aBitmap; } SdrPaintView::SdrPaintView(SdrModel& rSdrModel, OutputDevice* pOut) diff --git a/svx/source/unodraw/UnoGraphicExporter.cxx b/svx/source/unodraw/UnoGraphicExporter.cxx index 7fc53a73d329..aff08a85e2c6 100644 --- a/svx/source/unodraw/UnoGraphicExporter.cxx +++ b/svx/source/unodraw/UnoGraphicExporter.cxx @@ -1271,7 +1271,7 @@ Sequence< OUString > SAL_CALL GraphicExporter::getSupportedMimeTypeNames( ) /** creates a bitmap that is optionally transparent from a metafile */ -BitmapEx GetBitmapFromMetaFile(const GDIMetaFile& rMtf, const Size* pSize) +Bitmap GetBitmapFromMetaFile(const GDIMetaFile& rMtf, const Size* pSize) { // use new primitive conversion tooling basegfx::B2DRange aRange(basegfx::B2DPoint(0.0, 0.0)); @@ -1302,7 +1302,7 @@ BitmapEx GetBitmapFromMetaFile(const GDIMetaFile& rMtf, const Size* pSize) nMaximumQuadraticPixels = 2048 * 2048; } - return convertMetafileToBitmapEx(rMtf, aRange, nMaximumQuadraticPixels); + return convertMetafileToBitmap(rMtf, aRange, nMaximumQuadraticPixels); } Graphic SvxGetGraphicForShape( SdrObject& rShape ) diff --git a/vcl/source/bitmap/BitmapTools.cxx b/vcl/source/bitmap/BitmapTools.cxx index a48270bab507..7e6f864f0e6d 100644 --- a/vcl/source/bitmap/BitmapTools.cxx +++ b/vcl/source/bitmap/BitmapTools.cxx @@ -520,67 +520,52 @@ Bitmap CanvasTransformBitmap( const Bitmap& rSrcBitmap, return aDstBitmap; } -void DrawAlphaBitmapAndAlphaGradient(BitmapEx & rBitmapEx, bool bFixedTransparence, float fTransparence, const AlphaMask & rNewMask) +// mix existing and new alpha mask +void DrawAlphaBitmapAndAlphaGradient(Bitmap & rBitmap, bool bFixedTransparence, float fTransparence, const AlphaMask & rNewMask) { - // mix existing and new alpha mask - AlphaMask aOldMask; + const double fFactor(1.0 / 255.0); + BitmapScopedWriteAccess pOld(rBitmap); + assert(pOld && "Got no access to old alpha mask (!)"); - if(rBitmapEx.IsAlpha()) + if(bFixedTransparence) { - aOldMask = rBitmapEx.GetAlphaMask(); - } + const double fOpNew(1.0 - fTransparence); - { - - BitmapScopedWriteAccess pOld(aOldMask); - - assert(pOld && "Got no access to old alpha mask (!)"); - - const double fFactor(1.0 / 255.0); - - if(bFixedTransparence) + for(tools::Long y(0),nHeight(pOld->Height()); y < nHeight; y++) { - const double fOpNew(1.0 - fTransparence); - - for(tools::Long y(0),nHeight(pOld->Height()); y < nHeight; y++) + Scanline pScanline = pOld->GetScanline( y ); + for(tools::Long x(0),nWidth(pOld->Width()); x < nWidth; x++) { - Scanline pScanline = pOld->GetScanline( y ); - for(tools::Long x(0),nWidth(pOld->Width()); x < nWidth; x++) - { - const double fOpOld(pOld->GetIndexFromData(pScanline, x) * fFactor); - const sal_uInt8 aCol(basegfx::fround((fOpOld * fOpNew) * 255.0)); + BitmapColor aCol = pOld->GetPixelFromData(pScanline, x); + const double fOpOld(aCol.GetAlpha() * fFactor); + aCol.SetAlpha(basegfx::fround((fOpOld * fOpNew) * 255.0)); - pOld->SetPixelOnData(pScanline, x, BitmapColor(aCol)); - } + pOld->SetPixelOnData(pScanline, x, aCol); } } - else + } + else + { + BitmapScopedReadAccess pNew(rNewMask); + assert(pNew && "Got no access to new alpha mask (!)"); + + assert(pOld->Width() == pNew->Width() && pOld->Height() == pNew->Height() && + "Alpha masks have different sizes (!)"); + + for(tools::Long y(0),nHeight(pOld->Height()); y < nHeight; y++) { - BitmapScopedReadAccess pNew(rNewMask); - - assert(pNew && "Got no access to new alpha mask (!)"); - - assert(pOld->Width() == pNew->Width() && pOld->Height() == pNew->Height() && - "Alpha masks have different sizes (!)"); - - for(tools::Long y(0),nHeight(pOld->Height()); y < nHeight; y++) + Scanline pScanline = pOld->GetScanline( y ); + for(tools::Long x(0),nWidth(pOld->Width()); x < nWidth; x++) { - Scanline pScanline = pOld->GetScanline( y ); - for(tools::Long x(0),nWidth(pOld->Width()); x < nWidth; x++) - { - const double fOpOld(pOld->GetIndexFromData(pScanline, x) * fFactor); - const double fOpNew(pNew->GetIndexFromData(pScanline, x) * fFactor); - const sal_uInt8 aCol(basegfx::fround((fOpOld * fOpNew) * 255.0)); + BitmapColor aCol = pOld->GetPixelFromData(pScanline, x); + const double fOpOld(aCol.GetAlpha() * fFactor); + const double fOpNew(pNew->GetIndexFromData(pScanline, x) * fFactor); + aCol.SetAlpha(basegfx::fround((fOpOld * fOpNew) * 255.0)); - pOld->SetPixelOnData(pScanline, x, BitmapColor(aCol)); - } + pOld->SetPixelOnData(pScanline, x, aCol); } } - } - - // apply combined bitmap as mask - rBitmapEx = BitmapEx(rBitmapEx.GetBitmap(), aOldMask); }