LCOV - code coverage report
Current view: top level - lunchbox/compressor - compressorFastLZ.cpp (source / functions) Hit Total Coverage
Test: lcov2.info Lines: 30 30 100.0 %
Date: 2014-10-01 Functions: 6 6 100.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2012-2013, Stefan Eilemann <eile@eyescale.ch>
       3             :  *
       4             :  * This library is free software; you can redistribute it and/or modify it under
       5             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       6             :  * by the Free Software Foundation.
       7             :  *
       8             :  * This library is distributed in the hope that it will be useful, but WITHOUT
       9             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      10             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      11             :  * details.
      12             :  *
      13             :  * You should have received a copy of the GNU Lesser General Public License
      14             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      15             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      16             :  */
      17             : 
      18             : #include "compressorFastLZ.h"
      19             : 
      20             : #include "fastlz/fastlz.h"
      21             : 
      22             : namespace lunchbox
      23             : {
      24             : namespace plugin
      25             : {
      26             : namespace
      27             : {
      28           1 : static void _getInfo( EqCompressorInfo* const info )
      29             : {
      30           1 :     info->version = EQ_COMPRESSOR_VERSION;
      31           1 :     info->capabilities = EQ_COMPRESSOR_DATA_1D | EQ_COMPRESSOR_DATA_2D;
      32           1 :     info->quality = 1.f;
      33           1 :     info->ratio   = .50f;
      34           1 :     info->speed   = .22f;
      35           1 :     info->name = EQ_COMPRESSOR_FASTLZ_BYTE;
      36           1 :     info->tokenType = EQ_COMPRESSOR_DATATYPE_BYTE;
      37           1 : }
      38             : 
      39          30 : static bool _register()
      40             : {
      41             :     Compressor::registerEngine(
      42             :         Compressor::Functions( EQ_COMPRESSOR_FASTLZ_BYTE,
      43             :                                _getInfo,
      44             :                                CompressorFastLZ::getNewCompressor,
      45             :                                CompressorFastLZ::getNewDecompressor,
      46          30 :                                CompressorFastLZ::decompress, 0 ));
      47          30 :     return true;
      48             : }
      49             : 
      50          30 : static const bool _initialized = _register();
      51             : }
      52             : 
      53          76 : void CompressorFastLZ::compress( const void* const inData,
      54             :                                  const eq_uint64_t nPixels,
      55             :                                  const bool /*alpha*/ )
      56             : {
      57          76 :     _nResults = 1;
      58          76 :     if( _results.size() < _nResults )
      59          38 :         _results.push_back( new lunchbox::plugin::Compressor::Result );
      60          76 :     const eq_uint64_t maxSize = eq_uint64_t( float( nPixels ) * 1.1f ) + 66;
      61          76 :     _results[0]->reserve( maxSize );
      62             : 
      63          76 :     const int size = fastlz_compress( inData, nPixels, _results[0]->getData( ));
      64          76 :     _results[0]->resize( size );
      65          76 :     assert( size != 0 );
      66          76 : }
      67             : 
      68          76 : void CompressorFastLZ::decompress( const void* const* inData,
      69             :                                    const eq_uint64_t* const inSizes,
      70             :                                    const unsigned nInputs,
      71             :                                    void* const outData,
      72             :                                    eq_uint64_t* const outDims,
      73             :                                    const eq_uint64_t flags, void* const )
      74             : {
      75          76 :     if( nInputs == 0 )
      76          76 :         return;
      77             : 
      78          76 :     const eq_uint64_t nPixels = ( flags & EQ_COMPRESSOR_DATA_1D) ?
      79          76 :                                     outDims[1] : outDims[1] * outDims[3];
      80          76 :     fastlz_decompress( inData[0], inSizes[0], outData, nPixels );
      81             : }
      82             : 
      83             : }
      84          90 : }

Generated by: LCOV version 1.10