filter/source/msfilter/msdffimp.cxx  |   16 +++----
 filter/source/msfilter/mstoolbar.cxx |    6 +-
 filter/source/svg/svgexport.cxx      |    2 
 include/vcl/bitmap.hxx               |    5 ++
 vcl/source/bitmap/bitmap.cxx         |   71 +++++++++++++++++++++++++++++++++++
 5 files changed, 88 insertions(+), 12 deletions(-)

New commits:
commit 846998194b857e5faa74148caa6f6c97d60c4d16
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Mon Aug 25 16:22:58 2025 +0200
Commit:     Noel Grandin <noelgran...@gmail.com>
CommitDate: Mon Aug 25 22:38:23 2025 +0200

    BitmapEx->Bitmap in filter
    
    now that Bitmap supports transparency
    
    Change-Id: I54e5886897b6fbddfe516f77cf42dc3af514c1ea
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190182
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/filter/source/msfilter/msdffimp.cxx 
b/filter/source/msfilter/msdffimp.cxx
index 106cb53dd876..da400284cb36 100644
--- a/filter/source/msfilter/msdffimp.cxx
+++ b/filter/source/msfilter/msdffimp.cxx
@@ -3912,9 +3912,9 @@ rtl::Reference<SdrObject> SvxMSDffManager::ImportGraphic( 
SvStream& rSt, SfxItem
 
                 if ( aGraf.GetType() == GraphicType::Bitmap )
                 {
-                    BitmapEx aBitmapEx( aGraf.GetBitmapEx() );
-                    aBitmapEx.CombineMaskOr( MSO_CLR_ToColor( nTransColor, 
DFF_Prop_pictureTransparent ), 9 );
-                    aGraf = aBitmapEx;
+                    Bitmap aBitmap( aGraf.GetBitmap() );
+                    aBitmap.CombineMaskOr( MSO_CLR_ToColor( nTransColor, 
DFF_Prop_pictureTransparent ), 9 );
+                    aGraf = aBitmap;
                 }
             }
 
