View | Details | Raw Unified | Return to issue 35555
Collapse All | Expand All

(-)vcl/inc/image.h (-1 / +1 lines)
Lines 97-103 Link Here
97
private:
97
private:
98
98
99
	BitmapEx	maBmpEx;
99
	BitmapEx	maBmpEx;
100
	Bitmap		maDisabledBmp;
100
	BitmapEx	maDisabledBmpEx;
101
	BitmapEx*	mpDisplayBmp;
101
	BitmapEx*	mpDisplayBmp;
102
	Size		maSize;
102
	Size		maSize;
103
	BYTE*		mpInfoAry;
103
	BYTE*		mpInfoAry;
(-)vcl/source/gdi/impimage.cxx (-142 / +115 lines)
Lines 252-258 Link Here
252
	const Size aTotalSize( nInitSize * nItemWidth, nItemHeight );
252
	const Size aTotalSize( nInitSize * nItemWidth, nItemHeight );
253
253
254
	maBmpEx = Bitmap( aTotalSize, 24 );
254
	maBmpEx = Bitmap( aTotalSize, 24 );
255
	maDisabledBmp.SetEmpty();
255
	maDisabledBmpEx.SetEmpty();
256
256
257
	delete mpDisplayBmp;
257
	delete mpDisplayBmp;
258
	mpDisplayBmp = NULL; 
258
	mpDisplayBmp = NULL; 
Lines 270-276 Link Here
270
void ImplImageBmp::Create( const BitmapEx& rBmpEx, long nItemWidth, long nItemHeight, USHORT nInitSize )
270
void ImplImageBmp::Create( const BitmapEx& rBmpEx, long nItemWidth, long nItemHeight, USHORT nInitSize )
271
{
271
{
272
	maBmpEx = rBmpEx;
272
	maBmpEx = rBmpEx;
273
	maDisabledBmp.SetEmpty();
273
	maDisabledBmpEx.SetEmpty();
274
	
274
	
275
	delete mpDisplayBmp;
275
	delete mpDisplayBmp;
276
	mpDisplayBmp = NULL; 
276
	mpDisplayBmp = NULL; 
Lines 295-302 Link Here
295
295
296
	maBmpEx.Expand( nDX, 0UL );
296
	maBmpEx.Expand( nDX, 0UL );
297
297
298
	if( !maDisabledBmp.IsEmpty() )
298
	if( !maDisabledBmpEx.IsEmpty() )
299
		maDisabledBmp.Expand( nDX, 0UL );
299
		maDisabledBmpEx.Expand( nDX, 0UL );
300
300
301
	delete mpDisplayBmp;
301
	delete mpDisplayBmp;
302
	mpDisplayBmp = NULL; 
302
	mpDisplayBmp = NULL; 
Lines 327-334 Link Here
327
327
328
	maBmpEx.CopyPixel( aDstRect, aSrcRect );
328
	maBmpEx.CopyPixel( aDstRect, aSrcRect );
329
329
330
	if( !maDisabledBmp.IsEmpty() )
330
	if( !maDisabledBmpEx.IsEmpty() )
331
		maDisabledBmp.CopyPixel( aDstRect, aSrcRect );
331
		maDisabledBmpEx.CopyPixel( aDstRect, aSrcRect );
332
332
333
	delete mpDisplayBmp;
333
	delete mpDisplayBmp;
334
	mpDisplayBmp = NULL; 
334
	mpDisplayBmp = NULL; 
Lines 429-436 Link Here
429
429
430
			ImplUpdateDisabledBmp( -1 );
430
			ImplUpdateDisabledBmp( -1 );
431
431
432
			pOutDev->DrawMask( aOutPos1, aOutSize, aSrcPos, maSize, maDisabledBmp, rSettings.GetLightColor() );
432
			if( maDisabledBmpEx.IsAlpha() )
433
			pOutDev->DrawMask( rPos, aOutSize, aSrcPos, maSize, maDisabledBmp, rSettings.GetShadowColor() );
433
				pOutDev->DrawBitmapEx( rPos, aOutSize, aSrcPos, maSize, maDisabledBmpEx );
434
			else
435
			{
436
				pOutDev->DrawMask( aOutPos1, aOutSize, aSrcPos, maSize, maDisabledBmpEx.GetBitmap(),
437
								   rSettings.GetLightColor() );
438
				pOutDev->DrawMask( rPos, aOutSize, aSrcPos, maSize, maDisabledBmpEx.GetBitmap(),
439
								   rSettings.GetShadowColor() );
440
			}
434
		}
441
		}
