LCOV - code coverage report
Current view: top level - pression - decompressor.cpp (source / functions) Hit Total Coverage
Test: Pression Lines: 45 79 57.0 %
Date: 2016-12-06 05:44:58 Functions: 12 19 63.2 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2013-2014, Stefan.Eilemann@epfl.ch
       3             :  *
       4             :  * This file is part of Pression <https://github.com/Eyescale/Pression>
       5             :  *
       6             :  * This library is free software; you can redistribute it and/or modify it under
       7             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       8             :  * by the Free Software Foundation.
       9             :  *
      10             :  * This library is distributed in the hope that it will be useful, but WITHOUT
      11             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      12             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      13             :  * details.
      14             :  *
      15             :  * You should have received a copy of the GNU Lesser General Public License
      16             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      17             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      18             :  */
      19             : 
      20             : #include "decompressor.h"
      21             : 
      22             : #include "compressorResult.h"
      23             : #include "log.h"
      24             : #include "plugin.h"
      25             : #include "pluginInstance.h"
      26             : #include "pluginRegistry.h"
      27             : 
      28             : namespace pression
      29             : {
      30             : namespace detail
      31             : {
      32             : class Decompressor : public PluginInstance
      33             : {
      34             : public:
      35           1 :     Decompressor() {}
      36             : 
      37         185 :     Decompressor( pression::PluginRegistry& registry, const uint32_t name )
      38         185 :     {
      39         185 :         setup( registry, name );
      40         185 :     }
      41             : 
      42         186 :     ~Decompressor()
      43         186 :     {
      44         186 :         clear();
      45         186 :     }
      46             : 
      47         371 :     void clear()
      48             :     {
      49         371 :         if( plugin && instance )
      50           0 :             plugin->deleteDecompressor( instance );
      51         371 :         PluginInstance::clear();
      52         371 :     }
      53             : 
      54         185 :     bool setup( pression::PluginRegistry& registry, const uint32_t name )
      55             :     {
      56         185 :         if( plugin && info.name == name )
      57           0 :             return true;
      58             : 
      59         185 :         clear();
      60             : 
      61         185 :         if( name <= EQ_COMPRESSOR_NONE )
      62           0 :             return true;
      63             : 
      64         185 :         plugin = registry.findPlugin( name );
      65         185 :         LBASSERTINFO( plugin,
      66             :                       "Can't find plugin for decompressor " << name );
      67         185 :         if( !plugin )
      68           0 :             return false;
      69             : 
      70         185 :         instance = plugin->newDecompressor( name );
      71         185 :         info = plugin->findInfo( name );
      72         185 :         LBASSERT( info.name == name );
      73             : 
      74         185 :         LBLOG( LOG_PLUGIN ) << "Instantiated " << (instance ? "" : "empty ")
      75           0 :                             << "decompressor of type 0x" << std::hex << name
      76         185 :                             << std::dec << std::endl;
      77         185 :         return true;
      78             :     }
      79             : };
      80             : }
      81             : 
      82           1 : Decompressor::Decompressor()
      83           1 :     : impl_( new detail::Decompressor )
      84             : {
      85           1 :     LB_TS_THREAD( _thread );
      86           1 : }
      87             : 
      88         185 : Decompressor::Decompressor( PluginRegistry& registry, const uint32_t name )
      89         185 :     : impl_( new detail::Decompressor( registry, name ))
      90             : {
      91         185 :     LB_TS_THREAD( _thread );
      92         185 : }
      93             : 
      94         372 : Decompressor::~Decompressor()
      95             : {
      96         186 :     delete impl_;
      97         186 : }
      98             : 
      99         372 : bool Decompressor::isGood() const
     100             : {
     101         744 :     LB_TS_SCOPED( _thread );
     102         744 :     return impl_->isGood();
     103             : }
     104             : 
     105           0 : bool Decompressor::uses( const uint32_t name ) const
     106             : {
     107           0 :     return isGood() && impl_->info.name == name;
     108             : }
     109             : 
     110           0 : bool Decompressor::setup( PluginRegistry& from, const uint32_t name )
     111             : {
     112           0 :     return impl_->setup( from, name );
     113             : }
     114             : 
     115           0 : void Decompressor::clear()
     116             : {
     117           0 :     impl_->clear();
     118           0 : }
     119             : 
     120           0 : const EqCompressorInfo& Decompressor::getInfo() const
     121             : {
     122           0 :     return impl_->info;
     123             : }
     124             : 
     125           0 : bool Decompressor::decompress( const CompressorResult& input, void* const out,
     126             :                                uint64_t pvpOut[4], const uint64_t flags )
     127             : {
     128           0 :     LBASSERT( uses( input.compressor ));
     129           0 :     LBASSERT( !input.chunks.empty( ));
     130             : 
     131           0 :     if( !uses( input.compressor ) || input.chunks.empty( ))
     132           0 :         return false;
     133             : 
     134           0 :     const size_t num = input.chunks.size();
     135           0 :     const void** in = static_cast< const void** >( alloca( num *
     136           0 :                                                            sizeof( void* )));
     137           0 :     uint64_t* inSizes = static_cast< uint64_t* >( alloca( num *
     138           0 :                                                           sizeof( uint64_t )));
     139           0 :     for( size_t i = 0; i < num; ++i )
     140             :     {
     141           0 :         in[i] = input.chunks[i].data;
     142           0 :         inSizes[i] = input.chunks[i].getNumBytes();
     143             :     }
     144             : 
     145           0 :     impl_->plugin->decompress( impl_->instance, impl_->info.name, in, inSizes,
     146           0 :                                unsigned( num ), out, pvpOut, flags);
     147           0 :     return true;
     148             : }
     149             : 
     150             : 
     151           0 : void Decompressor::decompress( const void* const* in,
     152             :                                const uint64_t* const inSizes,
     153             :                                const unsigned numInputs, void* const out,
     154             :                                uint64_t pvpOut[4], const uint64_t flags )
     155             : {
     156           0 :     impl_->plugin->decompress( impl_->instance, impl_->info.name, in, inSizes,
     157           0 :                                numInputs, out, pvpOut, flags );
     158           0 : }
     159             : 
     160         370 : void Decompressor::decompress( const void* const* in,
     161             :                                const uint64_t* const inSizes,
     162             :                                const unsigned numInputs, void* const out,
     163             :                                uint64_t outDim[2] )
     164             : {
     165         370 :     impl_->plugin->decompress( impl_->instance, impl_->info.name, in, inSizes,
     166         370 :                                numInputs, out, outDim, EQ_COMPRESSOR_DATA_1D );
     167         370 : }
     168           3 : }

Generated by: LCOV version 1.11