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