xref: /AOO41X/main/vcl/source/gdi/impimage.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_vcl.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <vcl/outdev.hxx>
32*cdf0e10cSrcweir #include <vcl/bitmapex.hxx>
33*cdf0e10cSrcweir #include <vcl/alpha.hxx>
34*cdf0e10cSrcweir #include <vcl/window.hxx>
35*cdf0e10cSrcweir #include <vcl/bmpacc.hxx>
36*cdf0e10cSrcweir #include <vcl/virdev.hxx>
37*cdf0e10cSrcweir #include <vcl/image.hxx>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include <image.h>
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir // -----------
42*cdf0e10cSrcweir // - Defines -
43*cdf0e10cSrcweir // -----------
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir #define IMPSYSIMAGEITEM_MASK		( 0x01 )
46*cdf0e10cSrcweir #define IMPSYSIMAGEITEM_ALPHA		( 0x02 )
47*cdf0e10cSrcweir #define DISA_ALL					( 0xffff )
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir // ----------------
50*cdf0e10cSrcweir // - ImageAryData -
51*cdf0e10cSrcweir // ----------------
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir ImageAryData::ImageAryData() :
54*cdf0e10cSrcweir 	maName(),
55*cdf0e10cSrcweir 	mnId( 0 ),
56*cdf0e10cSrcweir 	maBitmapEx()
57*cdf0e10cSrcweir {
58*cdf0e10cSrcweir }
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir // -----------------------------------------------------------------------
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir ImageAryData::ImageAryData( const ImageAryData& rData ) :
63*cdf0e10cSrcweir 	maName( rData.maName ),
64*cdf0e10cSrcweir 	mnId( rData.mnId ),
65*cdf0e10cSrcweir 	maBitmapEx( rData.maBitmapEx )
66*cdf0e10cSrcweir {
67*cdf0e10cSrcweir }
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir ImageAryData::ImageAryData( const rtl::OUString &aName,
70*cdf0e10cSrcweir 							sal_uInt16 nId, const BitmapEx &aBitmap )
71*cdf0e10cSrcweir 		: maName( aName ), mnId( nId ), maBitmapEx( aBitmap )
72*cdf0e10cSrcweir {
73*cdf0e10cSrcweir }
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir // -----------------------------------------------------------------------
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir ImageAryData::~ImageAryData()
78*cdf0e10cSrcweir {
79*cdf0e10cSrcweir }
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir // -----------------------------------------------------------------------
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir ImageAryData& ImageAryData::operator=( const ImageAryData& rData )
84*cdf0e10cSrcweir {
85*cdf0e10cSrcweir 	maName = rData.maName;
86*cdf0e10cSrcweir 	mnId = rData.mnId;
87*cdf0e10cSrcweir 	maBitmapEx = rData.maBitmapEx;
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir 	return *this;
90*cdf0e10cSrcweir }
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir // -----------------
93*cdf0e10cSrcweir // - ImplImageList -
94*cdf0e10cSrcweir // -----------------
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir ImplImageList::ImplImageList()
97*cdf0e10cSrcweir {
98*cdf0e10cSrcweir }
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir ImplImageList::ImplImageList( const ImplImageList &aSrc ) :
101*cdf0e10cSrcweir     maPrefix( aSrc.maPrefix ),
102*cdf0e10cSrcweir     maImageSize( aSrc.maImageSize ),
103*cdf0e10cSrcweir     mnRefCount( 1 )
104*cdf0e10cSrcweir {
105*cdf0e10cSrcweir 	maImages.reserve( aSrc.maImages.size() );
106*cdf0e10cSrcweir     for ( ImageAryDataVec::const_iterator aIt = aSrc.maImages.begin(), aEnd = aSrc.maImages.end(); aIt != aEnd; ++aIt )
107*cdf0e10cSrcweir 	{
108*cdf0e10cSrcweir         ImageAryData* pAryData = new ImageAryData( **aIt );
109*cdf0e10cSrcweir         maImages.push_back( pAryData );
110*cdf0e10cSrcweir         if( pAryData->maName.getLength() )
111*cdf0e10cSrcweir             maNameHash [ pAryData->maName ] = pAryData;
112*cdf0e10cSrcweir 	}
113*cdf0e10cSrcweir }
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir ImplImageList::~ImplImageList()
116*cdf0e10cSrcweir {
117*cdf0e10cSrcweir     for ( ImageAryDataVec::iterator aIt = maImages.begin(), aEnd = maImages.end(); aIt != aEnd; ++aIt )
118*cdf0e10cSrcweir         delete *aIt;
119*cdf0e10cSrcweir }
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir void ImplImageList::AddImage( const ::rtl::OUString &aName,
122*cdf0e10cSrcweir 							  sal_uInt16 nId, const BitmapEx &aBitmapEx )
123*cdf0e10cSrcweir {
124*cdf0e10cSrcweir 	ImageAryData *pImg = new ImageAryData( aName, nId, aBitmapEx );
125*cdf0e10cSrcweir 	maImages.push_back( pImg );
126*cdf0e10cSrcweir 	if( aName.getLength() )
127*cdf0e10cSrcweir 		maNameHash [ aName ] = pImg;
128*cdf0e10cSrcweir }
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir void ImplImageList::RemoveImage( sal_uInt16 nPos )
131*cdf0e10cSrcweir {
132*cdf0e10cSrcweir 	ImageAryData *pImg = maImages[ nPos ];
133*cdf0e10cSrcweir 	if( pImg->maName.getLength() )
134*cdf0e10cSrcweir 		maNameHash.erase( pImg->maName );
135*cdf0e10cSrcweir 	maImages.erase( maImages.begin() + nPos );
136*cdf0e10cSrcweir }
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir sal_uInt16 ImplImageList::GetImageCount() const
139*cdf0e10cSrcweir {
140*cdf0e10cSrcweir     return sal::static_int_cast< sal_uInt16 >( maImages.size() );
141*cdf0e10cSrcweir }
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir // -----------------
144*cdf0e10cSrcweir // - ImplImageData -
145*cdf0e10cSrcweir // -----------------
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir ImplImageData::ImplImageData( const BitmapEx& rBmpEx ) :
148*cdf0e10cSrcweir 	mpImageBitmap( NULL ),
149*cdf0e10cSrcweir 	maBmpEx( rBmpEx )
150*cdf0e10cSrcweir {
151*cdf0e10cSrcweir }
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir // -----------------------------------------------------------------------
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir ImplImageData::~ImplImageData()
156*cdf0e10cSrcweir {
157*cdf0e10cSrcweir 	delete mpImageBitmap;
158*cdf0e10cSrcweir }
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir // -----------------
161*cdf0e10cSrcweir // - ImplImageData -
162*cdf0e10cSrcweir // -----------------
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir sal_Bool ImplImageData::IsEqual( const ImplImageData& rData )
165*cdf0e10cSrcweir {
166*cdf0e10cSrcweir 	return( maBmpEx == rData.maBmpEx );
167*cdf0e10cSrcweir }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir // -------------
170*cdf0e10cSrcweir // - ImplImage -
171*cdf0e10cSrcweir // -------------
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir ImplImage::ImplImage()
174*cdf0e10cSrcweir {
175*cdf0e10cSrcweir }
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir // ------------------------------------------------------------------------------
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir ImplImage::~ImplImage()
180*cdf0e10cSrcweir {
181*cdf0e10cSrcweir 	switch( meType )
182*cdf0e10cSrcweir 	{
183*cdf0e10cSrcweir 		case IMAGETYPE_BITMAP:
184*cdf0e10cSrcweir 			delete static_cast< Bitmap* >( mpData );
185*cdf0e10cSrcweir 		break;
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir 		case IMAGETYPE_IMAGE:
188*cdf0e10cSrcweir 			delete static_cast< ImplImageData* >( mpData );
189*cdf0e10cSrcweir 		break;
190*cdf0e10cSrcweir 	}
191*cdf0e10cSrcweir }
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir // ----------------
194*cdf0e10cSrcweir // - ImplImageBmp -
195*cdf0e10cSrcweir // ----------------
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir ImplImageBmp::ImplImageBmp() :
198*cdf0e10cSrcweir 	mpDisplayBmp( NULL ),
199*cdf0e10cSrcweir 	mpInfoAry( NULL ),
200*cdf0e10cSrcweir 	mnSize( 0 )
201*cdf0e10cSrcweir {
202*cdf0e10cSrcweir }
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir // -------------
205*cdf0e10cSrcweir // - ImplImage -
206*cdf0e10cSrcweir // -------------
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir ImplImageBmp::~ImplImageBmp()
209*cdf0e10cSrcweir {
210*cdf0e10cSrcweir 	delete[] mpInfoAry;
211*cdf0e10cSrcweir 	delete mpDisplayBmp;
212*cdf0e10cSrcweir }
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir // -----------------------------------------------------------------------
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir void ImplImageBmp::Create( long nItemWidth, long nItemHeight, sal_uInt16 nInitSize )
217*cdf0e10cSrcweir {
218*cdf0e10cSrcweir 	const Size aTotalSize( nInitSize * nItemWidth, nItemHeight );
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir 	maBmpEx = Bitmap( aTotalSize, 24 );
221*cdf0e10cSrcweir 	maDisabledBmpEx.SetEmpty();
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir 	delete mpDisplayBmp;
224*cdf0e10cSrcweir 	mpDisplayBmp = NULL;
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir 	maSize = Size( nItemWidth, nItemHeight );
227*cdf0e10cSrcweir 	mnSize = nInitSize;
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir 	delete[] mpInfoAry;
230*cdf0e10cSrcweir 	mpInfoAry = new sal_uInt8[ mnSize ];
231*cdf0e10cSrcweir 	memset( mpInfoAry, 0, mnSize );
232*cdf0e10cSrcweir }
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir // -----------------------------------------------------------------------
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir void ImplImageBmp::Create( const BitmapEx& rBmpEx, long nItemWidth, long nItemHeight, sal_uInt16 nInitSize )
237*cdf0e10cSrcweir {
238*cdf0e10cSrcweir 	maBmpEx = rBmpEx;
239*cdf0e10cSrcweir 	maDisabledBmpEx.SetEmpty();
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir 	delete mpDisplayBmp;
242*cdf0e10cSrcweir 	mpDisplayBmp = NULL;
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir 	maSize = Size( nItemWidth, nItemHeight );
245*cdf0e10cSrcweir 	mnSize = nInitSize;
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir 	delete[] mpInfoAry;
248*cdf0e10cSrcweir 	mpInfoAry = new sal_uInt8[ mnSize ];
249*cdf0e10cSrcweir 	memset( mpInfoAry,
250*cdf0e10cSrcweir 			rBmpEx.IsAlpha() ? IMPSYSIMAGEITEM_ALPHA : ( rBmpEx.IsTransparent() ? IMPSYSIMAGEITEM_MASK : 0 ),
251*cdf0e10cSrcweir 			mnSize );
252*cdf0e10cSrcweir }
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir // -----------------------------------------------------------------------
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir void ImplImageBmp::Expand( sal_uInt16 nGrowSize )
257*cdf0e10cSrcweir {
258*cdf0e10cSrcweir 	const sal_uLong 	nDX = nGrowSize * maSize.Width();
259*cdf0e10cSrcweir 	const sal_uInt16	nOldSize = mnSize;
260*cdf0e10cSrcweir 	sal_uInt8*			pNewAry = new sal_uInt8[ mnSize = sal::static_int_cast<sal_uInt16>(mnSize+nGrowSize) ];
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir 	maBmpEx.Expand( nDX, 0UL );
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir 	if( !maDisabledBmpEx.IsEmpty() )
265*cdf0e10cSrcweir 		maDisabledBmpEx.Expand( nDX, 0UL );
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir 	delete mpDisplayBmp;
268*cdf0e10cSrcweir 	mpDisplayBmp = NULL;
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir 	memset( pNewAry, 0, mnSize );
271*cdf0e10cSrcweir 	memcpy( pNewAry, mpInfoAry, nOldSize );
272*cdf0e10cSrcweir 	delete[] mpInfoAry;
273*cdf0e10cSrcweir 	mpInfoAry = pNewAry;
274*cdf0e10cSrcweir }
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir // -----------------------------------------------------------------------
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir void ImplImageBmp::Invert()
279*cdf0e10cSrcweir {
280*cdf0e10cSrcweir 	delete mpDisplayBmp;
281*cdf0e10cSrcweir 	mpDisplayBmp = NULL;
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir     maBmpEx.Invert();
284*cdf0e10cSrcweir }
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir // -----------------------------------------------------------------------
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir void ImplImageBmp::Replace( sal_uInt16 nPos, sal_uInt16 nSrcPos )
289*cdf0e10cSrcweir {
290*cdf0e10cSrcweir     const Point     aSrcPos( nSrcPos * maSize.Width(), 0L ), aPos( nPos * maSize.Width(), 0L );
291*cdf0e10cSrcweir 	const Rectangle aSrcRect( aSrcPos, maSize );
292*cdf0e10cSrcweir 	const Rectangle aDstRect( aPos, maSize );
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir 	maBmpEx.CopyPixel( aDstRect, aSrcRect );
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir 	if( !maDisabledBmpEx.IsEmpty() )
297*cdf0e10cSrcweir 		maDisabledBmpEx.CopyPixel( aDstRect, aSrcRect );
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir 	delete mpDisplayBmp;
300*cdf0e10cSrcweir 	mpDisplayBmp = NULL;
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir 	mpInfoAry[ nPos ] = mpInfoAry[ nSrcPos ];
303*cdf0e10cSrcweir }
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir // -----------------------------------------------------------------------
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir void ImplImageBmp::Replace( sal_uInt16 nPos, const ImplImageBmp& rImageBmp, sal_uInt16 nSrcPos )
308*cdf0e10cSrcweir {
309*cdf0e10cSrcweir     const Point     aSrcPos( nSrcPos * maSize.Width(), 0L ), aPos( nPos * maSize.Width(), 0L );
310*cdf0e10cSrcweir 	const Rectangle aSrcRect( aSrcPos, maSize );
311*cdf0e10cSrcweir 	const Rectangle aDstRect( aPos, maSize );
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir 	maBmpEx.CopyPixel( aDstRect, aSrcRect, &rImageBmp.maBmpEx );
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir 	ImplUpdateDisabledBmpEx( nPos );
316*cdf0e10cSrcweir 	delete mpDisplayBmp;
317*cdf0e10cSrcweir 	mpDisplayBmp = NULL;
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir 	mpInfoAry[ nPos ] = rImageBmp.mpInfoAry[ nSrcPos ];
320*cdf0e10cSrcweir }
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir // -----------------------------------------------------------------------
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir void ImplImageBmp::Replace( sal_uInt16 nPos, const BitmapEx& rBmpEx )
325*cdf0e10cSrcweir {
326*cdf0e10cSrcweir     const Point     aNullPos, aPos( nPos * maSize.Width(), 0L );
327*cdf0e10cSrcweir 	const Rectangle aSrcRect( aNullPos, maSize );
328*cdf0e10cSrcweir 	const Rectangle aDstRect( aPos, maSize );
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir 	maBmpEx.CopyPixel( aDstRect, aSrcRect, &rBmpEx );
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir 	ImplUpdateDisabledBmpEx( nPos );
333*cdf0e10cSrcweir 	delete mpDisplayBmp;
334*cdf0e10cSrcweir 	mpDisplayBmp = NULL;
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir 	mpInfoAry[ nPos ] &= ~( IMPSYSIMAGEITEM_MASK | IMPSYSIMAGEITEM_ALPHA );
337*cdf0e10cSrcweir 	mpInfoAry[ nPos ] |= ( rBmpEx.IsAlpha() ? IMPSYSIMAGEITEM_ALPHA : ( rBmpEx.IsTransparent() ? IMPSYSIMAGEITEM_MASK : 0 ) );
338*cdf0e10cSrcweir }
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir // -----------------------------------------------------------------------
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir void ImplImageBmp::ReplaceColors( const Color* pSrcColors, const Color* pDstColors, sal_uLong nColorCount )
343*cdf0e10cSrcweir {
344*cdf0e10cSrcweir 	maBmpEx.Replace( pSrcColors, pDstColors, nColorCount );
345*cdf0e10cSrcweir 	delete mpDisplayBmp;
346*cdf0e10cSrcweir 	mpDisplayBmp = NULL;
347*cdf0e10cSrcweir }
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir // -----------------------------------------------------------------------
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir void ImplImageBmp::ColorTransform( BmpColorMode eColorMode )
352*cdf0e10cSrcweir {
353*cdf0e10cSrcweir 	maBmpEx = maBmpEx.GetColorTransformedBitmapEx( eColorMode );
354*cdf0e10cSrcweir 	delete mpDisplayBmp;
355*cdf0e10cSrcweir 	mpDisplayBmp = NULL;
356*cdf0e10cSrcweir }
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir // -----------------------------------------------------------------------
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir BitmapEx ImplImageBmp::GetBitmapEx( sal_uInt16 nPosCount, sal_uInt16* pPosAry ) const
361*cdf0e10cSrcweir {
362*cdf0e10cSrcweir 	const Bitmap	aNewBmp( Size( nPosCount * maSize.Width(), maSize.Height() ),  maBmpEx.GetBitmap().GetBitCount() );
363*cdf0e10cSrcweir 	BitmapEx 		aRet;
364*cdf0e10cSrcweir     if( maBmpEx.IsAlpha() )
365*cdf0e10cSrcweir     {
366*cdf0e10cSrcweir         // initialize target bitmap with an empty alpha mask
367*cdf0e10cSrcweir         // which allows for using an optimized copypixel later on (see AlphaMask::CopyPixel)
368*cdf0e10cSrcweir         // that avoids palette lookups
369*cdf0e10cSrcweir         AlphaMask aAlpha( Size( nPosCount * maSize.Width(), maSize.Height() ) );
370*cdf0e10cSrcweir         aRet = BitmapEx( aNewBmp, aAlpha );
371*cdf0e10cSrcweir     }
372*cdf0e10cSrcweir     else
373*cdf0e10cSrcweir         aRet  = BitmapEx( aNewBmp );
374*cdf0e10cSrcweir 
375*cdf0e10cSrcweir 	for( sal_uInt16 i = 0; i < nPosCount; i++ )
376*cdf0e10cSrcweir 	{
377*cdf0e10cSrcweir         const Point     aSrcPos( pPosAry[ i ] * maSize.Width(), 0L );
378*cdf0e10cSrcweir 		const Point		aPos( i * maSize.Width(), 0L );
379*cdf0e10cSrcweir 		const Rectangle aSrcRect( aSrcPos, maSize );
380*cdf0e10cSrcweir 		const Rectangle aDstRect( aPos, maSize );
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir 		aRet.CopyPixel( aDstRect, aSrcRect, &maBmpEx );
383*cdf0e10cSrcweir 	}
384*cdf0e10cSrcweir 
385*cdf0e10cSrcweir 	return aRet;
386*cdf0e10cSrcweir }
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir // -----------------------------------------------------------------------
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir void ImplImageBmp::Draw( sal_uInt16 nPos, OutputDevice* pOutDev,
391*cdf0e10cSrcweir 						 const Point& rPos, sal_uInt16 nStyle,
392*cdf0e10cSrcweir 						 const Size* pSize )
393*cdf0e10cSrcweir {
394*cdf0e10cSrcweir 	if( pOutDev->IsDeviceOutputNecessary() )
395*cdf0e10cSrcweir 	{
396*cdf0e10cSrcweir         const Point aSrcPos( nPos * maSize.Width(), 0 );
397*cdf0e10cSrcweir 		Size 		aOutSize;
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir 		aOutSize = ( pSize ? *pSize : pOutDev->PixelToLogic( maSize ) );
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir 		if( nStyle & IMAGE_DRAW_DISABLE )
402*cdf0e10cSrcweir 		{
403*cdf0e10cSrcweir             ImplUpdateDisabledBmpEx( nPos);
404*cdf0e10cSrcweir             pOutDev->DrawBitmapEx( rPos, aOutSize, aSrcPos, maSize, maDisabledBmpEx );
405*cdf0e10cSrcweir 		}
406*cdf0e10cSrcweir 		else
407*cdf0e10cSrcweir 		{
408*cdf0e10cSrcweir 			if( nStyle & ( IMAGE_DRAW_COLORTRANSFORM |
409*cdf0e10cSrcweir 						   IMAGE_DRAW_MONOCHROME_BLACK | IMAGE_DRAW_MONOCHROME_WHITE |
410*cdf0e10cSrcweir 						   IMAGE_DRAW_HIGHLIGHT | IMAGE_DRAW_DEACTIVE | IMAGE_DRAW_SEMITRANSPARENT ) )
411*cdf0e10cSrcweir 			{
412*cdf0e10cSrcweir 				BitmapEx        aTmpBmpEx;
413*cdf0e10cSrcweir 				const Rectangle aCropRect( aSrcPos, maSize );
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir 				if( mpInfoAry[ nPos ] & ( IMPSYSIMAGEITEM_MASK | IMPSYSIMAGEITEM_ALPHA ) )
416*cdf0e10cSrcweir 					aTmpBmpEx = maBmpEx;
417*cdf0e10cSrcweir 				else
418*cdf0e10cSrcweir 					aTmpBmpEx = maBmpEx.GetBitmap();
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir 				aTmpBmpEx.Crop( aCropRect );
421*cdf0e10cSrcweir 
422*cdf0e10cSrcweir 				if( nStyle & ( IMAGE_DRAW_COLORTRANSFORM | IMAGE_DRAW_MONOCHROME_BLACK | IMAGE_DRAW_MONOCHROME_WHITE ) )
423*cdf0e10cSrcweir 				{
424*cdf0e10cSrcweir 					const BmpColorMode eMode = ( nStyle & IMAGE_DRAW_COLORTRANSFORM ) ? BMP_COLOR_HIGHCONTRAST :
425*cdf0e10cSrcweir 										 	   ( ( nStyle & IMAGE_DRAW_MONOCHROME_BLACK ) ? BMP_COLOR_MONOCHROME_BLACK : BMP_COLOR_MONOCHROME_WHITE );
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir 					aTmpBmpEx = aTmpBmpEx.GetColorTransformedBitmapEx( eMode );
428*cdf0e10cSrcweir 				}
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir 				Bitmap aTmpBmp( aTmpBmpEx.GetBitmap() );
431*cdf0e10cSrcweir 
432*cdf0e10cSrcweir 				if( nStyle & ( IMAGE_DRAW_HIGHLIGHT | IMAGE_DRAW_DEACTIVE ) )
433*cdf0e10cSrcweir 				{
434*cdf0e10cSrcweir 					BitmapWriteAccess* pAcc = aTmpBmp.AcquireWriteAccess();
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir 					if( pAcc )
437*cdf0e10cSrcweir 					{
438*cdf0e10cSrcweir 						const StyleSettings&	rSettings = pOutDev->GetSettings().GetStyleSettings();
439*cdf0e10cSrcweir 						Color					aColor;
440*cdf0e10cSrcweir 						BitmapColor				aCol;
441*cdf0e10cSrcweir 						const long				nW = pAcc->Width();
442*cdf0e10cSrcweir 						const long				nH = pAcc->Height();
443*cdf0e10cSrcweir 						sal_uInt8*					pMapR = new sal_uInt8[ 256 ];
444*cdf0e10cSrcweir 						sal_uInt8*					pMapG = new sal_uInt8[ 256 ];
445*cdf0e10cSrcweir 						sal_uInt8*					pMapB = new sal_uInt8[ 256 ];
446*cdf0e10cSrcweir 						long					nX, nY;
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir 						if( nStyle & IMAGE_DRAW_HIGHLIGHT )
449*cdf0e10cSrcweir 							aColor = rSettings.GetHighlightColor();
450*cdf0e10cSrcweir 						else
451*cdf0e10cSrcweir 							aColor = rSettings.GetDeactiveColor();
452*cdf0e10cSrcweir 
453*cdf0e10cSrcweir 						const sal_uInt8 cR = aColor.GetRed();
454*cdf0e10cSrcweir 						const sal_uInt8 cG = aColor.GetGreen();
455*cdf0e10cSrcweir 						const sal_uInt8 cB = aColor.GetBlue();
456*cdf0e10cSrcweir 
457*cdf0e10cSrcweir 						for( nX = 0L; nX < 256L; nX++ )
458*cdf0e10cSrcweir 						{
459*cdf0e10cSrcweir 							pMapR[ nX ] = (sal_uInt8) ( ( ( nY = ( nX + cR ) >> 1 ) > 255 ) ? 255 : nY );
460*cdf0e10cSrcweir 							pMapG[ nX ] = (sal_uInt8) ( ( ( nY = ( nX + cG ) >> 1 ) > 255 ) ? 255 : nY );
461*cdf0e10cSrcweir 							pMapB[ nX ] = (sal_uInt8) ( ( ( nY = ( nX + cB ) >> 1 ) > 255 ) ? 255 : nY );
462*cdf0e10cSrcweir 						}
463*cdf0e10cSrcweir 
464*cdf0e10cSrcweir 						if( pAcc->HasPalette() )
465*cdf0e10cSrcweir 						{
466*cdf0e10cSrcweir 							for( sal_uInt16 i = 0, nCount = pAcc->GetPaletteEntryCount(); i < nCount; i++ )
467*cdf0e10cSrcweir 							{
468*cdf0e10cSrcweir 								const BitmapColor& rCol = pAcc->GetPaletteColor( i );
469*cdf0e10cSrcweir 								aCol.SetRed( pMapR[ rCol.GetRed() ] );
470*cdf0e10cSrcweir 								aCol.SetGreen( pMapG[ rCol.GetGreen() ] );
471*cdf0e10cSrcweir 								aCol.SetBlue( pMapB[ rCol.GetBlue() ] );
472*cdf0e10cSrcweir 								pAcc->SetPaletteColor( i, aCol );
473*cdf0e10cSrcweir 							}
474*cdf0e10cSrcweir 						}
475*cdf0e10cSrcweir 						else if( pAcc->GetScanlineFormat() == BMP_FORMAT_24BIT_TC_BGR )
476*cdf0e10cSrcweir 						{
477*cdf0e10cSrcweir 							for( nY = 0L; nY < nH; nY++ )
478*cdf0e10cSrcweir 							{
479*cdf0e10cSrcweir 								Scanline pScan = pAcc->GetScanline( nY );
480*cdf0e10cSrcweir 
481*cdf0e10cSrcweir 								for( nX = 0L; nX < nW; nX++ )
482*cdf0e10cSrcweir 								{
483*cdf0e10cSrcweir 									*pScan = pMapB[ *pScan ]; pScan++;
484*cdf0e10cSrcweir 									*pScan = pMapG[ *pScan ]; pScan++;
485*cdf0e10cSrcweir 									*pScan = pMapR[ *pScan ]; pScan++;
486*cdf0e10cSrcweir 								}
487*cdf0e10cSrcweir 							}
488*cdf0e10cSrcweir 						}
489*cdf0e10cSrcweir 						else
490*cdf0e10cSrcweir 						{
491*cdf0e10cSrcweir 							for( nY = 0L; nY < nH; nY++ )
492*cdf0e10cSrcweir 							{
493*cdf0e10cSrcweir 								for( nX = 0L; nX < nW; nX++ )
494*cdf0e10cSrcweir 								{
495*cdf0e10cSrcweir 									aCol = pAcc->GetPixel( nY, nX );
496*cdf0e10cSrcweir 									aCol.SetRed( pMapR[ aCol.GetRed() ] );
497*cdf0e10cSrcweir 									aCol.SetGreen( pMapG[ aCol.GetGreen() ] );
498*cdf0e10cSrcweir 									aCol.SetBlue( pMapB[ aCol.GetBlue() ] );
499*cdf0e10cSrcweir 									pAcc->SetPixel( nY, nX, aCol );
500*cdf0e10cSrcweir 								}
501*cdf0e10cSrcweir 							}
502*cdf0e10cSrcweir 						}
503*cdf0e10cSrcweir 
504*cdf0e10cSrcweir 						delete[] pMapR;
505*cdf0e10cSrcweir 						delete[] pMapG;
506*cdf0e10cSrcweir 						delete[] pMapB;
507*cdf0e10cSrcweir 						aTmpBmp.ReleaseAccess( pAcc );
508*cdf0e10cSrcweir 					}
509*cdf0e10cSrcweir 				}
510*cdf0e10cSrcweir 
511*cdf0e10cSrcweir 				if( nStyle & IMAGE_DRAW_SEMITRANSPARENT )
512*cdf0e10cSrcweir 				{
513*cdf0e10cSrcweir 					if( aTmpBmpEx.IsTransparent()  )
514*cdf0e10cSrcweir 					{
515*cdf0e10cSrcweir 						Bitmap aAlphaBmp( aTmpBmpEx.GetAlpha().GetBitmap() );
516*cdf0e10cSrcweir 
517*cdf0e10cSrcweir 						aAlphaBmp.Adjust( 50 );
518*cdf0e10cSrcweir 						aTmpBmpEx = BitmapEx( aTmpBmp, AlphaMask( aAlphaBmp ) );
519*cdf0e10cSrcweir 					}
520*cdf0e10cSrcweir 					else
521*cdf0e10cSrcweir 					{
522*cdf0e10cSrcweir 						sal_uInt8 cErase = 128;
523*cdf0e10cSrcweir 						aTmpBmpEx = BitmapEx( aTmpBmp, AlphaMask( aTmpBmp.GetSizePixel(),  &cErase ) );
524*cdf0e10cSrcweir 					}
525*cdf0e10cSrcweir 				}
526*cdf0e10cSrcweir 				else
527*cdf0e10cSrcweir 				{
528*cdf0e10cSrcweir 					if( aTmpBmpEx.IsAlpha() )
529*cdf0e10cSrcweir 						aTmpBmpEx = BitmapEx( aTmpBmp, aTmpBmpEx.GetAlpha() );
530*cdf0e10cSrcweir 					else if( aTmpBmpEx.IsAlpha() )
531*cdf0e10cSrcweir 						aTmpBmpEx = BitmapEx( aTmpBmp, aTmpBmpEx.GetMask() );
532*cdf0e10cSrcweir 				}
533*cdf0e10cSrcweir 
534*cdf0e10cSrcweir 				pOutDev->DrawBitmapEx( rPos, aOutSize, aTmpBmpEx );
535*cdf0e10cSrcweir 			}
536*cdf0e10cSrcweir 			else
537*cdf0e10cSrcweir 			{
538*cdf0e10cSrcweir 				const BitmapEx* pOutputBmp;
539*cdf0e10cSrcweir 
540*cdf0e10cSrcweir 				if( pOutDev->GetOutDevType() == OUTDEV_WINDOW )
541*cdf0e10cSrcweir 				{
542*cdf0e10cSrcweir 					ImplUpdateDisplayBmp( pOutDev );
543*cdf0e10cSrcweir 					pOutputBmp = mpDisplayBmp;
544*cdf0e10cSrcweir 				}
545*cdf0e10cSrcweir 				else
546*cdf0e10cSrcweir 					pOutputBmp = &maBmpEx;
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir 				if( pOutputBmp )
549*cdf0e10cSrcweir 					pOutDev->DrawBitmapEx( rPos, aOutSize, aSrcPos, maSize, *pOutputBmp );
550*cdf0e10cSrcweir 			}
551*cdf0e10cSrcweir 		}
552*cdf0e10cSrcweir 	}
553*cdf0e10cSrcweir }
554*cdf0e10cSrcweir 
555*cdf0e10cSrcweir // -----------------------------------------------------------------------
556*cdf0e10cSrcweir 
557*cdf0e10cSrcweir void ImplImageBmp::ImplUpdateDisplayBmp( OutputDevice*
558*cdf0e10cSrcweir #if defined WNT
559*cdf0e10cSrcweir pOutDev
560*cdf0e10cSrcweir #endif
561*cdf0e10cSrcweir )
562*cdf0e10cSrcweir {
563*cdf0e10cSrcweir 	if( !mpDisplayBmp && !maBmpEx.IsEmpty() )
564*cdf0e10cSrcweir 	{
565*cdf0e10cSrcweir #if defined WNT
566*cdf0e10cSrcweir 		if( maBmpEx.IsAlpha() )
567*cdf0e10cSrcweir 			mpDisplayBmp = new BitmapEx( maBmpEx );
568*cdf0e10cSrcweir 		else
569*cdf0e10cSrcweir 		{
570*cdf0e10cSrcweir 			const Bitmap aBmp( maBmpEx.GetBitmap().CreateDisplayBitmap( pOutDev ) );
571*cdf0e10cSrcweir 
572*cdf0e10cSrcweir 			if( maBmpEx.IsTransparent() )
573*cdf0e10cSrcweir 				mpDisplayBmp = new BitmapEx( aBmp, maBmpEx.GetMask().CreateDisplayBitmap( pOutDev ) );
574*cdf0e10cSrcweir 			else
575*cdf0e10cSrcweir 				mpDisplayBmp = new BitmapEx( aBmp );
576*cdf0e10cSrcweir 		}
577*cdf0e10cSrcweir #else
578*cdf0e10cSrcweir 		mpDisplayBmp = new BitmapEx( maBmpEx );
579*cdf0e10cSrcweir #endif
580*cdf0e10cSrcweir 	}
581*cdf0e10cSrcweir }
582*cdf0e10cSrcweir 
583*cdf0e10cSrcweir // -----------------------------------------------------------------------
584*cdf0e10cSrcweir 
585*cdf0e10cSrcweir void ImplImageBmp::ImplUpdateDisabledBmpEx( int nPos )
586*cdf0e10cSrcweir {
587*cdf0e10cSrcweir     const Size aTotalSize( maBmpEx.GetSizePixel() );
588*cdf0e10cSrcweir 
589*cdf0e10cSrcweir     if( maDisabledBmpEx.IsEmpty() )
590*cdf0e10cSrcweir     {
591*cdf0e10cSrcweir         Bitmap      aGrey( aTotalSize, 8, &Bitmap::GetGreyPalette( 256 ) );
592*cdf0e10cSrcweir         AlphaMask   aGreyAlphaMask( aTotalSize );
593*cdf0e10cSrcweir 
594*cdf0e10cSrcweir         maDisabledBmpEx = BitmapEx( aGrey, aGreyAlphaMask );
595*cdf0e10cSrcweir         nPos = -1;
596*cdf0e10cSrcweir     }
597*cdf0e10cSrcweir 
598*cdf0e10cSrcweir     Bitmap              aBmp( maBmpEx.GetBitmap() );
599*cdf0e10cSrcweir     BitmapReadAccess*   pBmp( aBmp.AcquireReadAccess() );
600*cdf0e10cSrcweir     AlphaMask           aBmpAlphaMask( maBmpEx.GetAlpha() );
601*cdf0e10cSrcweir     BitmapReadAccess*   pBmpAlphaMask( aBmpAlphaMask.AcquireReadAccess() );
602*cdf0e10cSrcweir     Bitmap              aGrey( maDisabledBmpEx.GetBitmap() );
603*cdf0e10cSrcweir     BitmapWriteAccess*  pGrey( aGrey.AcquireWriteAccess() );
604*cdf0e10cSrcweir     AlphaMask           aGreyAlphaMask( maDisabledBmpEx.GetAlpha() );
605*cdf0e10cSrcweir     BitmapWriteAccess*  pGreyAlphaMask( aGreyAlphaMask.AcquireWriteAccess() );
606*cdf0e10cSrcweir 
607*cdf0e10cSrcweir     if( pBmp && pBmpAlphaMask && pGrey && pGreyAlphaMask )
608*cdf0e10cSrcweir     {
609*cdf0e10cSrcweir         BitmapColor	aGreyVal( 0 );
610*cdf0e10cSrcweir         BitmapColor aGreyAlphaMaskVal( 0 );
611*cdf0e10cSrcweir         const Point aPos( ( nPos < 0 ) ? 0 : ( nPos * maSize.Width() ), 0 );
612*cdf0e10cSrcweir         const int  nLeft = aPos.X(), nRight = nLeft + ( ( nPos < 0 ) ? aTotalSize.Width() : maSize.Width() );
613*cdf0e10cSrcweir         const int  nTop = aPos.Y(), nBottom = nTop + maSize.Height();
614*cdf0e10cSrcweir 
615*cdf0e10cSrcweir         for( int nY = nTop; nY < nBottom; ++nY )
616*cdf0e10cSrcweir         {
617*cdf0e10cSrcweir             for( int nX = nLeft; nX < nRight; ++nX )
618*cdf0e10cSrcweir             {
619*cdf0e10cSrcweir                 aGreyVal.SetIndex( pBmp->GetLuminance( nY, nX ) );
620*cdf0e10cSrcweir                 pGrey->SetPixel( nY, nX, aGreyVal );
621*cdf0e10cSrcweir 
622*cdf0e10cSrcweir                 const BitmapColor aBmpAlphaMaskVal( pBmpAlphaMask->GetPixel( nY, nX ) );
623*cdf0e10cSrcweir 
624*cdf0e10cSrcweir                 aGreyAlphaMaskVal.SetIndex( static_cast< sal_uInt8 >( ::std::min( aBmpAlphaMaskVal.GetIndex() + 178ul, 255ul ) ) );
625*cdf0e10cSrcweir                 pGreyAlphaMask->SetPixel( nY, nX, aGreyAlphaMaskVal );
626*cdf0e10cSrcweir             }
627*cdf0e10cSrcweir         }
628*cdf0e10cSrcweir     }
629*cdf0e10cSrcweir 
630*cdf0e10cSrcweir     aBmp.ReleaseAccess( pBmp );
631*cdf0e10cSrcweir     aBmpAlphaMask.ReleaseAccess( pBmpAlphaMask );
632*cdf0e10cSrcweir     aGrey.ReleaseAccess( pGrey );
633*cdf0e10cSrcweir     aGreyAlphaMask.ReleaseAccess( pGreyAlphaMask );
634*cdf0e10cSrcweir 
635*cdf0e10cSrcweir     maDisabledBmpEx = BitmapEx( aGrey, aGreyAlphaMask );
636*cdf0e10cSrcweir }
637