1*6d739b60SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*6d739b60SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*6d739b60SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*6d739b60SAndrew Rist  * distributed with this work for additional information
6*6d739b60SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*6d739b60SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*6d739b60SAndrew Rist  * "License"); you may not use this file except in compliance
9*6d739b60SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*6d739b60SAndrew Rist  *
11*6d739b60SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*6d739b60SAndrew Rist  *
13*6d739b60SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*6d739b60SAndrew Rist  * software distributed under the License is distributed on an
15*6d739b60SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*6d739b60SAndrew Rist  * KIND, either express or implied.  See the License for the
17*6d739b60SAndrew Rist  * specific language governing permissions and limitations
18*6d739b60SAndrew Rist  * under the License.
19*6d739b60SAndrew Rist  *
20*6d739b60SAndrew Rist  *************************************************************/
21*6d739b60SAndrew Rist 
22*6d739b60SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_framework.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <classes/imagewrapper.hxx>
28cdf0e10cSrcweir #include <osl/mutex.hxx>
29cdf0e10cSrcweir #include <vcl/svapp.hxx>
30cdf0e10cSrcweir #include <vcl/bitmap.hxx>
31cdf0e10cSrcweir #include <vcl/bitmapex.hxx>
32cdf0e10cSrcweir #include <tools/stream.hxx>
33cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir using namespace com::sun::star::lang;
36cdf0e10cSrcweir using namespace com::sun::star::uno;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir namespace framework
39cdf0e10cSrcweir {
40cdf0e10cSrcweir 
41cdf0e10cSrcweir static Sequence< sal_Int8 > impl_getStaticIdentifier()
42cdf0e10cSrcweir {
43cdf0e10cSrcweir     static sal_uInt8 pGUID[16] = { 0x46, 0xAD, 0x69, 0xFB, 0xA7, 0xBE, 0x44, 0x83, 0xB2, 0xA7, 0xB3, 0xEC, 0x59, 0x4A, 0xB7, 0x00 };
44cdf0e10cSrcweir     static ::com::sun::star::uno::Sequence< sal_Int8 > seqID((sal_Int8*)pGUID,16) ;
45cdf0e10cSrcweir     return seqID ;
46cdf0e10cSrcweir }
47cdf0e10cSrcweir 
48cdf0e10cSrcweir 
49cdf0e10cSrcweir ImageWrapper::ImageWrapper( const Image& aImage ) : ThreadHelpBase( &Application::GetSolarMutex() )
50cdf0e10cSrcweir 													,	m_aImage( aImage )
51cdf0e10cSrcweir {
52cdf0e10cSrcweir }
53cdf0e10cSrcweir 
54cdf0e10cSrcweir 
55cdf0e10cSrcweir ImageWrapper::~ImageWrapper()
56cdf0e10cSrcweir {
57cdf0e10cSrcweir }
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 
60cdf0e10cSrcweir Sequence< sal_Int8 > ImageWrapper::GetUnoTunnelId()
61cdf0e10cSrcweir {
62cdf0e10cSrcweir 	return impl_getStaticIdentifier();
63cdf0e10cSrcweir }
64cdf0e10cSrcweir 
65cdf0e10cSrcweir // XBitmap
66cdf0e10cSrcweir com::sun::star::awt::Size SAL_CALL ImageWrapper::getSize() throw ( RuntimeException )
67cdf0e10cSrcweir {
68cdf0e10cSrcweir 	vos::OGuard	aGuard( Application::GetSolarMutex() );
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 	BitmapEx	aBitmapEx( m_aImage.GetBitmapEx() );
71cdf0e10cSrcweir 	Size		aBitmapSize( aBitmapEx.GetSizePixel() );
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 	return com::sun::star::awt::Size( aBitmapSize.Width(), aBitmapSize.Height() );
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir Sequence< sal_Int8 > SAL_CALL ImageWrapper::getDIB() throw ( RuntimeException )
77cdf0e10cSrcweir {
78cdf0e10cSrcweir 	vos::OGuard	aGuard( Application::GetSolarMutex() );
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 	SvMemoryStream aMem;
81cdf0e10cSrcweir 	aMem << m_aImage.GetBitmapEx().GetBitmap();
82cdf0e10cSrcweir 	return Sequence< sal_Int8 >( (sal_Int8*) aMem.GetData(), aMem.Tell() );
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir Sequence< sal_Int8 > SAL_CALL ImageWrapper::getMaskDIB() throw ( RuntimeException )
86cdf0e10cSrcweir {
87cdf0e10cSrcweir 	vos::OGuard	aGuard( Application::GetSolarMutex() );
88cdf0e10cSrcweir 	BitmapEx 	aBmpEx( m_aImage.GetBitmapEx() );
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 	if ( aBmpEx.IsAlpha() )
91cdf0e10cSrcweir 	{
92cdf0e10cSrcweir 		SvMemoryStream aMem;
93cdf0e10cSrcweir 		aMem << aBmpEx.GetAlpha().GetBitmap();
94cdf0e10cSrcweir 		return Sequence< sal_Int8 >( (sal_Int8*) aMem.GetData(), aMem.Tell() );
95cdf0e10cSrcweir 	}
96cdf0e10cSrcweir 	else if ( aBmpEx.IsTransparent() )
97cdf0e10cSrcweir 	{
98cdf0e10cSrcweir 		SvMemoryStream aMem;
99cdf0e10cSrcweir 		aMem << aBmpEx.GetMask();
100cdf0e10cSrcweir 		return Sequence< sal_Int8 >( (sal_Int8*) aMem.GetData(), aMem.Tell() );
101cdf0e10cSrcweir 	}
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 	return Sequence< sal_Int8 >();
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir // XUnoTunnel
107cdf0e10cSrcweir sal_Int64 SAL_CALL ImageWrapper::getSomething( const Sequence< sal_Int8 >& aIdentifier ) throw ( RuntimeException )
108cdf0e10cSrcweir {
109cdf0e10cSrcweir     if ( aIdentifier == impl_getStaticIdentifier() )
110cdf0e10cSrcweir         return reinterpret_cast< sal_Int64 >( this );
111cdf0e10cSrcweir     else
112cdf0e10cSrcweir         return 0;
113cdf0e10cSrcweir }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
117