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: bitmapex.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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
35 #include <vcl/salbtype.hxx>
36 #include <tools/stream.hxx>
37 #include <tools/debug.hxx>
38 #include <vcl/outdev.hxx>
39 #include <vcl/alpha.hxx>
40 #include <vcl/image.h>
41 #include <vcl/bitmapex.hxx>
42 #include <vcl/pngread.hxx>
43 #ifndef _SV_IMPIMAGETREE_H
44 #include <vcl/impimagetree.hxx>
49 #include <vcl/svapp.hxx>
50 #include <vcl/virdev.hxx>
56 BitmapEx::BitmapEx() :
57 eTransparent( TRANSPARENT_NONE
),
62 // ------------------------------------------------------------------
64 BitmapEx::BitmapEx( const BitmapEx
& rBitmapEx
) :
65 aBitmap ( rBitmapEx
.aBitmap
),
66 aMask ( rBitmapEx
.aMask
),
67 aBitmapSize ( rBitmapEx
.aBitmapSize
),
68 aTransparentColor ( rBitmapEx
.aTransparentColor
),
69 eTransparent ( rBitmapEx
.eTransparent
),
70 bAlpha ( rBitmapEx
.bAlpha
)
74 BitmapEx::BitmapEx( const BitmapEx
& rBitmapEx
, Point aSrc
, Size aSize
) :
75 eTransparent( TRANSPARENT_NONE
),
78 if( rBitmapEx
.IsEmpty() )
81 aBitmap
= Bitmap( aSize
, rBitmapEx
.aBitmap
.GetBitCount() );
83 if( rBitmapEx
.IsAlpha() )
86 aMask
= AlphaMask( aSize
).ImplGetBitmap();
88 else if( rBitmapEx
.IsTransparent() )
89 aMask
= Bitmap( aSize
, rBitmapEx
.aMask
.GetBitCount() );
91 Rectangle
aDestRect( Point( 0, 0 ), aSize
);
92 Rectangle
aSrcRect( aSrc
, aSize
);
93 CopyPixel( aDestRect
, aSrcRect
, &rBitmapEx
);
96 // ------------------------------------------------------------------
98 BitmapEx::BitmapEx( const ResId
& rResId
) :
99 eTransparent( TRANSPARENT_NONE
),
102 static ImplImageTreeSingletonRef aImageTree
;
103 ResMgr
* pResMgr
= NULL
;
105 ResMgr::GetResourceSkipHeader( rResId
.SetRT( RSC_BITMAP
), &pResMgr
);
109 const String
aFileName( pResMgr
->ReadString() );
110 ::rtl::OUString aCurrentSymbolsStyle
= Application::GetSettings().GetStyleSettings().GetCurrentSymbolsStyleName();
112 if( !aImageTree
->loadImage( aFileName
, aCurrentSymbolsStyle
, *this ) )
115 ByteString
aErrorStr( "BitmapEx::BitmapEx( const ResId& rResId ): could not load image <" );
116 DBG_ERROR( ( ( aErrorStr
+= ByteString( aFileName
, RTL_TEXTENCODING_ASCII_US
) ) += '>' ).GetBuffer() );
121 // ------------------------------------------------------------------
123 BitmapEx::BitmapEx( const Bitmap
& rBmp
) :
125 aBitmapSize ( aBitmap
.GetSizePixel() ),
126 eTransparent( TRANSPARENT_NONE
),
131 // ------------------------------------------------------------------
133 BitmapEx::BitmapEx( const Bitmap
& rBmp
, const Bitmap
& rMask
) :
136 aBitmapSize ( aBitmap
.GetSizePixel() ),
137 eTransparent ( !rMask
? TRANSPARENT_NONE
: TRANSPARENT_BITMAP
),
140 DBG_ASSERT( !rMask
|| rBmp
.GetSizePixel() == rMask
.GetSizePixel(),
141 "BitmapEx::BitmapEx(): size mismatch for bitmap and mask." );
143 // #105489# Ensure a mask is exactly one bit deep
144 if( !!aMask
&& aMask
.GetBitCount() != 1 )
146 OSL_TRACE("BitmapEx: forced mask to monochrome");
147 aMask
.ImplMakeMono( 255 );
151 // ------------------------------------------------------------------
153 BitmapEx::BitmapEx( const Bitmap
& rBmp
, const AlphaMask
& rAlphaMask
) :
155 aMask ( rAlphaMask
.ImplGetBitmap() ),
156 aBitmapSize ( aBitmap
.GetSizePixel() ),
157 eTransparent ( !rAlphaMask
? TRANSPARENT_NONE
: TRANSPARENT_BITMAP
),
158 bAlpha ( !rAlphaMask
? FALSE
: TRUE
)
160 DBG_ASSERT( !rAlphaMask
|| rBmp
.GetSizePixel() == rAlphaMask
.GetSizePixel(),
161 "BitmapEx::BitmapEx(): size mismatch for bitmap and alpha mask." );
163 // #i75531# the workaround below can go when
164 // X11SalGraphics::drawAlphaBitmap()'s render acceleration
165 // can handle the bitmap depth mismatch directly
166 if( aBitmap
.GetBitCount() < aMask
.GetBitCount() )
167 aBitmap
.Convert( BMP_CONVERSION_24BIT
);
170 // ------------------------------------------------------------------
172 BitmapEx::BitmapEx( const Bitmap
& rBmp
, const Color
& rTransparentColor
) :
174 aBitmapSize ( aBitmap
.GetSizePixel() ),
175 aTransparentColor ( rTransparentColor
),
176 eTransparent ( TRANSPARENT_BITMAP
),
179 aMask
= aBitmap
.CreateMask( aTransparentColor
);
181 DBG_ASSERT( rBmp
.GetSizePixel() == aMask
.GetSizePixel(),
182 "BitmapEx::BitmapEx(): size mismatch for bitmap and alpha mask." );
185 // ------------------------------------------------------------------
187 BitmapEx::~BitmapEx()
191 // ------------------------------------------------------------------
193 // ------------------------------------------------------------------
195 BitmapEx
& BitmapEx::operator=( const BitmapEx
& rBitmapEx
)
197 if( &rBitmapEx
!= this )
199 aBitmap
= rBitmapEx
.aBitmap
;
200 aMask
= rBitmapEx
.aMask
;
201 aBitmapSize
= rBitmapEx
.aBitmapSize
;
202 aTransparentColor
= rBitmapEx
.aTransparentColor
;
203 eTransparent
= rBitmapEx
.eTransparent
;
204 bAlpha
= rBitmapEx
.bAlpha
;
210 // ------------------------------------------------------------------
212 BOOL
BitmapEx::operator==( const BitmapEx
& rBitmapEx
) const
214 if( eTransparent
!= rBitmapEx
.eTransparent
)
217 if( aBitmap
!= rBitmapEx
.aBitmap
)
220 if( aBitmapSize
!= rBitmapEx
.aBitmapSize
)
223 if( eTransparent
== TRANSPARENT_NONE
)
226 if( eTransparent
== TRANSPARENT_COLOR
)
227 return aTransparentColor
== rBitmapEx
.aTransparentColor
;
229 return( ( aMask
== rBitmapEx
.aMask
) && ( bAlpha
== rBitmapEx
.bAlpha
) );
232 // ------------------------------------------------------------------
234 BOOL
BitmapEx::IsEqual( const BitmapEx
& rBmpEx
) const
236 return( rBmpEx
.eTransparent
== eTransparent
&&
237 rBmpEx
.bAlpha
== bAlpha
&&
238 rBmpEx
.aBitmap
.IsEqual( aBitmap
) &&
239 rBmpEx
.aMask
.IsEqual( aMask
) );
242 // ------------------------------------------------------------------
244 BOOL
BitmapEx::IsEmpty() const
246 return( aBitmap
.IsEmpty() && aMask
.IsEmpty() );
249 // ------------------------------------------------------------------
251 void BitmapEx::SetEmpty()
255 eTransparent
= TRANSPARENT_NONE
;
259 // ------------------------------------------------------------------
261 void BitmapEx::Clear()
266 // ------------------------------------------------------------------
268 BOOL
BitmapEx::IsTransparent() const
270 return( eTransparent
!= TRANSPARENT_NONE
);
273 // ------------------------------------------------------------------
275 BOOL
BitmapEx::IsAlpha() const
277 return( IsTransparent() && bAlpha
);
280 // ------------------------------------------------------------------
282 Bitmap
BitmapEx::GetBitmap( const Color
* pTransReplaceColor
) const
284 Bitmap
aRetBmp( aBitmap
);
286 if( pTransReplaceColor
&& ( eTransparent
!= TRANSPARENT_NONE
) )
290 if( eTransparent
== TRANSPARENT_COLOR
)
291 aTempMask
= aBitmap
.CreateMask( aTransparentColor
);
296 aRetBmp
.Replace( aTempMask
, *pTransReplaceColor
);
298 aRetBmp
.Replace( GetAlpha(), *pTransReplaceColor
);
304 // ------------------------------------------------------------------
306 BitmapEx
BitmapEx::GetColorTransformedBitmapEx( BmpColorMode eColorMode
) const
310 if( BMP_COLOR_HIGHCONTRAST
== eColorMode
)
313 aRet
.aBitmap
= aBitmap
.GetColorTransformedBitmap( eColorMode
);
315 else if( BMP_COLOR_MONOCHROME_BLACK
== eColorMode
||
316 BMP_COLOR_MONOCHROME_WHITE
== eColorMode
)
319 aRet
.aBitmap
= aRet
.aBitmap
.GetColorTransformedBitmap( eColorMode
);
321 if( !aRet
.aMask
.IsEmpty() )
323 aRet
.aMask
.CombineSimple( aRet
.aBitmap
, BMP_COMBINE_OR
);
324 aRet
.aBitmap
.Erase( ( BMP_COLOR_MONOCHROME_BLACK
== eColorMode
) ? COL_BLACK
: COL_WHITE
);
326 DBG_ASSERT( aRet
.aBitmap
.GetSizePixel() == aRet
.aMask
.GetSizePixel(),
327 "BitmapEx::GetColorTransformedBitmapEx(): size mismatch for bitmap and alpha mask." );
334 // ------------------------------------------------------------------
336 Bitmap
BitmapEx::GetMask() const
338 Bitmap
aRet( aMask
);
341 aRet
.ImplMakeMono( 255 );
346 // ------------------------------------------------------------------
348 AlphaMask
BitmapEx::GetAlpha() const
353 aAlpha
.ImplSetBitmap( aMask
);
360 // ------------------------------------------------------------------
362 ULONG
BitmapEx::GetSizeBytes() const
364 ULONG nSizeBytes
= aBitmap
.GetSizeBytes();
366 if( eTransparent
== TRANSPARENT_BITMAP
)
367 nSizeBytes
+= aMask
.GetSizeBytes();
372 // ------------------------------------------------------------------
374 ULONG
BitmapEx::GetChecksum() const
376 sal_uInt32 nCrc
= aBitmap
.GetChecksum();
379 UInt32ToSVBT32( (long) eTransparent
, aBT32
);
380 nCrc
= rtl_crc32( nCrc
, aBT32
, 4 );
382 UInt32ToSVBT32( (long) bAlpha
, aBT32
);
383 nCrc
= rtl_crc32( nCrc
, aBT32
, 4 );
385 if( ( TRANSPARENT_BITMAP
== eTransparent
) && !aMask
.IsEmpty() )
387 UInt32ToSVBT32( aMask
.GetChecksum(), aBT32
);
388 nCrc
= rtl_crc32( nCrc
, aBT32
, 4 );
394 // ------------------------------------------------------------------
396 void BitmapEx::SetSizePixel( const Size
& rNewSize
)
401 // ------------------------------------------------------------------
403 BOOL
BitmapEx::Invert()
409 bRet
= aBitmap
.Invert();
411 if( bRet
&& ( eTransparent
== TRANSPARENT_COLOR
) )
412 aTransparentColor
= BitmapColor( aTransparentColor
).Invert();
418 // ------------------------------------------------------------------
420 BOOL
BitmapEx::Mirror( ULONG nMirrorFlags
)
426 bRet
= aBitmap
.Mirror( nMirrorFlags
);
428 if( bRet
&& ( eTransparent
== TRANSPARENT_BITMAP
) && !!aMask
)
429 aMask
.Mirror( nMirrorFlags
);
435 // ------------------------------------------------------------------
437 BOOL
BitmapEx::Scale( const double& rScaleX
, const double& rScaleY
, ULONG nScaleFlag
)
443 bRet
= aBitmap
.Scale( rScaleX
, rScaleY
, nScaleFlag
);
445 if( bRet
&& ( eTransparent
== TRANSPARENT_BITMAP
) && !!aMask
)
446 aMask
.Scale( rScaleX
, rScaleY
, BMP_SCALE_FAST
);
448 aBitmapSize
= aBitmap
.GetSizePixel();
450 DBG_ASSERT( !aMask
|| aBitmap
.GetSizePixel() == aMask
.GetSizePixel(),
451 "BitmapEx::Scale(): size mismatch for bitmap and alpha mask." );
457 // ------------------------------------------------------------------------
459 BOOL
BitmapEx::Scale( const Size
& rNewSize
, ULONG nScaleFlag
)
463 if( aBitmapSize
.Width() && aBitmapSize
.Height() )
465 bRet
= Scale( (double) rNewSize
.Width() / aBitmapSize
.Width(),
466 (double) rNewSize
.Height() / aBitmapSize
.Height(),
475 // ------------------------------------------------------------------
477 BOOL
BitmapEx::Rotate( long nAngle10
, const Color
& rFillColor
)
483 const BOOL bTransRotate
= ( Color( COL_TRANSPARENT
) == rFillColor
);
487 if( eTransparent
== TRANSPARENT_COLOR
)
488 bRet
= aBitmap
.Rotate( nAngle10
, aTransparentColor
);
491 bRet
= aBitmap
.Rotate( nAngle10
, COL_BLACK
);
493 if( eTransparent
== TRANSPARENT_NONE
)
495 aMask
= Bitmap( aBitmapSize
, 1 );
496 aMask
.Erase( COL_BLACK
);
497 eTransparent
= TRANSPARENT_BITMAP
;
500 if( bRet
&& !!aMask
)
501 aMask
.Rotate( nAngle10
, COL_WHITE
);
506 bRet
= aBitmap
.Rotate( nAngle10
, rFillColor
);
508 if( bRet
&& ( eTransparent
== TRANSPARENT_BITMAP
) && !!aMask
)
509 aMask
.Rotate( nAngle10
, COL_WHITE
);
512 aBitmapSize
= aBitmap
.GetSizePixel();
514 DBG_ASSERT( !aMask
|| aBitmap
.GetSizePixel() == aMask
.GetSizePixel(),
515 "BitmapEx::Rotate(): size mismatch for bitmap and alpha mask." );
521 // ------------------------------------------------------------------
523 BOOL
BitmapEx::Crop( const Rectangle
& rRectPixel
)
529 bRet
= aBitmap
.Crop( rRectPixel
);
531 if( bRet
&& ( eTransparent
== TRANSPARENT_BITMAP
) && !!aMask
)
532 aMask
.Crop( rRectPixel
);
534 aBitmapSize
= aBitmap
.GetSizePixel();
536 DBG_ASSERT( !aMask
|| aBitmap
.GetSizePixel() == aMask
.GetSizePixel(),
537 "BitmapEx::Crop(): size mismatch for bitmap and alpha mask." );
543 // ------------------------------------------------------------------
545 BOOL
BitmapEx::Convert( BmpConversion eConversion
)
547 return( !!aBitmap
? aBitmap
.Convert( eConversion
) : FALSE
);
550 // ------------------------------------------------------------------
552 BOOL
BitmapEx::ReduceColors( USHORT nNewColorCount
, BmpReduce eReduce
)
554 return( !!aBitmap
? aBitmap
.ReduceColors( nNewColorCount
, eReduce
) : FALSE
);
557 // ------------------------------------------------------------------
559 BOOL
BitmapEx::Expand( ULONG nDX
, ULONG nDY
, const Color
* pInitColor
, BOOL bExpandTransparent
)
565 bRet
= aBitmap
.Expand( nDX
, nDY
, pInitColor
);
567 if( bRet
&& ( eTransparent
== TRANSPARENT_BITMAP
) && !!aMask
)
569 Color
aColor( bExpandTransparent
? COL_WHITE
: COL_BLACK
);
570 aMask
.Expand( nDX
, nDY
, &aColor
);
573 aBitmapSize
= aBitmap
.GetSizePixel();
575 DBG_ASSERT( !aMask
|| aBitmap
.GetSizePixel() == aMask
.GetSizePixel(),
576 "BitmapEx::Expand(): size mismatch for bitmap and alpha mask." );
582 // ------------------------------------------------------------------
584 BOOL
BitmapEx::CopyPixel( const Rectangle
& rRectDst
, const Rectangle
& rRectSrc
,
585 const BitmapEx
* pBmpExSrc
)
589 if( !pBmpExSrc
|| pBmpExSrc
->IsEmpty() )
591 if( !aBitmap
.IsEmpty() )
593 bRet
= aBitmap
.CopyPixel( rRectDst
, rRectSrc
);
595 if( bRet
&& ( eTransparent
== TRANSPARENT_BITMAP
) && !!aMask
)
596 aMask
.CopyPixel( rRectDst
, rRectSrc
);
601 if( !aBitmap
.IsEmpty() )
603 bRet
= aBitmap
.CopyPixel( rRectDst
, rRectSrc
, &pBmpExSrc
->aBitmap
);
607 if( pBmpExSrc
->IsAlpha() )
610 // cast to use the optimized AlphaMask::CopyPixel
611 ((AlphaMask
*) &aMask
)->CopyPixel( rRectDst
, rRectSrc
, (AlphaMask
*)&pBmpExSrc
->aMask
);
612 else if( IsTransparent() )
614 AlphaMask
* pAlpha
= new AlphaMask( aMask
);
616 aMask
= pAlpha
->ImplGetBitmap();
619 aMask
.CopyPixel( rRectDst
, rRectSrc
, &pBmpExSrc
->aMask
);
623 sal_uInt8 cBlack
= 0;
624 AlphaMask
* pAlpha
= new AlphaMask( GetSizePixel(), &cBlack
);
626 aMask
= pAlpha
->ImplGetBitmap();
628 eTransparent
= TRANSPARENT_BITMAP
;
630 aMask
.CopyPixel( rRectDst
, rRectSrc
, &pBmpExSrc
->aMask
);
633 else if( pBmpExSrc
->IsTransparent() )
637 AlphaMask
aAlpha( pBmpExSrc
->aMask
);
638 aMask
.CopyPixel( rRectDst
, rRectSrc
, &aAlpha
.ImplGetBitmap() );
640 else if( IsTransparent() )
641 aMask
.CopyPixel( rRectDst
, rRectSrc
, &pBmpExSrc
->aMask
);
644 aMask
= Bitmap( GetSizePixel(), 1 );
645 aMask
.Erase( Color( COL_BLACK
) );
646 eTransparent
= TRANSPARENT_BITMAP
;
647 aMask
.CopyPixel( rRectDst
, rRectSrc
, &pBmpExSrc
->aMask
);
652 sal_uInt8 cBlack
= 0;
653 const AlphaMask
aAlphaSrc( pBmpExSrc
->GetSizePixel(), &cBlack
);
655 aMask
.CopyPixel( rRectDst
, rRectSrc
, &aAlphaSrc
.ImplGetBitmap() );
657 else if( IsTransparent() )
659 Bitmap
aMaskSrc( pBmpExSrc
->GetSizePixel(), 1 );
661 aMaskSrc
.Erase( Color( COL_BLACK
) );
662 aMask
.CopyPixel( rRectDst
, rRectSrc
, &aMaskSrc
);
671 // ------------------------------------------------------------------
673 BOOL
BitmapEx::Erase( const Color
& rFillColor
)
679 bRet
= aBitmap
.Erase( rFillColor
);
681 if( bRet
&& ( eTransparent
== TRANSPARENT_BITMAP
) && !!aMask
)
683 // #104416# Respect transparency on fill color
684 if( rFillColor
.GetTransparency() )
686 const Color
aFill( rFillColor
.GetTransparency(), rFillColor
.GetTransparency(), rFillColor
.GetTransparency() );
687 aMask
.Erase( aFill
);
691 const Color
aBlack( COL_BLACK
);
692 aMask
.Erase( aBlack
);
700 // ------------------------------------------------------------------
702 BOOL
BitmapEx::Dither( ULONG nDitherFlags
)
704 return( !!aBitmap
? aBitmap
.Dither( nDitherFlags
) : FALSE
);
707 // ------------------------------------------------------------------
709 BOOL
BitmapEx::Replace( const Color
& rSearchColor
, const Color
& rReplaceColor
, ULONG nTol
)
711 return( !!aBitmap
? aBitmap
.Replace( rSearchColor
, rReplaceColor
, nTol
) : FALSE
);
714 // ------------------------------------------------------------------
716 BOOL
BitmapEx::Replace( const Color
* pSearchColors
, const Color
* pReplaceColors
, ULONG nColorCount
, const ULONG
* pTols
)
718 return( !!aBitmap
? aBitmap
.Replace( pSearchColors
, pReplaceColors
, nColorCount
, (ULONG
*) pTols
) : FALSE
);
721 // ------------------------------------------------------------------
723 BOOL
BitmapEx::Adjust( short nLuminancePercent
, short nContrastPercent
,
724 short nChannelRPercent
, short nChannelGPercent
, short nChannelBPercent
,
725 double fGamma
, BOOL bInvert
)
727 return( !!aBitmap
? aBitmap
.Adjust( nLuminancePercent
, nContrastPercent
,
728 nChannelRPercent
, nChannelGPercent
, nChannelBPercent
,
729 fGamma
, bInvert
) : FALSE
);
732 // ------------------------------------------------------------------
734 BOOL
BitmapEx::Filter( BmpFilter eFilter
, const BmpFilterParam
* pFilterParam
, const Link
* pProgress
)
736 return( !!aBitmap
? aBitmap
.Filter( eFilter
, pFilterParam
, pProgress
) : FALSE
);
739 // ------------------------------------------------------------------
741 void BitmapEx::Draw( OutputDevice
* pOutDev
, const Point
& rDestPt
) const
743 pOutDev
->DrawBitmapEx( rDestPt
, *this );
746 // ------------------------------------------------------------------
748 void BitmapEx::Draw( OutputDevice
* pOutDev
,
749 const Point
& rDestPt
, const Size
& rDestSize
) const
751 pOutDev
->DrawBitmapEx( rDestPt
, rDestSize
, *this );
754 // ------------------------------------------------------------------
756 void BitmapEx::Draw( OutputDevice
* pOutDev
,
757 const Point
& rDestPt
, const Size
& rDestSize
,
758 const Point
& rSrcPtPixel
, const Size
& rSrcSizePixel
) const
760 pOutDev
->DrawBitmapEx( rDestPt
, rDestSize
, rSrcPtPixel
, rSrcSizePixel
, *this );
763 BitmapEx
BitmapEx:: AutoScaleBitmap(BitmapEx
& aBitmap
, const long aStandardSize
)
765 Point
aEmptyPoint(0,0);
766 sal_Int32 imgNewWidth
= 0;
767 sal_Int32 imgNewHeight
= 0;
770 BitmapEx aRet
= aBitmap
;
771 double imgOldWidth
= aRet
.GetSizePixel().Width();
772 double imgOldHeight
=aRet
.GetSizePixel().Height();
775 if (imgOldWidth
>= aStandardSize
|| imgOldHeight
>= aStandardSize
)
777 if (imgOldWidth
>= imgOldHeight
)
779 imgNewWidth
= aStandardSize
;
780 imgNewHeight
= sal_Int32(imgOldHeight
/ (imgOldWidth
/ aStandardSize
) + 0.5);
782 imgposY
= (aStandardSize
- (imgOldHeight
/ (imgOldWidth
/ aStandardSize
) + 0.5)) / 2 + 0.5;
786 imgNewHeight
= aStandardSize
;
787 imgNewWidth
= sal_Int32(imgOldWidth
/ (imgOldHeight
/ aStandardSize
) + 0.5);
789 imgposX
= (aStandardSize
- (imgOldWidth
/ (imgOldHeight
/ aStandardSize
) + 0.5)) / 2 + 0.5;
792 aScaledSize
= Size( imgNewWidth
, imgNewHeight
);
793 aRet
.Scale( aScaledSize
, BMP_SCALE_INTERPOLATE
);
797 imgposX
= (aStandardSize
- imgOldWidth
) / 2 + 0.5;
798 imgposY
= (aStandardSize
- imgOldHeight
) / 2 + 0.5;
801 Size aBmpSize
= aRet
.GetSizePixel();
802 Size
aStdSize( aStandardSize
, aStandardSize
);
803 Rectangle
aRect(aEmptyPoint
, aStdSize
);
805 VirtualDevice
aVirDevice( *Application::GetDefaultDevice(), 0, 1 );
806 aVirDevice
.SetOutputSizePixel( aStdSize
);
807 aVirDevice
.SetFillColor( COL_TRANSPARENT
);
808 aVirDevice
.SetLineColor( COL_TRANSPARENT
);
810 //draw a rect into virDevice
811 aVirDevice
.DrawRect( aRect
);
812 Point
aPointPixel( (long)imgposX
, (long)imgposY
);
813 aVirDevice
.DrawBitmapEx( aPointPixel
, aRet
);
814 aRet
= aVirDevice
.GetBitmapEx( aEmptyPoint
, aStdSize
);
818 // ------------------------------------------------------------------
820 SvStream
& operator<<( SvStream
& rOStm
, const BitmapEx
& rBitmapEx
)
822 rBitmapEx
.aBitmap
.Write( rOStm
);
824 rOStm
<< (UINT32
) 0x25091962;
825 rOStm
<< (UINT32
) 0xACB20201;
826 rOStm
<< (BYTE
) rBitmapEx
.eTransparent
;
828 if( rBitmapEx
.eTransparent
== TRANSPARENT_BITMAP
)
829 rBitmapEx
.aMask
.Write( rOStm
);
830 else if( rBitmapEx
.eTransparent
== TRANSPARENT_COLOR
)
831 rOStm
<< rBitmapEx
.aTransparentColor
;
836 // ------------------------------------------------------------------
838 SvStream
& operator>>( SvStream
& rIStm
, BitmapEx
& rBitmapEx
)
844 if( !rIStm
.GetError() )
846 const ULONG nStmPos
= rIStm
.Tell();
850 rIStm
>> nMagic1
>> nMagic2
;
852 if( ( nMagic1
!= 0x25091962 ) || ( nMagic2
!= 0xACB20201 ) || rIStm
.GetError() )
855 rIStm
.Seek( nStmPos
);
860 BYTE bTransparent
= false;
862 rIStm
>> bTransparent
;
864 if( bTransparent
== (BYTE
) TRANSPARENT_BITMAP
)
872 // do we have an alpha mask?
873 if( ( 8 == aMask
.GetBitCount() ) && aMask
.HasGreyPalette() )
877 // create alpha mask quickly (without greyscale conversion)
878 aAlpha
.ImplSetBitmap( aMask
);
879 rBitmapEx
= BitmapEx( aBmp
, aAlpha
);
882 rBitmapEx
= BitmapEx( aBmp
, aMask
);
887 else if( bTransparent
== (BYTE
) TRANSPARENT_COLOR
)
889 Color aTransparentColor
;
891 rIStm
>> aTransparentColor
;
892 rBitmapEx
= BitmapEx( aBmp
, aTransparentColor
);