LCOV - code coverage report
Current view: top level - libreoffice/svx/source/gallery2 - codec.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 69 0.0 %
Date: 2012-12-27 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 <tools/debug.hxx>
      24             : #include "codec.hxx"
      25             : 
      26             : // ----------------
      27             : // - GalleryCodec -
      28             : // ----------------
      29             : DBG_NAME(GalleryCodec)
      30             : 
      31           0 : GalleryCodec::GalleryCodec( SvStream& rIOStm ) :
      32           0 :     rStm( rIOStm )
      33             : {
      34             :     DBG_CTOR(GalleryCodec,NULL);
      35           0 : }
      36             : 
      37             : // -----------------------------------------------------------------------------
      38             : 
      39           0 : GalleryCodec::~GalleryCodec()
      40             : {
      41             :     DBG_DTOR(GalleryCodec,NULL);
      42           0 : }
      43             : 
      44             : // -----------------------------------------------------------------------------
      45             : 
      46           0 : sal_Bool GalleryCodec::IsCoded( SvStream& rStm, sal_uInt32& rVersion )
      47             : {
      48           0 :     const sal_uIntPtr   nPos = rStm.Tell();
      49             :     sal_Bool        bRet;
      50             :     sal_uInt8       cByte1, cByte2, cByte3, cByte4, cByte5, cByte6;
      51             : 
      52           0 :     rStm >> cByte1 >> cByte2 >> cByte3 >> cByte4 >> cByte5 >> cByte6;
      53             : 
      54           0 :     if ( cByte1 == 'S' && cByte2 == 'V' && cByte3 == 'R' && cByte4 == 'L' && cByte5 == 'E' && ( cByte6 == '1' || cByte6 == '2' ) )
      55             :     {
      56           0 :         rVersion = ( ( cByte6 == '1' ) ? 1 : 2 );
      57           0 :         bRet = sal_True;
      58             :     }
      59             :     else
      60             :     {
      61           0 :         rVersion = 0;
      62           0 :         bRet = sal_False;
      63             :     }
      64             : 
      65           0 :     rStm.Seek( nPos );
      66             : 
      67           0 :     return bRet;
      68             : }
      69             : 
      70             : // -----------------------------------------------------------------------------
      71             : 
      72           0 : void GalleryCodec::Write( SvStream& rStmToWrite )
      73             : {
      74             :     sal_uInt32 nPos, nCompSize;
      75             : 
      76           0 :     rStmToWrite.Seek( STREAM_SEEK_TO_END );
      77           0 :     const sal_uInt32 nSize = rStmToWrite.Tell();
      78           0 :     rStmToWrite.Seek( 0UL );
      79             : 
      80           0 :     rStm << 'S' << 'V' << 'R' << 'L' << 'E' << '2';
      81           0 :     rStm << nSize;
      82             : 
      83           0 :     nPos = rStm.Tell();
      84           0 :     rStm.SeekRel( 4UL );
      85             : 
      86           0 :     ZCodec aCodec;
      87           0 :     aCodec.BeginCompression();
      88           0 :     aCodec.Compress( rStmToWrite, rStm );
      89           0 :     aCodec.EndCompression();
      90             : 
      91           0 :     nCompSize = rStm.Tell() - nPos - 4UL;
      92           0 :     rStm.Seek( nPos );
      93           0 :     rStm << nCompSize;
      94           0 :     rStm.Seek( STREAM_SEEK_TO_END );
      95           0 : }
      96             : 
      97             : // -----------------------------------------------------------------------------
      98             : 
      99           0 : void GalleryCodec::Read( SvStream& rStmToRead )
     100             : {
     101           0 :     sal_uInt32 nVersion = 0;
     102             : 
     103           0 :     if( IsCoded( rStm, nVersion ) )
     104             :     {
     105             :         sal_uInt32  nCompressedSize, nUnCompressedSize;
     106             : 
     107           0 :         rStm.SeekRel( 6 );
     108           0 :         rStm >> nUnCompressedSize >> nCompressedSize;
     109             : 
     110             :         // decompress
     111           0 :         if( 1 == nVersion )
     112             :         {
     113           0 :             sal_uInt8*   pCompressedBuffer = new sal_uInt8[ nCompressedSize ]; rStm.Read( pCompressedBuffer, nCompressedSize );
     114           0 :             sal_uInt8*  pInBuf = pCompressedBuffer;
     115           0 :             sal_uInt8*  pOutBuf = new sal_uInt8[ nUnCompressedSize ];
     116           0 :             sal_uInt8*  pTmpBuf = pOutBuf;
     117           0 :             sal_uInt8*  pLast = pOutBuf + nUnCompressedSize - 1;
     118           0 :             sal_uIntPtr   nIndex = 0UL, nCountByte, nRunByte;
     119           0 :             sal_Bool    bEndDecoding = sal_False;
     120             : 
     121           0 :             do
     122             :             {
     123           0 :                 nCountByte = *pInBuf++;
     124             : 
     125           0 :                 if ( !nCountByte )
     126             :                 {
     127           0 :                     nRunByte = *pInBuf++;
     128             : 
     129           0 :                     if ( nRunByte > 2 )
     130             :                     {
     131             :                         // absolutes Fuellen
     132           0 :                         memcpy( &pTmpBuf[ nIndex ], pInBuf, nRunByte );
     133           0 :                         pInBuf += nRunByte;
     134           0 :                         nIndex += nRunByte;
     135             : 
     136             :                         // WORD-Alignment beachten
     137           0 :                         if ( nRunByte & 1 )
     138           0 :                             pInBuf++;
     139             :                     }
     140           0 :                     else if ( nRunByte == 1 )   // Ende des Bildes
     141           0 :                         bEndDecoding = sal_True;
     142             :                 }
     143             :                 else
     144             :                 {
     145           0 :                     const sal_uInt8 cVal = *pInBuf++;
     146             : 
     147           0 :                     memset( &pTmpBuf[ nIndex ], cVal, nCountByte );
     148           0 :                     nIndex += nCountByte;
     149             :                 }
     150             :             }
     151             :             while ( !bEndDecoding && ( pTmpBuf <= pLast ) );
     152             : 
     153           0 :                rStmToRead.Write( pOutBuf, nUnCompressedSize );
     154             : 
     155           0 :             delete[] pOutBuf;
     156           0 :             delete[] pCompressedBuffer;
     157             :         }
     158           0 :         else if( 2 == nVersion )
     159             :         {
     160           0 :             ZCodec aCodec;
     161             : 
     162           0 :             aCodec.BeginCompression();
     163           0 :             aCodec.Decompress( rStm, rStmToRead );
     164           0 :             aCodec.EndCompression();
     165             :         }
     166             :     }
     167           0 : }
     168             : 
     169             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10