canvas/source/vcl/canvashelper.cxx                        |    8 +++----
 drawinglayer/source/processor2d/cairopixelprocessor2d.cxx |    2 -
 include/vcl/bitmap.hxx                                    |    5 ++++
 svx/source/dialog/_bmpmask.cxx                            |    6 ++---
 svx/source/svdraw/svdfmtf.cxx                             |    2 -
 sw/source/core/layout/paintfrm.cxx                        |   16 +++++++-------
 vcl/source/bitmap/bitmap.cxx                              |   15 +++++++++++++
 vcl/source/gdi/pdfwriter_impl.cxx                         |    4 +--
 vcl/workben/vcldemo.cxx                                   |    2 -
 9 files changed, 40 insertions(+), 20 deletions(-)

New commits:
commit 6b61142487387f365257e75422c34c442ab4e069
Author:     Noel Grandin <[email protected]>
AuthorDate: Tue Aug 12 12:45:08 2025 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Wed Aug 13 11:49:33 2025 +0200

    new methods on Bitmap to avoid going via BitmapEx
    
    have new methods for extracting a color bitmap
    and an alpha mask from Bitmap. Avoids going via
    BitmapEx.
    
    Change-Id: I8c613008cfb8ecc0a57d1d983b6961798db52632
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189470
    Reviewed-by: Noel Grandin <[email protected]>
    Tested-by: Jenkins

diff --git a/canvas/source/vcl/canvashelper.cxx 
b/canvas/source/vcl/canvashelper.cxx
index 373f0d4dcd7e..bda1abecef21 100644
--- a/canvas/source/vcl/canvashelper.cxx
+++ b/canvas/source/vcl/canvashelper.cxx
@@ -719,9 +719,9 @@ namespace vclcanvas
                         // the alpha mask needs to be inverted. Note: when
                         // testing tdf#157790, this code only gets executed
                         // when Skia is enabled.
-                        AlphaMask aAlpha( BitmapEx(aBmp).GetAlphaMask() );
+                        AlphaMask aAlpha( aBmp.CreateAlphaMask() );
                         aAlpha.Invert();
-                        aBmp = Bitmap(BitmapEx( BitmapEx(aBmp).GetBitmap(), 
aAlpha ));
+                        aBmp = Bitmap(BitmapEx( aBmp.CreateColorBitmap(), 
aAlpha ));
 
                         // HACK. Normally, CanvasHelper does not care about
                         // actually what mp2ndOutDev is...  well, here we do &
@@ -839,9 +839,9 @@ namespace vclcanvas
                         // the alpha mask needs to be inverted. Note: when
                         // testing tdf#157790, this code only gets executed
                         // when Skia is disabled.
-                        AlphaMask aAlpha( BitmapEx(aBmp).GetAlphaMask() );
+                        AlphaMask aAlpha( aBmp.CreateAlphaMask() );
                         aAlpha.Invert();
-                        BitmapEx a2ndBmpEx( BitmapEx(aBmp).GetBitmap(), aAlpha 
);
+                        BitmapEx a2ndBmpEx( aBmp.CreateColorBitmap(), aAlpha );
                         p2ndGrfObj = std::make_shared<GraphicObject>( 
a2ndBmpEx );
                     }
 
diff --git a/drawinglayer/source/processor2d/cairopixelprocessor2d.cxx 
b/drawinglayer/source/processor2d/cairopixelprocessor2d.cxx
index e72c5a5d8d66..390a14e4dc20 100644
--- a/drawinglayer/source/processor2d/cairopixelprocessor2d.cxx
+++ b/drawinglayer/source/processor2d/cairopixelprocessor2d.cxx
@@ -2136,7 +2136,7 @@ void CairoPixelProcessor2D::processMarkerArrayPrimitive2D(
             aBitmap.Erase(Color(aReplacementColor));
 
             if (rMarker.HasAlpha())
-                aBitmapEx = BitmapEx(aBitmap, 
BitmapEx(rMarker).GetAlphaMask());
+                aBitmapEx = BitmapEx(aBitmap, rMarker.CreateAlphaMask());
             else
                 aBitmapEx = BitmapEx(aBitmap);
         }
diff --git a/include/vcl/bitmap.hxx b/include/vcl/bitmap.hxx
index c40b563953e1..e21c5bc519b4 100644
--- a/include/vcl/bitmap.hxx
+++ b/include/vcl/bitmap.hxx
@@ -141,6 +141,11 @@ public:
     // does this bitmap have alpha information?
     inline bool             HasAlpha() const { return getPixelFormat() == 
vcl::PixelFormat::N32_BPP; }
 
