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 : : #include "headless/svpbmp.hxx"
30 : :
31 : : #include <basegfx/vector/b2ivector.hxx>
32 : : #include <basegfx/range/b2ibox.hxx>
33 : : #include <basebmp/scanlineformats.hxx>
34 : : #include <basebmp/color.hxx>
35 : :
36 : : #include <vcl/salbtype.hxx>
37 : : #include <vcl/bitmap.hxx>
38 : :
39 : : using namespace basebmp;
40 : : using namespace basegfx;
41 : :
42 [ + - ][ + - ]: 884295 : SvpSalBitmap::~SvpSalBitmap()
43 : : {
44 [ - + ]: 1768590 : }
45 : :
46 : 250924 : bool SvpSalBitmap::Create( const Size& rSize,
47 : : sal_uInt16 nBitCount,
48 : : const BitmapPalette& rPalette )
49 : : {
50 : 250924 : sal_uInt32 nFormat = SVP_DEFAULT_BITMAP_FORMAT;
51 [ + + + - : 250924 : switch( nBitCount )
+ - - ]
52 : : {
53 : 1189 : case 1: nFormat = Format::ONE_BIT_MSB_PAL; break;
54 : 442 : case 4: nFormat = Format::FOUR_BIT_MSB_PAL; break;
55 : 110987 : case 8: nFormat = Format::EIGHT_BIT_PAL; break;
56 : : #ifdef OSL_BIGENDIAN
57 : : case 16: nFormat = Format::SIXTEEN_BIT_MSB_TC_MASK; break;
58 : : #else
59 : 0 : case 16: nFormat = Format::SIXTEEN_BIT_LSB_TC_MASK; break;
60 : : #endif
61 : 138306 : case 24: nFormat = Format::TWENTYFOUR_BIT_TC_MASK; break;
62 : : #if defined(ANDROID) || defined(IOS)
63 : : case 32: nFormat = Format::THIRTYTWO_BIT_TC_MASK_RGBA; break;
64 : : #else
65 : 0 : case 32: nFormat = Format::THIRTYTWO_BIT_TC_MASK; break;
66 : : #endif
67 : : }
68 : 250924 : B2IVector aSize( rSize.Width(), rSize.Height() );
69 [ - + ]: 250924 : if( aSize.getX() == 0 )
70 : 0 : aSize.setX( 1 );
71 [ - + ]: 250924 : if( aSize.getY() == 0 )
72 : 0 : aSize.setY( 1 );
73 [ + + ]: 250924 : if( nBitCount > 8 )
74 [ + - ][ + - ]: 138306 : m_aBitmap = createBitmapDevice( aSize, false, nFormat );
[ + - ]
75 : : else
76 : : {
77 : : // prepare palette
78 : 112618 : unsigned int nEntries = 1U << nBitCount;
79 : : std::vector<basebmp::Color>* pPalette =
80 [ + - ][ + - ]: 112618 : new std::vector<basebmp::Color>( nEntries, basebmp::Color(COL_WHITE) );
81 : 112618 : unsigned int nColors = rPalette.GetEntryCount();
82 [ + + ]: 28529508 : for( unsigned int i = 0; i < nColors; i++ )
83 : : {
84 : 28416890 : const BitmapColor& rCol = rPalette[i];
85 : 28416890 : (*pPalette)[i] = basebmp::Color( rCol.GetRed(), rCol.GetGreen(), rCol.GetBlue() );
86 : : }
87 : : m_aBitmap = createBitmapDevice( aSize, false, nFormat,
88 : : basebmp::RawMemorySharedArray(),
89 : : basebmp::PaletteMemorySharedVector( pPalette )
90 [ + - ][ + - ]: 112618 : );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
91 : : }
92 : 250924 : return true;
93 : : }
94 : :
95 : 207847 : bool SvpSalBitmap::Create( const SalBitmap& rSalBmp )
96 : : {
97 : 207847 : const SvpSalBitmap& rSrc = static_cast<const SvpSalBitmap&>(rSalBmp);
98 : 207847 : const BitmapDeviceSharedPtr& rSrcBmp = rSrc.getBitmap();
99 [ + - ]: 207847 : if( rSrcBmp.get() )
100 : : {
101 [ + - ]: 207847 : B2IVector aSize = rSrcBmp->getSize();
102 [ + - ][ + - ]: 207847 : m_aBitmap = cloneBitmapDevice( aSize, rSrcBmp );
[ + - ]
103 [ + - ]: 207847 : B2IBox aRect( 0, 0, aSize.getX(), aSize.getY() );
104 [ + - ]: 207847 : m_aBitmap->drawBitmap( rSrcBmp, aRect, aRect, DrawMode_PAINT );
105 : : }
106 : : else
107 : 0 : m_aBitmap.reset();
108 : :
109 : 207847 : return true;
110 : : }
111 : :
112 : 6 : bool SvpSalBitmap::Create( const SalBitmap& /*rSalBmp*/,
113 : : SalGraphics* /*pGraphics*/ )
114 : : {
115 : 6 : return false;
116 : : }
117 : :
118 : 6 : bool SvpSalBitmap::Create( const SalBitmap& /*rSalBmp*/,
119 : : sal_uInt16 /*nNewBitCount*/ )
120 : : {
121 : 6 : return false;
122 : : }
123 : :
124 : 0 : bool SvpSalBitmap::Create( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmapCanvas > /*xBitmapCanvas*/, Size& /*rSize*/, bool /*bMask*/ )
125 : : {
126 : 0 : return false;
127 : : }
128 : :
129 : 0 : void SvpSalBitmap::Destroy()
130 : : {
131 : 0 : m_aBitmap.reset();
132 : 0 : }
133 : :
134 : 1678756 : Size SvpSalBitmap::GetSize() const
135 : : {
136 : 1678756 : Size aSize;
137 [ + - ]: 1678756 : if( m_aBitmap.get() )
138 : : {
139 [ + - ]: 1678756 : B2IVector aVec( m_aBitmap->getSize() );
140 : 1678756 : aSize = Size( aVec.getX(), aVec.getY() );
141 : : }
142 : :
143 : 1678756 : return aSize;
144 : : }
145 : :
146 : 472379 : sal_uInt16 SvpSalBitmap::GetBitCount() const
147 : : {
148 : 472379 : sal_uInt16 nDepth = 0;
149 [ + + ]: 472379 : if( m_aBitmap.get() )
150 : 472373 : nDepth = getBitCountFromScanlineFormat( m_aBitmap->getScanlineFormat() );
151 : 472379 : return nDepth;
152 : : }
153 : :
154 : 1279948 : BitmapBuffer* SvpSalBitmap::AcquireBuffer( bool )
155 : : {
156 : 1279948 : BitmapBuffer* pBuf = NULL;
157 [ + + ]: 1279948 : if( m_aBitmap.get() )
158 : : {
159 [ + - ][ + - ]: 1279942 : pBuf = new BitmapBuffer();
160 : 1279942 : sal_uInt16 nBitCount = 1;
161 [ + - ][ + - : 1279942 : switch( m_aBitmap->getScanlineFormat() )
+ - + - -
- + - - -
- - ]
162 : : {
163 : : case Format::ONE_BIT_MSB_GREY:
164 : : case Format::ONE_BIT_MSB_PAL:
165 : 6003 : nBitCount = 1;
166 : 6003 : pBuf->mnFormat = BMP_FORMAT_1BIT_MSB_PAL;
167 : 6003 : break;
168 : : case Format::ONE_BIT_LSB_GREY:
169 : : case Format::ONE_BIT_LSB_PAL:
170 : 0 : nBitCount = 1;
171 : 0 : pBuf->mnFormat = BMP_FORMAT_1BIT_LSB_PAL;
172 : 0 : break;
173 : : case Format::FOUR_BIT_MSB_GREY:
174 : : case Format::FOUR_BIT_MSB_PAL:
175 : 838 : nBitCount = 4;
176 : 838 : pBuf->mnFormat = BMP_FORMAT_4BIT_MSN_PAL;
177 : 838 : break;
178 : : case Format::FOUR_BIT_LSB_GREY:
179 : : case Format::FOUR_BIT_LSB_PAL:
180 : 0 : nBitCount = 4;
181 : 0 : pBuf->mnFormat = BMP_FORMAT_4BIT_LSN_PAL;
182 : 0 : break;
183 : : case Format::EIGHT_BIT_PAL:
184 : 652411 : nBitCount = 8;
185 : 652411 : pBuf->mnFormat = BMP_FORMAT_8BIT_PAL;
186 : 652411 : break;
187 : : case Format::EIGHT_BIT_GREY:
188 : 0 : nBitCount = 8;
189 : 0 : pBuf->mnFormat = BMP_FORMAT_8BIT_PAL;
190 : 0 : break;
191 : : case Format::SIXTEEN_BIT_LSB_TC_MASK:
192 : 0 : nBitCount = 16;
193 : 0 : pBuf->mnFormat = BMP_FORMAT_16BIT_TC_LSB_MASK;
194 [ # # ]: 0 : pBuf->maColorMask = ColorMask( 0xf800, 0x07e0, 0x001f );
195 : 0 : break;
196 : : case Format::SIXTEEN_BIT_MSB_TC_MASK:
197 : 0 : nBitCount = 16;
198 : 0 : pBuf->mnFormat = BMP_FORMAT_16BIT_TC_MSB_MASK;
199 [ # # ]: 0 : pBuf->maColorMask = ColorMask( 0xf800, 0x07e0, 0x001f );
200 : 0 : break;
201 : : case Format::TWENTYFOUR_BIT_TC_MASK:
202 : 620690 : nBitCount = 24;
203 : 620690 : pBuf->mnFormat = BMP_FORMAT_24BIT_TC_BGR;
204 : 620690 : break;
205 : : case Format::THIRTYTWO_BIT_TC_MASK_BGRA:
206 : 0 : nBitCount = 32;
207 : 0 : pBuf->mnFormat = BMP_FORMAT_32BIT_TC_MASK;
208 : : #ifdef OSL_BIGENDIAN
209 : : pBuf->maColorMask = ColorMask( 0x0000ff00, 0x00ff0000, 0xff000000 );
210 : : #else
211 [ # # ]: 0 : pBuf->maColorMask = ColorMask( 0x00ff0000, 0x0000ff00, 0x000000ff );
212 : : #endif
213 : 0 : break;
214 : : case Format::THIRTYTWO_BIT_TC_MASK_ARGB:
215 : 0 : nBitCount = 32;
216 : 0 : pBuf->mnFormat = BMP_FORMAT_32BIT_TC_MASK;
217 : : #ifdef OSL_BIGENDIAN
218 : : pBuf->maColorMask = ColorMask( 0x00ff0000, 0x0000ff00, 0x000000ff );
219 : : #else
220 [ # # ]: 0 : pBuf->maColorMask = ColorMask( 0x0000ff00, 0x00ff0000, 0xff000000 );
221 : : #endif
222 : 0 : break;
223 : : case Format::THIRTYTWO_BIT_TC_MASK_ABGR:
224 : 0 : nBitCount = 32;
225 : 0 : pBuf->mnFormat = BMP_FORMAT_32BIT_TC_MASK;
226 : : #ifdef OSL_BIGENDIAN
227 : : pBuf->maColorMask = ColorMask( 0x000000ff, 0x0000ff00, 0x00ff0000 );
228 : : #else
229 [ # # ]: 0 : pBuf->maColorMask = ColorMask( 0xff000000, 0x00ff0000, 0x0000ff00 );
230 : : #endif
231 : 0 : break;
232 : : case Format::THIRTYTWO_BIT_TC_MASK_RGBA:
233 : 0 : nBitCount = 32;
234 : 0 : pBuf->mnFormat = BMP_FORMAT_32BIT_TC_MASK;
235 : : #ifdef OSL_BIGENDIAN
236 : : pBuf->maColorMask = ColorMask( 0xff000000, 0x00ff0000, 0x0000ff00 );
237 : : #else
238 [ # # ]: 0 : pBuf->maColorMask = ColorMask( 0x000000ff, 0x0000ff00, 0x00ff0000 );
239 : : #endif
240 : 0 : break;
241 : :
242 : : default:
243 : : // this is an error case !!!!!
244 : 0 : nBitCount = 1;
245 : 0 : pBuf->mnFormat = BMP_FORMAT_1BIT_MSB_PAL;
246 : 0 : break;
247 : : }
248 [ + - ][ - + ]: 1279942 : if( m_aBitmap->isTopDown() )
249 : 0 : pBuf->mnFormat |= BMP_FORMAT_TOP_DOWN;
250 : :
251 [ + - ]: 1279942 : B2IVector aSize = m_aBitmap->getSize();
252 : 1279942 : pBuf->mnWidth = aSize.getX();
253 : 1279942 : pBuf->mnHeight = aSize.getY();
254 [ + - ]: 1279942 : pBuf->mnScanlineSize = m_aBitmap->getScanlineStride();
255 : 1279942 : pBuf->mnBitCount = nBitCount;
256 [ + - ][ + - ]: 1279942 : pBuf->mpBits = (sal_uInt8*)m_aBitmap->getBuffer().get();
257 [ + + ]: 1279942 : if( nBitCount <= 8 )
258 : : {
259 [ + - ][ + - ]: 3296260 : if( m_aBitmap->getScanlineFormat() == Format::EIGHT_BIT_GREY ||
[ + - ][ + - ]
[ + - ][ - + ]
[ - + ]
260 [ + - ]: 659252 : m_aBitmap->getScanlineFormat() == Format::FOUR_BIT_LSB_GREY ||
261 [ + - ]: 659252 : m_aBitmap->getScanlineFormat() == Format::FOUR_BIT_MSB_GREY ||
262 [ + - ]: 659252 : m_aBitmap->getScanlineFormat() == Format::ONE_BIT_LSB_GREY ||
263 [ + - ]: 659252 : m_aBitmap->getScanlineFormat() == Format::ONE_BIT_MSB_GREY
264 : : )
265 [ # # ][ # # ]: 0 : pBuf->maPalette = Bitmap::GetGreyPalette( 1U << nBitCount );
266 : : else
267 : : {
268 [ + - ]: 659252 : basebmp::PaletteMemorySharedVector aPalette = m_aBitmap->getPalette();
269 [ + - ]: 659252 : if( aPalette.get() )
270 : : {
271 : 659252 : unsigned int nColors = aPalette->size();
272 [ + - ]: 659252 : if( nColors > 0 )
273 : : {
274 [ + - ]: 659252 : pBuf->maPalette.SetEntryCount( nColors );
275 [ + + ]: 167701882 : for( unsigned int i = 0; i < nColors; i++ )
276 : : {
277 : 167042630 : const basebmp::Color& rCol = (*aPalette)[i];
278 : 167042630 : pBuf->maPalette[i] = BitmapColor( rCol.getRed(), rCol.getGreen(), rCol.getBlue() );
279 : : }
280 : : }
281 [ + - ]: 659252 : }
282 : : }
283 : 1279942 : }
284 : : }
285 : :
286 : 1279948 : return pBuf;
287 : : }
288 : :
289 : 1279942 : void SvpSalBitmap::ReleaseBuffer( BitmapBuffer* pBuffer, bool bReadOnly )
290 : : {
291 [ + + ][ + + ]: 1279942 : if( !bReadOnly && pBuffer->maPalette.GetEntryCount() )
[ + + ]
292 : : {
293 : : // palette might have changed, clone device (but recycle
294 : : // memory)
295 : 134390 : sal_uInt16 nBitCount = 0;
296 [ + + + - ]: 134390 : switch( m_aBitmap->getScanlineFormat() )
297 : : {
298 : : case Format::ONE_BIT_MSB_GREY:
299 : : // FALLTHROUGH intended
300 : : case Format::ONE_BIT_MSB_PAL:
301 : : // FALLTHROUGH intended
302 : : case Format::ONE_BIT_LSB_GREY:
303 : : // FALLTHROUGH intended
304 : : case Format::ONE_BIT_LSB_PAL:
305 : 1218 : nBitCount = 1;
306 : 1218 : break;
307 : :
308 : : case Format::FOUR_BIT_MSB_GREY:
309 : : // FALLTHROUGH intended
310 : : case Format::FOUR_BIT_MSB_PAL:
311 : : // FALLTHROUGH intended
312 : : case Format::FOUR_BIT_LSB_GREY:
313 : : // FALLTHROUGH intended
314 : : case Format::FOUR_BIT_LSB_PAL:
315 : 588 : nBitCount = 4;
316 : 588 : break;
317 : :
318 : : case Format::EIGHT_BIT_PAL:
319 : : // FALLTHROUGH intended
320 : : case Format::EIGHT_BIT_GREY:
321 : 132584 : nBitCount = 8;
322 : 132584 : break;
323 : :
324 : : default:
325 : 0 : break;
326 : : }
327 : :
328 [ + - ]: 134390 : if( nBitCount )
329 : : {
330 : 134390 : sal_uInt32 nEntries = 1U << nBitCount;
331 : :
332 : : boost::shared_ptr< std::vector<basebmp::Color> > pPal(
333 : : new std::vector<basebmp::Color>( nEntries,
334 [ + - ][ + - ]: 134390 : basebmp::Color(COL_WHITE)));
[ + - ]
335 : : const sal_uInt32 nColors = std::min(
336 : 134390 : (sal_uInt32)pBuffer->maPalette.GetEntryCount(),
337 [ + - ]: 134390 : nEntries);
338 [ + + ]: 33921237 : for( sal_uInt32 i = 0; i < nColors; i++ )
339 : : {
340 : 33786847 : const BitmapColor& rCol = pBuffer->maPalette[i];
341 : 33786847 : (*pPal)[i] = basebmp::Color( rCol.GetRed(), rCol.GetGreen(), rCol.GetBlue() );
342 : : }
343 : :
344 : : m_aBitmap = basebmp::createBitmapDevice( m_aBitmap->getSize(),
345 [ + - ]: 134390 : m_aBitmap->isTopDown(),
346 : : m_aBitmap->getScanlineFormat(),
347 : : m_aBitmap->getBuffer(),
348 [ + - ][ + - ]: 268780 : pPal );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
349 : : }
350 : : }
351 : :
352 [ + - ]: 1279942 : delete pBuffer;
353 : 1279942 : }
354 : :
355 : 0 : bool SvpSalBitmap::GetSystemData( BitmapSystemData& )
356 : : {
357 : 0 : return false;
358 : : }
359 : :
360 : :
361 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|