1*9f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*9f62ea84SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*9f62ea84SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*9f62ea84SAndrew Rist * distributed with this work for additional information
6*9f62ea84SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*9f62ea84SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*9f62ea84SAndrew Rist * "License"); you may not use this file except in compliance
9*9f62ea84SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*9f62ea84SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*9f62ea84SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*9f62ea84SAndrew Rist * software distributed under the License is distributed on an
15*9f62ea84SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9f62ea84SAndrew Rist * KIND, either express or implied. See the License for the
17*9f62ea84SAndrew Rist * specific language governing permissions and limitations
18*9f62ea84SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*9f62ea84SAndrew Rist *************************************************************/
21*9f62ea84SAndrew Rist
22*9f62ea84SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include "svpbmp.hxx"
25cdf0e10cSrcweir
26cdf0e10cSrcweir #include <basegfx/vector/b2ivector.hxx>
27cdf0e10cSrcweir #include <basegfx/range/b2irange.hxx>
28cdf0e10cSrcweir #include <basebmp/scanlineformats.hxx>
29cdf0e10cSrcweir #include <basebmp/color.hxx>
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include <vcl/salbtype.hxx>
32cdf0e10cSrcweir #include <vcl/bitmap.hxx>
33cdf0e10cSrcweir
34cdf0e10cSrcweir using namespace basebmp;
35cdf0e10cSrcweir using namespace basegfx;
36cdf0e10cSrcweir
~SvpSalBitmap()37cdf0e10cSrcweir SvpSalBitmap::~SvpSalBitmap()
38cdf0e10cSrcweir {
39cdf0e10cSrcweir }
40cdf0e10cSrcweir
Create(const Size & rSize,sal_uInt16 nBitCount,const BitmapPalette & rPalette)41cdf0e10cSrcweir bool SvpSalBitmap::Create( const Size& rSize,
42cdf0e10cSrcweir sal_uInt16 nBitCount,
43cdf0e10cSrcweir const BitmapPalette& rPalette )
44cdf0e10cSrcweir {
45cdf0e10cSrcweir sal_uInt32 nFormat = SVP_DEFAULT_BITMAP_FORMAT;
46cdf0e10cSrcweir switch( nBitCount )
47cdf0e10cSrcweir {
48cdf0e10cSrcweir case 1: nFormat = Format::ONE_BIT_MSB_PAL; break;
49cdf0e10cSrcweir case 4: nFormat = Format::FOUR_BIT_MSB_PAL; break;
50cdf0e10cSrcweir case 8: nFormat = Format::EIGHT_BIT_PAL; break;
51cdf0e10cSrcweir #ifdef OSL_BIGENDIAN
52cdf0e10cSrcweir case 16: nFormat = Format::SIXTEEN_BIT_MSB_TC_MASK; break;
53cdf0e10cSrcweir #else
54cdf0e10cSrcweir case 16: nFormat = Format::SIXTEEN_BIT_LSB_TC_MASK; break;
55cdf0e10cSrcweir #endif
56cdf0e10cSrcweir case 24: nFormat = Format::TWENTYFOUR_BIT_TC_MASK; break;
57cdf0e10cSrcweir case 32: nFormat = Format::THIRTYTWO_BIT_TC_MASK; break;
58cdf0e10cSrcweir }
59cdf0e10cSrcweir B2IVector aSize( rSize.Width(), rSize.Height() );
60cdf0e10cSrcweir if( aSize.getX() == 0 )
61cdf0e10cSrcweir aSize.setX( 1 );
62cdf0e10cSrcweir if( aSize.getY() == 0 )
63cdf0e10cSrcweir aSize.setY( 1 );
64cdf0e10cSrcweir if( nBitCount > 8 )
65cdf0e10cSrcweir m_aBitmap = createBitmapDevice( aSize, false, nFormat );
66cdf0e10cSrcweir else
67cdf0e10cSrcweir {
68cdf0e10cSrcweir // prepare palette
69cdf0e10cSrcweir unsigned int nEntries = 1U << nBitCount;
70cdf0e10cSrcweir std::vector<basebmp::Color>* pPalette =
71cdf0e10cSrcweir new std::vector<basebmp::Color>( nEntries, basebmp::Color(COL_WHITE) );
72cdf0e10cSrcweir unsigned int nColors = rPalette.GetEntryCount();
73cdf0e10cSrcweir for( unsigned int i = 0; i < nColors; i++ )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir const BitmapColor& rCol = rPalette[i];
76cdf0e10cSrcweir (*pPalette)[i] = basebmp::Color( rCol.GetRed(), rCol.GetGreen(), rCol.GetBlue() );
77cdf0e10cSrcweir }
78cdf0e10cSrcweir m_aBitmap = createBitmapDevice( aSize, false, nFormat,
79cdf0e10cSrcweir basebmp::RawMemorySharedArray(),
80cdf0e10cSrcweir basebmp::PaletteMemorySharedVector( pPalette )
81cdf0e10cSrcweir );
82cdf0e10cSrcweir }
83cdf0e10cSrcweir return true;
84cdf0e10cSrcweir }
85cdf0e10cSrcweir
Create(const SalBitmap & rSalBmp)86cdf0e10cSrcweir bool SvpSalBitmap::Create( const SalBitmap& rSalBmp )
87cdf0e10cSrcweir {
88cdf0e10cSrcweir const SvpSalBitmap& rSrc = static_cast<const SvpSalBitmap&>(rSalBmp);
89cdf0e10cSrcweir const BitmapDeviceSharedPtr& rSrcBmp = rSrc.getBitmap();
90cdf0e10cSrcweir if( rSrcBmp.get() )
91cdf0e10cSrcweir {
92cdf0e10cSrcweir B2IVector aSize = rSrcBmp->getSize();
93cdf0e10cSrcweir m_aBitmap = cloneBitmapDevice( aSize, rSrcBmp );
94cdf0e10cSrcweir B2IRange aRect( 0, 0, aSize.getX(), aSize.getY() );
95cdf0e10cSrcweir m_aBitmap->drawBitmap( rSrcBmp, aRect, aRect, DrawMode_PAINT );
96cdf0e10cSrcweir }
97cdf0e10cSrcweir else
98cdf0e10cSrcweir m_aBitmap.reset();
99cdf0e10cSrcweir
100cdf0e10cSrcweir return true;
101cdf0e10cSrcweir }
102cdf0e10cSrcweir
Create(const SalBitmap &,SalGraphics *)103cdf0e10cSrcweir bool SvpSalBitmap::Create( const SalBitmap& /*rSalBmp*/,
104cdf0e10cSrcweir SalGraphics* /*pGraphics*/ )
105cdf0e10cSrcweir {
106cdf0e10cSrcweir return false;
107cdf0e10cSrcweir }
108cdf0e10cSrcweir
Create(const SalBitmap &,sal_uInt16)109cdf0e10cSrcweir bool SvpSalBitmap::Create( const SalBitmap& /*rSalBmp*/,
110cdf0e10cSrcweir sal_uInt16 /*nNewBitCount*/ )
111cdf0e10cSrcweir {
112cdf0e10cSrcweir return false;
113cdf0e10cSrcweir }
114cdf0e10cSrcweir
Destroy()115cdf0e10cSrcweir void SvpSalBitmap::Destroy()
116cdf0e10cSrcweir {
117cdf0e10cSrcweir m_aBitmap.reset();
118cdf0e10cSrcweir }
119cdf0e10cSrcweir
GetSize() const120cdf0e10cSrcweir Size SvpSalBitmap::GetSize() const
121cdf0e10cSrcweir {
122cdf0e10cSrcweir Size aSize;
123cdf0e10cSrcweir if( m_aBitmap.get() )
124cdf0e10cSrcweir {
125cdf0e10cSrcweir B2IVector aVec( m_aBitmap->getSize() );
126cdf0e10cSrcweir aSize = Size( aVec.getX(), aVec.getY() );
127cdf0e10cSrcweir }
128cdf0e10cSrcweir
129cdf0e10cSrcweir return aSize;
130cdf0e10cSrcweir }
131cdf0e10cSrcweir
GetBitCount() const132cdf0e10cSrcweir sal_uInt16 SvpSalBitmap::GetBitCount() const
133cdf0e10cSrcweir {
134cdf0e10cSrcweir sal_uInt16 nDepth = 0;
135cdf0e10cSrcweir if( m_aBitmap.get() )
136cdf0e10cSrcweir nDepth = getBitCountFromScanlineFormat( m_aBitmap->getScanlineFormat() );
137cdf0e10cSrcweir return nDepth;
138cdf0e10cSrcweir }
139cdf0e10cSrcweir
AcquireBuffer(bool)140cdf0e10cSrcweir BitmapBuffer* SvpSalBitmap::AcquireBuffer( bool )
141cdf0e10cSrcweir {
142cdf0e10cSrcweir BitmapBuffer* pBuf = NULL;
143cdf0e10cSrcweir if( m_aBitmap.get() )
144cdf0e10cSrcweir {
145cdf0e10cSrcweir pBuf = new BitmapBuffer();
146cdf0e10cSrcweir sal_uInt16 nBitCount = 1;
147cdf0e10cSrcweir switch( m_aBitmap->getScanlineFormat() )
148cdf0e10cSrcweir {
149cdf0e10cSrcweir case Format::ONE_BIT_MSB_GREY:
150cdf0e10cSrcweir case Format::ONE_BIT_MSB_PAL:
151cdf0e10cSrcweir nBitCount = 1;
152cdf0e10cSrcweir pBuf->mnFormat = BMP_FORMAT_1BIT_MSB_PAL;
153cdf0e10cSrcweir break;
154cdf0e10cSrcweir case Format::ONE_BIT_LSB_GREY:
155cdf0e10cSrcweir case Format::ONE_BIT_LSB_PAL:
156cdf0e10cSrcweir nBitCount = 1;
157cdf0e10cSrcweir pBuf->mnFormat = BMP_FORMAT_1BIT_LSB_PAL;
158cdf0e10cSrcweir break;
159cdf0e10cSrcweir case Format::FOUR_BIT_MSB_GREY:
160cdf0e10cSrcweir case Format::FOUR_BIT_MSB_PAL:
161cdf0e10cSrcweir nBitCount = 4;
162cdf0e10cSrcweir pBuf->mnFormat = BMP_FORMAT_4BIT_MSN_PAL;
163cdf0e10cSrcweir break;
164cdf0e10cSrcweir case Format::FOUR_BIT_LSB_GREY:
165cdf0e10cSrcweir case Format::FOUR_BIT_LSB_PAL:
166cdf0e10cSrcweir nBitCount = 4;
167cdf0e10cSrcweir pBuf->mnFormat = BMP_FORMAT_4BIT_LSN_PAL;
168cdf0e10cSrcweir break;
169cdf0e10cSrcweir case Format::EIGHT_BIT_PAL:
170cdf0e10cSrcweir nBitCount = 8;
171cdf0e10cSrcweir pBuf->mnFormat = BMP_FORMAT_8BIT_PAL;
172cdf0e10cSrcweir break;
173cdf0e10cSrcweir case Format::EIGHT_BIT_GREY:
174cdf0e10cSrcweir nBitCount = 8;
175cdf0e10cSrcweir pBuf->mnFormat = BMP_FORMAT_8BIT_PAL;
176cdf0e10cSrcweir break;
177cdf0e10cSrcweir case Format::SIXTEEN_BIT_LSB_TC_MASK:
178cdf0e10cSrcweir nBitCount = 16;
179cdf0e10cSrcweir pBuf->mnFormat = BMP_FORMAT_16BIT_TC_LSB_MASK;
180cdf0e10cSrcweir pBuf->maColorMask = ColorMask( 0xf800, 0x07e0, 0x001f );
181cdf0e10cSrcweir break;
182cdf0e10cSrcweir case Format::SIXTEEN_BIT_MSB_TC_MASK:
183cdf0e10cSrcweir nBitCount = 16;
184cdf0e10cSrcweir pBuf->mnFormat = BMP_FORMAT_16BIT_TC_MSB_MASK;
185cdf0e10cSrcweir pBuf->maColorMask = ColorMask( 0xf800, 0x07e0, 0x001f );
186cdf0e10cSrcweir break;
187cdf0e10cSrcweir case Format::TWENTYFOUR_BIT_TC_MASK:
188cdf0e10cSrcweir nBitCount = 24;
189cdf0e10cSrcweir pBuf->mnFormat = BMP_FORMAT_24BIT_TC_BGR;
190cdf0e10cSrcweir break;
191cdf0e10cSrcweir case Format::THIRTYTWO_BIT_TC_MASK:
192cdf0e10cSrcweir nBitCount = 32;
193cdf0e10cSrcweir pBuf->mnFormat = BMP_FORMAT_32BIT_TC_MASK;
194cdf0e10cSrcweir #ifdef OSL_BIGENDIAN
195cdf0e10cSrcweir pBuf->maColorMask = ColorMask( 0x0000ff, 0x00ff00, 0xff0000 );
196cdf0e10cSrcweir #else
197cdf0e10cSrcweir pBuf->maColorMask = ColorMask( 0xff0000, 0x00ff00, 0x0000ff );
198cdf0e10cSrcweir #endif
199cdf0e10cSrcweir break;
200cdf0e10cSrcweir
201cdf0e10cSrcweir default:
202cdf0e10cSrcweir // this is an error case !!!!!
203cdf0e10cSrcweir nBitCount = 1;
204cdf0e10cSrcweir pBuf->mnFormat = BMP_FORMAT_1BIT_MSB_PAL;
205cdf0e10cSrcweir break;
206cdf0e10cSrcweir }
207cdf0e10cSrcweir if( m_aBitmap->isTopDown() )
208cdf0e10cSrcweir pBuf->mnFormat |= BMP_FORMAT_TOP_DOWN;
209cdf0e10cSrcweir
210cdf0e10cSrcweir B2IVector aSize = m_aBitmap->getSize();
211cdf0e10cSrcweir pBuf->mnWidth = aSize.getX();
212cdf0e10cSrcweir pBuf->mnHeight = aSize.getY();
213cdf0e10cSrcweir pBuf->mnScanlineSize = m_aBitmap->getScanlineStride();
214cdf0e10cSrcweir pBuf->mnBitCount = nBitCount;
215cdf0e10cSrcweir pBuf->mpBits = (sal_uInt8*)m_aBitmap->getBuffer().get();
216cdf0e10cSrcweir if( nBitCount <= 8 )
217cdf0e10cSrcweir {
218cdf0e10cSrcweir if( m_aBitmap->getScanlineFormat() == Format::EIGHT_BIT_GREY ||
219cdf0e10cSrcweir m_aBitmap->getScanlineFormat() == Format::FOUR_BIT_LSB_GREY ||
220cdf0e10cSrcweir m_aBitmap->getScanlineFormat() == Format::FOUR_BIT_MSB_GREY ||
221cdf0e10cSrcweir m_aBitmap->getScanlineFormat() == Format::ONE_BIT_LSB_GREY ||
222cdf0e10cSrcweir m_aBitmap->getScanlineFormat() == Format::ONE_BIT_MSB_GREY
223cdf0e10cSrcweir )
224cdf0e10cSrcweir pBuf->maPalette = Bitmap::GetGreyPalette( 1U << nBitCount );
225cdf0e10cSrcweir else
226cdf0e10cSrcweir {
227cdf0e10cSrcweir basebmp::PaletteMemorySharedVector aPalette = m_aBitmap->getPalette();
228cdf0e10cSrcweir if( aPalette.get() )
229cdf0e10cSrcweir {
230cdf0e10cSrcweir unsigned int nColors = aPalette->size();
231cdf0e10cSrcweir if( nColors > 0 )
232cdf0e10cSrcweir {
233cdf0e10cSrcweir pBuf->maPalette.SetEntryCount( nColors );
234cdf0e10cSrcweir for( unsigned int i = 0; i < nColors; i++ )
235cdf0e10cSrcweir {
236cdf0e10cSrcweir const basebmp::Color& rCol = (*aPalette)[i];
237cdf0e10cSrcweir pBuf->maPalette[i] = BitmapColor( rCol.getRed(), rCol.getGreen(), rCol.getBlue() );
238cdf0e10cSrcweir }
239cdf0e10cSrcweir }
240cdf0e10cSrcweir }
241cdf0e10cSrcweir }
242cdf0e10cSrcweir }
243cdf0e10cSrcweir }
244cdf0e10cSrcweir
245cdf0e10cSrcweir return pBuf;
246cdf0e10cSrcweir }
247cdf0e10cSrcweir
ReleaseBuffer(BitmapBuffer * pBuffer,bool bReadOnly)248cdf0e10cSrcweir void SvpSalBitmap::ReleaseBuffer( BitmapBuffer* pBuffer, bool bReadOnly )
249cdf0e10cSrcweir {
250cdf0e10cSrcweir if( !bReadOnly && pBuffer->maPalette.GetEntryCount() )
251cdf0e10cSrcweir {
252cdf0e10cSrcweir // palette might have changed, clone device (but recycle
253cdf0e10cSrcweir // memory)
254cdf0e10cSrcweir sal_uInt16 nBitCount = 0;
255cdf0e10cSrcweir switch( m_aBitmap->getScanlineFormat() )
256cdf0e10cSrcweir {
257cdf0e10cSrcweir case Format::ONE_BIT_MSB_GREY:
258cdf0e10cSrcweir // FALLTHROUGH intended
259cdf0e10cSrcweir case Format::ONE_BIT_MSB_PAL:
260cdf0e10cSrcweir // FALLTHROUGH intended
261cdf0e10cSrcweir case Format::ONE_BIT_LSB_GREY:
262cdf0e10cSrcweir // FALLTHROUGH intended
263cdf0e10cSrcweir case Format::ONE_BIT_LSB_PAL:
264cdf0e10cSrcweir nBitCount = 1;
265cdf0e10cSrcweir break;
266cdf0e10cSrcweir
267cdf0e10cSrcweir case Format::FOUR_BIT_MSB_GREY:
268cdf0e10cSrcweir // FALLTHROUGH intended
269cdf0e10cSrcweir case Format::FOUR_BIT_MSB_PAL:
270cdf0e10cSrcweir // FALLTHROUGH intended
271cdf0e10cSrcweir case Format::FOUR_BIT_LSB_GREY:
272cdf0e10cSrcweir // FALLTHROUGH intended
273cdf0e10cSrcweir case Format::FOUR_BIT_LSB_PAL:
274cdf0e10cSrcweir nBitCount = 4;
275cdf0e10cSrcweir break;
276cdf0e10cSrcweir
277cdf0e10cSrcweir case Format::EIGHT_BIT_PAL:
278cdf0e10cSrcweir // FALLTHROUGH intended
279cdf0e10cSrcweir case Format::EIGHT_BIT_GREY:
280cdf0e10cSrcweir nBitCount = 8;
281cdf0e10cSrcweir break;
282cdf0e10cSrcweir
283cdf0e10cSrcweir default:
284cdf0e10cSrcweir break;
285cdf0e10cSrcweir }
286cdf0e10cSrcweir
287cdf0e10cSrcweir if( nBitCount )
288cdf0e10cSrcweir {
289cdf0e10cSrcweir sal_uInt32 nEntries = 1U << nBitCount;
290cdf0e10cSrcweir
291cdf0e10cSrcweir boost::shared_ptr< std::vector<basebmp::Color> > pPal(
292cdf0e10cSrcweir new std::vector<basebmp::Color>( nEntries,
293cdf0e10cSrcweir basebmp::Color(COL_WHITE)));
294cdf0e10cSrcweir const sal_uInt32 nColors = std::min(
295cdf0e10cSrcweir (sal_uInt32)pBuffer->maPalette.GetEntryCount(),
296cdf0e10cSrcweir nEntries);
297cdf0e10cSrcweir for( sal_uInt32 i = 0; i < nColors; i++ )
298cdf0e10cSrcweir {
299cdf0e10cSrcweir const BitmapColor& rCol = pBuffer->maPalette[i];
300cdf0e10cSrcweir (*pPal)[i] = basebmp::Color( rCol.GetRed(), rCol.GetGreen(), rCol.GetBlue() );
301cdf0e10cSrcweir }
302cdf0e10cSrcweir
303cdf0e10cSrcweir m_aBitmap = basebmp::createBitmapDevice( m_aBitmap->getSize(),
304cdf0e10cSrcweir m_aBitmap->isTopDown(),
305cdf0e10cSrcweir m_aBitmap->getScanlineFormat(),
306cdf0e10cSrcweir m_aBitmap->getBuffer(),
307cdf0e10cSrcweir pPal );
308cdf0e10cSrcweir }
309cdf0e10cSrcweir }
310cdf0e10cSrcweir
311cdf0e10cSrcweir delete pBuffer;
312cdf0e10cSrcweir }
313cdf0e10cSrcweir
GetSystemData(BitmapSystemData &)314cdf0e10cSrcweir bool SvpSalBitmap::GetSystemData( BitmapSystemData& )
315cdf0e10cSrcweir {
316cdf0e10cSrcweir return false;
317cdf0e10cSrcweir }
318cdf0e10cSrcweir
319cdf0e10cSrcweir
320