summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2013-07-11 12:40:25 +0200
committerStephan Bergmann <sbergman@redhat.com>2013-07-11 13:22:33 +0200
commitb100f3f06be2dd79c8145cdf487901bc5d71b332 (patch)
tree6d4033f11b87c7292258b00567b24697a9082ed6 /vcl
parent3a58a0f9d3600d0475e1a2c6595785cfcf5f362e (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')
-rw-r--r--vcl/Library_vcl.mk1
-rw-r--r--vcl/source/gdi/bmpconv.cxx209
-rw-r--r--vcl/source/window/window.cxx8
-rw-r--r--vcl/unx/generic/dtrans/X11_selection.cxx34
-rw-r--r--vcl/unx/generic/dtrans/X11_selection.hxx3
-rw-r--r--vcl/unx/generic/dtrans/bmp.cxx87
-rw-r--r--vcl/unx/generic/dtrans/bmp.hxx20
7 files changed, 53 insertions, 309 deletions
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index 6216d679161c..3c56c4495423 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 24bb15961398..000000000000
--- 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 a0de356ff3eb..dc450e378dd8 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 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);
}