Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "vcl/bitmap.hxx"
31 : : #include "vcl/svapp.hxx"
32 : : #include "vcl/salctype.hxx"
33 : : #include <osl/mutex.hxx>
34 : : #include "tools/stream.hxx"
35 : : #include "com/sun/star/script/XInvocation.hpp"
36 : : #include "com/sun/star/awt/XBitmap.hpp"
37 : : #include "cppuhelper/compbase1.hxx"
38 : :
39 : :
40 : : using namespace com::sun::star::uno;
41 : : using namespace com::sun::star::script;
42 : : using namespace com::sun::star::beans;
43 : : using namespace com::sun::star::reflection;
44 : : using namespace com::sun::star::awt;
45 : :
46 : : using ::rtl::OUString;
47 : :
48 : : namespace vcl {
49 : :
50 : : class BmpTransporter :
51 : : public cppu::WeakImplHelper1< com::sun::star::awt::XBitmap >
52 : : {
53 : : Sequence<sal_Int8> m_aBM;
54 : : com::sun::star::awt::Size m_aSize;
55 : : public:
56 : : BmpTransporter( const Bitmap& rBM );
57 : : virtual ~BmpTransporter();
58 : :
59 : : virtual com::sun::star::awt::Size SAL_CALL getSize() throw();
60 : : virtual Sequence< sal_Int8 > SAL_CALL getDIB() throw();
61 : : virtual Sequence< sal_Int8 > SAL_CALL getMaskDIB() throw();
62 : : };
63 : :
64 : : class BmpConverter :
65 : : public cppu::WeakImplHelper1< com::sun::star::script::XInvocation >
66 : : {
67 : : public:
68 : : BmpConverter();
69 : : virtual ~BmpConverter();
70 : :
71 : : virtual Reference< XIntrospectionAccess > SAL_CALL getIntrospection() throw();
72 : : virtual void SAL_CALL setValue( const OUString& rProperty, const Any& rValue )
73 : : throw( UnknownPropertyException );
74 : : virtual Any SAL_CALL getValue( const OUString& rProperty )
75 : : throw( UnknownPropertyException );
76 : : virtual sal_Bool SAL_CALL hasMethod( const OUString& rName ) throw();
77 : : virtual sal_Bool SAL_CALL hasProperty( const OUString& rProp ) throw();
78 : :
79 : : virtual Any SAL_CALL invoke( const OUString& rFunction,
80 : : const Sequence< Any >& rParams,
81 : : Sequence< sal_Int16 >& rOutParamIndex,
82 : : Sequence< Any >& rOutParam
83 : : )
84 : : throw( CannotConvertException, InvocationTargetException );
85 : : };
86 : :
87 : : }
88 : :
89 : : using namespace vcl;
90 : :
91 : 6751 : Reference< XInvocation > vcl::createBmpConverter()
92 : : {
93 [ + - ][ + - ]: 6751 : return static_cast<XInvocation*>(new BmpConverter());
94 : : }
95 : :
96 : 6751 : BmpConverter::BmpConverter()
97 : : {
98 : 6751 : }
99 : :
100 : 6751 : BmpConverter::~BmpConverter()
101 : : {
102 [ - + ]: 13502 : }
103 : :
104 : 0 : Reference< XIntrospectionAccess > SAL_CALL BmpConverter::getIntrospection() throw()
105 : : {
106 : 0 : return Reference< XIntrospectionAccess >();
107 : : }
108 : :
109 : 0 : void SAL_CALL BmpConverter::setValue( const OUString&, const Any& ) throw( UnknownPropertyException )
110 : : {
111 [ # # ]: 0 : throw UnknownPropertyException();
112 : : }
113 : :
114 : 0 : Any SAL_CALL BmpConverter::getValue( const OUString& ) throw( UnknownPropertyException )
115 : : {
116 [ # # ]: 0 : throw UnknownPropertyException();
117 : : }
118 : :
119 : 0 : sal_Bool SAL_CALL BmpConverter::hasMethod( const OUString& rName ) throw()
120 : : {
121 : 0 : return rName.equalsIgnoreAsciiCase( OUString("convert-bitmap-depth") );
122 : : }
123 : :
124 : 0 : sal_Bool SAL_CALL BmpConverter::hasProperty( const OUString& ) throw()
125 : : {
126 : 0 : return sal_False;
127 : : }
128 : :
129 : 0 : Any SAL_CALL BmpConverter::invoke(
130 : : const OUString& rFunction,
131 : : const Sequence< Any >& rParams,
132 : : Sequence< sal_Int16 >&,
133 : : Sequence< Any >& )
134 : : throw( CannotConvertException, InvocationTargetException )
135 : : {
136 : 0 : Any aRet;
137 : :
138 [ # # ]: 0 : if( rFunction.equalsIgnoreAsciiCase( OUString("convert-bitmap-depth") ) )
139 : : {
140 : 0 : Reference< XBitmap > xBM;
141 : 0 : sal_uInt16 nTargetDepth = 0;
142 [ # # ]: 0 : if( rParams.getLength() != 2 )
143 [ # # ]: 0 : throw CannotConvertException();
144 : :
145 [ # # ]: 0 : if( ! (rParams.getConstArray()[0] >>= xBM ) ||
[ # # # # ]
[ # # ]
146 : 0 : ! ( rParams.getConstArray()[1] >>= nTargetDepth ) )
147 [ # # ]: 0 : throw CannotConvertException();
148 : :
149 [ # # ][ # # ]: 0 : Sequence< sal_Int8 > aDIB = xBM->getDIB();
150 : :
151 : : // call into vcl not thread safe
152 [ # # ]: 0 : SolarMutexGuard aGuard;
153 : :
154 [ # # ][ # # ]: 0 : SvMemoryStream aStream( aDIB.getArray(), aDIB.getLength(), STREAM_READ | STREAM_WRITE );
155 [ # # ]: 0 : Bitmap aBM;
156 [ # # ]: 0 : aBM.Read( aStream, sal_True );
157 [ # # ]: 0 : if( nTargetDepth < 4 )
158 : 0 : nTargetDepth = 1;
159 [ # # ]: 0 : else if( nTargetDepth < 8 )
160 : 0 : nTargetDepth = 4;
161 [ # # ][ # # ]: 0 : else if( nTargetDepth >8 && nTargetDepth < 24 )
162 : 0 : nTargetDepth = 24;
163 : :
164 [ # # ][ # # ]: 0 : if( aBM.GetBitCount() == 24 && nTargetDepth <= 8 )
[ # # ][ # # ]
165 [ # # ]: 0 : aBM.Dither( BMP_DITHER_FLOYD );
166 : :
167 [ # # ][ # # ]: 0 : if( aBM.GetBitCount() != nTargetDepth )
168 : : {
169 [ # # # # : 0 : switch( nTargetDepth )
# ]
170 : : {
171 [ # # ]: 0 : case 1: aBM.Convert( BMP_CONVERSION_1BIT_THRESHOLD );break;
172 [ # # ]: 0 : case 4: aBM.ReduceColors( BMP_CONVERSION_4BIT_COLORS );break;
173 [ # # ]: 0 : case 8: aBM.ReduceColors( BMP_CONVERSION_8BIT_COLORS );break;
174 [ # # ]: 0 : case 24: aBM.Convert( BMP_CONVERSION_24BIT );break;
175 : : }
176 : : }
177 [ # # ][ # # ]: 0 : xBM = new BmpTransporter( aBM );
[ # # ]
178 [ # # ][ # # ]: 0 : aRet <<= xBM;
[ # # ][ # # ]
[ # # ]
179 : : }
180 : : else
181 [ # # ]: 0 : throw InvocationTargetException();
182 : :
183 : 0 : return aRet;
184 : : }
185 : :
186 [ # # ]: 0 : BmpTransporter::BmpTransporter( const Bitmap& rBM )
187 : : {
188 [ # # ]: 0 : m_aSize.Width = rBM.GetSizePixel().Width();
189 [ # # ]: 0 : m_aSize.Height = rBM.GetSizePixel().Height();
190 [ # # ]: 0 : SvMemoryStream aStream;
191 [ # # ]: 0 : rBM.Write( aStream, sal_False, sal_True );
192 [ # # ]: 0 : m_aBM = Sequence<sal_Int8>(static_cast<const sal_Int8*>(aStream.GetData()),
193 [ # # ][ # # ]: 0 : aStream.GetEndOfData());
[ # # ][ # # ]
194 : 0 : }
195 : :
196 [ # # ]: 0 : BmpTransporter::~BmpTransporter()
197 : : {
198 [ # # ]: 0 : }
199 : :
200 : 0 : com::sun::star::awt::Size SAL_CALL BmpTransporter::getSize() throw()
201 : : {
202 : 0 : return m_aSize;
203 : : }
204 : :
205 : 0 : Sequence< sal_Int8 > SAL_CALL BmpTransporter::getDIB() throw()
206 : : {
207 : 0 : return m_aBM;
208 : : }
209 : :
210 : 0 : Sequence< sal_Int8 > SAL_CALL BmpTransporter::getMaskDIB() throw()
211 : : {
212 : 0 : return Sequence< sal_Int8 >();
213 : : }
214 : :
215 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|