[Libreoffice-commits] core.git: 2 commits - include/vcl vcl/inc vcl/Library_vcl.mk vcl/source vcl/unx

Stephan Bergmann sbergman at redhat.com
Thu Jul 11 04:22:59 PDT 2013


 include/vcl/salctype.hxx                 |    8 -
 vcl/Library_vcl.mk                       |    1 
 vcl/inc/unx/salinst.h                    |    2 
 vcl/source/gdi/bmpconv.cxx               |  209 -------------------------------
 vcl/source/window/window.cxx             |   15 --
 vcl/unx/generic/dtrans/X11_selection.cxx |   34 -----
 vcl/unx/generic/dtrans/X11_selection.hxx |    3 
 vcl/unx/generic/dtrans/X11_service.cxx   |   52 ++-----
 vcl/unx/generic/dtrans/bmp.cxx           |   87 ++++++------
 vcl/unx/generic/dtrans/bmp.hxx           |   20 --
 10 files changed, 74 insertions(+), 357 deletions(-)

New commits:
commit 31144904919cf386f7ef6941a2932bc00497ed13
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Thu Jul 11 13:22:02 2013 +0200

    X11SalInstance::CreateClipboard is only ever used with the default $DISPLAY
    
    Change-Id: Id9a407b9ee4419fc6342931b249eb00e70addfad

