LCOV - code coverage report
Current view: top level - filter/source/graphicfilter/epbm - epbm.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 68 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                 :            : //============================ PBMWriter ==================================
      39                 :            : 
      40                 :            : class PBMWriter {
      41                 :            : 
      42                 :            : private:
      43                 :            : 
      44                 :            :     SvStream& m_rOStm;          // Die auszugebende PBM-Datei
      45                 :            :     sal_uInt16              mpOStmOldModus;
      46                 :            : 
      47                 :            :     sal_Bool                mbStatus;
      48                 :            :     sal_Int32           mnMode;             // 0 -> raw, 1-> ascii
      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                 :            :     PBMWriter(SvStream &rPBM);
      60                 :            :     ~PBMWriter();
      61                 :            : 
      62                 :            :     sal_Bool WritePBM( const Graphic& rGraphic, FilterConfigItem* pFilterConfigItem );
      63                 :            : };
      64                 :            : 
      65                 :            : //=================== Methoden von PBMWriter ==============================
      66                 :            : 
      67                 :          0 : PBMWriter::PBMWriter(SvStream &rPBM)
      68                 :            :     : m_rOStm(rPBM)
      69                 :            :     , mbStatus(sal_True)
      70                 :          0 :     , mpAcc(NULL)
      71                 :            : {
      72                 :          0 : }
      73                 :            : 
      74                 :            : // ------------------------------------------------------------------------
      75                 :            : 
      76                 :          0 : PBMWriter::~PBMWriter()
      77                 :            : {
      78                 :          0 : }
      79                 :            : 
      80                 :            : // ------------------------------------------------------------------------
      81                 :            : 
      82                 :          0 : sal_Bool PBMWriter::WritePBM( 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_1BIT_THRESHOLD );
      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                 :          0 :             ImplWriteBody();
     108                 :            : 
     109                 :          0 :         aBmp.ReleaseAccess( mpAcc );
     110                 :            :     }
     111                 :            :     else
     112                 :          0 :         mbStatus = sal_False;
     113                 :            : 
     114                 :          0 :     m_rOStm.SetNumberFormatInt( mpOStmOldModus );
     115                 :            : 
     116                 :          0 :     if ( xStatusIndicator.is() )
     117                 :          0 :         xStatusIndicator->end();
     118                 :            : 
     119                 :          0 :     return mbStatus;
     120                 :            : }
     121                 :            : 
     122                 :            : // ------------------------------------------------------------------------
     123                 :            : 
     124                 :          0 : sal_Bool PBMWriter::ImplWriteHeader()
     125                 :            : {
     126                 :          0 :     mnWidth = mpAcc->Width();
     127                 :          0 :     mnHeight = mpAcc->Height();
     128                 :          0 :     if ( mnWidth && mnHeight )
     129                 :            :     {
     130                 :          0 :         if ( mnMode == 0 )
     131                 :          0 :             m_rOStm << "P4\x0a";
     132                 :            :         else
     133                 :          0 :             m_rOStm << "P1\x0a";
     134                 :            : 
     135                 :          0 :         ImplWriteNumber( mnWidth );
     136                 :          0 :         m_rOStm << (sal_uInt8)32;
     137                 :          0 :         ImplWriteNumber( mnHeight );
     138                 :          0 :         m_rOStm << (sal_uInt8)10;
     139                 :            :     }
     140                 :          0 :     else mbStatus = sal_False;
     141                 :          0 :     return mbStatus;
     142                 :            : }
     143                 :            : 
     144                 :            : // ------------------------------------------------------------------------
     145                 :            : 
     146                 :          0 : void PBMWriter::ImplWriteBody()
     147                 :            : {
     148                 :          0 :     if ( mnMode == 0 )
     149                 :            :     {
     150                 :          0 :         sal_uInt8   nBYTE = 0;
     151                 :          0 :         for ( sal_uLong y = 0; y < mnHeight; y++ )
     152                 :            :         {
     153                 :            :             sal_uLong x;
     154                 :          0 :             for ( x = 0; x < mnWidth; x++ )
     155                 :            :             {
     156                 :          0 :                 nBYTE <<= 1;
     157                 :          0 :                 if (!(mpAcc->GetPixel( y, x ) & 1 ) )
     158                 :          0 :                     nBYTE++;
     159                 :          0 :                 if ( ( x & 7 ) == 7 )
     160                 :          0 :                     m_rOStm << nBYTE;
     161                 :            :             }
     162                 :          0 :             if ( ( x & 7 ) != 0 )
     163                 :          0 :                 m_rOStm << (sal_uInt8)( nBYTE << ( ( x ^ 7 ) + 1 ) );
     164                 :            :         }
     165                 :            :     }
     166                 :            :     else
     167                 :            :     {
     168                 :            :         int nxCount;
     169                 :          0 :         for ( sal_uLong y = 0; y < mnHeight; y++ )
     170                 :            :         {
     171                 :          0 :             nxCount = 70;
     172                 :          0 :             for ( sal_uLong x = 0; x < mnWidth; x++ )
     173                 :            :             {
     174                 :          0 :                 if (!( --nxCount ) )
     175                 :            :                 {
     176                 :          0 :                     nxCount = 69;
     177                 :          0 :                     m_rOStm << (sal_uInt8)10;
     178                 :            :                 }
     179                 :          0 :                 m_rOStm << (sal_uInt8)( ( mpAcc->GetPixel( y, x ) ^ 1 ) + '0' ) ;
     180                 :            :             }
     181                 :          0 :             m_rOStm << (sal_uInt8)10;
     182                 :            :         }
     183                 :            :     }
     184                 :          0 : }
     185                 :            : 
     186                 :            : // ------------------------------------------------------------------------
     187                 :            : // eine Dezimalzahl im ASCII format wird in den Stream geschrieben
     188                 :            : 
     189                 :          0 : void PBMWriter::ImplWriteNumber(sal_Int32 nNumber)
     190                 :            : {
     191                 :          0 :     const rtl::OString aNum(rtl::OString::valueOf(nNumber));
     192                 :          0 :     m_rOStm << aNum.getStr();
     193                 :          0 : }
     194                 :            : 
     195                 :            : // ------------------------------------------------------------------------
     196                 :            : 
     197                 :            : // ---------------------
     198                 :            : // - exported function -
     199                 :            : // ---------------------
     200                 :            : 
     201                 :            : extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool __LOADONCALLAPI
     202                 :          0 : GraphicExport(SvStream& rStream, Graphic& rGraphic, FilterConfigItem* pFilterConfigItem, sal_Bool)
     203                 :            : {
     204                 :          0 :     PBMWriter aPBMWriter(rStream);
     205                 :            : 
     206                 :          0 :     return aPBMWriter.WritePBM( rGraphic, pFilterConfigItem );
     207                 :            : }
     208                 :            : 
     209                 :            : // ------------------------------------------------------------------------
     210                 :            : 
     211                 :            : 
     212                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10