vcl/source/graphic/UnoGraphicProvider.cxx |   60 +++++++++++++++---------------
 1 file changed, 31 insertions(+), 29 deletions(-)

New commits:
commit d0d0141b105694bec7d84527f998527f86bb121f
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Thu May 22 15:02:19 2025 +0200
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Thu May 22 22:03:46 2025 +0200

    Simplify vcl::GetGraphic
    
    Change-Id: I0406d66485ef17fd9b978dff4fe666226c3932a0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185665
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/vcl/source/graphic/UnoGraphicProvider.cxx 
b/vcl/source/graphic/UnoGraphicProvider.cxx
index c0bdbc089ae9..0e75a7505975 100644
--- a/vcl/source/graphic/UnoGraphicProvider.cxx
+++ b/vcl/source/graphic/UnoGraphicProvider.cxx
@@ -100,9 +100,7 @@ css::uno::Reference<css::graphic::XGraphic> 
GetGraphic(const css::uno::Any& any)
 
     if (BitmapEx aBmpEx = GetBitmap(any.query<css::awt::XBitmap>()); 
!aBmpEx.IsEmpty())
     {
-        rtl::Reference pUnoGraphic(new unographic::Graphic);
-        pUnoGraphic->init(aBmpEx);
-        return pUnoGraphic;
+        return Graphic(aBmpEx).GetXGraphic();
     }
 
     return {};
commit 176a52dbce43e84177154ee42061aee1b017852e
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Thu May 22 13:02:05 2025 +0200
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Thu May 22 22:03:35 2025 +0200

    Simplify vcl::GetBitmap
    
    Change-Id: I75232d76017fa2787c54131c90c6481adefd6d0c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185659
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/vcl/source/graphic/UnoGraphicProvider.cxx 
b/vcl/source/graphic/UnoGraphicProvider.cxx
index a954a8d681b0..c0bdbc089ae9 100644
--- a/vcl/source/graphic/UnoGraphicProvider.cxx
+++ b/vcl/source/graphic/UnoGraphicProvider.cxx
@@ -18,6 +18,7 @@
  */
 
 #include <o3tl/string_view.hxx>
+#include <o3tl/temporary.hxx>
 #include <vcl/svapp.hxx>
 #include <vcl/image.hxx>
 #include <vcl/metaact.hxx>
@@ -53,39 +54,42 @@
 
 using namespace com::sun::star;
 
+namespace
+{
+SvMemoryStream AsStream(const css::uno::Sequence<sal_Int8>& s)
+{
+    return SvMemoryStream(const_cast<sal_Int8*>(s.getConstArray()), 
s.getLength(),
+                          StreamMode::READ);
+}
+
+Bitmap BitmapFromDIB(const css::uno::Sequence<sal_Int8>& dib)
+{
+    Bitmap bmp;
+    if (dib.hasElements())
+        ReadDIB(bmp, o3tl::temporary(AsStream(dib)), true);
+    return bmp;
+}
+}
+
 namespace vcl
 {
 BitmapEx GetBitmap(const css::uno::Reference<css::awt::XBitmap>& xBitmap)
 {
-    BitmapEx aBmp;
+    if (!xBitmap)
+        return {};
+
     if (auto xGraphic = xBitmap.query<css::graphic::XGraphic>())
+        return Graphic(xGraphic).GetBitmapEx();
+
+    // This is an unknown implementation of a XBitmap interface
+    if (Bitmap aMask = BitmapFromDIB(xBitmap->getMaskDIB()); !aMask.IsEmpty())
     {
-        Graphic aGraphic(xGraphic);
-        aBmp = aGraphic.GetBitmapEx();
-    }
-    else if (xBitmap)
-    {
-        // This is an unknown implementation of a XBitmap interface
-        Bitmap aMask;
-        if (css::uno::Sequence<sal_Int8> aBytes = xBitmap->getMaskDIB(); 
aBytes.hasElements())
-        {
-            SvMemoryStream aMem(aBytes.getArray(), aBytes.getLength(), 
StreamMode::READ);
-            ReadDIB(aMask, aMem, true);
-            aMask.Invert(); // Convert from transparency to alpha
-        }
-        css::uno::Sequence<sal_Int8> aBytes = xBitmap->getDIB();
-        SvMemoryStream aMem(aBytes.getArray(), aBytes.getLength(), 
StreamMode::READ);
-        if (!aMask.IsEmpty())
-        {
-            Bitmap aDIB;
-            ReadDIB(aDIB, aMem, true);
-            aBmp = BitmapEx(aDIB, aMask);
-        }
-        else
-        {
-            ReadDIBBitmapEx(aBmp, aMem, true);
-        }
+        aMask.Invert(); // Convert from transparency to alpha
+        return BitmapEx(BitmapFromDIB(xBitmap->getDIB()), aMask);
     }
+
+    BitmapEx aBmp;
+    ReadDIBBitmapEx(aBmp, o3tl::temporary(AsStream(xBitmap->getDIB())), true);
     return aBmp;
 }
 

Reply via email to