bitmapex.cxx (6d53c851) bitmapex.cxx (f2e5373e)
1/**************************************************************
1/**************************************************************
2 *
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
19 *
20 *************************************************************/
21
20 *************************************************************/
21
22
23
22// MARKER(update_precomp.py): autogen include statement, do not remove
23#include "precompiled_vcl.hxx"
24
25#include <ctype.h>
26#include <rtl/crc.h>
27#include <tools/stream.hxx>
28#include <tools/debug.hxx>
29#include <tools/rc.h>

--- 42 unchanged lines hidden (view full) ---

72 aBitmapSize = aSize;
73 if( rBitmapEx.IsAlpha() )
74 {
75 bAlpha = sal_True;
76 aMask = AlphaMask( aSize ).ImplGetBitmap();
77 }
78 else if( rBitmapEx.IsTransparent() )
79 aMask = Bitmap( aSize, rBitmapEx.aMask.GetBitCount() );
24// MARKER(update_precomp.py): autogen include statement, do not remove
25#include "precompiled_vcl.hxx"
26
27#include <ctype.h>
28#include <rtl/crc.h>
29#include <tools/stream.hxx>
30#include <tools/debug.hxx>
31#include <tools/rc.h>

--- 42 unchanged lines hidden (view full) ---

74 aBitmapSize = aSize;
75 if( rBitmapEx.IsAlpha() )
76 {
77 bAlpha = sal_True;
78 aMask = AlphaMask( aSize ).ImplGetBitmap();
79 }
80 else if( rBitmapEx.IsTransparent() )
81 aMask = Bitmap( aSize, rBitmapEx.aMask.GetBitCount() );
80
82
81 Rectangle aDestRect( Point( 0, 0 ), aSize );
82 Rectangle aSrcRect( aSrc, aSize );
83 CopyPixel( aDestRect, aSrcRect, &rBitmapEx );
84}
85
86// ------------------------------------------------------------------
87
88BitmapEx::BitmapEx( const ResId& rResId ) :
89 eTransparent( TRANSPARENT_NONE ),
90 bAlpha ( sal_False )
91{
92 static ImplImageTreeSingletonRef aImageTree;
93 ResMgr* pResMgr = NULL;
94
95 ResMgr::GetResourceSkipHeader( rResId.SetRT( RSC_BITMAP ), &pResMgr );
96 pResMgr->ReadLong();
97 pResMgr->ReadLong();
83 Rectangle aDestRect( Point( 0, 0 ), aSize );
84 Rectangle aSrcRect( aSrc, aSize );
85 CopyPixel( aDestRect, aSrcRect, &rBitmapEx );
86}
87
88// ------------------------------------------------------------------
89
90BitmapEx::BitmapEx( const ResId& rResId ) :
91 eTransparent( TRANSPARENT_NONE ),
92 bAlpha ( sal_False )
93{
94 static ImplImageTreeSingletonRef aImageTree;
95 ResMgr* pResMgr = NULL;
96
97 ResMgr::GetResourceSkipHeader( rResId.SetRT( RSC_BITMAP ), &pResMgr );
98 pResMgr->ReadLong();
99 pResMgr->ReadLong();
98
100
99 const String aFileName( pResMgr->ReadString() );
100 ::rtl::OUString aCurrentSymbolsStyle = Application::GetSettings().GetStyleSettings().GetCurrentSymbolsStyleName();
101 const String aFileName( pResMgr->ReadString() );
102 ::rtl::OUString aCurrentSymbolsStyle = Application::GetSettings().GetStyleSettings().GetCurrentSymbolsStyleName();
101
103
102 if( !aImageTree->loadImage( aFileName, aCurrentSymbolsStyle, *this ) )
103 {
104 if( !aImageTree->loadImage( aFileName, aCurrentSymbolsStyle, *this ) )
105 {
104#ifdef DBG_UTIL
106#ifdef DBG_UTIL
105 ByteString aErrorStr( "BitmapEx::BitmapEx( const ResId& rResId ): could not load image <" );
106 DBG_ERROR( ( ( aErrorStr += ByteString( aFileName, RTL_TEXTENCODING_ASCII_US ) ) += '>' ).GetBuffer() );
107#endif
108 }
109}
110
111// ------------------------------------------------------------------
112

--- 9 unchanged lines hidden (view full) ---

122
123BitmapEx::BitmapEx( const Bitmap& rBmp, const Bitmap& rMask ) :
124 aBitmap ( rBmp ),
125 aMask ( rMask ),
126 aBitmapSize ( aBitmap.GetSizePixel() ),
127 eTransparent ( !rMask ? TRANSPARENT_NONE : TRANSPARENT_BITMAP ),
128 bAlpha ( sal_False )
129{
107 ByteString aErrorStr( "BitmapEx::BitmapEx( const ResId& rResId ): could not load image <" );
108 DBG_ERROR( ( ( aErrorStr += ByteString( aFileName, RTL_TEXTENCODING_ASCII_US ) ) += '>' ).GetBuffer() );
109#endif
110 }
111}
112
113// ------------------------------------------------------------------
114

--- 9 unchanged lines hidden (view full) ---

124
125BitmapEx::BitmapEx( const Bitmap& rBmp, const Bitmap& rMask ) :
126 aBitmap ( rBmp ),
127 aMask ( rMask ),
128 aBitmapSize ( aBitmap.GetSizePixel() ),
129 eTransparent ( !rMask ? TRANSPARENT_NONE : TRANSPARENT_BITMAP ),
130 bAlpha ( sal_False )
131{
130 if(!!aBitmap && !!aMask && aBitmap.GetSizePixel() != aMask.GetSizePixel())
131 {
132 OSL_ENSURE(false, "Mask size differs from Bitmap size, corrected Mask (!)");
133 aMask.Scale(aBitmap.GetSizePixel());
134 }
132 if(!!aBitmap && !!aMask && aBitmap.GetSizePixel() != aMask.GetSizePixel())
133 {
134 OSL_ENSURE(false, "Mask size differs from Bitmap size, corrected Mask (!)");
135 aMask.Scale(aBitmap.GetSizePixel());
136 }
135
137
136 // #105489# Ensure a mask is exactly one bit deep
137 if( !!aMask && aMask.GetBitCount() != 1 )
138 {
139 OSL_TRACE("BitmapEx: forced mask to monochrome");
140 aMask.ImplMakeMono( 255 );
141 }
138 // #105489# Ensure a mask is exactly one bit deep
139 if( !!aMask && aMask.GetBitCount() != 1 )
140 {
141 OSL_TRACE("BitmapEx: forced mask to monochrome");
142 aMask.ImplMakeMono( 255 );
143 }
142}
143
144// ------------------------------------------------------------------
145
146BitmapEx::BitmapEx( const Bitmap& rBmp, const AlphaMask& rAlphaMask ) :
147 aBitmap ( rBmp ),
148 aMask ( rAlphaMask.ImplGetBitmap() ),
149 aBitmapSize ( aBitmap.GetSizePixel() ),
150 eTransparent ( !rAlphaMask ? TRANSPARENT_NONE : TRANSPARENT_BITMAP ),
151 bAlpha ( !rAlphaMask ? sal_False : sal_True )
152{
144}
145
146// ------------------------------------------------------------------
147
148BitmapEx::BitmapEx( const Bitmap& rBmp, const AlphaMask& rAlphaMask ) :
149 aBitmap ( rBmp ),
150 aMask ( rAlphaMask.ImplGetBitmap() ),
151 aBitmapSize ( aBitmap.GetSizePixel() ),
152 eTransparent ( !rAlphaMask ? TRANSPARENT_NONE : TRANSPARENT_BITMAP ),
153 bAlpha ( !rAlphaMask ? sal_False : sal_True )
154{
153 if(!!aBitmap && !!aMask && aBitmap.GetSizePixel() != aMask.GetSizePixel())
154 {
155 OSL_ENSURE(false, "Alpha size differs from Bitmap size, corrected Mask (!)");
156 aMask.Scale(rBmp.GetSizePixel());
157 }
155 if(!!aBitmap && !!aMask && aBitmap.GetSizePixel() != aMask.GetSizePixel())
156 {
157 OSL_ENSURE(false, "Alpha size differs from Bitmap size, corrected Mask (!)");
158 aMask.Scale(rBmp.GetSizePixel());
159 }
158
160
159 // #i75531# the workaround below can go when
160 // X11SalGraphics::drawAlphaBitmap()'s render acceleration
161 // can handle the bitmap depth mismatch directly
162 if( aBitmap.GetBitCount() < aMask.GetBitCount() )
163 aBitmap.Convert( BMP_CONVERSION_24BIT );
161 // #i75531# the workaround below can go when
162 // X11SalGraphics::drawAlphaBitmap()'s render acceleration
163 // can handle the bitmap depth mismatch directly
164 if( aBitmap.GetBitCount() < aMask.GetBitCount() )
165 aBitmap.Convert( BMP_CONVERSION_24BIT );
164}
165
166// ------------------------------------------------------------------
167
168BitmapEx::BitmapEx( const Bitmap& rBmp, const Color& rTransparentColor ) :
169 aBitmap ( rBmp ),
170 aBitmapSize ( aBitmap.GetSizePixel() ),
171 aTransparentColor ( rTransparentColor ),
172 eTransparent ( TRANSPARENT_BITMAP ),
173 bAlpha ( sal_False )
174{
175 aMask = aBitmap.CreateMask( aTransparentColor );
176
166}
167
168// ------------------------------------------------------------------
169
170BitmapEx::BitmapEx( const Bitmap& rBmp, const Color& rTransparentColor ) :
171 aBitmap ( rBmp ),
172 aBitmapSize ( aBitmap.GetSizePixel() ),
173 aTransparentColor ( rTransparentColor ),
174 eTransparent ( TRANSPARENT_BITMAP ),
175 bAlpha ( sal_False )
176{
177 aMask = aBitmap.CreateMask( aTransparentColor );
178
177 DBG_ASSERT( rBmp.GetSizePixel() == aMask.GetSizePixel(),
178 "BitmapEx::BitmapEx(): size mismatch for bitmap and alpha mask." );
179 DBG_ASSERT( rBmp.GetSizePixel() == aMask.GetSizePixel(),
180 "BitmapEx::BitmapEx(): size mismatch for bitmap and alpha mask." );
179}
180
181// ------------------------------------------------------------------
182
183BitmapEx::~BitmapEx()
184{
185}
186

