1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_vcl.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <ctype.h> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <rtl/crc.h> 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <tools/stream.hxx> 36*cdf0e10cSrcweir #include <tools/debug.hxx> 37*cdf0e10cSrcweir #include <tools/rc.h> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include <vcl/salbtype.hxx> 40*cdf0e10cSrcweir #include <vcl/outdev.hxx> 41*cdf0e10cSrcweir #include <vcl/alpha.hxx> 42*cdf0e10cSrcweir #include <vcl/bitmapex.hxx> 43*cdf0e10cSrcweir #include <vcl/pngread.hxx> 44*cdf0e10cSrcweir #include <vcl/svapp.hxx> 45*cdf0e10cSrcweir #include <vcl/bmpacc.hxx> 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir #include <image.h> 48*cdf0e10cSrcweir #include <impimagetree.hxx> 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir // ------------ 51*cdf0e10cSrcweir // - BitmapEx - 52*cdf0e10cSrcweir // ------------ 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir BitmapEx::BitmapEx() : 55*cdf0e10cSrcweir eTransparent( TRANSPARENT_NONE ), 56*cdf0e10cSrcweir bAlpha ( sal_False ) 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir } 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir // ------------------------------------------------------------------ 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir BitmapEx::BitmapEx( const BitmapEx& rBitmapEx ) : 63*cdf0e10cSrcweir aBitmap ( rBitmapEx.aBitmap ), 64*cdf0e10cSrcweir aMask ( rBitmapEx.aMask ), 65*cdf0e10cSrcweir aBitmapSize ( rBitmapEx.aBitmapSize ), 66*cdf0e10cSrcweir aTransparentColor ( rBitmapEx.aTransparentColor ), 67*cdf0e10cSrcweir eTransparent ( rBitmapEx.eTransparent ), 68*cdf0e10cSrcweir bAlpha ( rBitmapEx.bAlpha ) 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir } 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir BitmapEx::BitmapEx( const BitmapEx& rBitmapEx, Point aSrc, Size aSize ) : 73*cdf0e10cSrcweir eTransparent( TRANSPARENT_NONE ), 74*cdf0e10cSrcweir bAlpha ( sal_False ) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir if( rBitmapEx.IsEmpty() ) 77*cdf0e10cSrcweir return; 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir aBitmap = Bitmap( aSize, rBitmapEx.aBitmap.GetBitCount() ); 80*cdf0e10cSrcweir aBitmapSize = aSize; 81*cdf0e10cSrcweir if( rBitmapEx.IsAlpha() ) 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir bAlpha = sal_True; 84*cdf0e10cSrcweir aMask = AlphaMask( aSize ).ImplGetBitmap(); 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir else if( rBitmapEx.IsTransparent() ) 87*cdf0e10cSrcweir aMask = Bitmap( aSize, rBitmapEx.aMask.GetBitCount() ); 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir Rectangle aDestRect( Point( 0, 0 ), aSize ); 90*cdf0e10cSrcweir Rectangle aSrcRect( aSrc, aSize ); 91*cdf0e10cSrcweir CopyPixel( aDestRect, aSrcRect, &rBitmapEx ); 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir // ------------------------------------------------------------------ 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir BitmapEx::BitmapEx( const ResId& rResId ) : 97*cdf0e10cSrcweir eTransparent( TRANSPARENT_NONE ), 98*cdf0e10cSrcweir bAlpha ( sal_False ) 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir static ImplImageTreeSingletonRef aImageTree; 101*cdf0e10cSrcweir ResMgr* pResMgr = NULL; 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir ResMgr::GetResourceSkipHeader( rResId.SetRT( RSC_BITMAP ), &pResMgr ); 104*cdf0e10cSrcweir pResMgr->ReadLong(); 105*cdf0e10cSrcweir pResMgr->ReadLong(); 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir const String aFileName( pResMgr->ReadString() ); 108*cdf0e10cSrcweir ::rtl::OUString aCurrentSymbolsStyle = Application::GetSettings().GetStyleSettings().GetCurrentSymbolsStyleName(); 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir if( !aImageTree->loadImage( aFileName, aCurrentSymbolsStyle, *this ) ) 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir #ifdef DBG_UTIL 113*cdf0e10cSrcweir ByteString aErrorStr( "BitmapEx::BitmapEx( const ResId& rResId ): could not load image <" ); 114*cdf0e10cSrcweir DBG_ERROR( ( ( aErrorStr += ByteString( aFileName, RTL_TEXTENCODING_ASCII_US ) ) += '>' ).GetBuffer() ); 115*cdf0e10cSrcweir #endif 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir // ------------------------------------------------------------------ 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir BitmapEx::BitmapEx( const Bitmap& rBmp ) : 122*cdf0e10cSrcweir aBitmap ( rBmp ), 123*cdf0e10cSrcweir aBitmapSize ( aBitmap.GetSizePixel() ), 124*cdf0e10cSrcweir eTransparent( TRANSPARENT_NONE ), 125*cdf0e10cSrcweir bAlpha ( sal_False ) 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir // ------------------------------------------------------------------ 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir BitmapEx::BitmapEx( const Bitmap& rBmp, const Bitmap& rMask ) : 132*cdf0e10cSrcweir aBitmap ( rBmp ), 133*cdf0e10cSrcweir aMask ( rMask ), 134*cdf0e10cSrcweir aBitmapSize ( aBitmap.GetSizePixel() ), 135*cdf0e10cSrcweir eTransparent ( !rMask ? TRANSPARENT_NONE : TRANSPARENT_BITMAP ), 136*cdf0e10cSrcweir bAlpha ( sal_False ) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir DBG_ASSERT( !rMask || rBmp.GetSizePixel() == rMask.GetSizePixel(), 139*cdf0e10cSrcweir "BitmapEx::BitmapEx(): size mismatch for bitmap and mask." ); 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir // #105489# Ensure a mask is exactly one bit deep 142*cdf0e10cSrcweir if( !!aMask && aMask.GetBitCount() != 1 ) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir OSL_TRACE("BitmapEx: forced mask to monochrome"); 145*cdf0e10cSrcweir aMask.ImplMakeMono( 255 ); 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir // ------------------------------------------------------------------ 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir BitmapEx::BitmapEx( const Bitmap& rBmp, const AlphaMask& rAlphaMask ) : 152*cdf0e10cSrcweir aBitmap ( rBmp ), 153*cdf0e10cSrcweir aMask ( rAlphaMask.ImplGetBitmap() ), 154*cdf0e10cSrcweir aBitmapSize ( aBitmap.GetSizePixel() ), 155*cdf0e10cSrcweir eTransparent ( !rAlphaMask ? TRANSPARENT_NONE : TRANSPARENT_BITMAP ), 156*cdf0e10cSrcweir bAlpha ( !rAlphaMask ? sal_False : sal_True ) 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir DBG_ASSERT( !rAlphaMask || rBmp.GetSizePixel() == rAlphaMask.GetSizePixel(), 159*cdf0e10cSrcweir "BitmapEx::BitmapEx(): size mismatch for bitmap and alpha mask." ); 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir // #i75531# the workaround below can go when 162*cdf0e10cSrcweir // X11SalGraphics::drawAlphaBitmap()'s render acceleration 163*cdf0e10cSrcweir // can handle the bitmap depth mismatch directly 164*cdf0e10cSrcweir if( aBitmap.GetBitCount() < aMask.GetBitCount() ) 165*cdf0e10cSrcweir aBitmap.Convert( BMP_CONVERSION_24BIT ); 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir // ------------------------------------------------------------------ 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir BitmapEx::BitmapEx( const Bitmap& rBmp, const Color& rTransparentColor ) : 171*cdf0e10cSrcweir aBitmap ( rBmp ), 172*cdf0e10cSrcweir aBitmapSize ( aBitmap.GetSizePixel() ), 173*cdf0e10cSrcweir aTransparentColor ( rTransparentColor ), 174*cdf0e10cSrcweir eTransparent ( TRANSPARENT_BITMAP ), 175*cdf0e10cSrcweir bAlpha ( sal_False ) 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir aMask = aBitmap.CreateMask( aTransparentColor ); 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir DBG_ASSERT( rBmp.GetSizePixel() == aMask.GetSizePixel(), 180*cdf0e10cSrcweir "BitmapEx::BitmapEx(): size mismatch for bitmap and alpha mask." ); 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir // ------------------------------------------------------------------ 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir BitmapEx::~BitmapEx() 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir // ------------------------------------------------------------------ 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir // ------------------------------------------------------------------ 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir BitmapEx& BitmapEx::operator=( const BitmapEx& rBitmapEx ) 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir if( &rBitmapEx != this ) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir aBitmap = rBitmapEx.aBitmap; 198*cdf0e10cSrcweir aMask = rBitmapEx.aMask; 199*cdf0e10cSrcweir aBitmapSize = rBitmapEx.aBitmapSize; 200*cdf0e10cSrcweir aTransparentColor = rBitmapEx.aTransparentColor; 201*cdf0e10cSrcweir eTransparent = rBitmapEx.eTransparent; 202*cdf0e10cSrcweir bAlpha = rBitmapEx.bAlpha; 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir return *this; 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir // ------------------------------------------------------------------ 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir sal_Bool BitmapEx::operator==( const BitmapEx& rBitmapEx ) const 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir if( eTransparent != rBitmapEx.eTransparent ) 213*cdf0e10cSrcweir return sal_False; 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir if( aBitmap != rBitmapEx.aBitmap ) 216*cdf0e10cSrcweir return sal_False; 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir if( aBitmapSize != rBitmapEx.aBitmapSize ) 219*cdf0e10cSrcweir return sal_False; 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir if( eTransparent == TRANSPARENT_NONE ) 222*cdf0e10cSrcweir return sal_True; 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir if( eTransparent == TRANSPARENT_COLOR ) 225*cdf0e10cSrcweir return aTransparentColor == rBitmapEx.aTransparentColor; 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir return( ( aMask == rBitmapEx.aMask ) && ( bAlpha == rBitmapEx.bAlpha ) ); 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir // ------------------------------------------------------------------ 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir sal_Bool BitmapEx::IsEqual( const BitmapEx& rBmpEx ) const 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir return( rBmpEx.eTransparent == eTransparent && 235*cdf0e10cSrcweir rBmpEx.bAlpha == bAlpha && 236*cdf0e10cSrcweir rBmpEx.aBitmap.IsEqual( aBitmap ) && 237*cdf0e10cSrcweir rBmpEx.aMask.IsEqual( aMask ) ); 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir // ------------------------------------------------------------------ 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir sal_Bool BitmapEx::IsEmpty() const 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir return( aBitmap.IsEmpty() && aMask.IsEmpty() ); 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir // ------------------------------------------------------------------ 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir void BitmapEx::SetEmpty() 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir aBitmap.SetEmpty(); 252*cdf0e10cSrcweir aMask.SetEmpty(); 253*cdf0e10cSrcweir eTransparent = TRANSPARENT_NONE; 254*cdf0e10cSrcweir bAlpha = sal_False; 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir // ------------------------------------------------------------------ 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir void BitmapEx::Clear() 260*cdf0e10cSrcweir { 261*cdf0e10cSrcweir SetEmpty(); 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir // ------------------------------------------------------------------ 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir sal_Bool BitmapEx::IsTransparent() const 267*cdf0e10cSrcweir { 268*cdf0e10cSrcweir return( eTransparent != TRANSPARENT_NONE ); 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir // ------------------------------------------------------------------ 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir sal_Bool BitmapEx::IsAlpha() const 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir return( IsTransparent() && bAlpha ); 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir // ------------------------------------------------------------------ 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir Bitmap BitmapEx::GetBitmap( const Color* pTransReplaceColor ) const 281*cdf0e10cSrcweir { 282*cdf0e10cSrcweir Bitmap aRetBmp( aBitmap ); 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir if( pTransReplaceColor && ( eTransparent != TRANSPARENT_NONE ) ) 285*cdf0e10cSrcweir { 286*cdf0e10cSrcweir Bitmap aTempMask; 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir if( eTransparent == TRANSPARENT_COLOR ) 289*cdf0e10cSrcweir aTempMask = aBitmap.CreateMask( aTransparentColor ); 290*cdf0e10cSrcweir else 291*cdf0e10cSrcweir aTempMask = aMask; 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir if( !IsAlpha() ) 294*cdf0e10cSrcweir aRetBmp.Replace( aTempMask, *pTransReplaceColor ); 295*cdf0e10cSrcweir else 296*cdf0e10cSrcweir aRetBmp.Replace( GetAlpha(), *pTransReplaceColor ); 297*cdf0e10cSrcweir } 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir return aRetBmp; 300*cdf0e10cSrcweir } 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir // ------------------------------------------------------------------ 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir BitmapEx BitmapEx::GetColorTransformedBitmapEx( BmpColorMode eColorMode ) const 305*cdf0e10cSrcweir { 306*cdf0e10cSrcweir BitmapEx aRet; 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir if( BMP_COLOR_HIGHCONTRAST == eColorMode ) 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir aRet = *this; 311*cdf0e10cSrcweir aRet.aBitmap = aBitmap.GetColorTransformedBitmap( eColorMode ); 312*cdf0e10cSrcweir } 313*cdf0e10cSrcweir else if( BMP_COLOR_MONOCHROME_BLACK == eColorMode || 314*cdf0e10cSrcweir BMP_COLOR_MONOCHROME_WHITE == eColorMode ) 315*cdf0e10cSrcweir { 316*cdf0e10cSrcweir aRet = *this; 317*cdf0e10cSrcweir aRet.aBitmap = aRet.aBitmap.GetColorTransformedBitmap( eColorMode ); 318*cdf0e10cSrcweir 319*cdf0e10cSrcweir if( !aRet.aMask.IsEmpty() ) 320*cdf0e10cSrcweir { 321*cdf0e10cSrcweir aRet.aMask.CombineSimple( aRet.aBitmap, BMP_COMBINE_OR ); 322*cdf0e10cSrcweir aRet.aBitmap.Erase( ( BMP_COLOR_MONOCHROME_BLACK == eColorMode ) ? COL_BLACK : COL_WHITE ); 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir DBG_ASSERT( aRet.aBitmap.GetSizePixel() == aRet.aMask.GetSizePixel(), 325*cdf0e10cSrcweir "BitmapEx::GetColorTransformedBitmapEx(): size mismatch for bitmap and alpha mask." ); 326*cdf0e10cSrcweir } 327*cdf0e10cSrcweir } 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir return aRet; 330*cdf0e10cSrcweir } 331*cdf0e10cSrcweir 332*cdf0e10cSrcweir // ------------------------------------------------------------------ 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir Bitmap BitmapEx::GetMask() const 335*cdf0e10cSrcweir { 336*cdf0e10cSrcweir Bitmap aRet( aMask ); 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir if( IsAlpha() ) 339*cdf0e10cSrcweir aRet.ImplMakeMono( 255 ); 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir return aRet; 342*cdf0e10cSrcweir } 343*cdf0e10cSrcweir 344*cdf0e10cSrcweir // ------------------------------------------------------------------ 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir AlphaMask BitmapEx::GetAlpha() const 347*cdf0e10cSrcweir { 348*cdf0e10cSrcweir AlphaMask aAlpha; 349*cdf0e10cSrcweir 350*cdf0e10cSrcweir if( IsAlpha() ) 351*cdf0e10cSrcweir aAlpha.ImplSetBitmap( aMask ); 352*cdf0e10cSrcweir else 353*cdf0e10cSrcweir aAlpha = aMask; 354*cdf0e10cSrcweir 355*cdf0e10cSrcweir return aAlpha; 356*cdf0e10cSrcweir } 357*cdf0e10cSrcweir 358*cdf0e10cSrcweir // ------------------------------------------------------------------ 359*cdf0e10cSrcweir 360*cdf0e10cSrcweir sal_uLong BitmapEx::GetSizeBytes() const 361*cdf0e10cSrcweir { 362*cdf0e10cSrcweir sal_uLong nSizeBytes = aBitmap.GetSizeBytes(); 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir if( eTransparent == TRANSPARENT_BITMAP ) 365*cdf0e10cSrcweir nSizeBytes += aMask.GetSizeBytes(); 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir return nSizeBytes; 368*cdf0e10cSrcweir } 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir // ------------------------------------------------------------------ 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir sal_uLong BitmapEx::GetChecksum() const 373*cdf0e10cSrcweir { 374*cdf0e10cSrcweir sal_uInt32 nCrc = aBitmap.GetChecksum(); 375*cdf0e10cSrcweir SVBT32 aBT32; 376*cdf0e10cSrcweir 377*cdf0e10cSrcweir UInt32ToSVBT32( (long) eTransparent, aBT32 ); 378*cdf0e10cSrcweir nCrc = rtl_crc32( nCrc, aBT32, 4 ); 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir UInt32ToSVBT32( (long) bAlpha, aBT32 ); 381*cdf0e10cSrcweir nCrc = rtl_crc32( nCrc, aBT32, 4 ); 382*cdf0e10cSrcweir 383*cdf0e10cSrcweir if( ( TRANSPARENT_BITMAP == eTransparent ) && !aMask.IsEmpty() ) 384*cdf0e10cSrcweir { 385*cdf0e10cSrcweir UInt32ToSVBT32( aMask.GetChecksum(), aBT32 ); 386*cdf0e10cSrcweir nCrc = rtl_crc32( nCrc, aBT32, 4 ); 387*cdf0e10cSrcweir } 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir return nCrc; 390*cdf0e10cSrcweir } 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir // ------------------------------------------------------------------ 393*cdf0e10cSrcweir 394*cdf0e10cSrcweir void BitmapEx::SetSizePixel( const Size& rNewSize ) 395*cdf0e10cSrcweir { 396*cdf0e10cSrcweir Scale( rNewSize ); 397*cdf0e10cSrcweir } 398*cdf0e10cSrcweir 399*cdf0e10cSrcweir // ------------------------------------------------------------------ 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir sal_Bool BitmapEx::Invert() 402*cdf0e10cSrcweir { 403*cdf0e10cSrcweir sal_Bool bRet = sal_False; 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir if( !!aBitmap ) 406*cdf0e10cSrcweir { 407*cdf0e10cSrcweir bRet = aBitmap.Invert(); 408*cdf0e10cSrcweir 409*cdf0e10cSrcweir if( bRet && ( eTransparent == TRANSPARENT_COLOR ) ) 410*cdf0e10cSrcweir aTransparentColor = BitmapColor( aTransparentColor ).Invert(); 411*cdf0e10cSrcweir } 412*cdf0e10cSrcweir 413*cdf0e10cSrcweir return bRet; 414*cdf0e10cSrcweir } 415*cdf0e10cSrcweir 416*cdf0e10cSrcweir // ------------------------------------------------------------------ 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir sal_Bool BitmapEx::Mirror( sal_uLong nMirrorFlags ) 419*cdf0e10cSrcweir { 420*cdf0e10cSrcweir sal_Bool bRet = sal_False; 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir if( !!aBitmap ) 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir bRet = aBitmap.Mirror( nMirrorFlags ); 425*cdf0e10cSrcweir 426*cdf0e10cSrcweir if( bRet && ( eTransparent == TRANSPARENT_BITMAP ) && !!aMask ) 427*cdf0e10cSrcweir aMask.Mirror( nMirrorFlags ); 428*cdf0e10cSrcweir } 429*cdf0e10cSrcweir 430*cdf0e10cSrcweir return bRet; 431*cdf0e10cSrcweir } 432*cdf0e10cSrcweir 433*cdf0e10cSrcweir // ------------------------------------------------------------------ 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir sal_Bool BitmapEx::Scale( const double& rScaleX, const double& rScaleY, sal_uLong nScaleFlag ) 436*cdf0e10cSrcweir { 437*cdf0e10cSrcweir sal_Bool bRet = sal_False; 438*cdf0e10cSrcweir 439*cdf0e10cSrcweir if( !!aBitmap ) 440*cdf0e10cSrcweir { 441*cdf0e10cSrcweir bRet = aBitmap.Scale( rScaleX, rScaleY, nScaleFlag ); 442*cdf0e10cSrcweir 443*cdf0e10cSrcweir if( bRet && ( eTransparent == TRANSPARENT_BITMAP ) && !!aMask ) 444*cdf0e10cSrcweir aMask.Scale( rScaleX, rScaleY, BMP_SCALE_FAST ); 445*cdf0e10cSrcweir 446*cdf0e10cSrcweir aBitmapSize = aBitmap.GetSizePixel(); 447*cdf0e10cSrcweir 448*cdf0e10cSrcweir DBG_ASSERT( !aMask || aBitmap.GetSizePixel() == aMask.GetSizePixel(), 449*cdf0e10cSrcweir "BitmapEx::Scale(): size mismatch for bitmap and alpha mask." ); 450*cdf0e10cSrcweir } 451*cdf0e10cSrcweir 452*cdf0e10cSrcweir return bRet; 453*cdf0e10cSrcweir } 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir // ------------------------------------------------------------------------ 456*cdf0e10cSrcweir 457*cdf0e10cSrcweir sal_Bool BitmapEx::Scale( const Size& rNewSize, sal_uLong nScaleFlag ) 458*cdf0e10cSrcweir { 459*cdf0e10cSrcweir sal_Bool bRet; 460*cdf0e10cSrcweir 461*cdf0e10cSrcweir if( aBitmapSize.Width() && aBitmapSize.Height() ) 462*cdf0e10cSrcweir { 463*cdf0e10cSrcweir bRet = Scale( (double) rNewSize.Width() / aBitmapSize.Width(), 464*cdf0e10cSrcweir (double) rNewSize.Height() / aBitmapSize.Height(), 465*cdf0e10cSrcweir nScaleFlag ); 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir else 468*cdf0e10cSrcweir bRet = sal_True; 469*cdf0e10cSrcweir 470*cdf0e10cSrcweir return bRet; 471*cdf0e10cSrcweir } 472*cdf0e10cSrcweir 473*cdf0e10cSrcweir // ------------------------------------------------------------------ 474*cdf0e10cSrcweir 475*cdf0e10cSrcweir sal_Bool BitmapEx::Rotate( long nAngle10, const Color& rFillColor ) 476*cdf0e10cSrcweir { 477*cdf0e10cSrcweir sal_Bool bRet = sal_False; 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir if( !!aBitmap ) 480*cdf0e10cSrcweir { 481*cdf0e10cSrcweir const sal_Bool bTransRotate = ( Color( COL_TRANSPARENT ) == rFillColor ); 482*cdf0e10cSrcweir 483*cdf0e10cSrcweir if( bTransRotate ) 484*cdf0e10cSrcweir { 485*cdf0e10cSrcweir if( eTransparent == TRANSPARENT_COLOR ) 486*cdf0e10cSrcweir bRet = aBitmap.Rotate( nAngle10, aTransparentColor ); 487*cdf0e10cSrcweir else 488*cdf0e10cSrcweir { 489*cdf0e10cSrcweir bRet = aBitmap.Rotate( nAngle10, COL_BLACK ); 490*cdf0e10cSrcweir 491*cdf0e10cSrcweir if( eTransparent == TRANSPARENT_NONE ) 492*cdf0e10cSrcweir { 493*cdf0e10cSrcweir aMask = Bitmap( aBitmapSize, 1 ); 494*cdf0e10cSrcweir aMask.Erase( COL_BLACK ); 495*cdf0e10cSrcweir eTransparent = TRANSPARENT_BITMAP; 496*cdf0e10cSrcweir } 497*cdf0e10cSrcweir 498*cdf0e10cSrcweir if( bRet && !!aMask ) 499*cdf0e10cSrcweir aMask.Rotate( nAngle10, COL_WHITE ); 500*cdf0e10cSrcweir } 501*cdf0e10cSrcweir } 502*cdf0e10cSrcweir else 503*cdf0e10cSrcweir { 504*cdf0e10cSrcweir bRet = aBitmap.Rotate( nAngle10, rFillColor ); 505*cdf0e10cSrcweir 506*cdf0e10cSrcweir if( bRet && ( eTransparent == TRANSPARENT_BITMAP ) && !!aMask ) 507*cdf0e10cSrcweir aMask.Rotate( nAngle10, COL_WHITE ); 508*cdf0e10cSrcweir } 509*cdf0e10cSrcweir 510*cdf0e10cSrcweir aBitmapSize = aBitmap.GetSizePixel(); 511*cdf0e10cSrcweir 512*cdf0e10cSrcweir DBG_ASSERT( !aMask || aBitmap.GetSizePixel() == aMask.GetSizePixel(), 513*cdf0e10cSrcweir "BitmapEx::Rotate(): size mismatch for bitmap and alpha mask." ); 514*cdf0e10cSrcweir } 515*cdf0e10cSrcweir 516*cdf0e10cSrcweir return bRet; 517*cdf0e10cSrcweir } 518*cdf0e10cSrcweir 519*cdf0e10cSrcweir // ------------------------------------------------------------------ 520*cdf0e10cSrcweir 521*cdf0e10cSrcweir sal_Bool BitmapEx::Crop( const Rectangle& rRectPixel ) 522*cdf0e10cSrcweir { 523*cdf0e10cSrcweir sal_Bool bRet = sal_False; 524*cdf0e10cSrcweir 525*cdf0e10cSrcweir if( !!aBitmap ) 526*cdf0e10cSrcweir { 527*cdf0e10cSrcweir bRet = aBitmap.Crop( rRectPixel ); 528*cdf0e10cSrcweir 529*cdf0e10cSrcweir if( bRet && ( eTransparent == TRANSPARENT_BITMAP ) && !!aMask ) 530*cdf0e10cSrcweir aMask.Crop( rRectPixel ); 531*cdf0e10cSrcweir 532*cdf0e10cSrcweir aBitmapSize = aBitmap.GetSizePixel(); 533*cdf0e10cSrcweir 534*cdf0e10cSrcweir DBG_ASSERT( !aMask || aBitmap.GetSizePixel() == aMask.GetSizePixel(), 535*cdf0e10cSrcweir "BitmapEx::Crop(): size mismatch for bitmap and alpha mask." ); 536*cdf0e10cSrcweir } 537*cdf0e10cSrcweir 538*cdf0e10cSrcweir return bRet; 539*cdf0e10cSrcweir } 540*cdf0e10cSrcweir 541*cdf0e10cSrcweir // ------------------------------------------------------------------ 542*cdf0e10cSrcweir 543*cdf0e10cSrcweir sal_Bool BitmapEx::Convert( BmpConversion eConversion ) 544*cdf0e10cSrcweir { 545*cdf0e10cSrcweir return( !!aBitmap ? aBitmap.Convert( eConversion ) : sal_False ); 546*cdf0e10cSrcweir } 547*cdf0e10cSrcweir 548*cdf0e10cSrcweir // ------------------------------------------------------------------ 549*cdf0e10cSrcweir 550*cdf0e10cSrcweir sal_Bool BitmapEx::ReduceColors( sal_uInt16 nNewColorCount, BmpReduce eReduce ) 551*cdf0e10cSrcweir { 552*cdf0e10cSrcweir return( !!aBitmap ? aBitmap.ReduceColors( nNewColorCount, eReduce ) : sal_False ); 553*cdf0e10cSrcweir } 554*cdf0e10cSrcweir 555*cdf0e10cSrcweir // ------------------------------------------------------------------ 556*cdf0e10cSrcweir 557*cdf0e10cSrcweir sal_Bool BitmapEx::Expand( sal_uLong nDX, sal_uLong nDY, const Color* pInitColor, sal_Bool bExpandTransparent ) 558*cdf0e10cSrcweir { 559*cdf0e10cSrcweir sal_Bool bRet = sal_False; 560*cdf0e10cSrcweir 561*cdf0e10cSrcweir if( !!aBitmap ) 562*cdf0e10cSrcweir { 563*cdf0e10cSrcweir bRet = aBitmap.Expand( nDX, nDY, pInitColor ); 564*cdf0e10cSrcweir 565*cdf0e10cSrcweir if( bRet && ( eTransparent == TRANSPARENT_BITMAP ) && !!aMask ) 566*cdf0e10cSrcweir { 567*cdf0e10cSrcweir Color aColor( bExpandTransparent ? COL_WHITE : COL_BLACK ); 568*cdf0e10cSrcweir aMask.Expand( nDX, nDY, &aColor ); 569*cdf0e10cSrcweir } 570*cdf0e10cSrcweir 571*cdf0e10cSrcweir aBitmapSize = aBitmap.GetSizePixel(); 572*cdf0e10cSrcweir 573*cdf0e10cSrcweir DBG_ASSERT( !aMask || aBitmap.GetSizePixel() == aMask.GetSizePixel(), 574*cdf0e10cSrcweir "BitmapEx::Expand(): size mismatch for bitmap and alpha mask." ); 575*cdf0e10cSrcweir } 576*cdf0e10cSrcweir 577*cdf0e10cSrcweir return bRet; 578*cdf0e10cSrcweir } 579*cdf0e10cSrcweir 580*cdf0e10cSrcweir // ------------------------------------------------------------------ 581*cdf0e10cSrcweir 582*cdf0e10cSrcweir sal_Bool BitmapEx::CopyPixel( const Rectangle& rRectDst, const Rectangle& rRectSrc, 583*cdf0e10cSrcweir const BitmapEx* pBmpExSrc ) 584*cdf0e10cSrcweir { 585*cdf0e10cSrcweir sal_Bool bRet = sal_False; 586*cdf0e10cSrcweir 587*cdf0e10cSrcweir if( !pBmpExSrc || pBmpExSrc->IsEmpty() ) 588*cdf0e10cSrcweir { 589*cdf0e10cSrcweir if( !aBitmap.IsEmpty() ) 590*cdf0e10cSrcweir { 591*cdf0e10cSrcweir bRet = aBitmap.CopyPixel( rRectDst, rRectSrc ); 592*cdf0e10cSrcweir 593*cdf0e10cSrcweir if( bRet && ( eTransparent == TRANSPARENT_BITMAP ) && !!aMask ) 594*cdf0e10cSrcweir aMask.CopyPixel( rRectDst, rRectSrc ); 595*cdf0e10cSrcweir } 596*cdf0e10cSrcweir } 597*cdf0e10cSrcweir else 598*cdf0e10cSrcweir { 599*cdf0e10cSrcweir if( !aBitmap.IsEmpty() ) 600*cdf0e10cSrcweir { 601*cdf0e10cSrcweir bRet = aBitmap.CopyPixel( rRectDst, rRectSrc, &pBmpExSrc->aBitmap ); 602*cdf0e10cSrcweir 603*cdf0e10cSrcweir if( bRet ) 604*cdf0e10cSrcweir { 605*cdf0e10cSrcweir if( pBmpExSrc->IsAlpha() ) 606*cdf0e10cSrcweir { 607*cdf0e10cSrcweir if( IsAlpha() ) 608*cdf0e10cSrcweir // cast to use the optimized AlphaMask::CopyPixel 609*cdf0e10cSrcweir ((AlphaMask*) &aMask)->CopyPixel( rRectDst, rRectSrc, (AlphaMask*)&pBmpExSrc->aMask ); 610*cdf0e10cSrcweir else if( IsTransparent() ) 611*cdf0e10cSrcweir { 612*cdf0e10cSrcweir AlphaMask* pAlpha = new AlphaMask( aMask ); 613*cdf0e10cSrcweir 614*cdf0e10cSrcweir aMask = pAlpha->ImplGetBitmap(); 615*cdf0e10cSrcweir delete pAlpha; 616*cdf0e10cSrcweir bAlpha = sal_True; 617*cdf0e10cSrcweir aMask.CopyPixel( rRectDst, rRectSrc, &pBmpExSrc->aMask ); 618*cdf0e10cSrcweir } 619*cdf0e10cSrcweir else 620*cdf0e10cSrcweir { 621*cdf0e10cSrcweir sal_uInt8 cBlack = 0; 622*cdf0e10cSrcweir AlphaMask* pAlpha = new AlphaMask( GetSizePixel(), &cBlack ); 623*cdf0e10cSrcweir 624*cdf0e10cSrcweir aMask = pAlpha->ImplGetBitmap(); 625*cdf0e10cSrcweir delete pAlpha; 626*cdf0e10cSrcweir eTransparent = TRANSPARENT_BITMAP; 627*cdf0e10cSrcweir bAlpha = sal_True; 628*cdf0e10cSrcweir aMask.CopyPixel( rRectDst, rRectSrc, &pBmpExSrc->aMask ); 629*cdf0e10cSrcweir } 630*cdf0e10cSrcweir } 631*cdf0e10cSrcweir else if( pBmpExSrc->IsTransparent() ) 632*cdf0e10cSrcweir { 633*cdf0e10cSrcweir if( IsAlpha() ) 634*cdf0e10cSrcweir { 635*cdf0e10cSrcweir AlphaMask aAlpha( pBmpExSrc->aMask ); 636*cdf0e10cSrcweir aMask.CopyPixel( rRectDst, rRectSrc, &aAlpha.ImplGetBitmap() ); 637*cdf0e10cSrcweir } 638*cdf0e10cSrcweir else if( IsTransparent() ) 639*cdf0e10cSrcweir aMask.CopyPixel( rRectDst, rRectSrc, &pBmpExSrc->aMask ); 640*cdf0e10cSrcweir else 641*cdf0e10cSrcweir { 642*cdf0e10cSrcweir aMask = Bitmap( GetSizePixel(), 1 ); 643*cdf0e10cSrcweir aMask.Erase( Color( COL_BLACK ) ); 644*cdf0e10cSrcweir eTransparent = TRANSPARENT_BITMAP; 645*cdf0e10cSrcweir aMask.CopyPixel( rRectDst, rRectSrc, &pBmpExSrc->aMask ); 646*cdf0e10cSrcweir } 647*cdf0e10cSrcweir } 648*cdf0e10cSrcweir else if( IsAlpha() ) 649*cdf0e10cSrcweir { 650*cdf0e10cSrcweir sal_uInt8 cBlack = 0; 651*cdf0e10cSrcweir const AlphaMask aAlphaSrc( pBmpExSrc->GetSizePixel(), &cBlack ); 652*cdf0e10cSrcweir 653*cdf0e10cSrcweir aMask.CopyPixel( rRectDst, rRectSrc, &aAlphaSrc.ImplGetBitmap() ); 654*cdf0e10cSrcweir } 655*cdf0e10cSrcweir else if( IsTransparent() ) 656*cdf0e10cSrcweir { 657*cdf0e10cSrcweir Bitmap aMaskSrc( pBmpExSrc->GetSizePixel(), 1 ); 658*cdf0e10cSrcweir 659*cdf0e10cSrcweir aMaskSrc.Erase( Color( COL_BLACK ) ); 660*cdf0e10cSrcweir aMask.CopyPixel( rRectDst, rRectSrc, &aMaskSrc ); 661*cdf0e10cSrcweir } 662*cdf0e10cSrcweir } 663*cdf0e10cSrcweir } 664*cdf0e10cSrcweir } 665*cdf0e10cSrcweir 666*cdf0e10cSrcweir return bRet; 667*cdf0e10cSrcweir } 668*cdf0e10cSrcweir 669*cdf0e10cSrcweir // ------------------------------------------------------------------ 670*cdf0e10cSrcweir 671*cdf0e10cSrcweir sal_Bool BitmapEx::Erase( const Color& rFillColor ) 672*cdf0e10cSrcweir { 673*cdf0e10cSrcweir sal_Bool bRet = sal_False; 674*cdf0e10cSrcweir 675*cdf0e10cSrcweir if( !!aBitmap ) 676*cdf0e10cSrcweir { 677*cdf0e10cSrcweir bRet = aBitmap.Erase( rFillColor ); 678*cdf0e10cSrcweir 679*cdf0e10cSrcweir if( bRet && ( eTransparent == TRANSPARENT_BITMAP ) && !!aMask ) 680*cdf0e10cSrcweir { 681*cdf0e10cSrcweir // #104416# Respect transparency on fill color 682*cdf0e10cSrcweir if( rFillColor.GetTransparency() ) 683*cdf0e10cSrcweir { 684*cdf0e10cSrcweir const Color aFill( rFillColor.GetTransparency(), rFillColor.GetTransparency(), rFillColor.GetTransparency() ); 685*cdf0e10cSrcweir aMask.Erase( aFill ); 686*cdf0e10cSrcweir } 687*cdf0e10cSrcweir else 688*cdf0e10cSrcweir { 689*cdf0e10cSrcweir const Color aBlack( COL_BLACK ); 690*cdf0e10cSrcweir aMask.Erase( aBlack ); 691*cdf0e10cSrcweir } 692*cdf0e10cSrcweir } 693*cdf0e10cSrcweir } 694*cdf0e10cSrcweir 695*cdf0e10cSrcweir return bRet; 696*cdf0e10cSrcweir } 697*cdf0e10cSrcweir 698*cdf0e10cSrcweir // ------------------------------------------------------------------ 699*cdf0e10cSrcweir 700*cdf0e10cSrcweir sal_Bool BitmapEx::Dither( sal_uLong nDitherFlags ) 701*cdf0e10cSrcweir { 702*cdf0e10cSrcweir return( !!aBitmap ? aBitmap.Dither( nDitherFlags ) : sal_False ); 703*cdf0e10cSrcweir } 704*cdf0e10cSrcweir 705*cdf0e10cSrcweir // ------------------------------------------------------------------ 706*cdf0e10cSrcweir 707*cdf0e10cSrcweir sal_Bool BitmapEx::Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uLong nTol ) 708*cdf0e10cSrcweir { 709*cdf0e10cSrcweir return( !!aBitmap ? aBitmap.Replace( rSearchColor, rReplaceColor, nTol ) : sal_False ); 710*cdf0e10cSrcweir } 711*cdf0e10cSrcweir 712*cdf0e10cSrcweir // ------------------------------------------------------------------ 713*cdf0e10cSrcweir 714*cdf0e10cSrcweir sal_Bool BitmapEx::Replace( const Color* pSearchColors, const Color* pReplaceColors, sal_uLong nColorCount, const sal_uLong* pTols ) 715*cdf0e10cSrcweir { 716*cdf0e10cSrcweir return( !!aBitmap ? aBitmap.Replace( pSearchColors, pReplaceColors, nColorCount, (sal_uLong*) pTols ) : sal_False ); 717*cdf0e10cSrcweir } 718*cdf0e10cSrcweir 719*cdf0e10cSrcweir // ------------------------------------------------------------------ 720*cdf0e10cSrcweir 721*cdf0e10cSrcweir sal_Bool BitmapEx::Adjust( short nLuminancePercent, short nContrastPercent, 722*cdf0e10cSrcweir short nChannelRPercent, short nChannelGPercent, short nChannelBPercent, 723*cdf0e10cSrcweir double fGamma, sal_Bool bInvert ) 724*cdf0e10cSrcweir { 725*cdf0e10cSrcweir return( !!aBitmap ? aBitmap.Adjust( nLuminancePercent, nContrastPercent, 726*cdf0e10cSrcweir nChannelRPercent, nChannelGPercent, nChannelBPercent, 727*cdf0e10cSrcweir fGamma, bInvert ) : sal_False ); 728*cdf0e10cSrcweir } 729*cdf0e10cSrcweir 730*cdf0e10cSrcweir // ------------------------------------------------------------------ 731*cdf0e10cSrcweir 732*cdf0e10cSrcweir sal_Bool BitmapEx::Filter( BmpFilter eFilter, const BmpFilterParam* pFilterParam, const Link* pProgress ) 733*cdf0e10cSrcweir { 734*cdf0e10cSrcweir return( !!aBitmap ? aBitmap.Filter( eFilter, pFilterParam, pProgress ) : sal_False ); 735*cdf0e10cSrcweir } 736*cdf0e10cSrcweir 737*cdf0e10cSrcweir // ------------------------------------------------------------------ 738*cdf0e10cSrcweir 739*cdf0e10cSrcweir void BitmapEx::Draw( OutputDevice* pOutDev, const Point& rDestPt ) const 740*cdf0e10cSrcweir { 741*cdf0e10cSrcweir pOutDev->DrawBitmapEx( rDestPt, *this ); 742*cdf0e10cSrcweir } 743*cdf0e10cSrcweir 744*cdf0e10cSrcweir // ------------------------------------------------------------------ 745*cdf0e10cSrcweir 746*cdf0e10cSrcweir void BitmapEx::Draw( OutputDevice* pOutDev, 747*cdf0e10cSrcweir const Point& rDestPt, const Size& rDestSize ) const 748*cdf0e10cSrcweir { 749*cdf0e10cSrcweir pOutDev->DrawBitmapEx( rDestPt, rDestSize, *this ); 750*cdf0e10cSrcweir } 751*cdf0e10cSrcweir 752*cdf0e10cSrcweir // ------------------------------------------------------------------ 753*cdf0e10cSrcweir 754*cdf0e10cSrcweir void BitmapEx::Draw( OutputDevice* pOutDev, 755*cdf0e10cSrcweir const Point& rDestPt, const Size& rDestSize, 756*cdf0e10cSrcweir const Point& rSrcPtPixel, const Size& rSrcSizePixel ) const 757*cdf0e10cSrcweir { 758*cdf0e10cSrcweir pOutDev->DrawBitmapEx( rDestPt, rDestSize, rSrcPtPixel, rSrcSizePixel, *this ); 759*cdf0e10cSrcweir } 760*cdf0e10cSrcweir 761*cdf0e10cSrcweir // ------------------------------------------------------------------ 762*cdf0e10cSrcweir 763*cdf0e10cSrcweir sal_uInt8 BitmapEx::GetTransparency(sal_Int32 nX, sal_Int32 nY) const 764*cdf0e10cSrcweir { 765*cdf0e10cSrcweir sal_uInt8 nTransparency(0xff); 766*cdf0e10cSrcweir 767*cdf0e10cSrcweir if(!aBitmap.IsEmpty()) 768*cdf0e10cSrcweir { 769*cdf0e10cSrcweir if(nX >= 0 && nX < aBitmapSize.Width() && nY >= 0 && nY < aBitmapSize.Height()) 770*cdf0e10cSrcweir { 771*cdf0e10cSrcweir switch(eTransparent) 772*cdf0e10cSrcweir { 773*cdf0e10cSrcweir case TRANSPARENT_NONE: 774*cdf0e10cSrcweir { 775*cdf0e10cSrcweir // not transparent, ergo all covered 776*cdf0e10cSrcweir nTransparency = 0x00; 777*cdf0e10cSrcweir break; 778*cdf0e10cSrcweir } 779*cdf0e10cSrcweir case TRANSPARENT_COLOR: 780*cdf0e10cSrcweir { 781*cdf0e10cSrcweir Bitmap aTestBitmap(aBitmap); 782*cdf0e10cSrcweir BitmapReadAccess* pRead = aTestBitmap.AcquireReadAccess(); 783*cdf0e10cSrcweir 784*cdf0e10cSrcweir if(pRead) 785*cdf0e10cSrcweir { 786*cdf0e10cSrcweir const Color aColor = pRead->GetColor(nY, nX); 787*cdf0e10cSrcweir 788*cdf0e10cSrcweir // if color is not equal to TransparentColor, we are not transparent 789*cdf0e10cSrcweir if(aColor != aTransparentColor) 790*cdf0e10cSrcweir { 791*cdf0e10cSrcweir nTransparency = 0x00; 792*cdf0e10cSrcweir } 793*cdf0e10cSrcweir 794*cdf0e10cSrcweir aTestBitmap.ReleaseAccess(pRead); 795*cdf0e10cSrcweir } 796*cdf0e10cSrcweir break; 797*cdf0e10cSrcweir } 798*cdf0e10cSrcweir case TRANSPARENT_BITMAP: 799*cdf0e10cSrcweir { 800*cdf0e10cSrcweir if(!aMask.IsEmpty()) 801*cdf0e10cSrcweir { 802*cdf0e10cSrcweir Bitmap aTestBitmap(aMask); 803*cdf0e10cSrcweir BitmapReadAccess* pRead = aTestBitmap.AcquireReadAccess(); 804*cdf0e10cSrcweir 805*cdf0e10cSrcweir if(pRead) 806*cdf0e10cSrcweir { 807*cdf0e10cSrcweir const BitmapColor aBitmapColor(pRead->GetPixel(nY, nX)); 808*cdf0e10cSrcweir 809*cdf0e10cSrcweir if(bAlpha) 810*cdf0e10cSrcweir { 811*cdf0e10cSrcweir nTransparency = aBitmapColor.GetIndex(); 812*cdf0e10cSrcweir } 813*cdf0e10cSrcweir else 814*cdf0e10cSrcweir { 815*cdf0e10cSrcweir if(0x00 == aBitmapColor.GetIndex()) 816*cdf0e10cSrcweir { 817*cdf0e10cSrcweir nTransparency = 0x00; 818*cdf0e10cSrcweir } 819*cdf0e10cSrcweir } 820*cdf0e10cSrcweir 821*cdf0e10cSrcweir aTestBitmap.ReleaseAccess(pRead); 822*cdf0e10cSrcweir } 823*cdf0e10cSrcweir } 824*cdf0e10cSrcweir break; 825*cdf0e10cSrcweir } 826*cdf0e10cSrcweir } 827*cdf0e10cSrcweir } 828*cdf0e10cSrcweir } 829*cdf0e10cSrcweir 830*cdf0e10cSrcweir return nTransparency; 831*cdf0e10cSrcweir } 832*cdf0e10cSrcweir 833*cdf0e10cSrcweir // ------------------------------------------------------------------ 834*cdf0e10cSrcweir 835*cdf0e10cSrcweir SvStream& operator<<( SvStream& rOStm, const BitmapEx& rBitmapEx ) 836*cdf0e10cSrcweir { 837*cdf0e10cSrcweir rBitmapEx.aBitmap.Write( rOStm ); 838*cdf0e10cSrcweir 839*cdf0e10cSrcweir rOStm << (sal_uInt32) 0x25091962; 840*cdf0e10cSrcweir rOStm << (sal_uInt32) 0xACB20201; 841*cdf0e10cSrcweir rOStm << (sal_uInt8) rBitmapEx.eTransparent; 842*cdf0e10cSrcweir 843*cdf0e10cSrcweir if( rBitmapEx.eTransparent == TRANSPARENT_BITMAP ) 844*cdf0e10cSrcweir rBitmapEx.aMask.Write( rOStm ); 845*cdf0e10cSrcweir else if( rBitmapEx.eTransparent == TRANSPARENT_COLOR ) 846*cdf0e10cSrcweir rOStm << rBitmapEx.aTransparentColor; 847*cdf0e10cSrcweir 848*cdf0e10cSrcweir return rOStm; 849*cdf0e10cSrcweir } 850*cdf0e10cSrcweir 851*cdf0e10cSrcweir // ------------------------------------------------------------------ 852*cdf0e10cSrcweir 853*cdf0e10cSrcweir SvStream& operator>>( SvStream& rIStm, BitmapEx& rBitmapEx ) 854*cdf0e10cSrcweir { 855*cdf0e10cSrcweir Bitmap aBmp; 856*cdf0e10cSrcweir 857*cdf0e10cSrcweir rIStm >> aBmp; 858*cdf0e10cSrcweir 859*cdf0e10cSrcweir if( !rIStm.GetError() ) 860*cdf0e10cSrcweir { 861*cdf0e10cSrcweir const sal_uLong nStmPos = rIStm.Tell(); 862*cdf0e10cSrcweir sal_uInt32 nMagic1 = 0; 863*cdf0e10cSrcweir sal_uInt32 nMagic2 = 0; 864*cdf0e10cSrcweir 865*cdf0e10cSrcweir rIStm >> nMagic1 >> nMagic2; 866*cdf0e10cSrcweir 867*cdf0e10cSrcweir if( ( nMagic1 != 0x25091962 ) || ( nMagic2 != 0xACB20201 ) || rIStm.GetError() ) 868*cdf0e10cSrcweir { 869*cdf0e10cSrcweir rIStm.ResetError(); 870*cdf0e10cSrcweir rIStm.Seek( nStmPos ); 871*cdf0e10cSrcweir rBitmapEx = aBmp; 872*cdf0e10cSrcweir } 873*cdf0e10cSrcweir else 874*cdf0e10cSrcweir { 875*cdf0e10cSrcweir sal_uInt8 bTransparent = false; 876*cdf0e10cSrcweir 877*cdf0e10cSrcweir rIStm >> bTransparent; 878*cdf0e10cSrcweir 879*cdf0e10cSrcweir if( bTransparent == (sal_uInt8) TRANSPARENT_BITMAP ) 880*cdf0e10cSrcweir { 881*cdf0e10cSrcweir Bitmap aMask; 882*cdf0e10cSrcweir 883*cdf0e10cSrcweir rIStm >> aMask; 884*cdf0e10cSrcweir 885*cdf0e10cSrcweir if( !!aMask) 886*cdf0e10cSrcweir { 887*cdf0e10cSrcweir // do we have an alpha mask? 888*cdf0e10cSrcweir if( ( 8 == aMask.GetBitCount() ) && aMask.HasGreyPalette() ) 889*cdf0e10cSrcweir { 890*cdf0e10cSrcweir AlphaMask aAlpha; 891*cdf0e10cSrcweir 892*cdf0e10cSrcweir // create alpha mask quickly (without greyscale conversion) 893*cdf0e10cSrcweir aAlpha.ImplSetBitmap( aMask ); 894*cdf0e10cSrcweir rBitmapEx = BitmapEx( aBmp, aAlpha ); 895*cdf0e10cSrcweir } 896*cdf0e10cSrcweir else 897*cdf0e10cSrcweir rBitmapEx = BitmapEx( aBmp, aMask ); 898*cdf0e10cSrcweir } 899*cdf0e10cSrcweir else 900*cdf0e10cSrcweir rBitmapEx = aBmp; 901*cdf0e10cSrcweir } 902*cdf0e10cSrcweir else if( bTransparent == (sal_uInt8) TRANSPARENT_COLOR ) 903*cdf0e10cSrcweir { 904*cdf0e10cSrcweir Color aTransparentColor; 905*cdf0e10cSrcweir 906*cdf0e10cSrcweir rIStm >> aTransparentColor; 907*cdf0e10cSrcweir rBitmapEx = BitmapEx( aBmp, aTransparentColor ); 908*cdf0e10cSrcweir } 909*cdf0e10cSrcweir else 910*cdf0e10cSrcweir rBitmapEx = aBmp; 911*cdf0e10cSrcweir } 912*cdf0e10cSrcweir } 913*cdf0e10cSrcweir 914*cdf0e10cSrcweir return rIStm; 915*cdf0e10cSrcweir } 916