435
		else
442
		else
436
		{
443
		{
Lines 609-766 Link Here
609
616
610
void ImplImageBmp::ImplUpdateDisabledBmp( int nPos )
617
void ImplImageBmp::ImplUpdateDisabledBmp( int nPos )
611
{
618
{
612
	if( ( nPos >= 0 && !maDisabledBmp.IsEmpty() ) || 
619
	if( ! ( nPos >= 0 && !maDisabledBmpEx.IsEmpty() ) &&
613
		( nPos < 0 && maDisabledBmp.IsEmpty() ) )
620
	    ! ( nPos < 0 && maDisabledBmpEx.IsEmpty() ) )
614
	{
621
		return;
615
		Bitmap aBmp( maBmpEx.GetBitmap() );
616
		Bitmap aMask;
617
622
618
		if( maBmpEx.IsTransparent() )
623
	AlphaMask aAlpha;
619
			aMask = maBmpEx.GetMask();
624
	Bitmap    aBitmap;
620
		else
621
		{
622
			aMask = aBmp;
623
			aMask.Convert( BMP_CONVERSION_1BIT_THRESHOLD );
624
		}
625
		
626
		if( maDisabledBmp.IsEmpty() )
627
			maDisabledBmp = Bitmap( aBmp.GetSizePixel(), 1 );
628
		
629
		BitmapReadAccess*	pAcc = aBmp.AcquireReadAccess();
630
		BitmapReadAccess*	pMsk = aMask.AcquireReadAccess();
631
		BitmapWriteAccess*	pDis = maDisabledBmp.AcquireWriteAccess();
632
625
633
		if( pAcc && pMsk && pDis )
626
	if( maBmpEx.IsAlpha() )
634
		{
627
	{
635
			const Color 		aWhite( COL_WHITE );
628
		aAlpha = AlphaMask( maBmpEx.GetSizePixel() );
636
			const Color 		aBlack( COL_BLACK );
629
		aBitmap = Bitmap( maBmpEx.GetSizePixel(),
637
			const BitmapColor	aAccWhite( pAcc->GetBestMatchingColor( aWhite ) );
630
						  maBmpEx.GetBitCount() );
638
			const BitmapColor	aMskWhite( pMsk->GetBestMatchingColor( aWhite ) );
631
	}
639
			const BitmapColor	aDisWhite( pDis->GetBestMatchingColor( aWhite ) );
632
	else
640
			const BitmapColor	aDisBlack( pDis->GetBestMatchingColor( aBlack ) );
633
        aBitmap = Bitmap( maBmpEx.GetSizePixel(), 1 );
641
			long				nLeft, nTop, nRight, nBottom;
642
			long				nCurLeft, nCurRight;
643
			const long			nBlackThreshold = FRound( maSize.Width() * maSize.Height() * 0.10 );
644
634
645
			if( nPos >= 0 )
635
	BitmapReadAccess  *pAcc = maBmpEx.GetBitmap().AcquireReadAccess();
646
			{
636
	BitmapWriteAccess *pDis = aBitmap.AcquireWriteAccess();
647
				const Point aPos( nPos * maSize.Width(), 0 );
648
637
649
				nLeft = aPos.X();
638
	if( !pAcc || !pDis )
650
				nTop = 0;
639
		return; // leak
651
				nRight = nLeft + maSize.Width();
652
				nBottom = nTop + maSize.Height();
653
			}
654
			else
655
			{
656
				nLeft = nTop = 0L;
657
				nRight = pDis->Width();
658
				nBottom = pDis->Height();
659
			}
660
640
661
			nCurLeft = nLeft;
641
	long nLeft, nTop, nRight, nBottom;
662
			nCurRight = nCurLeft + maSize.Width();
663
642
664
			while( nCurLeft < nRight )
643
	if( nPos >= 0 )
665
			{
644
	{
666
				sal_Int32 nBlackCount = 0;
645
		const Point aPos( nPos * maSize.Width(), 0 );
667
646
668
				if( pAcc->GetScanlineFormat() == BMP_FORMAT_4BIT_MSN_PAL &&
647
		nLeft = aPos.X();
669
					pMsk->GetScanlineFormat() == BMP_FORMAT_1BIT_MSB_PAL )
648
		nTop = 0;
670
				{
649
		nRight = nLeft + maSize.Width();
671
					// optimized version
650
		nBottom = nTop + maSize.Height();
672
					const BYTE cAccTest = aAccWhite.GetIndex();
651
	}
673
					const BYTE cMskTest = aMskWhite.GetIndex();
652
	else
653
	{
654
		nLeft = nTop = 0L;
655
		nRight = pDis->Width();
656
		nBottom = pDis->Height();
657
	}
674
658
675
					for( long nY = nTop; nY < nBottom; nY++ )
659
	if( maBmpEx.IsAlpha() )
676
					{
660
	{
677
						Scanline pAccScan = pAcc->GetScanline( nY );
661
		if( pAcc && pDis )
678
						Scanline pMskScan = pMsk->GetScanline( nY );
662
		{
679
				
663
			for( long nY = nTop; nY < nBottom; nY++ )
680
						for( long nX = nCurLeft; nX < nCurRight; nX++ )
664
			{
681
						{
665
				for( long nX = nLeft; nX < nRight; nX++ )
682
							if( ( cMskTest == ( pMskScan[ nX >> 3 ] & ( 1 << ( 7 - ( nX & 7 ) ) ) ? 1 : 0 ) ) || 
666
 				{
683
								( cAccTest == ( ( pAccScan[ nX >> 1 ] >> ( nX & 1 ? 0 : 4 ) ) & 0x0f ) ) )
667
					BitmapColor col = pAcc->GetPixel( nY, nX );
684
							{
685
								pDis->SetPixel( nY, nX, aDisWhite );
686
							}
687
							else
688
							{
689
								pDis->SetPixel( nY, nX, aDisBlack );
690
								++nBlackCount;
691
							}
692
						}
693
					}
694
				}
695
				else if( pAcc->GetScanlineFormat() == BMP_FORMAT_8BIT_PAL &&
696
						pMsk->GetScanlineFormat() == BMP_FORMAT_1BIT_MSB_PAL )
697
				{
698
					// optimized version
699
					const BYTE cAccTest = aAccWhite.GetIndex();
700
					const BYTE cMskTest = aMskWhite.GetIndex();
701
668
702
					for( long nY = nTop; nY < nBottom; nY++ )
669
					if ((nY + nX) % 2 == 0)
703
					{
670
					{
704
						Scanline pAccScan = pAcc->GetScanline( nY );
671
						unsigned char i;
705
						Scanline pMskScan = pMsk->GetScanline( nY );
672
						i = (unsigned char ) ( col.GetRed() * 0.3 + // magic numbers
706
				
673
								       col.GetGreen() * 0.59 +
707
						for( long nX = nCurLeft; nX < nCurRight; nX++ )
674
								       col.GetBlue () * 0.11 );
708
						{
675
709
							if( ( cMskTest == ( pMskScan[ nX >> 3 ] & ( 1 << ( 7 - ( nX & 7 ) ) ) ? 1 : 0 ) ) || 
676
						col.SetRed   (i / 2 + 127);
710
								( cAccTest == pAccScan[ nX ] ) )
677
						col.SetGreen (i / 2 + 127);
711
							{
678
						col.SetBlue  (i / 2 + 127);
712
								pDis->SetPixel( nY, nX, aDisWhite );
713
							}
714
							else
715
							{
716
								pDis->SetPixel( nY, nX, aDisBlack );
717
								++nBlackCount;
718
							}
719
						}
720
					}
679
					}
721
				}
680
					else
722
				else
723
				{	
724
					for( long nY = nTop; nY < nBottom; nY++ )
725
					{
681
					{
726
						for( long nX = nCurLeft; nX < nCurRight; nX++ )
682
#define GT_ZERO(c) ((unsigned char)(((c) >= 0) ? (c) : 0))
727
						{
683
						col.SetRed   (GT_ZERO (( col.GetRed ())   * 0.7));
728
							if( ( aMskWhite == pMsk->GetPixel( nY, nX ) ) || 
684
						col.SetGreen (GT_ZERO (( col.GetGreen ()) * 0.7));
729
								( aAccWhite == pAcc->GetPixel( nY, nX ) ) )
685
						col.SetBlue  (GT_ZERO (( col.GetBlue ())  * 0.7));
730
							{
686
#undef GT_ZERO
731
								pDis->SetPixel( nY, nX, aDisWhite );
732
							}
733
							else
734
							{
735
								pDis->SetPixel( nY, nX, aDisBlack );
736
								++nBlackCount;
737
							}
738
						}
739
					}
687
					}
688
					pDis->SetPixel( nY, nX, col );
740
				}
689
				}
690
			}
691
		}
741
692
742
				if( nBlackCount < nBlackThreshold )
693
		BitmapReadAccess  *pAlpha = maBmpEx.GetAlpha().AcquireReadAccess();
743
				{
694
		BitmapWriteAccess *pDisAlpha = aAlpha.AcquireWriteAccess();
744
					// emergency solution if paint bitmap is mostly white
695
		if( pAlpha && pDisAlpha )
745
					for( long nY = nTop; nY < nBottom; nY++ )
696
		{
746
					{
697
			for( long nY = nTop; nY < nBottom; nY++ )
747
						for( long nX = nCurLeft; nX < nCurRight; nX++ )
698
			{
748
						{
699
				for( long nX = nLeft; nX < nRight; nX++ )
749
							if( aMskWhite == pMsk->GetPixel( nY, nX ) )
700
 				{
750
								pDis->SetPixel( nY, nX, aDisWhite );
701
					// The way the mask is polarised is most strange
751
							else
702
					BYTE nAlpha = 255 - (BYTE)pAlpha->GetPixel( nY, nX );
752
								pDis->SetPixel( nY, nX, aDisBlack );
703
					pDisAlpha->SetPixel( nY, nX, BitmapColor( 255 - (nAlpha / 2) ) );
753
						}
754
					}
755
				}
704
				}
756
757
				nCurLeft += maSize.Width();
758
				nCurRight += maSize.Width();
759
			}
705
			}
760
		}
706
		}
707
		aAlpha.ReleaseAccess( pDisAlpha );
708
		maBmpEx.GetAlpha().ReleaseAccess( pAlpha );
709
	}
710
	else
711
	{
712
		BitmapReadAccess *pMsk = aBitmap.AcquireReadAccess();
713
714
		const Color aWhite( COL_WHITE );
715
		const Color aBlack( COL_BLACK );
716
		const BitmapColor aAccWhite( pAcc->GetBestMatchingColor( aWhite ) );
717
		const BitmapColor aMskWhite( pMsk->GetBestMatchingColor( aWhite ) );
718
		const BitmapColor aDisWhite( pDis->GetBestMatchingColor( aWhite ) );
719
		const BitmapColor aDisBlack( pDis->GetBestMatchingColor( aBlack ) );
761
720
762
		aBmp.ReleaseAccess( pAcc );
721
		for( long nY = nTop; nY < nBottom; nY++ )
763
		aMask.ReleaseAccess( pMsk );
722
		{
764
		maDisabledBmp.ReleaseAccess( pDis );
723
			for( long nX = nLeft; nX < nRight; nX++ )
724
			{
725
				if( ( aMskWhite == pMsk->GetPixel( nY, nX ) ) &&
726
				    ( aAccWhite != pAcc->GetPixel( nY, nX ) ) )
727
					pDis->SetPixel( nY, nX, aDisBlack );
728
				else
729
					pDis->SetPixel( nY, nX, aDisWhite );
730
			}
731
		}
732
		aBitmap.ReleaseAccess( pMsk );
765
	}
733
	}
734
735
	if( maBmpEx.IsAlpha() )
736
			maDisabledBmpEx = BitmapEx( aBitmap, aAlpha );
737
	else
738
			maDisabledBmpEx = BitmapEx( aBitmap );
766
}
739
}

Return to issue 35555