--- 110 unchanged lines hidden (view full) ---

297 return aRetBmp;
298}
299
300// ------------------------------------------------------------------
301
302BitmapEx BitmapEx::GetColorTransformedBitmapEx( BmpColorMode eColorMode ) const
303{
304 BitmapEx aRet;
181}
182
183// ------------------------------------------------------------------
184
185BitmapEx::~BitmapEx()
186{
187}
188

--- 110 unchanged lines hidden (view full) ---

299 return aRetBmp;
300}
301
302// ------------------------------------------------------------------
303
304BitmapEx BitmapEx::GetColorTransformedBitmapEx( BmpColorMode eColorMode ) const
305{
306 BitmapEx aRet;
305
307
306 if( BMP_COLOR_HIGHCONTRAST == eColorMode )
307 {
308 aRet = *this;
309 aRet.aBitmap = aBitmap.GetColorTransformedBitmap( eColorMode );
310 }
311 else if( BMP_COLOR_MONOCHROME_BLACK == eColorMode ||
312 BMP_COLOR_MONOCHROME_WHITE == eColorMode )
313 {
314 aRet = *this;
315 aRet.aBitmap = aRet.aBitmap.GetColorTransformedBitmap( eColorMode );
308 if( BMP_COLOR_HIGHCONTRAST == eColorMode )
309 {
310 aRet = *this;
311 aRet.aBitmap = aBitmap.GetColorTransformedBitmap( eColorMode );
312 }
313 else if( BMP_COLOR_MONOCHROME_BLACK == eColorMode ||
314 BMP_COLOR_MONOCHROME_WHITE == eColorMode )
315 {
316 aRet = *this;
317 aRet.aBitmap = aRet.aBitmap.GetColorTransformedBitmap( eColorMode );
316
318
317 if( !aRet.aMask.IsEmpty() )
318 {
319 aRet.aMask.CombineSimple( aRet.aBitmap, BMP_COMBINE_OR );
320 aRet.aBitmap.Erase( ( BMP_COLOR_MONOCHROME_BLACK == eColorMode ) ? COL_BLACK : COL_WHITE );
321
319 if( !aRet.aMask.IsEmpty() )
320 {
321 aRet.aMask.CombineSimple( aRet.aBitmap, BMP_COMBINE_OR );
322 aRet.aBitmap.Erase( ( BMP_COLOR_MONOCHROME_BLACK == eColorMode ) ? COL_BLACK : COL_WHITE );
323
322 DBG_ASSERT( aRet.aBitmap.GetSizePixel() == aRet.aMask.GetSizePixel(),
323 "BitmapEx::GetColorTransformedBitmapEx(): size mismatch for bitmap and alpha mask." );
324 DBG_ASSERT( aRet.aBitmap.GetSizePixel() == aRet.aMask.GetSizePixel(),
325 "BitmapEx::GetColorTransformedBitmapEx(): size mismatch for bitmap and alpha mask." );
324 }
325 }
326
327 return aRet;
328}
329
330// ------------------------------------------------------------------
331

--- 54 unchanged lines hidden (view full) ---

386
387 return nCrc;
388}
389
390// ------------------------------------------------------------------
391
392void BitmapEx::SetSizePixel( const Size& rNewSize, sal_uInt32 nScaleFlag )
393{
326 }
327 }
328
329 return aRet;
330}
331
332// ------------------------------------------------------------------
333

--- 54 unchanged lines hidden (view full) ---

388
389 return nCrc;
390}
391
392// ------------------------------------------------------------------
393
394void BitmapEx::SetSizePixel( const Size& rNewSize, sal_uInt32 nScaleFlag )
395{
394 if(GetSizePixel() != rNewSize)
395 {
396 Scale( rNewSize, nScaleFlag );
397 }
396 if(GetSizePixel() != rNewSize)
397 {
398 Scale( rNewSize, nScaleFlag );
399 }
398}
399
400// ------------------------------------------------------------------
401
402sal_Bool BitmapEx::Invert()
403{
404 sal_Bool bRet = sal_False;
405

--- 31 unchanged lines hidden (view full) ---

437{
438 sal_Bool bRet = sal_False;
439
440 if( !!aBitmap )
441 {
442 bRet = aBitmap.Scale( rScaleX, rScaleY, nScaleFlag );
443
444 if( bRet && ( eTransparent == TRANSPARENT_BITMAP ) && !!aMask )
400}
401
402// ------------------------------------------------------------------
403
404sal_Bool BitmapEx::Invert()
405{
406 sal_Bool bRet = sal_False;
407

--- 31 unchanged lines hidden (view full) ---

439{
440 sal_Bool bRet = sal_False;
441
442 if( !!aBitmap )
443 {
444 bRet = aBitmap.Scale( rScaleX, rScaleY, nScaleFlag );
445
446 if( bRet && ( eTransparent == TRANSPARENT_BITMAP ) && !!aMask )
445 {
447 {
446 aMask.Scale( rScaleX, rScaleY, nScaleFlag );
448 aMask.Scale( rScaleX, rScaleY, nScaleFlag );
447 }
449 }
448
449 aBitmapSize = aBitmap.GetSizePixel();
450
450
451 aBitmapSize = aBitmap.GetSizePixel();
452
451 DBG_ASSERT( !aMask || aBitmap.GetSizePixel() == aMask.GetSizePixel(),
452 "BitmapEx::Scale(): size mismatch for bitmap and alpha mask." );
453 DBG_ASSERT( !aMask || aBitmap.GetSizePixel() == aMask.GetSizePixel(),
454 "BitmapEx::Scale(): size mismatch for bitmap and alpha mask." );
453 }
454
455 return bRet;
456}
457
458// ------------------------------------------------------------------------
459
460sal_Bool BitmapEx::Scale( const Size& rNewSize, sal_uInt32 nScaleFlag )

--- 46 unchanged lines hidden (view full) ---

507 bRet = aBitmap.Rotate( nAngle10, rFillColor );
508
509 if( bRet && ( eTransparent == TRANSPARENT_BITMAP ) && !!aMask )
510 aMask.Rotate( nAngle10, COL_WHITE );
511 }
512
513 aBitmapSize = aBitmap.GetSizePixel();
514
455 }
456
457 return bRet;
458}
459
460// ------------------------------------------------------------------------
461
462sal_Bool BitmapEx::Scale( const Size& rNewSize, sal_uInt32 nScaleFlag )

--- 46 unchanged lines hidden (view full) ---

509 bRet = aBitmap.Rotate( nAngle10, rFillColor );
510
511 if( bRet && ( eTransparent == TRANSPARENT_BITMAP ) && !!aMask )
512 aMask.Rotate( nAngle10, COL_WHITE );
513 }
514
515 aBitmapSize = aBitmap.GetSizePixel();
516
515 DBG_ASSERT( !aMask || aBitmap.GetSizePixel() == aMask.GetSizePixel(),
516 "BitmapEx::Rotate(): size mismatch for bitmap and alpha mask." );
517 DBG_ASSERT( !aMask || aBitmap.GetSizePixel() == aMask.GetSizePixel(),
518 "BitmapEx::Rotate(): size mismatch for bitmap and alpha mask." );
517 }
518
519 return bRet;
520}
521
522// ------------------------------------------------------------------
523
524sal_Bool BitmapEx::Crop( const Rectangle& rRectPixel )

