diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2013-07-11 12:40:25 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2013-07-11 13:22:33 +0200 |
commit | b100f3f06be2dd79c8145cdf487901bc5d71b332 (patch) | |
tree | 6d4033f11b87c7292258b00567b24697a9082ed6 /vcl/unx | |
parent | 3a58a0f9d3600d0475e1a2c6595785cfcf5f362e (diff) |
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
Diffstat (limited to 'vcl/unx')
-rw-r--r-- | vcl/unx/generic/dtrans/X11_selection.cxx | 34 | ||||
-rw-r--r-- | vcl/unx/generic/dtrans/X11_selection.hxx | 3 | ||||
-rw-r--r-- | vcl/unx/generic/dtrans/bmp.cxx | 87 | ||||
-rw-r--r-- | vcl/unx/generic/dtrans/bmp.hxx | 20 |
4 files changed, 52 insertions, 92 deletions
diff --git a/vcl/unx/generic/dtrans/X11_selection.cxx b/vcl/unx/generic/dtrans/X11_selection.cxx index 871580f63c50..53207ca900ba 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 84b6c0adc6cd..d7948f586293 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 e7d2d51272e5..06c57486d03d 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 13d159ee37f3..8fb93410d33a 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); } |