vcl/source/bitmap/bitmap.cxx |   56 ++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 53 insertions(+), 3 deletions(-)

New commits:
commit 22037e26e2768635254be0d99967d8459b0063aa
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Fri Sep 5 13:58:32 2025 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri Sep 5 15:56:24 2025 +0200

    implement Bitmap::Expand without using BitmapEx
    
    as part of the process of phasing out BitmapEx
    
    Change-Id: I5ef62c75a873b2d745314cf65e85ef41f2038822
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190615
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/vcl/source/bitmap/bitmap.cxx b/vcl/source/bitmap/bitmap.cxx
index 6876e4b87451..e38b0236daa3 100644
--- a/vcl/source/bitmap/bitmap.cxx
+++ b/vcl/source/bitmap/bitmap.cxx
@@ -1949,9 +1949,59 @@ Color Bitmap::GetPixelColor(sal_Int32 nX, sal_Int32 nY) 
const
 
 void Bitmap::Expand(sal_Int32 nDX, sal_Int32 nDY, bool bExpandTransparent)
 {
-    BitmapEx aTmpEx(*this);
-    aTmpEx.Expand(nDX, nDY, bExpandTransparent);
-    operator=(Bitmap(aTmpEx));
+    if (IsEmpty())
+        return;
+    if( !nDX && !nDY )
+        return;
+
+    const Size          aSizePixel( GetSizePixel() );
+    const tools::Long   nWidth = aSizePixel.Width();
+    const tools::Long   nHeight = aSizePixel.Height();
+    const Size          aNewSize( nWidth + nDX, nHeight + nDY );
+    BitmapScopedReadAccess pReadAcc(*this);
+    assert(pReadAcc);
+    if( !pReadAcc )
+        return;
+
+    BitmapPalette aBmpPal( pReadAcc->GetPalette() );
+    Bitmap aNewBmp(aNewSize, getPixelFormat(), &aBmpPal);
+    BitmapScopedWriteAccess pWriteAcc(aNewBmp);
+    assert(pWriteAcc);
+    if( !pWriteAcc )
+        return;
+
+    const tools::Long  nNewX = nWidth;
+    const tools::Long  nNewY = nHeight;
+    const tools::Long  nNewWidth = pWriteAcc->Width();
+    const tools::Long  nNewHeight = pWriteAcc->Height();
+
+    Color aInitColor( bExpandTransparent ? COL_ALPHA_TRANSPARENT : 
COL_ALPHA_OPAQUE );
+    BitmapColor aColor = pWriteAcc->GetBestMatchingColor( aInitColor );
+
+    for( tools::Long nY = 0; nY < nHeight; nY++ )
+    {
+        pWriteAcc->CopyScanline( nY, *pReadAcc );
+
+        if( nDX )
+        {
+            Scanline pScanline = pWriteAcc->GetScanline(nY);
+            for( tools::Long nX = nNewX; nX < nNewWidth; nX++ )
+                pWriteAcc->SetPixelOnData( pScanline, nX, aColor );
+        }
+    }
+
+    if( nDY )
+        for( tools::Long nY = nNewY; nY < nNewHeight; nY++ )
+        {
+            Scanline pScanline = pWriteAcc->GetScanline(nY);
+            for( tools::Long nX = 0; nX < nNewWidth; nX++ )
+                pWriteAcc->SetPixelOnData( pScanline, nX, aColor );
+        }
+
+    pWriteAcc.reset();
+    pReadAcc.reset();
+
+    ReassignWithSize(aNewBmp);
 }
 
 namespace

Reply via email to