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

(-)vcl/inc/image.h (-1 / +1 lines)
Lines 97-103 public: 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 (-145 / +106 lines)
Lines 252-258 void ImplImageBmp::Create( long nItemWid 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 void ImplImageBmp::Create( long nItemWid 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 void ImplImageBmp::Expand( USHORT nGrowS 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 void ImplImageBmp::Replace( USHORT nPos, 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 void ImplImageBmp::Draw( USHORT nPos, Ou 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 618-775 Link Here
618
625
619
void ImplImageBmp::ImplUpdateDisabledBmp( int nPos )
626
void ImplImageBmp::ImplUpdateDisabledBmp( int nPos )
620
{
627
{
621
	if( ( nPos >= 0 && !maDisabledBmp.IsEmpty() ) || 
628
	if( ! ( nPos >= 0 && !maDisabledBmpEx.IsEmpty() ) &&
622
		( nPos < 0 && maDisabledBmp.IsEmpty() ) )
629
	    ! ( nPos < 0 && maDisabledBmpEx.IsEmpty() ) )
623
	{
630
		return;
624
		Bitmap aBmp( maBmpEx.GetBitmap() );
631
625
		Bitmap aMask;
632
	Bitmap aBitmap;
626
633
627
		if( maBmpEx.IsTransparent() )
634
	if( maBmpEx.IsAlpha() )
628
			aMask = maBmpEx.GetMask();
635
		aBitmap = Bitmap( maBmpEx.GetSizePixel(),
629
		else
636
						  maBmpEx.GetBitCount() );
630
		{
637
	else
631
			aMask = aBmp;
638
        aBitmap = Bitmap( maBmpEx.GetSizePixel(), 1 );
632
			aMask.Convert( BMP_CONVERSION_1BIT_THRESHOLD );
639
633
		}
640
	Bitmap aSrcBitmap = maBmpEx.GetBitmap();
634
		
641
	BitmapReadAccess  *pAcc = aSrcBitmap.AcquireReadAccess();
635
		if( maDisabledBmp.IsEmpty() )
642
	if( !pAcc )
636
			maDisabledBmp = Bitmap( aBmp.GetSizePixel(), 1 );
643
		return;
637
		
644
	BitmapWriteAccess *pDis = aBitmap.AcquireWriteAccess();
638
		BitmapReadAccess*	pAcc = aBmp.AcquireReadAccess();
639
		BitmapReadAccess*	pMsk = aMask.AcquireReadAccess();
640
		BitmapWriteAccess*	pDis = maDisabledBmp.AcquireWriteAccess();
641
645
642
		if( pAcc && pMsk && pDis )
646
	if( !pDis )
643
		{
647
	{
644
			const Color 		aWhite( COL_WHITE );
648
		aSrcBitmap.ReleaseAccess( pAcc );
645
			const Color 		aBlack( COL_BLACK );
649
		return;
646
			const BitmapColor	aAccWhite( pAcc->GetBestMatchingColor( aWhite ) );
650
	}
647
			const BitmapColor	aMskWhite( pMsk->GetBestMatchingColor( aWhite ) );
648
			const BitmapColor	aDisWhite( pDis->GetBestMatchingColor( aWhite ) );
649
			const BitmapColor	aDisBlack( pDis->GetBestMatchingColor( aBlack ) );
650
			long				nLeft, nTop, nRight, nBottom;
651
			long				nCurLeft, nCurRight;
652
			const long			nBlackThreshold = FRound( maSize.Width() * maSize.Height() * 0.10 );
653
651
654
			if( nPos >= 0 )
652
	long nLeft, nTop, nRight, nBottom;
655
			{
656
				const Point aPos( nPos * maSize.Width(), 0 );
657
653
658
				nLeft = aPos.X();
654
	if( nPos >= 0 )
659
				nTop = 0;
655
	{
660
				nRight = nLeft + maSize.Width();
656
		const Point aPos( nPos * maSize.Width(), 0 );
661
				nBottom = nTop + maSize.Height();
662
			}
663
			else
664
			{
665
				nLeft = nTop = 0L;
666
				nRight = pDis->Width();
667
				nBottom = pDis->Height();
668
			}
669
657
670
			nCurLeft = nLeft;
658
		nLeft = aPos.X();
671
			nCurRight = nCurLeft + maSize.Width();
659
		nTop = 0;
660
		nRight = nLeft + maSize.Width();
661
		nBottom = nTop + maSize.Height();
662
	}
663
	else
664
	{
665
		nLeft = nTop = 0L;
666
		nRight = pDis->Width();
667
		nBottom = pDis->Height();
668
	}
672
669
673
			while( nCurLeft < nRight )
670
	if( maBmpEx.IsAlpha() )
671
	{
672
		if( pAcc && pDis )
673
		{
674
			for( long nY = nTop; nY < nBottom; nY++ )
674
			{
675
			{
675
				sal_Int32 nBlackCount = 0;
676
				for( long nX = nLeft; nX < nRight; nX++ )
676
677
 				{
677
				if( pAcc->GetScanlineFormat() == BMP_FORMAT_4BIT_MSN_PAL &&
678
					BitmapColor col = pAcc->GetPixel( nY, nX );
678
					pMsk->GetScanlineFormat() == BMP_FORMAT_1BIT_MSB_PAL )
679
				{
680
					// optimized version
681
					const BYTE cAccTest = aAccWhite.GetIndex();
682
					const BYTE cMskTest = aMskWhite.GetIndex();
683
684
					for( long nY = nTop; nY < nBottom; nY++ )
685
					{
686
						Scanline pAccScan = pAcc->GetScanline( nY );
687
						Scanline pMskScan = pMsk->GetScanline( nY );
688
				
689
						for( long nX = nCurLeft; nX < nCurRight; nX++ )
690
						{
691
							if( ( cMskTest == ( pMskScan[ nX >> 3 ] & ( 1 << ( 7 - ( nX & 7 ) ) ) ? 1 : 0 ) ) || 
692
								( cAccTest == ( ( pAccScan[ nX >> 1 ] >> ( nX & 1 ? 0 : 4 ) ) & 0x0f ) ) )
693
							{
694
								pDis->SetPixel( nY, nX, aDisWhite );
695
							}
696
							else
697
							{
698
								pDis->SetPixel( nY, nX, aDisBlack );
699
								++nBlackCount;
700
							}
701
						}
702
					}
703
				}
704
				else if( pAcc->GetScanlineFormat() == BMP_FORMAT_8BIT_PAL &&
705
						pMsk->GetScanlineFormat() == BMP_FORMAT_1BIT_MSB_PAL )
706
				{
707
					// optimized version
708
					const BYTE cAccTest = aAccWhite.GetIndex();
709
					const BYTE cMskTest = aMskWhite.GetIndex();
710
679
711
					for( long nY = nTop; nY < nBottom; nY++ )
680
					if ((nY + nX) % 2 == 0)
712
					{
681
					{
713
						Scanline pAccScan = pAcc->GetScanline( nY );
682
						unsigned char i;
714
						Scanline pMskScan = pMsk->GetScanline( nY );
683
						i = (unsigned char ) ( col.GetRed() * 0.3 + // magic numbers
715
				
684
								       col.GetGreen() * 0.59 +
716
						for( long nX = nCurLeft; nX < nCurRight; nX++ )
685
								       col.GetBlue () * 0.11 );
717
						{
686
718
							if( ( cMskTest == ( pMskScan[ nX >> 3 ] & ( 1 << ( 7 - ( nX & 7 ) ) ) ? 1 : 0 ) ) || 
687
						col.SetRed   (i / 2 + 127);
719
								( cAccTest == pAccScan[ nX ] ) )
688
						col.SetGreen (i / 2 + 127);
720
							{
689
						col.SetBlue  (i / 2 + 127);
721
								pDis->SetPixel( nY, nX, aDisWhite );
722
							}
723
							else
724
							{
725
								pDis->SetPixel( nY, nX, aDisBlack );
726
								++nBlackCount;
727
							}
728
						}
729
					}
690
					}
730
				}
691
					else
731
				else
732
				{	
733
					for( long nY = nTop; nY < nBottom; nY++ )
734
					{
692
					{
735
						for( long nX = nCurLeft; nX < nCurRight; nX++ )
693
#define GT_ZERO(c) ((unsigned char)(((c) >= 0) ? (c) : 0))
736
						{
694
						col.SetRed   (GT_ZERO (( col.GetRed ())   * 0.7));
737
							if( ( aMskWhite == pMsk->GetPixel( nY, nX ) ) || 
695
						col.SetGreen (GT_ZERO (( col.GetGreen ()) * 0.7));
738
								( aAccWhite == pAcc->GetPixel( nY, nX ) ) )
696
						col.SetBlue  (GT_ZERO (( col.GetBlue ())  * 0.7));
739
							{
697
#undef GT_ZERO
740
								pDis->SetPixel( nY, nX, aDisWhite );
741
							}
742
							else
743
							{
744
								pDis->SetPixel( nY, nX, aDisBlack );
745
								++nBlackCount;
746
							}
747
						}
748
					}
698
					}
699
					pDis->SetPixel( nY, nX, col );
749
				}
700
				}
701
			}
702
		}
703
	}
704
	else
705
	{
706
		BitmapReadAccess *pMsk = aBitmap.AcquireReadAccess();
750
707
751
				if( nBlackCount < nBlackThreshold )
708
		const Color aWhite( COL_WHITE );
752
				{
709
		const Color aBlack( COL_BLACK );
753
					// emergency solution if paint bitmap is mostly white
710
		const BitmapColor aAccWhite( pAcc->GetBestMatchingColor( aWhite ) );
754
					for( long nY = nTop; nY < nBottom; nY++ )
711
		const BitmapColor aMskWhite( pMsk->GetBestMatchingColor( aWhite ) );
755
					{
712
		const BitmapColor aDisWhite( pDis->GetBestMatchingColor( aWhite ) );
756
						for( long nX = nCurLeft; nX < nCurRight; nX++ )
713
		const BitmapColor aDisBlack( pDis->GetBestMatchingColor( aBlack ) );
757
						{
758
							if( aMskWhite == pMsk->GetPixel( nY, nX ) )
759
								pDis->SetPixel( nY, nX, aDisWhite );
760
							else
761
								pDis->SetPixel( nY, nX, aDisBlack );
762
						}
763
					}
764
				}
765
714
766
				nCurLeft += maSize.Width();
715
		for( long nY = nTop; nY < nBottom; nY++ )
767
				nCurRight += maSize.Width();
716
		{
717
			for( long nX = nLeft; nX < nRight; nX++ )
718
			{
719
				if( ( aMskWhite == pMsk->GetPixel( nY, nX ) ) &&
720
				    ( aAccWhite != pAcc->GetPixel( nY, nX ) ) )
721
					pDis->SetPixel( nY, nX, aDisBlack );
722
				else
723
					pDis->SetPixel( nY, nX, aDisWhite );
768
			}
724
			}
769
		}
725
		}
770
726
		aBitmap.ReleaseAccess( pMsk );
771
		aBmp.ReleaseAccess( pAcc );
772
		aMask.ReleaseAccess( pMsk );
773
		maDisabledBmp.ReleaseAccess( pDis );
774
	}
727
	}
728
729
	aSrcBitmap.ReleaseAccess( pAcc );
730
	aBitmap.ReleaseAccess( pDis );
731
732
	if( maBmpEx.IsAlpha() )
733
			maDisabledBmpEx = BitmapEx( aBitmap, maBmpEx.GetAlpha() );
734
	else
735
			maDisabledBmpEx = BitmapEx( aBitmap );
775
}
736
}

Return to issue 35555