LCOV - code coverage report
Current view: top level - forms/source/component - imgprod.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 119 246 48.4 %
Date: 2012-08-25 Functions: 16 29 55.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 99 484 20.5 %

           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 "imgprod.hxx"
      31                 :            : 
      32                 :            : #include <vcl/bmpacc.hxx>
      33                 :            : #include <vcl/cvtgrf.hxx>
      34                 :            : #include <vcl/svapp.hxx>
      35                 :            : #include <unotools/ucbstreamhelper.hxx>
      36                 :            : #include <svtools/filter.hxx>
      37                 :            : #include <com/sun/star/io/XInputStream.hpp>
      38                 :            : 
      39                 :            : #include "svtools/imageresourceaccess.hxx"
      40                 :            : #include <comphelper/processfactory.hxx>
      41                 :            : 
      42                 :            : // --------------------
      43                 :            : // - ImgProdLockBytes -
      44                 :            : // --------------------
      45                 :            : 
      46                 :            : class ImgProdLockBytes : public SvLockBytes
      47                 :            : {
      48                 :            :     ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >      xStmRef;
      49                 :            :     ::com::sun::star::uno::Sequence<sal_Int8>       maSeq;
      50                 :            : 
      51                 :            :                         ImgProdLockBytes() {};
      52                 :            : 
      53                 :            : public:
      54                 :            : 
      55                 :            :                         ImgProdLockBytes( SvStream* pStm, sal_Bool bOwner );
      56                 :            :                         ImgProdLockBytes( ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > & rStreamRef );
      57                 :            :     virtual             ~ImgProdLockBytes();
      58                 :            : 
      59                 :            :     virtual ErrCode     ReadAt( sal_Size nPos, void* pBuffer, sal_Size nCount, sal_Size* pRead ) const;
      60                 :            :     virtual ErrCode     WriteAt( sal_Size nPos, const void* pBuffer, sal_Size nCount, sal_Size* pWritten );
      61                 :            :     virtual ErrCode     Flush() const;
      62                 :            :     virtual ErrCode     SetSize( sal_Size nSize );
      63                 :            :     virtual ErrCode     Stat( SvLockBytesStat*, SvLockBytesStatFlag ) const;
      64                 :            : };
      65                 :            : 
      66                 :            : // ------------------------------------------------------------------------
      67                 :            : 
      68                 :          0 : ImgProdLockBytes::ImgProdLockBytes( SvStream* pStm, sal_Bool bOwner ) :
      69 [ #  # ][ #  # ]:          0 :         SvLockBytes( pStm, bOwner )
         [ #  # ][ #  # ]
      70                 :            : {
      71                 :          0 : }
      72                 :            : 
      73                 :            : // ------------------------------------------------------------------------
      74                 :            : 
      75                 :          2 : ImgProdLockBytes::ImgProdLockBytes( ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > & rStmRef ) :
      76 [ +  - ][ +  - ]:          2 :         xStmRef( rStmRef )
         [ #  # ][ #  # ]
      77                 :            : {
      78 [ +  - ][ #  # ]:          2 :     if( xStmRef.is() )
      79                 :            :     {
      80                 :          2 :         const sal_uInt32    nBytesToRead = 65535;
      81                 :            :         sal_uInt32          nRead;
      82                 :            : 
      83 [ -  + ][ #  # ]:          2 :         do
      84                 :            :         {
      85 [ +  - ][ #  # ]:          2 :             ::com::sun::star::uno::Sequence< sal_Int8 > aReadSeq;
      86                 :            : 
      87 [ +  - ][ +  - ]:          2 :             nRead = xStmRef->readSomeBytes( aReadSeq, nBytesToRead );
         [ #  # ][ #  # ]
      88                 :            : 
      89 [ +  - ][ #  # ]:          2 :             if( nRead )
      90                 :            :             {
      91                 :          2 :                 const sal_uInt32 nOldLength = maSeq.getLength();
      92   [ +  -  #  # ]:          2 :                 maSeq.realloc( nOldLength + nRead );
      93 [ +  - ][ +  - ]:          2 :                 rtl_copyMemory( maSeq.getArray() + nOldLength, aReadSeq.getConstArray(), aReadSeq.getLength() );
         [ #  # ][ #  # ]
      94 [ +  - ][ #  # ]:          2 :             }
      95                 :            :         }
      96                 :            :         while( nBytesToRead == nRead );
      97                 :            :     }
      98                 :          2 : }
      99                 :            : 
     100                 :            : // ------------------------------------------------------------------------
     101                 :            : 
     102 [ +  - ][ +  - ]:          4 : ImgProdLockBytes::~ImgProdLockBytes()
         [ #  # ][ #  # ]
     103                 :            : {
     104 [ +  - ][ -  + ]:          6 : }
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     105                 :            : 
     106                 :            : // ------------------------------------------------------------------------
     107                 :            : 
     108                 :          8 : ErrCode ImgProdLockBytes::ReadAt( sal_Size nPos, void* pBuffer, sal_Size nCount, sal_Size* pRead ) const
     109                 :            : {
     110         [ -  + ]:          8 :     if( GetStream() )
     111                 :            :     {
     112                 :          0 :         ( (SvStream*) GetStream() )->ResetError();
     113                 :          0 :         const ErrCode nErr = SvLockBytes::ReadAt( nPos, pBuffer, nCount, pRead );
     114                 :          0 :         ( (SvStream*) GetStream() )->ResetError();
     115                 :          0 :         return nErr;
     116                 :            :     }
     117                 :            :     else
     118                 :            :     {
     119                 :          8 :         const sal_Size nSeqLen = maSeq.getLength();
     120                 :          8 :         ErrCode nErr = ERRCODE_NONE;
     121                 :            : 
     122         [ +  - ]:          8 :         if( nPos < nSeqLen )
     123                 :            :         {
     124         [ +  + ]:          8 :             if( ( nPos + nCount ) > nSeqLen )
     125                 :          2 :                 nCount = nSeqLen - nPos;
     126                 :            : 
     127                 :          8 :             memcpy( pBuffer, maSeq.getConstArray() + nPos, nCount );
     128                 :          8 :             *pRead = nCount;
     129                 :            :         }
     130                 :            :         else
     131                 :          0 :             *pRead = 0UL;
     132                 :            : 
     133                 :          8 :         return nErr;
     134                 :            :     }
     135                 :            : }
     136                 :            : 
     137                 :            : // ------------------------------------------------------------------------
     138                 :            : 
     139                 :          0 : ErrCode ImgProdLockBytes::WriteAt( sal_Size nPos, const void* pBuffer, sal_Size nCount, sal_Size* pWritten )
     140                 :            : {
     141         [ #  # ]:          0 :     if( GetStream() )
     142                 :          0 :         return SvLockBytes::WriteAt( nPos, pBuffer, nCount, pWritten );
     143                 :            :     else
     144                 :            :     {
     145                 :            :         DBG_ASSERT( xStmRef.is(), "ImgProdLockBytes::WriteAt: xInputStream has no reference..." );
     146                 :          0 :         return ERRCODE_IO_CANTWRITE;
     147                 :            :     }
     148                 :            : }
     149                 :            : 
     150                 :            : // ------------------------------------------------------------------------
     151                 :            : 
     152                 :          2 : ErrCode ImgProdLockBytes::Flush() const
     153                 :            : {
     154                 :          2 :     return ERRCODE_NONE;
     155                 :            : }
     156                 :            : 
     157                 :            : // ------------------------------------------------------------------------
     158                 :            : 
     159                 :          0 : ErrCode ImgProdLockBytes::SetSize( sal_Size nSize )
     160                 :            : {
     161         [ #  # ]:          0 :     if( GetStream() )
     162                 :          0 :         return SvLockBytes::SetSize( nSize );
     163                 :            :     else
     164                 :            :     {
     165                 :            :         OSL_FAIL( "ImgProdLockBytes::SetSize not supported for xInputStream..." );
     166                 :          0 :         return ERRCODE_IO_CANTWRITE;
     167                 :            :     }
     168                 :            : }
     169                 :            : 
     170                 :            : // ------------------------------------------------------------------------
     171                 :            : 
     172                 :          2 : ErrCode ImgProdLockBytes::Stat( SvLockBytesStat* pStat, SvLockBytesStatFlag eFlag ) const
     173                 :            : {
     174         [ -  + ]:          2 :     if( GetStream() )
     175                 :          0 :         return SvLockBytes::Stat( pStat, eFlag );
     176                 :            :     else
     177                 :            :     {
     178                 :            :         DBG_ASSERT( xStmRef.is(), "ImgProdLockBytes::Stat: xInputStream has no reference..." );
     179                 :          2 :         pStat->nSize = maSeq.getLength();
     180                 :          2 :         return ERRCODE_NONE;
     181                 :            :     }
     182                 :            : }
     183                 :            : 
     184                 :            : // -----------------
     185                 :            : // - ImageProducer -
     186                 :            : // -----------------
     187                 :            : 
     188                 :         97 : ImageProducer::ImageProducer() :
     189                 :            :     mpStm       ( NULL ),
     190 [ +  - ][ +  - ]:         97 :     mbConsInit  ( sal_False )
     191                 :            : {
     192 [ +  - ][ +  - ]:         97 :     mpGraphic = new Graphic;
     193                 :            :     DBG_ASSERT( Application::GetFilterHdl().IsSet(), "ImageProducer::ImageProducer(): No filter handler set" );
     194                 :         97 : }
     195                 :            : 
     196                 :            : // ------------------------------------------------------------
     197                 :            : 
     198 [ +  - ][ +  - ]:         87 : ImageProducer::~ImageProducer()
     199                 :            : {
     200 [ +  - ][ +  - ]:         87 :     delete mpGraphic;
     201                 :         87 :     mpGraphic = NULL;
     202                 :            : 
     203 [ +  + ][ +  - ]:         87 :     delete mpStm;
     204                 :         87 :     mpStm = NULL;
     205         [ -  + ]:        174 : }
     206                 :            : 
     207                 :            : // ------------------------------------------------------------
     208                 :            : 
     209                 :            : // ::com::sun::star::uno::XInterface
     210                 :          2 : ::com::sun::star::uno::Any ImageProducer::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
     211                 :            : {
     212                 :            :     ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
     213                 :            :                                         (static_cast< ::com::sun::star::lang::XInitialization* >(this)),
     214         [ +  - ]:          2 :                                         (static_cast< ::com::sun::star::awt::XImageProducer* >(this)) );
     215 [ -  + ][ +  - ]:          2 :     return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ));
     216                 :            : }
     217                 :            : 
     218                 :            : // ------------------------------------------------------------
     219                 :            : 
     220                 :          0 : void ImageProducer::addConsumer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer >& rxConsumer ) throw(::com::sun::star::uno::RuntimeException)
     221                 :            : {
     222                 :            :     DBG_ASSERT( rxConsumer.is(), "::AddConsumer(...): No consumer referenced!" );
     223         [ #  # ]:          0 :     if( rxConsumer.is() )
     224                 :          0 :         maConsList.push_back( new ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer > ( rxConsumer ));
     225                 :          0 : }
     226                 :            : 
     227                 :            : // ------------------------------------------------------------
     228                 :            : 
     229                 :          0 : void ImageProducer::removeConsumer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer >& rxConsumer ) throw(::com::sun::star::uno::RuntimeException)
     230                 :            : {
     231 [ #  # ][ #  # ]:          0 :     ConsumerList_t::reverse_iterator riter = std::find(maConsList.rbegin(),maConsList.rend(),rxConsumer);
                 [ #  # ]
     232                 :            : 
     233 [ #  # ][ #  # ]:          0 :     if (riter != maConsList.rend())
                 [ #  # ]
     234 [ #  # ][ #  # ]:          0 :         maConsList.erase(riter.base()-1);
     235                 :          0 : }
     236                 :            : 
     237                 :            : // ------------------------------------------------------------
     238                 :            : 
     239                 :          2 : void ImageProducer::SetImage( const ::rtl::OUString& rPath )
     240                 :            : {
     241                 :          2 :     maURL = rPath;
     242                 :          2 :     mpGraphic->Clear();
     243                 :          2 :     mbConsInit = sal_False;
     244         [ -  + ]:          2 :     delete mpStm;
     245                 :            : 
     246         [ -  + ]:          2 :     if ( ::svt::GraphicAccess::isSupportedURL( maURL ) )
     247                 :            :     {
     248         [ #  # ]:          0 :         mpStm = ::svt::GraphicAccess::getImageStream( ::comphelper::getProcessServiceFactory(), maURL );
     249                 :            :     }
     250         [ -  + ]:          2 :     else if( !maURL.isEmpty() )
     251                 :            :     {
     252         [ #  # ]:          0 :         SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( maURL, STREAM_STD_READ );
     253 [ #  # ][ #  # ]:          0 :         mpStm = pIStm ? new SvStream( new ImgProdLockBytes( pIStm, sal_True ) ) : NULL;
                 [ #  # ]
     254                 :            :     }
     255                 :            :     else
     256                 :          2 :         mpStm = NULL;
     257                 :          2 : }
     258                 :            : 
     259                 :            : // ------------------------------------------------------------
     260                 :            : 
     261                 :          0 : void ImageProducer::SetImage( SvStream& rStm )
     262                 :            : {
     263                 :          0 :     maURL = ::rtl::OUString();
     264                 :          0 :     mpGraphic->Clear();
     265                 :          0 :     mbConsInit = sal_False;
     266                 :            : 
     267         [ #  # ]:          0 :     delete mpStm;
     268 [ #  # ][ #  # ]:          0 :     mpStm = new SvStream( new ImgProdLockBytes( &rStm, sal_False ) );
     269                 :          0 : }
     270                 :            : 
     271                 :            : // ------------------------------------------------------------
     272                 :            : 
     273                 :         12 : void ImageProducer::setImage( ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > & rInputStmRef )
     274                 :            : {
     275                 :         12 :     maURL = ::rtl::OUString();
     276                 :         12 :     mpGraphic->Clear();
     277                 :         12 :     mbConsInit = sal_False;
     278         [ -  + ]:         12 :     delete mpStm;
     279                 :            : 
     280         [ +  + ]:         12 :     if( rInputStmRef.is() )
     281 [ +  - ][ +  - ]:          2 :         mpStm = new SvStream( new ImgProdLockBytes( rInputStmRef ) );
     282                 :            :     else
     283                 :         10 :         mpStm = NULL;
     284                 :         12 : }
     285                 :            : 
     286                 :            : // ------------------------------------------------------------
     287                 :            : 
     288                 :          0 : void ImageProducer::NewDataAvailable()
     289                 :            : {
     290 [ #  # ][ #  # ]:          0 :     if( ( GRAPHIC_NONE == mpGraphic->GetType() ) || mpGraphic->GetContext() )
                 [ #  # ]
     291                 :          0 :         startProduction();
     292                 :          0 : }
     293                 :            : 
     294                 :            : // ------------------------------------------------------------
     295                 :            : 
     296                 :         12 : void ImageProducer::startProduction() throw(::com::sun::star::uno::RuntimeException)
     297                 :            : {
     298 [ +  - ][ +  - ]:         12 :     if( !maConsList.empty() || maDoneHdl.IsSet() )
                 [ +  - ]
     299                 :            :     {
     300                 :         12 :         bool bNotifyEmptyGraphics = false;
     301                 :            : 
     302                 :            :         // valid stream or filled graphic? => update consumers
     303 [ +  + ][ -  + ]:         12 :         if( mpStm || ( mpGraphic->GetType() != GRAPHIC_NONE ) )
                 [ +  + ]
     304                 :            :         {
     305                 :            :             // if we already have a graphic, we don't have to import again;
     306                 :            :             // graphic is cleared if a new Stream is set
     307 [ -  + ][ #  # ]:          2 :             if( ( mpGraphic->GetType() == GRAPHIC_NONE ) || mpGraphic->GetContext() )
                 [ +  - ]
     308                 :            :             {
     309 [ +  - ][ +  - ]:          2 :                 if ( ImplImportGraphic( *mpGraphic ) && maDoneHdl.IsSet() )
                 [ +  - ]
     310                 :          2 :                     maDoneHdl.Call( mpGraphic );
     311                 :            :             }
     312                 :            : 
     313         [ +  - ]:          2 :             if( mpGraphic->GetType() != GRAPHIC_NONE )
     314                 :          2 :                 ImplUpdateData( *mpGraphic );
     315                 :            :             else
     316                 :          0 :                 bNotifyEmptyGraphics = true;
     317                 :            :         }
     318                 :            :         else
     319                 :         10 :             bNotifyEmptyGraphics = true;
     320                 :            : 
     321         [ +  + ]:         12 :         if ( bNotifyEmptyGraphics )
     322                 :            :         {
     323                 :            :             // reset image
     324                 :            :             // create temporary list to hold interfaces
     325         [ +  - ]:         10 :             ConsumerList_t aTmp = maConsList;
     326                 :            : 
     327                 :            :             // iterate through interfaces
     328 [ +  - ][ #  # ]:         10 :             for( ConsumerList_t::iterator iter = aTmp.begin(); iter != aTmp.end(); ++iter )
         [ +  - ][ +  - ]
                 [ -  + ]
     329                 :            :             {
     330 [ #  # ][ #  # ]:          0 :                 (*iter)->init( 0, 0 );
                 [ #  # ]
     331 [ #  # ][ #  # ]:          0 :                 (*iter)->complete( ::com::sun::star::awt::ImageStatus::IMAGESTATUS_STATICIMAGEDONE, this );
         [ #  # ][ #  # ]
     332                 :            :             }
     333                 :            : 
     334 [ +  - ][ +  - ]:         10 :             if ( maDoneHdl.IsSet() )
     335 [ +  - ][ +  - ]:         10 :                 maDoneHdl.Call( NULL );
     336                 :            :         }
     337                 :            :     }
     338                 :         12 : }
     339                 :            : 
     340                 :            : // ------------------------------------------------------------
     341                 :            : 
     342                 :          2 : sal_Bool ImageProducer::ImplImportGraphic( Graphic& rGraphic )
     343                 :            : {
     344         [ -  + ]:          2 :     if( ERRCODE_IO_PENDING == mpStm->GetError() )
     345                 :          0 :         mpStm->ResetError();
     346                 :            : 
     347                 :          2 :     mpStm->Seek( 0UL );
     348                 :            : 
     349                 :          2 :     sal_Bool bRet = GraphicConverter::Import( *mpStm, rGraphic ) == ERRCODE_NONE;
     350                 :            : 
     351         [ -  + ]:          2 :     if( ERRCODE_IO_PENDING == mpStm->GetError() )
     352                 :          0 :         mpStm->ResetError();
     353                 :            : 
     354                 :          2 :     return bRet;
     355                 :            : }
     356                 :            : 
     357                 :            : // ------------------------------------------------------------
     358                 :            : 
     359                 :          2 : void ImageProducer::ImplUpdateData( const Graphic& rGraphic )
     360                 :            : {
     361                 :          2 :     ImplInitConsumer( rGraphic );
     362                 :            : 
     363 [ -  + ][ -  + ]:          2 :     if( mbConsInit && !maConsList.empty() )
                 [ +  - ]
     364                 :            :     {
     365                 :            :         // create temporary list to hold interfaces
     366         [ #  # ]:          0 :         ConsumerList_t aTmp = maConsList;
     367                 :            : 
     368         [ #  # ]:          0 :         ImplUpdateConsumer( rGraphic );
     369                 :          0 :         mbConsInit = sal_False;
     370                 :            : 
     371                 :            :         // iterate through interfaces
     372 [ #  # ][ #  # ]:          0 :         for( ConsumerList_t::iterator iter = aTmp.begin(); iter != aTmp.end(); ++iter )
         [ #  # ][ #  # ]
                 [ #  # ]
     373 [ #  # ][ #  # ]:          0 :             (*iter)->complete( ::com::sun::star::awt::ImageStatus::IMAGESTATUS_STATICIMAGEDONE, this );
         [ #  # ][ #  # ]
                 [ #  # ]
     374                 :            :     }
     375                 :          2 : }
     376                 :            : 
     377                 :            : // ------------------------------------------------------------
     378                 :            : 
     379                 :          2 : void ImageProducer::ImplInitConsumer( const Graphic& rGraphic )
     380                 :            : {
     381 [ +  - ][ +  - ]:          2 :     Bitmap              aBmp( rGraphic.GetBitmapEx().GetBitmap() );
                 [ +  - ]
     382         [ +  - ]:          2 :     BitmapReadAccess*   pBmpAcc = aBmp.AcquireReadAccess();
     383                 :            : 
     384         [ +  - ]:          2 :     if( pBmpAcc )
     385                 :            :     {
     386                 :          2 :         sal_uInt16       nPalCount = 0;
     387                 :          2 :         sal_uInt32       nRMask = 0;
     388                 :          2 :         sal_uInt32       nGMask = 0;
     389                 :          2 :         sal_uInt32       nBMask = 0;
     390                 :          2 :         sal_uInt32       nAMask = 0;
     391         [ +  - ]:          2 :         ::com::sun::star::uno::Sequence< sal_Int32 >    aRGBPal;
     392                 :            : 
     393         [ +  - ]:          2 :         if( pBmpAcc->HasPalette() )
     394                 :            :         {
     395                 :          2 :             nPalCount = pBmpAcc->GetPaletteEntryCount();
     396                 :            : 
     397         [ +  - ]:          2 :             if( nPalCount )
     398                 :            :             {
     399 [ +  - ][ +  - ]:          2 :                 aRGBPal = ::com::sun::star::uno::Sequence< sal_Int32 >( nPalCount + 1 );
                 [ +  - ]
     400                 :            : 
     401         [ +  - ]:          2 :                 sal_Int32* pTmp = aRGBPal.getArray();
     402                 :            : 
     403         [ +  + ]:        514 :                 for( sal_uInt32 i = 0; i < nPalCount; i++, pTmp++ )
     404                 :            :                 {
     405                 :        512 :                     const BitmapColor& rCol = pBmpAcc->GetPaletteColor( (sal_uInt16) i );
     406                 :            : 
     407                 :        512 :                     *pTmp = ( (sal_Int32) rCol.GetRed() ) << (sal_Int32)(24L);
     408                 :        512 :                     *pTmp |= ( (sal_Int32) rCol.GetGreen() ) << (sal_Int32)(16L);
     409                 :        512 :                     *pTmp |= ( (sal_Int32) rCol.GetBlue() ) << (sal_Int32)(8L);
     410                 :        512 :                     *pTmp |= (sal_Int32)(0x000000ffL);
     411                 :            :                 }
     412                 :            : 
     413 [ +  - ][ +  - ]:          2 :                 if( rGraphic.IsTransparent() )
     414                 :            :                 {
     415                 :            :                     // append transparent entry
     416                 :          2 :                     *pTmp = (sal_Int32)(0xffffff00L);
     417                 :          2 :                     mnTransIndex = nPalCount;
     418                 :          2 :                     nPalCount++;
     419                 :            :                 }
     420                 :            :                 else
     421                 :          0 :                     mnTransIndex = 0;
     422                 :            : 
     423                 :            :             }
     424                 :            :         }
     425                 :            :         else
     426                 :            :         {
     427                 :          0 :             nRMask = 0xff000000UL;
     428                 :          0 :             nGMask = 0x00ff0000UL;
     429                 :          0 :             nBMask = 0x0000ff00UL;
     430                 :          0 :             nAMask = 0x000000ffUL;
     431                 :            :         }
     432                 :            : 
     433                 :            :         // create temporary list to hold interfaces
     434         [ +  - ]:          2 :         ConsumerList_t aTmp = maConsList;
     435                 :            : 
     436                 :            :         // iterate through interfaces
     437 [ +  - ][ #  # ]:          2 :         for( ConsumerList_t::iterator iter = aTmp.begin(); iter != aTmp.end(); ++iter)
         [ +  - ][ +  - ]
                 [ -  + ]
     438                 :            :         {
     439 [ #  # ][ #  # ]:          0 :             (*iter)->init( pBmpAcc->Width(), pBmpAcc->Height() );
                 [ #  # ]
     440 [ #  # ][ #  # ]:          0 :             (*iter)->setColorModel( pBmpAcc->GetBitCount(),aRGBPal, nRMask, nGMask, nBMask, nAMask );
                 [ #  # ]
     441                 :            :         }
     442                 :            : 
     443         [ +  - ]:          2 :         aBmp.ReleaseAccess( pBmpAcc );
     444 [ +  - ][ +  - ]:          2 :         mbConsInit = sal_True;
     445         [ +  - ]:          2 :     }
     446                 :          2 : }
     447                 :            : 
     448                 :            : // ------------------------------------------------------------
     449                 :            : 
     450                 :          0 : void ImageProducer::ImplUpdateConsumer( const Graphic& rGraphic )
     451                 :            : {
     452         [ #  # ]:          0 :     BitmapEx            aBmpEx( rGraphic.GetBitmapEx() );
     453         [ #  # ]:          0 :     Bitmap              aBmp( aBmpEx.GetBitmap() );
     454         [ #  # ]:          0 :     BitmapReadAccess*   pBmpAcc = aBmp.AcquireReadAccess();
     455                 :            : 
     456         [ #  # ]:          0 :     if( pBmpAcc )
     457                 :            :     {
     458         [ #  # ]:          0 :         Bitmap              aMask( aBmpEx.GetMask() );
     459 [ #  # ][ #  # ]:          0 :         BitmapReadAccess*   pMskAcc = !!aMask ? aMask.AcquireReadAccess() : NULL;
     460                 :          0 :         const long          nWidth = pBmpAcc->Width();
     461                 :          0 :         const long          nHeight = pBmpAcc->Height();
     462                 :          0 :         const long          nStartX = 0L;
     463                 :          0 :         const long          nEndX = nWidth - 1L;
     464                 :          0 :         const long          nStartY = 0L;
     465                 :          0 :         const long          nEndY = nHeight - 1L;
     466                 :          0 :         const long          nPartWidth = nEndX - nStartX + 1;
     467                 :          0 :         const long          nPartHeight = nEndY - nStartY + 1;
     468                 :            : 
     469         [ #  # ]:          0 :         if( !pMskAcc )
     470                 :            :         {
     471 [ #  # ][ #  # ]:          0 :             aMask = Bitmap( aBmp.GetSizePixel(), 1 );
         [ #  # ][ #  # ]
     472         [ #  # ]:          0 :             aMask.Erase( COL_BLACK );
     473         [ #  # ]:          0 :             pMskAcc = aMask.AcquireReadAccess();
     474                 :            :         }
     475                 :            : 
     476                 :            :         // create temporary list to hold interfaces
     477         [ #  # ]:          0 :         ConsumerList_t aTmp = maConsList;
     478                 :            : 
     479         [ #  # ]:          0 :         if( pBmpAcc->HasPalette() )
     480                 :            :         {
     481         [ #  # ]:          0 :             const BitmapColor aWhite( pMskAcc->GetBestMatchingColor( Color( COL_WHITE ) ) );
     482                 :            : 
     483         [ #  # ]:          0 :             if( mnTransIndex < 256 )
     484                 :            :             {
     485         [ #  # ]:          0 :                 ::com::sun::star::uno::Sequence<sal_Int8>   aData( nPartWidth * nPartHeight );
     486         [ #  # ]:          0 :                 sal_Int8*                                   pTmp = aData.getArray();
     487                 :            : 
     488         [ #  # ]:          0 :                 for( long nY = nStartY; nY <= nEndY; nY++ )
     489                 :            :                 {
     490         [ #  # ]:          0 :                     for( long nX = nStartX; nX <= nEndX; nX++ )
     491                 :            :                     {
     492 [ #  # ][ #  # ]:          0 :                         if( pMskAcc->GetPixel( nY, nX ) == aWhite )
     493                 :            :                             *pTmp++ = sal::static_int_cast< sal_Int8 >(
     494                 :          0 :                                 mnTransIndex );
     495                 :            :                         else
     496         [ #  # ]:          0 :                             *pTmp++ = pBmpAcc->GetPixel( nY, nX ).GetIndex();
     497                 :            :                     }
     498                 :            :                 }
     499                 :            : 
     500                 :            :                 // iterate through interfaces
     501 [ #  # ][ #  # ]:          0 :                 for (ConsumerList_t::iterator iter = aTmp.begin(); iter != aTmp.end(); ++iter)
         [ #  # ][ #  # ]
                 [ #  # ]
     502 [ #  # ][ #  # ]:          0 :                     (*iter)->setPixelsByBytes( nStartX, nStartY, nPartWidth, nPartHeight, aData, 0UL, nPartWidth );
         [ #  # ][ #  # ]
     503                 :            :             }
     504                 :            :             else
     505                 :            :             {
     506         [ #  # ]:          0 :                 ::com::sun::star::uno::Sequence<sal_Int32>  aData( nPartWidth * nPartHeight );
     507         [ #  # ]:          0 :                 sal_Int32*                                  pTmp = aData.getArray();
     508                 :            : 
     509         [ #  # ]:          0 :                 for( long nY = nStartY; nY <= nEndY; nY++ )
     510                 :            :                 {
     511         [ #  # ]:          0 :                     for( long nX = nStartX; nX <= nEndX; nX++ )
     512                 :            :                     {
     513 [ #  # ][ #  # ]:          0 :                         if( pMskAcc->GetPixel( nY, nX ) == aWhite )
     514                 :          0 :                             *pTmp++ = mnTransIndex;
     515                 :            :                         else
     516         [ #  # ]:          0 :                             *pTmp++ = pBmpAcc->GetPixel( nY, nX ).GetIndex();
     517                 :            :                     }
     518                 :            :                 }
     519                 :            : 
     520                 :            :                 // iterate through interfaces
     521 [ #  # ][ #  # ]:          0 :                 for (ConsumerList_t::iterator iter = aTmp.begin(); iter != aTmp.end(); ++iter)
         [ #  # ][ #  # ]
                 [ #  # ]
     522 [ #  # ][ #  # ]:          0 :                     (*iter)->setPixelsByLongs( nStartX, nStartY, nPartWidth, nPartHeight, aData, 0UL, nPartWidth );
         [ #  # ][ #  # ]
     523                 :          0 :             }
     524                 :            :         }
     525                 :            :         else
     526                 :            :         {
     527         [ #  # ]:          0 :             ::com::sun::star::uno::Sequence<sal_Int32>  aData( nPartWidth * nPartHeight );
     528         [ #  # ]:          0 :             const BitmapColor                           aWhite( pMskAcc->GetBestMatchingColor( Color( COL_WHITE ) ) );
     529         [ #  # ]:          0 :             sal_Int32*                                  pTmp = aData.getArray();
     530                 :            : 
     531         [ #  # ]:          0 :             for( long nY = nStartY; nY <= nEndY; nY++ )
     532                 :            :             {
     533         [ #  # ]:          0 :                 for( long nX = nStartX; nX <= nEndX; nX++, pTmp++ )
     534                 :            :                 {
     535         [ #  # ]:          0 :                     const BitmapColor aCol( pBmpAcc->GetPixel( nY, nX ) );
     536                 :            : 
     537                 :          0 :                     *pTmp = ( (sal_Int32) aCol.GetRed() ) << (sal_Int32)(24L);
     538                 :          0 :                     *pTmp |= ( (sal_Int32) aCol.GetGreen() ) << (sal_Int32)(16L);
     539                 :          0 :                     *pTmp |= ( (sal_Int32) aCol.GetBlue() ) << (sal_Int32)(8L);
     540                 :            : 
     541 [ #  # ][ #  # ]:          0 :                     if( pMskAcc->GetPixel( nY, nX ) != aWhite )
     542                 :          0 :                         *pTmp |= 0x000000ffUL;
     543                 :          0 :                 }
     544                 :            :             }
     545                 :            : 
     546                 :            :             // iterate through interfaces
     547 [ #  # ][ #  # ]:          0 :                 for (ConsumerList_t::iterator iter = aTmp.begin(); iter != aTmp.end(); ++iter)
         [ #  # ][ #  # ]
                 [ #  # ]
     548 [ #  # ][ #  # ]:          0 :                     (*iter)->setPixelsByLongs( nStartX, nStartY, nPartWidth, nPartHeight, aData, 0UL, nPartWidth );
         [ #  # ][ #  # ]
     549                 :            :         }
     550                 :            : 
     551         [ #  # ]:          0 :         aBmp.ReleaseAccess( pBmpAcc );
     552 [ #  # ][ #  # ]:          0 :         aMask.ReleaseAccess( pMskAcc );
                 [ #  # ]
     553 [ #  # ][ #  # ]:          0 :     }
     554                 :          0 : }
     555                 :            : 
     556                 :          0 : void ImageProducer::initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
     557                 :            : {
     558         [ #  # ]:          0 :     if ( aArguments.getLength() == 1 )
     559                 :            :     {
     560                 :          0 :         ::com::sun::star::uno::Any aArg = aArguments.getConstArray()[0];
     561                 :          0 :         rtl::OUString aURL;
     562         [ #  # ]:          0 :         if ( aArg >>= aURL )
     563                 :            :         {
     564         [ #  # ]:          0 :             SetImage( aURL );
     565                 :          0 :         }
     566                 :            :     }
     567                 :          0 : }
     568                 :            : 
     569                 :            : namespace frm
     570                 :            : {
     571                 :            : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
     572                 :          0 : SAL_CALL ImageProducer_CreateInstance(
     573                 :            :     const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& )
     574                 :            : {
     575                 :            :     return ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface >(
     576 [ #  # ][ #  # ]:          0 :         ( ::cppu::OWeakObject* ) new ImageProducer );
     577                 :            : }
     578                 :            : } // namespace frm
     579                 :            : 
     580                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10