LCOV - code coverage report
Current view: top level - pression/compressor - compressorSnappy.cpp (source / functions) Hit Total Coverage
Test: Pression Lines: 29 30 96.7 %
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 "compressorSnappy.h"
      19             : 
      20             : #include "snappy/snappy.h"
      21             : 
      22             : namespace pression
      23             : {
      24             : namespace plugin
      25             : {
      26             : namespace
      27             : {
      28             : #ifndef __xlC__
      29           1 : static void _getInfo( EqCompressorInfo* const info )
      30             : {
      31           1 :     info->version = EQ_COMPRESSOR_VERSION;
      32           1 :     info->capabilities = EQ_COMPRESSOR_DATA_1D | EQ_COMPRESSOR_DATA_2D;
      33           1 :     info->quality = 1.f;
      34           1 :     info->ratio   = .60f;
      35           1 :     info->speed   = .55f;
      36           1 :     info->name = EQ_COMPRESSOR_SNAPPY_BYTE;
      37           1 :     info->tokenType = EQ_COMPRESSOR_DATATYPE_BYTE;
      38           1 : }
      39             : 
      40           1 : static bool _register()
      41             : {
      42             :     Compressor::registerEngine(
      43           2 :         Compressor::Functions( EQ_COMPRESSOR_SNAPPY_BYTE,
      44             :                                _getInfo,
      45             :                                CompressorSnappy::getNewCompressor,
      46             :                                CompressorSnappy::getNewDecompressor,
      47           1 :                                CompressorSnappy::decompress, 0 ));
      48           1 :     return true;
      49             : }
      50             : 
      51           1 : static const bool LB_UNUSED _initialized = _register();
      52             : #endif
      53             : }
      54             : 
      55          74 : void CompressorSnappy::compress( const void* const inData,
      56             :                                  const eq_uint64_t nPixels,
      57             :                                  const bool /*alpha*/ )
      58             : {
      59          74 :     _nResults = 1;
      60          74 :     if( _results.size() < _nResults )
      61          37 :         _results.push_back( new pression::plugin::Compressor::Result );
      62          74 :     size_t size = snappy::MaxCompressedLength( nPixels );
      63          74 :     _results[0]->reserve( size );
      64             : 
      65             :     snappy::RawCompress( (const char*)(inData), nPixels,
      66          74 :                          (char*)( _results[0]->getData( )), &size );
      67          74 :     assert( size != 0 );
      68          74 :     _results[0]->setSize( size );
      69          74 : }
      70             : 
      71          74 : void CompressorSnappy::decompress( const void* const* inData,
      72             :                                    const eq_uint64_t* const inSizes,
      73             :                                    const unsigned nInputs,
      74             :                                    void* const outData,
      75             :                                    eq_uint64_t* const /*outDims*/,
      76             :                                    const eq_uint64_t, void* const )
      77             : {
      78          74 :     if( nInputs == 0 )
      79           0 :         return;
      80             : 
      81          74 :     snappy::RawUncompress( (const char*)(inData[0]), inSizes[0],
      82          74 :                            (char*)(outData) );
      83             : }
      84             : 
      85             : }
      86           3 : }

Generated by: LCOV version 1.11