LCOV - code coverage report
Current view: top level - vcl/source/gdi - bitmap.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 439 959 45.8 %
Date: 2012-08-25 Functions: 31 42 73.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 341 1444 23.6 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <rtl/crc.h>
      31                 :            : #include <tools/stream.hxx>
      32                 :            : #include <tools/poly.hxx>
      33                 :            : #include <tools/rc.h>
      34                 :            : #include <vcl/salbtype.hxx>
      35                 :            : #include <vcl/bmpacc.hxx>
      36                 :            : #include <vcl/outdev.hxx>
      37                 :            : #include <vcl/bitmap.hxx>
      38                 :            : #include <vcl/bitmapex.hxx>
      39                 :            : #include <vcl/svapp.hxx>
      40                 :            : #include <vcl/image.hxx>
      41                 :            : 
      42                 :            : #include <impbmp.hxx>
      43                 :            : #include <salbmp.hxx>
      44                 :            : 
      45                 :            : // ----------
      46                 :            : // - Bitmap -
      47                 :            : // ----------
      48                 :            : 
      49                 :    3922174 : Bitmap::Bitmap() :
      50                 :    3922174 :     mpImpBmp( NULL )
      51                 :            : {
      52                 :    3922174 : }
      53                 :            : 
      54                 :            : // ------------------------------------------------------------------
      55                 :            : 
      56                 :       1871 : Bitmap::Bitmap( const ResId& rResId ) :
      57                 :       1871 :     mpImpBmp( NULL )
      58                 :            : {
      59         [ +  - ]:       1871 :     const BitmapEx aBmpEx( rResId );
      60                 :            : 
      61 [ +  - ][ +  + ]:       1871 :     if( !aBmpEx.IsEmpty() )
      62 [ +  - ][ +  - ]:       1871 :         *this = aBmpEx.GetBitmap();
         [ +  - ][ +  - ]
      63                 :       1871 : }
      64                 :            : 
      65                 :            : // ------------------------------------------------------------------
      66                 :            : 
      67                 :    2985914 : Bitmap::Bitmap( const Bitmap& rBitmap ) :
      68                 :            :     maPrefMapMode   ( rBitmap.maPrefMapMode ),
      69                 :    2985914 :     maPrefSize      ( rBitmap.maPrefSize )
      70                 :            : {
      71                 :    2985914 :     mpImpBmp = rBitmap.mpImpBmp;
      72                 :            : 
      73         [ +  + ]:    2985914 :     if ( mpImpBmp )
      74                 :    2630741 :         mpImpBmp->ImplIncRefCount();
      75                 :    2985914 : }
      76                 :            : 
      77                 :            : // ------------------------------------------------------------------
      78                 :            : 
      79                 :          0 : Bitmap::Bitmap( SalBitmap* pSalBitmap )
      80                 :            : {
      81 [ #  # ][ #  # ]:          0 :     mpImpBmp = new ImpBitmap();
      82         [ #  # ]:          0 :     mpImpBmp->ImplSetSalBitmap( pSalBitmap );
      83 [ #  # ][ #  # ]:          0 :     maPrefMapMode = MapMode( MAP_PIXEL );
                 [ #  # ]
      84         [ #  # ]:          0 :     maPrefSize = mpImpBmp->ImplGetSize();
      85                 :          0 : }
      86                 :            : 
      87                 :            : // ------------------------------------------------------------------
      88                 :            : 
      89                 :     251068 : Bitmap::Bitmap( const Size& rSizePixel, sal_uInt16 nBitCount, const BitmapPalette* pPal )
      90                 :            : {
      91 [ +  - ][ +  + ]:     251068 :     if( rSizePixel.Width() && rSizePixel.Height() )
                 [ +  + ]
      92                 :            :     {
      93                 :     250924 :         BitmapPalette   aPal;
      94                 :     250924 :         BitmapPalette*  pRealPal = NULL;
      95                 :            : 
      96         [ +  + ]:     250924 :         if( nBitCount <= 8 )
      97                 :            :         {
      98         [ +  + ]:     112618 :             if( !pPal )
      99                 :            :             {
     100         [ +  + ]:       3262 :                 if( 1 == nBitCount )
     101                 :            :                 {
     102         [ +  - ]:       1177 :                     aPal.SetEntryCount( 2 );
     103                 :       1177 :                     aPal[ 0 ] = Color( COL_BLACK );
     104                 :       1177 :                     aPal[ 1 ] = Color( COL_WHITE );
     105                 :            :                 }
     106 [ +  + ][ +  - ]:       2085 :                 else if( ( 4 == nBitCount ) || ( 8 == nBitCount ) )
     107                 :            :                 {
     108         [ +  - ]:       2085 :                     aPal.SetEntryCount( 1 << nBitCount );
     109                 :       2085 :                     aPal[ 0 ] = Color( COL_BLACK );
     110                 :       2085 :                     aPal[ 1 ] = Color( COL_BLUE );
     111                 :       2085 :                     aPal[ 2 ] = Color( COL_GREEN );
     112                 :       2085 :                     aPal[ 3 ] = Color( COL_CYAN );
     113                 :       2085 :                     aPal[ 4 ] = Color( COL_RED );
     114                 :       2085 :                     aPal[ 5 ] = Color( COL_MAGENTA );
     115                 :       2085 :                     aPal[ 6 ] = Color( COL_BROWN );
     116                 :       2085 :                     aPal[ 7 ] = Color( COL_GRAY );
     117                 :       2085 :                     aPal[ 8 ] = Color( COL_LIGHTGRAY );
     118                 :       2085 :                     aPal[ 9 ] = Color( COL_LIGHTBLUE );
     119                 :       2085 :                     aPal[ 10 ] = Color( COL_LIGHTGREEN );
     120                 :       2085 :                     aPal[ 11 ] = Color( COL_LIGHTCYAN );
     121                 :       2085 :                     aPal[ 12 ] = Color( COL_LIGHTRED );
     122                 :       2085 :                     aPal[ 13 ] = Color( COL_LIGHTMAGENTA );
     123                 :       2085 :                     aPal[ 14 ] = Color( COL_YELLOW );
     124                 :       2085 :                     aPal[ 15 ] = Color( COL_WHITE );
     125                 :            : 
     126                 :            :                     // Dither-Palette erzeugen
     127         [ +  + ]:       2085 :                     if( 8 == nBitCount )
     128                 :            :                     {
     129                 :       1777 :                         sal_uInt16 nActCol = 16;
     130                 :            : 
     131         [ +  + ]:      12439 :                         for( sal_uInt16 nB = 0; nB < 256; nB += 51 )
     132         [ +  + ]:      74634 :                             for( sal_uInt16 nG = 0; nG < 256; nG += 51 )
     133         [ +  + ]:     447804 :                                 for( sal_uInt16 nR = 0; nR < 256; nR += 51 )
     134                 :     383832 :                                     aPal[ nActCol++ ] = BitmapColor( (sal_uInt8) nR, (sal_uInt8) nG, (sal_uInt8) nB );
     135                 :            : 
     136                 :            :                         // Standard-Office-Farbe setzen
     137                 :       1777 :                         aPal[ nActCol++ ] = BitmapColor( 0, 184, 255 );
     138                 :            :                     }
     139                 :            :                 }
     140                 :            :             }
     141                 :            :             else
     142                 :     109356 :                 pRealPal = (BitmapPalette*) pPal;
     143                 :            :         }
     144                 :            : 
     145 [ +  - ][ +  - ]:     250924 :         mpImpBmp = new ImpBitmap;
     146 [ +  + ][ +  - ]:     250924 :         mpImpBmp->ImplCreate( rSizePixel, nBitCount, pRealPal ? *pRealPal : aPal );
     147                 :            :     }
     148                 :            :     else
     149                 :        144 :         mpImpBmp = NULL;
     150                 :     251068 : }
     151                 :            : 
     152                 :            : // ------------------------------------------------------------------
     153                 :            : 
     154                 :    7159326 : Bitmap::~Bitmap()
     155                 :            : {
     156         [ +  - ]:    7159326 :     ImplReleaseRef();
     157                 :    7159326 : }
     158                 :            : 
     159                 :            : // ------------------------------------------------------------------
     160                 :            : 
     161                 :     281277 : const BitmapPalette& Bitmap::GetGreyPalette( int nEntries )
     162                 :            : {
     163 [ +  + ][ +  - ]:     281277 :     static BitmapPalette aGreyPalette2;
     164 [ +  + ][ +  - ]:     281277 :     static BitmapPalette aGreyPalette4;
     165 [ +  + ][ +  - ]:     281277 :     static BitmapPalette aGreyPalette16;
     166 [ +  + ][ +  - ]:     281277 :     static BitmapPalette aGreyPalette256;
     167                 :            : 
     168                 :            :     // create greyscale palette with 2, 4, 16 or 256 entries
     169 [ +  - ][ +  - ]:     281277 :     if( 2 == nEntries || 4 == nEntries || 16 == nEntries || 256 == nEntries )
         [ +  - ][ +  - ]
     170                 :            :     {
     171         [ -  + ]:     281277 :         if( 2 == nEntries )
     172                 :            :         {
     173         [ #  # ]:          0 :             if( !aGreyPalette2.GetEntryCount() )
     174                 :            :             {
     175                 :          0 :                 aGreyPalette2.SetEntryCount( 2 );
     176                 :          0 :                 aGreyPalette2[ 0 ] = BitmapColor( 0, 0, 0 );
     177                 :          0 :                 aGreyPalette2[ 1 ] = BitmapColor( 255, 255, 255 );
     178                 :            :             }
     179                 :            : 
     180                 :          0 :             return aGreyPalette2;
     181                 :            :         }
     182         [ -  + ]:     281277 :         else if( 4 == nEntries )
     183                 :            :         {
     184         [ #  # ]:          0 :             if( !aGreyPalette4.GetEntryCount() )
     185                 :            :             {
     186                 :          0 :                 aGreyPalette4.SetEntryCount( 4 );
     187                 :          0 :                 aGreyPalette4[ 0 ] = BitmapColor( 0, 0, 0 );
     188                 :          0 :                 aGreyPalette4[ 1 ] = BitmapColor( 85, 85, 85 );
     189                 :          0 :                 aGreyPalette4[ 2 ] = BitmapColor( 170, 170, 170 );
     190                 :          0 :                 aGreyPalette4[ 3 ] = BitmapColor( 255, 255, 255 );
     191                 :            :             }
     192                 :            : 
     193                 :          0 :             return aGreyPalette4;
     194                 :            :         }
     195         [ -  + ]:     281277 :         else if( 16 == nEntries )
     196                 :            :         {
     197         [ #  # ]:          0 :             if( !aGreyPalette16.GetEntryCount() )
     198                 :            :             {
     199                 :          0 :                 sal_uInt8 cGrey = 0, cGreyInc = 17;
     200                 :            : 
     201                 :          0 :                 aGreyPalette16.SetEntryCount( 16 );
     202                 :            : 
     203         [ #  # ]:          0 :                 for( sal_uInt16 i = 0; i < 16; i++, cGrey = sal::static_int_cast<sal_uInt8>(cGrey + cGreyInc) )
     204                 :          0 :                     aGreyPalette16[ i ] = BitmapColor( cGrey, cGrey, cGrey );
     205                 :            :             }
     206                 :            : 
     207                 :          0 :             return aGreyPalette16;
     208                 :            :         }
     209                 :            :         else
     210                 :            :         {
     211         [ +  + ]:     281277 :             if( !aGreyPalette256.GetEntryCount() )
     212                 :            :             {
     213                 :         74 :                 aGreyPalette256.SetEntryCount( 256 );
     214                 :            : 
     215         [ +  + ]:      19018 :                 for( sal_uInt16 i = 0; i < 256; i++ )
     216                 :      18944 :                     aGreyPalette256[ i ] = BitmapColor( (sal_uInt8) i, (sal_uInt8) i, (sal_uInt8) i );
     217                 :            :             }
     218                 :            : 
     219                 :     281277 :             return aGreyPalette256;
     220                 :            :         }
     221                 :            :     }
     222                 :            :     else
     223                 :            :     {
     224                 :            :         OSL_FAIL( "Bitmap::GetGreyPalette: invalid entry count (2/4/16/256 allowed)" );
     225                 :     281277 :         return aGreyPalette2;
     226                 :            :     }
     227                 :            : }
     228                 :            : 
     229                 :            : // ------------------------------------------------------------------
     230                 :            : 
     231                 :         13 : bool BitmapPalette::IsGreyPalette() const
     232                 :            : {
     233                 :         13 :     const int nEntryCount = GetEntryCount();
     234         [ -  + ]:         13 :     if( !nEntryCount ) // NOTE: an empty palette means 1:1 mapping
     235                 :          0 :         return true;
     236                 :            :     // see above: only certain entry values will result in a valid call to GetGreyPalette
     237 [ +  - ][ +  - ]:         13 :     if( nEntryCount == 2 || nEntryCount == 4 || nEntryCount == 16 || nEntryCount == 256 )
         [ +  - ][ +  - ]
     238                 :            :     {
     239                 :         13 :         const BitmapPalette& rGreyPalette = Bitmap::GetGreyPalette( nEntryCount );
     240         [ +  - ]:         13 :         if( rGreyPalette == *this )
     241                 :         13 :             return true;
     242                 :            :     }
     243                 :            : 
     244                 :          0 :     bool bRet = false;
     245                 :            :     // TODO: is it worth to compare the entries for the general case?
     246         [ #  # ]:          0 :     if (nEntryCount == 2)
     247                 :            :     {
     248                 :          0 :        const BitmapColor& rCol0(mpBitmapColor[0]);
     249                 :          0 :        const BitmapColor& rCol1(mpBitmapColor[1]);
     250                 :          0 :        bRet = rCol0.GetRed() == rCol0.GetGreen() && rCol0.GetRed() == rCol0.GetBlue() &&
     251 [ #  # ][ #  # ]:          0 :               rCol1.GetRed() == rCol1.GetGreen() && rCol1.GetRed() == rCol1.GetBlue();
           [ #  #  #  # ]
     252                 :            :     }
     253                 :         13 :     return bRet;
     254                 :            : }
     255                 :            : 
     256                 :            : // ------------------------------------------------------------------
     257                 :            : 
     258                 :    3114815 : Bitmap& Bitmap::operator=( const Bitmap& rBitmap )
     259                 :            : {
     260                 :    3114815 :     maPrefSize = rBitmap.maPrefSize;
     261                 :    3114815 :     maPrefMapMode = rBitmap.maPrefMapMode;
     262                 :            : 
     263         [ +  + ]:    3114815 :     if ( rBitmap.mpImpBmp )
     264                 :    3085716 :         rBitmap.mpImpBmp->ImplIncRefCount();
     265                 :            : 
     266                 :    3114815 :     ImplReleaseRef();
     267                 :    3114815 :     mpImpBmp = rBitmap.mpImpBmp;
     268                 :            : 
     269                 :    3114815 :     return *this;
     270                 :            : }
     271                 :            : 
     272                 :            : // ------------------------------------------------------------------
     273                 :            : 
     274                 :          0 : sal_Bool Bitmap::IsEqual( const Bitmap& rBmp ) const
     275                 :            : {
     276                 :          0 :     return( IsSameInstance( rBmp ) ||
     277 [ #  # ][ #  # ]:          0 :             ( rBmp.GetSizePixel() == GetSizePixel() &&
         [ #  # ][ #  # ]
           [ #  #  #  # ]
     278 [ #  # ][ #  # ]:          0 :               rBmp.GetBitCount() == GetBitCount() &&
     279 [ #  # ][ #  # ]:          0 :               rBmp.GetChecksum() == GetChecksum() ) );
         [ #  # ][ #  # ]
           [ #  #  #  # ]
     280                 :            : }
     281                 :            : 
     282                 :            : // ------------------------------------------------------------------
     283                 :            : 
     284                 :     813952 : void Bitmap::SetEmpty()
     285                 :            : {
     286         [ +  - ]:     813952 :     maPrefMapMode = MapMode();
     287                 :     813952 :     maPrefSize = Size();
     288                 :            : 
     289                 :     813952 :     ImplReleaseRef();
     290                 :     813952 :     mpImpBmp = NULL;
     291                 :     813952 : }
     292                 :            : 
     293                 :            : // ------------------------------------------------------------------
     294                 :            : 
     295                 :    1688367 : Size Bitmap::GetSizePixel() const
     296                 :            : {
     297         [ +  + ]:    1688367 :     return( mpImpBmp ? mpImpBmp->ImplGetSize() : Size() );
     298                 :            : }
     299                 :            : // ------------------------------------------------------------------
     300                 :            : 
     301                 :       9427 : void Bitmap::SetSourceSizePixel( const Size& rSize)
     302                 :            : {
     303         [ +  - ]:       9427 :     if( mpImpBmp )
     304                 :       9427 :         mpImpBmp->ImplSetSourceSize( rSize);
     305                 :       9427 : }
     306                 :            : 
     307                 :            : // ------------------------------------------------------------------
     308                 :            : 
     309                 :     475567 : sal_uInt16 Bitmap::GetBitCount() const
     310                 :            : {
     311         [ +  + ]:     475567 :     return( mpImpBmp ? mpImpBmp->ImplGetBitCount() : 0 );
     312                 :            : }
     313                 :            : 
     314                 :            : // ------------------------------------------------------------------
     315                 :            : 
     316                 :         13 : sal_Bool Bitmap::HasGreyPalette() const
     317                 :            : {
     318                 :         13 :     const sal_uInt16    nBitCount = GetBitCount();
     319         [ -  + ]:         13 :     sal_Bool            bRet = nBitCount == 1 ? sal_True : sal_False;
     320                 :            : 
     321                 :         13 :     BitmapReadAccess* pRAcc = ( (Bitmap*) this )->AcquireReadAccess();
     322                 :            : 
     323         [ +  - ]:         13 :     if( pRAcc )
     324                 :            :     {
     325 [ +  - ][ +  - ]:         13 :         bRet = pRAcc->HasPalette() && pRAcc->GetPalette().IsGreyPalette();
     326                 :         13 :         ( (Bitmap*) this )->ReleaseAccess( pRAcc );
     327                 :            :     }
     328                 :            : 
     329                 :         13 :     return bRet;
     330                 :            : }
     331                 :            : 
     332                 :            : // ------------------------------------------------------------------
     333                 :            : 
     334                 :      71332 : sal_uLong Bitmap::GetChecksum() const
     335                 :            : {
     336                 :      71332 :     sal_uLong nRet = 0UL;
     337                 :            : 
     338         [ +  - ]:      71332 :     if( mpImpBmp )
     339                 :            :     {
     340                 :      71332 :         nRet = mpImpBmp->ImplGetChecksum();
     341                 :            : 
     342         [ +  + ]:      71332 :         if( !nRet )
     343                 :            :         {
     344                 :       2877 :             BitmapReadAccess* pRAcc = ( (Bitmap*) this )->AcquireReadAccess();
     345                 :            : 
     346 [ +  - ][ +  - ]:       2877 :             if( pRAcc && pRAcc->Width() && pRAcc->Height() )
         [ +  - ][ +  - ]
     347                 :            :             {
     348                 :       2877 :                 sal_uInt32  nCrc = 0;
     349                 :            :                 SVBT32      aBT32;
     350                 :            : 
     351         [ +  - ]:       2877 :                 pRAcc->ImplZeroInitUnusedBits();
     352                 :            : 
     353                 :       2877 :                 UInt32ToSVBT32( pRAcc->Width(), aBT32 );
     354                 :       2877 :                 nCrc = rtl_crc32( nCrc, aBT32, 4 );
     355                 :            : 
     356                 :       2877 :                 UInt32ToSVBT32( pRAcc->Height(), aBT32 );
     357                 :       2877 :                 nCrc = rtl_crc32( nCrc, aBT32, 4 );
     358                 :            : 
     359                 :       2877 :                 UInt32ToSVBT32( pRAcc->GetBitCount(), aBT32 );
     360                 :       2877 :                 nCrc = rtl_crc32( nCrc, aBT32, 4 );
     361                 :            : 
     362                 :       2877 :                 UInt32ToSVBT32( pRAcc->GetColorMask().GetRedMask(), aBT32 );
     363                 :       2877 :                 nCrc = rtl_crc32( nCrc, aBT32, 4 );
     364                 :            : 
     365                 :       2877 :                 UInt32ToSVBT32( pRAcc->GetColorMask().GetGreenMask(), aBT32 );
     366                 :       2877 :                 nCrc = rtl_crc32( nCrc, aBT32, 4 );
     367                 :            : 
     368                 :       2877 :                 UInt32ToSVBT32( pRAcc->GetColorMask().GetBlueMask(), aBT32 );
     369                 :       2877 :                 nCrc = rtl_crc32( nCrc, aBT32, 4 );
     370                 :            : 
     371         [ +  + ]:       2877 :                 if( pRAcc->HasPalette() )
     372                 :            :                 {
     373                 :       1598 :                     nCrc = rtl_crc32( nCrc, pRAcc->GetPalette().ImplGetColorBuffer(),
     374                 :       3196 :                                       pRAcc->GetPaletteEntryCount() * sizeof( BitmapColor ) );
     375                 :            :                 }
     376                 :            : 
     377                 :       2877 :                 nCrc = rtl_crc32( nCrc, pRAcc->GetBuffer(), pRAcc->GetScanlineSize() * pRAcc->Height() );
     378                 :            : 
     379                 :       2877 :                 mpImpBmp->ImplSetChecksum( nRet = nCrc );
     380                 :            :             }
     381                 :            : 
     382         [ +  - ]:       2877 :             if (pRAcc) ( (Bitmap*) this )->ReleaseAccess( pRAcc );
     383                 :            :         }
     384                 :            :     }
     385                 :            : 
     386                 :      71332 :     return nRet;
     387                 :            : }
     388                 :            : 
     389                 :            : // ------------------------------------------------------------------
     390                 :            : 
     391                 :   11300866 : void Bitmap::ImplReleaseRef()
     392                 :            : {
     393         [ +  + ]:   11300866 :     if( mpImpBmp )
     394                 :            :     {
     395         [ +  + ]:    6180116 :         if( mpImpBmp->ImplGetRefCount() > 1UL )
     396                 :    5508606 :             mpImpBmp->ImplDecRefCount();
     397                 :            :         else
     398                 :            :         {
     399         [ +  - ]:     671510 :             delete mpImpBmp;
     400                 :     671510 :             mpImpBmp = NULL;
     401                 :            :         }
     402                 :            :     }
     403                 :   11300866 : }
     404                 :            : 
     405                 :            : // ------------------------------------------------------------------
     406                 :            : 
     407                 :     458443 : void Bitmap::ImplMakeUnique()
     408                 :            : {
     409 [ +  - ][ +  + ]:     458443 :     if( mpImpBmp && mpImpBmp->ImplGetRefCount() > 1UL )
                 [ +  + ]
     410                 :            :     {
     411                 :     207847 :         ImpBitmap* pOldImpBmp = mpImpBmp;
     412                 :            : 
     413                 :     207847 :         pOldImpBmp->ImplDecRefCount();
     414                 :            : 
     415         [ +  - ]:     207847 :         mpImpBmp = new ImpBitmap;
     416                 :     207847 :         mpImpBmp->ImplCreate( *pOldImpBmp );
     417                 :            :     }
     418                 :     458443 : }
     419                 :            : 
     420                 :            : // ------------------------------------------------------------------
     421                 :            : 
     422                 :     177961 : void Bitmap::ImplAssignWithSize( const Bitmap& rBitmap )
     423                 :            : {
     424         [ +  - ]:     177961 :     const Size      aOldSizePix( GetSizePixel() );
     425         [ +  - ]:     177961 :     const Size      aNewSizePix( rBitmap.GetSizePixel() );
     426         [ +  - ]:     177961 :     const MapMode   aOldMapMode( maPrefMapMode );
     427                 :     177961 :     Size            aNewPrefSize;
     428                 :            : 
     429 [ +  - ][ +  - ]:     177961 :     if( ( aOldSizePix != aNewSizePix ) && aOldSizePix.Width() && aOldSizePix.Height() )
         [ +  + ][ +  + ]
     430                 :            :     {
     431                 :     177949 :         aNewPrefSize.Width() = FRound( maPrefSize.Width() * aNewSizePix.Width() / aOldSizePix.Width() );
     432                 :     177949 :         aNewPrefSize.Height() = FRound( maPrefSize.Height() * aNewSizePix.Height() / aOldSizePix.Height() );
     433                 :            :     }
     434                 :            :     else
     435                 :         12 :         aNewPrefSize = maPrefSize;
     436                 :            : 
     437         [ +  - ]:     177961 :     *this = rBitmap;
     438                 :            : 
     439                 :     177961 :     maPrefSize = aNewPrefSize;
     440 [ +  - ][ +  - ]:     177961 :     maPrefMapMode = aOldMapMode;
     441                 :     177961 : }
     442                 :            : 
     443                 :            : // ------------------------------------------------------------------
     444                 :            : 
     445                 :    4405157 : ImpBitmap* Bitmap::ImplGetImpBitmap() const
     446                 :            : {
     447                 :    4405157 :     return mpImpBmp;
     448                 :            : }
     449                 :            : 
     450                 :            : // ------------------------------------------------------------------
     451                 :            : 
     452                 :     212773 : void Bitmap::ImplSetImpBitmap( ImpBitmap* pImpBmp )
     453                 :            : {
     454         [ +  - ]:     212773 :     if( pImpBmp != mpImpBmp )
     455                 :            :     {
     456                 :     212773 :         ImplReleaseRef();
     457                 :     212773 :         mpImpBmp = pImpBmp;
     458                 :            :     }
     459                 :     212773 : }
     460                 :            : 
     461                 :            : // ------------------------------------------------------------------
     462                 :            : 
     463                 :     821505 : BitmapReadAccess* Bitmap::AcquireReadAccess()
     464                 :            : {
     465         [ +  - ]:     821505 :     BitmapReadAccess* pReadAccess = new BitmapReadAccess( *this );
     466                 :            : 
     467         [ -  + ]:     821505 :     if( !*pReadAccess )
     468                 :            :     {
     469         [ #  # ]:          0 :         delete pReadAccess;
     470                 :          0 :         pReadAccess = NULL;
     471                 :            :     }
     472                 :            : 
     473                 :     821505 :     return pReadAccess;
     474                 :            : }
     475                 :            : 
     476                 :            : // ------------------------------------------------------------------
     477                 :            : 
     478                 :     458443 : BitmapWriteAccess* Bitmap::AcquireWriteAccess()
     479                 :            : {
     480         [ +  - ]:     458443 :     BitmapWriteAccess* pWriteAccess = new BitmapWriteAccess( *this );
     481                 :            : 
     482         [ +  + ]:     458443 :     if( !*pWriteAccess )
     483                 :            :     {
     484         [ +  - ]:          6 :         delete pWriteAccess;
     485                 :          6 :         pWriteAccess = NULL;
     486                 :            :     }
     487                 :            : 
     488                 :     458443 :     return pWriteAccess;
     489                 :            : }
     490                 :            : 
     491                 :            : // ------------------------------------------------------------------
     492                 :            : 
     493                 :    1279942 : void Bitmap::ReleaseAccess( BitmapReadAccess* pBitmapAccess )
     494                 :            : {
     495         [ +  - ]:    1279942 :     delete pBitmapAccess;
     496                 :    1279942 : }
     497                 :            : 
     498                 :            : // ------------------------------------------------------------------
     499                 :            : 
     500                 :      14860 : sal_Bool Bitmap::Erase( const Color& rFillColor )
     501                 :            : {
     502         [ +  + ]:      14860 :     if( !(*this) )
     503                 :        144 :         return sal_True;
     504                 :            : 
     505                 :      14716 :     BitmapWriteAccess*  pWriteAcc = AcquireWriteAccess();
     506                 :      14716 :     sal_Bool                bRet = sal_False;
     507                 :            : 
     508         [ +  + ]:      14716 :     if( pWriteAcc )
     509                 :            :     {
     510                 :      14713 :         const sal_uLong nFormat = pWriteAcc->GetScanlineFormat();
     511                 :      14713 :         sal_uInt8       cIndex = 0;
     512                 :      14713 :         sal_Bool        bFast = sal_False;
     513                 :            : 
     514   [ +  -  +  +  :      14713 :         switch( nFormat )
                      - ]
     515                 :            :         {
     516                 :            :             case( BMP_FORMAT_1BIT_MSB_PAL ):
     517                 :            :             case( BMP_FORMAT_1BIT_LSB_PAL ):
     518                 :            :             {
     519         [ +  - ]:        329 :                 cIndex = (sal_uInt8) pWriteAcc->GetBestPaletteIndex( rFillColor );
     520         [ +  + ]:        329 :                 cIndex = ( cIndex ? 255 : 0 );
     521                 :        329 :                 bFast = sal_True;
     522                 :            :             }
     523                 :        329 :             break;
     524                 :            : 
     525                 :            :             case( BMP_FORMAT_4BIT_MSN_PAL ):
     526                 :            :             case( BMP_FORMAT_4BIT_LSN_PAL ):
     527                 :            :             {
     528         [ #  # ]:          0 :                 cIndex = (sal_uInt8) pWriteAcc->GetBestPaletteIndex( rFillColor );
     529                 :          0 :                 cIndex = cIndex | ( cIndex << 4 );
     530                 :          0 :                 bFast = sal_True;
     531                 :            :             }
     532                 :          0 :             break;
     533                 :            : 
     534                 :            :             case( BMP_FORMAT_8BIT_PAL ):
     535                 :            :             {
     536         [ +  - ]:      12979 :                 cIndex = (sal_uInt8) pWriteAcc->GetBestPaletteIndex( rFillColor );
     537                 :      12979 :                 bFast = sal_True;
     538                 :            :             }
     539                 :      12979 :             break;
     540                 :            : 
     541                 :            :             case( BMP_FORMAT_24BIT_TC_BGR ):
     542                 :            :             case( BMP_FORMAT_24BIT_TC_RGB ):
     543                 :            :             {
     544   [ +  -  +  - ]:       2810 :                 if( ( rFillColor.GetRed() == rFillColor.GetGreen() ) &&
                 [ +  - ]
     545                 :       1405 :                     ( rFillColor.GetRed() == rFillColor.GetBlue() ) )
     546                 :            :                 {
     547                 :       1405 :                     cIndex = rFillColor.GetRed();
     548                 :       1405 :                     bFast = sal_True;
     549                 :            :                 }
     550                 :            :                 else
     551                 :          0 :                     bFast = sal_False;
     552                 :            :             }
     553                 :       1405 :             break;
     554                 :            : 
     555                 :            :             default:
     556                 :          0 :                 bFast = sal_False;
     557                 :          0 :             break;
     558                 :            :         }
     559                 :            : 
     560         [ +  - ]:      14713 :         if( bFast )
     561                 :            :         {
     562                 :      14713 :             const sal_uLong nBufSize = pWriteAcc->GetScanlineSize() * pWriteAcc->Height();
     563                 :      14713 :             memset( pWriteAcc->GetBuffer(), cIndex, nBufSize );
     564                 :            :         }
     565                 :            :         else
     566                 :            :         {
     567                 :          0 :             Point aTmpPoint;
     568         [ #  # ]:          0 :             const Rectangle aRect( aTmpPoint, Size( pWriteAcc->Width(), pWriteAcc->Height() ) );
     569         [ #  # ]:          0 :             pWriteAcc->SetFillColor( rFillColor );
     570         [ #  # ]:          0 :             pWriteAcc->FillRect( aRect );
     571                 :            :         }
     572                 :            : 
     573                 :      14713 :         ReleaseAccess( pWriteAcc );
     574                 :      14713 :         bRet = sal_True;
     575                 :            :     }
     576                 :            : 
     577                 :      14860 :     return bRet;
     578                 :            : }
     579                 :            : 
     580                 :            : // ------------------------------------------------------------------
     581                 :            : 
     582                 :         12 : sal_Bool Bitmap::Invert()
     583                 :            : {
     584                 :         12 :     BitmapWriteAccess*  pAcc = AcquireWriteAccess();
     585                 :         12 :     sal_Bool                bRet = sal_False;
     586                 :            : 
     587         [ +  - ]:         12 :     if( pAcc )
     588                 :            :     {
     589         [ +  - ]:         12 :         if( pAcc->HasPalette() )
     590                 :            :         {
     591         [ +  - ]:         12 :             BitmapPalette   aBmpPal( pAcc->GetPalette() );
     592                 :         12 :             const sal_uInt16    nCount = aBmpPal.GetEntryCount();
     593                 :            : 
     594         [ +  + ]:         36 :             for( sal_uInt16 i = 0; i < nCount; i++ )
     595                 :         24 :                 aBmpPal[ i ].Invert();
     596                 :            : 
     597         [ +  - ]:         12 :             pAcc->SetPalette( aBmpPal );
     598                 :            :         }
     599                 :            :         else
     600                 :            :         {
     601                 :          0 :             const long  nWidth = pAcc->Width();
     602                 :          0 :             const long  nHeight = pAcc->Height();
     603                 :            : 
     604         [ #  # ]:          0 :             for( long nX = 0L; nX < nWidth; nX++ )
     605         [ #  # ]:          0 :                 for( long nY = 0L; nY < nHeight; nY++ )
     606         [ #  # ]:          0 :                     pAcc->SetPixel( nY, nX, pAcc->GetPixel( nY, nX ).Invert() );
     607                 :            :         }
     608                 :            : 
     609                 :         12 :         ReleaseAccess( pAcc );
     610                 :         12 :         bRet = sal_True;
     611                 :            :     }
     612                 :            : 
     613                 :         12 :     return bRet;
     614                 :            : }
     615                 :            : 
     616                 :            : // ------------------------------------------------------------------
     617                 :            : 
     618                 :          0 : sal_Bool Bitmap::Mirror( sal_uLong nMirrorFlags )
     619                 :            : {
     620                 :          0 :     sal_Bool bHorz = ( ( nMirrorFlags & BMP_MIRROR_HORZ ) == BMP_MIRROR_HORZ );
     621                 :          0 :     sal_Bool bVert = ( ( nMirrorFlags & BMP_MIRROR_VERT ) == BMP_MIRROR_VERT );
     622                 :          0 :     sal_Bool bRet = sal_False;
     623                 :            : 
     624 [ #  # ][ #  # ]:          0 :     if( bHorz && !bVert )
     625                 :            :     {
     626                 :          0 :         BitmapWriteAccess*  pAcc = AcquireWriteAccess();
     627                 :            : 
     628         [ #  # ]:          0 :         if( pAcc )
     629                 :            :         {
     630                 :          0 :             const long  nWidth = pAcc->Width();
     631                 :          0 :             const long  nHeight = pAcc->Height();
     632                 :          0 :             const long  nWidth1 = nWidth - 1L;
     633                 :          0 :             const long  nWidth_2 = nWidth >> 1L;
     634                 :            : 
     635         [ #  # ]:          0 :             for( long nY = 0L; nY < nHeight; nY++ )
     636                 :            :             {
     637         [ #  # ]:          0 :                 for( long nX = 0L, nOther = nWidth1; nX < nWidth_2; nX++, nOther-- )
     638                 :            :                 {
     639         [ #  # ]:          0 :                     const BitmapColor aTemp( pAcc->GetPixel( nY, nX ) );
     640                 :            : 
     641 [ #  # ][ #  # ]:          0 :                     pAcc->SetPixel( nY, nX, pAcc->GetPixel( nY, nOther ) );
     642         [ #  # ]:          0 :                     pAcc->SetPixel( nY, nOther, aTemp );
     643                 :          0 :                 }
     644                 :            :             }
     645                 :            : 
     646                 :          0 :             ReleaseAccess( pAcc );
     647                 :          0 :             bRet = sal_True;
     648                 :          0 :         }
     649                 :            :     }
     650 [ #  # ][ #  # ]:          0 :     else if( bVert && !bHorz )
     651                 :            :     {
     652                 :          0 :         BitmapWriteAccess*  pAcc = AcquireWriteAccess();
     653                 :            : 
     654         [ #  # ]:          0 :         if( pAcc )
     655                 :            :         {
     656                 :          0 :             const long  nScanSize = pAcc->GetScanlineSize();
     657                 :          0 :             sal_uInt8*      pBuffer = new sal_uInt8[ nScanSize ];
     658                 :          0 :             const long  nHeight = pAcc->Height();
     659                 :          0 :             const long  nHeight1 = nHeight - 1L;
     660                 :          0 :             const long  nHeight_2 = nHeight >> 1L;
     661                 :            : 
     662         [ #  # ]:          0 :             for( long nY = 0L, nOther = nHeight1; nY < nHeight_2; nY++, nOther-- )
     663                 :            :             {
     664                 :          0 :                 memcpy( pBuffer, pAcc->GetScanline( nY ), nScanSize );
     665                 :          0 :                 memcpy( pAcc->GetScanline( nY ), pAcc->GetScanline( nOther ), nScanSize );
     666                 :          0 :                 memcpy( pAcc->GetScanline( nOther ), pBuffer, nScanSize );
     667                 :            :             }
     668                 :            : 
     669         [ #  # ]:          0 :             delete[] pBuffer;
     670                 :          0 :             ReleaseAccess( pAcc );
     671                 :          0 :             bRet = sal_True;
     672                 :          0 :         }
     673                 :            :     }
     674 [ #  # ][ #  # ]:          0 :     else if( bHorz && bVert )
     675                 :            :     {
     676                 :          0 :         BitmapWriteAccess*  pAcc = AcquireWriteAccess();
     677                 :            : 
     678         [ #  # ]:          0 :         if( pAcc )
     679                 :            :         {
     680                 :          0 :             const long  nWidth = pAcc->Width();
     681                 :          0 :             const long  nWidth1 = nWidth - 1L;
     682                 :          0 :             const long  nHeight = pAcc->Height();
     683                 :          0 :             long        nHeight_2 = nHeight >> 1;
     684                 :            : 
     685         [ #  # ]:          0 :             for( long nY = 0L, nOtherY = nHeight - 1L; nY < nHeight_2; nY++, nOtherY-- )
     686                 :            :             {
     687         [ #  # ]:          0 :                 for( long nX = 0L, nOtherX = nWidth1; nX < nWidth; nX++, nOtherX-- )
     688                 :            :                 {
     689         [ #  # ]:          0 :                     const BitmapColor aTemp( pAcc->GetPixel( nY, nX ) );
     690                 :            : 
     691 [ #  # ][ #  # ]:          0 :                     pAcc->SetPixel( nY, nX, pAcc->GetPixel( nOtherY, nOtherX ) );
     692         [ #  # ]:          0 :                     pAcc->SetPixel( nOtherY, nOtherX, aTemp );
     693                 :          0 :                 }
     694                 :            :             }
     695                 :            : 
     696                 :            :             // ggf. noch mittlere Zeile horizontal spiegeln
     697         [ #  # ]:          0 :             if( nHeight & 1 )
     698                 :            :             {
     699         [ #  # ]:          0 :                 for( long nX = 0L, nOtherX = nWidth1, nWidth_2 = nWidth >> 1; nX < nWidth_2; nX++, nOtherX-- )
     700                 :            :                 {
     701         [ #  # ]:          0 :                     const BitmapColor aTemp( pAcc->GetPixel( nHeight_2, nX ) );
     702 [ #  # ][ #  # ]:          0 :                     pAcc->SetPixel( nHeight_2, nX, pAcc->GetPixel( nHeight_2, nOtherX ) );
     703         [ #  # ]:          0 :                     pAcc->SetPixel( nHeight_2, nOtherX, aTemp );
     704                 :          0 :                 }
     705                 :            :             }
     706                 :            : 
     707                 :          0 :             ReleaseAccess( pAcc );
     708                 :          0 :             bRet = sal_True;
     709                 :          0 :         }
     710                 :            :     }
     711                 :            :     else
     712                 :          0 :         bRet = sal_True;
     713                 :            : 
     714                 :          0 :     return bRet;
     715                 :            : }
     716                 :            : 
     717                 :            : // ------------------------------------------------------------------
     718                 :            : 
     719                 :          0 : sal_Bool Bitmap::Rotate( long nAngle10, const Color& rFillColor )
     720                 :            : {
     721                 :          0 :     sal_Bool bRet = sal_False;
     722                 :            : 
     723                 :          0 :     nAngle10 %= 3600L;
     724         [ #  # ]:          0 :     nAngle10 = ( nAngle10 < 0L ) ? ( 3599L + nAngle10 ) : nAngle10;
     725                 :            : 
     726         [ #  # ]:          0 :     if( !nAngle10    )
     727                 :          0 :         bRet = sal_True;
     728         [ #  # ]:          0 :     else if( 1800L == nAngle10 )
     729                 :          0 :         bRet = Mirror( BMP_MIRROR_HORZ | BMP_MIRROR_VERT );
     730                 :            :     else
     731                 :            :     {
     732         [ #  # ]:          0 :         BitmapReadAccess*   pReadAcc = AcquireReadAccess();
     733         [ #  # ]:          0 :         Bitmap              aRotatedBmp;
     734                 :            : 
     735         [ #  # ]:          0 :         if( pReadAcc )
     736                 :            :         {
     737         [ #  # ]:          0 :             const Size  aSizePix( GetSizePixel() );
     738                 :            : 
     739 [ #  # ][ #  # ]:          0 :             if( ( 900L == nAngle10 ) || ( 2700L == nAngle10 ) )
     740                 :            :             {
     741                 :          0 :                 const Size          aNewSizePix( aSizePix.Height(), aSizePix.Width() );
     742 [ #  # ][ #  # ]:          0 :                 Bitmap              aNewBmp( aNewSizePix, GetBitCount(), &pReadAcc->GetPalette() );
     743         [ #  # ]:          0 :                 BitmapWriteAccess*  pWriteAcc = aNewBmp.AcquireWriteAccess();
     744                 :            : 
     745         [ #  # ]:          0 :                 if( pWriteAcc )
     746                 :            :                 {
     747                 :          0 :                     const long  nWidth = aSizePix.Width();
     748                 :          0 :                     const long  nWidth1 = nWidth - 1L;
     749                 :          0 :                     const long  nHeight = aSizePix.Height();
     750                 :          0 :                     const long  nHeight1 = nHeight - 1L;
     751                 :          0 :                     const long  nNewWidth = aNewSizePix.Width();
     752                 :          0 :                     const long  nNewHeight = aNewSizePix.Height();
     753                 :            : 
     754         [ #  # ]:          0 :                     if( 900L == nAngle10 )
     755                 :            :                     {
     756         [ #  # ]:          0 :                         for( long nY = 0L, nOtherX = nWidth1; nY < nNewHeight; nY++, nOtherX-- )
     757         [ #  # ]:          0 :                             for( long nX = 0L, nOtherY = 0L; nX < nNewWidth; nX++ )
     758 [ #  # ][ #  # ]:          0 :                                 pWriteAcc->SetPixel( nY, nX, pReadAcc->GetPixel( nOtherY++, nOtherX ) );
     759                 :            :                     }
     760         [ #  # ]:          0 :                     else if( 2700L == nAngle10 )
     761                 :            :                     {
     762         [ #  # ]:          0 :                         for( long nY = 0L, nOtherX = 0L; nY < nNewHeight; nY++, nOtherX++ )
     763         [ #  # ]:          0 :                             for( long nX = 0L, nOtherY = nHeight1; nX < nNewWidth; nX++ )
     764 [ #  # ][ #  # ]:          0 :                                 pWriteAcc->SetPixel( nY, nX, pReadAcc->GetPixel( nOtherY--, nOtherX ) );
     765                 :            :                     }
     766                 :            : 
     767         [ #  # ]:          0 :                     aNewBmp.ReleaseAccess( pWriteAcc );
     768                 :            :                 }
     769                 :            : 
     770 [ #  # ][ #  # ]:          0 :                 aRotatedBmp = aNewBmp;
     771                 :            :             }
     772                 :            :             else
     773                 :            :             {
     774                 :          0 :                 Point       aTmpPoint;
     775         [ #  # ]:          0 :                 Rectangle   aTmpRectangle( aTmpPoint, aSizePix );
     776         [ #  # ]:          0 :                 Polygon     aPoly( aTmpRectangle );
     777         [ #  # ]:          0 :                 aPoly.Rotate( aTmpPoint, (sal_uInt16) nAngle10 );
     778                 :            : 
     779         [ #  # ]:          0 :                 Rectangle           aNewBound( aPoly.GetBoundRect() );
     780         [ #  # ]:          0 :                 const Size          aNewSizePix( aNewBound.GetSize() );
     781 [ #  # ][ #  # ]:          0 :                 Bitmap              aNewBmp( aNewSizePix, GetBitCount(), &pReadAcc->GetPalette() );
     782         [ #  # ]:          0 :                 BitmapWriteAccess*  pWriteAcc = aNewBmp.AcquireWriteAccess();
     783                 :            : 
     784         [ #  # ]:          0 :                 if( pWriteAcc )
     785                 :            :                 {
     786         [ #  # ]:          0 :                     const BitmapColor   aFillColor( pWriteAcc->GetBestMatchingColor( rFillColor ) );
     787                 :          0 :                     const double        fCosAngle = cos( nAngle10 * F_PI1800 );
     788                 :          0 :                     const double        fSinAngle = sin( nAngle10 * F_PI1800 );
     789                 :          0 :                     const double        fXMin = aNewBound.Left();
     790                 :          0 :                     const double        fYMin = aNewBound.Top();
     791                 :          0 :                     const long          nWidth = aSizePix.Width();
     792                 :          0 :                     const long          nHeight = aSizePix.Height();
     793                 :          0 :                     const long          nNewWidth = aNewSizePix.Width();
     794                 :          0 :                     const long          nNewHeight = aNewSizePix.Height();
     795                 :            :                     long                nX;
     796                 :            :                     long                nY;
     797                 :            :                     long                nRotX;
     798                 :            :                     long                nRotY;
     799                 :            :                     long                nSinY;
     800                 :            :                     long                nCosY;
     801         [ #  # ]:          0 :                     long*               pCosX = new long[ nNewWidth ];
     802         [ #  # ]:          0 :                     long*               pSinX = new long[ nNewWidth ];
     803         [ #  # ]:          0 :                     long*               pCosY = new long[ nNewHeight ];
     804         [ #  # ]:          0 :                     long*               pSinY = new long[ nNewHeight ];
     805                 :            : 
     806         [ #  # ]:          0 :                     for ( nX = 0; nX < nNewWidth; nX++ )
     807                 :            :                     {
     808                 :          0 :                         const double fTmp = ( fXMin + nX ) * 64.;
     809                 :            : 
     810                 :          0 :                         pCosX[ nX ] = FRound( fCosAngle * fTmp );
     811                 :          0 :                         pSinX[ nX ] = FRound( fSinAngle * fTmp );
     812                 :            :                     }
     813                 :            : 
     814         [ #  # ]:          0 :                     for ( nY = 0; nY < nNewHeight; nY++ )
     815                 :            :                     {
     816                 :          0 :                         const double fTmp = ( fYMin + nY ) * 64.;
     817                 :            : 
     818                 :          0 :                         pCosY[ nY ] = FRound( fCosAngle * fTmp );
     819                 :          0 :                         pSinY[ nY ] = FRound( fSinAngle * fTmp );
     820                 :            :                     }
     821                 :            : 
     822         [ #  # ]:          0 :                     for( nY = 0L; nY < nNewHeight; nY++ )
     823                 :            :                     {
     824                 :          0 :                         nSinY = pSinY[ nY ];
     825                 :          0 :                         nCosY = pCosY[ nY ];
     826                 :            : 
     827         [ #  # ]:          0 :                         for( nX = 0L; nX < nNewWidth; nX++ )
     828                 :            :                         {
     829                 :          0 :                             nRotX = ( pCosX[ nX ] - nSinY ) >> 6;
     830                 :          0 :                             nRotY = ( pSinX[ nX ] + nCosY ) >> 6;
     831                 :            : 
     832 [ #  # ][ #  # ]:          0 :                             if ( ( nRotX > -1L ) && ( nRotX < nWidth ) && ( nRotY > -1L ) && ( nRotY < nHeight ) )
         [ #  # ][ #  # ]
     833 [ #  # ][ #  # ]:          0 :                                 pWriteAcc->SetPixel( nY, nX, pReadAcc->GetPixel( nRotY, nRotX ) );
     834                 :            :                             else
     835         [ #  # ]:          0 :                                 pWriteAcc->SetPixel( nY, nX, aFillColor );
     836                 :            :                         }
     837                 :            :                     }
     838                 :            : 
     839         [ #  # ]:          0 :                     delete[] pSinX;
     840         [ #  # ]:          0 :                     delete[] pCosX;
     841         [ #  # ]:          0 :                     delete[] pSinY;
     842         [ #  # ]:          0 :                     delete[] pCosY;
     843                 :            : 
     844         [ #  # ]:          0 :                     aNewBmp.ReleaseAccess( pWriteAcc );
     845                 :            :                 }
     846                 :            : 
     847 [ #  # ][ #  # ]:          0 :                 aRotatedBmp = aNewBmp;
                 [ #  # ]
     848                 :            :             }
     849                 :            : 
     850         [ #  # ]:          0 :             ReleaseAccess( pReadAcc );
     851                 :            :         }
     852                 :            : 
     853         [ #  # ]:          0 :         if( ( bRet = !!aRotatedBmp ) == sal_True )
     854 [ #  # ][ #  # ]:          0 :             ImplAssignWithSize( aRotatedBmp );
     855                 :            :     }
     856                 :            : 
     857                 :          0 :     return bRet;
     858                 :            : };
     859                 :            : 
     860                 :            : // ------------------------------------------------------------------
     861                 :            : 
     862                 :       2680 : sal_Bool Bitmap::Crop( const Rectangle& rRectPixel )
     863                 :            : {
     864         [ +  - ]:       2680 :     const Size          aSizePix( GetSizePixel() );
     865                 :       2680 :     Rectangle           aRect( rRectPixel );
     866                 :       2680 :     sal_Bool                bRet = sal_False;
     867                 :            : 
     868 [ +  - ][ +  - ]:       2680 :     aRect.Intersection( Rectangle( Point(), aSizePix ) );
     869                 :            : 
     870 [ +  - ][ +  - ]:       2680 :     if( !aRect.IsEmpty() )
     871                 :            :     {
     872         [ +  - ]:       2680 :         BitmapReadAccess* pReadAcc = AcquireReadAccess();
     873                 :            : 
     874         [ +  - ]:       2680 :         if( pReadAcc )
     875                 :            :         {
     876                 :       2680 :             Point               aTmpPoint;
     877 [ +  - ][ +  - ]:       2680 :             const Rectangle     aNewRect( aTmpPoint, aRect.GetSize() );
     878 [ +  - ][ +  - ]:       2680 :             Bitmap              aNewBmp( aNewRect.GetSize(), GetBitCount(), &pReadAcc->GetPalette() );
                 [ +  - ]
     879         [ +  - ]:       2680 :             BitmapWriteAccess*  pWriteAcc = aNewBmp.AcquireWriteAccess();
     880                 :            : 
     881         [ +  - ]:       2680 :             if( pWriteAcc )
     882                 :            :             {
     883                 :       2680 :                 const long nOldX = aRect.Left();
     884                 :       2680 :                 const long nOldY = aRect.Top();
     885         [ +  - ]:       2680 :                 const long nNewWidth = aNewRect.GetWidth();
     886         [ +  - ]:       2680 :                 const long nNewHeight = aNewRect.GetHeight();
     887                 :            : 
     888         [ +  + ]:      32324 :                 for( long nY = 0, nY2 = nOldY; nY < nNewHeight; nY++, nY2++ )
     889         [ +  + ]:     500744 :                     for( long nX = 0, nX2 = nOldX; nX < nNewWidth; nX++, nX2++ )
     890 [ +  - ][ +  - ]:     471100 :                         pWriteAcc->SetPixel( nY, nX, pReadAcc->GetPixel( nY2, nX2 ) );
     891                 :            : 
     892         [ +  - ]:       2680 :                 aNewBmp.ReleaseAccess( pWriteAcc );
     893                 :       2680 :                 bRet = sal_True;
     894                 :            :             }
     895                 :            : 
     896         [ +  - ]:       2680 :             ReleaseAccess( pReadAcc );
     897                 :            : 
     898         [ +  - ]:       2680 :             if( bRet )
     899 [ +  - ][ +  - ]:       2680 :                 ImplAssignWithSize( aNewBmp );
     900                 :            :         }
     901                 :            :     }
     902                 :            : 
     903                 :       2680 :     return bRet;
     904                 :            : };
     905                 :            : 
     906                 :            : // ------------------------------------------------------------------
     907                 :            : 
     908                 :       8745 : sal_Bool Bitmap::CopyPixel( const Rectangle& rRectDst,
     909                 :            :                         const Rectangle& rRectSrc, const Bitmap* pBmpSrc )
     910                 :            : {
     911         [ +  - ]:       8745 :     const Size  aSizePix( GetSizePixel() );
     912                 :       8745 :     Rectangle   aRectDst( rRectDst );
     913                 :       8745 :     sal_Bool        bRet = sal_False;
     914                 :            : 
     915 [ +  - ][ +  - ]:       8745 :     aRectDst.Intersection( Rectangle( Point(), aSizePix ) );
     916                 :            : 
     917 [ +  - ][ +  - ]:       8745 :     if( !aRectDst.IsEmpty() )
     918                 :            :     {
     919 [ +  - ][ +  - ]:       8745 :         if( pBmpSrc && ( *pBmpSrc != *this ) )
                 [ +  - ]
     920                 :            :         {
     921                 :       8745 :             Bitmap*         pSrc = (Bitmap*) pBmpSrc;
     922         [ +  - ]:       8745 :             const Size      aCopySizePix( pSrc->GetSizePixel() );
     923                 :       8745 :             Rectangle       aRectSrc( rRectSrc );
     924         [ +  - ]:       8745 :             const sal_uInt16    nSrcBitCount = pBmpSrc->GetBitCount();
     925         [ +  - ]:       8745 :             const sal_uInt16    nDstBitCount = GetBitCount();
     926                 :            : 
     927         [ -  + ]:       8745 :             if( nSrcBitCount > nDstBitCount )
     928                 :            :             {
     929                 :          0 :                 long nNextIndex = 0L;
     930                 :            : 
     931 [ #  # ][ #  # ]:          0 :                 if( ( nSrcBitCount == 24 ) && ( nDstBitCount < 24 ) )
     932         [ #  # ]:          0 :                     Convert( BMP_CONVERSION_24BIT );
     933 [ #  # ][ #  # ]:          0 :                 else if( ( nSrcBitCount == 8 ) && ( nDstBitCount < 8 ) )
     934                 :            :                 {
     935         [ #  # ]:          0 :                     Convert( BMP_CONVERSION_8BIT_COLORS );
     936                 :          0 :                     nNextIndex = 16;
     937                 :            :                 }
     938 [ #  # ][ #  # ]:          0 :                 else if( ( nSrcBitCount == 4 ) && ( nDstBitCount < 4 ) )
     939                 :            :                 {
     940         [ #  # ]:          0 :                     Convert( BMP_CONVERSION_4BIT_COLORS );
     941                 :          0 :                     nNextIndex = 2;
     942                 :            :                 }
     943                 :            : 
     944         [ #  # ]:          0 :                 if( nNextIndex )
     945                 :            :                 {
     946         [ #  # ]:          0 :                     BitmapReadAccess*   pSrcAcc = pSrc->AcquireReadAccess();
     947         [ #  # ]:          0 :                     BitmapWriteAccess*  pDstAcc = AcquireWriteAccess();
     948                 :            : 
     949 [ #  # ][ #  # ]:          0 :                     if( pSrcAcc && pDstAcc )
     950                 :            :                     {
     951                 :          0 :                         const long      nSrcCount = pDstAcc->GetPaletteEntryCount();
     952                 :          0 :                         const long      nDstCount = 1 << nDstBitCount;
     953                 :            :                         sal_Bool            bFound;
     954                 :            : 
     955 [ #  # ][ #  # ]:          0 :                         for( long i = 0L; ( i < nSrcCount ) && ( nNextIndex < nSrcCount ); i++ )
                 [ #  # ]
     956                 :            :                         {
     957                 :          0 :                             const BitmapColor& rSrcCol = pSrcAcc->GetPaletteColor( (sal_uInt16) i );
     958                 :            : 
     959                 :          0 :                             bFound = sal_False;
     960                 :            : 
     961         [ #  # ]:          0 :                             for( long j = 0L; j < nDstCount; j++ )
     962                 :            :                             {
     963         [ #  # ]:          0 :                                 if( rSrcCol == pDstAcc->GetPaletteColor( (sal_uInt16) j ) )
     964                 :            :                                 {
     965                 :          0 :                                     bFound = sal_True;
     966                 :          0 :                                     break;
     967                 :            :                                 }
     968                 :            :                             }
     969                 :            : 
     970         [ #  # ]:          0 :                             if( !bFound )
     971                 :          0 :                                 pDstAcc->SetPaletteColor( (sal_uInt16) nNextIndex++, rSrcCol );
     972                 :            :                         }
     973                 :            :                     }
     974                 :            : 
     975         [ #  # ]:          0 :                     if( pSrcAcc )
     976         [ #  # ]:          0 :                         pSrc->ReleaseAccess( pSrcAcc );
     977                 :            : 
     978         [ #  # ]:          0 :                     if( pDstAcc )
     979         [ #  # ]:          0 :                         ReleaseAccess( pDstAcc );
     980                 :            :                 }
     981                 :            :             }
     982                 :            : 
     983 [ +  - ][ +  - ]:       8745 :             aRectSrc.Intersection( Rectangle( Point(), aCopySizePix ) );
     984                 :            : 
     985 [ +  - ][ +  - ]:       8745 :             if( !aRectSrc.IsEmpty() )
     986                 :            :             {
     987         [ +  - ]:       8745 :                 BitmapReadAccess* pReadAcc = pSrc->AcquireReadAccess();
     988                 :            : 
     989         [ +  - ]:       8745 :                 if( pReadAcc )
     990                 :            :                 {
     991         [ +  - ]:       8745 :                     BitmapWriteAccess* pWriteAcc = AcquireWriteAccess();
     992                 :            : 
     993         [ +  - ]:       8745 :                     if( pWriteAcc )
     994                 :            :                     {
     995 [ +  - ][ +  - ]:       8745 :                         const long  nWidth = Min( aRectSrc.GetWidth(), aRectDst.GetWidth() );
     996 [ +  - ][ +  - ]:       8745 :                         const long  nHeight = Min( aRectSrc.GetHeight(), aRectDst.GetHeight() );
     997                 :       8745 :                         const long  nSrcEndX = aRectSrc.Left() + nWidth;
     998                 :       8745 :                         const long  nSrcEndY = aRectSrc.Top() + nHeight;
     999                 :       8745 :                         long        nDstY = aRectDst.Top();
    1000                 :            : 
    1001 [ +  - ][ +  + ]:       8745 :                         if( pReadAcc->HasPalette() && pWriteAcc->HasPalette() )
                 [ +  + ]
    1002                 :            :                         {
    1003                 :       4134 :                             const sal_uInt16    nCount = pReadAcc->GetPaletteEntryCount();
    1004         [ +  - ]:       4134 :                             sal_uInt8*          pMap = new sal_uInt8[ nCount ];
    1005                 :            : 
    1006                 :            :                             // Index-Map fuer Farbtabelle
    1007                 :            :                             // aufbauen, da das Bild ja (relativ) farbgenau
    1008                 :            :                             // kopiert werden soll
    1009         [ +  + ]:     947190 :                             for( sal_uInt16 i = 0; i < nCount; i++ )
    1010         [ +  - ]:     943056 :                                 pMap[ i ] = (sal_uInt8) pWriteAcc->GetBestPaletteIndex( pReadAcc->GetPaletteColor( i ) );
    1011                 :            : 
    1012         [ +  + ]:      31356 :                             for( long nSrcY = aRectSrc.Top(); nSrcY < nSrcEndY; nSrcY++, nDstY++ )
    1013         [ +  + ]:     242268 :                                 for( long nSrcX = aRectSrc.Left(), nDstX = aRectDst.Left(); nSrcX < nSrcEndX; nSrcX++, nDstX++ )
    1014 [ +  - ][ +  - ]:     215046 :                                     pWriteAcc->SetPixel( nDstY, nDstX, pMap[ pReadAcc->GetPixel( nSrcY, nSrcX ).GetIndex() ] );
    1015                 :            : 
    1016         [ +  - ]:       4134 :                             delete[] pMap;
    1017                 :            :                         }
    1018         [ -  + ]:       4611 :                         else if( pReadAcc->HasPalette() )
    1019                 :            :                         {
    1020         [ #  # ]:          0 :                             for( long nSrcY = aRectSrc.Top(); nSrcY < nSrcEndY; nSrcY++, nDstY++ )
    1021         [ #  # ]:          0 :                                 for( long nSrcX = aRectSrc.Left(), nDstX = aRectDst.Left(); nSrcX < nSrcEndX; nSrcX++, nDstX++ )
    1022 [ #  # ][ #  # ]:          0 :                                     pWriteAcc->SetPixel( nDstY, nDstX, pReadAcc->GetPaletteColor( pReadAcc->GetPixel( nSrcY, nSrcX ) ) );
    1023                 :            :                         }
    1024                 :            :                         else
    1025         [ +  + ]:      32529 :                             for( long nSrcY = aRectSrc.Top(); nSrcY < nSrcEndY; nSrcY++, nDstY++ )
    1026         [ +  + ]:     207972 :                                 for( long nSrcX = aRectSrc.Left(), nDstX = aRectDst.Left(); nSrcX < nSrcEndX; nSrcX++, nDstX++ )
    1027 [ +  - ][ +  - ]:     180054 :                                     pWriteAcc->SetPixel( nDstY, nDstX, pReadAcc->GetPixel( nSrcY, nSrcX ) );
    1028                 :            : 
    1029         [ +  - ]:       8745 :                         ReleaseAccess( pWriteAcc );
    1030 [ +  - ][ +  - ]:       8745 :                         bRet = ( nWidth > 0L ) && ( nHeight > 0L );
    1031                 :            :                     }
    1032                 :            : 
    1033         [ +  - ]:       8745 :                     pSrc->ReleaseAccess( pReadAcc );
    1034                 :            :                 }
    1035                 :            :             }
    1036                 :            :         }
    1037                 :            :         else
    1038                 :            :         {
    1039                 :          0 :             Rectangle aRectSrc( rRectSrc );
    1040                 :            : 
    1041 [ #  # ][ #  # ]:          0 :             aRectSrc.Intersection( Rectangle( Point(), aSizePix ) );
    1042                 :            : 
    1043 [ #  # ][ #  # ]:          0 :             if( !aRectSrc.IsEmpty() && ( aRectSrc != aRectDst ) )
         [ #  # ][ #  # ]
                 [ #  # ]
    1044                 :            :             {
    1045         [ #  # ]:          0 :                 BitmapWriteAccess*  pWriteAcc = AcquireWriteAccess();
    1046                 :            : 
    1047         [ #  # ]:          0 :                 if( pWriteAcc )
    1048                 :            :                 {
    1049 [ #  # ][ #  # ]:          0 :                     const long  nWidth = Min( aRectSrc.GetWidth(), aRectDst.GetWidth() );
    1050 [ #  # ][ #  # ]:          0 :                     const long  nHeight = Min( aRectSrc.GetHeight(), aRectDst.GetHeight() );
    1051                 :          0 :                     const long  nSrcX = aRectSrc.Left();
    1052                 :          0 :                     const long  nSrcY = aRectSrc.Top();
    1053                 :          0 :                     const long  nSrcEndX1 = nSrcX + nWidth - 1L;
    1054                 :          0 :                     const long  nSrcEndY1 = nSrcY + nHeight - 1L;
    1055                 :          0 :                     const long  nDstX = aRectDst.Left();
    1056                 :          0 :                     const long  nDstY = aRectDst.Top();
    1057                 :          0 :                     const long  nDstEndX1 = nDstX + nWidth - 1L;
    1058                 :          0 :                     const long  nDstEndY1 = nDstY + nHeight - 1L;
    1059                 :            : 
    1060 [ #  # ][ #  # ]:          0 :                     if( ( nDstX <= nSrcX ) && ( nDstY <= nSrcY ) )
    1061                 :            :                     {
    1062         [ #  # ]:          0 :                         for( long nY = nSrcY, nYN = nDstY; nY <= nSrcEndY1; nY++, nYN++ )
    1063         [ #  # ]:          0 :                             for( long nX = nSrcX, nXN = nDstX; nX <= nSrcEndX1; nX++, nXN++ )
    1064 [ #  # ][ #  # ]:          0 :                                 pWriteAcc->SetPixel( nYN, nXN, pWriteAcc->GetPixel( nY, nX ) );
    1065                 :            :                     }
    1066 [ #  # ][ #  # ]:          0 :                     else if( ( nDstX <= nSrcX ) && ( nDstY >= nSrcY ) )
    1067                 :            :                     {
    1068         [ #  # ]:          0 :                         for( long nY = nSrcEndY1, nYN = nDstEndY1; nY >= nSrcY; nY--, nYN-- )
    1069         [ #  # ]:          0 :                             for( long nX = nSrcX, nXN = nDstX; nX <= nSrcEndX1; nX++, nXN++ )
    1070 [ #  # ][ #  # ]:          0 :                                 pWriteAcc->SetPixel( nYN, nXN, pWriteAcc->GetPixel( nY, nX ) );
    1071                 :            :                     }
    1072 [ #  # ][ #  # ]:          0 :                     else if( ( nDstX >= nSrcX ) && ( nDstY <= nSrcY ) )
    1073                 :            :                     {
    1074         [ #  # ]:          0 :                         for( long nY = nSrcY, nYN = nDstY; nY <= nSrcEndY1; nY++, nYN++ )
    1075         [ #  # ]:          0 :                             for( long nX = nSrcEndX1, nXN = nDstEndX1; nX >= nSrcX; nX--, nXN-- )
    1076 [ #  # ][ #  # ]:          0 :                                 pWriteAcc->SetPixel( nYN, nXN, pWriteAcc->GetPixel( nY, nX ) );
    1077                 :            :                     }
    1078                 :            :                     else
    1079                 :            :                     {
    1080         [ #  # ]:          0 :                         for( long nY = nSrcEndY1, nYN = nDstEndY1; nY >= nSrcY; nY--, nYN-- )
    1081         [ #  # ]:          0 :                             for( long nX = nSrcEndX1, nXN = nDstEndX1; nX >= nSrcX; nX--, nXN-- )
    1082 [ #  # ][ #  # ]:          0 :                                 pWriteAcc->SetPixel( nYN, nXN, pWriteAcc->GetPixel( nY, nX ) );
    1083                 :            :                     }
    1084                 :            : 
    1085         [ #  # ]:          0 :                     ReleaseAccess( pWriteAcc );
    1086                 :          0 :                     bRet = sal_True;
    1087                 :            :                 }
    1088                 :            :             }
    1089                 :            :         }
    1090                 :            :     }
    1091                 :            : 
    1092                 :       8745 :     return bRet;
    1093                 :            : }
    1094                 :            : 
    1095                 :            : // ------------------------------------------------------------------
    1096                 :            : 
    1097                 :          0 : sal_Bool Bitmap::Expand( sal_uLong nDX, sal_uLong nDY, const Color* pInitColor )
    1098                 :            : {
    1099                 :          0 :     sal_Bool bRet = sal_False;
    1100                 :            : 
    1101 [ #  # ][ #  # ]:          0 :     if( nDX || nDY )
    1102                 :            :     {
    1103         [ #  # ]:          0 :         const Size          aSizePixel( GetSizePixel() );
    1104                 :          0 :         const long          nWidth = aSizePixel.Width();
    1105                 :          0 :         const long          nHeight = aSizePixel.Height();
    1106                 :          0 :         const Size          aNewSize( nWidth + nDX, nHeight + nDY );
    1107         [ #  # ]:          0 :         BitmapReadAccess*   pReadAcc = AcquireReadAccess();
    1108                 :            : 
    1109         [ #  # ]:          0 :         if( pReadAcc )
    1110                 :            :         {
    1111         [ #  # ]:          0 :             BitmapPalette       aBmpPal( pReadAcc->GetPalette() );
    1112 [ #  # ][ #  # ]:          0 :             Bitmap              aNewBmp( aNewSize, GetBitCount(), &aBmpPal );
    1113         [ #  # ]:          0 :             BitmapWriteAccess*  pWriteAcc = aNewBmp.AcquireWriteAccess();
    1114                 :            : 
    1115         [ #  # ]:          0 :             if( pWriteAcc )
    1116                 :            :             {
    1117                 :          0 :                 BitmapColor aColor;
    1118                 :          0 :                 const long  nNewX = nWidth;
    1119                 :          0 :                 const long  nNewY = nHeight;
    1120                 :          0 :                 const long  nNewWidth = pWriteAcc->Width();
    1121                 :          0 :                 const long  nNewHeight = pWriteAcc->Height();
    1122                 :            :                 long        nX;
    1123                 :            :                 long        nY;
    1124                 :            : 
    1125         [ #  # ]:          0 :                 if( pInitColor )
    1126         [ #  # ]:          0 :                     aColor = pWriteAcc->GetBestMatchingColor( *pInitColor );
    1127                 :            : 
    1128         [ #  # ]:          0 :                 for( nY = 0L; nY < nHeight; nY++ )
    1129                 :            :                 {
    1130         [ #  # ]:          0 :                     pWriteAcc->CopyScanline( nY, *pReadAcc );
    1131                 :            : 
    1132 [ #  # ][ #  # ]:          0 :                     if( pInitColor && nDX )
    1133         [ #  # ]:          0 :                         for( nX = nNewX; nX < nNewWidth; nX++ )
    1134         [ #  # ]:          0 :                             pWriteAcc->SetPixel( nY, nX, aColor );
    1135                 :            :                 }
    1136                 :            : 
    1137 [ #  # ][ #  # ]:          0 :                 if( pInitColor && nDY )
    1138         [ #  # ]:          0 :                     for( nY = nNewY; nY < nNewHeight; nY++ )
    1139         [ #  # ]:          0 :                         for( nX = 0; nX < nNewWidth; nX++ )
    1140         [ #  # ]:          0 :                             pWriteAcc->SetPixel( nY, nX, aColor );
    1141                 :            : 
    1142         [ #  # ]:          0 :                 aNewBmp.ReleaseAccess( pWriteAcc );
    1143                 :          0 :                 bRet = sal_True;
    1144                 :            :             }
    1145                 :            : 
    1146         [ #  # ]:          0 :             ReleaseAccess( pReadAcc );
    1147                 :            : 
    1148         [ #  # ]:          0 :             if( bRet )
    1149 [ #  # ][ #  # ]:          0 :                 ImplAssignWithSize( aNewBmp );
    1150                 :            :         }
    1151                 :            :     }
    1152                 :            : 
    1153                 :          0 :     return bRet;
    1154                 :            : }
    1155                 :            : 
    1156                 :            : // ------------------------------------------------------------------
    1157                 :            : 
    1158                 :         44 : Bitmap Bitmap::CreateMask( const Color& rTransColor, sal_uLong nTol ) const
    1159                 :            : {
    1160         [ +  - ]:         44 :     Bitmap              aNewBmp( GetSizePixel(), 1 );
    1161         [ +  - ]:         44 :     BitmapWriteAccess*  pWriteAcc = aNewBmp.AcquireWriteAccess();
    1162                 :         44 :     sal_Bool                bRet = sal_False;
    1163                 :            : 
    1164         [ +  - ]:         44 :     if( pWriteAcc )
    1165                 :            :     {
    1166         [ +  - ]:         44 :         BitmapReadAccess* pReadAcc = ( (Bitmap*) this )->AcquireReadAccess();
    1167                 :            : 
    1168         [ +  - ]:         44 :         if( pReadAcc )
    1169                 :            :         {
    1170                 :         44 :             const long          nWidth = pReadAcc->Width();
    1171                 :         44 :             const long          nHeight = pReadAcc->Height();
    1172         [ +  - ]:         44 :             const BitmapColor   aBlack( pWriteAcc->GetBestMatchingColor( Color( COL_BLACK ) ) );
    1173         [ +  - ]:         44 :             const BitmapColor   aWhite( pWriteAcc->GetBestMatchingColor( Color( COL_WHITE ) ) );
    1174                 :            : 
    1175         [ +  - ]:         44 :             if( !nTol )
    1176                 :            :             {
    1177         [ +  - ]:         44 :                 const BitmapColor   aTest( pReadAcc->GetBestMatchingColor( rTransColor ) );
    1178                 :            :                 long nX, nY;
    1179                 :            : 
    1180         [ +  + ]:         68 :                 if( pReadAcc->GetScanlineFormat() == BMP_FORMAT_4BIT_MSN_PAL ||
           [ +  +  -  + ]
    1181                 :         24 :                     pReadAcc->GetScanlineFormat() == BMP_FORMAT_4BIT_LSN_PAL )
    1182                 :            :                 {
    1183                 :            :                     // optimized for 4Bit-MSN/LSN source palette
    1184                 :         20 :                     const sal_uInt8 cTest = aTest.GetIndex();
    1185         [ +  - ]:         20 :                     const long nShiftInit = ( ( pReadAcc->GetScanlineFormat() == BMP_FORMAT_4BIT_MSN_PAL ) ? 4 : 0 );
    1186                 :            : 
    1187   [ +  -  +  - ]:         40 :                     if( pWriteAcc->GetScanlineFormat() == BMP_FORMAT_1BIT_MSB_PAL &&
                 [ +  - ]
    1188                 :         20 :                         aWhite.GetIndex() == 1 )
    1189                 :            :                     {
    1190                 :            :                         // optimized for 1Bit-MSB destination palette
    1191         [ +  + ]:        280 :                         for( nY = 0L; nY < nHeight; nY++ )
    1192                 :            :                         {
    1193                 :        260 :                             Scanline pSrc = pReadAcc->GetScanline( nY );
    1194                 :        260 :                             Scanline pDst = pWriteAcc->GetScanline( nY );
    1195                 :        260 :                             long nShift = 0;
    1196         [ +  + ]:      25610 :                             for( nX = 0L, nShift = nShiftInit; nX < nWidth; nX++, nShift ^= 4 )
    1197                 :            :                             {
    1198         [ +  + ]:      25350 :                                 if( cTest == ( ( pSrc[ nX >> 1 ] >> nShift ) & 0x0f ) )
    1199                 :       3420 :                                     pDst[ nX >> 3 ] |= 1 << ( 7 - ( nX & 7 ) );
    1200                 :            :                                 else
    1201                 :      21930 :                                     pDst[ nX >> 3 ] &= ~( 1 << ( 7 - ( nX & 7 ) ) );
    1202                 :            :                             }
    1203                 :            :                         }
    1204                 :            :                     }
    1205                 :            :                     else
    1206                 :            :                     {
    1207         [ #  # ]:          0 :                         for( nY = 0L; nY < nHeight; nY++ )
    1208                 :            :                         {
    1209                 :          0 :                             Scanline pSrc = pReadAcc->GetScanline( nY );
    1210                 :          0 :                             long nShift = 0;
    1211         [ #  # ]:          0 :                             for( nX = 0L, nShift = nShiftInit; nX < nWidth; nX++, nShift ^= 4 )
    1212                 :            :                             {
    1213         [ #  # ]:          0 :                                 if( cTest == ( ( pSrc[ nX >> 1 ] >> nShift ) & 0x0f ) )
    1214         [ #  # ]:          0 :                                     pWriteAcc->SetPixel( nY, nX, aWhite );
    1215                 :            :                                 else
    1216         [ #  # ]:          0 :                                     pWriteAcc->SetPixel( nY, nX, aBlack );
    1217                 :            :                             }
    1218                 :            :                         }
    1219                 :            :                     }
    1220                 :            :                 }
    1221         [ +  + ]:         24 :                 else if( pReadAcc->GetScanlineFormat() == BMP_FORMAT_8BIT_PAL )
    1222                 :            :                 {
    1223                 :            :                     // optimized for 8Bit source palette
    1224                 :         22 :                     const sal_uInt8 cTest = aTest.GetIndex();
    1225                 :            : 
    1226         [ +  - ]:         44 :                     if( pWriteAcc->GetScanlineFormat() == BMP_FORMAT_1BIT_MSB_PAL &&
           [ +  -  +  - ]
    1227                 :         22 :                         aWhite.GetIndex() == 1 )
    1228                 :            :                     {
    1229                 :            :                         // optimized for 1Bit-MSB destination palette
    1230         [ +  + ]:        300 :                         for( nY = 0L; nY < nHeight; nY++ )
    1231                 :            :                         {
    1232                 :        278 :                             Scanline pSrc = pReadAcc->GetScanline( nY );
    1233                 :        278 :                             Scanline pDst = pWriteAcc->GetScanline( nY );
    1234         [ +  + ]:      27818 :                             for( nX = 0L; nX < nWidth; nX++ )
    1235                 :            :                             {
    1236         [ +  + ]:      27540 :                                 if( cTest == pSrc[ nX ] )
    1237                 :       4446 :                                     pDst[ nX >> 3 ] |= 1 << ( 7 - ( nX & 7 ) );
    1238                 :            :                                 else
    1239                 :      23094 :                                     pDst[ nX >> 3 ] &= ~( 1 << ( 7 - ( nX & 7 ) ) );
    1240                 :            :                             }
    1241                 :            :                         }
    1242                 :            :                     }
    1243                 :            :                     else
    1244                 :            :                     {
    1245         [ #  # ]:          0 :                         for( nY = 0L; nY < nHeight; nY++ )
    1246                 :            :                         {
    1247                 :          0 :                             Scanline pSrc = pReadAcc->GetScanline( nY );
    1248         [ #  # ]:          0 :                             for( nX = 0L; nX < nWidth; nX++ )
    1249                 :            :                             {
    1250         [ #  # ]:          0 :                                 if( cTest == pSrc[ nX ] )
    1251         [ #  # ]:          0 :                                     pWriteAcc->SetPixel( nY, nX, aWhite );
    1252                 :            :                                 else
    1253         [ #  # ]:          0 :                                     pWriteAcc->SetPixel( nY, nX, aBlack );
    1254                 :            :                             }
    1255                 :            :                         }
    1256                 :            :                     }
    1257                 :            :                 }
    1258                 :            :                 else
    1259                 :            :                 {
    1260                 :            :                     // not optimized
    1261         [ +  + ]:         20 :                     for( nY = 0L; nY < nHeight; nY++ )
    1262                 :            :                     {
    1263         [ +  + ]:        180 :                         for( nX = 0L; nX < nWidth; nX++ )
    1264                 :            :                         {
    1265 [ +  - ][ -  + ]:        162 :                             if( aTest == pReadAcc->GetPixel( nY, nX ) )
    1266         [ #  # ]:          0 :                                 pWriteAcc->SetPixel( nY, nX, aWhite );
    1267                 :            :                             else
    1268         [ +  - ]:        162 :                                 pWriteAcc->SetPixel( nY, nX, aBlack );
    1269                 :            :                         }
    1270                 :            :                     }
    1271                 :         44 :                 }
    1272                 :            :             }
    1273                 :            :             else
    1274                 :            :             {
    1275                 :          0 :                 BitmapColor aCol;
    1276                 :            :                 long        nR, nG, nB;
    1277                 :          0 :                 const long  nMinR = MinMax( (long) rTransColor.GetRed() - nTol, 0, 255 );
    1278                 :          0 :                 const long  nMaxR = MinMax( (long) rTransColor.GetRed() + nTol, 0, 255 );
    1279                 :          0 :                 const long  nMinG = MinMax( (long) rTransColor.GetGreen() - nTol, 0, 255 );
    1280                 :          0 :                 const long  nMaxG = MinMax( (long) rTransColor.GetGreen() + nTol, 0, 255 );
    1281                 :          0 :                 const long  nMinB = MinMax( (long) rTransColor.GetBlue() - nTol, 0, 255 );
    1282                 :          0 :                 const long  nMaxB = MinMax( (long) rTransColor.GetBlue() + nTol, 0, 255 );
    1283                 :            : 
    1284         [ #  # ]:          0 :                 if( pReadAcc->HasPalette() )
    1285                 :            :                 {
    1286         [ #  # ]:          0 :                     for( long nY = 0L; nY < nHeight; nY++ )
    1287                 :            :                     {
    1288         [ #  # ]:          0 :                         for( long nX = 0L; nX < nWidth; nX++ )
    1289                 :            :                         {
    1290         [ #  # ]:          0 :                             aCol = pReadAcc->GetPaletteColor( pReadAcc->GetPixel( nY, nX ) );
    1291                 :          0 :                             nR = aCol.GetRed();
    1292                 :          0 :                             nG = aCol.GetGreen();
    1293                 :          0 :                             nB = aCol.GetBlue();
    1294                 :            : 
    1295 [ #  # ][ #  # ]:          0 :                             if( nMinR <= nR && nMaxR >= nR &&
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1296                 :            :                                 nMinG <= nG && nMaxG >= nG &&
    1297                 :            :                                 nMinB <= nB && nMaxB >= nB )
    1298                 :            :                             {
    1299         [ #  # ]:          0 :                                 pWriteAcc->SetPixel( nY, nX, aWhite );
    1300                 :            :                             }
    1301                 :            :                             else
    1302         [ #  # ]:          0 :                                 pWriteAcc->SetPixel( nY, nX, aBlack );
    1303                 :            :                         }
    1304                 :            :                     }
    1305                 :            :                 }
    1306                 :            :                 else
    1307                 :            :                 {
    1308         [ #  # ]:          0 :                     for( long nY = 0L; nY < nHeight; nY++ )
    1309                 :            :                     {
    1310         [ #  # ]:          0 :                         for( long nX = 0L; nX < nWidth; nX++ )
    1311                 :            :                         {
    1312         [ #  # ]:          0 :                             aCol = pReadAcc->GetPixel( nY, nX );
    1313                 :          0 :                             nR = aCol.GetRed();
    1314                 :          0 :                             nG = aCol.GetGreen();
    1315                 :          0 :                             nB = aCol.GetBlue();
    1316                 :            : 
    1317 [ #  # ][ #  # ]:          0 :                             if( nMinR <= nR && nMaxR >= nR &&
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1318                 :            :                                 nMinG <= nG && nMaxG >= nG &&
    1319                 :            :                                 nMinB <= nB && nMaxB >= nB )
    1320                 :            :                             {
    1321         [ #  # ]:          0 :                                 pWriteAcc->SetPixel( nY, nX, aWhite );
    1322                 :            :                             }
    1323                 :            :                             else
    1324         [ #  # ]:          0 :                                 pWriteAcc->SetPixel( nY, nX, aBlack );
    1325                 :            :                         }
    1326                 :            :                     }
    1327                 :          0 :                 }
    1328                 :            :             }
    1329                 :            : 
    1330         [ +  - ]:         44 :             ( (Bitmap*) this )->ReleaseAccess( pReadAcc );
    1331                 :         44 :             bRet = sal_True;
    1332                 :            :         }
    1333                 :            : 
    1334         [ +  - ]:         44 :         aNewBmp.ReleaseAccess( pWriteAcc );
    1335                 :            :     }
    1336                 :            : 
    1337         [ +  - ]:         44 :     if( bRet )
    1338                 :            :     {
    1339                 :         44 :         aNewBmp.maPrefSize = maPrefSize;
    1340         [ +  - ]:         44 :         aNewBmp.maPrefMapMode = maPrefMapMode;
    1341                 :            :     }
    1342                 :            :     else
    1343 [ #  # ][ #  # ]:          0 :         aNewBmp = Bitmap();
                 [ #  # ]
    1344                 :            : 
    1345                 :         44 :     return aNewBmp;
    1346                 :            : }
    1347                 :            : 
    1348                 :            : // ------------------------------------------------------------------
    1349                 :            : 
    1350                 :          0 : Region Bitmap::CreateRegion( const Color& rColor, const Rectangle& rRect ) const
    1351                 :            : {
    1352         [ #  # ]:          0 :     Region              aRegion;
    1353                 :          0 :     Rectangle           aRect( rRect );
    1354         [ #  # ]:          0 :     BitmapReadAccess*   pReadAcc = ( (Bitmap*) this )->AcquireReadAccess();
    1355                 :            : 
    1356 [ #  # ][ #  # ]:          0 :     aRect.Intersection( Rectangle( Point(), GetSizePixel() ) );
                 [ #  # ]
    1357         [ #  # ]:          0 :     aRect.Justify();
    1358                 :            : 
    1359         [ #  # ]:          0 :     if( pReadAcc )
    1360                 :            :     {
    1361         [ #  # ]:          0 :         Rectangle           aSubRect;
    1362                 :          0 :         const long          nLeft = aRect.Left();
    1363                 :          0 :         const long          nTop = aRect.Top();
    1364                 :          0 :         const long          nRight = aRect.Right();
    1365                 :          0 :         const long          nBottom = aRect.Bottom();
    1366         [ #  # ]:          0 :         const BitmapColor   aMatch( pReadAcc->GetBestMatchingColor( rColor ) );
    1367                 :            : 
    1368         [ #  # ]:          0 :         aRegion.ImplBeginAddRect();
    1369                 :            : 
    1370         [ #  # ]:          0 :         for( long nY = nTop; nY <= nBottom; nY++ )
    1371                 :            :         {
    1372                 :          0 :             aSubRect.Top() = aSubRect.Bottom() = nY;
    1373                 :            : 
    1374         [ #  # ]:          0 :             for( long nX = nLeft; nX <= nRight; )
    1375                 :            :             {
    1376 [ #  # ][ #  # ]:          0 :                 while( ( nX <= nRight ) && ( aMatch != pReadAcc->GetPixel( nY, nX ) ) )
         [ #  # ][ #  # ]
           [ #  #  #  # ]
    1377                 :          0 :                     nX++;
    1378                 :            : 
    1379         [ #  # ]:          0 :                 if( nX <= nRight )
    1380                 :            :                 {
    1381                 :          0 :                     aSubRect.Left() = nX;
    1382                 :            : 
    1383 [ #  # ][ #  # ]:          0 :                     while( ( nX <= nRight ) && ( aMatch == pReadAcc->GetPixel( nY, nX ) ) )
         [ #  # ][ #  # ]
           [ #  #  #  # ]
    1384                 :          0 :                         nX++;
    1385                 :            : 
    1386                 :          0 :                     aSubRect.Right() = nX - 1L;
    1387         [ #  # ]:          0 :                     aRegion.ImplAddRect( aSubRect );
    1388                 :            :                 }
    1389                 :            :             }
    1390                 :            :         }
    1391                 :            : 
    1392         [ #  # ]:          0 :         aRegion.ImplEndAddRect();
    1393         [ #  # ]:          0 :         ( (Bitmap*) this )->ReleaseAccess( pReadAcc );
    1394                 :            :     }
    1395                 :            :     else
    1396         [ #  # ]:          0 :         aRegion = aRect;
    1397                 :            : 
    1398                 :          0 :     return aRegion;
    1399                 :            : }
    1400                 :            : 
    1401                 :            : // ------------------------------------------------------------------
    1402                 :            : 
    1403                 :          6 : sal_Bool Bitmap::Replace( const Bitmap& rMask, const Color& rReplaceColor )
    1404                 :            : {
    1405                 :          6 :     BitmapReadAccess*   pMaskAcc = ( (Bitmap&) rMask ).AcquireReadAccess();
    1406                 :          6 :     BitmapWriteAccess*  pAcc = AcquireWriteAccess();
    1407                 :          6 :     sal_Bool                bRet = sal_False;
    1408                 :            : 
    1409 [ +  - ][ +  - ]:          6 :     if( pMaskAcc && pAcc )
    1410                 :            :     {
    1411                 :          6 :         const long          nWidth = Min( pMaskAcc->Width(), pAcc->Width() );
    1412                 :          6 :         const long          nHeight = Min( pMaskAcc->Height(), pAcc->Height() );
    1413         [ +  - ]:          6 :         const BitmapColor   aMaskWhite( pMaskAcc->GetBestMatchingColor( Color( COL_WHITE ) ) );
    1414                 :          6 :         BitmapColor         aReplace;
    1415                 :            : 
    1416         [ -  + ]:          6 :         if( pAcc->HasPalette() )
    1417                 :            :         {
    1418                 :          0 :             const sal_uInt16 nActColors = pAcc->GetPaletteEntryCount();
    1419                 :          0 :             const sal_uInt16 nMaxColors = 1 << pAcc->GetBitCount();
    1420                 :            : 
    1421                 :            :             // erst einmal naechste Farbe nehmen
    1422         [ #  # ]:          0 :             aReplace = pAcc->GetBestMatchingColor( rReplaceColor );
    1423                 :            : 
    1424                 :            :             // falls Palettenbild, und die zu setzende Farbe ist nicht
    1425                 :            :             // in der Palette, suchen wir nach freien Eintraegen (teuer)
    1426         [ #  # ]:          0 :             if( pAcc->GetPaletteColor( (sal_uInt8) aReplace ) != BitmapColor( rReplaceColor ) )
    1427                 :            :             {
    1428                 :            :                 // erst einmal nachsehen, ob wir unsere ReplaceColor
    1429                 :            :                 // nicht auf einen freien Platz am Ende der Palette
    1430                 :            :                 // setzen koennen
    1431         [ #  # ]:          0 :                 if( nActColors < nMaxColors )
    1432                 :            :                 {
    1433         [ #  # ]:          0 :                     pAcc->SetPaletteEntryCount( nActColors + 1 );
    1434                 :          0 :                     pAcc->SetPaletteColor( nActColors, rReplaceColor );
    1435                 :          0 :                     aReplace = BitmapColor( (sal_uInt8) nActColors );
    1436                 :            :                 }
    1437                 :            :                 else
    1438                 :            :                 {
    1439         [ #  # ]:          0 :                     sal_Bool* pFlags = new sal_Bool[ nMaxColors ];
    1440                 :            : 
    1441                 :            :                     // alle Eintraege auf 0 setzen
    1442                 :          0 :                     memset( pFlags, 0, nMaxColors );
    1443                 :            : 
    1444         [ #  # ]:          0 :                     for( long nY = 0L; nY < nHeight; nY++ )
    1445         [ #  # ]:          0 :                         for( long nX = 0L; nX < nWidth; nX++ )
    1446         [ #  # ]:          0 :                             pFlags[ (sal_uInt8) pAcc->GetPixel( nY, nX ) ] = sal_True;
    1447                 :            : 
    1448         [ #  # ]:          0 :                     for( sal_uInt16 i = 0UL; i < nMaxColors; i++ )
    1449                 :            :                     {
    1450                 :            :                         // Hurra, wir haben einen unbenutzten Eintrag
    1451         [ #  # ]:          0 :                         if( !pFlags[ i ] )
    1452                 :            :                         {
    1453                 :          0 :                             pAcc->SetPaletteColor( (sal_uInt16) i, rReplaceColor );
    1454                 :          0 :                             aReplace = BitmapColor( (sal_uInt8) i );
    1455                 :            :                         }
    1456                 :            :                     }
    1457                 :            : 
    1458         [ #  # ]:          0 :                     delete[] pFlags;
    1459                 :            :                 }
    1460                 :            :             }
    1461                 :            :         }
    1462                 :            :         else
    1463                 :          6 :             aReplace = rReplaceColor;
    1464                 :            : 
    1465         [ +  + ]:        174 :         for( long nY = 0L; nY < nHeight; nY++ )
    1466         [ +  + ]:      37488 :             for( long nX = 0L; nX < nWidth; nX++ )
    1467 [ +  - ][ +  + ]:      37320 :                 if( pMaskAcc->GetPixel( nY, nX ) == aMaskWhite )
    1468         [ +  - ]:      18654 :                     pAcc->SetPixel( nY, nX, aReplace );
    1469                 :            : 
    1470                 :          6 :         bRet = sal_True;
    1471                 :            :     }
    1472                 :            : 
    1473                 :          6 :     ( (Bitmap&) rMask ).ReleaseAccess( pMaskAcc );
    1474                 :          6 :     ReleaseAccess( pAcc );
    1475                 :            : 
    1476                 :          6 :     return bRet;
    1477                 :            : }
    1478                 :            : 
    1479                 :            : // ------------------------------------------------------------------
    1480                 :            : 
    1481                 :          0 : sal_Bool Bitmap::Replace( const AlphaMask& rAlpha, const Color& rMergeColor )
    1482                 :            : {
    1483 [ #  # ][ #  # ]:          0 :     Bitmap              aNewBmp( GetSizePixel(), 24 );
    1484         [ #  # ]:          0 :     BitmapReadAccess*   pAcc = AcquireReadAccess();
    1485         [ #  # ]:          0 :     BitmapReadAccess*   pAlphaAcc = ( (AlphaMask&) rAlpha ).AcquireReadAccess();
    1486         [ #  # ]:          0 :     BitmapWriteAccess*  pNewAcc = aNewBmp.AcquireWriteAccess();
    1487                 :          0 :     sal_Bool                bRet = sal_False;
    1488                 :            : 
    1489 [ #  # ][ #  # ]:          0 :     if( pAcc && pAlphaAcc && pNewAcc )
                 [ #  # ]
    1490                 :            :     {
    1491                 :          0 :         BitmapColor aCol;
    1492                 :          0 :         const long  nWidth = Min( pAlphaAcc->Width(), pAcc->Width() );
    1493                 :          0 :         const long  nHeight = Min( pAlphaAcc->Height(), pAcc->Height() );
    1494                 :            : 
    1495         [ #  # ]:          0 :         for( long nY = 0L; nY < nHeight; nY++ )
    1496                 :            :         {
    1497         [ #  # ]:          0 :             for( long nX = 0L; nX < nWidth; nX++ )
    1498                 :            :             {
    1499         [ #  # ]:          0 :                 aCol = pAcc->GetColor( nY, nX );
    1500 [ #  # ][ #  # ]:          0 :                 pNewAcc->SetPixel( nY, nX, aCol.Merge( rMergeColor, 255 - (sal_uInt8) pAlphaAcc->GetPixel( nY, nX ) ) );
    1501                 :            :             }
    1502                 :            :         }
    1503                 :            : 
    1504                 :          0 :         bRet = sal_True;
    1505                 :            :     }
    1506                 :            : 
    1507         [ #  # ]:          0 :     ReleaseAccess( pAcc );
    1508         [ #  # ]:          0 :     ( (AlphaMask&) rAlpha ).ReleaseAccess( pAlphaAcc );
    1509         [ #  # ]:          0 :     aNewBmp.ReleaseAccess( pNewAcc );
    1510                 :            : 
    1511         [ #  # ]:          0 :     if( bRet )
    1512                 :            :     {
    1513         [ #  # ]:          0 :         const MapMode   aMap( maPrefMapMode );
    1514                 :          0 :         const Size      aSize( maPrefSize );
    1515                 :            : 
    1516         [ #  # ]:          0 :         *this = aNewBmp;
    1517                 :            : 
    1518         [ #  # ]:          0 :         maPrefMapMode = aMap;
    1519         [ #  # ]:          0 :         maPrefSize = aSize;
    1520                 :            :     }
    1521                 :            : 
    1522         [ #  # ]:          0 :     return bRet;
    1523                 :            : }
    1524                 :            : 
    1525                 :            : // ------------------------------------------------------------------
    1526                 :            : 
    1527                 :       1040 : sal_Bool Bitmap::Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uLong nTol )
    1528                 :            : {
    1529                 :            :     // Bitmaps with 1 bit color depth can cause problems
    1530                 :            :     // if they have other entries than black/white in their palette
    1531         [ -  + ]:       1040 :     if( 1 == GetBitCount() )
    1532                 :          0 :         Convert( BMP_CONVERSION_4BIT_COLORS );
    1533                 :            : 
    1534                 :       1040 :     BitmapWriteAccess*  pAcc = AcquireWriteAccess();
    1535                 :       1040 :     sal_Bool                bRet = sal_False;
    1536                 :            : 
    1537         [ +  - ]:       1040 :     if( pAcc )
    1538                 :            :     {
    1539                 :       1040 :         const long  nMinR = MinMax( (long) rSearchColor.GetRed() - nTol, 0, 255 );
    1540                 :       1040 :         const long  nMaxR = MinMax( (long) rSearchColor.GetRed() + nTol, 0, 255 );
    1541                 :       1040 :         const long  nMinG = MinMax( (long) rSearchColor.GetGreen() - nTol, 0, 255 );
    1542                 :       1040 :         const long  nMaxG = MinMax( (long) rSearchColor.GetGreen() + nTol, 0, 255 );
    1543                 :       1040 :         const long  nMinB = MinMax( (long) rSearchColor.GetBlue() - nTol, 0, 255 );
    1544                 :       1040 :         const long  nMaxB = MinMax( (long) rSearchColor.GetBlue() + nTol, 0, 255 );
    1545                 :            : 
    1546         [ -  + ]:       1040 :         if( pAcc->HasPalette() )
    1547                 :            :         {
    1548         [ #  # ]:          0 :             for( sal_uInt16 i = 0, nPalCount = pAcc->GetPaletteEntryCount(); i < nPalCount; i++ )
    1549                 :            :             {
    1550                 :          0 :                 const BitmapColor& rCol = pAcc->GetPaletteColor( i );
    1551                 :            : 
    1552   [ #  #  #  #  :          0 :                 if( nMinR <= rCol.GetRed() && nMaxR >= rCol.GetRed() &&
          #  #  #  #  #  
              # ][ #  # ]
                 [ #  # ]
    1553                 :          0 :                     nMinG <= rCol.GetGreen() && nMaxG >= rCol.GetGreen() &&
    1554                 :          0 :                     nMinB <= rCol.GetBlue() && nMaxB >= rCol.GetBlue() )
    1555                 :            :                 {
    1556                 :          0 :                     pAcc->SetPaletteColor( i, rReplaceColor );
    1557                 :            :                 }
    1558                 :            :             }
    1559                 :            :         }
    1560                 :            :         else
    1561                 :            :         {
    1562                 :       1040 :             BitmapColor         aCol;
    1563         [ +  - ]:       1040 :             const BitmapColor   aReplace( pAcc->GetBestMatchingColor( rReplaceColor ) );
    1564                 :            : 
    1565         [ +  + ]:      24700 :             for( long nY = 0L, nHeight = pAcc->Height(); nY < nHeight; nY++ )
    1566                 :            :             {
    1567         [ +  + ]:     365300 :                 for( long nX = 0L, nWidth = pAcc->Width(); nX < nWidth; nX++ )
    1568                 :            :                 {
    1569         [ +  - ]:     341640 :                     aCol = pAcc->GetPixel( nY, nX );
    1570                 :            : 
    1571   [ +  -  +  -  :     809640 :                     if( nMinR <= aCol.GetRed() && nMaxR >= aCol.GetRed() &&
          +  -  +  -  +  
              - ][ +  + ]
                 [ +  + ]
    1572                 :     234000 :                         nMinG <= aCol.GetGreen() && nMaxG >= aCol.GetGreen() &&
    1573                 :     234000 :                         nMinB <= aCol.GetBlue() && nMaxB >= aCol.GetBlue() )
    1574                 :            :                     {
    1575         [ +  - ]:     117000 :                         pAcc->SetPixel( nY, nX, aReplace );
    1576                 :            :                     }
    1577                 :            :                 }
    1578                 :       1040 :             }
    1579                 :            :         }
    1580                 :            : 
    1581                 :       1040 :         ReleaseAccess( pAcc );
    1582                 :       1040 :         bRet = sal_True;
    1583                 :            :     }
    1584                 :            : 
    1585                 :       1040 :     return bRet;
    1586                 :            : }
    1587                 :            : 
    1588                 :            : // ------------------------------------------------------------------
    1589                 :            : 
    1590                 :        166 : sal_Bool Bitmap::Replace( const Color* pSearchColors, const Color* pReplaceColors,
    1591                 :            :                       sal_uLong nColorCount, sal_uLong* _pTols )
    1592                 :            : {
    1593                 :            :     // Bitmaps with 1 bit color depth can cause problems
    1594                 :            :     // if they have other entries than black/white in their palette
    1595         [ +  + ]:        166 :     if( 1 == GetBitCount() )
    1596                 :        126 :         Convert( BMP_CONVERSION_4BIT_COLORS );
    1597                 :            : 
    1598                 :        166 :     BitmapWriteAccess*  pAcc = AcquireWriteAccess();
    1599                 :        166 :     sal_Bool                bRet = sal_False;
    1600                 :            : 
    1601         [ +  - ]:        166 :     if( pAcc )
    1602                 :            :     {
    1603                 :        166 :         long*   pMinR = new long[ nColorCount ];
    1604                 :        166 :         long*   pMaxR = new long[ nColorCount ];
    1605                 :        166 :         long*   pMinG = new long[ nColorCount ];
    1606                 :        166 :         long*   pMaxG = new long[ nColorCount ];
    1607                 :        166 :         long*   pMinB = new long[ nColorCount ];
    1608                 :        166 :         long*   pMaxB = new long[ nColorCount ];
    1609                 :            :         long*   pTols;
    1610                 :            :         sal_uLong   i;
    1611                 :            : 
    1612         [ +  - ]:        166 :         if( !_pTols )
    1613                 :            :         {
    1614                 :        166 :             pTols = new long[ nColorCount ];
    1615                 :        166 :             memset( pTols, 0, nColorCount * sizeof( long ) );
    1616                 :            :         }
    1617                 :            :         else
    1618                 :          0 :             pTols = (long*) _pTols;
    1619                 :            : 
    1620         [ +  + ]:        658 :         for( i = 0UL; i < nColorCount; i++ )
    1621                 :            :         {
    1622                 :        492 :             const Color&    rCol = pSearchColors[ i ];
    1623                 :        492 :             const long      nTol = pTols[ i ];
    1624                 :            : 
    1625                 :        492 :             pMinR[ i ] = MinMax( (long) rCol.GetRed() - nTol, 0, 255 );
    1626                 :        492 :             pMaxR[ i ] = MinMax( (long) rCol.GetRed() + nTol, 0, 255 );
    1627                 :        492 :             pMinG[ i ] = MinMax( (long) rCol.GetGreen() - nTol, 0, 255 );
    1628                 :        492 :             pMaxG[ i ] = MinMax( (long) rCol.GetGreen() + nTol, 0, 255 );
    1629                 :        492 :             pMinB[ i ] = MinMax( (long) rCol.GetBlue() - nTol, 0, 255 );
    1630                 :        492 :             pMaxB[ i ] = MinMax( (long) rCol.GetBlue() + nTol, 0, 255 );
    1631                 :            :         }
    1632                 :            : 
    1633         [ +  - ]:        166 :         if( pAcc->HasPalette() )
    1634                 :            :         {
    1635         [ +  + ]:       7622 :             for( sal_uInt16 nEntry = 0, nPalCount = pAcc->GetPaletteEntryCount(); nEntry < nPalCount; nEntry++ )
    1636                 :            :             {
    1637                 :       7456 :                 const BitmapColor& rCol = pAcc->GetPaletteColor( nEntry );
    1638                 :            : 
    1639         [ +  + ]:      21170 :                 for( i = 0UL; i < nColorCount; i++ )
    1640                 :            :                 {
    1641 [ +  + ][ +  +  :      70830 :                     if( pMinR[ i ] <= rCol.GetRed() && pMaxR[ i ] >= rCol.GetRed() &&
          +  +  +  +  +  
                +  +  + ]
                 [ +  + ]
    1642                 :      25146 :                         pMinG[ i ] <= rCol.GetGreen() && pMaxG[ i ] >= rCol.GetGreen() &&
    1643                 :      24720 :                         pMinB[ i ] <= rCol.GetBlue() && pMaxB[ i ] >= rCol.GetBlue() )
    1644                 :            :                     {
    1645                 :       7250 :                         pAcc->SetPaletteColor( (sal_uInt16)nEntry, pReplaceColors[ i ] );
    1646                 :       7250 :                         break;
    1647                 :            :                     }
    1648                 :            :                 }
    1649                 :            :             }
    1650                 :            :         }
    1651                 :            :         else
    1652                 :            :         {
    1653                 :          0 :             BitmapColor     aCol;
    1654 [ #  # ][ #  # ]:          0 :             BitmapColor*    pReplaces = new BitmapColor[ nColorCount ];
    1655                 :            : 
    1656         [ #  # ]:          0 :             for( i = 0UL; i < nColorCount; i++ )
    1657         [ #  # ]:          0 :                 pReplaces[ i ] = pAcc->GetBestMatchingColor( pReplaceColors[ i ] );
    1658                 :            : 
    1659         [ #  # ]:          0 :             for( long nY = 0L, nHeight = pAcc->Height(); nY < nHeight; nY++ )
    1660                 :            :             {
    1661         [ #  # ]:          0 :                 for( long nX = 0L, nWidth = pAcc->Width(); nX < nWidth; nX++ )
    1662                 :            :                 {
    1663         [ #  # ]:          0 :                     aCol = pAcc->GetPixel( nY, nX );
    1664                 :            : 
    1665         [ #  # ]:          0 :                     for( i = 0UL; i < nColorCount; i++ )
    1666                 :            :                     {
    1667 [ #  # ][ #  #  :          0 :                         if( pMinR[ i ] <= aCol.GetRed() && pMaxR[ i ] >= aCol.GetRed() &&
          #  #  #  #  #  
                #  #  # ]
                 [ #  # ]
    1668                 :          0 :                             pMinG[ i ] <= aCol.GetGreen() && pMaxG[ i ] >= aCol.GetGreen() &&
    1669                 :          0 :                             pMinB[ i ] <= aCol.GetBlue() && pMaxB[ i ] >= aCol.GetBlue() )
    1670                 :            :                         {
    1671         [ #  # ]:          0 :                             pAcc->SetPixel( nY, nX, pReplaces[ i ] );
    1672                 :          0 :                             break;
    1673                 :            :                         }
    1674                 :            :                     }
    1675                 :            :                 }
    1676                 :            :             }
    1677                 :            : 
    1678 [ #  # ][ #  # ]:          0 :             delete[] pReplaces;
    1679                 :            :         }
    1680                 :            : 
    1681         [ +  - ]:        166 :         if( !_pTols )
    1682         [ +  - ]:        166 :             delete[] pTols;
    1683                 :            : 
    1684         [ +  - ]:        166 :         delete[] pMinR;
    1685         [ +  - ]:        166 :         delete[] pMaxR;
    1686         [ +  - ]:        166 :         delete[] pMinG;
    1687         [ +  - ]:        166 :         delete[] pMaxG;
    1688         [ +  - ]:        166 :         delete[] pMinB;
    1689         [ +  - ]:        166 :         delete[] pMaxB;
    1690                 :        166 :         ReleaseAccess( pAcc );
    1691                 :        166 :         bRet = sal_True;
    1692                 :            :     }
    1693                 :            : 
    1694                 :        166 :     return bRet;
    1695                 :            : }
    1696                 :            : 
    1697                 :            : // ------------------------------------------------------------------
    1698                 :            : 
    1699                 :          6 : Bitmap Bitmap::CreateDisplayBitmap( OutputDevice* pDisplay )
    1700                 :            : {
    1701                 :          6 :     Bitmap aDispBmp( *this );
    1702                 :            : 
    1703 [ -  + ][ #  # ]:          6 :     if( mpImpBmp && ( pDisplay->mpGraphics || pDisplay->ImplGetGraphics() ) )
         [ #  # ][ +  - ]
                 [ +  - ]
    1704                 :            :     {
    1705 [ +  - ][ +  - ]:          6 :         ImpBitmap* pImpDispBmp = new ImpBitmap;
    1706                 :            : 
    1707 [ +  - ][ -  + ]:          6 :         if( pImpDispBmp->ImplCreate( *mpImpBmp, pDisplay->mpGraphics ) )
    1708         [ #  # ]:          0 :             aDispBmp.ImplSetImpBitmap( pImpDispBmp );
    1709                 :            :         else
    1710 [ +  - ][ +  - ]:          6 :             delete pImpDispBmp;
    1711                 :            :     }
    1712                 :            : 
    1713                 :          6 :     return aDispBmp;
    1714                 :            : }
    1715                 :            : 
    1716                 :            : // ------------------------------------------------------------------
    1717                 :            : 
    1718                 :          0 : sal_Bool Bitmap::CombineSimple( const Bitmap& rMask, BmpCombine eCombine )
    1719                 :            : {
    1720                 :          0 :     BitmapReadAccess*   pMaskAcc = ( (Bitmap&) rMask ).AcquireReadAccess();
    1721                 :          0 :     BitmapWriteAccess*  pAcc = AcquireWriteAccess();
    1722                 :          0 :     sal_Bool                bRet = sal_False;
    1723                 :            : 
    1724 [ #  # ][ #  # ]:          0 :     if( pMaskAcc && pAcc )
    1725                 :            :     {
    1726                 :          0 :         const long          nWidth = Min( pMaskAcc->Width(), pAcc->Width() );
    1727                 :          0 :         const long          nHeight = Min( pMaskAcc->Height(), pAcc->Height() );
    1728                 :          0 :         const Color         aColBlack( COL_BLACK );
    1729                 :          0 :         BitmapColor         aPixel;
    1730                 :          0 :         BitmapColor         aMaskPixel;
    1731         [ #  # ]:          0 :         const BitmapColor   aWhite( pAcc->GetBestMatchingColor( Color( COL_WHITE ) ) );
    1732         [ #  # ]:          0 :         const BitmapColor   aBlack( pAcc->GetBestMatchingColor( aColBlack ) );
    1733         [ #  # ]:          0 :         const BitmapColor   aMaskBlack( pMaskAcc->GetBestMatchingColor( aColBlack ) );
    1734                 :            : 
    1735   [ #  #  #  #  :          0 :         switch( eCombine )
             #  #  #  #  
                      # ]
    1736                 :            :         {
    1737                 :            :             case( BMP_COMBINE_COPY ):
    1738                 :            :             {
    1739 [ #  # ][ #  # ]:          0 :                 for( long nY = 0L; nY < nHeight; nY++ ) for( long nX = 0L; nX < nWidth; nX++ )
    1740                 :            :                 {
    1741 [ #  # ][ #  # ]:          0 :                     if( pMaskAcc->GetPixel( nY, nX ) == aMaskBlack )
    1742         [ #  # ]:          0 :                         pAcc->SetPixel( nY, nX, aBlack );
    1743                 :            :                     else
    1744         [ #  # ]:          0 :                         pAcc->SetPixel( nY, nX, aWhite );
    1745                 :            :                 }
    1746                 :            :             }
    1747                 :          0 :             break;
    1748                 :            : 
    1749                 :            :             case( BMP_COMBINE_INVERT ):
    1750                 :            :             {
    1751 [ #  # ][ #  # ]:          0 :                 for( long nY = 0L; nY < nHeight; nY++ ) for( long nX = 0L; nX < nWidth; nX++ )
    1752                 :            :                 {
    1753 [ #  # ][ #  # ]:          0 :                     if( pAcc->GetPixel( nY, nX ) == aBlack )
    1754         [ #  # ]:          0 :                         pAcc->SetPixel( nY, nX, aWhite );
    1755                 :            :                     else
    1756         [ #  # ]:          0 :                         pAcc->SetPixel( nY, nX, aBlack );
    1757                 :            :                 }
    1758                 :            :             }
    1759                 :          0 :             break;
    1760                 :            : 
    1761                 :            :             case( BMP_COMBINE_AND ):
    1762                 :            :             {
    1763 [ #  # ][ #  # ]:          0 :                 for( long nY = 0L; nY < nHeight; nY++ ) for( long nX = 0L; nX < nWidth; nX++ )
    1764                 :            :                 {
    1765 [ #  # ][ #  # ]:          0 :                     if( pMaskAcc->GetPixel( nY, nX ) != aMaskBlack && pAcc->GetPixel( nY, nX ) != aBlack )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  #  
                   #  # ]
    1766         [ #  # ]:          0 :                         pAcc->SetPixel( nY, nX, aWhite );
    1767                 :            :                     else
    1768         [ #  # ]:          0 :                         pAcc->SetPixel( nY, nX, aBlack );
    1769                 :            :                 }
    1770                 :            :             }
    1771                 :          0 :             break;
    1772                 :            : 
    1773                 :            :             case( BMP_COMBINE_NAND ):
    1774                 :            :             {
    1775 [ #  # ][ #  # ]:          0 :                 for( long nY = 0L; nY < nHeight; nY++ ) for( long nX = 0L; nX < nWidth; nX++ )
    1776                 :            :                 {
    1777 [ #  # ][ #  # ]:          0 :                     if( pMaskAcc->GetPixel( nY, nX ) != aMaskBlack && pAcc->GetPixel( nY, nX ) != aBlack )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  #  
                   #  # ]
    1778         [ #  # ]:          0 :                         pAcc->SetPixel( nY, nX, aBlack );
    1779                 :            :                     else
    1780         [ #  # ]:          0 :                         pAcc->SetPixel( nY, nX, aWhite );
    1781                 :            :                 }
    1782                 :            :             }
    1783                 :          0 :             break;
    1784                 :            : 
    1785                 :            :             case( BMP_COMBINE_OR ):
    1786                 :            :             {
    1787 [ #  # ][ #  # ]:          0 :                 for( long nY = 0L; nY < nHeight; nY++ ) for( long nX = 0L; nX < nWidth; nX++ )
    1788                 :            :                 {
    1789 [ #  # ][ #  # ]:          0 :                     if( pMaskAcc->GetPixel( nY, nX ) != aMaskBlack || pAcc->GetPixel( nY, nX ) != aBlack )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  #  
                   #  # ]
    1790         [ #  # ]:          0 :                         pAcc->SetPixel( nY, nX, aWhite );
    1791                 :            :                     else
    1792         [ #  # ]:          0 :                         pAcc->SetPixel( nY, nX, aBlack );
    1793                 :            :                 }
    1794                 :            :             }
    1795                 :          0 :             break;
    1796                 :            : 
    1797                 :            :             case( BMP_COMBINE_NOR ):
    1798                 :            :             {
    1799 [ #  # ][ #  # ]:          0 :                 for( long nY = 0L; nY < nHeight; nY++ ) for( long nX = 0L; nX < nWidth; nX++ )
    1800                 :            :                 {
    1801 [ #  # ][ #  # ]:          0 :                     if( pMaskAcc->GetPixel( nY, nX ) != aMaskBlack || pAcc->GetPixel( nY, nX ) != aBlack )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  #  
                   #  # ]
    1802         [ #  # ]:          0 :                         pAcc->SetPixel( nY, nX, aBlack );
    1803                 :            :                     else
    1804         [ #  # ]:          0 :                         pAcc->SetPixel( nY, nX, aWhite );
    1805                 :            :                 }
    1806                 :            :             }
    1807                 :          0 :             break;
    1808                 :            : 
    1809                 :            :             case( BMP_COMBINE_XOR ):
    1810                 :            :             {
    1811 [ #  # ][ #  # ]:          0 :                 for( long nY = 0L; nY < nHeight; nY++ ) for( long nX = 0L; nX < nWidth; nX++ )
    1812                 :            :                 {
    1813         [ #  # ]:          0 :                     aPixel = pAcc->GetPixel( nY, nX );
    1814         [ #  # ]:          0 :                     aMaskPixel = pMaskAcc->GetPixel( nY, nX );
    1815                 :            : 
    1816   [ #  #  #  #  :          0 :                     if( ( aMaskPixel != aMaskBlack && aPixel == aBlack ) ||
           #  # ][ #  # ]
                 [ #  # ]
    1817                 :          0 :                         ( aMaskPixel == aMaskBlack && aPixel != aBlack ) )
    1818                 :            :                     {
    1819         [ #  # ]:          0 :                         pAcc->SetPixel( nY, nX, aWhite );
    1820                 :            :                     }
    1821                 :            :                     else
    1822         [ #  # ]:          0 :                         pAcc->SetPixel( nY, nX, aBlack );
    1823                 :            :                 }
    1824                 :            :             }
    1825                 :          0 :             break;
    1826                 :            : 
    1827                 :            :             case( BMP_COMBINE_NXOR ):
    1828                 :            :             {
    1829 [ #  # ][ #  # ]:          0 :                 for( long nY = 0L; nY < nHeight; nY++ ) for( long nX = 0L; nX < nWidth; nX++ )
    1830                 :            :                 {
    1831         [ #  # ]:          0 :                     aPixel = pAcc->GetPixel( nY, nX );
    1832         [ #  # ]:          0 :                     aMaskPixel = pMaskAcc->GetPixel( nY, nX );
    1833                 :            : 
    1834   [ #  #  #  #  :          0 :                     if( ( aMaskPixel != aMaskBlack && aPixel == aBlack ) ||
           #  # ][ #  # ]
                 [ #  # ]
    1835                 :          0 :                         ( aMaskPixel == aMaskBlack && aPixel != aBlack ) )
    1836                 :            :                     {
    1837         [ #  # ]:          0 :                         pAcc->SetPixel( nY, nX, aBlack );
    1838                 :            :                     }
    1839                 :            :                     else
    1840         [ #  # ]:          0 :                         pAcc->SetPixel( nY, nX, aWhite );
    1841                 :            :                 }
    1842                 :            :             }
    1843                 :          0 :             break;
    1844                 :            :         }
    1845                 :            : 
    1846                 :          0 :         bRet = sal_True;
    1847                 :            :     }
    1848                 :            : 
    1849                 :          0 :     ( (Bitmap&) rMask ).ReleaseAccess( pMaskAcc );
    1850                 :          0 :     ReleaseAccess( pAcc );
    1851                 :            : 
    1852                 :          0 :     return bRet;
    1853                 :            : }
    1854                 :            : 
    1855                 :            : // ------------------------------------------------------------------
    1856                 :            : 
    1857                 :          0 : sal_Bool Bitmap::Blend( const AlphaMask& rAlpha, const Color& rBackgroundColor )
    1858                 :            : {
    1859                 :            :     // TODO: Have a look at OutputDevice::ImplDrawAlpha() for some
    1860                 :            :     // optimizations. Might even consolidate the code here and there.
    1861                 :            : 
    1862                 :            :     // convert to a truecolor bitmap, if we're a paletted one. There's
    1863                 :            :     // room for tradeoff decision here, maybe later for an overload (or a flag)
    1864         [ #  # ]:          0 :     if( GetBitCount() <= 8 )
    1865                 :          0 :         Convert( BMP_CONVERSION_24BIT );
    1866                 :            : 
    1867                 :          0 :     BitmapReadAccess*   pAlphaAcc = const_cast<AlphaMask&>(rAlpha).AcquireReadAccess();
    1868                 :          0 :     BitmapWriteAccess*  pAcc = AcquireWriteAccess();
    1869                 :          0 :     sal_Bool                bRet = sal_False;
    1870                 :            : 
    1871 [ #  # ][ #  # ]:          0 :     if( pAlphaAcc && pAcc )
    1872                 :            :     {
    1873                 :          0 :         const long          nWidth = Min( pAlphaAcc->Width(), pAcc->Width() );
    1874                 :          0 :         const long          nHeight = Min( pAlphaAcc->Height(), pAcc->Height() );
    1875                 :            : 
    1876         [ #  # ]:          0 :         for( long nY = 0L; nY < nHeight; ++nY )
    1877         [ #  # ]:          0 :             for( long nX = 0L; nX < nWidth; ++nX )
    1878                 :            :                 pAcc->SetPixel( nY, nX,
    1879                 :            :                                 pAcc->GetPixel( nY, nX ).Merge( rBackgroundColor,
    1880 [ #  # ][ #  # ]:          0 :                                                                 255 - pAlphaAcc->GetPixel( nY, nX ) ) );
    1881                 :            : 
    1882                 :          0 :         bRet = sal_True;
    1883                 :            :     }
    1884                 :            : 
    1885                 :          0 :     const_cast<AlphaMask&>(rAlpha).ReleaseAccess( pAlphaAcc );
    1886                 :          0 :     ReleaseAccess( pAcc );
    1887                 :            : 
    1888                 :          0 :     return bRet;
    1889                 :            : }
    1890                 :            : 
    1891                 :            : // ------------------------------------------------------------------
    1892                 :            : 
    1893                 :          0 : sal_Bool Bitmap::MakeMono( sal_uInt8 cThreshold )
    1894                 :            : {
    1895                 :          0 :     return ImplMakeMono( cThreshold );
    1896                 :            : }
    1897                 :            : 
    1898                 :            : // ------------------------------------------------------------------
    1899                 :            : 
    1900                 :          0 : bool Bitmap::GetSystemData( BitmapSystemData& rData ) const
    1901                 :            : {
    1902                 :          0 :     bool bRet = false;
    1903         [ #  # ]:          0 :     if( mpImpBmp )
    1904                 :            :     {
    1905                 :          0 :         SalBitmap* pSalBitmap = mpImpBmp->ImplGetSalBitmap();
    1906         [ #  # ]:          0 :         if( pSalBitmap )
    1907                 :          0 :             bRet = pSalBitmap->GetSystemData( rData );
    1908                 :            :     }
    1909                 :            : 
    1910                 :          0 :     return bRet;
    1911                 :            : }
    1912                 :            : 
    1913                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10