--- 4 unchanged lines hidden (view full) ---

529 {
530 bRet = aBitmap.Crop( rRectPixel );
531
532 if( bRet && ( eTransparent == TRANSPARENT_BITMAP ) && !!aMask )
533 aMask.Crop( rRectPixel );
534
535 aBitmapSize = aBitmap.GetSizePixel();
536
519 }
520
521 return bRet;
522}
523
524// ------------------------------------------------------------------
525
526sal_Bool BitmapEx::Crop( const Rectangle& rRectPixel )

--- 4 unchanged lines hidden (view full) ---

531 {
532 bRet = aBitmap.Crop( rRectPixel );
533
534 if( bRet && ( eTransparent == TRANSPARENT_BITMAP ) && !!aMask )
535 aMask.Crop( rRectPixel );
536
537 aBitmapSize = aBitmap.GetSizePixel();
538
537 DBG_ASSERT( !aMask || aBitmap.GetSizePixel() == aMask.GetSizePixel(),
538 "BitmapEx::Crop(): size mismatch for bitmap and alpha mask." );
539 DBG_ASSERT( !aMask || aBitmap.GetSizePixel() == aMask.GetSizePixel(),
540 "BitmapEx::Crop(): size mismatch for bitmap and alpha mask." );
539 }
540
541 return bRet;
542}
543
544// ------------------------------------------------------------------
545
546sal_Bool BitmapEx::Convert( BmpConversion eConversion )

--- 21 unchanged lines hidden (view full) ---

568 if( bRet && ( eTransparent == TRANSPARENT_BITMAP ) && !!aMask )
569 {
570 Color aColor( bExpandTransparent ? COL_WHITE : COL_BLACK );
571 aMask.Expand( nDX, nDY, &aColor );
572 }
573
574 aBitmapSize = aBitmap.GetSizePixel();
575
541 }
542
543 return bRet;
544}
545
546// ------------------------------------------------------------------
547
548sal_Bool BitmapEx::Convert( BmpConversion eConversion )

--- 21 unchanged lines hidden (view full) ---

570 if( bRet && ( eTransparent == TRANSPARENT_BITMAP ) && !!aMask )
571 {
572 Color aColor( bExpandTransparent ? COL_WHITE : COL_BLACK );
573 aMask.Expand( nDX, nDY, &aColor );
574 }
575
576 aBitmapSize = aBitmap.GetSizePixel();
577
576 DBG_ASSERT( !aMask || aBitmap.GetSizePixel() == aMask.GetSizePixel(),
577 "BitmapEx::Expand(): size mismatch for bitmap and alpha mask." );
578 DBG_ASSERT( !aMask || aBitmap.GetSizePixel() == aMask.GetSizePixel(),
579 "BitmapEx::Expand(): size mismatch for bitmap and alpha mask." );
578 }
579
580 return bRet;
581}
582
583// ------------------------------------------------------------------
584
585sal_Bool BitmapEx::CopyPixel( const Rectangle& rRectDst, const Rectangle& rRectSrc,

--- 17 unchanged lines hidden (view full) ---

603 {
604 bRet = aBitmap.CopyPixel( rRectDst, rRectSrc, &pBmpExSrc->aBitmap );
605
606 if( bRet )
607 {
608 if( pBmpExSrc->IsAlpha() )
609 {
610 if( IsAlpha() )
580 }
581
582 return bRet;
583}
584
585// ------------------------------------------------------------------
586
587sal_Bool BitmapEx::CopyPixel( const Rectangle& rRectDst, const Rectangle& rRectSrc,

--- 17 unchanged lines hidden (view full) ---

605 {
606 bRet = aBitmap.CopyPixel( rRectDst, rRectSrc, &pBmpExSrc->aBitmap );
607
608 if( bRet )
609 {
610 if( pBmpExSrc->IsAlpha() )
611 {
612 if( IsAlpha() )
611 // cast to use the optimized AlphaMask::CopyPixel
613 // cast to use the optimized AlphaMask::CopyPixel
612 ((AlphaMask*) &aMask)->CopyPixel( rRectDst, rRectSrc, (AlphaMask*)&pBmpExSrc->aMask );
613 else if( IsTransparent() )
614 {
615 AlphaMask* pAlpha = new AlphaMask( aMask );
616
617 aMask = pAlpha->ImplGetBitmap();
618 delete pAlpha;
619 bAlpha = sal_True;

--- 23 unchanged lines hidden (view full) ---

643 else
644 {
645 aMask = Bitmap( GetSizePixel(), 1 );
646 aMask.Erase( Color( COL_BLACK ) );
647 eTransparent = TRANSPARENT_BITMAP;
648 aMask.CopyPixel( rRectDst, rRectSrc, &pBmpExSrc->aMask );
649 }
650 }
614 ((AlphaMask*) &aMask)->CopyPixel( rRectDst, rRectSrc, (AlphaMask*)&pBmpExSrc->aMask );
615 else if( IsTransparent() )
616 {
617 AlphaMask* pAlpha = new AlphaMask( aMask );
618
619 aMask = pAlpha->ImplGetBitmap();
620 delete pAlpha;
621 bAlpha = sal_True;

--- 23 unchanged lines hidden (view full) ---

645 else
646 {
647 aMask = Bitmap( GetSizePixel(), 1 );
648 aMask.Erase( Color( COL_BLACK ) );
649 eTransparent = TRANSPARENT_BITMAP;
650 aMask.CopyPixel( rRectDst, rRectSrc, &pBmpExSrc->aMask );
651 }
652 }
651 else if( IsAlpha() )
652 {
653 sal_uInt8 cBlack = 0;
654 const AlphaMask aAlphaSrc( pBmpExSrc->GetSizePixel(), &cBlack );
653 else if( IsAlpha() )
654 {
655 sal_uInt8 cBlack = 0;
656 const AlphaMask aAlphaSrc( pBmpExSrc->GetSizePixel(), &cBlack );
655
657
656 aMask.CopyPixel( rRectDst, rRectSrc, &aAlphaSrc.ImplGetBitmap() );
657 }
658 else if( IsTransparent() )
659 {
660 Bitmap aMaskSrc( pBmpExSrc->GetSizePixel(), 1 );
658 aMask.CopyPixel( rRectDst, rRectSrc, &aAlphaSrc.ImplGetBitmap() );
659 }
660 else if( IsTransparent() )
661 {
662 Bitmap aMaskSrc( pBmpExSrc->GetSizePixel(), 1 );
661
663
662 aMaskSrc.Erase( Color( COL_BLACK ) );
663 aMask.CopyPixel( rRectDst, rRectSrc, &aMaskSrc );
664 }
664 aMaskSrc.Erase( Color( COL_BLACK ) );
665 aMask.CopyPixel( rRectDst, rRectSrc, &aMaskSrc );
666 }
665 }
666 }
667 }
668
669 return bRet;
670}
671
672// ------------------------------------------------------------------
673
674sal_Bool BitmapEx::Erase( const Color& rFillColor )
675{
676 sal_Bool bRet = sal_False;
677
678 if( !!aBitmap )
679 {
680 bRet = aBitmap.Erase( rFillColor );
681
682 if( bRet && ( eTransparent == TRANSPARENT_BITMAP ) && !!aMask )
683 {
667 }
668 }
669 }
670
671 return bRet;
672}
673
674// ------------------------------------------------------------------
675
676sal_Bool BitmapEx::Erase( const Color& rFillColor )
677{
678 sal_Bool bRet = sal_False;
679
680 if( !!aBitmap )
681 {
682 bRet = aBitmap.Erase( rFillColor );
683
684 if( bRet && ( eTransparent == TRANSPARENT_BITMAP ) && !!aMask )
685 {
684 // #104416# Respect transparency on fill color
685 if( rFillColor.GetTransparency() )
686 {
687 const Color aFill( rFillColor.GetTransparency(), rFillColor.GetTransparency(), rFillColor.GetTransparency() );
688 aMask.Erase( aFill );
689 }
690 else
691 {
692 const Color aBlack( COL_BLACK );
693 aMask.Erase( aBlack );
694 }
686 // #104416# Respect transparency on fill color
687 if( rFillColor.GetTransparency() )
688 {
689 const Color aFill( rFillColor.GetTransparency(), rFillColor.GetTransparency(), rFillColor.GetTransparency() );
690 aMask.Erase( aFill );
691 }
692 else
693 {
694 const Color aBlack( COL_BLACK );
695 aMask.Erase( aBlack );
696 }
695 }
696 }
697
698 return bRet;
699}
700
701// ------------------------------------------------------------------
702

--- 57 unchanged lines hidden (view full) ---

760{
761 pOutDev->DrawBitmapEx( rDestPt, rDestSize, rSrcPtPixel, rSrcSizePixel, *this );
762}
763
764// ------------------------------------------------------------------
765
766sal_uInt8 BitmapEx::GetTransparency(sal_Int32 nX, sal_Int32 nY) const
767{
697 }
698 }
699
700 return bRet;
701}
702
703// ------------------------------------------------------------------
704

