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 10cdf0e10cSrcweir * 11*9f62ea84SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 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. 19cdf0e10cSrcweir * 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 <vcl/outdev.hxx> 28cdf0e10cSrcweir #include <vcl/bitmapex.hxx> 29cdf0e10cSrcweir #include <vcl/alpha.hxx> 30cdf0e10cSrcweir #include <vcl/window.hxx> 31cdf0e10cSrcweir #include <vcl/bmpacc.hxx> 32cdf0e10cSrcweir #include <vcl/virdev.hxx> 33cdf0e10cSrcweir #include <vcl/image.hxx> 34cdf0e10cSrcweir 35cdf0e10cSrcweir #include <image.h> 36cdf0e10cSrcweir 37cdf0e10cSrcweir // ----------- 38cdf0e10cSrcweir // - Defines - 39cdf0e10cSrcweir // ----------- 40cdf0e10cSrcweir 41cdf0e10cSrcweir #define IMPSYSIMAGEITEM_MASK ( 0x01 ) 42cdf0e10cSrcweir #define IMPSYSIMAGEITEM_ALPHA ( 0x02 ) 43cdf0e10cSrcweir #define DISA_ALL ( 0xffff ) 44cdf0e10cSrcweir 45cdf0e10cSrcweir // ---------------- 46cdf0e10cSrcweir // - ImageAryData - 47cdf0e10cSrcweir // ---------------- 48cdf0e10cSrcweir 49cdf0e10cSrcweir ImageAryData::ImageAryData() : 50cdf0e10cSrcweir maName(), 51cdf0e10cSrcweir mnId( 0 ), 52cdf0e10cSrcweir maBitmapEx() 53cdf0e10cSrcweir { 54cdf0e10cSrcweir } 55cdf0e10cSrcweir 56cdf0e10cSrcweir // ----------------------------------------------------------------------- 57cdf0e10cSrcweir 58cdf0e10cSrcweir ImageAryData::ImageAryData( const ImageAryData& rData ) : 59cdf0e10cSrcweir maName( rData.maName ), 60cdf0e10cSrcweir mnId( rData.mnId ), 61cdf0e10cSrcweir maBitmapEx( rData.maBitmapEx ) 62cdf0e10cSrcweir { 63cdf0e10cSrcweir } 64cdf0e10cSrcweir 65cdf0e10cSrcweir ImageAryData::ImageAryData( const rtl::OUString &aName, 66cdf0e10cSrcweir sal_uInt16 nId, const BitmapEx &aBitmap ) 67cdf0e10cSrcweir : maName( aName ), mnId( nId ), maBitmapEx( aBitmap ) 68cdf0e10cSrcweir { 69cdf0e10cSrcweir } 70cdf0e10cSrcweir 71cdf0e10cSrcweir // ----------------------------------------------------------------------- 72cdf0e10cSrcweir 73cdf0e10cSrcweir ImageAryData::~ImageAryData() 74cdf0e10cSrcweir { 75cdf0e10cSrcweir } 76cdf0e10cSrcweir 77cdf0e10cSrcweir // ----------------------------------------------------------------------- 78cdf0e10cSrcweir 79cdf0e10cSrcweir ImageAryData& ImageAryData::operator=( const ImageAryData& rData ) 80cdf0e10cSrcweir { 81cdf0e10cSrcweir maName = rData.maName; 82cdf0e10cSrcweir mnId = rData.mnId; 83cdf0e10cSrcweir maBitmapEx = rData.maBitmapEx; 84cdf0e10cSrcweir 85cdf0e10cSrcweir return *this; 86cdf0e10cSrcweir } 87cdf0e10cSrcweir 88cdf0e10cSrcweir // ----------------- 89cdf0e10cSrcweir // - ImplImageList - 90cdf0e10cSrcweir // ----------------- 91cdf0e10cSrcweir 92cdf0e10cSrcweir ImplImageList::ImplImageList() 93cdf0e10cSrcweir { 94cdf0e10cSrcweir } 95cdf0e10cSrcweir 96cdf0e10cSrcweir ImplImageList::ImplImageList( const ImplImageList &aSrc ) : 97cdf0e10cSrcweir maPrefix( aSrc.maPrefix ), 98cdf0e10cSrcweir maImageSize( aSrc.maImageSize ), 99cdf0e10cSrcweir mnRefCount( 1 ) 100cdf0e10cSrcweir { 101cdf0e10cSrcweir maImages.reserve( aSrc.maImages.size() ); 102cdf0e10cSrcweir for ( ImageAryDataVec::const_iterator aIt = aSrc.maImages.begin(), aEnd = aSrc.maImages.end(); aIt != aEnd; ++aIt ) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir ImageAryData* pAryData = new ImageAryData( **aIt ); 105cdf0e10cSrcweir maImages.push_back( pAryData ); 106cdf0e10cSrcweir if( pAryData->maName.getLength() ) 107cdf0e10cSrcweir maNameHash [ pAryData->maName ] = pAryData; 108cdf0e10cSrcweir } 109cdf0e10cSrcweir } 110cdf0e10cSrcweir 111cdf0e10cSrcweir ImplImageList::~ImplImageList() 112cdf0e10cSrcweir { 113cdf0e10cSrcweir for ( ImageAryDataVec::iterator aIt = maImages.begin(), aEnd = maImages.end(); aIt != aEnd; ++aIt ) 114cdf0e10cSrcweir delete *aIt; 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 117cdf0e10cSrcweir void ImplImageList::AddImage( const ::rtl::OUString &aName, 118cdf0e10cSrcweir sal_uInt16 nId, const BitmapEx &aBitmapEx ) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir ImageAryData *pImg = new ImageAryData( aName, nId, aBitmapEx ); 121cdf0e10cSrcweir maImages.push_back( pImg ); 122cdf0e10cSrcweir if( aName.getLength() ) 123cdf0e10cSrcweir maNameHash [ aName ] = pImg; 124cdf0e10cSrcweir } 125cdf0e10cSrcweir 126cdf0e10cSrcweir void ImplImageList::RemoveImage( sal_uInt16 nPos ) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir ImageAryData *pImg = maImages[ nPos ]; 129cdf0e10cSrcweir if( pImg->maName.getLength() ) 130cdf0e10cSrcweir maNameHash.erase( pImg->maName ); 131cdf0e10cSrcweir maImages.erase( maImages.begin() + nPos ); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir 134cdf0e10cSrcweir sal_uInt16 ImplImageList::GetImageCount() const 135cdf0e10cSrcweir { 136cdf0e10cSrcweir return sal::static_int_cast< sal_uInt16 >( maImages.size() ); 137cdf0e10cSrcweir } 138cdf0e10cSrcweir 139cdf0e10cSrcweir // ----------------- 140cdf0e10cSrcweir // - ImplImageData - 141cdf0e10cSrcweir // ----------------- 142cdf0e10cSrcweir 143cdf0e10cSrcweir ImplImageData::ImplImageData( const BitmapEx& rBmpEx ) : 144cdf0e10cSrcweir mpImageBitmap( NULL ), 145cdf0e10cSrcweir maBmpEx( rBmpEx ) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir } 148cdf0e10cSrcweir 149cdf0e10cSrcweir // ----------------------------------------------------------------------- 150cdf0e10cSrcweir 151cdf0e10cSrcweir ImplImageData::~ImplImageData() 152cdf0e10cSrcweir { 153cdf0e10cSrcweir delete mpImageBitmap; 154cdf0e10cSrcweir } 155cdf0e10cSrcweir 156cdf0e10cSrcweir // ----------------- 157cdf0e10cSrcweir // - ImplImageData - 158cdf0e10cSrcweir // ----------------- 159cdf0e10cSrcweir 160cdf0e10cSrcweir sal_Bool ImplImageData::IsEqual( const ImplImageData& rData ) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir return( maBmpEx == rData.maBmpEx ); 163cdf0e10cSrcweir } 164cdf0e10cSrcweir 165cdf0e10cSrcweir // ------------- 166cdf0e10cSrcweir // - ImplImage - 167cdf0e10cSrcweir // ------------- 168cdf0e10cSrcweir 169cdf0e10cSrcweir ImplImage::ImplImage() 170cdf0e10cSrcweir { 171cdf0e10cSrcweir } 172cdf0e10cSrcweir 173cdf0e10cSrcweir // ------------------------------------------------------------------------------ 174cdf0e10cSrcweir 175cdf0e10cSrcweir ImplImage::~ImplImage() 176cdf0e10cSrcweir { 177cdf0e10cSrcweir switch( meType ) 178cdf0e10cSrcweir { 179cdf0e10cSrcweir case IMAGETYPE_BITMAP: 180cdf0e10cSrcweir delete static_cast< Bitmap* >( mpData ); 181cdf0e10cSrcweir break; 182cdf0e10cSrcweir 183cdf0e10cSrcweir case IMAGETYPE_IMAGE: 184cdf0e10cSrcweir delete static_cast< ImplImageData* >( mpData ); 185cdf0e10cSrcweir break; 186cdf0e10cSrcweir } 187cdf0e10cSrcweir } 188cdf0e10cSrcweir 189cdf0e10cSrcweir // ---------------- 190cdf0e10cSrcweir // - ImplImageBmp - 191cdf0e10cSrcweir // ---------------- 192cdf0e10cSrcweir 193cdf0e10cSrcweir ImplImageBmp::ImplImageBmp() : 194cdf0e10cSrcweir mpDisplayBmp( NULL ), 195cdf0e10cSrcweir mpInfoAry( NULL ), 196cdf0e10cSrcweir mnSize( 0 ) 197cdf0e10cSrcweir { 198cdf0e10cSrcweir } 199cdf0e10cSrcweir 200cdf0e10cSrcweir // ------------- 201cdf0e10cSrcweir // - ImplImage - 202cdf0e10cSrcweir // ------------- 203cdf0e10cSrcweir 204cdf0e10cSrcweir ImplImageBmp::~ImplImageBmp() 205cdf0e10cSrcweir { 206cdf0e10cSrcweir delete[] mpInfoAry; 207cdf0e10cSrcweir delete mpDisplayBmp; 208cdf0e10cSrcweir } 209cdf0e10cSrcweir 210cdf0e10cSrcweir // ----------------------------------------------------------------------- 211cdf0e10cSrcweir 212cdf0e10cSrcweir void ImplImageBmp::Create( long nItemWidth, long nItemHeight, sal_uInt16 nInitSize ) 213cdf0e10cSrcweir { 214cdf0e10cSrcweir const Size aTotalSize( nInitSize * nItemWidth, nItemHeight ); 215cdf0e10cSrcweir 216cdf0e10cSrcweir maBmpEx = Bitmap( aTotalSize, 24 ); 217cdf0e10cSrcweir maDisabledBmpEx.SetEmpty(); 218cdf0e10cSrcweir 219cdf0e10cSrcweir delete mpDisplayBmp; 220cdf0e10cSrcweir mpDisplayBmp = NULL; 221cdf0e10cSrcweir 222cdf0e10cSrcweir maSize = Size( nItemWidth, nItemHeight ); 223cdf0e10cSrcweir mnSize = nInitSize; 224cdf0e10cSrcweir 225cdf0e10cSrcweir delete[] mpInfoAry; 226cdf0e10cSrcweir mpInfoAry = new sal_uInt8[ mnSize ]; 227cdf0e10cSrcweir memset( mpInfoAry, 0, mnSize ); 228cdf0e10cSrcweir } 229cdf0e10cSrcweir 230cdf0e10cSrcweir // ----------------------------------------------------------------------- 231cdf0e10cSrcweir 232cdf0e10cSrcweir void ImplImageBmp::Create( const BitmapEx& rBmpEx, long nItemWidth, long nItemHeight, sal_uInt16 nInitSize ) 233cdf0e10cSrcweir { 234cdf0e10cSrcweir maBmpEx = rBmpEx; 235cdf0e10cSrcweir maDisabledBmpEx.SetEmpty(); 236cdf0e10cSrcweir 237cdf0e10cSrcweir delete mpDisplayBmp; 238cdf0e10cSrcweir mpDisplayBmp = NULL; 239cdf0e10cSrcweir 240cdf0e10cSrcweir maSize = Size( nItemWidth, nItemHeight ); 241cdf0e10cSrcweir mnSize = nInitSize; 242cdf0e10cSrcweir 243cdf0e10cSrcweir delete[] mpInfoAry; 244cdf0e10cSrcweir mpInfoAry = new sal_uInt8[ mnSize ]; 245cdf0e10cSrcweir memset( mpInfoAry, 246cdf0e10cSrcweir rBmpEx.IsAlpha() ? IMPSYSIMAGEITEM_ALPHA : ( rBmpEx.IsTransparent() ? IMPSYSIMAGEITEM_MASK : 0 ), 247cdf0e10cSrcweir mnSize ); 248cdf0e10cSrcweir } 249cdf0e10cSrcweir 250cdf0e10cSrcweir // ----------------------------------------------------------------------- 251cdf0e10cSrcweir 252cdf0e10cSrcweir void ImplImageBmp::Expand( sal_uInt16 nGrowSize ) 253cdf0e10cSrcweir { 254cdf0e10cSrcweir const sal_uLong nDX = nGrowSize * maSize.Width(); 255cdf0e10cSrcweir const sal_uInt16 nOldSize = mnSize; 256cdf0e10cSrcweir sal_uInt8* pNewAry = new sal_uInt8[ mnSize = sal::static_int_cast<sal_uInt16>(mnSize+nGrowSize) ]; 257cdf0e10cSrcweir 258cdf0e10cSrcweir maBmpEx.Expand( nDX, 0UL ); 259cdf0e10cSrcweir 260cdf0e10cSrcweir if( !maDisabledBmpEx.IsEmpty() ) 261cdf0e10cSrcweir maDisabledBmpEx.Expand( nDX, 0UL ); 262cdf0e10cSrcweir 263cdf0e10cSrcweir delete mpDisplayBmp; 264cdf0e10cSrcweir mpDisplayBmp = NULL; 265cdf0e10cSrcweir 266cdf0e10cSrcweir memset( pNewAry, 0, mnSize ); 267cdf0e10cSrcweir memcpy( pNewAry, mpInfoAry, nOldSize ); 268cdf0e10cSrcweir delete[] mpInfoAry; 269cdf0e10cSrcweir mpInfoAry = pNewAry; 270cdf0e10cSrcweir } 271cdf0e10cSrcweir 272cdf0e10cSrcweir // ----------------------------------------------------------------------- 273cdf0e10cSrcweir 274cdf0e10cSrcweir void ImplImageBmp::Invert() 275cdf0e10cSrcweir { 276cdf0e10cSrcweir delete mpDisplayBmp; 277cdf0e10cSrcweir mpDisplayBmp = NULL; 278cdf0e10cSrcweir 279cdf0e10cSrcweir maBmpEx.Invert(); 280cdf0e10cSrcweir } 281cdf0e10cSrcweir 282cdf0e10cSrcweir // ----------------------------------------------------------------------- 283cdf0e10cSrcweir 284cdf0e10cSrcweir void ImplImageBmp::Replace( sal_uInt16 nPos, sal_uInt16 nSrcPos ) 285cdf0e10cSrcweir { 286cdf0e10cSrcweir const Point aSrcPos( nSrcPos * maSize.Width(), 0L ), aPos( nPos * maSize.Width(), 0L ); 287cdf0e10cSrcweir const Rectangle aSrcRect( aSrcPos, maSize ); 288cdf0e10cSrcweir const Rectangle aDstRect( aPos, maSize ); 289cdf0e10cSrcweir 290cdf0e10cSrcweir maBmpEx.CopyPixel( aDstRect, aSrcRect ); 291cdf0e10cSrcweir 292cdf0e10cSrcweir if( !maDisabledBmpEx.IsEmpty() ) 293cdf0e10cSrcweir maDisabledBmpEx.CopyPixel( aDstRect, aSrcRect ); 294cdf0e10cSrcweir 295cdf0e10cSrcweir delete mpDisplayBmp; 296cdf0e10cSrcweir mpDisplayBmp = NULL; 297cdf0e10cSrcweir 298cdf0e10cSrcweir mpInfoAry[ nPos ] = mpInfoAry[ nSrcPos ]; 299cdf0e10cSrcweir } 300cdf0e10cSrcweir 301cdf0e10cSrcweir // ----------------------------------------------------------------------- 302cdf0e10cSrcweir 303cdf0e10cSrcweir void ImplImageBmp::Replace( sal_uInt16 nPos, const ImplImageBmp& rImageBmp, sal_uInt16 nSrcPos ) 304cdf0e10cSrcweir { 305cdf0e10cSrcweir const Point aSrcPos( nSrcPos * maSize.Width(), 0L ), aPos( nPos * maSize.Width(), 0L ); 306cdf0e10cSrcweir const Rectangle aSrcRect( aSrcPos, maSize ); 307cdf0e10cSrcweir const Rectangle aDstRect( aPos, maSize ); 308cdf0e10cSrcweir 309cdf0e10cSrcweir maBmpEx.CopyPixel( aDstRect, aSrcRect, &rImageBmp.maBmpEx ); 310cdf0e10cSrcweir 311cdf0e10cSrcweir ImplUpdateDisabledBmpEx( nPos ); 312cdf0e10cSrcweir delete mpDisplayBmp; 313cdf0e10cSrcweir mpDisplayBmp = NULL; 314cdf0e10cSrcweir 315cdf0e10cSrcweir mpInfoAry[ nPos ] = rImageBmp.mpInfoAry[ nSrcPos ]; 316cdf0e10cSrcweir } 317cdf0e10cSrcweir 318cdf0e10cSrcweir // ----------------------------------------------------------------------- 319cdf0e10cSrcweir 320cdf0e10cSrcweir void ImplImageBmp::Replace( sal_uInt16 nPos, const BitmapEx& rBmpEx ) 321cdf0e10cSrcweir { 322cdf0e10cSrcweir const Point aNullPos, aPos( nPos * maSize.Width(), 0L ); 323cdf0e10cSrcweir const Rectangle aSrcRect( aNullPos, maSize ); 324cdf0e10cSrcweir const Rectangle aDstRect( aPos, maSize ); 325cdf0e10cSrcweir 326cdf0e10cSrcweir maBmpEx.CopyPixel( aDstRect, aSrcRect, &rBmpEx ); 327cdf0e10cSrcweir 328cdf0e10cSrcweir ImplUpdateDisabledBmpEx( nPos ); 329cdf0e10cSrcweir delete mpDisplayBmp; 330cdf0e10cSrcweir mpDisplayBmp = NULL; 331cdf0e10cSrcweir 332cdf0e10cSrcweir mpInfoAry[ nPos ] &= ~( IMPSYSIMAGEITEM_MASK | IMPSYSIMAGEITEM_ALPHA ); 333cdf0e10cSrcweir mpInfoAry[ nPos ] |= ( rBmpEx.IsAlpha() ? IMPSYSIMAGEITEM_ALPHA : ( rBmpEx.IsTransparent() ? IMPSYSIMAGEITEM_MASK : 0 ) ); 334cdf0e10cSrcweir } 335cdf0e10cSrcweir 336cdf0e10cSrcweir // ----------------------------------------------------------------------- 337cdf0e10cSrcweir 338cdf0e10cSrcweir void ImplImageBmp::ReplaceColors( const Color* pSrcColors, const Color* pDstColors, sal_uLong nColorCount ) 339cdf0e10cSrcweir { 340cdf0e10cSrcweir maBmpEx.Replace( pSrcColors, pDstColors, nColorCount ); 341cdf0e10cSrcweir delete mpDisplayBmp; 342cdf0e10cSrcweir mpDisplayBmp = NULL; 343cdf0e10cSrcweir } 344cdf0e10cSrcweir 345cdf0e10cSrcweir // ----------------------------------------------------------------------- 346cdf0e10cSrcweir 347cdf0e10cSrcweir void ImplImageBmp::ColorTransform( BmpColorMode eColorMode ) 348cdf0e10cSrcweir { 349cdf0e10cSrcweir maBmpEx = maBmpEx.GetColorTransformedBitmapEx( eColorMode ); 350cdf0e10cSrcweir delete mpDisplayBmp; 351cdf0e10cSrcweir mpDisplayBmp = NULL; 352cdf0e10cSrcweir } 353cdf0e10cSrcweir 354cdf0e10cSrcweir // ----------------------------------------------------------------------- 355cdf0e10cSrcweir 356cdf0e10cSrcweir BitmapEx ImplImageBmp::GetBitmapEx( sal_uInt16 nPosCount, sal_uInt16* pPosAry ) const 357cdf0e10cSrcweir { 358cdf0e10cSrcweir const Bitmap aNewBmp( Size( nPosCount * maSize.Width(), maSize.Height() ), maBmpEx.GetBitmap().GetBitCount() ); 359cdf0e10cSrcweir BitmapEx aRet; 360cdf0e10cSrcweir if( maBmpEx.IsAlpha() ) 361cdf0e10cSrcweir { 362cdf0e10cSrcweir // initialize target bitmap with an empty alpha mask 363cdf0e10cSrcweir // which allows for using an optimized copypixel later on (see AlphaMask::CopyPixel) 364cdf0e10cSrcweir // that avoids palette lookups 365cdf0e10cSrcweir AlphaMask aAlpha( Size( nPosCount * maSize.Width(), maSize.Height() ) ); 366cdf0e10cSrcweir aRet = BitmapEx( aNewBmp, aAlpha ); 367cdf0e10cSrcweir } 368cdf0e10cSrcweir else 369cdf0e10cSrcweir aRet = BitmapEx( aNewBmp ); 370cdf0e10cSrcweir 371cdf0e10cSrcweir for( sal_uInt16 i = 0; i < nPosCount; i++ ) 372cdf0e10cSrcweir { 373cdf0e10cSrcweir const Point aSrcPos( pPosAry[ i ] * maSize.Width(), 0L ); 374cdf0e10cSrcweir const Point aPos( i * maSize.Width(), 0L ); 375cdf0e10cSrcweir const Rectangle aSrcRect( aSrcPos, maSize ); 376cdf0e10cSrcweir const Rectangle aDstRect( aPos, maSize ); 377cdf0e10cSrcweir 378cdf0e10cSrcweir aRet.CopyPixel( aDstRect, aSrcRect, &maBmpEx ); 379cdf0e10cSrcweir } 380cdf0e10cSrcweir 381cdf0e10cSrcweir return aRet; 382cdf0e10cSrcweir } 383cdf0e10cSrcweir 384cdf0e10cSrcweir // ----------------------------------------------------------------------- 385cdf0e10cSrcweir 386cdf0e10cSrcweir void ImplImageBmp::Draw( sal_uInt16 nPos, OutputDevice* pOutDev, 387cdf0e10cSrcweir const Point& rPos, sal_uInt16 nStyle, 388cdf0e10cSrcweir const Size* pSize ) 389cdf0e10cSrcweir { 390cdf0e10cSrcweir if( pOutDev->IsDeviceOutputNecessary() ) 391cdf0e10cSrcweir { 392cdf0e10cSrcweir const Point aSrcPos( nPos * maSize.Width(), 0 ); 393cdf0e10cSrcweir Size aOutSize; 394cdf0e10cSrcweir 395cdf0e10cSrcweir aOutSize = ( pSize ? *pSize : pOutDev->PixelToLogic( maSize ) ); 396cdf0e10cSrcweir 397cdf0e10cSrcweir if( nStyle & IMAGE_DRAW_DISABLE ) 398cdf0e10cSrcweir { 399cdf0e10cSrcweir ImplUpdateDisabledBmpEx( nPos); 400cdf0e10cSrcweir pOutDev->DrawBitmapEx( rPos, aOutSize, aSrcPos, maSize, maDisabledBmpEx ); 401cdf0e10cSrcweir } 402cdf0e10cSrcweir else 403cdf0e10cSrcweir { 404cdf0e10cSrcweir if( nStyle & ( IMAGE_DRAW_COLORTRANSFORM | 405cdf0e10cSrcweir IMAGE_DRAW_MONOCHROME_BLACK | IMAGE_DRAW_MONOCHROME_WHITE | 406cdf0e10cSrcweir IMAGE_DRAW_HIGHLIGHT | IMAGE_DRAW_DEACTIVE | IMAGE_DRAW_SEMITRANSPARENT ) ) 407cdf0e10cSrcweir { 408cdf0e10cSrcweir BitmapEx aTmpBmpEx; 409cdf0e10cSrcweir const Rectangle aCropRect( aSrcPos, maSize ); 410cdf0e10cSrcweir 411cdf0e10cSrcweir if( mpInfoAry[ nPos ] & ( IMPSYSIMAGEITEM_MASK | IMPSYSIMAGEITEM_ALPHA ) ) 412cdf0e10cSrcweir aTmpBmpEx = maBmpEx; 413cdf0e10cSrcweir else 414cdf0e10cSrcweir aTmpBmpEx = maBmpEx.GetBitmap(); 415cdf0e10cSrcweir 416cdf0e10cSrcweir aTmpBmpEx.Crop( aCropRect ); 417cdf0e10cSrcweir 418cdf0e10cSrcweir if( nStyle & ( IMAGE_DRAW_COLORTRANSFORM | IMAGE_DRAW_MONOCHROME_BLACK | IMAGE_DRAW_MONOCHROME_WHITE ) ) 419cdf0e10cSrcweir { 420cdf0e10cSrcweir const BmpColorMode eMode = ( nStyle & IMAGE_DRAW_COLORTRANSFORM ) ? BMP_COLOR_HIGHCONTRAST : 421cdf0e10cSrcweir ( ( nStyle & IMAGE_DRAW_MONOCHROME_BLACK ) ? BMP_COLOR_MONOCHROME_BLACK : BMP_COLOR_MONOCHROME_WHITE ); 422cdf0e10cSrcweir 423cdf0e10cSrcweir aTmpBmpEx = aTmpBmpEx.GetColorTransformedBitmapEx( eMode ); 424cdf0e10cSrcweir } 425cdf0e10cSrcweir 426cdf0e10cSrcweir Bitmap aTmpBmp( aTmpBmpEx.GetBitmap() ); 427cdf0e10cSrcweir 428cdf0e10cSrcweir if( nStyle & ( IMAGE_DRAW_HIGHLIGHT | IMAGE_DRAW_DEACTIVE ) ) 429cdf0e10cSrcweir { 430cdf0e10cSrcweir BitmapWriteAccess* pAcc = aTmpBmp.AcquireWriteAccess(); 431cdf0e10cSrcweir 432cdf0e10cSrcweir if( pAcc ) 433cdf0e10cSrcweir { 434cdf0e10cSrcweir const StyleSettings& rSettings = pOutDev->GetSettings().GetStyleSettings(); 435cdf0e10cSrcweir Color aColor; 436cdf0e10cSrcweir BitmapColor aCol; 437cdf0e10cSrcweir const long nW = pAcc->Width(); 438cdf0e10cSrcweir const long nH = pAcc->Height(); 439cdf0e10cSrcweir sal_uInt8* pMapR = new sal_uInt8[ 256 ]; 440cdf0e10cSrcweir sal_uInt8* pMapG = new sal_uInt8[ 256 ]; 441cdf0e10cSrcweir sal_uInt8* pMapB = new sal_uInt8[ 256 ]; 442cdf0e10cSrcweir long nX, nY; 443cdf0e10cSrcweir 444cdf0e10cSrcweir if( nStyle & IMAGE_DRAW_HIGHLIGHT ) 445cdf0e10cSrcweir aColor = rSettings.GetHighlightColor(); 446cdf0e10cSrcweir else 447cdf0e10cSrcweir aColor = rSettings.GetDeactiveColor(); 448cdf0e10cSrcweir 449cdf0e10cSrcweir const sal_uInt8 cR = aColor.GetRed(); 450cdf0e10cSrcweir const sal_uInt8 cG = aColor.GetGreen(); 451cdf0e10cSrcweir const sal_uInt8 cB = aColor.GetBlue(); 452cdf0e10cSrcweir 453cdf0e10cSrcweir for( nX = 0L; nX < 256L; nX++ ) 454cdf0e10cSrcweir { 455cdf0e10cSrcweir pMapR[ nX ] = (sal_uInt8) ( ( ( nY = ( nX + cR ) >> 1 ) > 255 ) ? 255 : nY ); 456cdf0e10cSrcweir pMapG[ nX ] = (sal_uInt8) ( ( ( nY = ( nX + cG ) >> 1 ) > 255 ) ? 255 : nY ); 457cdf0e10cSrcweir pMapB[ nX ] = (sal_uInt8) ( ( ( nY = ( nX + cB ) >> 1 ) > 255 ) ? 255 : nY ); 458cdf0e10cSrcweir } 459cdf0e10cSrcweir 460cdf0e10cSrcweir if( pAcc->HasPalette() ) 461cdf0e10cSrcweir { 462cdf0e10cSrcweir for( sal_uInt16 i = 0, nCount = pAcc->GetPaletteEntryCount(); i < nCount; i++ ) 463cdf0e10cSrcweir { 464cdf0e10cSrcweir const BitmapColor& rCol = pAcc->GetPaletteColor( i ); 465cdf0e10cSrcweir aCol.SetRed( pMapR[ rCol.GetRed() ] ); 466cdf0e10cSrcweir aCol.SetGreen( pMapG[ rCol.GetGreen() ] ); 467cdf0e10cSrcweir aCol.SetBlue( pMapB[ rCol.GetBlue() ] ); 468cdf0e10cSrcweir pAcc->SetPaletteColor( i, aCol ); 469cdf0e10cSrcweir } 470cdf0e10cSrcweir } 471cdf0e10cSrcweir else if( pAcc->GetScanlineFormat() == BMP_FORMAT_24BIT_TC_BGR ) 472cdf0e10cSrcweir { 473cdf0e10cSrcweir for( nY = 0L; nY < nH; nY++ ) 474cdf0e10cSrcweir { 475cdf0e10cSrcweir Scanline pScan = pAcc->GetScanline( nY ); 476cdf0e10cSrcweir 477cdf0e10cSrcweir for( nX = 0L; nX < nW; nX++ ) 478cdf0e10cSrcweir { 479cdf0e10cSrcweir *pScan = pMapB[ *pScan ]; pScan++; 480cdf0e10cSrcweir *pScan = pMapG[ *pScan ]; pScan++; 481cdf0e10cSrcweir *pScan = pMapR[ *pScan ]; pScan++; 482cdf0e10cSrcweir } 483cdf0e10cSrcweir } 484cdf0e10cSrcweir } 485cdf0e10cSrcweir else 486cdf0e10cSrcweir { 487cdf0e10cSrcweir for( nY = 0L; nY < nH; nY++ ) 488cdf0e10cSrcweir { 489cdf0e10cSrcweir for( nX = 0L; nX < nW; nX++ ) 490cdf0e10cSrcweir { 491cdf0e10cSrcweir aCol = pAcc->GetPixel( nY, nX ); 492cdf0e10cSrcweir aCol.SetRed( pMapR[ aCol.GetRed() ] ); 493cdf0e10cSrcweir aCol.SetGreen( pMapG[ aCol.GetGreen() ] ); 494cdf0e10cSrcweir aCol.SetBlue( pMapB[ aCol.GetBlue() ] ); 495cdf0e10cSrcweir pAcc->SetPixel( nY, nX, aCol ); 496cdf0e10cSrcweir } 497cdf0e10cSrcweir } 498cdf0e10cSrcweir } 499cdf0e10cSrcweir 500cdf0e10cSrcweir delete[] pMapR; 501cdf0e10cSrcweir delete[] pMapG; 502cdf0e10cSrcweir delete[] pMapB; 503cdf0e10cSrcweir aTmpBmp.ReleaseAccess( pAcc ); 504cdf0e10cSrcweir } 505cdf0e10cSrcweir } 506cdf0e10cSrcweir 507cdf0e10cSrcweir if( nStyle & IMAGE_DRAW_SEMITRANSPARENT ) 508cdf0e10cSrcweir { 509cdf0e10cSrcweir if( aTmpBmpEx.IsTransparent() ) 510cdf0e10cSrcweir { 511cdf0e10cSrcweir Bitmap aAlphaBmp( aTmpBmpEx.GetAlpha().GetBitmap() ); 512cdf0e10cSrcweir 513cdf0e10cSrcweir aAlphaBmp.Adjust( 50 ); 514cdf0e10cSrcweir aTmpBmpEx = BitmapEx( aTmpBmp, AlphaMask( aAlphaBmp ) ); 515cdf0e10cSrcweir } 516cdf0e10cSrcweir else 517cdf0e10cSrcweir { 518cdf0e10cSrcweir sal_uInt8 cErase = 128; 519cdf0e10cSrcweir aTmpBmpEx = BitmapEx( aTmpBmp, AlphaMask( aTmpBmp.GetSizePixel(), &cErase ) ); 520cdf0e10cSrcweir } 521cdf0e10cSrcweir } 522cdf0e10cSrcweir else 523cdf0e10cSrcweir { 524cdf0e10cSrcweir if( aTmpBmpEx.IsAlpha() ) 525cdf0e10cSrcweir aTmpBmpEx = BitmapEx( aTmpBmp, aTmpBmpEx.GetAlpha() ); 526cdf0e10cSrcweir else if( aTmpBmpEx.IsAlpha() ) 527cdf0e10cSrcweir aTmpBmpEx = BitmapEx( aTmpBmp, aTmpBmpEx.GetMask() ); 528cdf0e10cSrcweir } 529cdf0e10cSrcweir 530cdf0e10cSrcweir pOutDev->DrawBitmapEx( rPos, aOutSize, aTmpBmpEx ); 531cdf0e10cSrcweir } 532cdf0e10cSrcweir else 533cdf0e10cSrcweir { 534cdf0e10cSrcweir const BitmapEx* pOutputBmp; 535cdf0e10cSrcweir 536cdf0e10cSrcweir if( pOutDev->GetOutDevType() == OUTDEV_WINDOW ) 537cdf0e10cSrcweir { 538cdf0e10cSrcweir ImplUpdateDisplayBmp( pOutDev ); 539cdf0e10cSrcweir pOutputBmp = mpDisplayBmp; 540cdf0e10cSrcweir } 541cdf0e10cSrcweir else 542cdf0e10cSrcweir pOutputBmp = &maBmpEx; 543cdf0e10cSrcweir 544cdf0e10cSrcweir if( pOutputBmp ) 545cdf0e10cSrcweir pOutDev->DrawBitmapEx( rPos, aOutSize, aSrcPos, maSize, *pOutputBmp ); 546cdf0e10cSrcweir } 547cdf0e10cSrcweir } 548cdf0e10cSrcweir } 549cdf0e10cSrcweir } 550cdf0e10cSrcweir 551cdf0e10cSrcweir // ----------------------------------------------------------------------- 552cdf0e10cSrcweir 553cdf0e10cSrcweir void ImplImageBmp::ImplUpdateDisplayBmp( OutputDevice* 554cdf0e10cSrcweir #if defined WNT 555cdf0e10cSrcweir pOutDev 556cdf0e10cSrcweir #endif 557cdf0e10cSrcweir ) 558cdf0e10cSrcweir { 559cdf0e10cSrcweir if( !mpDisplayBmp && !maBmpEx.IsEmpty() ) 560cdf0e10cSrcweir { 561cdf0e10cSrcweir #if defined WNT 562cdf0e10cSrcweir if( maBmpEx.IsAlpha() ) 563cdf0e10cSrcweir mpDisplayBmp = new BitmapEx( maBmpEx ); 564cdf0e10cSrcweir else 565cdf0e10cSrcweir { 566cdf0e10cSrcweir const Bitmap aBmp( maBmpEx.GetBitmap().CreateDisplayBitmap( pOutDev ) ); 567cdf0e10cSrcweir 568cdf0e10cSrcweir if( maBmpEx.IsTransparent() ) 569cdf0e10cSrcweir mpDisplayBmp = new BitmapEx( aBmp, maBmpEx.GetMask().CreateDisplayBitmap( pOutDev ) ); 570cdf0e10cSrcweir else 571cdf0e10cSrcweir mpDisplayBmp = new BitmapEx( aBmp ); 572cdf0e10cSrcweir } 573cdf0e10cSrcweir #else 574cdf0e10cSrcweir mpDisplayBmp = new BitmapEx( maBmpEx ); 575cdf0e10cSrcweir #endif 576cdf0e10cSrcweir } 577cdf0e10cSrcweir } 578cdf0e10cSrcweir 579cdf0e10cSrcweir // ----------------------------------------------------------------------- 580cdf0e10cSrcweir 581cdf0e10cSrcweir void ImplImageBmp::ImplUpdateDisabledBmpEx( int nPos ) 582cdf0e10cSrcweir { 583cdf0e10cSrcweir const Size aTotalSize( maBmpEx.GetSizePixel() ); 584cdf0e10cSrcweir 585cdf0e10cSrcweir if( maDisabledBmpEx.IsEmpty() ) 586cdf0e10cSrcweir { 587cdf0e10cSrcweir Bitmap aGrey( aTotalSize, 8, &Bitmap::GetGreyPalette( 256 ) ); 588cdf0e10cSrcweir AlphaMask aGreyAlphaMask( aTotalSize ); 589cdf0e10cSrcweir 590cdf0e10cSrcweir maDisabledBmpEx = BitmapEx( aGrey, aGreyAlphaMask ); 591cdf0e10cSrcweir nPos = -1; 592cdf0e10cSrcweir } 593cdf0e10cSrcweir 594cdf0e10cSrcweir Bitmap aBmp( maBmpEx.GetBitmap() ); 595cdf0e10cSrcweir BitmapReadAccess* pBmp( aBmp.AcquireReadAccess() ); 596cdf0e10cSrcweir AlphaMask aBmpAlphaMask( maBmpEx.GetAlpha() ); 597cdf0e10cSrcweir BitmapReadAccess* pBmpAlphaMask( aBmpAlphaMask.AcquireReadAccess() ); 598cdf0e10cSrcweir Bitmap aGrey( maDisabledBmpEx.GetBitmap() ); 599cdf0e10cSrcweir BitmapWriteAccess* pGrey( aGrey.AcquireWriteAccess() ); 600cdf0e10cSrcweir AlphaMask aGreyAlphaMask( maDisabledBmpEx.GetAlpha() ); 601cdf0e10cSrcweir BitmapWriteAccess* pGreyAlphaMask( aGreyAlphaMask.AcquireWriteAccess() ); 602cdf0e10cSrcweir 603cdf0e10cSrcweir if( pBmp && pBmpAlphaMask && pGrey && pGreyAlphaMask ) 604cdf0e10cSrcweir { 605cdf0e10cSrcweir BitmapColor aGreyVal( 0 ); 606cdf0e10cSrcweir BitmapColor aGreyAlphaMaskVal( 0 ); 607cdf0e10cSrcweir const Point aPos( ( nPos < 0 ) ? 0 : ( nPos * maSize.Width() ), 0 ); 608cdf0e10cSrcweir const int nLeft = aPos.X(), nRight = nLeft + ( ( nPos < 0 ) ? aTotalSize.Width() : maSize.Width() ); 609cdf0e10cSrcweir const int nTop = aPos.Y(), nBottom = nTop + maSize.Height(); 610cdf0e10cSrcweir 611cdf0e10cSrcweir for( int nY = nTop; nY < nBottom; ++nY ) 612cdf0e10cSrcweir { 613cdf0e10cSrcweir for( int nX = nLeft; nX < nRight; ++nX ) 614cdf0e10cSrcweir { 615cdf0e10cSrcweir aGreyVal.SetIndex( pBmp->GetLuminance( nY, nX ) ); 616cdf0e10cSrcweir pGrey->SetPixel( nY, nX, aGreyVal ); 617cdf0e10cSrcweir 618cdf0e10cSrcweir const BitmapColor aBmpAlphaMaskVal( pBmpAlphaMask->GetPixel( nY, nX ) ); 619cdf0e10cSrcweir 620cdf0e10cSrcweir aGreyAlphaMaskVal.SetIndex( static_cast< sal_uInt8 >( ::std::min( aBmpAlphaMaskVal.GetIndex() + 178ul, 255ul ) ) ); 621cdf0e10cSrcweir pGreyAlphaMask->SetPixel( nY, nX, aGreyAlphaMaskVal ); 622cdf0e10cSrcweir } 623cdf0e10cSrcweir } 624cdf0e10cSrcweir } 625cdf0e10cSrcweir 626cdf0e10cSrcweir aBmp.ReleaseAccess( pBmp ); 627cdf0e10cSrcweir aBmpAlphaMask.ReleaseAccess( pBmpAlphaMask ); 628cdf0e10cSrcweir aGrey.ReleaseAccess( pGrey ); 629cdf0e10cSrcweir aGreyAlphaMask.ReleaseAccess( pGreyAlphaMask ); 630cdf0e10cSrcweir 631cdf0e10cSrcweir maDisabledBmpEx = BitmapEx( aGrey, aGreyAlphaMask ); 632cdf0e10cSrcweir } 633