LCOV - code coverage report
Current view: top level - libreoffice/filter/source/graphicfilter/eras - eras.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 108 0.0 %
Date: 2012-12-27 Functions: 0 9 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include <vcl/graph.hxx>
      22             : #include <vcl/bmpacc.hxx>
      23             : #include <svtools/fltcall.hxx>
      24             : #include <svtools/FilterConfigItem.hxx>
      25             : 
      26             : //============================ RASWriter ==================================
      27             : 
      28             : class RASWriter {
      29             : 
      30             : private:
      31             : 
      32             :     SvStream & m_rOStm;
      33             :     sal_uInt16              mpOStmOldModus;
      34             : 
      35             :     sal_Bool                mbStatus;
      36             :     BitmapReadAccess*   mpAcc;
      37             : 
      38             :     sal_uLong               mnWidth, mnHeight;
      39             :     sal_uInt16              mnColors, mnDepth;
      40             : 
      41             :     sal_uLong               mnRepCount;
      42             :     sal_uInt8               mnRepVal;
      43             : 
      44             :     com::sun::star::uno::Reference< com::sun::star::task::XStatusIndicator > xStatusIndicator;
      45             : 
      46             :     void                ImplCallback( sal_uLong nCurrentYPos );
      47             :     sal_Bool                ImplWriteHeader();
      48             :     void                ImplWritePalette();
      49             :     void                ImplWriteBody();
      50             :     void                ImplPutByte( sal_uInt8 );   // RLE decoding
      51             : 
      52             : public:
      53             :     RASWriter(SvStream &rStream);
      54             :     ~RASWriter();
      55             : 
      56             :     sal_Bool WriteRAS( const Graphic& rGraphic, FilterConfigItem* pFilterConfigItem );
      57             : };
      58             : 
      59             : //=================== Methoden von RASWriter ==============================
      60             : 
      61           0 : RASWriter::RASWriter(SvStream &rStream)
      62             :     : m_rOStm(rStream)
      63             :     , mbStatus(sal_True)
      64             :     , mpAcc(NULL)
      65           0 :     , mnRepCount( 0xffffffff )
      66             : {
      67           0 : }
      68             : 
      69             : // ------------------------------------------------------------------------
      70             : 
      71           0 : RASWriter::~RASWriter()
      72             : {
      73           0 : }
      74             : 
      75             : // ------------------------------------------------------------------------
      76             : 
      77           0 : void RASWriter::ImplCallback( sal_uLong nYPos )
      78             : {
      79           0 :     if ( xStatusIndicator.is() )
      80           0 :         xStatusIndicator->setValue( (sal_uInt16)( ( 100 * nYPos ) / mnHeight ) );
      81           0 : }
      82             : 
      83             : //  ------------------------------------------------------------------------
      84             : 
      85           0 : sal_Bool RASWriter::WriteRAS( const Graphic& rGraphic, FilterConfigItem* pFilterConfigItem)
      86             : {
      87           0 :     Bitmap  aBmp;
      88             : 
      89           0 :     if ( pFilterConfigItem )
      90             :     {
      91           0 :         xStatusIndicator = pFilterConfigItem->GetStatusIndicator();
      92           0 :         if ( xStatusIndicator.is() )
      93             :         {
      94           0 :             rtl::OUString aMsg;
      95           0 :             xStatusIndicator->start( aMsg, 100 );
      96             :         }
      97             :     }
      98             : 
      99           0 :     BitmapEx    aBmpEx( rGraphic.GetBitmapEx() );
     100           0 :     aBmp = aBmpEx.GetBitmap();
     101             : 
     102           0 :     if ( aBmp.GetBitCount() == 4 )
     103           0 :         aBmp.Convert( BMP_CONVERSION_8BIT_COLORS );
     104             : 
     105           0 :     mnDepth = aBmp.GetBitCount();
     106             : 
     107             :     // export code below only handles three discrete cases
     108           0 :     mnDepth = mnDepth <= 1 ? 1 : mnDepth <= 8 ? 8 : 24;
     109             : 
     110           0 :     mpAcc = aBmp.AcquireReadAccess();
     111           0 :     if ( mpAcc )
     112             :     {
     113           0 :         mpOStmOldModus = m_rOStm.GetNumberFormatInt();
     114           0 :         m_rOStm.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN );
     115             : 
     116           0 :         if ( ImplWriteHeader() )
     117             :         {
     118           0 :             if ( mnDepth <= 8 )
     119           0 :                 ImplWritePalette();
     120           0 :             ImplWriteBody();
     121             :         }
     122           0 :         aBmp.ReleaseAccess( mpAcc );
     123             :     }
     124             :     else
     125           0 :         mbStatus = sal_False;
     126             : 
     127           0 :     m_rOStm.SetNumberFormatInt( mpOStmOldModus );
     128             : 
     129           0 :     if ( xStatusIndicator.is() )
     130           0 :         xStatusIndicator->end();
     131             : 
     132           0 :     return mbStatus;
     133             : }
     134             : 
     135             : // ------------------------------------------------------------------------
     136             : 
     137           0 : sal_Bool RASWriter::ImplWriteHeader()
     138             : {
     139           0 :     mnWidth = mpAcc->Width();
     140           0 :     mnHeight = mpAcc->Height();
     141           0 :     if ( mnDepth <= 8 )
     142             :     {
     143           0 :         mnColors = mpAcc->GetPaletteEntryCount();
     144           0 :         if (mnColors == 0)
     145           0 :             mbStatus = sal_False;
     146             :     }
     147           0 :         if ( mbStatus && mnWidth && mnHeight && mnDepth )
     148             :     {
     149           0 :         m_rOStm << (sal_uInt32)0x59a66a95 << (sal_uInt32)mnWidth << (sal_uInt32)mnHeight
     150           0 :             << (sal_uInt32)mnDepth
     151           0 :             << (sal_uInt32)(( ( ( ( mnWidth * mnDepth ) + 15 ) >> 4 ) << 1 ) * mnHeight)
     152           0 :             << (sal_uInt32)2;
     153             : 
     154           0 :         if ( mnDepth > 8 )
     155           0 :             m_rOStm << (sal_uInt32)0 << (sal_uInt32)0;
     156             :         else
     157             :         {
     158             : 
     159           0 :             m_rOStm << (sal_uInt32)1 << (sal_uInt32)( mnColors * 3 );
     160             :         }
     161             :     }
     162           0 :     else mbStatus = sal_False;
     163             : 
     164           0 :     return mbStatus;
     165             : }
     166             : 
     167             : // ------------------------------------------------------------------------
     168             : 
     169           0 : void RASWriter::ImplWritePalette()
     170             : {
     171             :     sal_uInt16 i;
     172             : 
     173           0 :     for ( i = 0; i < mnColors; m_rOStm << mpAcc->GetPaletteColor( i++ ).GetRed() ) ;
     174           0 :     for ( i = 0; i < mnColors; m_rOStm << mpAcc->GetPaletteColor( i++ ).GetGreen() ) ;
     175           0 :     for ( i = 0; i < mnColors; m_rOStm << mpAcc->GetPaletteColor( i++ ).GetBlue() ) ;
     176           0 : }
     177             : 
     178             : // ------------------------------------------------------------------------
     179             : 
     180           0 : void RASWriter::ImplWriteBody()
     181             : {
     182             :     sal_uLong   x, y;
     183             : 
     184           0 :     if ( mnDepth == 24 )
     185             :     {
     186           0 :         for ( y = 0; y < mnHeight; y++ )
     187             :         {
     188           0 :             ImplCallback( y );                              // processing output
     189           0 :             for ( x = 0; x < mnWidth; x++ )
     190             :             {
     191           0 :                 BitmapColor aColor( mpAcc->GetPixel( y, x ) );
     192           0 :                 ImplPutByte( aColor.GetBlue() );            // Format ist BGR
     193           0 :                 ImplPutByte( aColor.GetGreen() );
     194           0 :                 ImplPutByte( aColor.GetRed() );
     195           0 :             }
     196           0 :             if ( x & 1 ) ImplPutByte( 0 );      // WORD ALIGNMENT ???
     197             :         }
     198             :     }
     199           0 :     else if ( mnDepth == 8 )
     200             :     {
     201           0 :         for ( y = 0; y < mnHeight; y++ )
     202             :         {
     203           0 :             ImplCallback( y );                              // processing output
     204           0 :             for ( x = 0; x < mnWidth; x++ )
     205             :             {
     206           0 :                 ImplPutByte ( mpAcc->GetPixel( y, x ) );
     207             :             }
     208           0 :             if ( x & 1 ) ImplPutByte( 0 );      // WORD ALIGNMENT ???
     209             :         }
     210             :     }
     211           0 :     else if ( mnDepth == 1 )
     212             :     {
     213           0 :         sal_uInt8 nDat = 0;
     214             : 
     215           0 :         for ( y = 0; y < mnHeight; y++ )
     216             :         {
     217           0 :             ImplCallback( y );                              // processing output
     218           0 :             for ( x = 0; x < mnWidth; x++ )
     219             :             {
     220           0 :                 nDat = ( ( nDat << 1 ) | ( mpAcc->GetPixel ( y, x ) & 1 ) );
     221           0 :                 if ( ( x & 7 ) == 7 )
     222           0 :                     ImplPutByte( nDat );
     223             :             }
     224           0 :             if ( x & 7 )
     225           0 :                 ImplPutByte( sal::static_int_cast< sal_uInt8 >(nDat << ( ( ( x & 7 ) ^ 7 ) + 1)) );// write remaining bits
     226           0 :             if (!( ( x - 1 ) & 0x8 ) )
     227           0 :                 ImplPutByte( 0 );               // WORD ALIGNMENT ???
     228             :         }
     229             :     }
     230           0 :     ImplPutByte( mnRepVal + 1 );    // end of RLE decoding
     231           0 : }
     232             : 
     233             : // ------------------------------------------------------------------------
     234             : 
     235           0 : void RASWriter::ImplPutByte( sal_uInt8 nPutThis )
     236             : {
     237           0 :     if ( mnRepCount == 0xffffffff )
     238             :     {
     239           0 :         mnRepCount = 0;
     240           0 :         mnRepVal = nPutThis;
     241             :     }
     242             :     else
     243             :     {
     244           0 :         if ( ( nPutThis == mnRepVal ) && ( mnRepCount != 0xff ) )
     245           0 :             mnRepCount++;
     246             :         else
     247             :         {
     248           0 :             if ( mnRepCount == 0 )
     249             :             {
     250           0 :                 m_rOStm << (sal_uInt8)mnRepVal;
     251           0 :                 if ( mnRepVal == 0x80 )
     252           0 :                     m_rOStm << (sal_uInt8)0;
     253             :             }
     254             :             else
     255             :             {
     256           0 :                 m_rOStm << (sal_uInt8)0x80;
     257           0 :                 m_rOStm << (sal_uInt8)mnRepCount;
     258           0 :                 m_rOStm << (sal_uInt8)mnRepVal;
     259             :             }
     260           0 :             mnRepVal = nPutThis;
     261           0 :             mnRepCount = 0;
     262             :         }
     263             :     }
     264           0 : }
     265             : 
     266             : // ------------------------------------------------------------------------
     267             : 
     268             : // ---------------------
     269             : // - exported function -
     270             : // ---------------------
     271             : 
     272             : #ifdef DISABLE_DYNLOADING
     273             : #define GraphicExport eraGraphicExport
     274             : #endif
     275             : 
     276             : extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL
     277           0 : GraphicExport(SvStream& rStream, Graphic& rGraphic, FilterConfigItem* pFilterConfigItem, sal_Bool)
     278             : {
     279           0 :     RASWriter aRASWriter(rStream);
     280             : 
     281           0 :     return aRASWriter.WriteRAS( rGraphic, pFilterConfigItem );
     282             : }
     283             : 
     284             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10