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