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