vcl/source/graphic/GraphicObject.cxx  |   34 +++++++--------
 vcl/source/graphic/GraphicObject2.cxx |   76 +++++++++++++++++++++++++++++++++-
 vcl/source/graphic/UnoGraphic.cxx     |   30 ++++++-------
 3 files changed, 107 insertions(+), 33 deletions(-)

New commits:
commit e0c66069e9734d4af9e877b1ec32644b843d0e10
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Tue Aug 26 17:34:45 2025 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Aug 26 21:10:56 2025 +0200

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

diff --git a/vcl/source/graphic/GraphicObject.cxx 
b/vcl/source/graphic/GraphicObject.cxx
index dccd0c959fbf..158751f723d9 100644
--- a/vcl/source/graphic/GraphicObject.cxx
+++ b/vcl/source/graphic/GraphicObject.cxx
@@ -133,7 +133,7 @@ bool lclDrawObj(OutputDevice& rOut, const Point& rPt, const 
Size& rSz,
     return bRet;
 }
 
-void lclImplAdjust( BitmapEx& rBmpEx, const GraphicAttr& rAttr, 
GraphicAdjustmentFlags nAdjustmentFlags )
+void lclImplAdjust( Bitmap& rBmp, const GraphicAttr& rAttr, 
GraphicAdjustmentFlags nAdjustmentFlags )
 {
     GraphicAttr aAttr( rAttr );
 
@@ -142,11 +142,11 @@ void lclImplAdjust( BitmapEx& rBmpEx, const GraphicAttr& 
rAttr, GraphicAdjustmen
         switch( aAttr.GetDrawMode() )
         {
             case GraphicDrawMode::Mono:
-                rBmpEx.Convert( BmpConversion::N1BitThreshold );
+                rBmp.Convert( BmpConversion::N1BitThreshold );
             break;
 
             case GraphicDrawMode::Greys:
-                rBmpEx.Convert( BmpConversion::N8BitGreys );
+                rBmp.Convert( BmpConversion::N8BitGreys );
             break;
 
             case GraphicDrawMode::Watermark:
@@ -163,24 +163,24 @@ void lclImplAdjust( BitmapEx& rBmpEx, const GraphicAttr& 
rAttr, GraphicAdjustmen
 
     if( ( nAdjustmentFlags & GraphicAdjustmentFlags::COLORS ) && 
aAttr.IsAdjusted() )
     {
-        rBmpEx.Adjust( aAttr.GetLuminance(), aAttr.GetContrast(),
+        rBmp.Adjust( aAttr.GetLuminance(), aAttr.GetContrast(),
                        aAttr.GetChannelR(), aAttr.GetChannelG(), 
aAttr.GetChannelB(),
                        aAttr.GetGamma(), aAttr.IsInvert() );
     }
 
     if( ( nAdjustmentFlags & GraphicAdjustmentFlags::MIRROR ) && 
aAttr.IsMirrored() )
     {
-        rBmpEx.Mirror( aAttr.GetMirrorFlags() );
+        rBmp.Mirror( aAttr.GetMirrorFlags() );
     }
 
     if( ( nAdjustmentFlags & GraphicAdjustmentFlags::ROTATE ) && 
aAttr.IsRotated() )
     {
-        rBmpEx.Rotate( aAttr.GetRotation(), COL_TRANSPARENT );
+        rBmp.Rotate( aAttr.GetRotation(), COL_TRANSPARENT );
     }
 
     if( ( nAdjustmentFlags & GraphicAdjustmentFlags::TRANSPARENCY ) && 
aAttr.IsTransparent() )
     {
-        rBmpEx.AdjustTransparency(255 - aAttr.GetAlpha());
+        rBmp.AdjustTransparency(255 - aAttr.GetAlpha());
     }
 }
 
@@ -694,7 +694,7 @@ Graphic GraphicObject::GetTransformedGraphic( const Size& 
rDestSize, const MapMo
     }
     else if( GraphicType::Bitmap == eType )
     {
-        BitmapEx aBitmapEx( aTransGraphic.GetBitmapEx() );
+        Bitmap aBitmap( aTransGraphic.GetBitmap() );
         tools::Rectangle aCropRect;
 
         // convert crops to pixel
@@ -728,7 +728,7 @@ Graphic GraphicObject::GetTransformedGraphic( const Size& 
rDestSize, const MapMo
                     aMapGraph));
 
             if(rAttr.IsCropped()
-                && (aSrcSizePixel.Width() != aBitmapEx.GetSizePixel().Width() 
|| aSrcSizePixel.Height() != aBitmapEx.GetSizePixel().Height())
+                && (aSrcSizePixel.Width() != aBitmap.GetSizePixel().Width() || 
aSrcSizePixel.Height() != aBitmap.GetSizePixel().Height())
                 && aSrcSizePixel.Width())
             {
                 // the size in pixels calculated from Graphic's internal 
MapMode (aTransGraphic.GetPrefMapMode())
@@ -740,15 +740,15 @@ Graphic GraphicObject::GetTransformedGraphic( const Size& 
rDestSize, const MapMo
                 // another possibility is to adapt the values created so far 
with a factor; this
                 // will keep the original Bitmap untouched and thus quality 
will not change
                 // caution: convert to double first, else pretty big errors 
may occur
-                const double 
fFactorX(static_cast<double>(aBitmapEx.GetSizePixel().Width()) / 
aSrcSizePixel.Width());
-                const double 
fFactorY(static_cast<double>(aBitmapEx.GetSizePixel().Height()) / 
aSrcSizePixel.Height());
+                const double 
fFactorX(static_cast<double>(aBitmap.GetSizePixel().Width()) / 
aSrcSizePixel.Width());
+                const double 
fFactorY(static_cast<double>(aBitmap.GetSizePixel().Height()) / 
aSrcSizePixel.Height());
 
                 aCropLeftTop.setWidth( 
basegfx::fround<tools::Long>(aCropLeftTop.Width() * fFactorX) );
                 aCropLeftTop.setHeight( 
basegfx::fround<tools::Long>(aCropLeftTop.Height() * fFactorY) );
                 aCropRightBottom.setWidth( 
basegfx::fround<tools::Long>(aCropRightBottom.Width() * fFactorX) );
                 aCropRightBottom.setHeight( 
basegfx::fround<tools::Long>(aCropRightBottom.Height() * fFactorY) );
 
-                aSrcSizePixel = aBitmapEx.GetSizePixel();
+                aSrcSizePixel = aBitmap.GetSizePixel();
             }
 
             // setup crop rectangle in pixel
@@ -820,10 +820,10 @@ Graphic GraphicObject::GetTransformedGraphic( const Size& 
rDestSize, const MapMo
         }
         else
         {
-            ImplTransformBitmap( aBitmapEx, rAttr, aCropLeftTop, 
aCropRightBottom,
+            ImplTransformBitmap( aBitmap, rAttr, aCropLeftTop, 
aCropRightBottom,
                                  aCropRect, rDestSize, true );
 
-            aTransGraphic = aBitmapEx;
+            aTransGraphic = aBitmap;
         }
 
         aTransGraphic.SetPrefSize( rDestSize );
@@ -858,9 +858,9 @@ Graphic GraphicObject::GetTransformedGraphic( const 
GraphicAttr* pAttr ) const
                 }
                 else
                 {
-                    BitmapEx aBmpEx( maGraphic.GetBitmapEx() );
-                    lclImplAdjust( aBmpEx, aAttr, GraphicAdjustmentFlags::ALL 
);
-                    aGraphic = aBmpEx;
+                    Bitmap aBmp( maGraphic.GetBitmap() );
+                    lclImplAdjust( aBmp, aAttr, GraphicAdjustmentFlags::ALL );
+                    aGraphic = aBmp;
                 }
             }
             else
diff --git a/vcl/source/graphic/GraphicObject2.cxx 
b/vcl/source/graphic/GraphicObject2.cxx
index 2fd570cb12b8..191288c2cff3 100644
--- a/vcl/source/graphic/GraphicObject2.cxx
+++ b/vcl/source/graphic/GraphicObject2.cxx
@@ -308,7 +308,7 @@ bool GraphicObject::ImplDrawTiled(OutputDevice& rOut, const 
tools::Rectangle& rA
                 GraphicObject aAlphaGraphic;
 
                 if( GetGraphic().IsAlpha() )
-                    
aAlphaGraphic.SetGraphic(BitmapEx(GetGraphic().GetBitmapEx().GetAlphaMask().GetBitmap()));
+                    
aAlphaGraphic.SetGraphic(BitmapEx(GetGraphic().GetBitmap().CreateAlphaMask().GetBitmap()));
                 else
                     aAlphaGraphic.SetGraphic(BitmapEx(Bitmap()));
 
@@ -499,4 +499,78 @@ void GraphicObject::ImplTransformBitmap( BitmapEx&         
 rBmpEx,
     rBmpEx.Scale( fScaleX, fScaleY );
 }
 
+void GraphicObject::ImplTransformBitmap( Bitmap&            rBmp,
+                                         const GraphicAttr& rAttr,
+                                         const Size&        rCropLeftTop,
+                                         const Size&        rCropRightBottom,
+                                         const tools::Rectangle&   rCropRect,
+                                         const Size&        rDstSize,
+                                         bool               bEnlarge ) const
+{
+    // #107947# Extracted from svdograf.cxx
+
+    // #104115# Crop the bitmap
+    if( rAttr.IsCropped() )
+    {
+        rBmp.Crop( rCropRect );
+
+        // #104115# Negative crop sizes mean: enlarge bitmap and pad
+        if( bEnlarge && (
+            rCropLeftTop.Width() < 0 ||
+            rCropLeftTop.Height() < 0 ||
+            rCropRightBottom.Width() < 0 ||
+            rCropRightBottom.Height() < 0 ) )
+        {
+            Size aBmpSize( rBmp.GetSizePixel() );
+            sal_Int32 nPadLeft( rCropLeftTop.Width() < 0 ? 
-rCropLeftTop.Width() : 0 );
+            sal_Int32 nPadTop( rCropLeftTop.Height() < 0 ? 
-rCropLeftTop.Height() : 0 );
+            sal_Int32 nPadTotalWidth( aBmpSize.Width() + nPadLeft + 
(rCropRightBottom.Width() < 0 ? -rCropRightBottom.Width() : 0) );
+            sal_Int32 nPadTotalHeight( aBmpSize.Height() + nPadTop + 
(rCropRightBottom.Height() < 0 ? -rCropRightBottom.Height() : 0) );
+
+            Bitmap aBmp2;
+
+            if( rBmp.HasAlpha() )
+            {
+                aBmp2 = rBmp;
+            }
+            else
+            {
+                // #104115# Generate mask bitmap and init to zero
+                AlphaMask aMask(aBmpSize);
+                aMask.Erase(255);
+
+                // #104115# Always generate transparent bitmap, we need the 
border transparent
+                aBmp2 = Bitmap(BitmapEx( rBmp.CreateColorBitmap(), aMask ));
+
+                // #104115# Add opaque mask to source bitmap, otherwise the 
destination remains transparent
+                rBmp = aBmp2;
+            }
+
+            aBmp2.Scale(Size(nPadTotalWidth, nPadTotalHeight));
+            aBmp2.Erase( Color(ColorAlpha,0,0,0,0) );
+            aBmp2.CopyPixel( tools::Rectangle( Point(nPadLeft, nPadTop), 
aBmpSize ), tools::Rectangle( Point(0, 0), aBmpSize ), rBmp );
+            rBmp = aBmp2;
+        }
+    }
+
+    const Size  aSizePixel( rBmp.GetSizePixel() );
+
+    if( rAttr.GetRotation() == 0_deg10 || IsAnimated() )
+        return;
+
+    if( !(aSizePixel.Width() && aSizePixel.Height() && rDstSize.Width() && 
rDstSize.Height()) )
+        return;
+
+    double fSrcWH = static_cast<double>(aSizePixel.Width()) / 
aSizePixel.Height();
+    double fDstWH = static_cast<double>(rDstSize.Width()) / rDstSize.Height();
+    double fScaleX = 1.0, fScaleY = 1.0;
+
+    // always choose scaling to shrink bitmap
+    if( fSrcWH < fDstWH )
+        fScaleY = aSizePixel.Width() / ( fDstWH * aSizePixel.Height() );
+    else
+        fScaleX = fDstWH * aSizePixel.Height() / aSizePixel.Width();
+
+    rBmp.Scale( fScaleX, fScaleY );
+}
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit d1285adffa2aefddab8466dbe60db75125d67048
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Tue Aug 26 15:46:51 2025 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Aug 26 21:10:46 2025 +0200

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

diff --git a/vcl/source/graphic/UnoGraphic.cxx 
b/vcl/source/graphic/UnoGraphic.cxx
index e6fafee8b979..4b6b8d60621d 100644
--- a/vcl/source/graphic/UnoGraphic.cxx
+++ b/vcl/source/graphic/UnoGraphic.cxx
@@ -145,7 +145,7 @@ uno::Sequence<sal_Int8> SAL_CALL Graphic::getDIB()
     {
         SvMemoryStream aMemoryStream;
 
-        WriteDIB(maGraphic.GetBitmapEx().GetBitmap(), aMemoryStream, false, 
true);
+        WriteDIB(maGraphic.GetBitmap().CreateColorBitmap(), aMemoryStream, 
false, true);
         return css::uno::Sequence<sal_Int8>(static_cast<sal_Int8 const 
*>(aMemoryStream.GetData()), aMemoryStream.Tell());
     }
     else
@@ -187,27 +187,27 @@ uno::Reference< graphic::XGraphic > SAL_CALL 
Graphic::colorChange(
     if (aGraphic.GetType() == GraphicType::Bitmap ||
         aGraphic.GetType() == GraphicType::GdiMetafile)
     {
-        BitmapEx aBitmapEx(aGraphic.GetBitmapEx());
+        Bitmap aBitmap(aGraphic.GetBitmap());
 
-        if (aBitmapEx.IsAlpha())
+        if (aBitmap.HasAlpha())
         {
-            aBitmapEx.ChangeColorAlpha( cIndexFrom, nAlphaTo );
-            aBitmapEx.Replace(aColorFrom, aColorTo, nTolerance);
-            aReturnGraphic = ::Graphic(aBitmapEx);
+            aBitmap.ChangeColorAlpha( cIndexFrom, nAlphaTo );
+            aBitmap.Replace(aColorFrom, aColorTo, nTolerance);
+            aReturnGraphic = ::Graphic(aBitmap);
         }
         else
         {
             if ((nAlphaTo == 0) || (nAlphaTo == sal::static_int_cast< sal_Int8 
>(0xff)))
             {
-                Bitmap aBitmap(aBitmapEx.GetBitmap());
-                AlphaMask aMask(aBitmap.CreateAlphaMask(aColorFrom, 
nTolerance));
-                aBitmap.Replace(aColorFrom, aColorTo, nTolerance);
-                aReturnGraphic = ::Graphic(BitmapEx(aBitmap, aMask));
+                Bitmap aBitmap2(aBitmap);
+                AlphaMask aMask(aBitmap2.CreateAlphaMask(aColorFrom, 
nTolerance));
+                aBitmap2.Replace(aColorFrom, aColorTo, nTolerance);
+                aReturnGraphic = ::Graphic(BitmapEx(aBitmap2, aMask));
             }
             else
             {
-                aBitmapEx.Replace(aColorFrom, aColorTo, nTolerance);
-                aReturnGraphic = ::Graphic(aBitmapEx);
+                aBitmap.Replace(aColorFrom, aColorTo, nTolerance);
+                aReturnGraphic = ::Graphic(aBitmap);
             }
         }
     }
@@ -242,9 +242,9 @@ uno::Reference< graphic::XGraphic > SAL_CALL 
Graphic::applyBrightnessContrast(
     ::Graphic aGraphic(rxGraphic);
     ::Graphic aReturnGraphic;
 
-    BitmapEx aBitmapEx(aGraphic.GetBitmapEx());
-    aBitmapEx.Adjust(nBrightness, nContrast, 0, 0, 0, 0, false, mso);
-    aReturnGraphic = ::Graphic(aBitmapEx);
+    Bitmap aBitmap(aGraphic.GetBitmap());
+    aBitmap.Adjust(nBrightness, nContrast, 0, 0, 0, 0, false, mso);
+    aReturnGraphic = ::Graphic(aBitmap);
     aReturnGraphic.setOriginURL(aGraphic.getOriginURL());
     return aReturnGraphic.GetXGraphic();
 }

Reply via email to