23#include <com/sun/star/lang/XServiceInfo.hpp>
24#include <com/sun/star/rendering/XIntegerBitmap.hpp>
26#include <vcl/bitmap.hxx>
41 sal_Int32 calcDIBColorCount(
const BITMAPINFOHEADER& rBIH )
43 if( rBIH.biSize !=
sizeof( BITMAPCOREHEADER ) )
45 if( rBIH.biBitCount <= 8 )
48 return rBIH.biClrUsed;
50 return 1 << rBIH.biBitCount;
55 BITMAPCOREHEADER
const * pCoreHeader =
reinterpret_cast<BITMAPCOREHEADER
const *
>(&rBIH);
57 if( pCoreHeader->bcBitCount <= 8 )
58 return 1 << pCoreHeader->bcBitCount;
65 bool drawDIBits(
const std::shared_ptr< Gdiplus::Graphics >& rGraphics,
70 const BITMAPINFO* pBI =
static_cast<BITMAPINFO*
>(GlobalLock(
const_cast<void *
>(hDIB) ));
74 const BYTE* pBits =
reinterpret_cast<BYTE const *
>(pBI) + pBI->bmiHeader.biSize +
75 calcDIBColorCount( pBI->bmiHeader ) *
sizeof( RGBQUAD );
81 GlobalUnlock(
const_cast<void *
>(hDIB) );
93 bool drawVCLBitmap(
const std::shared_ptr< Gdiplus::Graphics >& rGraphics,
135 RawRGBABitmap bitmapFromVCLBitmapEx( const ::BitmapEx& rBmpEx )
144 "::dxcanvas::tools::bitmapFromVCLBitmapEx(): "
145 "BmpEx has no alpha" );
150 const ::Size aBmpSize( rBmpEx.GetSizePixel() );
153 aBmpData.mnWidth = aBmpSize.Width();
154 aBmpData.mnHeight = aBmpSize.Height();
157 Bitmap aBitmap( rBmpEx.GetBitmap() );
161 const sal_Int32 nWidth( aBmpSize.Width() );
162 const sal_Int32 nHeight( aBmpSize.Height() );
165 "::dxcanvas::tools::bitmapFromVCLBitmapEx(): "
166 "Unable to acquire read access to bitmap" );
168 Bitmap aAlpha( rBmpEx.GetAlphaMask().GetBitmap() );
187 "::dxcanvas::tools::bitmapFromVCLBitmapEx(): "
188 "Unable to acquire read access to alpha" );
190 ENSURE_OR_THROW( pAlphaReadAccess->GetScanlineFormat() == ScanlineFormat::N8BitPal,
191 "::dxcanvas::tools::bitmapFromVCLBitmapEx(): "
192 "Unsupported alpha scanline format" );
198 for(
y=0;
y<nHeight; ++
y )
200 switch( pReadAccess->GetScanlineFormat() )
202 case ScanlineFormat::N8BitPal:
204 Scanline pScan = pReadAccess->GetScanline(
y );
205 Scanline pAScan = pAlphaReadAccess->GetScanline(
y );
207 for(
x=0;
x<nWidth; ++
x )
209 aCol = pReadAccess->GetPaletteColor( *pScan++ );
211 *pCurrOutput++ = aCol.GetBlue();
212 *pCurrOutput++ = aCol.GetGreen();
213 *pCurrOutput++ = aCol.GetRed();
214 *pCurrOutput++ =
static_cast<BYTE>(*pAScan++);
219 case ScanlineFormat::N24BitTcBgr:
221 Scanline pScan = pReadAccess->GetScanline(
y );
222 Scanline pAScan = pAlphaReadAccess->GetScanline(
y );
224 for(
x=0;
x<nWidth; ++
x )
227 *pCurrOutput++ = *pScan++;
228 *pCurrOutput++ = *pScan++;
229 *pCurrOutput++ = *pScan++;
230 *pCurrOutput++ =
static_cast<BYTE>(*pAScan++);
238 case ScanlineFormat::N1BitMsbPal:
239 case ScanlineFormat::N32BitTcMask:
241 Scanline pAScan = pAlphaReadAccess->GetScanline(
y );
245 for(
x=0;
x<nWidth; ++
x )
248 aCol = pReadAccess->GetColor(
y,
x);
250 *pCurrOutput++ = aCol.GetBlue();
251 *pCurrOutput++ = aCol.GetGreen();
252 *pCurrOutput++ = aCol.GetRed();
253 *pCurrOutput++ =
static_cast<BYTE>(*pAScan++);
258 case ScanlineFormat::N24BitTcRgb:
259 case ScanlineFormat::N32BitTcAbgr:
260 case ScanlineFormat::N32BitTcArgb:
261 case ScanlineFormat::N32BitTcBgra:
262 case ScanlineFormat::N32BitTcRgba:
265 "::dxcanvas::tools::bitmapFromVCLBitmapEx(): "
266 "Unexpected scanline format - has "
267 "WinSalBitmap::AcquireBuffer() changed?" );
274 bool drawVCLBitmapEx(
const std::shared_ptr< Gdiplus::Graphics >& rGraphics,
275 const ::BitmapEx& rBmpEx )
277 if( !rBmpEx.IsAlpha() )
279 Bitmap aBmp( rBmpEx.GetBitmap() );
280 return drawVCLBitmap( rGraphics, aBmp );
285 bitmapFromVCLBitmapEx( rBmpEx ) );
291 const uno::Reference< rendering::XBitmap >& xBitmap )
294 uno::Reference< rendering::XIntegerReadOnlyBitmap > xIntBmp(
295 xBitmap, uno::UNO_QUERY );
304 return drawVCLBitmapEx( rGraphics, aBmpEx );
static void ReleaseAccess(BitmapInfoAccess *pAccess)
BitmapReadAccess * AcquireReadAccess()
bool GetSystemData(BitmapSystemData &rData) const
#define ENSURE_OR_THROW(c, m)
Gdiplus::BitmapData aBmpData