Index: vcl/source/gdi/impimage.cxx
===================================================================
RCS file: /cvs/gsl/vcl/source/gdi/impimage.cxx,v
retrieving revision 1.18
diff -u -r1.18 impimage.cxx
--- vcl/source/gdi/impimage.cxx	9 Sep 2005 12:01:31 -0000	1.18
+++ vcl/source/gdi/impimage.cxx	22 Mar 2006 12:25:14 -0000
@@ -225,7 +225,7 @@
 	const Size aTotalSize( nInitSize * nItemWidth, nItemHeight );
 
 	maBmpEx = Bitmap( aTotalSize, 24 );
-	maDisabledBmp.SetEmpty();
+	maDisabledBmpEx.SetEmpty();
 
 	delete mpDisplayBmp;
 	mpDisplayBmp = NULL; 
@@ -243,7 +243,7 @@
 void ImplImageBmp::Create( const BitmapEx& rBmpEx, long nItemWidth, long nItemHeight, USHORT nInitSize )
 {
 	maBmpEx = rBmpEx;
-	maDisabledBmp.SetEmpty();
+	maDisabledBmpEx.SetEmpty();
 	
 	delete mpDisplayBmp;
 	mpDisplayBmp = NULL; 
@@ -268,8 +268,8 @@
 
 	maBmpEx.Expand( nDX, 0UL );
 
-	if( !maDisabledBmp.IsEmpty() )
-		maDisabledBmp.Expand( nDX, 0UL );
+	if( !maDisabledBmpEx.IsEmpty() )
+		maDisabledBmpEx.Expand( nDX, 0UL );
 
 	delete mpDisplayBmp;
 	mpDisplayBmp = NULL; 
@@ -300,8 +300,8 @@
 
 	maBmpEx.CopyPixel( aDstRect, aSrcRect );
 
-	if( !maDisabledBmp.IsEmpty() )
-		maDisabledBmp.CopyPixel( aDstRect, aSrcRect );
+	if( !maDisabledBmpEx.IsEmpty() )
+		maDisabledBmpEx.CopyPixel( aDstRect, aSrcRect );
 
 	delete mpDisplayBmp;
 	mpDisplayBmp = NULL; 
@@ -412,8 +412,15 @@
 
 			ImplUpdateDisabledBmp( -1 );
 
-			pOutDev->DrawMask( aOutPos1, aOutSize, aSrcPos, maSize, maDisabledBmp, rSettings.GetLightColor() );
-			pOutDev->DrawMask( rPos, aOutSize, aSrcPos, maSize, maDisabledBmp, rSettings.GetShadowColor() );
+			if( maDisabledBmpEx.IsAlpha() )
+				pOutDev->DrawBitmapEx( rPos, aOutSize, aSrcPos, maSize, maDisabledBmpEx );
+			else
+			{
+				pOutDev->DrawMask( aOutPos1, aOutSize, aSrcPos, maSize, maDisabledBmpEx.GetBitmap(),
+								   rSettings.GetLightColor() );
+				pOutDev->DrawMask( rPos, aOutSize, aSrcPos, maSize, maDisabledBmpEx.GetBitmap(),
+								   rSettings.GetShadowColor() );
+			}
 		}
 		else
 		{
@@ -590,160 +597,121 @@
 
 // -----------------------------------------------------------------------
 
-void ImplImageBmp::ImplUpdateDisabledBmp( int nPos )
+static unsigned char deSaturate (unsigned char col, unsigned char intensity)
 {
-	if( ( nPos >= 0 && !maDisabledBmp.IsEmpty() ) || 
-		( nPos < 0 && maDisabledBmp.IsEmpty() ) )
-	{
-		Bitmap aBmp( maBmpEx.GetBitmap() );
-		Bitmap aMask;
+	int i = (int) ((0.2 * intensity + col * 0.8) * 0.7);
+	if (i <= 0)
+		return 0;
+	if (i >= 255)
+		return 255;
+	return (unsigned char) i;
+}
 
-		if( maBmpEx.IsTransparent() )
-			aMask = maBmpEx.GetMask();
-		else
-		{
-			aMask = aBmp;
-			aMask.Convert( BMP_CONVERSION_1BIT_THRESHOLD );
-		}
-		
-		if( maDisabledBmp.IsEmpty() )
-			maDisabledBmp = Bitmap( aBmp.GetSizePixel(), 1 );
-		
-		BitmapReadAccess*	pAcc = aBmp.AcquireReadAccess();
-		BitmapReadAccess*	pMsk = aMask.AcquireReadAccess();
-		BitmapWriteAccess*	pDis = maDisabledBmp.AcquireWriteAccess();
+void ImplImageBmp::ImplUpdateDisabledBmp( int nPos )
+{
+	if( ! ( nPos >= 0 && !maDisabledBmpEx.IsEmpty() ) &&
+	    ! ( nPos < 0 && maDisabledBmpEx.IsEmpty() ) )
+		return;
+
+	Bitmap aBitmap;
+
+	if( maBmpEx.IsAlpha() )
+		aBitmap = Bitmap( maBmpEx.GetSizePixel(),
+						  maBmpEx.GetBitCount() );
+	else
+        aBitmap = Bitmap( maBmpEx.GetSizePixel(), 1 );
+
+	Bitmap aSrcBitmap = maBmpEx.GetBitmap();
+	BitmapReadAccess  *pAcc = aSrcBitmap.AcquireReadAccess();
+	if( !pAcc )
+		return;
+	BitmapWriteAccess *pDis = aBitmap.AcquireWriteAccess();
 
-		if( pAcc && pMsk && pDis )
-		{
-			const Color 		aWhite( COL_WHITE );
-			const Color 		aBlack( COL_BLACK );
-			const BitmapColor	aAccWhite( pAcc->GetBestMatchingColor( aWhite ) );
-			const BitmapColor	aMskWhite( pMsk->GetBestMatchingColor( aWhite ) );
-			const BitmapColor	aDisWhite( pDis->GetBestMatchingColor( aWhite ) );
-			const BitmapColor	aDisBlack( pDis->GetBestMatchingColor( aBlack ) );
-			long				nLeft, nTop, nRight, nBottom;
-			long				nCurLeft, nCurRight;
-			const long			nBlackThreshold = FRound( maSize.Width() * maSize.Height() * 0.10 );
+	if( !pDis )
+	{
+		aSrcBitmap.ReleaseAccess( pAcc );
+		return;
+	}
 
-			if( nPos >= 0 )
-			{
-				const Point aPos( nPos * maSize.Width(), 0 );
+	long nLeft, nTop, nRight, nBottom;
 
-				nLeft = aPos.X();
-				nTop = 0;
-				nRight = nLeft + maSize.Width();
-				nBottom = nTop + maSize.Height();
-			}
-			else
-			{
-				nLeft = nTop = 0L;
-				nRight = pDis->Width();
-				nBottom = pDis->Height();
-			}
+	if( nPos >= 0 )
+	{
+		const Point aPos( nPos * maSize.Width(), 0 );
 
-			nCurLeft = nLeft;
-			nCurRight = nCurLeft + maSize.Width();
+		nLeft = aPos.X();
+		nTop = 0;
+		nRight = nLeft + maSize.Width();
+		nBottom = nTop + maSize.Height();
+	}
+	else
+	{
+		nLeft = nTop = 0L;
+		nRight = pDis->Width();
+		nBottom = pDis->Height();
+	}
 
-			while( nCurLeft < nRight )
+	if( maBmpEx.IsAlpha() )
+	{
+		if( pAcc && pDis )
+		{
+			for( long nY = nTop; nY < nBottom; nY++ )
 			{
-				sal_Int32 nBlackCount = 0;
-
-				if( pAcc->GetScanlineFormat() == BMP_FORMAT_4BIT_MSN_PAL &&
-					pMsk->GetScanlineFormat() == BMP_FORMAT_1BIT_MSB_PAL )
-				{
-					// optimized version
-					const BYTE cAccTest = aAccWhite.GetIndex();
-					const BYTE cMskTest = aMskWhite.GetIndex();
-
-					for( long nY = nTop; nY < nBottom; nY++ )
-					{
-						Scanline pAccScan = pAcc->GetScanline( nY );
-						Scanline pMskScan = pMsk->GetScanline( nY );
-				
-						for( long nX = nCurLeft; nX < nCurRight; nX++ )
-						{
-							if( ( cMskTest == ( pMskScan[ nX >> 3 ] & ( 1 << ( 7 - ( nX & 7 ) ) ) ? 1 : 0 ) ) || 
-								( cAccTest == ( ( pAccScan[ nX >> 1 ] >> ( nX & 1 ? 0 : 4 ) ) & 0x0f ) ) )
-							{
-								pDis->SetPixel( nY, nX, aDisWhite );
-							}
-							else
-							{
-								pDis->SetPixel( nY, nX, aDisBlack );
-								++nBlackCount;
-							}
-						}
-					}
-				}
-				else if( pAcc->GetScanlineFormat() == BMP_FORMAT_8BIT_PAL &&
-						pMsk->GetScanlineFormat() == BMP_FORMAT_1BIT_MSB_PAL )
-				{
-					// optimized version
-					const BYTE cAccTest = aAccWhite.GetIndex();
-					const BYTE cMskTest = aMskWhite.GetIndex();
-
-					for( long nY = nTop; nY < nBottom; nY++ )
+				for( long nX = nLeft; nX < nRight; nX++ )
+ 				{
+					BitmapColor col = pAcc->GetPixel( nY, nX );
+					unsigned char i;
+
+					i = (unsigned char ) ( col.GetRed() * 0.3 + // magic numbers
+										   col.GetGreen() * 0.59 +
+										   col.GetBlue () * 0.11 );
+					if ((nY + nX) % 2 == 0)
 					{
-						Scanline pAccScan = pAcc->GetScanline( nY );
-						Scanline pMskScan = pMsk->GetScanline( nY );
-				
-						for( long nX = nCurLeft; nX < nCurRight; nX++ )
-						{
-							if( ( cMskTest == ( pMskScan[ nX >> 3 ] & ( 1 << ( 7 - ( nX & 7 ) ) ) ? 1 : 0 ) ) || 
-								( cAccTest == pAccScan[ nX ] ) )
-							{
-								pDis->SetPixel( nY, nX, aDisWhite );
-							}
-							else
-							{
-								pDis->SetPixel( nY, nX, aDisBlack );
-								++nBlackCount;
-							}
-						}
+						col.SetRed   (i / 2 + 127);
+						col.SetGreen (i / 2 + 127);
+						col.SetBlue  (i / 2 + 127);
 					}
-				}
-				else
-				{	
-					for( long nY = nTop; nY < nBottom; nY++ )
+					else
 					{
-						for( long nX = nCurLeft; nX < nCurRight; nX++ )
-						{
-							if( ( aMskWhite == pMsk->GetPixel( nY, nX ) ) || 
-								( aAccWhite == pAcc->GetPixel( nY, nX ) ) )
-							{
-								pDis->SetPixel( nY, nX, aDisWhite );
-							}
-							else
-							{
-								pDis->SetPixel( nY, nX, aDisBlack );
-								++nBlackCount;
-							}
-						}
+						col.SetRed   (deSaturate (col.GetRed(), i));
+						col.SetGreen (deSaturate (col.GetGreen(), i));
+						col.SetBlue  (deSaturate (col.GetBlue(), i));
 					}
+					pDis->SetPixel( nY, nX, col );
 				}
+			}
+		}
+	}
+	else
+	{
+		BitmapReadAccess *pMsk = aBitmap.AcquireReadAccess();
 
-				if( nBlackCount < nBlackThreshold )
-				{
-					// emergency solution if paint bitmap is mostly white
-					for( long nY = nTop; nY < nBottom; nY++ )
-					{
-						for( long nX = nCurLeft; nX < nCurRight; nX++ )
-						{
-							if( aMskWhite == pMsk->GetPixel( nY, nX ) )
-								pDis->SetPixel( nY, nX, aDisWhite );
-							else
-								pDis->SetPixel( nY, nX, aDisBlack );
-						}
-					}
-				}
+		const Color aWhite( COL_WHITE );
+		const Color aBlack( COL_BLACK );
+		const BitmapColor aAccWhite( pAcc->GetBestMatchingColor( aWhite ) );
+		const BitmapColor aMskWhite( pMsk->GetBestMatchingColor( aWhite ) );
+		const BitmapColor aDisWhite( pDis->GetBestMatchingColor( aWhite ) );
+		const BitmapColor aDisBlack( pDis->GetBestMatchingColor( aBlack ) );
 
-				nCurLeft += maSize.Width();
-				nCurRight += maSize.Width();
+		for( long nY = nTop; nY < nBottom; nY++ )
+		{
+			for( long nX = nLeft; nX < nRight; nX++ )
+			{
+				if( ( aMskWhite == pMsk->GetPixel( nY, nX ) ) &&
+				    ( aAccWhite != pAcc->GetPixel( nY, nX ) ) )
+					pDis->SetPixel( nY, nX, aDisBlack );
+				else
+					pDis->SetPixel( nY, nX, aDisWhite );
 			}
 		}
-
-		aBmp.ReleaseAccess( pAcc );
-		aMask.ReleaseAccess( pMsk );
-		maDisabledBmp.ReleaseAccess( pDis );
+		aBitmap.ReleaseAccess( pMsk );
 	}
+
+	aSrcBitmap.ReleaseAccess( pAcc );
+	aBitmap.ReleaseAccess( pDis );
+
+	if( maBmpEx.IsAlpha() )
+			maDisabledBmpEx = BitmapEx( aBitmap, maBmpEx.GetAlpha() );
+	else
+			maDisabledBmpEx = BitmapEx( aBitmap );
 }
Index: vcl/inc/image.h
===================================================================
RCS file: /cvs/gsl/vcl/inc/image.h,v
retrieving revision 1.8
diff -u -r1.8 image.h
--- vcl/inc/image.h	9 Sep 2005 11:01:36 -0000	1.8
+++ vcl/inc/image.h	22 Mar 2006 12:25:15 -0000
@@ -71,7 +71,7 @@
 private:
 
 	BitmapEx	maBmpEx;
-	Bitmap		maDisabledBmp;
+	BitmapEx	maDisabledBmpEx;
 	BitmapEx*	mpDisplayBmp;
 	Size		maSize;
 	BYTE*		mpInfoAry;
