1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svpbmp.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 #include <basegfx/vector/b2ivector.hxx>
34 #include <basegfx/range/b2irange.hxx>
35 #include <basebmp/scanlineformats.hxx>
36 #include <basebmp/color.hxx>
38 #include <vcl/salbtype.hxx>
39 #include <vcl/bitmap.hxx>
41 using namespace basebmp
;
42 using namespace basegfx
;
44 SvpSalBitmap::~SvpSalBitmap()
48 bool SvpSalBitmap::Create( const Size
& rSize
,
50 const BitmapPalette
& rPalette
)
52 sal_uInt32 nFormat
= SVP_DEFAULT_BITMAP_FORMAT
;
55 case 1: nFormat
= Format::ONE_BIT_MSB_PAL
; break;
56 case 4: nFormat
= Format::FOUR_BIT_MSB_PAL
; break;
57 case 8: nFormat
= Format::EIGHT_BIT_PAL
; break;
59 case 16: nFormat
= Format::SIXTEEN_BIT_MSB_TC_MASK
; break;
61 case 16: nFormat
= Format::SIXTEEN_BIT_LSB_TC_MASK
; break;
63 case 24: nFormat
= Format::TWENTYFOUR_BIT_TC_MASK
; break;
64 case 32: nFormat
= Format::THIRTYTWO_BIT_TC_MASK
; break;
66 B2IVector
aSize( rSize
.Width(), rSize
.Height() );
67 if( aSize
.getX() == 0 )
69 if( aSize
.getY() == 0 )
72 m_aBitmap
= createBitmapDevice( aSize
, false, nFormat
);
76 unsigned int nEntries
= 1U << nBitCount
;
77 std::vector
<basebmp::Color
>* pPalette
=
78 new std::vector
<basebmp::Color
>( nEntries
, basebmp::Color(COL_WHITE
) );
79 unsigned int nColors
= rPalette
.GetEntryCount();
80 for( unsigned int i
= 0; i
< nColors
; i
++ )
82 const BitmapColor
& rCol
= rPalette
[i
];
83 (*pPalette
)[i
] = basebmp::Color( rCol
.GetRed(), rCol
.GetGreen(), rCol
.GetBlue() );
85 m_aBitmap
= createBitmapDevice( aSize
, false, nFormat
,
86 basebmp::RawMemorySharedArray(),
87 basebmp::PaletteMemorySharedVector( pPalette
)
93 bool SvpSalBitmap::Create( const SalBitmap
& rSalBmp
)
95 const SvpSalBitmap
& rSrc
= static_cast<const SvpSalBitmap
&>(rSalBmp
);
96 const BitmapDeviceSharedPtr
& rSrcBmp
= rSrc
.getBitmap();
99 B2IVector aSize
= rSrcBmp
->getSize();
100 m_aBitmap
= cloneBitmapDevice( aSize
, rSrcBmp
);
101 B2IRange
aRect( 0, 0, aSize
.getX(), aSize
.getY() );
102 m_aBitmap
->drawBitmap( rSrcBmp
, aRect
, aRect
, DrawMode_PAINT
);
110 bool SvpSalBitmap::Create( const SalBitmap
& /*rSalBmp*/,
111 SalGraphics
* /*pGraphics*/ )
116 bool SvpSalBitmap::Create( const SalBitmap
& /*rSalBmp*/,
117 USHORT
/*nNewBitCount*/ )
122 bool SvpSalBitmap::Create( const ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XBitmapCanvas
> /*xBitmapCanvas*/, Size
& /*rSize*/, bool /*bMask*/ )
127 void SvpSalBitmap::Destroy()
132 Size
SvpSalBitmap::GetSize() const
135 if( m_aBitmap
.get() )
137 B2IVector
aVec( m_aBitmap
->getSize() );
138 aSize
= Size( aVec
.getX(), aVec
.getY() );
144 USHORT
SvpSalBitmap::GetBitCount() const
147 if( m_aBitmap
.get() )
148 nDepth
= getBitCountFromScanlineFormat( m_aBitmap
->getScanlineFormat() );
152 BitmapBuffer
* SvpSalBitmap::AcquireBuffer( bool )
154 BitmapBuffer
* pBuf
= NULL
;
155 if( m_aBitmap
.get() )
157 pBuf
= new BitmapBuffer();
158 USHORT nBitCount
= 1;
159 switch( m_aBitmap
->getScanlineFormat() )
161 case Format::ONE_BIT_MSB_GREY
:
162 case Format::ONE_BIT_MSB_PAL
:
164 pBuf
->mnFormat
= BMP_FORMAT_1BIT_MSB_PAL
;
166 case Format::ONE_BIT_LSB_GREY
:
167 case Format::ONE_BIT_LSB_PAL
:
169 pBuf
->mnFormat
= BMP_FORMAT_1BIT_LSB_PAL
;
171 case Format::FOUR_BIT_MSB_GREY
:
172 case Format::FOUR_BIT_MSB_PAL
:
174 pBuf
->mnFormat
= BMP_FORMAT_4BIT_MSN_PAL
;
176 case Format::FOUR_BIT_LSB_GREY
:
177 case Format::FOUR_BIT_LSB_PAL
:
179 pBuf
->mnFormat
= BMP_FORMAT_4BIT_LSN_PAL
;
181 case Format::EIGHT_BIT_PAL
:
183 pBuf
->mnFormat
= BMP_FORMAT_8BIT_PAL
;
185 case Format::EIGHT_BIT_GREY
:
187 pBuf
->mnFormat
= BMP_FORMAT_8BIT_PAL
;
189 case Format::SIXTEEN_BIT_LSB_TC_MASK
:
191 pBuf
->mnFormat
= BMP_FORMAT_16BIT_TC_LSB_MASK
;
192 pBuf
->maColorMask
= ColorMask( 0xf800, 0x07e0, 0x001f );
194 case Format::SIXTEEN_BIT_MSB_TC_MASK
:
196 pBuf
->mnFormat
= BMP_FORMAT_16BIT_TC_MSB_MASK
;
197 pBuf
->maColorMask
= ColorMask( 0xf800, 0x07e0, 0x001f );
199 case Format::TWENTYFOUR_BIT_TC_MASK
:
201 pBuf
->mnFormat
= BMP_FORMAT_24BIT_TC_BGR
;
203 case Format::THIRTYTWO_BIT_TC_MASK
:
205 pBuf
->mnFormat
= BMP_FORMAT_32BIT_TC_MASK
;
207 pBuf
->maColorMask
= ColorMask( 0x0000ff, 0x00ff00, 0xff0000 );
209 pBuf
->maColorMask
= ColorMask( 0xff0000, 0x00ff00, 0x0000ff );
214 // this is an error case !!!!!
216 pBuf
->mnFormat
= BMP_FORMAT_1BIT_MSB_PAL
;
219 if( m_aBitmap
->isTopDown() )
220 pBuf
->mnFormat
|= BMP_FORMAT_TOP_DOWN
;
222 B2IVector aSize
= m_aBitmap
->getSize();
223 pBuf
->mnWidth
= aSize
.getX();
224 pBuf
->mnHeight
= aSize
.getY();
225 pBuf
->mnScanlineSize
= m_aBitmap
->getScanlineStride();
226 pBuf
->mnBitCount
= nBitCount
;
227 pBuf
->mpBits
= (BYTE
*)m_aBitmap
->getBuffer().get();
230 if( m_aBitmap
->getScanlineFormat() == Format::EIGHT_BIT_GREY
||
231 m_aBitmap
->getScanlineFormat() == Format::FOUR_BIT_LSB_GREY
||
232 m_aBitmap
->getScanlineFormat() == Format::FOUR_BIT_MSB_GREY
||
233 m_aBitmap
->getScanlineFormat() == Format::ONE_BIT_LSB_GREY
||
234 m_aBitmap
->getScanlineFormat() == Format::ONE_BIT_MSB_GREY
236 pBuf
->maPalette
= Bitmap::GetGreyPalette( 1U << nBitCount
);
239 basebmp::PaletteMemorySharedVector aPalette
= m_aBitmap
->getPalette();
242 unsigned int nColors
= aPalette
->size();
245 pBuf
->maPalette
.SetEntryCount( nColors
);
246 for( unsigned int i
= 0; i
< nColors
; i
++ )
248 const basebmp::Color
& rCol
= (*aPalette
)[i
];
249 pBuf
->maPalette
[i
] = BitmapColor( rCol
.getRed(), rCol
.getGreen(), rCol
.getBlue() );
260 void SvpSalBitmap::ReleaseBuffer( BitmapBuffer
* pBuffer
, bool bReadOnly
)
262 if( !bReadOnly
&& pBuffer
->maPalette
.GetEntryCount() )
264 // palette might have changed, clone device (but recycle
266 USHORT nBitCount
= 0;
267 switch( m_aBitmap
->getScanlineFormat() )
269 case Format::ONE_BIT_MSB_GREY
:
270 // FALLTHROUGH intended
271 case Format::ONE_BIT_MSB_PAL
:
272 // FALLTHROUGH intended
273 case Format::ONE_BIT_LSB_GREY
:
274 // FALLTHROUGH intended
275 case Format::ONE_BIT_LSB_PAL
:
279 case Format::FOUR_BIT_MSB_GREY
:
280 // FALLTHROUGH intended
281 case Format::FOUR_BIT_MSB_PAL
:
282 // FALLTHROUGH intended
283 case Format::FOUR_BIT_LSB_GREY
:
284 // FALLTHROUGH intended
285 case Format::FOUR_BIT_LSB_PAL
:
289 case Format::EIGHT_BIT_PAL
:
290 // FALLTHROUGH intended
291 case Format::EIGHT_BIT_GREY
:
301 sal_uInt32 nEntries
= 1U << nBitCount
;
303 boost::shared_ptr
< std::vector
<basebmp::Color
> > pPal(
304 new std::vector
<basebmp::Color
>( nEntries
,
305 basebmp::Color(COL_WHITE
)));
306 const sal_uInt32 nColors
= std::min(
307 (sal_uInt32
)pBuffer
->maPalette
.GetEntryCount(),
309 for( sal_uInt32 i
= 0; i
< nColors
; i
++ )
311 const BitmapColor
& rCol
= pBuffer
->maPalette
[i
];
312 (*pPal
)[i
] = basebmp::Color( rCol
.GetRed(), rCol
.GetGreen(), rCol
.GetBlue() );
315 m_aBitmap
= basebmp::createBitmapDevice( m_aBitmap
->getSize(),
316 m_aBitmap
->isTopDown(),
317 m_aBitmap
->getScanlineFormat(),
318 m_aBitmap
->getBuffer(),
326 bool SvpSalBitmap::GetSystemData( BitmapSystemData
& )