xref: /aoo42x/main/vcl/source/gdi/bitmapex.cxx (revision 479f2b27)
19f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
39f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
49f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
59f62ea84SAndrew Rist  * distributed with this work for additional information
69f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
79f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
89f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
99f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
109f62ea84SAndrew Rist  *
119f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
129f62ea84SAndrew Rist  *
139f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
149f62ea84SAndrew Rist  * software distributed under the License is distributed on an
159f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
179f62ea84SAndrew Rist  * specific language governing permissions and limitations
189f62ea84SAndrew Rist  * under the License.
199f62ea84SAndrew Rist  *
209f62ea84SAndrew Rist  *************************************************************/
219f62ea84SAndrew Rist 
229f62ea84SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <ctype.h>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <rtl/crc.h>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <tools/stream.hxx>
32cdf0e10cSrcweir #include <tools/debug.hxx>
33cdf0e10cSrcweir #include <tools/rc.h>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include <vcl/salbtype.hxx>
36cdf0e10cSrcweir #include <vcl/outdev.hxx>
37cdf0e10cSrcweir #include <vcl/alpha.hxx>
38cdf0e10cSrcweir #include <vcl/bitmapex.hxx>
39cdf0e10cSrcweir #include <vcl/pngread.hxx>
40cdf0e10cSrcweir #include <vcl/svapp.hxx>
41cdf0e10cSrcweir #include <vcl/bmpacc.hxx>
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #include <image.h>
44cdf0e10cSrcweir #include <impimagetree.hxx>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir // ------------
47cdf0e10cSrcweir // - BitmapEx -
48cdf0e10cSrcweir // ------------
49cdf0e10cSrcweir 
50cdf0e10cSrcweir BitmapEx::BitmapEx() :
51cdf0e10cSrcweir 		eTransparent( TRANSPARENT_NONE ),
52cdf0e10cSrcweir 		bAlpha		( sal_False )
53cdf0e10cSrcweir {
54cdf0e10cSrcweir }
55cdf0e10cSrcweir 
56cdf0e10cSrcweir // ------------------------------------------------------------------
57cdf0e10cSrcweir 
58cdf0e10cSrcweir BitmapEx::BitmapEx( const BitmapEx& rBitmapEx ) :
59cdf0e10cSrcweir 		aBitmap				( rBitmapEx.aBitmap ),
60cdf0e10cSrcweir 		aMask				( rBitmapEx.aMask ),
61cdf0e10cSrcweir 		aBitmapSize			( rBitmapEx.aBitmapSize ),
62cdf0e10cSrcweir 		aTransparentColor	( rBitmapEx.aTransparentColor ),
63cdf0e10cSrcweir 		eTransparent		( rBitmapEx.eTransparent ),
64cdf0e10cSrcweir 		bAlpha				( rBitmapEx.bAlpha )
65cdf0e10cSrcweir {
66cdf0e10cSrcweir }
67cdf0e10cSrcweir 
68cdf0e10cSrcweir BitmapEx::BitmapEx( const BitmapEx& rBitmapEx, Point aSrc, Size aSize ) :
69cdf0e10cSrcweir 		eTransparent( TRANSPARENT_NONE ),
70cdf0e10cSrcweir 		bAlpha		( sal_False )
71cdf0e10cSrcweir {
72cdf0e10cSrcweir 	if( rBitmapEx.IsEmpty() )
73cdf0e10cSrcweir 		return;
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 	aBitmap = Bitmap( aSize, rBitmapEx.aBitmap.GetBitCount() );
76cdf0e10cSrcweir 	aBitmapSize = aSize;
77cdf0e10cSrcweir 	if( rBitmapEx.IsAlpha() )
78cdf0e10cSrcweir 	{
79cdf0e10cSrcweir 		bAlpha = sal_True;
80cdf0e10cSrcweir 		aMask = AlphaMask( aSize ).ImplGetBitmap();
81cdf0e10cSrcweir 	}
82cdf0e10cSrcweir 	else if( rBitmapEx.IsTransparent() )
83cdf0e10cSrcweir 		aMask = Bitmap( aSize, rBitmapEx.aMask.GetBitCount() );
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 	Rectangle aDestRect( Point( 0, 0 ), aSize );
86cdf0e10cSrcweir 	Rectangle aSrcRect( aSrc, aSize );
87cdf0e10cSrcweir 	CopyPixel( aDestRect, aSrcRect, &rBitmapEx );
88cdf0e10cSrcweir }
89cdf0e10cSrcweir 
90cdf0e10cSrcweir // ------------------------------------------------------------------
91cdf0e10cSrcweir 
92cdf0e10cSrcweir BitmapEx::BitmapEx( const ResId& rResId ) :
93cdf0e10cSrcweir 		eTransparent( TRANSPARENT_NONE ),
94cdf0e10cSrcweir 		bAlpha		( sal_False )
95cdf0e10cSrcweir {
96cdf0e10cSrcweir 	static ImplImageTreeSingletonRef	aImageTree;
97cdf0e10cSrcweir 	ResMgr* 							pResMgr = NULL;
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 	ResMgr::GetResourceSkipHeader( rResId.SetRT( RSC_BITMAP ), &pResMgr );
100cdf0e10cSrcweir 	pResMgr->ReadLong();
101cdf0e10cSrcweir 	pResMgr->ReadLong();
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 	const String aFileName( pResMgr->ReadString() );
104cdf0e10cSrcweir 	::rtl::OUString aCurrentSymbolsStyle = Application::GetSettings().GetStyleSettings().GetCurrentSymbolsStyleName();
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 	if( !aImageTree->loadImage( aFileName, aCurrentSymbolsStyle, *this ) )
107cdf0e10cSrcweir 	{
108cdf0e10cSrcweir #ifdef DBG_UTIL
109cdf0e10cSrcweir 		ByteString aErrorStr( "BitmapEx::BitmapEx( const ResId& rResId ): could not load image <" );
110cdf0e10cSrcweir 		DBG_ERROR( ( ( aErrorStr += ByteString( aFileName, RTL_TEXTENCODING_ASCII_US ) ) += '>' ).GetBuffer() );
111cdf0e10cSrcweir #endif
112cdf0e10cSrcweir 	}
113cdf0e10cSrcweir }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir // ------------------------------------------------------------------
116cdf0e10cSrcweir 
117cdf0e10cSrcweir BitmapEx::BitmapEx( const Bitmap& rBmp ) :
118cdf0e10cSrcweir 		aBitmap		( rBmp ),
119cdf0e10cSrcweir 		aBitmapSize	( aBitmap.GetSizePixel() ),
120cdf0e10cSrcweir 		eTransparent( TRANSPARENT_NONE ),
121cdf0e10cSrcweir 		bAlpha		( sal_False )
122cdf0e10cSrcweir {
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir // ------------------------------------------------------------------
126cdf0e10cSrcweir 
127cdf0e10cSrcweir BitmapEx::BitmapEx( const Bitmap& rBmp, const Bitmap& rMask ) :
128cdf0e10cSrcweir 		aBitmap			( rBmp ),
129cdf0e10cSrcweir 		aMask			( rMask ),
130cdf0e10cSrcweir 		aBitmapSize		( aBitmap.GetSizePixel() ),
131cdf0e10cSrcweir 		eTransparent	( !rMask ? TRANSPARENT_NONE : TRANSPARENT_BITMAP ),
132cdf0e10cSrcweir 		bAlpha			( sal_False )
133cdf0e10cSrcweir {
134*479f2b27SArmin Le Grand     if(!rMask)
135*479f2b27SArmin Le Grand     {
136*479f2b27SArmin Le Grand         OSL_ENSURE(false, "Empty mask given (!)");
137*479f2b27SArmin Le Grand     }
138*479f2b27SArmin Le Grand     else if(rBmp.GetSizePixel() != rMask.GetSizePixel())
139*479f2b27SArmin Le Grand     {
140*479f2b27SArmin Le Grand         OSL_ENSURE(false, "Mask size differs from Bitmap size, corrected Mask (!)");
141*479f2b27SArmin Le Grand         aMask.Scale(rBmp.GetSizePixel());
142*479f2b27SArmin Le Grand     }
143cdf0e10cSrcweir 
144cdf0e10cSrcweir     // #105489# Ensure a mask is exactly one bit deep
145cdf0e10cSrcweir     if( !!aMask && aMask.GetBitCount() != 1 )
146cdf0e10cSrcweir     {
147cdf0e10cSrcweir         OSL_TRACE("BitmapEx: forced mask to monochrome");
148cdf0e10cSrcweir         aMask.ImplMakeMono( 255 );
149cdf0e10cSrcweir     }
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir // ------------------------------------------------------------------
153cdf0e10cSrcweir 
154cdf0e10cSrcweir BitmapEx::BitmapEx( const Bitmap& rBmp, const AlphaMask& rAlphaMask ) :
155cdf0e10cSrcweir 		aBitmap			( rBmp ),
156cdf0e10cSrcweir 		aMask			( rAlphaMask.ImplGetBitmap() ),
157cdf0e10cSrcweir 		aBitmapSize		( aBitmap.GetSizePixel() ),
158cdf0e10cSrcweir 		eTransparent	( !rAlphaMask ? TRANSPARENT_NONE : TRANSPARENT_BITMAP ),
159cdf0e10cSrcweir 		bAlpha			( !rAlphaMask ? sal_False : sal_True )
160cdf0e10cSrcweir {
161*479f2b27SArmin Le Grand     if(!rAlphaMask)
162*479f2b27SArmin Le Grand     {
163*479f2b27SArmin Le Grand         OSL_ENSURE(false, "Empty alpha given (!)");
164*479f2b27SArmin Le Grand     }
165*479f2b27SArmin Le Grand     else if(rBmp.GetSizePixel() != rAlphaMask.GetSizePixel())
166*479f2b27SArmin Le Grand     {
167*479f2b27SArmin Le Grand         OSL_ENSURE(false, "Alpha size differs from Bitmap size, corrected Mask (!)");
168*479f2b27SArmin Le Grand         aMask.Scale(rBmp.GetSizePixel());
169*479f2b27SArmin Le Grand     }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir     // #i75531# the workaround below can go when
172cdf0e10cSrcweir     // X11SalGraphics::drawAlphaBitmap()'s render acceleration
173cdf0e10cSrcweir     // can handle the bitmap depth mismatch directly
174cdf0e10cSrcweir     if( aBitmap.GetBitCount() < aMask.GetBitCount() )
175cdf0e10cSrcweir         aBitmap.Convert( BMP_CONVERSION_24BIT );
176cdf0e10cSrcweir }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir // ------------------------------------------------------------------
179cdf0e10cSrcweir 
180cdf0e10cSrcweir BitmapEx::BitmapEx( const Bitmap& rBmp, const Color& rTransparentColor ) :
181cdf0e10cSrcweir 		aBitmap				( rBmp ),
182cdf0e10cSrcweir 		aBitmapSize			( aBitmap.GetSizePixel() ),
183cdf0e10cSrcweir 		aTransparentColor	( rTransparentColor ),
184cdf0e10cSrcweir 		eTransparent		( TRANSPARENT_BITMAP ),
185cdf0e10cSrcweir 		bAlpha				( sal_False )
186cdf0e10cSrcweir {
187cdf0e10cSrcweir 	aMask = aBitmap.CreateMask( aTransparentColor );
188cdf0e10cSrcweir 
189cdf0e10cSrcweir     DBG_ASSERT( rBmp.GetSizePixel() == aMask.GetSizePixel(),
190cdf0e10cSrcweir                 "BitmapEx::BitmapEx(): size mismatch for bitmap and alpha mask." );
191cdf0e10cSrcweir }
192cdf0e10cSrcweir 
193cdf0e10cSrcweir // ------------------------------------------------------------------
194cdf0e10cSrcweir 
195cdf0e10cSrcweir BitmapEx::~BitmapEx()
196cdf0e10cSrcweir {
197cdf0e10cSrcweir }
198cdf0e10cSrcweir 
199cdf0e10cSrcweir // ------------------------------------------------------------------
200cdf0e10cSrcweir 
201cdf0e10cSrcweir // ------------------------------------------------------------------
202cdf0e10cSrcweir 
203cdf0e10cSrcweir BitmapEx& BitmapEx::operator=( const BitmapEx& rBitmapEx )
204cdf0e10cSrcweir {
205cdf0e10cSrcweir 	if( &rBitmapEx != this )
206cdf0e10cSrcweir 	{
207cdf0e10cSrcweir 		aBitmap = rBitmapEx.aBitmap;
208cdf0e10cSrcweir 		aMask = rBitmapEx.aMask;
209cdf0e10cSrcweir 		aBitmapSize = rBitmapEx.aBitmapSize;
210cdf0e10cSrcweir 		aTransparentColor = rBitmapEx.aTransparentColor;
211cdf0e10cSrcweir 		eTransparent = rBitmapEx.eTransparent;
212cdf0e10cSrcweir 		bAlpha = rBitmapEx.bAlpha;
213cdf0e10cSrcweir 	}
214cdf0e10cSrcweir 
215cdf0e10cSrcweir 	return *this;
216cdf0e10cSrcweir }
217cdf0e10cSrcweir 
218cdf0e10cSrcweir // ------------------------------------------------------------------
219cdf0e10cSrcweir 
220cdf0e10cSrcweir sal_Bool BitmapEx::operator==( const BitmapEx& rBitmapEx ) const
221cdf0e10cSrcweir {
222cdf0e10cSrcweir 	if( eTransparent != rBitmapEx.eTransparent )
223cdf0e10cSrcweir 		return sal_False;
224cdf0e10cSrcweir 
225cdf0e10cSrcweir 	if( aBitmap != rBitmapEx.aBitmap )
226cdf0e10cSrcweir 		return sal_False;
227cdf0e10cSrcweir 
228cdf0e10cSrcweir 	if( aBitmapSize != rBitmapEx.aBitmapSize )
229cdf0e10cSrcweir 		return sal_False;
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 	if( eTransparent == TRANSPARENT_NONE )
232cdf0e10cSrcweir 		return sal_True;
233cdf0e10cSrcweir 
234cdf0e10cSrcweir 	if( eTransparent == TRANSPARENT_COLOR )
235cdf0e10cSrcweir 		return aTransparentColor == rBitmapEx.aTransparentColor;
236cdf0e10cSrcweir 
237cdf0e10cSrcweir 	return( ( aMask == rBitmapEx.aMask ) && ( bAlpha == rBitmapEx.bAlpha ) );
238cdf0e10cSrcweir }
239cdf0e10cSrcweir 
240cdf0e10cSrcweir // ------------------------------------------------------------------
241cdf0e10cSrcweir 
242cdf0e10cSrcweir sal_Bool BitmapEx::IsEqual( const BitmapEx& rBmpEx ) const
243cdf0e10cSrcweir {
244cdf0e10cSrcweir 	return( rBmpEx.eTransparent == eTransparent &&
245cdf0e10cSrcweir 			rBmpEx.bAlpha == bAlpha &&
246cdf0e10cSrcweir 			rBmpEx.aBitmap.IsEqual( aBitmap ) &&
247cdf0e10cSrcweir 			rBmpEx.aMask.IsEqual( aMask ) );
248cdf0e10cSrcweir }
249cdf0e10cSrcweir 
250cdf0e10cSrcweir // ------------------------------------------------------------------
251cdf0e10cSrcweir 
252cdf0e10cSrcweir sal_Bool BitmapEx::IsEmpty() const
253cdf0e10cSrcweir {
254cdf0e10cSrcweir 	return( aBitmap.IsEmpty() && aMask.IsEmpty() );
255cdf0e10cSrcweir }
256cdf0e10cSrcweir 
257cdf0e10cSrcweir // ------------------------------------------------------------------
258cdf0e10cSrcweir 
259cdf0e10cSrcweir void BitmapEx::SetEmpty()
260cdf0e10cSrcweir {
261cdf0e10cSrcweir 	aBitmap.SetEmpty();
262cdf0e10cSrcweir 	aMask.SetEmpty();
263cdf0e10cSrcweir 	eTransparent = TRANSPARENT_NONE;
264cdf0e10cSrcweir 	bAlpha = sal_False;
265cdf0e10cSrcweir }
266cdf0e10cSrcweir 
267cdf0e10cSrcweir // ------------------------------------------------------------------
268cdf0e10cSrcweir 
269cdf0e10cSrcweir void BitmapEx::Clear()
270cdf0e10cSrcweir {
271cdf0e10cSrcweir 	SetEmpty();
272cdf0e10cSrcweir }
273cdf0e10cSrcweir 
274cdf0e10cSrcweir // ------------------------------------------------------------------
275cdf0e10cSrcweir 
276cdf0e10cSrcweir sal_Bool BitmapEx::IsTransparent() const
277cdf0e10cSrcweir {
278cdf0e10cSrcweir 	return( eTransparent != TRANSPARENT_NONE );
279cdf0e10cSrcweir }
280cdf0e10cSrcweir 
281cdf0e10cSrcweir // ------------------------------------------------------------------
282cdf0e10cSrcweir 
283cdf0e10cSrcweir sal_Bool BitmapEx::IsAlpha() const
284cdf0e10cSrcweir {
285cdf0e10cSrcweir 	return( IsTransparent() && bAlpha );
286cdf0e10cSrcweir }
287cdf0e10cSrcweir 
288cdf0e10cSrcweir // ------------------------------------------------------------------
289cdf0e10cSrcweir 
290cdf0e10cSrcweir Bitmap BitmapEx::GetBitmap( const Color* pTransReplaceColor ) const
291cdf0e10cSrcweir {
292cdf0e10cSrcweir 	Bitmap aRetBmp( aBitmap );
293cdf0e10cSrcweir 
294cdf0e10cSrcweir 	if( pTransReplaceColor && ( eTransparent != TRANSPARENT_NONE ) )
295cdf0e10cSrcweir 	{
296cdf0e10cSrcweir 		Bitmap aTempMask;
297cdf0e10cSrcweir 
298cdf0e10cSrcweir 		if( eTransparent == TRANSPARENT_COLOR )
299cdf0e10cSrcweir 			aTempMask = aBitmap.CreateMask( aTransparentColor );
300cdf0e10cSrcweir 		else
301cdf0e10cSrcweir 			aTempMask = aMask;
302cdf0e10cSrcweir 
303cdf0e10cSrcweir 		if( !IsAlpha() )
304cdf0e10cSrcweir 			aRetBmp.Replace( aTempMask, *pTransReplaceColor );
305cdf0e10cSrcweir 		else
306cdf0e10cSrcweir 			aRetBmp.Replace( GetAlpha(), *pTransReplaceColor );
307cdf0e10cSrcweir 	}
308cdf0e10cSrcweir 
309cdf0e10cSrcweir 	return aRetBmp;
310cdf0e10cSrcweir }
311cdf0e10cSrcweir 
312cdf0e10cSrcweir // ------------------------------------------------------------------
313cdf0e10cSrcweir 
314cdf0e10cSrcweir BitmapEx BitmapEx::GetColorTransformedBitmapEx( BmpColorMode eColorMode ) const
315cdf0e10cSrcweir {
316cdf0e10cSrcweir 	BitmapEx aRet;
317cdf0e10cSrcweir 
318cdf0e10cSrcweir 	if( BMP_COLOR_HIGHCONTRAST == eColorMode )
319cdf0e10cSrcweir 	{
320cdf0e10cSrcweir 		aRet = *this;
321cdf0e10cSrcweir 		aRet.aBitmap = aBitmap.GetColorTransformedBitmap( eColorMode );
322cdf0e10cSrcweir 	}
323cdf0e10cSrcweir 	else if( BMP_COLOR_MONOCHROME_BLACK == eColorMode ||
324cdf0e10cSrcweir 			 BMP_COLOR_MONOCHROME_WHITE == eColorMode )
325cdf0e10cSrcweir 	{
326cdf0e10cSrcweir 		aRet = *this;
327cdf0e10cSrcweir 		aRet.aBitmap = aRet.aBitmap.GetColorTransformedBitmap( eColorMode );
328cdf0e10cSrcweir 
329cdf0e10cSrcweir 		if( !aRet.aMask.IsEmpty() )
330cdf0e10cSrcweir 		{
331cdf0e10cSrcweir 			aRet.aMask.CombineSimple( aRet.aBitmap, BMP_COMBINE_OR );
332cdf0e10cSrcweir 			aRet.aBitmap.Erase( ( BMP_COLOR_MONOCHROME_BLACK == eColorMode ) ? COL_BLACK : COL_WHITE );
333cdf0e10cSrcweir 
334cdf0e10cSrcweir             DBG_ASSERT( aRet.aBitmap.GetSizePixel() == aRet.aMask.GetSizePixel(),
335cdf0e10cSrcweir                         "BitmapEx::GetColorTransformedBitmapEx(): size mismatch for bitmap and alpha mask." );
336cdf0e10cSrcweir 		}
337cdf0e10cSrcweir 	}
338cdf0e10cSrcweir 
339cdf0e10cSrcweir 	return aRet;
340cdf0e10cSrcweir }
341cdf0e10cSrcweir 
342cdf0e10cSrcweir // ------------------------------------------------------------------
343cdf0e10cSrcweir 
344cdf0e10cSrcweir Bitmap BitmapEx::GetMask() const
345cdf0e10cSrcweir {
346cdf0e10cSrcweir 	Bitmap aRet( aMask );
347cdf0e10cSrcweir 
348cdf0e10cSrcweir 	if( IsAlpha() )
349cdf0e10cSrcweir 		aRet.ImplMakeMono( 255 );
350cdf0e10cSrcweir 
351cdf0e10cSrcweir 	return aRet;
352cdf0e10cSrcweir }
353cdf0e10cSrcweir 
354cdf0e10cSrcweir // ------------------------------------------------------------------
355cdf0e10cSrcweir 
356cdf0e10cSrcweir AlphaMask BitmapEx::GetAlpha() const
357cdf0e10cSrcweir {
358cdf0e10cSrcweir 	AlphaMask aAlpha;
359cdf0e10cSrcweir 
360cdf0e10cSrcweir 	if( IsAlpha() )
361cdf0e10cSrcweir 		aAlpha.ImplSetBitmap( aMask );
362cdf0e10cSrcweir 	else
363cdf0e10cSrcweir 		aAlpha = aMask;
364cdf0e10cSrcweir 
365cdf0e10cSrcweir 	return aAlpha;
366cdf0e10cSrcweir }
367cdf0e10cSrcweir 
368cdf0e10cSrcweir // ------------------------------------------------------------------
369cdf0e10cSrcweir 
370cdf0e10cSrcweir sal_uLong BitmapEx::GetSizeBytes() const
371cdf0e10cSrcweir {
372cdf0e10cSrcweir 	sal_uLong nSizeBytes = aBitmap.GetSizeBytes();
373cdf0e10cSrcweir 
374cdf0e10cSrcweir 	if( eTransparent == TRANSPARENT_BITMAP )
375cdf0e10cSrcweir 		nSizeBytes += aMask.GetSizeBytes();
376cdf0e10cSrcweir 
377cdf0e10cSrcweir 	return nSizeBytes;
378cdf0e10cSrcweir }
379cdf0e10cSrcweir 
380cdf0e10cSrcweir // ------------------------------------------------------------------
381cdf0e10cSrcweir 
382cdf0e10cSrcweir sal_uLong BitmapEx::GetChecksum() const
383cdf0e10cSrcweir {
384cdf0e10cSrcweir 	sal_uInt32	nCrc = aBitmap.GetChecksum();
385cdf0e10cSrcweir 	SVBT32		aBT32;
386cdf0e10cSrcweir 
387cdf0e10cSrcweir 	UInt32ToSVBT32( (long) eTransparent, aBT32 );
388cdf0e10cSrcweir 	nCrc = rtl_crc32( nCrc, aBT32, 4 );
389cdf0e10cSrcweir 
390cdf0e10cSrcweir 	UInt32ToSVBT32( (long) bAlpha, aBT32 );
391cdf0e10cSrcweir 	nCrc = rtl_crc32( nCrc, aBT32, 4 );
392cdf0e10cSrcweir 
393cdf0e10cSrcweir 	if( ( TRANSPARENT_BITMAP == eTransparent ) && !aMask.IsEmpty() )
394cdf0e10cSrcweir 	{
395cdf0e10cSrcweir 		UInt32ToSVBT32( aMask.GetChecksum(), aBT32 );
396cdf0e10cSrcweir 		nCrc = rtl_crc32( nCrc, aBT32, 4 );
397cdf0e10cSrcweir 	}
398cdf0e10cSrcweir 
399cdf0e10cSrcweir 	return nCrc;
400cdf0e10cSrcweir }
401cdf0e10cSrcweir 
402cdf0e10cSrcweir // ------------------------------------------------------------------
403cdf0e10cSrcweir 
404cdf0e10cSrcweir void BitmapEx::SetSizePixel( const Size& rNewSize )
405cdf0e10cSrcweir {
406cdf0e10cSrcweir 	Scale( rNewSize );
407cdf0e10cSrcweir }
408cdf0e10cSrcweir 
409cdf0e10cSrcweir // ------------------------------------------------------------------
410cdf0e10cSrcweir 
411cdf0e10cSrcweir sal_Bool BitmapEx::Invert()
412cdf0e10cSrcweir {
413cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
414cdf0e10cSrcweir 
415cdf0e10cSrcweir 	if( !!aBitmap )
416cdf0e10cSrcweir 	{
417cdf0e10cSrcweir 		bRet = aBitmap.Invert();
418cdf0e10cSrcweir 
419cdf0e10cSrcweir 		if( bRet && ( eTransparent == TRANSPARENT_COLOR ) )
420cdf0e10cSrcweir 			aTransparentColor = BitmapColor( aTransparentColor ).Invert();
421cdf0e10cSrcweir 	}
422cdf0e10cSrcweir 
423cdf0e10cSrcweir 	return bRet;
424cdf0e10cSrcweir }
425cdf0e10cSrcweir 
426cdf0e10cSrcweir // ------------------------------------------------------------------
427cdf0e10cSrcweir 
428cdf0e10cSrcweir sal_Bool BitmapEx::Mirror( sal_uLong nMirrorFlags )
429cdf0e10cSrcweir {
430cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
431cdf0e10cSrcweir 
432cdf0e10cSrcweir 	if( !!aBitmap )
433cdf0e10cSrcweir 	{
434cdf0e10cSrcweir 		bRet = aBitmap.Mirror( nMirrorFlags );
435cdf0e10cSrcweir 
436cdf0e10cSrcweir 		if( bRet && ( eTransparent == TRANSPARENT_BITMAP ) && !!aMask )
437cdf0e10cSrcweir 			aMask.Mirror( nMirrorFlags );
438cdf0e10cSrcweir 	}
439cdf0e10cSrcweir 
440cdf0e10cSrcweir 	return bRet;
441cdf0e10cSrcweir }
442cdf0e10cSrcweir 
443cdf0e10cSrcweir // ------------------------------------------------------------------
444cdf0e10cSrcweir 
445cdf0e10cSrcweir sal_Bool BitmapEx::Scale( const double& rScaleX, const double& rScaleY, sal_uLong nScaleFlag )
446cdf0e10cSrcweir {
447cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
448cdf0e10cSrcweir 
449cdf0e10cSrcweir 	if( !!aBitmap )
450cdf0e10cSrcweir 	{
451cdf0e10cSrcweir 		bRet = aBitmap.Scale( rScaleX, rScaleY, nScaleFlag );
452cdf0e10cSrcweir 
453cdf0e10cSrcweir 		if( bRet && ( eTransparent == TRANSPARENT_BITMAP ) && !!aMask )
454cdf0e10cSrcweir 			aMask.Scale( rScaleX, rScaleY, BMP_SCALE_FAST );
455cdf0e10cSrcweir 
456cdf0e10cSrcweir 		aBitmapSize = aBitmap.GetSizePixel();
457cdf0e10cSrcweir 
458cdf0e10cSrcweir         DBG_ASSERT( !aMask || aBitmap.GetSizePixel() == aMask.GetSizePixel(),
459cdf0e10cSrcweir                     "BitmapEx::Scale(): size mismatch for bitmap and alpha mask." );
460cdf0e10cSrcweir 	}
461cdf0e10cSrcweir 
462cdf0e10cSrcweir 	return bRet;
463cdf0e10cSrcweir }
464cdf0e10cSrcweir 
465cdf0e10cSrcweir // ------------------------------------------------------------------------
466cdf0e10cSrcweir 
467cdf0e10cSrcweir sal_Bool BitmapEx::Scale( const Size& rNewSize, sal_uLong nScaleFlag )
468cdf0e10cSrcweir {
469cdf0e10cSrcweir 	sal_Bool bRet;
470cdf0e10cSrcweir 
471cdf0e10cSrcweir 	if( aBitmapSize.Width() && aBitmapSize.Height() )
472cdf0e10cSrcweir 	{
473cdf0e10cSrcweir 		bRet = Scale( (double) rNewSize.Width() / aBitmapSize.Width(),
474cdf0e10cSrcweir 					  (double) rNewSize.Height() / aBitmapSize.Height(),
475cdf0e10cSrcweir 					  nScaleFlag );
476cdf0e10cSrcweir 	}
477cdf0e10cSrcweir 	else
478cdf0e10cSrcweir 		bRet = sal_True;
479cdf0e10cSrcweir 
480cdf0e10cSrcweir 	return bRet;
481cdf0e10cSrcweir }
482cdf0e10cSrcweir 
483cdf0e10cSrcweir // ------------------------------------------------------------------
484cdf0e10cSrcweir 
485cdf0e10cSrcweir sal_Bool BitmapEx::Rotate( long nAngle10, const Color& rFillColor )
486cdf0e10cSrcweir {
487cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
488cdf0e10cSrcweir 
489cdf0e10cSrcweir 	if( !!aBitmap )
490cdf0e10cSrcweir 	{
491cdf0e10cSrcweir 		const sal_Bool bTransRotate = ( Color( COL_TRANSPARENT ) == rFillColor );
492cdf0e10cSrcweir 
493cdf0e10cSrcweir 		if( bTransRotate )
494cdf0e10cSrcweir 		{
495cdf0e10cSrcweir 			if( eTransparent == TRANSPARENT_COLOR )
496cdf0e10cSrcweir 				bRet = aBitmap.Rotate( nAngle10, aTransparentColor );
497cdf0e10cSrcweir 			else
498cdf0e10cSrcweir 			{
499cdf0e10cSrcweir 				bRet = aBitmap.Rotate( nAngle10, COL_BLACK );
500cdf0e10cSrcweir 
501cdf0e10cSrcweir 				if( eTransparent == TRANSPARENT_NONE )
502cdf0e10cSrcweir 				{
503cdf0e10cSrcweir 					aMask = Bitmap( aBitmapSize, 1 );
504cdf0e10cSrcweir 					aMask.Erase( COL_BLACK );
505cdf0e10cSrcweir 					eTransparent = TRANSPARENT_BITMAP;
506cdf0e10cSrcweir 				}
507cdf0e10cSrcweir 
508cdf0e10cSrcweir 				if( bRet && !!aMask )
509cdf0e10cSrcweir 					aMask.Rotate( nAngle10, COL_WHITE );
510cdf0e10cSrcweir 			}
511cdf0e10cSrcweir 		}
512cdf0e10cSrcweir 		else
513cdf0e10cSrcweir 		{
514cdf0e10cSrcweir 			bRet = aBitmap.Rotate( nAngle10, rFillColor );
515cdf0e10cSrcweir 
516cdf0e10cSrcweir 			if( bRet && ( eTransparent == TRANSPARENT_BITMAP ) && !!aMask )
517cdf0e10cSrcweir 				aMask.Rotate( nAngle10, COL_WHITE );
518cdf0e10cSrcweir 		}
519cdf0e10cSrcweir 
520cdf0e10cSrcweir 		aBitmapSize = aBitmap.GetSizePixel();
521cdf0e10cSrcweir 
522cdf0e10cSrcweir         DBG_ASSERT( !aMask || aBitmap.GetSizePixel() == aMask.GetSizePixel(),
523cdf0e10cSrcweir                     "BitmapEx::Rotate(): size mismatch for bitmap and alpha mask." );
524cdf0e10cSrcweir 	}
525cdf0e10cSrcweir 
526cdf0e10cSrcweir 	return bRet;
527cdf0e10cSrcweir }
528cdf0e10cSrcweir 
529cdf0e10cSrcweir // ------------------------------------------------------------------
530cdf0e10cSrcweir 
531cdf0e10cSrcweir sal_Bool BitmapEx::Crop( const Rectangle& rRectPixel )
532cdf0e10cSrcweir {
533cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
534cdf0e10cSrcweir 
535cdf0e10cSrcweir 	if( !!aBitmap )
536cdf0e10cSrcweir 	{
537cdf0e10cSrcweir 		bRet = aBitmap.Crop( rRectPixel );
538cdf0e10cSrcweir 
539cdf0e10cSrcweir 		if( bRet && ( eTransparent == TRANSPARENT_BITMAP ) && !!aMask )
540cdf0e10cSrcweir 			aMask.Crop( rRectPixel );
541cdf0e10cSrcweir 
542cdf0e10cSrcweir 		aBitmapSize = aBitmap.GetSizePixel();
543cdf0e10cSrcweir 
544cdf0e10cSrcweir         DBG_ASSERT( !aMask || aBitmap.GetSizePixel() == aMask.GetSizePixel(),
545cdf0e10cSrcweir                     "BitmapEx::Crop(): size mismatch for bitmap and alpha mask." );
546cdf0e10cSrcweir 	}
547cdf0e10cSrcweir 
548cdf0e10cSrcweir 	return bRet;
549cdf0e10cSrcweir }
550cdf0e10cSrcweir 
551cdf0e10cSrcweir // ------------------------------------------------------------------
552cdf0e10cSrcweir 
553cdf0e10cSrcweir sal_Bool BitmapEx::Convert( BmpConversion eConversion )
554cdf0e10cSrcweir {
555cdf0e10cSrcweir 	return( !!aBitmap ? aBitmap.Convert( eConversion ) : sal_False );
556cdf0e10cSrcweir }
557cdf0e10cSrcweir 
558cdf0e10cSrcweir // ------------------------------------------------------------------
559cdf0e10cSrcweir 
560cdf0e10cSrcweir sal_Bool BitmapEx::ReduceColors( sal_uInt16 nNewColorCount, BmpReduce eReduce )
561cdf0e10cSrcweir {
562cdf0e10cSrcweir 	return( !!aBitmap ? aBitmap.ReduceColors( nNewColorCount, eReduce ) : sal_False );
563cdf0e10cSrcweir }
564cdf0e10cSrcweir 
565cdf0e10cSrcweir // ------------------------------------------------------------------
566cdf0e10cSrcweir 
567cdf0e10cSrcweir sal_Bool BitmapEx::Expand( sal_uLong nDX, sal_uLong nDY, const Color* pInitColor, sal_Bool bExpandTransparent )
568cdf0e10cSrcweir {
569cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
570cdf0e10cSrcweir 
571cdf0e10cSrcweir 	if( !!aBitmap )
572cdf0e10cSrcweir 	{
573cdf0e10cSrcweir 		bRet = aBitmap.Expand( nDX, nDY, pInitColor );
574cdf0e10cSrcweir 
575cdf0e10cSrcweir 		if( bRet && ( eTransparent == TRANSPARENT_BITMAP ) && !!aMask )
576cdf0e10cSrcweir 		{
577cdf0e10cSrcweir 			Color aColor( bExpandTransparent ? COL_WHITE : COL_BLACK );
578cdf0e10cSrcweir 			aMask.Expand( nDX, nDY, &aColor );
579cdf0e10cSrcweir 		}
580cdf0e10cSrcweir 
581cdf0e10cSrcweir 		aBitmapSize = aBitmap.GetSizePixel();
582cdf0e10cSrcweir 
583cdf0e10cSrcweir         DBG_ASSERT( !aMask || aBitmap.GetSizePixel() == aMask.GetSizePixel(),
584cdf0e10cSrcweir                     "BitmapEx::Expand(): size mismatch for bitmap and alpha mask." );
585cdf0e10cSrcweir 	}
586cdf0e10cSrcweir 
587cdf0e10cSrcweir 	return bRet;
588cdf0e10cSrcweir }
589cdf0e10cSrcweir 
590cdf0e10cSrcweir // ------------------------------------------------------------------
591cdf0e10cSrcweir 
592cdf0e10cSrcweir sal_Bool BitmapEx::CopyPixel( const Rectangle& rRectDst, const Rectangle& rRectSrc,
593cdf0e10cSrcweir 						  const BitmapEx* pBmpExSrc )
594cdf0e10cSrcweir {
595cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
596cdf0e10cSrcweir 
597cdf0e10cSrcweir 	if( !pBmpExSrc || pBmpExSrc->IsEmpty() )
598cdf0e10cSrcweir 	{
599cdf0e10cSrcweir 		if( !aBitmap.IsEmpty() )
600cdf0e10cSrcweir 		{
601cdf0e10cSrcweir 			bRet = aBitmap.CopyPixel( rRectDst, rRectSrc );
602cdf0e10cSrcweir 
603cdf0e10cSrcweir 			if( bRet && ( eTransparent == TRANSPARENT_BITMAP ) && !!aMask )
604cdf0e10cSrcweir 				aMask.CopyPixel( rRectDst, rRectSrc );
605cdf0e10cSrcweir 		}
606cdf0e10cSrcweir 	}
607cdf0e10cSrcweir 	else
608cdf0e10cSrcweir 	{
609cdf0e10cSrcweir 		if( !aBitmap.IsEmpty() )
610cdf0e10cSrcweir 		{
611cdf0e10cSrcweir 			bRet = aBitmap.CopyPixel( rRectDst, rRectSrc, &pBmpExSrc->aBitmap );
612cdf0e10cSrcweir 
613cdf0e10cSrcweir 			if( bRet )
614cdf0e10cSrcweir 			{
615cdf0e10cSrcweir 				if( pBmpExSrc->IsAlpha() )
616cdf0e10cSrcweir 				{
617cdf0e10cSrcweir 					if( IsAlpha() )
618cdf0e10cSrcweir                         // cast to use the optimized AlphaMask::CopyPixel
619cdf0e10cSrcweir 						((AlphaMask*) &aMask)->CopyPixel( rRectDst, rRectSrc, (AlphaMask*)&pBmpExSrc->aMask );
620cdf0e10cSrcweir 					else if( IsTransparent() )
621cdf0e10cSrcweir 					{
622cdf0e10cSrcweir 						AlphaMask* pAlpha = new AlphaMask( aMask );
623cdf0e10cSrcweir 
624cdf0e10cSrcweir 						aMask = pAlpha->ImplGetBitmap();
625cdf0e10cSrcweir 						delete pAlpha;
626cdf0e10cSrcweir 						bAlpha = sal_True;
627cdf0e10cSrcweir 						aMask.CopyPixel( rRectDst, rRectSrc, &pBmpExSrc->aMask );
628cdf0e10cSrcweir 					}
629cdf0e10cSrcweir 					else
630cdf0e10cSrcweir 					{
631cdf0e10cSrcweir 						sal_uInt8	cBlack = 0;
632cdf0e10cSrcweir 						AlphaMask*	pAlpha = new AlphaMask( GetSizePixel(), &cBlack );
633cdf0e10cSrcweir 
634cdf0e10cSrcweir 						aMask = pAlpha->ImplGetBitmap();
635cdf0e10cSrcweir 						delete pAlpha;
636cdf0e10cSrcweir 						eTransparent = TRANSPARENT_BITMAP;
637cdf0e10cSrcweir 						bAlpha = sal_True;
638cdf0e10cSrcweir 						aMask.CopyPixel( rRectDst, rRectSrc, &pBmpExSrc->aMask );
639cdf0e10cSrcweir 					}
640cdf0e10cSrcweir 				}
641cdf0e10cSrcweir 				else if( pBmpExSrc->IsTransparent() )
642cdf0e10cSrcweir 				{
643cdf0e10cSrcweir 					if( IsAlpha() )
644cdf0e10cSrcweir 					{
645cdf0e10cSrcweir 						AlphaMask aAlpha( pBmpExSrc->aMask );
646cdf0e10cSrcweir 						aMask.CopyPixel( rRectDst, rRectSrc, &aAlpha.ImplGetBitmap() );
647cdf0e10cSrcweir 					}
648cdf0e10cSrcweir 					else if( IsTransparent() )
649cdf0e10cSrcweir 						aMask.CopyPixel( rRectDst, rRectSrc, &pBmpExSrc->aMask );
650cdf0e10cSrcweir 					else
651cdf0e10cSrcweir 					{
652cdf0e10cSrcweir 						aMask = Bitmap( GetSizePixel(), 1 );
653cdf0e10cSrcweir 						aMask.Erase( Color( COL_BLACK ) );
654cdf0e10cSrcweir 						eTransparent = TRANSPARENT_BITMAP;
655cdf0e10cSrcweir 						aMask.CopyPixel( rRectDst, rRectSrc, &pBmpExSrc->aMask );
656cdf0e10cSrcweir 					}
657cdf0e10cSrcweir 				}
658cdf0e10cSrcweir                 else if( IsAlpha() )
659cdf0e10cSrcweir                 {
660cdf0e10cSrcweir                     sal_uInt8	      cBlack = 0;
661cdf0e10cSrcweir                     const AlphaMask   aAlphaSrc( pBmpExSrc->GetSizePixel(), &cBlack );
662cdf0e10cSrcweir 
663cdf0e10cSrcweir                     aMask.CopyPixel( rRectDst, rRectSrc, &aAlphaSrc.ImplGetBitmap() );
664cdf0e10cSrcweir                 }
665cdf0e10cSrcweir                 else if( IsTransparent() )
666cdf0e10cSrcweir                 {
667cdf0e10cSrcweir                     Bitmap aMaskSrc( pBmpExSrc->GetSizePixel(), 1 );
668cdf0e10cSrcweir 
669cdf0e10cSrcweir                     aMaskSrc.Erase( Color( COL_BLACK ) );
670cdf0e10cSrcweir                     aMask.CopyPixel( rRectDst, rRectSrc, &aMaskSrc );
671cdf0e10cSrcweir                 }
672cdf0e10cSrcweir 			}
673cdf0e10cSrcweir 		}
674cdf0e10cSrcweir 	}
675cdf0e10cSrcweir 
676cdf0e10cSrcweir 	return bRet;
677cdf0e10cSrcweir }
678cdf0e10cSrcweir 
679cdf0e10cSrcweir // ------------------------------------------------------------------
680cdf0e10cSrcweir 
681cdf0e10cSrcweir sal_Bool BitmapEx::Erase( const Color& rFillColor )
682cdf0e10cSrcweir {
683cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
684cdf0e10cSrcweir 
685cdf0e10cSrcweir 	if( !!aBitmap )
686cdf0e10cSrcweir 	{
687cdf0e10cSrcweir 		bRet = aBitmap.Erase( rFillColor );
688cdf0e10cSrcweir 
689cdf0e10cSrcweir 		if( bRet && ( eTransparent == TRANSPARENT_BITMAP ) && !!aMask )
690cdf0e10cSrcweir 		{
691cdf0e10cSrcweir             // #104416# Respect transparency on fill color
692cdf0e10cSrcweir             if( rFillColor.GetTransparency() )
693cdf0e10cSrcweir             {
694cdf0e10cSrcweir                 const Color aFill( rFillColor.GetTransparency(), rFillColor.GetTransparency(), rFillColor.GetTransparency() );
695cdf0e10cSrcweir                 aMask.Erase( aFill );
696cdf0e10cSrcweir             }
697cdf0e10cSrcweir             else
698cdf0e10cSrcweir             {
699cdf0e10cSrcweir                 const Color aBlack( COL_BLACK );
700cdf0e10cSrcweir                 aMask.Erase( aBlack );
701cdf0e10cSrcweir             }
702cdf0e10cSrcweir 		}
703cdf0e10cSrcweir 	}
704cdf0e10cSrcweir 
705cdf0e10cSrcweir 	return bRet;
706cdf0e10cSrcweir }
707cdf0e10cSrcweir 
708cdf0e10cSrcweir // ------------------------------------------------------------------
709cdf0e10cSrcweir 
710cdf0e10cSrcweir sal_Bool BitmapEx::Dither( sal_uLong nDitherFlags )
711cdf0e10cSrcweir {
712cdf0e10cSrcweir 	return( !!aBitmap ? aBitmap.Dither( nDitherFlags ) : sal_False );
713cdf0e10cSrcweir }
714cdf0e10cSrcweir 
715cdf0e10cSrcweir // ------------------------------------------------------------------
716cdf0e10cSrcweir 
717cdf0e10cSrcweir sal_Bool BitmapEx::Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uLong nTol )
718cdf0e10cSrcweir {
719cdf0e10cSrcweir 	return( !!aBitmap ? aBitmap.Replace( rSearchColor, rReplaceColor, nTol ) : sal_False );
720cdf0e10cSrcweir }
721cdf0e10cSrcweir 
722cdf0e10cSrcweir // ------------------------------------------------------------------
723cdf0e10cSrcweir 
724cdf0e10cSrcweir sal_Bool BitmapEx::Replace( const Color* pSearchColors, const Color* pReplaceColors, sal_uLong nColorCount, const sal_uLong* pTols )
725cdf0e10cSrcweir {
726cdf0e10cSrcweir 	return( !!aBitmap ? aBitmap.Replace( pSearchColors, pReplaceColors, nColorCount, (sal_uLong*) pTols ) : sal_False );
727cdf0e10cSrcweir }
728cdf0e10cSrcweir 
729cdf0e10cSrcweir // ------------------------------------------------------------------
730cdf0e10cSrcweir 
731cdf0e10cSrcweir sal_Bool BitmapEx::Adjust( short nLuminancePercent, short nContrastPercent,
732cdf0e10cSrcweir 					   short nChannelRPercent, short nChannelGPercent, short nChannelBPercent,
733cdf0e10cSrcweir 					   double fGamma, sal_Bool bInvert )
734cdf0e10cSrcweir {
735cdf0e10cSrcweir 	return( !!aBitmap ? aBitmap.Adjust( nLuminancePercent, nContrastPercent,
736cdf0e10cSrcweir 										nChannelRPercent, nChannelGPercent, nChannelBPercent,
737cdf0e10cSrcweir 										fGamma, bInvert ) : sal_False );
738cdf0e10cSrcweir }
739cdf0e10cSrcweir 
740cdf0e10cSrcweir // ------------------------------------------------------------------
741cdf0e10cSrcweir 
742cdf0e10cSrcweir sal_Bool BitmapEx::Filter( BmpFilter eFilter, const BmpFilterParam* pFilterParam, const Link* pProgress )
743cdf0e10cSrcweir {
744cdf0e10cSrcweir 	return( !!aBitmap ? aBitmap.Filter( eFilter, pFilterParam, pProgress ) : sal_False );
745cdf0e10cSrcweir }
746cdf0e10cSrcweir 
747cdf0e10cSrcweir // ------------------------------------------------------------------
748cdf0e10cSrcweir 
749cdf0e10cSrcweir void BitmapEx::Draw( OutputDevice* pOutDev, const Point& rDestPt ) const
750cdf0e10cSrcweir {
751cdf0e10cSrcweir 	pOutDev->DrawBitmapEx( rDestPt, *this );
752cdf0e10cSrcweir }
753cdf0e10cSrcweir 
754cdf0e10cSrcweir // ------------------------------------------------------------------
755cdf0e10cSrcweir 
756cdf0e10cSrcweir void BitmapEx::Draw( OutputDevice* pOutDev,
757cdf0e10cSrcweir 					 const Point& rDestPt, const Size& rDestSize ) const
758cdf0e10cSrcweir {
759cdf0e10cSrcweir 	pOutDev->DrawBitmapEx( rDestPt, rDestSize, *this );
760cdf0e10cSrcweir }
761cdf0e10cSrcweir 
762cdf0e10cSrcweir // ------------------------------------------------------------------
763cdf0e10cSrcweir 
764cdf0e10cSrcweir void BitmapEx::Draw( OutputDevice* pOutDev,
765cdf0e10cSrcweir 					 const Point& rDestPt, const Size& rDestSize,
766cdf0e10cSrcweir 					 const Point& rSrcPtPixel, const Size& rSrcSizePixel ) const
767cdf0e10cSrcweir {
768cdf0e10cSrcweir 	pOutDev->DrawBitmapEx( rDestPt, rDestSize, rSrcPtPixel, rSrcSizePixel, *this );
769cdf0e10cSrcweir }
770cdf0e10cSrcweir 
771cdf0e10cSrcweir // ------------------------------------------------------------------
772cdf0e10cSrcweir 
773cdf0e10cSrcweir sal_uInt8 BitmapEx::GetTransparency(sal_Int32 nX, sal_Int32 nY) const
774cdf0e10cSrcweir {
775cdf0e10cSrcweir     sal_uInt8 nTransparency(0xff);
776cdf0e10cSrcweir 
777cdf0e10cSrcweir     if(!aBitmap.IsEmpty())
778cdf0e10cSrcweir     {
779cdf0e10cSrcweir         if(nX >= 0 && nX < aBitmapSize.Width() && nY >= 0 && nY < aBitmapSize.Height())
780cdf0e10cSrcweir         {
781cdf0e10cSrcweir             switch(eTransparent)
782cdf0e10cSrcweir             {
783cdf0e10cSrcweir                 case TRANSPARENT_NONE:
784cdf0e10cSrcweir                 {
785cdf0e10cSrcweir                     // not transparent, ergo all covered
786cdf0e10cSrcweir                     nTransparency = 0x00;
787cdf0e10cSrcweir                     break;
788cdf0e10cSrcweir                 }
789cdf0e10cSrcweir                 case TRANSPARENT_COLOR:
790cdf0e10cSrcweir                 {
791cdf0e10cSrcweir                     Bitmap aTestBitmap(aBitmap);
792cdf0e10cSrcweir                     BitmapReadAccess* pRead = aTestBitmap.AcquireReadAccess();
793cdf0e10cSrcweir 
794cdf0e10cSrcweir                     if(pRead)
795cdf0e10cSrcweir                     {
796cdf0e10cSrcweir                         const Color aColor = pRead->GetColor(nY, nX);
797cdf0e10cSrcweir 
798cdf0e10cSrcweir                         // if color is not equal to TransparentColor, we are not transparent
799cdf0e10cSrcweir                         if(aColor != aTransparentColor)
800cdf0e10cSrcweir                         {
801cdf0e10cSrcweir                             nTransparency = 0x00;
802cdf0e10cSrcweir                         }
803cdf0e10cSrcweir 
804cdf0e10cSrcweir                         aTestBitmap.ReleaseAccess(pRead);
805cdf0e10cSrcweir                     }
806cdf0e10cSrcweir                     break;
807cdf0e10cSrcweir                 }
808cdf0e10cSrcweir                 case TRANSPARENT_BITMAP:
809cdf0e10cSrcweir                 {
810cdf0e10cSrcweir                     if(!aMask.IsEmpty())
811cdf0e10cSrcweir                     {
812cdf0e10cSrcweir                         Bitmap aTestBitmap(aMask);
813cdf0e10cSrcweir                         BitmapReadAccess* pRead = aTestBitmap.AcquireReadAccess();
814cdf0e10cSrcweir 
815cdf0e10cSrcweir                         if(pRead)
816cdf0e10cSrcweir                         {
817cdf0e10cSrcweir                             const BitmapColor aBitmapColor(pRead->GetPixel(nY, nX));
818cdf0e10cSrcweir 
819cdf0e10cSrcweir                             if(bAlpha)
820cdf0e10cSrcweir                             {
821cdf0e10cSrcweir                                 nTransparency = aBitmapColor.GetIndex();
822cdf0e10cSrcweir                             }
823cdf0e10cSrcweir                             else
824cdf0e10cSrcweir                             {
825cdf0e10cSrcweir                                 if(0x00 == aBitmapColor.GetIndex())
826cdf0e10cSrcweir                                 {
827cdf0e10cSrcweir                                     nTransparency = 0x00;
828cdf0e10cSrcweir                                 }
829cdf0e10cSrcweir                             }
830cdf0e10cSrcweir 
831cdf0e10cSrcweir                             aTestBitmap.ReleaseAccess(pRead);
832cdf0e10cSrcweir                         }
833cdf0e10cSrcweir                     }
834cdf0e10cSrcweir                     break;
835cdf0e10cSrcweir                 }
836cdf0e10cSrcweir             }
837cdf0e10cSrcweir         }
838cdf0e10cSrcweir     }
839cdf0e10cSrcweir 
840cdf0e10cSrcweir     return nTransparency;
841cdf0e10cSrcweir }
842cdf0e10cSrcweir 
843cdf0e10cSrcweir // ------------------------------------------------------------------
844cdf0e10cSrcweir 
845cdf0e10cSrcweir SvStream& operator<<( SvStream& rOStm, const BitmapEx& rBitmapEx )
846cdf0e10cSrcweir {
847cdf0e10cSrcweir 	rBitmapEx.aBitmap.Write( rOStm );
848cdf0e10cSrcweir 
849cdf0e10cSrcweir 	rOStm << (sal_uInt32) 0x25091962;
850cdf0e10cSrcweir 	rOStm << (sal_uInt32) 0xACB20201;
851cdf0e10cSrcweir 	rOStm << (sal_uInt8) rBitmapEx.eTransparent;
852cdf0e10cSrcweir 
853cdf0e10cSrcweir 	if( rBitmapEx.eTransparent == TRANSPARENT_BITMAP )
854cdf0e10cSrcweir 		rBitmapEx.aMask.Write( rOStm );
855cdf0e10cSrcweir 	else if( rBitmapEx.eTransparent == TRANSPARENT_COLOR )
856cdf0e10cSrcweir 		rOStm << rBitmapEx.aTransparentColor;
857cdf0e10cSrcweir 
858cdf0e10cSrcweir 	return rOStm;
859cdf0e10cSrcweir }
860cdf0e10cSrcweir 
861cdf0e10cSrcweir // ------------------------------------------------------------------
862cdf0e10cSrcweir 
863cdf0e10cSrcweir SvStream& operator>>( SvStream& rIStm, BitmapEx& rBitmapEx )
864cdf0e10cSrcweir {
865cdf0e10cSrcweir 	Bitmap aBmp;
866cdf0e10cSrcweir 
867cdf0e10cSrcweir 	rIStm >> aBmp;
868cdf0e10cSrcweir 
869cdf0e10cSrcweir 	if( !rIStm.GetError() )
870cdf0e10cSrcweir 	{
871cdf0e10cSrcweir 		const sal_uLong nStmPos = rIStm.Tell();
872cdf0e10cSrcweir 		sal_uInt32		nMagic1 = 0;
873cdf0e10cSrcweir 		sal_uInt32		nMagic2 = 0;
874cdf0e10cSrcweir 
875cdf0e10cSrcweir 		rIStm >> nMagic1 >> nMagic2;
876cdf0e10cSrcweir 
877cdf0e10cSrcweir 		if( ( nMagic1 != 0x25091962 ) || ( nMagic2 != 0xACB20201 ) || rIStm.GetError() )
878cdf0e10cSrcweir 		{
879cdf0e10cSrcweir 			rIStm.ResetError();
880cdf0e10cSrcweir 			rIStm.Seek( nStmPos );
881cdf0e10cSrcweir 			rBitmapEx = aBmp;
882cdf0e10cSrcweir 		}
883cdf0e10cSrcweir 		else
884cdf0e10cSrcweir 		{
885cdf0e10cSrcweir 			sal_uInt8 bTransparent = false;
886cdf0e10cSrcweir 
887cdf0e10cSrcweir 			rIStm >> bTransparent;
888cdf0e10cSrcweir 
889cdf0e10cSrcweir 			if( bTransparent == (sal_uInt8) TRANSPARENT_BITMAP )
890cdf0e10cSrcweir 			{
891cdf0e10cSrcweir 				Bitmap aMask;
892cdf0e10cSrcweir 
893cdf0e10cSrcweir 				rIStm >> aMask;
894cdf0e10cSrcweir 
895cdf0e10cSrcweir 				if( !!aMask)
896cdf0e10cSrcweir 				{
897cdf0e10cSrcweir 					// do we have an alpha mask?
898cdf0e10cSrcweir 					if( ( 8 == aMask.GetBitCount() ) && aMask.HasGreyPalette() )
899cdf0e10cSrcweir 					{
900cdf0e10cSrcweir 						AlphaMask aAlpha;
901cdf0e10cSrcweir 
902cdf0e10cSrcweir 						// create alpha mask quickly (without greyscale conversion)
903cdf0e10cSrcweir 						aAlpha.ImplSetBitmap( aMask );
904cdf0e10cSrcweir 						rBitmapEx = BitmapEx( aBmp, aAlpha );
905cdf0e10cSrcweir 					}
906cdf0e10cSrcweir 					else
907cdf0e10cSrcweir 						rBitmapEx = BitmapEx( aBmp, aMask );
908cdf0e10cSrcweir 				}
909cdf0e10cSrcweir 				else
910cdf0e10cSrcweir 					rBitmapEx = aBmp;
911cdf0e10cSrcweir 			}
912cdf0e10cSrcweir 			else if( bTransparent == (sal_uInt8) TRANSPARENT_COLOR )
913cdf0e10cSrcweir 			{
914cdf0e10cSrcweir 				Color aTransparentColor;
915cdf0e10cSrcweir 
916cdf0e10cSrcweir 				rIStm >> aTransparentColor;
917cdf0e10cSrcweir 				rBitmapEx = BitmapEx( aBmp, aTransparentColor );
918cdf0e10cSrcweir 			}
919cdf0e10cSrcweir 			else
920cdf0e10cSrcweir 				rBitmapEx = aBmp;
921cdf0e10cSrcweir 		}
922cdf0e10cSrcweir 	}
923cdf0e10cSrcweir 
924cdf0e10cSrcweir 	return rIStm;
925cdf0e10cSrcweir }
926