LCOV - code coverage report
Current view: top level - svx/source/gallery2 - codec.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 69 0.0 %
Date: 2014-11-03 Functions: 0 5 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 <tools/stream.hxx>
      22             : #include <tools/zcodec.hxx>
      23             : #include "codec.hxx"
      24             : #include <boost/scoped_array.hpp>
      25             : 
      26             : // - GalleryCodec -
      27             : 
      28             : 
      29           0 : GalleryCodec::GalleryCodec( SvStream& rIOStm ) :
      30           0 :     rStm( rIOStm )
      31             : {
      32           0 : }
      33             : 
      34           0 : GalleryCodec::~GalleryCodec()
      35             : {
      36           0 : }
      37             : 
      38           0 : bool GalleryCodec::IsCoded( SvStream& rStm, sal_uInt32& rVersion )
      39             : {
      40           0 :     const sal_uIntPtr   nPos = rStm.Tell();
      41             :     bool        bRet;
      42             :     sal_uInt8       cByte1, cByte2, cByte3, cByte4, cByte5, cByte6;
      43             : 
      44           0 :     rStm.ReadUChar( cByte1 ).ReadUChar( cByte2 ).ReadUChar( cByte3 ).ReadUChar( cByte4 ).ReadUChar( cByte5 ).ReadUChar( cByte6 );
      45             : 
      46           0 :     if ( cByte1 == 'S' && cByte2 == 'V' && cByte3 == 'R' && cByte4 == 'L' && cByte5 == 'E' && ( cByte6 == '1' || cByte6 == '2' ) )
      47             :     {
      48           0 :         rVersion = ( ( cByte6 == '1' ) ? 1 : 2 );
      49           0 :         bRet = true;
      50             :     }
      51             :     else
      52             :     {
      53           0 :         rVersion = 0;
      54           0 :         bRet = false;
      55             :     }
      56             : 
      57           0 :     rStm.Seek( nPos );
      58             : 
      59           0 :     return bRet;
      60             : }
      61             : 
      62           0 : void GalleryCodec::Write( SvStream& rStmToWrite )
      63             : {
      64             :     sal_uInt32 nPos, nCompSize;
      65             : 
      66           0 :     rStmToWrite.Seek( STREAM_SEEK_TO_END );
      67           0 :     const sal_uInt32 nSize = rStmToWrite.Tell();
      68           0 :     rStmToWrite.Seek( 0UL );
      69             : 
      70           0 :     rStm.WriteChar( 'S' ).WriteChar( 'V' ).WriteChar( 'R' ).WriteChar( 'L' ).WriteChar( 'E' ).WriteChar( '2' );
      71           0 :     rStm.WriteUInt32( nSize );
      72             : 
      73           0 :     nPos = rStm.Tell();
      74           0 :     rStm.SeekRel( 4UL );
      75             : 
      76           0 :     ZCodec aCodec;
      77           0 :     aCodec.BeginCompression();
      78           0 :     aCodec.Compress( rStmToWrite, rStm );
      79           0 :     aCodec.EndCompression();
      80             : 
      81           0 :     nCompSize = rStm.Tell() - nPos - 4UL;
      82           0 :     rStm.Seek( nPos );
      83           0 :     rStm.WriteUInt32( nCompSize );
      84           0 :     rStm.Seek( STREAM_SEEK_TO_END );
      85           0 : }
      86             : 
      87           0 : void GalleryCodec::Read( SvStream& rStmToRead )
      88             : {
      89           0 :     sal_uInt32 nVersion = 0;
      90             : 
      91           0 :     if( IsCoded( rStm, nVersion ) )
      92             :     {
      93             :         sal_uInt32  nCompressedSize, nUnCompressedSize;
      94             : 
      95           0 :         rStm.SeekRel( 6 );
      96           0 :         rStm.ReadUInt32( nUnCompressedSize ).ReadUInt32( nCompressedSize );
      97             : 
      98             :         // decompress
      99           0 :         if( 1 == nVersion )
     100             :         {
     101           0 :             boost::scoped_array<sal_uInt8> pCompressedBuffer(new sal_uInt8[ nCompressedSize ]);
     102           0 :             rStm.Read( pCompressedBuffer.get(), nCompressedSize );
     103           0 :             sal_uInt8*  pInBuf = pCompressedBuffer.get();
     104           0 :             boost::scoped_array<sal_uInt8> pOutBuf(new sal_uInt8[ nUnCompressedSize ]);
     105           0 :             sal_uInt8*  pTmpBuf = pOutBuf.get();
     106           0 :             sal_uInt8*  pLast = pOutBuf.get() + nUnCompressedSize - 1;
     107           0 :             sal_uIntPtr   nIndex = 0UL, nCountByte, nRunByte;
     108           0 :             bool    bEndDecoding = false;
     109             : 
     110           0 :             do
     111             :             {
     112           0 :                 nCountByte = *pInBuf++;
     113             : 
     114           0 :                 if ( !nCountByte )
     115             :                 {
     116           0 :                     nRunByte = *pInBuf++;
     117             : 
     118           0 :                     if ( nRunByte > 2 )
     119             :                     {
     120             :                         // filling absolutely
     121           0 :                         memcpy( &pTmpBuf[ nIndex ], pInBuf, nRunByte );
     122           0 :                         pInBuf += nRunByte;
     123           0 :                         nIndex += nRunByte;
     124             : 
     125             :                         // note WORD alignment
     126           0 :                         if ( nRunByte & 1 )
     127           0 :                             pInBuf++;
     128             :                     }
     129           0 :                     else if ( nRunByte == 1 )   // End of the image
     130           0 :                         bEndDecoding = true;
     131             :                 }
     132             :                 else
     133             :                 {
     134           0 :                     const sal_uInt8 cVal = *pInBuf++;
     135             : 
     136           0 :                     memset( &pTmpBuf[ nIndex ], cVal, nCountByte );
     137           0 :                     nIndex += nCountByte;
     138             :                 }
     139             :             }
     140           0 :             while ( !bEndDecoding && ( pTmpBuf <= pLast ) );
     141             : 
     142           0 :             rStmToRead.Write( pOutBuf.get(), nUnCompressedSize );
     143             :         }
     144           0 :         else if( 2 == nVersion )
     145             :         {
     146           0 :             ZCodec aCodec;
     147             : 
     148           0 :             aCodec.BeginCompression();
     149           0 :             aCodec.Decompress( rStm, rStmToRead );
     150           0 :             aCodec.EndCompression();
     151             :         }
     152             :     }
     153           0 : }
     154             : 
     155             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10