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