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