diff --git a/vcl/inc/unx/salinst.h b/vcl/inc/unx/salinst.h
index 3f8d06e..afe8e84 100644
--- a/vcl/inc/unx/salinst.h
+++ b/vcl/inc/unx/salinst.h
@@ -39,7 +39,7 @@ class SalXLib;
 class VCLPLUG_GEN_PUBLIC X11SalInstance : public SalGenericInstance
 {
 private:
-    boost::unordered_map< OUString, boost::unordered_map< Atom, com::sun::star::uno::Reference< com::sun::star::datatransfer::clipboard::XClipboard > >, OUStringHash > m_aInstances;
+    boost::unordered_map< Atom, com::sun::star::uno::Reference< com::sun::star::datatransfer::clipboard::XClipboard > > m_aInstances;
 
 protected:
     SalXLib *mpXLib;
diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx
index dc450e3..2125cda 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -8508,11 +8508,10 @@ uno::Reference< XClipboard > Window::GetPrimarySelection()
                 uno::Reference< XComponentContext > xContext( comphelper::getProcessComponentContext() );
 
 #if defined(UNX) && !defined(MACOSX)
-                // A hack, making the primary selection available as an instance of
-                // the SystemClipboard service on X11:
-                css::uno::Sequence<css::uno::Any> args(2);
-                args[0] <<= Application::GetDisplayConnection();
-                args[1] <<= OUString("PRIMARY");
+                // A hack, making the primary selection available as an instance
+                // of the SystemClipboard service on X11:
+                css::uno::Sequence<css::uno::Any> args(1);
+                args[0] <<= OUString("PRIMARY");
                 mpWindowImpl->mpFrameData->mxSelection.set(
                     (xContext->getServiceManager()->
                      createInstanceWithArgumentsAndContext(
diff --git a/vcl/unx/generic/dtrans/X11_service.cxx b/vcl/unx/generic/dtrans/X11_service.cxx
index 2e8e0cd..59d7e45 100644
--- a/vcl/unx/generic/dtrans/X11_service.cxx
+++ b/vcl/unx/generic/dtrans/X11_service.cxx
@@ -61,47 +61,27 @@ Sequence< OUString > SAL_CALL x11::Xdnd_dropTarget_getSupportedServiceNames()
 
 css::uno::Reference< XInterface > X11SalInstance::CreateClipboard( const Sequence< Any >& arguments )
 {
-    OUString aDisplayName;
-    Atom nSelection;
-
-    // extract display name from connection argument. An exception is thrown
-    // by SelectionManager.initialize() if no display connection is given.
-    if( arguments.getLength() > 0 )
-    {
-        css::uno::Reference< XDisplayConnection > xConn;
-        arguments.getConstArray()[0] >>= xConn;
-
-        if( xConn.is() )
-        {
-            Any aIdentifier = xConn->getIdentifier();
-            aIdentifier >>= aDisplayName;
-        }
+    SelectionManager& rManager = SelectionManager::get();
+    css::uno::Sequence<css::uno::Any> mgrArgs(1);
+    mgrArgs[0] <<= Application::GetDisplayConnection();
+    rManager.initialize(mgrArgs);
+
+    OUString sel;
+    if (arguments.getLength() == 0) {
+        sel = "CLIPBOARD";
+    } else if (arguments.getLength() != 1 || !(arguments[0] >>= sel)) {
+        throw css::lang::IllegalArgumentException(
+            "bad X11SalInstance::CreateClipboard arguments",
+            css::uno::Reference<css::uno::XInterface>(), -1);
     }
+    Atom nSelection = rManager.getAtom(sel);
 
-    SelectionManager& rManager = SelectionManager::get( aDisplayName );
-    rManager.initialize( arguments );
-
-    // check if any other selection than clipboard selection is specified
-    if( arguments.getLength() > 1 )
-    {
-        OUString aSelectionName;
-
-        arguments.getConstArray()[1] >>= aSelectionName;
-        nSelection = rManager.getAtom( aSelectionName );
-    }
-    else
-    {
-        // default atom is clipboard selection
-        nSelection = rManager.getAtom( OUString("CLIPBOARD") );
-    }
-
-    ::boost::unordered_map< Atom, css::uno::Reference< XClipboard > >& rMap( m_aInstances[ aDisplayName ] );
-    ::boost::unordered_map< Atom, css::uno::Reference< XClipboard > >::iterator it = rMap.find( nSelection );
-    if( it != rMap.end() )
+    ::boost::unordered_map< Atom, css::uno::Reference< XClipboard > >::iterator it = m_aInstances.find( nSelection );
+    if( it != m_aInstances.end() )
         return it->second;
 
     X11Clipboard* pClipboard = new X11Clipboard( rManager, nSelection );
-    rMap[ nSelection ] = pClipboard;
+    m_aInstances[ nSelection ] = pClipboard;
 
     return static_cast<OWeakObject*>(pClipboard);
 }
commit b100f3f06be2dd79c8145cdf487901bc5d71b332
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Thu Jul 11 12:40:25 2013 +0200

    Simplify support for bitmap depth conversion in X11 clipboard/dnd code
    
    ...I see no good reason to make the code from bmpconv.cxx available to
    vcl/unx/generic/dtrans/ in a complicated way via UNO, instead of calling it
    there directly.
    
    Change-Id: I4f2e53c4610e8e19c96e1230a5c5ef034aab80da

diff --git a/include/vcl/salctype.hxx b/include/vcl/salctype.hxx
index 4fbb65d..01e1035 100644
--- a/include/vcl/salctype.hxx
+++ b/include/vcl/salctype.hxx
@@ -20,8 +20,7 @@
 #ifndef _SV_SALCTYPE_HXX
 #define _SV_SALCTYPE_HXX
 
-#include <com/sun/star/script/XInvocation.hpp>
-#include <com/sun/star/uno/Reference.hxx>
+#include "sal/config.h"
 
 #include <vcl/graph.hxx>
 
@@ -61,11 +60,6 @@ typedef sal_uLong (*SALGRFCVTPROC)( void* pInst,
                                 sal_uLong nInFormat, void* pInBuffer, sal_uLong nInBufSize,
                                 sal_uLong nOutFormat, void** ppOutBuffer );
 
-namespace vcl
-{
-com::sun::star::uno::Reference< com::sun::star::script::XInvocation > createBmpConverter();
-}
-
 #endif // _SV_SALCTYPE_HXX
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index 6216d67..3c56c44 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -196,7 +196,6 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
     vcl/source/gdi/bmpacc2 \
     vcl/source/gdi/bmpacc3 \
     vcl/source/gdi/bmpacc \
-    vcl/source/gdi/bmpconv \
     vcl/source/gdi/bmpfast \
     vcl/source/gdi/configsettings \
     vcl/source/gdi/cvtgrf \
diff --git a/vcl/source/gdi/bmpconv.cxx b/vcl/source/gdi/bmpconv.cxx
deleted file mode 100644
index 24bb159..0000000
--- a/vcl/source/gdi/bmpconv.cxx
+++ /dev/null
@@ -1,209 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- *   Licensed to the Apache Software Foundation (ASF) under one or more
- *   contributor license agreements. See the NOTICE file distributed
- *   with this work for additional information regarding copyright
- *   ownership. The ASF licenses this file to you under the Apache
- *   License, Version 2.0 (the "License"); you may not use this file
- *   except in compliance with the License. You may obtain a copy of
- *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#include "vcl/bitmap.hxx"
-#include "vcl/svapp.hxx"
-#include "vcl/salctype.hxx"
-#include <osl/mutex.hxx>
-#include "tools/stream.hxx"
-#include "com/sun/star/script/XInvocation.hpp"
-#include "com/sun/star/awt/XBitmap.hpp"
-#include "cppuhelper/compbase1.hxx"
-#include <vcl/dibtools.hxx>
-
-using namespace com::sun::star::uno;
-using namespace com::sun::star::script;
-using namespace com::sun::star::beans;
-using namespace com::sun::star::reflection;
-using namespace com::sun::star::awt;
-
-
-namespace vcl {
-
-class BmpTransporter :
-        public cppu::WeakImplHelper1< com::sun::star::awt::XBitmap >
-{
-    Sequence<sal_Int8>          m_aBM;
-    com::sun::star::awt::Size   m_aSize;
-public:
-    BmpTransporter( const Bitmap& rBM );
-    virtual  ~BmpTransporter();
-
-    virtual com::sun::star::awt::Size SAL_CALL getSize() throw();
-    virtual Sequence< sal_Int8 > SAL_CALL getDIB() throw();
-    virtual Sequence< sal_Int8 > SAL_CALL getMaskDIB() throw();
-};
-
-class BmpConverter :
-        public cppu::WeakImplHelper1< com::sun::star::script::XInvocation >
-{
-public:
-    BmpConverter();
-    virtual ~BmpConverter();
-
-    virtual Reference< XIntrospectionAccess > SAL_CALL getIntrospection() throw();
-    virtual void SAL_CALL setValue( const OUString& rProperty, const Any& rValue )
-        throw( UnknownPropertyException );
-    virtual Any SAL_CALL getValue( const OUString& rProperty )
-        throw( UnknownPropertyException );
-    virtual sal_Bool SAL_CALL hasMethod( const OUString& rName ) throw();
-    virtual sal_Bool SAL_CALL hasProperty( const OUString& rProp ) throw();
-
-    virtual Any SAL_CALL invoke( const OUString& rFunction,
-                                 const Sequence< Any >& rParams,
-                                 Sequence< sal_Int16 >& rOutParamIndex,
-                                 Sequence< Any >& rOutParam
-                                 )
-        throw( CannotConvertException, InvocationTargetException );
-};
-
-}
-
-using namespace vcl;
-
-Reference< XInvocation > vcl::createBmpConverter()
-{
-    return static_cast<XInvocation*>(new BmpConverter());
-}
-
-BmpConverter::BmpConverter()
-{
-}
-
-BmpConverter::~BmpConverter()
-{
-}
-
-Reference< XIntrospectionAccess > SAL_CALL BmpConverter::getIntrospection() throw()
-{
-    return Reference< XIntrospectionAccess >();
-}
-
-void SAL_CALL BmpConverter::setValue( const OUString&, const Any& ) throw( UnknownPropertyException )
-{
-    throw UnknownPropertyException();
-}
-
-Any SAL_CALL BmpConverter::getValue( const OUString& ) throw( UnknownPropertyException )
-{
-    throw UnknownPropertyException();
-}
-
-sal_Bool SAL_CALL BmpConverter::hasMethod( const OUString& rName ) throw()
-{
-    return rName.equalsIgnoreAsciiCase( OUString("convert-bitmap-depth") );
-}
-
-sal_Bool SAL_CALL BmpConverter::hasProperty( const OUString& ) throw()
-{
-    return sal_False;
-}
-
-Any SAL_CALL BmpConverter::invoke(
-                                  const OUString& rFunction,
-                                  const Sequence< Any >& rParams,
-                                  Sequence< sal_Int16 >&,
-                                  Sequence< Any >& )
-    throw( CannotConvertException, InvocationTargetException )
-{
-    Any aRet;
-
-    if( rFunction.equalsIgnoreAsciiCase( OUString("convert-bitmap-depth") ) )
-    {
-        Reference< XBitmap > xBM;
-        sal_uInt16 nTargetDepth = 0;
-        if( rParams.getLength() != 2 )
-            throw CannotConvertException();
-
-        if( ! (rParams.getConstArray()[0] >>= xBM ) ||
-            ! ( rParams.getConstArray()[1] >>= nTargetDepth ) )
-            throw CannotConvertException();
-
-        Sequence< sal_Int8 > aDIB = xBM->getDIB();
-
-        // call into vcl not thread safe
-        SolarMutexGuard aGuard;
-
-        SvMemoryStream aStream( aDIB.getArray(), aDIB.getLength(), STREAM_READ | STREAM_WRITE );
-        Bitmap aBM;
-
-        ReadDIB(aBM, aStream, true);
-
-        if( nTargetDepth < 4 )
-            nTargetDepth = 1;
-        else if( nTargetDepth < 8 )
-            nTargetDepth = 4;
-        else if( nTargetDepth >8 && nTargetDepth < 24 )
-            nTargetDepth = 24;
-
-        if( aBM.GetBitCount() == 24 && nTargetDepth <= 8 )
-            aBM.Dither( BMP_DITHER_FLOYD );
-
-        if( aBM.GetBitCount() != nTargetDepth )
-        {
-            switch( nTargetDepth )
-            {
-                case 1:     aBM.Convert( BMP_CONVERSION_1BIT_THRESHOLD );break;
-                case 4:     aBM.ReduceColors( BMP_CONVERSION_4BIT_COLORS );break;
-                case 8:     aBM.ReduceColors( BMP_CONVERSION_8BIT_COLORS );break;
-                case 24:    aBM.Convert( BMP_CONVERSION_24BIT );break;
-            }
-        }
-        xBM = new BmpTransporter( aBM );
-        aRet <<= xBM;
-    }
-    else
-        throw InvocationTargetException();
-
-    return aRet;
-}
-
-BmpTransporter::BmpTransporter( const Bitmap& rBM )
-{
-    m_aSize.Width = rBM.GetSizePixel().Width();
-    m_aSize.Height = rBM.GetSizePixel().Height();
-
-    SvMemoryStream aStream;
-
-    WriteDIB(rBM, aStream, false, true);
-
-    m_aBM = Sequence<sal_Int8>(static_cast<const sal_Int8*>(aStream.GetData()),
-                aStream.GetEndOfData());
-}
-
-BmpTransporter::~BmpTransporter()
-{
-}
-
-com::sun::star::awt::Size SAL_CALL BmpTransporter::getSize() throw()
-{
-    return m_aSize;
-}
-
-Sequence< sal_Int8 > SAL_CALL BmpTransporter::getDIB() throw()
-{
-    return m_aBM;
-}
-
-Sequence< sal_Int8 > SAL_CALL BmpTransporter::getMaskDIB() throw()
-{
-    return Sequence< sal_Int8 >();
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx
index a0de356..dc450e3 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -43,7 +43,6 @@
 #include "vcl/wrkwin.hxx"
 #include "vcl/wall.hxx"
 #include "vcl/gradient.hxx"
-#include "vcl/salctype.hxx"
 #include "vcl/button.hxx"
 #include "vcl/taskpanelist.hxx"
 #include "vcl/dialog.hxx"
@@ -8423,16 +8422,12 @@ uno::Reference< XDragSource > Window::GetDragSource()
                     aDragSourceAL[ 1 ] = makeAny( static_cast<sal_uInt64>( reinterpret_cast<sal_IntPtr>(pEnvData->pView) ) );
                     aDropTargetAL[ 0 ] = makeAny( static_cast<sal_uInt64>( reinterpret_cast<sal_IntPtr>(pEnvData->pView) ) );
 #elif defined UNX
-                    aDropTargetAL.realloc( 3 );
-                    aDragSourceAL.realloc( 3 );
                     aDragSourceSN = OUString("com.sun.star.datatransfer.dnd.X11DragSource");
                     aDropTargetSN = OUString("com.sun.star.datatransfer.dnd.X11DropTarget");
 
                     aDragSourceAL[ 0 ] = makeAny( Application::GetDisplayConnection() );
-                    aDragSourceAL[ 2 ] = makeAny( vcl::createBmpConverter() );
                     aDropTargetAL[ 0 ] = makeAny( Application::GetDisplayConnection() );
                     aDropTargetAL[ 1 ] = makeAny( (sal_Size)(pEnvData->aShellWindow) );
-                    aDropTargetAL[ 2 ] = makeAny( vcl::createBmpConverter() );
 #endif
                     if( !aDragSourceSN.isEmpty() )
                         mpWindowImpl->mpFrameData->mxDragSource.set(
@@ -8515,10 +8510,9 @@ uno::Reference< XClipboard > Window::GetPrimarySelection()
 #if defined(UNX) && !defined(MACOSX)
                 // A hack, making the primary selection available as an instance of
                 // the SystemClipboard service on X11:
-                css::uno::Sequence<css::uno::Any> args(3);
+                css::uno::Sequence<css::uno::Any> args(2);
                 args[0] <<= Application::GetDisplayConnection();
                 args[1] <<= OUString("PRIMARY");
-                args[2] <<= vcl::createBmpConverter();
                 mpWindowImpl->mpFrameData->mxSelection.set(
                     (xContext->getServiceManager()->
                      createInstanceWithArgumentsAndContext(
diff --git a/vcl/unx/generic/dtrans/X11_selection.cxx b/vcl/unx/generic/dtrans/X11_selection.cxx
index 871580f..53207ca 100644
--- a/vcl/unx/generic/dtrans/X11_selection.cxx
+++ b/vcl/unx/generic/dtrans/X11_selection.cxx
@@ -341,12 +341,6 @@ void SelectionManager::initialize( const Sequence< Any >& arguments ) throw (::c
             m_xDisplayConnection->addEventHandler( Any(), this, ~0 );
     }
 
-    if( !m_xBitmapConverter.is() )
-    {
-        if( arguments.getLength() > 2 )
-            arguments.getConstArray()[2] >>= m_xBitmapConverter;
-    }
-
     if( ! m_pDisplay )
     {
         OUString aUDisplay;
@@ -1496,32 +1490,12 @@ bool SelectionManager::sendData( SelectionAdaptor* pAdaptor,
                     // the pixmap in another thread
                     pPixmap = getPixmapHolder( selection );
                     // conversion succeeded, so aData contains image/bmp now
-                    if( pPixmap->needsConversion( (const sal_uInt8*)aData.getConstArray() )
-                        && m_xBitmapConverter.is() )
+                    if( pPixmap->needsConversion( (const sal_uInt8*)aData.getConstArray() ) )
                     {
-#if OSL_DEBUG_LEVEL > 1
-                        fprintf( stderr, "trying bitmap conversion\n" );
-#endif
-                        css::uno::Reference<XBitmap> xBM( new BmpTransporter( aData ) );
-                        Sequence<Any> aArgs(2), aOutArgs;
-                        Sequence<sal_Int16> aOutIndex;
-                        aArgs.getArray()[0] = makeAny( xBM );
-                        aArgs.getArray()[1] = makeAny( (sal_uInt16)pPixmap->getDepth() );
+                        SAL_INFO( "vcl", "trying bitmap conversion" );
+                        int depth = pPixmap->getDepth();
                         aGuard.clear();
-                        try
-                        {
-                            Any aResult =
-                                m_xBitmapConverter->invoke( OUString("convert-bitmap-depth"),
-                                                            aArgs, aOutIndex, aOutArgs );
-                            if( aResult >>= xBM )
-                                aData = xBM->getDIB();
-                        }
-                        catch(...)
-                        {
-#if OSL_DEBUG_LEVEL > 1
-                            fprintf( stderr, "exception in bitmap converter\n" );
-#endif
-                        }
+                        aData = convertBitmapDepth(aData, depth);
                         aGuard.reset();
                     }
                     // get pixmap again since clearing the guard could have invalidated
diff --git a/vcl/unx/generic/dtrans/X11_selection.hxx b/vcl/unx/generic/dtrans/X11_selection.hxx
index 84b6c0a..d7948f5 100644
--- a/vcl/unx/generic/dtrans/X11_selection.hxx
+++ b/vcl/unx/generic/dtrans/X11_selection.hxx
@@ -28,7 +28,6 @@
 #include <com/sun/star/awt/XDisplayConnection.hpp>
 #include <com/sun/star/lang/XInitialization.hpp>
 #include <com/sun/star/lang/XServiceInfo.hpp>
-#include <com/sun/star/script/XInvocation.hpp>
 #include <com/sun/star/frame/XDesktop2.hpp>
 #include <osl/thread.h>
 
@@ -257,8 +256,6 @@ namespace x11 {
         com::sun::star::uno::Reference< ::com::sun::star::frame::XDesktop2 > m_xDesktop;
         com::sun::star::uno::Reference< ::com::sun::star::awt::XDisplayConnection >
                                     m_xDisplayConnection;
-        com::sun::star::uno::Reference< com::sun::star::script::XInvocation >
-                                    m_xBitmapConverter;
         sal_Int32                   m_nSelectionTimeout;
         XLIB_Time                   m_nSelectionTimestamp;
 
diff --git a/vcl/unx/generic/dtrans/bmp.cxx b/vcl/unx/generic/dtrans/bmp.cxx
index e7d2d51..06c5748 100644
--- a/vcl/unx/generic/dtrans/bmp.cxx
+++ b/vcl/unx/generic/dtrans/bmp.cxx
@@ -26,12 +26,13 @@
 
 #include <X11_selection.hxx>
 #include <unx/x11/xlimits.hxx>
+
 #include <sal/macros.h>
+#include <tools/stream.hxx>
+#include <vcl/dibtools.hxx>
+#include <vcl/svapp.hxx>
 
 using namespace x11;
-using namespace com::sun::star::uno;
-using namespace com::sun::star::script;
-using namespace com::sun::star::awt;
 
 /*
  *  helper functions
@@ -65,45 +66,6 @@ inline sal_uInt16 readLE32( const sal_uInt8* pBuffer )
         pBuffer[0];
 }
 
-
-/*
- * BmpTransporter
- */
-
-BmpTransporter::BmpTransporter( const Sequence<sal_Int8>& rBmp ) :
-        m_aBM( rBmp )
-{
-    const sal_uInt8* pData = (const sal_uInt8*)rBmp.getConstArray();
-
-    if( pData[0] == 'B' || pData[1] == 'M' )
-    {
-        pData = pData+14;
-        m_aSize.Width   = readLE32( pData+4 );
-        m_aSize.Height  = readLE32( pData+8 );
-    }
-    else
-        m_aSize.Width = m_aSize.Height = 0;
-}
-
-BmpTransporter::~BmpTransporter()
-{
-}
-
-com::sun::star::awt::Size SAL_CALL BmpTransporter::getSize() throw()
-{
-    return m_aSize;
-}
-
-Sequence< sal_Int8 > SAL_CALL BmpTransporter::getDIB() throw()
-{
-    return m_aBM;
-}
-
-Sequence< sal_Int8 > SAL_CALL BmpTransporter::getMaskDIB() throw()
-{
-    return Sequence< sal_Int8 >();
-}
-
 /*
  * scanline helpers
  */
@@ -729,4 +691,45 @@ Pixmap PixmapHolder::setBitmapData( const sal_uInt8* pData )
     return m_aPixmap;
 }
 
+css::uno::Sequence<sal_Int8> x11::convertBitmapDepth(
+    css::uno::Sequence<sal_Int8> const & data, int depth)
+{
+    if (depth < 4) {
+        depth = 1;
+    } else if (depth < 8) {
+        depth = 4;
+    } else if (depth > 8 && depth < 24) {
+        depth = 24;
+    }
+    SolarMutexGuard g;
+    SvMemoryStream in(
+        const_cast<sal_Int8 *>(data.getConstArray()), data.getLength(),
+        STREAM_READ);
+    Bitmap bm;
+    ReadDIB(bm, in, true);
+    if (bm.GetBitCount() == 24 && depth <= 8) {
+        bm.Dither(BMP_DITHER_FLOYD);
+    }
+    if (bm.GetBitCount() != depth) {
+        switch (depth) {
+        case 1:
+            bm.Convert(BMP_CONVERSION_1BIT_THRESHOLD);
+            break;
+        case 4:
+            bm.ReduceColors(BMP_CONVERSION_4BIT_COLORS);
+            break;
+        case 8:
+            bm.ReduceColors(BMP_CONVERSION_8BIT_COLORS);
+            break;
+        case 24:
+            bm.Convert(BMP_CONVERSION_24BIT);
+            break;
+        }
+    }
+    SvMemoryStream out;
+    WriteDIB(bm, out, false, true);
+    return css::uno::Sequence<sal_Int8>(
+        static_cast<sal_Int8 const *>(out.GetData()), out.GetEndOfData());
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/unx/generic/dtrans/bmp.hxx b/vcl/unx/generic/dtrans/bmp.hxx
index 13d159e..8fb9341 100644
--- a/vcl/unx/generic/dtrans/bmp.hxx
+++ b/vcl/unx/generic/dtrans/bmp.hxx
@@ -27,11 +27,8 @@
 #include <X11/Xutil.h>
 #include <postx.h>
 
+#include <com/sun/star/uno/Sequence.hxx>
 #include <sal/types.h>
-#include <com/sun/star/awt/XBitmap.hpp>
-#include <cppuhelper/compbase1.hxx>
-
-
 
 namespace x11 {
 
@@ -78,19 +75,8 @@ public:
     int getDepth() const { return m_aInfo.depth; }
 };
 
-class BmpTransporter :
-        public cppu::WeakImplHelper1< com::sun::star::awt::XBitmap >
-{
-    com::sun::star::uno::Sequence<sal_Int8>         m_aBM;
-    com::sun::star::awt::Size                       m_aSize;
-public:
-    BmpTransporter( const com::sun::star::uno::Sequence<sal_Int8>& rBmp );
-    virtual  ~BmpTransporter();
-
-    virtual com::sun::star::awt::Size SAL_CALL getSize() throw();
-    virtual com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getDIB() throw();
-    virtual com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getMaskDIB() throw();
-};
+css::uno::Sequence<sal_Int8> convertBitmapDepth(
+    css::uno::Sequence<sal_Int8> const & data, int depth);
 
 }
 


More information about the Libreoffice-commits mailing list