LCOV - code coverage report
Current view: top level - sdext/source/pdfimport/tree - imagecontainer.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 50 52 96.2 %
Date: 2014-04-11 Functions: 6 6 100.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 "imagecontainer.hxx"
      22             : #include "genericelements.hxx"
      23             : #include "xmlemitter.hxx"
      24             : 
      25             : #include <rtl/ustrbuf.hxx>
      26             : #include <osl/file.h>
      27             : #include <rtl/crc.h>
      28             : 
      29             : #include <com/sun/star/graphic/XGraphicProvider.hpp>
      30             : #include <com/sun/star/beans/PropertyValue.hpp>
      31             : 
      32             : #include <cppuhelper/implbase1.hxx>
      33             : #include <comphelper/stl_types.hxx>
      34             : 
      35             : #include <boost/bind.hpp>
      36             : 
      37             : using namespace com::sun::star;
      38             : 
      39             : namespace pdfi
      40             : {
      41             : 
      42             : namespace
      43             : {
      44             : 
      45             : static const sal_Char aBase64EncodeTable[] =
      46             :     { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
      47             :       'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
      48             :       'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
      49             :       'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
      50             :       '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' };
      51             : 
      52           3 : OUString encodeBase64( const sal_Int8* i_pBuffer, const sal_uInt32 i_nBufferLength )
      53             : {
      54           3 :     OUStringBuffer aBuf( (i_nBufferLength+1) * 4 / 3 );
      55           3 :     const sal_Int32 nRemain(i_nBufferLength%3);
      56           3 :     const sal_Int32 nFullTripleLength( i_nBufferLength - (i_nBufferLength%3));
      57           3 :     sal_Int32 nBufPos( 0 );
      58       44130 :     for( sal_Int32 i = 0; i < nFullTripleLength; i += 3, nBufPos += 4 )
      59             :     {
      60       88254 :         const sal_Int32 nBinary = (((sal_uInt8)i_pBuffer[i + 0]) << 16) +
      61       44127 :                                   (((sal_uInt8)i_pBuffer[i + 1]) <<  8) +
      62       44127 :                                   ((sal_uInt8)i_pBuffer[i + 2]);
      63             : 
      64       44127 :         aBuf.appendAscii("====");
      65             : 
      66       44127 :         sal_uInt8 nIndex (static_cast<sal_uInt8>((nBinary & 0xFC0000) >> 18));
      67       44127 :         aBuf[nBufPos] = aBase64EncodeTable [nIndex];
      68             : 
      69       44127 :         nIndex = static_cast<sal_uInt8>((nBinary & 0x3F000) >> 12);
      70       44127 :         aBuf[nBufPos+1] = aBase64EncodeTable [nIndex];
      71             : 
      72       44127 :         nIndex = static_cast<sal_uInt8>((nBinary & 0xFC0) >> 6);
      73       44127 :         aBuf[nBufPos+2] = aBase64EncodeTable [nIndex];
      74             : 
      75       44127 :         nIndex = static_cast<sal_uInt8>((nBinary & 0x3F));
      76       44127 :         aBuf[nBufPos+3] = aBase64EncodeTable [nIndex];
      77             :     }
      78           3 :     if( nRemain > 0 )
      79             :     {
      80           3 :         aBuf.appendAscii("====");
      81           3 :         sal_Int32 nBinary( 0 );
      82           3 :         const sal_Int32 nStart(i_nBufferLength-nRemain);
      83           3 :         switch(nRemain)
      84             :         {
      85           0 :             case 1: nBinary = ((sal_uInt8)i_pBuffer[nStart + 0]) << 16;
      86           0 :                 break;
      87           3 :             case 2: nBinary = (((sal_uInt8)i_pBuffer[nStart + 0]) << 16) +
      88           3 :                               (((sal_uInt8)i_pBuffer[nStart + 1]) <<  8);
      89           3 :                 break;
      90             :         }
      91           3 :         sal_uInt8 nIndex (static_cast<sal_uInt8>((nBinary & 0xFC0000) >> 18));
      92           3 :         aBuf[nBufPos] = aBase64EncodeTable [nIndex];
      93             : 
      94           3 :         nIndex = static_cast<sal_uInt8>((nBinary & 0x3F000) >> 12);
      95           3 :         aBuf[nBufPos+1] = aBase64EncodeTable [nIndex];
      96             : 
      97           3 :         if( nRemain == 2 )
      98             :         {
      99           3 :             nIndex = static_cast<sal_uInt8>((nBinary & 0xFC0) >> 6);
     100           3 :             aBuf[nBufPos+2] = aBase64EncodeTable [nIndex];
     101             :         }
     102             :     }
     103             : 
     104           3 :     return aBuf.makeStringAndClear();
     105             : }
     106             : 
     107             : } // namespace
     108             : 
     109           2 : ImageContainer::ImageContainer() :
     110           2 :     m_aImages()
     111           2 : {}
     112             : 
     113           2 : ImageId ImageContainer::addImage( const uno::Sequence<beans::PropertyValue>& xBitmap )
     114             : {
     115           2 :     m_aImages.push_back( xBitmap );
     116           2 :     return m_aImages.size()-1;
     117             : }
     118             : 
     119           3 : void ImageContainer::writeBase64EncodedStream( ImageId nId, EmitContext& rContext )
     120             : {
     121             :     OSL_ASSERT( nId >= 0 && nId < ImageId( m_aImages.size()) );
     122             : 
     123           3 :     const uno::Sequence<beans::PropertyValue>& rEntry( m_aImages[nId] );
     124             : 
     125             :     // find "InputSequence" property
     126           3 :     const beans::PropertyValue* pAry(rEntry.getConstArray());
     127           3 :     const sal_Int32             nLen(rEntry.getLength());
     128             :     const beans::PropertyValue* pValue(
     129             :         std::find_if(pAry,pAry+nLen,
     130             :                      boost::bind(comphelper::TPropertyValueEqualFunctor(),
     131             :                                  _1,
     132           3 :                                  OUString("InputSequence"))));
     133             :     OSL_ENSURE( pValue != pAry+nLen,
     134             :                 "InputSequence not found" );
     135             : 
     136           3 :     uno::Sequence<sal_Int8> aData;
     137           3 :     if( !(pValue->Value >>= aData) )
     138             :         OSL_FAIL("Wrong data type");
     139             : 
     140           3 :     rContext.rEmitter.write( encodeBase64( aData.getConstArray(), aData.getLength() ));
     141           3 : }
     142             : 
     143           3 : }
     144             : 
     145             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10