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 560942 : SvpSalBitmap::~SvpSalBitmap()
37 : {
38 560942 : }
39 :
40 72579 : 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 72579 : SvpSalInstance* pInst = SvpSalInstance::s_pDefaultInstance;
47 : assert( pInst );
48 72579 : basebmp::Format nFormat = pInst->getFormatForBitCount( nBitCount );
49 :
50 72579 : B2IVector aSize( rSize.Width(), rSize.Height() );
51 72579 : if( aSize.getX() == 0 )
52 0 : aSize.setX( 1 );
53 72579 : if( aSize.getY() == 0 )
54 0 : aSize.setY( 1 );
55 72579 : sal_Int32 nStride = getBitmapDeviceStrideForWidth(nFormat, aSize.getX());
56 72579 : if( nBitCount > 8 )
57 21552 : m_aBitmap = createBitmapDevice( aSize, false, nFormat, nStride );
58 : else
59 : {
60 : // prepare palette
61 51027 : unsigned int nEntries = 1U << nBitCount;
62 : std::vector<basebmp::Color>* pPalette =
63 51027 : new std::vector<basebmp::Color>( nEntries, basebmp::Color(COL_WHITE) );
64 51027 : unsigned int nColors = rPalette.GetEntryCount();
65 12537735 : for( unsigned int i = 0; i < nColors; i++ )
66 : {
67 12486708 : const BitmapColor& rCol = rPalette[i];
68 12486708 : (*pPalette)[i] = basebmp::Color( rCol.GetRed(), rCol.GetGreen(), rCol.GetBlue() );
69 : }
70 102054 : m_aBitmap = createBitmapDevice( aSize, false, nFormat, nStride,
71 : basebmp::RawMemorySharedArray(),
72 : basebmp::PaletteMemorySharedVector( pPalette )
73 51027 : );
74 : }
75 72579 : return true;
76 : }
77 :
78 35816 : bool SvpSalBitmap::Create( const SalBitmap& rSalBmp )
79 : {
80 35816 : const SvpSalBitmap& rSrc = static_cast<const SvpSalBitmap&>(rSalBmp);
81 35816 : const BitmapDeviceSharedPtr& rSrcBmp = rSrc.getBitmap();
82 35816 : if( rSrcBmp.get() )
83 : {
84 35816 : B2IVector aSize = rSrcBmp->getSize();
85 35816 : m_aBitmap = cloneBitmapDevice( aSize, rSrcBmp );
86 35816 : B2IBox aRect( 0, 0, aSize.getX(), aSize.getY() );
87 35816 : m_aBitmap->drawBitmap( rSrcBmp, aRect, aRect, DrawMode::Paint );
88 : }
89 : else
90 0 : m_aBitmap.reset();
91 :
92 35816 : return true;
93 : }
94 :
95 0 : bool SvpSalBitmap::Create( const SalBitmap& /*rSalBmp*/,
96 : SalGraphics* /*pGraphics*/ )
97 : {
98 0 : return false;
99 : }
100 :
101 3 : bool SvpSalBitmap::Create( const SalBitmap& /*rSalBmp*/,
102 : sal_uInt16 /*nNewBitCount*/ )
103 : {
104 3 : return false;
105 : }
106 :
107 0 : bool SvpSalBitmap::Create( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmapCanvas >& /*xBitmapCanvas*/, Size& /*rSize*/, bool /*bMask*/ )
108 : {
109 0 : return false;
110 : }
111 :
112 0 : void SvpSalBitmap::Destroy()
113 : {
114 0 : m_aBitmap.reset();
115 0 : }
116 :
117 884712 : Size SvpSalBitmap::GetSize() const
118 : {
119 884712 : Size aSize;
120 884712 : if( m_aBitmap.get() )
121 : {
122 884712 : B2IVector aVec( m_aBitmap->getSize() );
123 884712 : aSize = Size( aVec.getX(), aVec.getY() );
124 : }
125 :
126 884712 : return aSize;
127 : }
128 :
129 361056 : sal_uInt16 SvpSalBitmap::GetBitCount() const
130 : {
131 361056 : sal_uInt16 nDepth = 0;
132 361056 : if( m_aBitmap.get() )
133 361053 : nDepth = getBitCountFromScanlineFormat( m_aBitmap->getScanlineFormat() );
134 361056 : return nDepth;
135 : }
136 :
137 887106 : BitmapBuffer* SvpSalBitmap::AcquireBuffer( BitmapAccessMode )
138 : {
139 887106 : BitmapBuffer* pBuf = NULL;
140 887106 : if( m_aBitmap.get() )
141 : {
142 887103 : pBuf = new BitmapBuffer();
143 887103 : sal_uInt16 nBitCount = 1;
144 887103 : switch( m_aBitmap->getScanlineFormat() )
145 : {
146 : case Format::OneBitMsbGrey:
147 : case Format::OneBitMsbPal:
148 4489 : nBitCount = 1;
149 4489 : pBuf->mnFormat = BMP_FORMAT_1BIT_MSB_PAL;
150 4489 : break;
151 : case Format::OneBitLsbGrey:
152 : case Format::OneBitLsbPal:
153 0 : nBitCount = 1;
154 0 : pBuf->mnFormat = BMP_FORMAT_1BIT_LSB_PAL;
155 0 : break;
156 : case Format::FourBitMsbGrey:
157 : case Format::FourBitMsbPal:
158 274 : nBitCount = 4;
159 274 : pBuf->mnFormat = BMP_FORMAT_4BIT_MSN_PAL;
160 274 : break;
161 : case Format::FourBitLsbGrey:
162 : case Format::FourBitLsbPal:
163 0 : nBitCount = 4;
164 0 : pBuf->mnFormat = BMP_FORMAT_4BIT_LSN_PAL;
165 0 : break;
166 : case Format::EightBitPal:
167 461482 : nBitCount = 8;
168 461482 : pBuf->mnFormat = BMP_FORMAT_8BIT_PAL;
169 461482 : break;
170 : case Format::EightBitGrey:
171 0 : nBitCount = 8;
172 0 : pBuf->mnFormat = BMP_FORMAT_8BIT_PAL;
173 0 : break;
174 : case Format::SixteenBitLsbTcMask:
175 11 : nBitCount = 16;
176 11 : pBuf->mnFormat = BMP_FORMAT_16BIT_TC_LSB_MASK;
177 11 : pBuf->maColorMask = ColorMask( 0xf800, 0x07e0, 0x001f );
178 11 : break;
179 : case Format::SixteenBitMsbTcMask:
180 0 : nBitCount = 16;
181 0 : pBuf->mnFormat = BMP_FORMAT_16BIT_TC_MSB_MASK;
182 0 : pBuf->maColorMask = ColorMask( 0xf800, 0x07e0, 0x001f );
183 0 : break;
184 : case Format::TwentyFourBitTcMask:
185 0 : nBitCount = 24;
186 0 : pBuf->mnFormat = BMP_FORMAT_24BIT_TC_BGR;
187 0 : break;
188 : case Format::ThirtyTwoBitTcMaskBGRX:
189 412339 : nBitCount = 32;
190 412339 : pBuf->mnFormat = BMP_FORMAT_32BIT_TC_MASK;
191 : #ifdef OSL_BIGENDIAN
192 : pBuf->maColorMask = ColorMask( 0x0000ff00, 0x00ff0000, 0xff000000 );
193 : #else
194 412339 : pBuf->maColorMask = ColorMask( 0x00ff0000, 0x0000ff00, 0x000000ff );
195 : #endif
196 412339 : break;
197 : case Format::ThirtyTwoBitTcMaskBGRA:
198 8508 : nBitCount = 32;
199 8508 : pBuf->mnFormat = BMP_FORMAT_32BIT_TC_MASK;
200 : #ifdef OSL_BIGENDIAN
201 : pBuf->maColorMask = ColorMask( 0x0000ff00, 0x00ff0000, 0xff000000, 0x000000ff );
202 : #else
203 8508 : pBuf->maColorMask = ColorMask( 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 );
204 : #endif
205 8508 : break;
206 : case Format::ThirtyTwoBitTcMaskARGB:
207 0 : nBitCount = 32;
208 0 : pBuf->mnFormat = BMP_FORMAT_32BIT_TC_MASK;
209 : #ifdef OSL_BIGENDIAN
210 : pBuf->maColorMask = ColorMask( 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 );
211 : #else
212 0 : pBuf->maColorMask = ColorMask( 0x0000ff00, 0x00ff0000, 0xff000000, 0x000000ff );
213 : #endif
214 0 : break;
215 : case Format::ThirtyTwoBitTcMaskABGR:
216 0 : nBitCount = 32;
217 0 : pBuf->mnFormat = BMP_FORMAT_32BIT_TC_MASK;
218 : #ifdef OSL_BIGENDIAN
219 : pBuf->maColorMask = ColorMask( 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 );
220 : #else
221 0 : pBuf->maColorMask = ColorMask( 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff );
222 : #endif
223 0 : break;
224 : case Format::ThirtyTwoBitTcMaskRGBA:
225 0 : nBitCount = 32;
226 0 : pBuf->mnFormat = BMP_FORMAT_32BIT_TC_MASK;
227 : #ifdef OSL_BIGENDIAN
228 : pBuf->maColorMask = ColorMask( 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff );
229 : #else
230 0 : pBuf->maColorMask = ColorMask( 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 );
231 : #endif
232 0 : break;
233 :
234 : default:
235 : // this is an error case !!!!!
236 0 : nBitCount = 1;
237 0 : pBuf->mnFormat = BMP_FORMAT_1BIT_MSB_PAL;
238 0 : break;
239 : }
240 887103 : if( m_aBitmap->isTopDown() )
241 0 : pBuf->mnFormat |= BMP_FORMAT_TOP_DOWN;
242 :
243 887103 : B2IVector aSize = m_aBitmap->getSize();
244 887103 : pBuf->mnWidth = aSize.getX();
245 887103 : pBuf->mnHeight = aSize.getY();
246 887103 : pBuf->mnScanlineSize = m_aBitmap->getScanlineStride();
247 887103 : pBuf->mnBitCount = nBitCount;
248 887103 : pBuf->mpBits = m_aBitmap->getBuffer().get();
249 887103 : if( nBitCount <= 8 )
250 : {
251 1398735 : if( m_aBitmap->getScanlineFormat() == Format::EightBitGrey ||
252 932490 : m_aBitmap->getScanlineFormat() == Format::FourBitLsbGrey ||
253 932490 : m_aBitmap->getScanlineFormat() == Format::FourBitMsbGrey ||
254 1398735 : m_aBitmap->getScanlineFormat() == Format::OneBitLsbGrey ||
255 466245 : m_aBitmap->getScanlineFormat() == Format::OneBitMsbGrey
256 : )
257 0 : pBuf->maPalette = Bitmap::GetGreyPalette( 1U << nBitCount );
258 : else
259 : {
260 466245 : basebmp::PaletteMemorySharedVector aPalette = m_aBitmap->getPalette();
261 466245 : if( aPalette.get() )
262 : {
263 466245 : unsigned int nColors = aPalette->size();
264 466245 : if( nColors > 0 )
265 : {
266 466245 : pBuf->maPalette.SetEntryCount( nColors );
267 118622671 : for( unsigned int i = 0; i < nColors; i++ )
268 : {
269 118156426 : const basebmp::Color& rCol = (*aPalette)[i];
270 118156426 : pBuf->maPalette[i] = BitmapColor( rCol.getRed(), rCol.getGreen(), rCol.getBlue() );
271 : }
272 : }
273 466245 : }
274 : }
275 887103 : }
276 : }
277 :
278 887106 : return pBuf;
279 : }
280 :
281 887103 : void SvpSalBitmap::ReleaseBuffer( BitmapBuffer* pBuffer, BitmapAccessMode nMode )
282 : {
283 887103 : if( nMode == BITMAP_WRITE_ACCESS && pBuffer->maPalette.GetEntryCount() )
284 : {
285 : // palette might have changed, clone device (but recycle
286 : // memory)
287 90027 : sal_uInt16 nBitCount = 0;
288 90027 : switch( m_aBitmap->getScanlineFormat() )
289 : {
290 : case Format::OneBitMsbGrey:
291 : // FALLTHROUGH intended
292 : case Format::OneBitMsbPal:
293 : // FALLTHROUGH intended
294 : case Format::OneBitLsbGrey:
295 : // FALLTHROUGH intended
296 : case Format::OneBitLsbPal:
297 1752 : nBitCount = 1;
298 1752 : break;
299 :
300 : case Format::FourBitMsbGrey:
301 : // FALLTHROUGH intended
302 : case Format::FourBitMsbPal:
303 : // FALLTHROUGH intended
304 : case Format::FourBitLsbGrey:
305 : // FALLTHROUGH intended
306 : case Format::FourBitLsbPal:
307 144 : nBitCount = 4;
308 144 : break;
309 :
310 : case Format::EightBitPal:
311 : // FALLTHROUGH intended
312 : case Format::EightBitGrey:
313 88131 : nBitCount = 8;
314 88131 : break;
315 :
316 : default:
317 0 : break;
318 : }
319 :
320 90027 : if( nBitCount )
321 : {
322 90027 : sal_uInt32 nEntries = 1U << nBitCount;
323 :
324 : boost::shared_ptr< std::vector<basebmp::Color> > pPal(
325 : new std::vector<basebmp::Color>( nEntries,
326 90027 : basebmp::Color(COL_WHITE)));
327 : const sal_uInt32 nColors = std::min(
328 90027 : (sal_uInt32)pBuffer->maPalette.GetEntryCount(),
329 90027 : nEntries);
330 22466962 : for( sal_uInt32 i = 0; i < nColors; i++ )
331 : {
332 22376935 : const BitmapColor& rCol = pBuffer->maPalette[i];
333 22376935 : (*pPal)[i] = basebmp::Color( rCol.GetRed(), rCol.GetGreen(), rCol.GetBlue() );
334 : }
335 :
336 270081 : m_aBitmap = basebmp::createBitmapDevice( m_aBitmap->getSize(),
337 90027 : m_aBitmap->isTopDown(),
338 : m_aBitmap->getScanlineFormat(),
339 : m_aBitmap->getScanlineStride(),
340 : m_aBitmap->getBuffer(),
341 180054 : pPal );
342 : }
343 : }
344 :
345 887103 : delete pBuffer;
346 887103 : }
347 :
348 0 : bool SvpSalBitmap::GetSystemData( BitmapSystemData& )
349 : {
350 0 : return false;
351 : }
352 :
353 0 : bool SvpSalBitmap::Crop( const Rectangle& /*rRectPixel*/ )
354 : {
355 0 : return false;
356 : }
357 :
358 0 : bool SvpSalBitmap::Erase( const ::Color& /*rFillColor*/ )
359 : {
360 0 : return false;
361 : }
362 :
363 4617 : bool SvpSalBitmap::Scale( const double& /*rScaleX*/, const double& /*rScaleY*/, BmpScaleFlag /*nScaleFlag*/ )
364 : {
365 4617 : return false;
366 : }
367 :
368 512 : bool SvpSalBitmap::Replace( const ::Color& /*rSearchColor*/, const ::Color& /*rReplaceColor*/, sal_uLong /*nTol*/ )
369 : {
370 512 : return false;
371 : }
372 :
373 589898 : sal_uInt32 SvpSalBitmap::getBitCountFromScanlineFormat( basebmp::Format nFormat )
374 : {
375 589898 : sal_uInt32 nBitCount = 1;
376 589898 : switch( nFormat )
377 : {
378 : case Format::OneBitMsbGrey:
379 : case Format::OneBitLsbGrey:
380 : case Format::OneBitMsbPal:
381 : case Format::OneBitLsbPal:
382 8418 : nBitCount = 1;
383 8418 : break;
384 : case Format::FourBitMsbGrey:
385 : case Format::FourBitLsbGrey:
386 : case Format::FourBitMsbPal:
387 : case Format::FourBitLsbPal:
388 395 : nBitCount = 4;
389 395 : break;
390 : case Format::EightBitPal:
391 : case Format::EightBitGrey:
392 259791 : nBitCount = 8;
393 259791 : break;
394 : case Format::SixteenBitLsbTcMask:
395 : case Format::SixteenBitMsbTcMask:
396 7 : nBitCount = 16;
397 7 : break;
398 : case Format::TwentyFourBitTcMask:
399 0 : nBitCount = 24;
400 0 : break;
401 : case Format::ThirtyTwoBitTcMaskBGRX:
402 : case Format::ThirtyTwoBitTcMaskBGRA:
403 : case Format::ThirtyTwoBitTcMaskARGB:
404 : case Format::ThirtyTwoBitTcMaskABGR:
405 : case Format::ThirtyTwoBitTcMaskRGBA:
406 321287 : nBitCount = 32;
407 321287 : break;
408 : default:
409 : OSL_FAIL( "unsupported basebmp format" );
410 0 : break;
411 : }
412 589898 : return nBitCount;
413 801 : }
414 :
415 : #endif
416 :
417 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|