+    /** return the alpha data, copied into an AlphaMask. Will assert if this 
Bitmap has no alpha. */
+    AlphaMask               CreateAlphaMask() const;
+    /** return the color data, copied into a new Bitmap. If this Bitmap does 
not have alpha, will return a copy of itself. */
+    Bitmap                  CreateColorBitmap() const;
+
     /** get system dependent bitmap data
 
         @param rData
diff --git a/svx/source/dialog/_bmpmask.cxx b/svx/source/dialog/_bmpmask.cxx
index e3b9c2795f62..4a3de2955f8e 100644
--- a/svx/source/dialog/_bmpmask.cxx
+++ b/svx/source/dialog/_bmpmask.cxx
@@ -612,12 +612,12 @@ Bitmap SvxBmpMask::ImpMaskTransparent( const Bitmap& 
rBitmap, const Color& rColo
 {
     EnterWait();
 
-    AlphaMask   aMask( BitmapEx(rBitmap).GetBitmap().CreateAlphaMask( rColor, 
nTol ) );
+    AlphaMask   aMask( rBitmap.CreateColorBitmap().CreateAlphaMask( rColor, 
nTol ) );
 
     if( rBitmap.HasAlpha() )
-        aMask.AlphaCombineOr( BitmapEx(rBitmap).GetAlphaMask() );
+        aMask.AlphaCombineOr( rBitmap.CreateAlphaMask() );
 
-    Bitmap aBmp(BitmapEx( BitmapEx(rBitmap).GetBitmap(), aMask ));
+    Bitmap aBmp(BitmapEx( rBitmap.CreateColorBitmap(), aMask ));
     LeaveWait();
 
     return aBmp;
diff --git a/svx/source/svdraw/svdfmtf.cxx b/svx/source/svdraw/svdfmtf.cxx
index 440548ffc255..737f9d7dbf0c 100644
--- a/svx/source/svdraw/svdfmtf.cxx
+++ b/svx/source/svdraw/svdfmtf.cxx
@@ -1592,7 +1592,7 @@ void 
ImpSdrGDIMetaFileImport::DoAction(MetaFloatTransparentAction const & rAct)
                 aNewMask = AlphaMask(aBitmap.GetSizePixel(), &nTransparence);
             }
 
-            aBitmap = Bitmap(BitmapEx(BitmapEx(aBitmap).GetBitmap(), 
aNewMask));
+            aBitmap = Bitmap(BitmapEx(aBitmap.CreateColorBitmap(), aNewMask));
         }
         else
         {
diff --git a/sw/source/core/layout/paintfrm.cxx 
b/sw/source/core/layout/paintfrm.cxx
index eed388c8f408..f1d8a7984a86 100644
--- a/sw/source/core/layout/paintfrm.cxx
+++ b/sw/source/core/layout/paintfrm.cxx
@@ -6401,42 +6401,42 @@ static void lcl_paintBitmapExToRect(vcl::RenderContext 
*pOut, const Point& aPoin
     {
         aShadowColor = _pViewShell->GetViewOptions()->GetShadowColor();
 
-        AlphaMask aMask( BitmapEx(shadowMask.getBottomRight()).GetBitmap() );
+        AlphaMask aMask( shadowMask.getBottomRight().CreateColorBitmap() );
         Bitmap aFilledSquare(aMask.GetSizePixel(), vcl::PixelFormat::N24_BPP);
         aFilledSquare.Erase( aShadowColor );
         aPageBottomRightShadow = BitmapEx( aFilledSquare, aMask );
 
-        aMask = AlphaMask( BitmapEx(shadowMask.getBottomLeft()).GetBitmap() );
+        aMask = AlphaMask( shadowMask.getBottomLeft().CreateColorBitmap() );
         aFilledSquare = Bitmap(aMask.GetSizePixel(), 
vcl::PixelFormat::N24_BPP);
         aFilledSquare.Erase( aShadowColor );
         aPageBottomLeftShadow = BitmapEx( aFilledSquare, aMask );
 
-        aMask = AlphaMask( BitmapEx(shadowMask.getBottom()).GetBitmap() );
+        aMask = AlphaMask( shadowMask.getBottom().CreateColorBitmap() );
         aFilledSquare = Bitmap(aMask.GetSizePixel(), 
vcl::PixelFormat::N24_BPP);
         aFilledSquare.Erase( aShadowColor );
         aPageBottomShadow = BitmapEx( aFilledSquare, aMask );
 
-        aMask = AlphaMask( BitmapEx(shadowMask.getTop()).GetBitmap() );
+        aMask = AlphaMask( shadowMask.getTop().CreateColorBitmap() );
         aFilledSquare = Bitmap(aMask.GetSizePixel(), 
vcl::PixelFormat::N24_BPP);
         aFilledSquare.Erase( aShadowColor );
         aPageTopShadow = BitmapEx( aFilledSquare, aMask );
 
-        aMask = AlphaMask( BitmapEx(shadowMask.getTopRight()).GetBitmap() );
+        aMask = AlphaMask( shadowMask.getTopRight().CreateColorBitmap() );
         aFilledSquare = Bitmap(aMask.GetSizePixel(), 
vcl::PixelFormat::N24_BPP);
         aFilledSquare.Erase( aShadowColor );
         aPageTopRightShadow = BitmapEx( aFilledSquare, aMask );
 
-        aMask = AlphaMask( BitmapEx(shadowMask.getRight()).GetBitmap() );
+        aMask = AlphaMask( shadowMask.getRight().CreateColorBitmap() );
         aFilledSquare = Bitmap(aMask.GetSizePixel(), 
vcl::PixelFormat::N24_BPP);
         aFilledSquare.Erase( aShadowColor );
         aPageRightShadow = BitmapEx( aFilledSquare, aMask );
 
-        aMask = AlphaMask( BitmapEx(shadowMask.getTopLeft()).GetBitmap() );
+        aMask = AlphaMask( shadowMask.getTopLeft().CreateColorBitmap() );
         aFilledSquare = Bitmap(aMask.GetSizePixel(), 
vcl::PixelFormat::N24_BPP);
         aFilledSquare.Erase( aShadowColor );
         aPageTopLeftShadow = BitmapEx( aFilledSquare, aMask );
 
-        aMask = AlphaMask( BitmapEx(shadowMask.getLeft()).GetBitmap() );
+        aMask = AlphaMask( shadowMask.getLeft().CreateColorBitmap() );
         aFilledSquare = Bitmap(aMask.GetSizePixel(), 
vcl::PixelFormat::N24_BPP);
         aFilledSquare.Erase( aShadowColor );
         aPageLeftShadow = BitmapEx( aFilledSquare, aMask );
diff --git a/vcl/source/bitmap/bitmap.cxx b/vcl/source/bitmap/bitmap.cxx
index cce71645c91c..635a738e5d4b 100644
--- a/vcl/source/bitmap/bitmap.cxx
+++ b/vcl/source/bitmap/bitmap.cxx
@@ -2113,4 +2113,19 @@ void Bitmap::Draw( OutputDevice* pOutDev,
     pOutDev->DrawBitmapEx( rDestPt, rDestSize, *this );
 }
 
+AlphaMask Bitmap::CreateAlphaMask() const
+{
+    assert(HasAlpha());
+    if (!HasAlpha())
+        return AlphaMask();
+    return BitmapEx(*this).GetAlphaMask();
+}
+
+Bitmap Bitmap::CreateColorBitmap() const
+{
+    if (!HasAlpha())
+        return *this;
+    return BitmapEx(*this).GetBitmap();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index 20944738d2ed..2b491fb87e93 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -9791,7 +9791,7 @@ bool PDFWriterImpl::writeBitmapObject( const BitmapEmit& 
rObject )
     if (!writeBuffer(aLine)) return false;
 
     if( nMaskObject )
-        return writeBitmapMaskObject( nMaskObject, 
BitmapEx(rObject.m_aBitmap).GetAlphaMask() );
+        return writeBitmapMaskObject( nMaskObject, 
rObject.m_aBitmap.CreateAlphaMask() );
 
     writeReferenceXObject(rObject.m_aReferenceXObject);
 
@@ -10048,7 +10048,7 @@ const BitmapEmit& PDFWriterImpl::createBitmapEmit(const 
Bitmap& i_rBitmap, const
     aID.m_nChecksum         = BitmapEx(aBitmap).GetBitmap().GetChecksum();
     aID.m_nMaskChecksum     = 0;
     if( aBitmap.HasAlpha() )
-        aID.m_nMaskChecksum = BitmapEx(aBitmap).GetAlphaMask().GetChecksum();
+        aID.m_nMaskChecksum = aBitmap.CreateAlphaMask().GetChecksum();
     std::list<BitmapEmit>::const_iterator it = std::find_if(rBitmaps.begin(), 
rBitmaps.end(),
                                              [&](const BitmapEmit& arg) { 
return aID == arg.m_aID; });
     if (it == rBitmaps.end())
diff --git a/vcl/workben/vcldemo.cxx b/vcl/workben/vcldemo.cxx
index 0424bda97cd3..56a0cfe44d50 100644
--- a/vcl/workben/vcldemo.cxx
+++ b/vcl/workben/vcldemo.cxx
@@ -844,7 +844,7 @@ public:
                 aRenderPt.Move(aShadowStretch.GetSizePixel().Width() + 4, 0);
             }
 
-            AlphaMask aWholeMask(BitmapEx(aPageShadowMask).GetBitmap());
+            AlphaMask aWholeMask(aPageShadowMask.CreateColorBitmap());
             aBlockColor = Bitmap(aPageShadowMask.GetSizePixel(), 
vcl::PixelFormat::N24_BPP);
             aBlockColor.Erase(COL_GREEN);
             BitmapEx aWhole(aBlockColor, aWholeMask);

Reply via email to