@@ -4006,14 +4006,14 @@ rtl::Reference<SdrObject> 
SvxMSDffManager::ImportGraphic( SvStream& rSt, SfxItem
                     {
                         case GraphicType::Bitmap :
                         {
-                            BitmapEx    aBitmapEx( aGraf.GetBitmapEx() );
+                            Bitmap    aBitmap( aGraf.GetBitmap() );
                             if ( nBrightness || nContrast || ( nGamma != 
0x10000 ) )
-                                aBitmapEx.Adjust( nBrightness, 
static_cast<sal_Int16>(nContrast), 0, 0, 0, static_cast<double>(nGamma) / 
0x10000, false, true );
+                                aBitmap.Adjust( nBrightness, 
static_cast<sal_Int16>(nContrast), 0, 0, 0, static_cast<double>(nGamma) / 
0x10000, false, true );
                             if ( eDrawMode == GraphicDrawMode::Greys )
-                                aBitmapEx.Convert( BmpConversion::N8BitGreys );
+                                aBitmap.Convert( BmpConversion::N8BitGreys );
                             else if ( eDrawMode == GraphicDrawMode::Mono )
-                                aBitmapEx.Convert( 
BmpConversion::N1BitThreshold );
-                            aGraf = aBitmapEx;
+                                aBitmap.Convert( BmpConversion::N1BitThreshold 
);
+                            aGraf = aBitmap;
 
                         }
                         break;
diff --git a/filter/source/msfilter/mstoolbar.cxx 
b/filter/source/msfilter/mstoolbar.cxx
index ac603881a8a1..47906a944777 100644
--- a/filter/source/msfilter/mstoolbar.cxx
+++ b/filter/source/msfilter/mstoolbar.cxx
@@ -45,9 +45,9 @@ void CustomToolBarImportHelper::ScaleImage( uno::Reference< 
graphic::XGraphic >&
         Graphic aImage(xGraphic);
         if ( aSize.Height() != nNewSize )
         {
-            BitmapEx aBitmap = aImage.GetBitmapEx();
-            BitmapEx aBitmapex = BitmapEx::AutoScaleBitmap(aBitmap, nNewSize );
-            aImage = Graphic(aBitmapex);
+            Bitmap aBitmap = aImage.GetBitmap();
+            aBitmap = Bitmap::AutoScaleBitmap(aBitmap, nNewSize );
+            aImage = Graphic(aBitmap);
             xGraphic = aImage.GetXGraphic();
         }
     }
diff --git a/filter/source/svg/svgexport.cxx b/filter/source/svg/svgexport.cxx
index 10b5f65ba8c7..566cc7440db5 100644
--- a/filter/source/svg/svgexport.cxx
+++ b/filter/source/svg/svgexport.cxx
@@ -2401,7 +2401,7 @@ bool SVGFilter::implCreateObjectsFromShape( const 
Reference< css::drawing::XDraw
                     const Point    aNullPt;
                     const Size    aSize( pObj->GetCurrentBoundRect().GetSize() 
);
 
-                    aMtf.AddAction( new MetaBmpExScaleAction( aNullPt, aSize, 
aGraphic.GetBitmapEx() ) );
+                    aMtf.AddAction( new MetaBmpExScaleAction( aNullPt, aSize, 
BitmapEx(aGraphic.GetBitmap()) ) );
                     aMtf.SetPrefSize( aSize );
                     aMtf.SetPrefMapMode(MapMode(MapUnit::Map100thMM));
 
diff --git a/include/vcl/bitmap.hxx b/include/vcl/bitmap.hxx
index b44005dbaa7a..2267c08d4e5a 100644
--- a/include/vcl/bitmap.hxx
+++ b/include/vcl/bitmap.hxx
@@ -596,6 +596,8 @@ public:
      */
     void BlendAlpha( sal_uInt8 nAlpha );
 
+    void CombineMaskOr(Color maskColor, sal_uInt8 nTol);
+
     /** Remove existing blending against COL_WHITE based on given AlphaMask
 
         Inside convertToBitmapEx the content gets rendered to RGB target (no 
'A'),
@@ -636,6 +638,9 @@ public:
     [[nodiscard]]
     Bitmap            Modify( const basegfx::BColorModifierStack& 
rBColorModifierStack) const;
 
+    [[nodiscard]]
+    static Bitmap     AutoScaleBitmap( Bitmap const & rBitmap, const 
tools::Long aStandardSize );
+
     SAL_DLLPRIVATE void Draw( OutputDevice* pOutDev,
                               const Point& rDestPt ) const;
     void                Draw( OutputDevice* pOutDev,
diff --git a/vcl/source/bitmap/bitmap.cxx b/vcl/source/bitmap/bitmap.cxx
index 4d093757aea2..c8a51284df5f 100644
--- a/vcl/source/bitmap/bitmap.cxx
+++ b/vcl/source/bitmap/bitmap.cxx
@@ -2310,4 +2310,75 @@ void Bitmap::ReplaceTransparency(const Color& 
rReplaceColor)
     *this = std::move(aNewBmp);
 }
 
+Bitmap Bitmap::AutoScaleBitmap(Bitmap const & aBitmap, const tools::Long 
aStandardSize)
+{
+    Point aEmptyPoint(0,0);
+    double imgposX = 0;
+    double imgposY = 0;
+    Bitmap aRet = aBitmap;
+    double imgOldWidth = aRet.GetSizePixel().Width();
+    double imgOldHeight = aRet.GetSizePixel().Height();
+
+    if (imgOldWidth >= aStandardSize || imgOldHeight >= aStandardSize)
+    {
+        sal_Int32 imgNewWidth = 0;
+        sal_Int32 imgNewHeight = 0;
+        if (imgOldWidth >= imgOldHeight)
+        {
+            imgNewWidth = aStandardSize;
+            imgNewHeight = sal_Int32(imgOldHeight / (imgOldWidth / 
aStandardSize) + 0.5);
+            imgposX = 0;
+            imgposY = (aStandardSize - (imgOldHeight / (imgOldWidth / 
aStandardSize) + 0.5)) / 2 + 0.5;
+        }
+        else
+        {
+            imgNewHeight = aStandardSize;
+            imgNewWidth = sal_Int32(imgOldWidth / (imgOldHeight / 
aStandardSize) + 0.5);
+            imgposY = 0;
+            imgposX = (aStandardSize - (imgOldWidth / (imgOldHeight / 
aStandardSize) + 0.5)) / 2 + 0.5;
+        }
+
+        Size aScaledSize( imgNewWidth, imgNewHeight );
+        aRet.Scale( aScaledSize, BmpScaleFlag::BestQuality );
+    }
+    else
+    {
+        imgposX = (aStandardSize - imgOldWidth) / 2 + 0.5;
+        imgposY = (aStandardSize - imgOldHeight) / 2 + 0.5;
+    }
+
+    Size aStdSize( aStandardSize, aStandardSize );
+    tools::Rectangle aRect(aEmptyPoint, aStdSize );
+
+    ScopedVclPtrInstance< VirtualDevice > 
aVirDevice(*Application::GetDefaultDevice());
+    aVirDevice->SetOutputSizePixel( aStdSize );
+    aVirDevice->SetFillColor( COL_TRANSPARENT );
+    aVirDevice->SetLineColor( COL_TRANSPARENT );
+
+    // Draw a rect into virDevice
+    aVirDevice->DrawRect( aRect );
+    Point aPointPixel( static_cast<tools::Long>(imgposX), 
static_cast<tools::Long>(imgposY) );
+    aVirDevice->DrawBitmapEx( aPointPixel, aRet );
+    aRet = aVirDevice->GetBitmap( aEmptyPoint, aStdSize );
+
+    return aRet;
+}
+
+void Bitmap::CombineMaskOr(Color rTransColor, sal_uInt8 nTol)
+{
+    Bitmap aColBmp = CreateColorBitmap();
+    AlphaMask aNewMask = aColBmp.CreateAlphaMask( rTransColor, nTol );
+
+    if ( HasAlpha() )
+        aNewMask.AlphaCombineOr( CreateAlphaMask() );
+
+    const MapMode aMap( maPrefMapMode );
+    const Size aSize( maPrefSize );
+
+    *this = Bitmap(BitmapEx(aColBmp, aNewMask));
+
+    maPrefMapMode = aMap;
+    maPrefSize = aSize;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to