LCOV - code coverage report
Current view: top level - pression/compressor - compressorLZF.cpp (source / functions) Hit Total Coverage
Test: Pression Lines: 31 32 96.9 %
Date: 2016-12-06 05:44:58 Functions: 6 6 100.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2012-2016, 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 "compressorLZF.h"
      19             : 
      20             : extern "C" {
      21             : #include "liblzf/lzf.h"
      22             : }
      23             : 
      24             : namespace pression
      25             : {
      26             : namespace plugin
      27             : {
      28             : namespace
      29             : {
      30           1 : static void _getInfo( EqCompressorInfo* const info )
      31             : {
      32           1 :     info->version = EQ_COMPRESSOR_VERSION;
      33           1 :     info->capabilities = EQ_COMPRESSOR_DATA_1D | EQ_COMPRESSOR_DATA_2D;
      34           1 :     info->quality = 1.f;
      35           1 :     info->ratio   = .60f;
      36           1 :     info->speed   = .26f;
      37           1 :     info->name = EQ_COMPRESSOR_LZF_BYTE;
      38           1 :     info->tokenType = EQ_COMPRESSOR_DATATYPE_BYTE;
      39           1 : }
      40             : 
      41           1 : static bool _register()
      42             : {
      43             :     Compressor::registerEngine(
      44           2 :         Compressor::Functions( EQ_COMPRESSOR_LZF_BYTE,
      45             :                                _getInfo,
      46             :                                CompressorLZF::getNewCompressor,
      47             :                                CompressorLZF::getNewDecompressor,
      48           1 :                                CompressorLZF::decompress, 0 ));
      49           1 :     return true;
      50             : }
      51             : 
      52           1 : static const bool LB_UNUSED _initialized = _register();
      53             : }
      54             : 
      55          74 : void CompressorLZF::compress( const void* const inData,
      56             :                               const eq_uint64_t nPixels, const bool /*alpha*/ )
      57             : {
      58          74 :     _nResults = 1;
      59          74 :     if( _results.size() < _nResults )
      60          37 :         _results.push_back( new pression::plugin::Compressor::Result );
      61          74 :     const eq_uint64_t maxSize = eq_uint64_t( float( nPixels ) * 1.1f ) + 8;
      62          74 :     _results[0]->reserve( maxSize );
      63             : 
      64         148 :     const unsigned size = lzf_compress( inData, nPixels,
      65         148 :                                         _results[0]->getData(), maxSize );
      66          74 :     _results[0]->resize( size );
      67          74 :     assert( size != 0 );
      68          74 : }
      69             : 
      70          74 : void CompressorLZF::decompress( const void* const* inData,
      71             :                                 const eq_uint64_t* const inSizes,
      72             :                                 const unsigned nInputs,
      73             :                                 void* const outData,
      74             :                                 eq_uint64_t* const outDims,
      75             :                                 const eq_uint64_t flags, void* const )
      76             : {
      77          74 :     if( nInputs == 0 )
      78           0 :         return;
      79             : 
      80          74 :     const eq_uint64_t nPixels = ( flags & EQ_COMPRESSOR_DATA_1D) ?
      81          74 :                                     outDims[1] : outDims[1] * outDims[3];
      82          74 :     lzf_decompress( inData[0], inSizes[0], outData, nPixels );
      83             : }
      84             : 
      85             : }
      86           3 : }

Generated by: LCOV version 1.11