LCOV - code coverage report
Current view: top level - filter/source/graphicfilter/eppm - eppm.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 88 0.0 %
Date: 2012-08-25 Functions: 0 7 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           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 <vcl/svapp.hxx>
      31                 :            : #include <vcl/graph.hxx>
      32                 :            : #include <vcl/bmpacc.hxx>
      33                 :            : #include <vcl/msgbox.hxx>
      34                 :            : #include <svl/solar.hrc>
      35                 :            : #include <svtools/fltcall.hxx>
      36                 :            : #include <svtools/FilterConfigItem.hxx>
      37                 :            : 
      38                 :            : //============================ PPMWriter ==================================
      39                 :            : 
      40                 :            : class PPMWriter {
      41                 :            : 
      42                 :            : private:
      43                 :            : 
      44                 :            :     SvStream& m_rOStm;          // Die auszugebende PPM-Datei
      45                 :            :     sal_uInt16              mpOStmOldModus;
      46                 :            : 
      47                 :            :     sal_Bool                mbStatus;
      48                 :            :     sal_Int32           mnMode;
      49                 :            :     BitmapReadAccess*   mpAcc;
      50                 :            :     sal_uLong               mnWidth, mnHeight;  // Bildausmass in Pixeln
      51                 :            : 
      52                 :            :     sal_Bool                ImplWriteHeader();
      53                 :            :     void                ImplWriteBody();
      54                 :            :     void                ImplWriteNumber( sal_Int32 );
      55                 :            : 
      56                 :            :     com::sun::star::uno::Reference< com::sun::star::task::XStatusIndicator > xStatusIndicator;
      57                 :            : 
      58                 :            : public:
      59                 :            :                         PPMWriter(SvStream &rStrm);
      60                 :            :                         ~PPMWriter();
      61                 :            : 
      62                 :            :     sal_Bool                WritePPM( const Graphic& rGraphic, FilterConfigItem* pFilterConfigItem );
      63                 :            : };
      64                 :            : 
      65                 :            : //=================== Methods of PPMWriter ==============================
      66                 :            : 
      67                 :          0 : PPMWriter::PPMWriter(SvStream &rStrm)
      68                 :            :     : m_rOStm(rStrm)
      69                 :            :     , mbStatus  ( sal_True )
      70                 :          0 :     , mpAcc     ( NULL )
      71                 :            : {
      72                 :          0 : }
      73                 :            : 
      74                 :            : // ------------------------------------------------------------------------
      75                 :            : 
      76                 :          0 : PPMWriter::~PPMWriter()
      77                 :            : {
      78                 :          0 : }
      79                 :            : 
      80                 :            : // ------------------------------------------------------------------------
      81                 :            : 
      82                 :          0 : sal_Bool PPMWriter::WritePPM( const Graphic& rGraphic, FilterConfigItem* pFilterConfigItem )
      83                 :            : {
      84                 :          0 :     if ( pFilterConfigItem )
      85                 :            :     {
      86                 :          0 :         mnMode = pFilterConfigItem->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "FileFormat" ) ), 0 );
      87                 :            : 
      88                 :          0 :         xStatusIndicator = pFilterConfigItem->GetStatusIndicator();
      89                 :          0 :         if ( xStatusIndicator.is() )
      90                 :            :         {
      91                 :          0 :             rtl::OUString aMsg;
      92                 :          0 :             xStatusIndicator->start( aMsg, 100 );
      93                 :            :         }
      94                 :            :     }
      95                 :            : 
      96                 :          0 :     BitmapEx    aBmpEx( rGraphic.GetBitmapEx() );
      97                 :          0 :     Bitmap      aBmp = aBmpEx.GetBitmap();
      98                 :          0 :     aBmp.Convert( BMP_CONVERSION_24BIT );
      99                 :            : 
     100                 :          0 :     mpOStmOldModus = m_rOStm.GetNumberFormatInt();
     101                 :          0 :     m_rOStm.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN );
     102                 :            : 
     103                 :          0 :     mpAcc = aBmp.AcquireReadAccess();
     104                 :          0 :     if( mpAcc )
     105                 :            :     {
     106                 :          0 :         if ( ImplWriteHeader() )
     107                 :            :         {
     108                 :          0 :             ImplWriteBody();
     109                 :            :         }
     110                 :          0 :         aBmp.ReleaseAccess( mpAcc );
     111                 :            :     }
     112                 :            :     else
     113                 :          0 :         mbStatus = sal_False;
     114                 :            : 
     115                 :          0 :     m_rOStm.SetNumberFormatInt( mpOStmOldModus );
     116                 :            : 
     117                 :          0 :     if ( xStatusIndicator.is() )
     118                 :          0 :         xStatusIndicator->end();
     119                 :            : 
     120                 :          0 :     return mbStatus;
     121                 :            : }
     122                 :            : 
     123                 :            : // ------------------------------------------------------------------------
     124                 :            : 
     125                 :          0 : sal_Bool PPMWriter::ImplWriteHeader()
     126                 :            : {
     127                 :          0 :     mnWidth = mpAcc->Width();
     128                 :          0 :     mnHeight = mpAcc->Height();
     129                 :          0 :     if ( mnWidth && mnHeight )
     130                 :            :     {
     131                 :          0 :         if ( mnMode == 0 )
     132                 :          0 :             m_rOStm << "P6\x0a";
     133                 :            :         else
     134                 :          0 :             m_rOStm << "P3\x0a";
     135                 :            : 
     136                 :          0 :         ImplWriteNumber( mnWidth );
     137                 :          0 :         m_rOStm << (sal_uInt8)32;
     138                 :          0 :         ImplWriteNumber( mnHeight );
     139                 :          0 :         m_rOStm << (sal_uInt8)32;
     140                 :          0 :         ImplWriteNumber( 255 );         // max. col.
     141                 :          0 :         m_rOStm << (sal_uInt8)10;
     142                 :            :     }
     143                 :            :     else
     144                 :          0 :         mbStatus = sal_False;
     145                 :            : 
     146                 :          0 :     return mbStatus;
     147                 :            : }
     148                 :            : 
     149                 :            : // ------------------------------------------------------------------------
     150                 :            : 
     151                 :          0 : void PPMWriter::ImplWriteBody()
     152                 :            : {
     153                 :          0 :     if ( mnMode == 0 )
     154                 :            :     {
     155                 :          0 :         for ( sal_uLong y = 0; y < mnHeight; y++ )
     156                 :            :         {
     157                 :          0 :             for ( sal_uLong x = 0; x < mnWidth; x++ )
     158                 :            :             {
     159                 :          0 :                 const BitmapColor& rColor = mpAcc->GetPixel( y, x );
     160                 :          0 :                 m_rOStm << rColor.GetRed();
     161                 :          0 :                 m_rOStm << rColor.GetGreen();
     162                 :          0 :                 m_rOStm << rColor.GetBlue();
     163                 :          0 :             }
     164                 :            :         }
     165                 :            :     }
     166                 :            :     else
     167                 :            :     {
     168                 :          0 :         for ( sal_uLong y = 0; y < mnHeight; y++ )
     169                 :            :         {
     170                 :          0 :             int nCount = 70;
     171                 :          0 :             for ( sal_uLong x = 0; x < mnWidth; x++ )
     172                 :            :             {
     173                 :            :                 sal_uInt8 i, nDat[3], nNumb;
     174                 :          0 :                 if ( nCount < 0 )
     175                 :            :                 {
     176                 :          0 :                     nCount = 69;
     177                 :          0 :                     m_rOStm << (sal_uInt8)10;
     178                 :            :                 }
     179                 :          0 :                 nDat[0] = mpAcc->GetPixel( y, x ).GetRed();
     180                 :          0 :                 nDat[1] = mpAcc->GetPixel( y, x ).GetGreen();
     181                 :          0 :                 nDat[2] = mpAcc->GetPixel( y, x ).GetBlue();
     182                 :          0 :                 for ( i = 0; i < 3; i++ )
     183                 :            :                 {
     184                 :          0 :                     nNumb = nDat[ i ] / 100;
     185                 :          0 :                     if ( nNumb )
     186                 :            :                     {
     187                 :          0 :                         m_rOStm << (sal_uInt8)( nNumb + '0' );
     188                 :          0 :                         nDat[ i ] -= ( nNumb * 100 );
     189                 :          0 :                         nNumb = nDat[ i ] / 10;
     190                 :          0 :                         m_rOStm << (sal_uInt8)( nNumb + '0' );
     191                 :          0 :                         nDat[ i ] -= ( nNumb * 10 );
     192                 :          0 :                         m_rOStm << (sal_uInt8)( nDat[ i ] + '0' );
     193                 :          0 :                         nCount -= 4;
     194                 :            :                     }
     195                 :            :                     else
     196                 :            :                     {
     197                 :          0 :                         nNumb = nDat[ i ] / 10;
     198                 :          0 :                         if ( nNumb )
     199                 :            :                         {
     200                 :          0 :                             m_rOStm << (sal_uInt8)( nNumb + '0' );
     201                 :          0 :                             nDat[ i ] -= ( nNumb * 10 );
     202                 :          0 :                             m_rOStm << (sal_uInt8)( nDat[ i ] + '0' );
     203                 :          0 :                             nCount -= 3;
     204                 :            :                         }
     205                 :            :                         else
     206                 :            :                         {
     207                 :          0 :                             m_rOStm << (sal_uInt8)( nDat[ i ] + '0' );
     208                 :          0 :                             nCount -= 2;
     209                 :            :                         }
     210                 :            :                     }
     211                 :          0 :                     m_rOStm << (sal_uInt8)' ';
     212                 :            :                 }
     213                 :            :             }
     214                 :          0 :             m_rOStm << (sal_uInt8)10;
     215                 :            :         }
     216                 :            :     }
     217                 :          0 : }
     218                 :            : 
     219                 :            : // ------------------------------------------------------------------------
     220                 :            : // a decimal number in ASCII format is being written into the stream
     221                 :            : 
     222                 :          0 : void PPMWriter::ImplWriteNumber(sal_Int32 nNumber)
     223                 :            : {
     224                 :          0 :     const rtl::OString aNum(rtl::OString::valueOf(nNumber));
     225                 :          0 :     m_rOStm << aNum.getStr();
     226                 :          0 : }
     227                 :            : 
     228                 :            : // ------------------------------------------------------------------------
     229                 :            : 
     230                 :            : // ---------------------
     231                 :            : // - exported function -
     232                 :            : // ---------------------
     233                 :            : 
     234                 :            : extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool __LOADONCALLAPI
     235                 :          0 : GraphicExport(SvStream& rStream, Graphic& rGraphic, FilterConfigItem* pFilterConfigItem, sal_Bool)
     236                 :            : {
     237                 :          0 :     PPMWriter aPPMWriter(rStream);
     238                 :          0 :     return aPPMWriter.WritePPM( rGraphic, pFilterConfigItem );
     239                 :            : }
     240                 :            : 
     241                 :            : // ------------------------------------------------------------------------
     242                 :            : 
     243                 :            : 
     244                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10