Index: vcl/inc/image.h =================================================================== RCS file: /cvs/gsl/vcl/inc/image.h,v retrieving revision 1.7 diff -u -r1.7 image.h --- vcl/inc/image.h 10 Jun 2004 17:38:14 -0000 1.7 +++ vcl/inc/image.h 14 Oct 2004 15:27:56 -0000 @@ -97,7 +97,7 @@ private: BitmapEx maBmpEx; - Bitmap maDisabledBmp; + BitmapEx maDisabledBmpEx; BitmapEx* mpDisplayBmp; Size maSize; BYTE* mpInfoAry; Index: vcl/source/gdi/impimage.cxx =================================================================== RCS file: /cvs/gsl/vcl/source/gdi/impimage.cxx,v retrieving revision 1.16 diff -u -r1.16 impimage.cxx --- vcl/source/gdi/impimage.cxx 10 Jun 2004 17:53:28 -0000 1.16 +++ vcl/source/gdi/impimage.cxx 14 Oct 2004 15:27:56 -0000 @@ -252,7 +252,7 @@ const Size aTotalSize( nInitSize * nItemWidth, nItemHeight ); maBmpEx = Bitmap( aTotalSize, 24 ); - maDisabledBmp.SetEmpty(); + maDisabledBmpEx.SetEmpty(); delete mpDisplayBmp; mpDisplayBmp = NULL; @@ -270,7 +270,7 @@ void ImplImageBmp::Create( const BitmapEx& rBmpEx, long nItemWidth, long nItemHeight, USHORT nInitSize ) { maBmpEx = rBmpEx; - maDisabledBmp.SetEmpty(); + maDisabledBmpEx.SetEmpty(); delete mpDisplayBmp; mpDisplayBmp = NULL; @@ -295,8 +295,8 @@ maBmpEx.Expand( nDX, 0UL ); - if( !maDisabledBmp.IsEmpty() ) - maDisabledBmp.Expand( nDX, 0UL ); + if( !maDisabledBmpEx.IsEmpty() ) + maDisabledBmpEx.Expand( nDX, 0UL ); delete mpDisplayBmp; mpDisplayBmp = NULL; @@ -327,8 +327,8 @@ maBmpEx.CopyPixel( aDstRect, aSrcRect ); - if( !maDisabledBmp.IsEmpty() ) - maDisabledBmp.CopyPixel( aDstRect, aSrcRect ); + if( !maDisabledBmpEx.IsEmpty() ) + maDisabledBmpEx.CopyPixel( aDstRect, aSrcRect ); delete mpDisplayBmp; mpDisplayBmp = NULL; @@ -429,8 +429,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 { @@ -609,158 +616,124 @@ void ImplImageBmp::ImplUpdateDisabledBmp( int nPos ) { - if( ( nPos >= 0 && !maDisabledBmp.IsEmpty() ) || - ( nPos < 0 && maDisabledBmp.IsEmpty() ) ) - { - Bitmap aBmp( maBmpEx.GetBitmap() ); - Bitmap aMask; + if( ! ( nPos >= 0 && !maDisabledBmpEx.IsEmpty() ) && + ! ( nPos < 0 && maDisabledBmpEx.IsEmpty() ) ) + return; - 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(); + AlphaMask aAlpha; + Bitmap aBitmap; - 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( maBmpEx.IsAlpha() ) + { + aAlpha = AlphaMask( maBmpEx.GetSizePixel() ); + aBitmap = Bitmap( maBmpEx.GetSizePixel(), + maBmpEx.GetBitCount() ); + } + else + aBitmap = Bitmap( maBmpEx.GetSizePixel(), 1 ); - if( nPos >= 0 ) - { - const Point aPos( nPos * maSize.Width(), 0 ); + BitmapReadAccess *pAcc = maBmpEx.GetBitmap().AcquireReadAccess(); + BitmapWriteAccess *pDis = aBitmap.AcquireWriteAccess(); - nLeft = aPos.X(); - nTop = 0; - nRight = nLeft + maSize.Width(); - nBottom = nTop + maSize.Height(); - } - else - { - nLeft = nTop = 0L; - nRight = pDis->Width(); - nBottom = pDis->Height(); - } + if( !pAcc || !pDis ) + return; // leak - nCurLeft = nLeft; - nCurRight = nCurLeft + maSize.Width(); + long nLeft, nTop, nRight, nBottom; - while( nCurLeft < nRight ) - { - sal_Int32 nBlackCount = 0; + if( nPos >= 0 ) + { + const Point aPos( nPos * maSize.Width(), 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(); + nLeft = aPos.X(); + nTop = 0; + nRight = nLeft + maSize.Width(); + nBottom = nTop + maSize.Height(); + } + else + { + nLeft = nTop = 0L; + nRight = pDis->Width(); + nBottom = pDis->Height(); + } - 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(); + if( maBmpEx.IsAlpha() ) + { + if( pAcc && pDis ) + { + for( long nY = nTop; nY < nBottom; nY++ ) + { + for( long nX = nLeft; nX < nRight; nX++ ) + { + BitmapColor col = pAcc->GetPixel( nY, nX ); - for( long nY = nTop; nY < nBottom; nY++ ) + 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; - } - } + unsigned char i; + i = (unsigned char ) ( col.GetRed() * 0.3 + // magic numbers + col.GetGreen() * 0.59 + + col.GetBlue () * 0.11 ); + + 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; - } - } +#define GT_ZERO(c) ((unsigned char)(((c) >= 0) ? (c) : 0)) + col.SetRed (GT_ZERO (( col.GetRed ()) * 0.7)); + col.SetGreen (GT_ZERO (( col.GetGreen ()) * 0.7)); + col.SetBlue (GT_ZERO (( col.GetBlue ()) * 0.7)); +#undef GT_ZERO } + pDis->SetPixel( nY, nX, col ); } + } + } - 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 ); - } - } + BitmapReadAccess *pAlpha = maBmpEx.GetAlpha().AcquireReadAccess(); + BitmapWriteAccess *pDisAlpha = aAlpha.AcquireWriteAccess(); + if( pAlpha && pDisAlpha ) + { + for( long nY = nTop; nY < nBottom; nY++ ) + { + for( long nX = nLeft; nX < nRight; nX++ ) + { + // The way the mask is polarised is most strange + BYTE nAlpha = 255 - (BYTE)pAlpha->GetPixel( nY, nX ); + pDisAlpha->SetPixel( nY, nX, BitmapColor( 255 - (nAlpha / 2) ) ); } - - nCurLeft += maSize.Width(); - nCurRight += maSize.Width(); } } + aAlpha.ReleaseAccess( pDisAlpha ); + maBmpEx.GetAlpha().ReleaseAccess( pAlpha ); + } + else + { + BitmapReadAccess *pMsk = aBitmap.AcquireReadAccess(); + + 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 ) ); - aBmp.ReleaseAccess( pAcc ); - aMask.ReleaseAccess( pMsk ); - maDisabledBmp.ReleaseAccess( pDis ); + 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 ); + } + } + aBitmap.ReleaseAccess( pMsk ); } + + if( maBmpEx.IsAlpha() ) + maDisabledBmpEx = BitmapEx( aBitmap, aAlpha ); + else + maDisabledBmpEx = BitmapEx( aBitmap ); }