--- 57 unchanged lines hidden (view full) ---

762{
763 pOutDev->DrawBitmapEx( rDestPt, rDestSize, rSrcPtPixel, rSrcSizePixel, *this );
764}
765
766// ------------------------------------------------------------------
767
768sal_uInt8 BitmapEx::GetTransparency(sal_Int32 nX, sal_Int32 nY) const
769{
768 sal_uInt8 nTransparency(0xff);
770 sal_uInt8 nTransparency(0xff);
769
771
770 if(!aBitmap.IsEmpty())
771 {
772 if(nX >= 0 && nX < aBitmapSize.Width() && nY >= 0 && nY < aBitmapSize.Height())
773 {
774 switch(eTransparent)
775 {
776 case TRANSPARENT_NONE:
777 {
778 // not transparent, ergo all covered
779 nTransparency = 0x00;
780 break;
781 }
782 case TRANSPARENT_COLOR:
783 {
784 Bitmap aTestBitmap(aBitmap);
785 BitmapReadAccess* pRead = aTestBitmap.AcquireReadAccess();
772 if(!aBitmap.IsEmpty())
773 {
774 if(nX >= 0 && nX < aBitmapSize.Width() && nY >= 0 && nY < aBitmapSize.Height())
775 {
776 switch(eTransparent)
777 {
778 case TRANSPARENT_NONE:
779 {
780 // not transparent, ergo all covered
781 nTransparency = 0x00;
782 break;
783 }
784 case TRANSPARENT_COLOR:
785 {
786 Bitmap aTestBitmap(aBitmap);
787 BitmapReadAccess* pRead = aTestBitmap.AcquireReadAccess();
786
788
787 if(pRead)
788 {
789 const Color aColor = pRead->GetColor(nY, nX);
789 if(pRead)
790 {
791 const Color aColor = pRead->GetColor(nY, nX);
790
792
791 // if color is not equal to TransparentColor, we are not transparent
792 if(aColor != aTransparentColor)
793 {
794 nTransparency = 0x00;
795 }
793 // if color is not equal to TransparentColor, we are not transparent
794 if(aColor != aTransparentColor)
795 {
796 nTransparency = 0x00;
797 }
796
798
797 aTestBitmap.ReleaseAccess(pRead);
798 }
799 break;
800 }
801 case TRANSPARENT_BITMAP:
802 {
803 if(!aMask.IsEmpty())
804 {
805 Bitmap aTestBitmap(aMask);
806 BitmapReadAccess* pRead = aTestBitmap.AcquireReadAccess();
799 aTestBitmap.ReleaseAccess(pRead);
800 }
801 break;
802 }
803 case TRANSPARENT_BITMAP:
804 {
805 if(!aMask.IsEmpty())
806 {
807 Bitmap aTestBitmap(aMask);
808 BitmapReadAccess* pRead = aTestBitmap.AcquireReadAccess();
807
809
808 if(pRead)
809 {
810 const BitmapColor aBitmapColor(pRead->GetPixel(nY, nX));
810 if(pRead)
811 {
812 const BitmapColor aBitmapColor(pRead->GetPixel(nY, nX));
811
813
812 if(bAlpha)
813 {
814 nTransparency = aBitmapColor.GetIndex();
815 }
816 else
817 {
818 if(0x00 == aBitmapColor.GetIndex())
819 {
820 nTransparency = 0x00;
821 }
822 }
814 if(bAlpha)
815 {
816 nTransparency = aBitmapColor.GetIndex();
817 }
818 else
819 {
820 if(0x00 == aBitmapColor.GetIndex())
821 {
822 nTransparency = 0x00;
823 }
824 }
823
825
824 aTestBitmap.ReleaseAccess(pRead);
825 }
826 }
827 break;
828 }
829 }
830 }
831 }
826 aTestBitmap.ReleaseAccess(pRead);
827 }
828 }
829 break;
830 }
831 }
832 }
833 }
832
834
833 return nTransparency;
835 return nTransparency;
834}
835
836// ------------------------------------------------------------------
837
838namespace
839{
836}
837
838// ------------------------------------------------------------------
839
840namespace
841{
840 Bitmap impTransformBitmap(
841 const Bitmap& rSource,
842 const Size aDestinationSize,
843 const basegfx::B2DHomMatrix& rTransform,
844 bool bSmooth)
845 {
846 Bitmap aDestination(aDestinationSize, 24);
847 BitmapWriteAccess* pWrite = aDestination.AcquireWriteAccess();
842 Bitmap impTransformBitmap(
843 const Bitmap& rSource,
844 const Size aDestinationSize,
845 const basegfx::B2DHomMatrix& rTransform,
846 bool bSmooth)
847 {
848 Bitmap aDestination(aDestinationSize, 24);
849 BitmapWriteAccess* pWrite = aDestination.AcquireWriteAccess();
848
850
849 if(pWrite)
850 {
851 //const Size aContentSizePixel(rSource.GetSizePixel());
852 BitmapReadAccess* pRead = (const_cast< Bitmap& >(rSource)).AcquireReadAccess();
851 if(pWrite)
852 {
853 //const Size aContentSizePixel(rSource.GetSizePixel());
854 BitmapReadAccess* pRead = (const_cast< Bitmap& >(rSource)).AcquireReadAccess();
853
855
854 if(pRead)
855 {
856 const Size aDestinationSizePixel(aDestination.GetSizePixel());
857 const BitmapColor aOutside(BitmapColor(0xff, 0xff, 0xff));
856 if(pRead)
857 {
858 const Size aDestinationSizePixel(aDestination.GetSizePixel());
859 const BitmapColor aOutside(BitmapColor(0xff, 0xff, 0xff));
858
860
859 for(sal_Int32 y(0L); y < aDestinationSizePixel.getHeight(); y++)
860 {
861 for(sal_Int32 x(0L); x < aDestinationSizePixel.getWidth(); x++)
862 {
863 const basegfx::B2DPoint aSourceCoor(rTransform * basegfx::B2DPoint(x, y));
861 for(sal_Int32 y(0L); y < aDestinationSizePixel.getHeight(); y++)
862 {
863 for(sal_Int32 x(0L); x < aDestinationSizePixel.getWidth(); x++)
864 {
865 const basegfx::B2DPoint aSourceCoor(rTransform * basegfx::B2DPoint(x, y));
864
866
865 if(bSmooth)
866 {
867 pWrite->SetPixel(
868 y,
869 x,
870 pRead->GetInterpolatedColorWithFallback(
871 aSourceCoor.getY(),
872 aSourceCoor.getX(),
873 aOutside));
874 }
875 else
876 {
877 // this version does the correct <= 0.0 checks, so no need
878 // to do the static_cast< sal_Int32 > self and make an error
879 pWrite->SetPixel(
880 y,
881 x,
882 pRead->GetColorWithFallback(
883 aSourceCoor.getY(),
884 aSourceCoor.getX(),
885 aOutside));
886 }
887 }
888 }
867 if(bSmooth)
868 {
869 pWrite->SetPixel(
870 y,
871 x,
872 pRead->GetInterpolatedColorWithFallback(
873 aSourceCoor.getY(),
874 aSourceCoor.getX(),
875 aOutside));
876 }
877 else
878 {
879 // this version does the correct <= 0.0 checks, so no need
880 // to do the static_cast< sal_Int32 > self and make an error
881 pWrite->SetPixel(
882 y,
883 x,
884 pRead->GetColorWithFallback(
885 aSourceCoor.getY(),
886 aSourceCoor.getX(),
887 aOutside));
888 }
889 }
890 }
889
891
890 delete pRead;
891 }
892 delete pRead;
893 }
892
894
893 delete pWrite;
894 }
895 delete pWrite;
896 }
895
897
896 rSource.AdaptBitCount(aDestination);
898 rSource.AdaptBitCount(aDestination);
897
899
898 return aDestination;
899 }
900 return aDestination;
901 }
900} // end of anonymous namespace
901
902BitmapEx BitmapEx::TransformBitmapEx(
902} // end of anonymous namespace
903
904BitmapEx BitmapEx::TransformBitmapEx(
903 double fWidth,
904 double fHeight,
905 const basegfx::B2DHomMatrix& rTransformation,
906 bool bSmooth) const
905 double fWidth,
906 double fHeight,
907 const basegfx::B2DHomMatrix& rTransformation,
908 bool bSmooth) const
907{
909{
908 if(fWidth <= 1 || fHeight <= 1)
909 return BitmapEx();
910 if(fWidth <= 1 || fHeight <= 1)
911 return BitmapEx();
910
912
911 // force destination to 24 bit, we want to smooth output
912 const Size aDestinationSize(basegfx::fround(fWidth), basegfx::fround(fHeight));
913 const Bitmap aDestination(impTransformBitmap(GetBitmap(), aDestinationSize, rTransformation, bSmooth));
913 // force destination to 24 bit, we want to smooth output
914 const Size aDestinationSize(basegfx::fround(fWidth), basegfx::fround(fHeight));
915 const Bitmap aDestination(impTransformBitmap(GetBitmap(), aDestinationSize, rTransformation, bSmooth));
914
916
915 // create mask
916 if(IsTransparent())
917 {
918 if(IsAlpha())
919 {
920 const Bitmap aAlpha(impTransformBitmap(GetAlpha().GetBitmap(), aDestinationSize, rTransformation, bSmooth));
921 return BitmapEx(aDestination, AlphaMask(aAlpha));
922 }
923 else
924 {
925 const Bitmap aMask(impTransformBitmap(GetMask(), aDestinationSize, rTransformation, false));
926 return BitmapEx(aDestination, aMask);
927 }
928 }
929
930 return BitmapEx(aDestination);
917 // create mask
918 if(IsTransparent())
919 {
920 if(IsAlpha())
921 {
922 const Bitmap aAlpha(impTransformBitmap(GetAlpha().GetBitmap(), aDestinationSize, rTransformation, bSmooth));
923 return BitmapEx(aDestination, AlphaMask(aAlpha));
924 }
925 else
926 {
927 const Bitmap aMask(impTransformBitmap(GetMask(), aDestinationSize, rTransformation, false));
928 return BitmapEx(aDestination, aMask);
929 }
930 }
931
932 return BitmapEx(aDestination);
931}
932
933// ------------------------------------------------------------------
934
935BitmapEx BitmapEx::getTransformed(
933}
934
935// ------------------------------------------------------------------
936
937BitmapEx BitmapEx::getTransformed(
936 const basegfx::B2DHomMatrix& rTransformation,
937 const basegfx::B2DRange& rVisibleRange,
938 double fMaximumArea,
939 bool bSmooth) const
938 const basegfx::B2DHomMatrix& rTransformation,
939 const basegfx::B2DRange& rVisibleRange,
940 double fMaximumArea,
941 bool bSmooth) const
940{
942{
941 BitmapEx aRetval;
943 BitmapEx aRetval;
942
944
943 if(IsEmpty())
944 return aRetval;
945 if(IsEmpty())
946 return aRetval;
945
947
946 const sal_uInt32 nSourceWidth(GetSizePixel().Width());
947 const sal_uInt32 nSourceHeight(GetSizePixel().Height());
948 const sal_uInt32 nSourceWidth(GetSizePixel().Width());
949 const sal_uInt32 nSourceHeight(GetSizePixel().Height());
948
950
949 if(!nSourceWidth || !nSourceHeight)
950 return aRetval;
951 if(!nSourceWidth || !nSourceHeight)
952 return aRetval;
951
953
952 // Get aOutlineRange
953 basegfx::B2DRange aOutlineRange(0.0, 0.0, 1.0, 1.0);
954 // Get aOutlineRange
955 basegfx::B2DRange aOutlineRange(0.0, 0.0, 1.0, 1.0);
954
956
955 aOutlineRange.transform(rTransformation);
957 aOutlineRange.transform(rTransformation);
956
958
957 // create visible range from it by moving from relative to absolute
958 basegfx::B2DRange aVisibleRange(rVisibleRange);
959 // create visible range from it by moving from relative to absolute
960 basegfx::B2DRange aVisibleRange(rVisibleRange);
959
961
960 aVisibleRange.transform(
961 basegfx::tools::createScaleTranslateB2DHomMatrix(
962 aOutlineRange.getRange(),
963 aOutlineRange.getMinimum()));
962 aVisibleRange.transform(
963 basegfx::tools::createScaleTranslateB2DHomMatrix(
964 aOutlineRange.getRange(),
965 aOutlineRange.getMinimum()));
964
966
965 // get target size (which is visible range's size)
966 double fWidth(aVisibleRange.getWidth());
967 double fHeight(aVisibleRange.getHeight());
967 // get target size (which is visible range's size)
968 double fWidth(aVisibleRange.getWidth());
969 double fHeight(aVisibleRange.getHeight());
968
970
969 if(fWidth < 1.0 || fHeight < 1.0)
970 {
971 return aRetval;
972 }
971 if(fWidth < 1.0 || fHeight < 1.0)
972 {
973 return aRetval;
974 }
973
975
974 // test if discrete size (pixel) maybe too big and limit it
975 const double fArea(fWidth * fHeight);
976 const bool bNeedToReduce(basegfx::fTools::more(fArea, fMaximumArea));
977 double fReduceFactor(1.0);
976 // test if discrete size (pixel) maybe too big and limit it
977 const double fArea(fWidth * fHeight);
978 const bool bNeedToReduce(basegfx::fTools::more(fArea, fMaximumArea));
979 double fReduceFactor(1.0);
978
980
979 if(bNeedToReduce)
980 {
981 fReduceFactor = sqrt(fMaximumArea / fArea);
982 fWidth *= fReduceFactor;
983 fHeight *= fReduceFactor;
984 }
981 if(bNeedToReduce)
982 {
983 fReduceFactor = sqrt(fMaximumArea / fArea);
984 fWidth *= fReduceFactor;
985 fHeight *= fReduceFactor;
986 }
985
987
986 // Build complete transform from source pixels to target pixels.
987 // Start by scaling from source pixel size to unit coordinates
988 basegfx::B2DHomMatrix aTransform(
989 basegfx::tools::createScaleB2DHomMatrix(
990 1.0 / nSourceWidth,
991 1.0 / nSourceHeight));
988 // Build complete transform from source pixels to target pixels.
989 // Start by scaling from source pixel size to unit coordinates
990 basegfx::B2DHomMatrix aTransform(
991 basegfx::tools::createScaleB2DHomMatrix(
992 1.0 / nSourceWidth,
993 1.0 / nSourceHeight));
992
994
993 // multiply with given transform which leads from unit coordinates inside
994 // aOutlineRange
995 aTransform = rTransformation * aTransform;
996
997 // subtract top-left of absolute VisibleRange
998 aTransform.translate(
999 -aVisibleRange.getMinX(),
1000 -aVisibleRange.getMinY());
995 // multiply with given transform which leads from unit coordinates inside
996 // aOutlineRange
997 aTransform = rTransformation * aTransform;
1001
998
1002 // scale to target pixels (if needed)
1003 if(bNeedToReduce)
1004 {
1005 aTransform.scale(fReduceFactor, fReduceFactor);
1006 }
999 // subtract top-left of absolute VisibleRange
1000 aTransform.translate(
1001 -aVisibleRange.getMinX(),
1002 -aVisibleRange.getMinY());
1007
1003
1008 // invert to get transformation from target pixel coordiates to source pixels
1009 aTransform.invert();
1004 // scale to target pixels (if needed)
1005 if(bNeedToReduce)
1006 {
1007 aTransform.scale(fReduceFactor, fReduceFactor);
1008 }
1010
1009
1011 // create bitmap using source, destination and linear back-transformation
1012 aRetval = TransformBitmapEx(fWidth, fHeight, aTransform, bSmooth);
1010 // invert to get transformation from target pixel coordinates to source pixels
1011 aTransform.invert();
1013
1012
1014 return aRetval;
1013 // create bitmap using source, destination and linear back-transformation
1014 aRetval = TransformBitmapEx(fWidth, fHeight, aTransform, bSmooth);
1015
1016 return aRetval;
1015}
1016
1017// ------------------------------------------------------------------
1018
1019BitmapEx BitmapEx::ModifyBitmapEx(const basegfx::BColorModifierStack& rBColorModifierStack) const
1020{
1017}
1018
1019// ------------------------------------------------------------------
1020
1021BitmapEx BitmapEx::ModifyBitmapEx(const basegfx::BColorModifierStack& rBColorModifierStack) const
1022{
1021 Bitmap aChangedBitmap(GetBitmap());
1022 bool bDone(false);
1023 Bitmap aChangedBitmap(GetBitmap());
1024 bool bDone(false);
1023
1025
1024 for(sal_uInt32 a(rBColorModifierStack.count()); a && !bDone; )
1025 {
1026 const basegfx::BColorModifierSharedPtr& rModifier = rBColorModifierStack.getBColorModifier(--a);
1027 const basegfx::BColorModifier_replace* pReplace = dynamic_cast< const basegfx::BColorModifier_replace* >(rModifier.get());
1026 for(sal_uInt32 a(rBColorModifierStack.count()); a && !bDone; )
1027 {
1028 const basegfx::BColorModifierSharedPtr& rModifier = rBColorModifierStack.getBColorModifier(--a);
1029 const basegfx::BColorModifier_replace* pReplace = dynamic_cast< const basegfx::BColorModifier_replace* >(rModifier.get());
1028
1030
1029 if(pReplace)
1030 {
1031 // complete replace
1032 if(IsTransparent())
1033 {
1034 // clear bitmap with dest color
1035 if(aChangedBitmap.GetBitCount() <= 8)
1036 {
1037 // do NOT use erase; for e.g. 8bit Bitmaps, the nearest color to the given
1038 // erase color is determined and used -> this may be different from what is
1039 // wanted here. Better create a new bitmap with the needed color explicitly
1040 BitmapReadAccess* pReadAccess = aChangedBitmap.AcquireReadAccess();
1041 OSL_ENSURE(pReadAccess, "Got no Bitmap ReadAccess ?!?");
1031 if(pReplace)
1032 {
1033 // complete replace
1034 if(IsTransparent())
1035 {
1036 // clear bitmap with dest color
1037 if(aChangedBitmap.GetBitCount() <= 8)
1038 {
1039 // do NOT use erase; for e.g. 8bit Bitmaps, the nearest color to the given
1040 // erase color is determined and used -> this may be different from what is
1041 // wanted here. Better create a new bitmap with the needed color explicitly
1042 BitmapReadAccess* pReadAccess = aChangedBitmap.AcquireReadAccess();
1043 OSL_ENSURE(pReadAccess, "Got no Bitmap ReadAccess ?!?");
1042
1044
1043 if(pReadAccess)
1044 {
1045 BitmapPalette aNewPalette(pReadAccess->GetPalette());
1046 aNewPalette[0] = BitmapColor(Color(pReplace->getBColor()));
1047 aChangedBitmap = Bitmap(
1048 aChangedBitmap.GetSizePixel(),
1049 aChangedBitmap.GetBitCount(),
1050 &aNewPalette);
1051 delete pReadAccess;
1052 }
1053 }
1054 else
1055 {
1056 aChangedBitmap.Erase(Color(pReplace->getBColor()));
1057 }
1058 }
1059 else
1060 {
1061 // erase bitmap, caller will know to paint direct
1062 aChangedBitmap.SetEmpty();
1063 }
1064
1065 bDone = true;
1066 }
1067 else
1068 {
1069 BitmapWriteAccess* pContent = aChangedBitmap.AcquireWriteAccess();
1045 if(pReadAccess)
1046 {
1047 BitmapPalette aNewPalette(pReadAccess->GetPalette());
1048 aNewPalette[0] = BitmapColor(Color(pReplace->getBColor()));
1049 aChangedBitmap = Bitmap(
1050 aChangedBitmap.GetSizePixel(),
1051 aChangedBitmap.GetBitCount(),
1052 &aNewPalette);
1053 delete pReadAccess;
1054 }
1055 }
1056 else
1057 {
1058 aChangedBitmap.Erase(Color(pReplace->getBColor()));
1059 }
1060 }
1061 else
1062 {
1063 // erase bitmap, caller will know to paint direct
1064 aChangedBitmap.SetEmpty();
1065 }
1070
1066
1071 if(pContent)
1072 {
1073 const double fConvertColor(1.0 / 255.0);
1067 bDone = true;
1068 }
1069 else
1070 {
1071 BitmapWriteAccess* pContent = aChangedBitmap.AcquireWriteAccess();
1074
1072
1075 if(pContent->HasPalette())
1076 {
1077 const sal_uInt16 nCount(pContent->GetPaletteEntryCount());
1073 if(pContent)
1074 {
1075 const double fConvertColor(1.0 / 255.0);
1078
1076
1079 for(sal_uInt16 a(0); a < nCount; a++)
1080 {
1081 const BitmapColor& rCol = pContent->GetPaletteColor(a);
1082 const basegfx::BColor aBSource(
1083 rCol.GetRed() * fConvertColor,
1084 rCol.GetGreen() * fConvertColor,
1085 rCol.GetBlue() * fConvertColor);
1086 const basegfx::BColor aBDest(rModifier->getModifiedColor(aBSource));
1087 pContent->SetPaletteColor(a, BitmapColor(Color(aBDest)));
1088 }
1089 }
1090 else if(BMP_FORMAT_24BIT_TC_BGR == pContent->GetScanlineFormat())
1091 {
1092 for(sal_uInt32 y(0L); y < (sal_uInt32)pContent->Height(); y++)
1093 {
1094 Scanline pScan = pContent->GetScanline(y);
1077 if(pContent->HasPalette())
1078 {
1079 const sal_uInt16 nCount(pContent->GetPaletteEntryCount());
1095
1080
1096 for(sal_uInt32 x(0L); x < (sal_uInt32)pContent->Width(); x++)
1097 {
1098 const basegfx::BColor aBSource(
1099 *(pScan + 2)* fConvertColor,
1100 *(pScan + 1) * fConvertColor,
1101 *pScan * fConvertColor);
1102 const basegfx::BColor aBDest(rModifier->getModifiedColor(aBSource));
1103 *pScan++ = static_cast< sal_uInt8 >(aBDest.getBlue() * 255.0);
1104 *pScan++ = static_cast< sal_uInt8 >(aBDest.getGreen() * 255.0);
1105 *pScan++ = static_cast< sal_uInt8 >(aBDest.getRed() * 255.0);
1106 }
1107 }
1108 }
1109 else if(BMP_FORMAT_24BIT_TC_RGB == pContent->GetScanlineFormat())
1110 {
1111 for(sal_uInt32 y(0L); y < (sal_uInt32)pContent->Height(); y++)
1112 {
1113 Scanline pScan = pContent->GetScanline(y);
1081 for(sal_uInt16 a(0); a < nCount; a++)
1082 {
1083 const BitmapColor& rCol = pContent->GetPaletteColor(a);
1084 const basegfx::BColor aBSource(
1085 rCol.GetRed() * fConvertColor,
1086 rCol.GetGreen() * fConvertColor,
1087 rCol.GetBlue() * fConvertColor);
1088 const basegfx::BColor aBDest(rModifier->getModifiedColor(aBSource));
1089 pContent->SetPaletteColor(a, BitmapColor(Color(aBDest)));
1090 }
1091 }
1092 else if(BMP_FORMAT_24BIT_TC_BGR == pContent->GetScanlineFormat())
1093 {
1094 for(sal_uInt32 y(0L); y < (sal_uInt32)pContent->Height(); y++)
1095 {
1096 Scanline pScan = pContent->GetScanline(y);
1114
1097
1115 for(sal_uInt32 x(0L); x < (sal_uInt32)pContent->Width(); x++)
1116 {
1117 const basegfx::BColor aBSource(
1118 *pScan * fConvertColor,
1119 *(pScan + 1) * fConvertColor,
1120 *(pScan + 2) * fConvertColor);
1121 const basegfx::BColor aBDest(rModifier->getModifiedColor(aBSource));
1122 *pScan++ = static_cast< sal_uInt8 >(aBDest.getRed() * 255.0);
1123 *pScan++ = static_cast< sal_uInt8 >(aBDest.getGreen() * 255.0);
1124 *pScan++ = static_cast< sal_uInt8 >(aBDest.getBlue() * 255.0);
1125 }
1126 }
1127 }
1128 else
1129 {
1130 for(sal_uInt32 y(0L); y < (sal_uInt32)pContent->Height(); y++)
1131 {
1132 for(sal_uInt32 x(0L); x < (sal_uInt32)pContent->Width(); x++)
1133 {
1134 const BitmapColor aBMCol(pContent->GetColor(y, x));
1135 const basegfx::BColor aBSource(
1136 (double)aBMCol.GetRed() * fConvertColor,
1137 (double)aBMCol.GetGreen() * fConvertColor,
1138 (double)aBMCol.GetBlue() * fConvertColor);
1139 const basegfx::BColor aBDest(rModifier->getModifiedColor(aBSource));
1140
1141 pContent->SetPixel(y, x, BitmapColor(Color(aBDest)));
1142 }
1143 }
1144 }
1098 for(sal_uInt32 x(0L); x < (sal_uInt32)pContent->Width(); x++)
1099 {
1100 const basegfx::BColor aBSource(
1101 *(pScan + 2)* fConvertColor,
1102 *(pScan + 1) * fConvertColor,
1103 *pScan * fConvertColor);
1104 const basegfx::BColor aBDest(rModifier->getModifiedColor(aBSource));
1105 *pScan++ = static_cast< sal_uInt8 >(aBDest.getBlue() * 255.0);
1106 *pScan++ = static_cast< sal_uInt8 >(aBDest.getGreen() * 255.0);
1107 *pScan++ = static_cast< sal_uInt8 >(aBDest.getRed() * 255.0);
1108 }
1109 }
1110 }
1111 else if(BMP_FORMAT_24BIT_TC_RGB == pContent->GetScanlineFormat())
1112 {
1113 for(sal_uInt32 y(0L); y < (sal_uInt32)pContent->Height(); y++)
1114 {
1115 Scanline pScan = pContent->GetScanline(y);
1145
1116
1146 delete pContent;
1147 }
1148 }
1149 }
1117 for(sal_uInt32 x(0L); x < (sal_uInt32)pContent->Width(); x++)
1118 {
1119 const basegfx::BColor aBSource(
1120 *pScan * fConvertColor,
1121 *(pScan + 1) * fConvertColor,
1122 *(pScan + 2) * fConvertColor);
1123 const basegfx::BColor aBDest(rModifier->getModifiedColor(aBSource));
1124 *pScan++ = static_cast< sal_uInt8 >(aBDest.getRed() * 255.0);
1125 *pScan++ = static_cast< sal_uInt8 >(aBDest.getGreen() * 255.0);
1126 *pScan++ = static_cast< sal_uInt8 >(aBDest.getBlue() * 255.0);
1127 }
1128 }
1129 }
1130 else
1131 {
1132 for(sal_uInt32 y(0L); y < (sal_uInt32)pContent->Height(); y++)
1133 {
1134 for(sal_uInt32 x(0L); x < (sal_uInt32)pContent->Width(); x++)
1135 {
1136 const BitmapColor aBMCol(pContent->GetColor(y, x));
1137 const basegfx::BColor aBSource(
1138 (double)aBMCol.GetRed() * fConvertColor,
1139 (double)aBMCol.GetGreen() * fConvertColor,
1140 (double)aBMCol.GetBlue() * fConvertColor);
1141 const basegfx::BColor aBDest(rModifier->getModifiedColor(aBSource));
1150
1142
1151 if(aChangedBitmap.IsEmpty())
1152 {
1153 return BitmapEx();
1154 }
1155 else
1156 {
1157 if(IsTransparent())
1158 {
1159 if(IsAlpha())
1160 {
1161 return BitmapEx(aChangedBitmap, GetAlpha());
1162 }
1163 else
1164 {
1165 return BitmapEx(aChangedBitmap, GetMask());
1166 }
1167 }
1168 else
1169 {
1170 return BitmapEx(aChangedBitmap);
1171 }
1172 }
1143 pContent->SetPixel(y, x, BitmapColor(Color(aBDest)));
1144 }
1145 }
1146 }
1147
1148 delete pContent;
1149 }
1150 }
1151 }
1152
1153 if(aChangedBitmap.IsEmpty())
1154 {
1155 return BitmapEx();
1156 }
1157 else
1158 {
1159 if(IsTransparent())
1160 {
1161 if(IsAlpha())
1162 {
1163 return BitmapEx(aChangedBitmap, GetAlpha());
1164 }
1165 else
1166 {
1167 return BitmapEx(aChangedBitmap, GetMask());
1168 }
1169 }
1170 else
1171 {
1172 return BitmapEx(aChangedBitmap);
1173 }
1174 }
1173}
1174
1175// -----------------------------------------------------------------------------
1176
1177BitmapEx VCL_DLLPUBLIC createBlendFrame(
1175}
1176
1177// -----------------------------------------------------------------------------
1178
1179BitmapEx VCL_DLLPUBLIC createBlendFrame(
1178 const Size& rSize,
1179 sal_uInt8 nAlpha,
1180 Color aColorTopLeft,
1181 Color aColorBottomRight)
1180 const Size& rSize,
1181 sal_uInt8 nAlpha,
1182 Color aColorTopLeft,
1183 Color aColorBottomRight)
1182{
1184{
1183 const sal_uInt32 nW(rSize.Width());
1184 const sal_uInt32 nH(rSize.Height());
1185 const sal_uInt32 nW(rSize.Width());
1186 const sal_uInt32 nH(rSize.Height());
1185
1187
1186 if(nW || nH)
1187 {
1188 Color aColTopRight(aColorTopLeft);
1189 Color aColBottomLeft(aColorTopLeft);
1190 const sal_uInt32 nDE(nW + nH);
1188 if(nW || nH)
1189 {
1190 Color aColTopRight(aColorTopLeft);
1191 Color aColBottomLeft(aColorTopLeft);
1192 const sal_uInt32 nDE(nW + nH);
1191
1193
1192 aColTopRight.Merge(aColorBottomRight, 255 - sal_uInt8((nW * 255) / nDE));
1193 aColBottomLeft.Merge(aColorBottomRight, 255 - sal_uInt8((nH * 255) / nDE));
1194 aColTopRight.Merge(aColorBottomRight, 255 - sal_uInt8((nW * 255) / nDE));
1195 aColBottomLeft.Merge(aColorBottomRight, 255 - sal_uInt8((nH * 255) / nDE));
1194
1196
1195 return createBlendFrame(rSize, nAlpha, aColorTopLeft, aColTopRight, aColorBottomRight, aColBottomLeft);
1196 }
1197 return createBlendFrame(rSize, nAlpha, aColorTopLeft, aColTopRight, aColorBottomRight, aColBottomLeft);
1198 }
1197
1199
1198 return BitmapEx();
1200 return BitmapEx();
1199}
1200
1201BitmapEx VCL_DLLPUBLIC createBlendFrame(
1201}
1202
1203BitmapEx VCL_DLLPUBLIC createBlendFrame(
1202 const Size& rSize,
1203 sal_uInt8 nAlpha,
1204 Color aColorTopLeft,
1205 Color aColorTopRight,
1206 Color aColorBottomRight,
1207 Color aColorBottomLeft)
1204 const Size& rSize,
1205 sal_uInt8 nAlpha,
1206 Color aColorTopLeft,
1207 Color aColorTopRight,
1208 Color aColorBottomRight,
1209 Color aColorBottomLeft)
1208{
1210{
1209 static Size aLastSize(0, 0);
1210 static sal_uInt8 nLastAlpha(0);
1211 static Color aLastColorTopLeft(COL_BLACK);
1212 static Color aLastColorTopRight(COL_BLACK);
1213 static Color aLastColorBottomRight(COL_BLACK);
1214 static Color aLastColorBottomLeft(COL_BLACK);
1215 static BitmapEx aLastResult;
1211 static Size aLastSize(0, 0);
1212 static sal_uInt8 nLastAlpha(0);
1213 static Color aLastColorTopLeft(COL_BLACK);
1214 static Color aLastColorTopRight(COL_BLACK);
1215 static Color aLastColorBottomRight(COL_BLACK);
1216 static Color aLastColorBottomLeft(COL_BLACK);
1217 static BitmapEx aLastResult;
1216
1218
1217 if(aLastSize == rSize
1218 && nLastAlpha == nAlpha
1219 && aLastColorTopLeft == aColorTopLeft
1220 && aLastColorTopRight == aColorTopRight
1221 && aLastColorBottomRight == aColorBottomRight
1222 && aLastColorBottomLeft == aColorBottomLeft)
1223 {
1224 return aLastResult;
1225 }
1219 if(aLastSize == rSize
1220 && nLastAlpha == nAlpha
1221 && aLastColorTopLeft == aColorTopLeft
1222 && aLastColorTopRight == aColorTopRight
1223 && aLastColorBottomRight == aColorBottomRight
1224 && aLastColorBottomLeft == aColorBottomLeft)
1225 {
1226 return aLastResult;
1227 }
1226
1228
1227 aLastSize = rSize;
1228 nLastAlpha = nAlpha;
1229 aLastColorTopLeft = aColorTopLeft;
1230 aLastColorTopRight = aColorTopRight;
1231 aLastColorBottomRight = aColorBottomRight;
1232 aLastColorBottomLeft = aColorBottomLeft;
1233 aLastResult.Clear();
1229 aLastSize = rSize;
1230 nLastAlpha = nAlpha;
1231 aLastColorTopLeft = aColorTopLeft;
1232 aLastColorTopRight = aColorTopRight;
1233 aLastColorBottomRight = aColorBottomRight;
1234 aLastColorBottomLeft = aColorBottomLeft;
1235 aLastResult.Clear();
1234
1236
1235 const long nW(rSize.Width());
1236 const long nH(rSize.Height());
1237 const long nW(rSize.Width());
1238 const long nH(rSize.Height());
1237
1239
1238 if(nW && nH)
1239 {
1240 sal_uInt8 aEraseTrans(0xff);
1241 Bitmap aContent(rSize, 24);
1242 AlphaMask aAlpha(rSize, &aEraseTrans);
1240 if(nW && nH)
1241 {
1242 sal_uInt8 aEraseTrans(0xff);
1243 Bitmap aContent(rSize, 24);
1244 AlphaMask aAlpha(rSize, &aEraseTrans);
1243
1245
1244 aContent.Erase(COL_BLACK);
1246 aContent.Erase(COL_BLACK);
1245
1247
1246 BitmapWriteAccess* pContent = aContent.AcquireWriteAccess();
1247 BitmapWriteAccess* pAlpha = aAlpha.AcquireWriteAccess();
1248 BitmapWriteAccess* pContent = aContent.AcquireWriteAccess();
1249 BitmapWriteAccess* pAlpha = aAlpha.AcquireWriteAccess();
1248
1250
1249 if(pContent && pAlpha)
1250 {
1251 long x(0);
1252 long y(0);
1251 if(pContent && pAlpha)
1252 {
1253 long x(0);
1254 long y(0);
1253
1255
1254 // x == 0, y == 0, top-left corner
1255 pContent->SetPixel(0, 0, aColorTopLeft);
1256 pAlpha->SetPixelIndex(0, 0, nAlpha);
1256 // x == 0, y == 0, top-left corner
1257 pContent->SetPixel(0, 0, aColorTopLeft);
1258 pAlpha->SetPixelIndex(0, 0, nAlpha);
1257
1259
1258 // y == 0, top line left to right
1259 for(x = 1; x < nW - 1; x++)
1260 {
1261 Color aMix(aColorTopLeft);
1260 // y == 0, top line left to right
1261 for(x = 1; x < nW - 1; x++)
1262 {
1263 Color aMix(aColorTopLeft);
1262
1264
1263 aMix.Merge(aColorTopRight, 255 - sal_uInt8((x * 255) / nW));
1264 pContent->SetPixel(0, x, aMix);
1265 pAlpha->SetPixelIndex(0, x, nAlpha);
1266 }
1265 aMix.Merge(aColorTopRight, 255 - sal_uInt8((x * 255) / nW));
1266 pContent->SetPixel(0, x, aMix);
1267 pAlpha->SetPixelIndex(0, x, nAlpha);
1268 }
1267
1269
1268 // x == nW - 1, y == 0, top-right corner
1269 // #123690# Caution! When nW is 1, x == nW is possible (!)
1270 if(x < nW)
1271 {
1272 pContent->SetPixel(0, x, aColorTopRight);
1273 pAlpha->SetPixelIndex(0, x, nAlpha);
1274 }
1270 // x == nW - 1, y == 0, top-right corner
1271 // #123690# Caution! When nW is 1, x == nW is possible (!)
1272 if(x < nW)
1273 {
1274 pContent->SetPixel(0, x, aColorTopRight);
1275 pAlpha->SetPixelIndex(0, x, nAlpha);
1276 }
1275
1277
1276 // x == 0 and nW - 1, left and right line top-down
1277 for(y = 1; y < nH - 1; y++)
1278 {
1279 Color aMixA(aColorTopLeft);
1278 // x == 0 and nW - 1, left and right line top-down
1279 for(y = 1; y < nH - 1; y++)
1280 {
1281 Color aMixA(aColorTopLeft);
1280
1282
1281 aMixA.Merge(aColorBottomLeft, 255 - sal_uInt8((y * 255) / nH));
1282 pContent->SetPixel(y, 0, aMixA);
1283 pAlpha->SetPixelIndex(y, 0, nAlpha);
1283 aMixA.Merge(aColorBottomLeft, 255 - sal_uInt8((y * 255) / nH));
1284 pContent->SetPixel(y, 0, aMixA);
1285 pAlpha->SetPixelIndex(y, 0, nAlpha);
1284
1286
1285 // #123690# Caution! When nW is 1, x == nW is possible (!)
1286 if(x < nW)
1287 {
1288 Color aMixB(aColorTopRight);
1287 // #123690# Caution! When nW is 1, x == nW is possible (!)
1288 if(x < nW)
1289 {
1290 Color aMixB(aColorTopRight);
1289
1291
1290 aMixB.Merge(aColorBottomRight, 255 - sal_uInt8((y * 255) / nH));
1291 pContent->SetPixel(y, x, aMixB);
1292 pAlpha->SetPixelIndex(y, x, nAlpha);
1293 }
1294 }
1292 aMixB.Merge(aColorBottomRight, 255 - sal_uInt8((y * 255) / nH));
1293 pContent->SetPixel(y, x, aMixB);
1294 pAlpha->SetPixelIndex(y, x, nAlpha);
1295 }
1296 }
1295
1297
1296 // #123690# Caution! When nH is 1, y == nH is possible (!)
1297 if(y < nH)
1298 {
1299 // x == 0, y == nH - 1, bottom-left corner
1300 pContent->SetPixel(y, 0, aColorBottomLeft);
1301 pAlpha->SetPixelIndex(y, 0, nAlpha);
1298 // #123690# Caution! When nH is 1, y == nH is possible (!)
1299 if(y < nH)
1300 {
1301 // x == 0, y == nH - 1, bottom-left corner
1302 pContent->SetPixel(y, 0, aColorBottomLeft);
1303 pAlpha->SetPixelIndex(y, 0, nAlpha);
1302
1304
1303 // y == nH - 1, bottom line left to right
1304 for(x = 1; x < nW - 1; x++)
1305 {
1306 Color aMix(aColorBottomLeft);
1305 // y == nH - 1, bottom line left to right
1306 for(x = 1; x < nW - 1; x++)
1307 {
1308 Color aMix(aColorBottomLeft);
1307
1309
1308 aMix.Merge(aColorBottomRight, 255 - sal_uInt8(((x - 0)* 255) / nW));
1309 pContent->SetPixel(y, x, aMix);
1310 pAlpha->SetPixelIndex(y, x, nAlpha);
1311 }
1310 aMix.Merge(aColorBottomRight, 255 - sal_uInt8(((x - 0)* 255) / nW));
1311 pContent->SetPixel(y, x, aMix);
1312 pAlpha->SetPixelIndex(y, x, nAlpha);
1313 }
1312
1314
1313 // x == nW - 1, y == nH - 1, bottom-right corner
1314 // #123690# Caution! When nW is 1, x == nW is possible (!)
1315 if(x < nW)
1316 {
1317 pContent->SetPixel(y, x, aColorBottomRight);
1318 pAlpha->SetPixelIndex(y, x, nAlpha);
1319 }
1320 }
1315 // x == nW - 1, y == nH - 1, bottom-right corner
1316 // #123690# Caution! When nW is 1, x == nW is possible (!)
1317 if(x < nW)
1318 {
1319 pContent->SetPixel(y, x, aColorBottomRight);
1320 pAlpha->SetPixelIndex(y, x, nAlpha);
1321 }
1322 }
1321
1323
1322 aContent.ReleaseAccess(pContent);
1323 aAlpha.ReleaseAccess(pAlpha);
1324 aContent.ReleaseAccess(pContent);
1325 aAlpha.ReleaseAccess(pAlpha);
1324
1326
1325 aLastResult = BitmapEx(aContent, aAlpha);
1326 }
1327 else
1328 {
1329 if(pContent)
1330 {
1331 aContent.ReleaseAccess(pContent);
1332 }
1327 aLastResult = BitmapEx(aContent, aAlpha);
1328 }
1329 else
1330 {
1331 if(pContent)
1332 {
1333 aContent.ReleaseAccess(pContent);
1334 }
1333
1335
1334 if(pAlpha)
1335 {
1336 aAlpha.ReleaseAccess(pAlpha);
1337 }
1338 }
1339 }
1336 if(pAlpha)
1337 {
1338 aAlpha.ReleaseAccess(pAlpha);
1339 }
1340 }
1341 }
1340
1342
1341 return aLastResult;
1343 return aLastResult;
1342}
1343
1344}
1345
1344// ------------------------------------------------------------------
1345// eof
1346/* vim: set noet sw=4 ts=4: */