Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef IOS
21 :
22 : #include "headless/svpbmp.hxx"
23 : #include "headless/svpinst.hxx"
24 :
25 : #include <basegfx/vector/b2ivector.hxx>
26 : #include <basegfx/range/b2ibox.hxx>
27 : #include <basebmp/scanlineformats.hxx>
28 : #include <basebmp/color.hxx>
29 :
30 : #include <vcl/salbtype.hxx>
31 : #include <vcl/bitmap.hxx>
32 :
33 : using namespace basebmp;
34 : using namespace basegfx;
35 :
36 1308342 : SvpSalBitmap::~SvpSalBitmap()
37 : {
38 1308342 : }
39 :
40 111419 : bool SvpSalBitmap::Create( const Size& rSize,
41 : sal_uInt16 nBitCount,
42 : const BitmapPalette& rPalette )
43 : {
44 : SAL_INFO( "vcl.headless", "SvpSalBitmap::Create(" << rSize.Width() << "," << rSize.Height() << "," << nBitCount << ")" );
45 :
46 111419 : SvpSalInstance* pInst = SvpSalInstance::s_pDefaultInstance;
47 : assert( pInst );
48 111419 : basebmp::Format nFormat = pInst->getFormatForBitCount( nBitCount );
49 :
50 111419 : B2IVector aSize( rSize.Width(), rSize.Height() );
51 111419 : if( aSize.getX() == 0 )
52 0 : aSize.setX( 1 );
53 111419 : if( aSize.getY() == 0 )
54 0 : aSize.setY( 1 );
55 111419 : if( nBitCount > 8 )
56 26522 : m_aBitmap = createBitmapDevice( aSize, false, nFormat );
57 : else
58 : {
59 : // prepare palette
60 84897 : unsigned int nEntries = 1U << nBitCount;
61 : std::vector<basebmp::Color>* pPalette =
62 84897 : new std::vector<basebmp::Color>( nEntries, basebmp::Color(COL_WHITE) );
63 84897 : unsigned int nColors = rPalette.GetEntryCount();
64 21120935 : for( unsigned int i = 0; i < nColors; i++ )
65 : {
66 21036038 : const BitmapColor& rCol = rPalette[i];
67 21036038 : (*pPalette)[i] = basebmp::Color( rCol.GetRed(), rCol.GetGreen(), rCol.GetBlue() );
68 : }
69 169794 : m_aBitmap = createBitmapDevice( aSize, false, nFormat,
70 : basebmp::RawMemorySharedArray(),
71 : basebmp::PaletteMemorySharedVector( pPalette )
72 84897 : );
73 : }
74 111419 : return true;
75 : }
76 :
77 41788 : bool SvpSalBitmap::Create( const SalBitmap& rSalBmp )
78 : {
79 41788 : const SvpSalBitmap& rSrc = static_cast<const SvpSalBitmap&>(rSalBmp);
80 41788 : const BitmapDeviceSharedPtr& rSrcBmp = rSrc.getBitmap();
81 41788 : if( rSrcBmp.get() )
82 : {
83 41788 : B2IVector aSize = rSrcBmp->getSize();
84 41788 : m_aBitmap = cloneBitmapDevice( aSize, rSrcBmp );
85 41788 : B2IBox aRect( 0, 0, aSize.getX(), aSize.getY() );
86 41788 : m_aBitmap->drawBitmap( rSrcBmp, aRect, aRect, DrawMode_PAINT );
87 : }
88 : else
89 0 : m_aBitmap.reset();
90 :
91 41788 : return true;
92 : }
93 :
94 0 : bool SvpSalBitmap::Create( const SalBitmap& /*rSalBmp*/,
95 : SalGraphics* /*pGraphics*/ )
96 : {
97 0 : return false;
98 : }
99 :
100 6 : bool SvpSalBitmap::Create( const SalBitmap& /*rSalBmp*/,
101 : sal_uInt16 /*nNewBitCount*/ )
102 : {
103 6 : return false;
104 : }
105 :
106 0 : bool SvpSalBitmap::Create( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmapCanvas > /*xBitmapCanvas*/, Size& /*rSize*/, bool /*bMask*/ )
107 : {
108 0 : return false;
109 : }
110 :
111 0 : void SvpSalBitmap::Destroy()
112 : {
113 0 : m_aBitmap.reset();
114 0 : }
115 :
116 1283621 : Size SvpSalBitmap::GetSize() const
117 : {
118 1283621 : Size aSize;
119 1283621 : if( m_aBitmap.get() )
120 : {
121 1283621 : B2IVector aVec( m_aBitmap->getSize() );
122 1283621 : aSize = Size( aVec.getX(), aVec.getY() );
123 : }
124 :
125 1283621 : return aSize;
126 : }
127 :
128 493149 : sal_uInt16 SvpSalBitmap::GetBitCount() const
129 : {
130 493149 : sal_uInt16 nDepth = 0;
131 493149 : if( m_aBitmap.get() )
132 493143 : nDepth = getBitCountFromScanlineFormat( m_aBitmap->getScanlineFormat() );
133 493149 : return nDepth;
134 : }
135 :
136 1168266 : BitmapBuffer* SvpSalBitmap::AcquireBuffer( bool )
137 : {
138 1168266 : BitmapBuffer* pBuf = NULL;
139 1168266 : if( m_aBitmap.get() )
140 : {
141 1168260 : pBuf = new BitmapBuffer();
142 1168260 : sal_uInt16 nBitCount = 1;
143 1168260 : switch( m_aBitmap->getScanlineFormat() )
144 : {
145 : case FORMAT_ONE_BIT_MSB_GREY:
146 : case FORMAT_ONE_BIT_MSB_PAL:
147 9898 : nBitCount = 1;
148 9898 : pBuf->mnFormat = BMP_FORMAT_1BIT_MSB_PAL;
149 9898 : break;
150 : case FORMAT_ONE_BIT_LSB_GREY:
151 : case FORMAT_ONE_BIT_LSB_PAL:
152 0 : nBitCount = 1;
153 0 : pBuf->mnFormat = BMP_FORMAT_1BIT_LSB_PAL;
154 0 : break;
155 : case FORMAT_FOUR_BIT_MSB_GREY:
156 : case FORMAT_FOUR_BIT_MSB_PAL:
157 426 : nBitCount = 4;
158 426 : pBuf->mnFormat = BMP_FORMAT_4BIT_MSN_PAL;
159 426 : break;
160 : case FORMAT_FOUR_BIT_LSB_GREY:
161 : case FORMAT_FOUR_BIT_LSB_PAL:
162 0 : nBitCount = 4;
163 0 : pBuf->mnFormat = BMP_FORMAT_4BIT_LSN_PAL;
164 0 : break;
165 : case FORMAT_EIGHT_BIT_PAL:
166 756197 : nBitCount = 8;
167 756197 : pBuf->mnFormat = BMP_FORMAT_8BIT_PAL;
168 756197 : break;
169 : case FORMAT_EIGHT_BIT_GREY:
170 0 : nBitCount = 8;
171 0 : pBuf->mnFormat = BMP_FORMAT_8BIT_PAL;
172 0 : break;
173 : case FORMAT_SIXTEEN_BIT_LSB_TC_MASK:
174 22 : nBitCount = 16;
175 22 : pBuf->mnFormat = BMP_FORMAT_16BIT_TC_LSB_MASK;
176 22 : pBuf->maColorMask = ColorMask( 0xf800, 0x07e0, 0x001f );
177 22 : break;
178 : case FORMAT_SIXTEEN_BIT_MSB_TC_MASK:
179 0 : nBitCount = 16;
180 0 : pBuf->mnFormat = BMP_FORMAT_16BIT_TC_MSB_MASK;
181 0 : pBuf->maColorMask = ColorMask( 0xf800, 0x07e0, 0x001f );
182 0 : break;
183 : case FORMAT_TWENTYFOUR_BIT_TC_MASK:
184 401717 : nBitCount = 24;
185 401717 : pBuf->mnFormat = BMP_FORMAT_24BIT_TC_BGR;
186 401717 : break;
187 : case FORMAT_THIRTYTWO_BIT_TC_MASK_BGRA:
188 0 : nBitCount = 32;
189 0 : pBuf->mnFormat = BMP_FORMAT_32BIT_TC_MASK;
190 : #ifdef OSL_BIGENDIAN
191 : pBuf->maColorMask = ColorMask( 0x0000ff00, 0x00ff0000, 0xff000000, 0x000000ff );
192 : #else
193 0 : pBuf->maColorMask = ColorMask( 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 );
194 : #endif
195 0 : break;
196 : case FORMAT_THIRTYTWO_BIT_TC_MASK_ARGB:
197 0 : nBitCount = 32;
198 0 : pBuf->mnFormat = BMP_FORMAT_32BIT_TC_MASK;
199 : #ifdef OSL_BIGENDIAN
200 : pBuf->maColorMask = ColorMask( 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 );
201 : #else
202 0 : pBuf->maColorMask = ColorMask( 0x0000ff00, 0x00ff0000, 0xff000000, 0x000000ff );
203 : #endif
204 0 : break;
205 : case FORMAT_THIRTYTWO_BIT_TC_MASK_ABGR:
206 0 : nBitCount = 32;
207 0 : pBuf->mnFormat = BMP_FORMAT_32BIT_TC_MASK;
208 : #ifdef OSL_BIGENDIAN
209 : pBuf->maColorMask = ColorMask( 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 );
210 : #else
211 0 : pBuf->maColorMask = ColorMask( 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff );
212 : #endif
213 0 : break;
214 : case FORMAT_THIRTYTWO_BIT_TC_MASK_RGBA:
215 0 : nBitCount = 32;
216 0 : pBuf->mnFormat = BMP_FORMAT_32BIT_TC_MASK;
217 : #ifdef OSL_BIGENDIAN
218 : pBuf->maColorMask = ColorMask( 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff );
219 : #else
220 0 : pBuf->maColorMask = ColorMask( 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 );
221 : #endif
222 0 : break;
223 :
224 : default:
225 : // this is an error case !!!!!
226 0 : nBitCount = 1;
227 0 : pBuf->mnFormat = BMP_FORMAT_1BIT_MSB_PAL;
228 0 : break;
229 : }
230 1168260 : if( m_aBitmap->isTopDown() )
231 0 : pBuf->mnFormat |= BMP_FORMAT_TOP_DOWN;
232 :
233 1168260 : B2IVector aSize = m_aBitmap->getSize();
234 1168260 : pBuf->mnWidth = aSize.getX();
235 1168260 : pBuf->mnHeight = aSize.getY();
236 1168260 : pBuf->mnScanlineSize = m_aBitmap->getScanlineStride();
237 1168260 : pBuf->mnBitCount = nBitCount;
238 1168260 : pBuf->mpBits = (sal_uInt8*)m_aBitmap->getBuffer().get();
239 1168260 : if( nBitCount <= 8 )
240 : {
241 2299563 : if( m_aBitmap->getScanlineFormat() == FORMAT_EIGHT_BIT_GREY ||
242 1533042 : m_aBitmap->getScanlineFormat() == FORMAT_FOUR_BIT_LSB_GREY ||
243 1533042 : m_aBitmap->getScanlineFormat() == FORMAT_FOUR_BIT_MSB_GREY ||
244 2299563 : m_aBitmap->getScanlineFormat() == FORMAT_ONE_BIT_LSB_GREY ||
245 766521 : m_aBitmap->getScanlineFormat() == FORMAT_ONE_BIT_MSB_GREY
246 : )
247 0 : pBuf->maPalette = Bitmap::GetGreyPalette( 1U << nBitCount );
248 : else
249 : {
250 766521 : basebmp::PaletteMemorySharedVector aPalette = m_aBitmap->getPalette();
251 766521 : if( aPalette.get() )
252 : {
253 766521 : unsigned int nColors = aPalette->size();
254 766521 : if( nColors > 0 )
255 : {
256 766521 : pBuf->maPalette.SetEntryCount( nColors );
257 194393789 : for( unsigned int i = 0; i < nColors; i++ )
258 : {
259 193627268 : const basebmp::Color& rCol = (*aPalette)[i];
260 193627268 : pBuf->maPalette[i] = BitmapColor( rCol.getRed(), rCol.getGreen(), rCol.getBlue() );
261 : }
262 : }
263 766521 : }
264 : }
265 1168260 : }
266 : }
267 :
268 1168266 : return pBuf;
269 : }
270 :
271 1168260 : void SvpSalBitmap::ReleaseBuffer( BitmapBuffer* pBuffer, bool bReadOnly )
272 : {
273 1168260 : if( !bReadOnly && pBuffer->maPalette.GetEntryCount() )
274 : {
275 : // palette might have changed, clone device (but recycle
276 : // memory)
277 143716 : sal_uInt16 nBitCount = 0;
278 143716 : switch( m_aBitmap->getScanlineFormat() )
279 : {
280 : case FORMAT_ONE_BIT_MSB_GREY:
281 : // FALLTHROUGH intended
282 : case FORMAT_ONE_BIT_MSB_PAL:
283 : // FALLTHROUGH intended
284 : case FORMAT_ONE_BIT_LSB_GREY:
285 : // FALLTHROUGH intended
286 : case FORMAT_ONE_BIT_LSB_PAL:
287 2036 : nBitCount = 1;
288 2036 : break;
289 :
290 : case FORMAT_FOUR_BIT_MSB_GREY:
291 : // FALLTHROUGH intended
292 : case FORMAT_FOUR_BIT_MSB_PAL:
293 : // FALLTHROUGH intended
294 : case FORMAT_FOUR_BIT_LSB_GREY:
295 : // FALLTHROUGH intended
296 : case FORMAT_FOUR_BIT_LSB_PAL:
297 264 : nBitCount = 4;
298 264 : break;
299 :
300 : case FORMAT_EIGHT_BIT_PAL:
301 : // FALLTHROUGH intended
302 : case FORMAT_EIGHT_BIT_GREY:
303 141416 : nBitCount = 8;
304 141416 : break;
305 :
306 : default:
307 0 : break;
308 : }
309 :
310 143716 : if( nBitCount )
311 : {
312 143716 : sal_uInt32 nEntries = 1U << nBitCount;
313 :
314 : boost::shared_ptr< std::vector<basebmp::Color> > pPal(
315 : new std::vector<basebmp::Color>( nEntries,
316 143716 : basebmp::Color(COL_WHITE)));
317 : const sal_uInt32 nColors = std::min(
318 143716 : (sal_uInt32)pBuffer->maPalette.GetEntryCount(),
319 143716 : nEntries);
320 35519781 : for( sal_uInt32 i = 0; i < nColors; i++ )
321 : {
322 35376065 : const BitmapColor& rCol = pBuffer->maPalette[i];
323 35376065 : (*pPal)[i] = basebmp::Color( rCol.GetRed(), rCol.GetGreen(), rCol.GetBlue() );
324 : }
325 :
326 431148 : m_aBitmap = basebmp::createBitmapDevice( m_aBitmap->getSize(),
327 143716 : m_aBitmap->isTopDown(),
328 : m_aBitmap->getScanlineFormat(),
329 : m_aBitmap->getBuffer(),
330 287432 : pPal );
331 : }
332 : }
333 :
334 1168260 : delete pBuffer;
335 1168260 : }
336 :
337 0 : bool SvpSalBitmap::GetSystemData( BitmapSystemData& )
338 : {
339 0 : return false;
340 : }
341 :
342 902602 : sal_uInt32 SvpSalBitmap::getBitCountFromScanlineFormat( basebmp::Format nFormat )
343 : {
344 902602 : sal_uInt32 nBitCount = 1;
345 902602 : switch( nFormat )
346 : {
347 : case FORMAT_ONE_BIT_MSB_GREY:
348 : case FORMAT_ONE_BIT_LSB_GREY:
349 : case FORMAT_ONE_BIT_MSB_PAL:
350 : case FORMAT_ONE_BIT_LSB_PAL:
351 7280 : nBitCount = 1;
352 7280 : break;
353 : case FORMAT_FOUR_BIT_MSB_GREY:
354 : case FORMAT_FOUR_BIT_LSB_GREY:
355 : case FORMAT_FOUR_BIT_MSB_PAL:
356 : case FORMAT_FOUR_BIT_LSB_PAL:
357 410 : nBitCount = 4;
358 410 : break;
359 : case FORMAT_EIGHT_BIT_PAL:
360 : case FORMAT_EIGHT_BIT_GREY:
361 391031 : nBitCount = 8;
362 391031 : break;
363 : case FORMAT_SIXTEEN_BIT_LSB_TC_MASK:
364 : case FORMAT_SIXTEEN_BIT_MSB_TC_MASK:
365 14 : nBitCount = 16;
366 14 : break;
367 : case FORMAT_TWENTYFOUR_BIT_TC_MASK:
368 503867 : nBitCount = 24;
369 503867 : break;
370 : case FORMAT_THIRTYTWO_BIT_TC_MASK_BGRA:
371 : case FORMAT_THIRTYTWO_BIT_TC_MASK_ARGB:
372 : case FORMAT_THIRTYTWO_BIT_TC_MASK_ABGR:
373 : case FORMAT_THIRTYTWO_BIT_TC_MASK_RGBA:
374 0 : nBitCount = 32;
375 0 : break;
376 : default:
377 : OSL_FAIL( "unsupported basebmp format" );
378 0 : break;
379 : }
380 902602 : return nBitCount;
381 1125 : }
382 :
383 : #endif
384 :
385 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|