LCOV - code coverage report
Current view: top level - lunchbox - decompressor.cpp (source / functions) Hit Total Coverage
Test: lcov2.info Lines: 44 76 57.9 %
Date: 2014-08-05 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 Lunchbox <https://github.com/Eyescale/Lunchbox>
       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 "plugin.h"
      24             : #include "pluginInstance.h"
      25             : #include "pluginRegistry.h"
      26             : 
      27             : namespace lunchbox
      28             : {
      29             : namespace detail
      30             : {
      31             : class Decompressor : public PluginInstance
      32             : {
      33             : public:
      34           1 :     Decompressor() {}
      35             : 
      36         152 :     Decompressor( lunchbox::PluginRegistry& registry, const uint32_t name )
      37         152 :     {
      38         152 :         setup( registry, name );
      39         152 :     }
      40             : 
      41         153 :     ~Decompressor()
      42         153 :     {
      43         153 :         clear();
      44         153 :     }
      45             : 
      46         305 :     void clear()
      47             :     {
      48         305 :         if( instance )
      49           0 :             plugin->deleteDecompressor( instance );
      50         305 :         PluginInstance::clear();
      51         305 :     }
      52             : 
      53         152 :     bool setup( lunchbox::PluginRegistry& registry, const uint32_t name )
      54             :     {
      55         152 :         if( plugin && info.name == name )
      56           0 :             return true;
      57             : 
      58         152 :         clear();
      59             : 
      60         152 :         if( name <= EQ_COMPRESSOR_NONE )
      61           0 :             return true;
      62             : 
      63         152 :         plugin = registry.findPlugin( name );
      64         152 :         LBASSERTINFO( plugin,
      65             :                       "Can't find plugin for decompressor " << name );
      66         152 :         if( !plugin )
      67           0 :             return false;
      68             : 
      69         152 :         instance = plugin->newDecompressor( name );
      70         152 :         info = plugin->findInfo( name );
      71         152 :         LBASSERT( info.name == name );
      72             : 
      73         152 :         LBLOG( LOG_PLUGIN ) << "Instantiated " << (instance ? "" : "empty ")
      74           0 :                             << "decompressor of type 0x" << std::hex << name
      75         152 :                             << std::dec << std::endl;
      76         152 :         return true;
      77             :     }
      78             : };
      79             : }
      80             : 
      81           1 : Decompressor::Decompressor()
      82           1 :     : impl_( new detail::Decompressor )
      83             : {
      84           1 :     LB_TS_THREAD( _thread );
      85           1 : }
      86             : 
      87         152 : Decompressor::Decompressor( PluginRegistry& registry, const uint32_t name )
      88         152 :     : impl_( new detail::Decompressor( registry, name ))
      89             : {
      90         152 :     LB_TS_THREAD( _thread );
      91         152 : }
      92             : 
      93         306 : Decompressor::~Decompressor()
      94             : {
      95         153 :     delete impl_;
      96         153 : }
      97             : 
      98         306 : bool Decompressor::isGood() const
      99             : {
     100         306 :     LB_TS_SCOPED( _thread );
     101         306 :     return impl_->isGood();
     102             : }
     103             : 
     104           0 : bool Decompressor::uses( const uint32_t name ) const
     105             : {
     106           0 :     return isGood() && impl_->info.name == name;
     107             : }
     108             : 
     109           0 : bool Decompressor::setup( PluginRegistry& from, const uint32_t name )
     110             : {
     111           0 :     return impl_->setup( from, name );
     112             : }
     113             : 
     114           0 : void Decompressor::clear()
     115             : {
     116           0 :     impl_->clear();
     117           0 : }
     118             : 
     119           0 : const EqCompressorInfo& Decompressor::getInfo() const
     120             : {
     121           0 :     return impl_->info;
     122             : }
     123             : 
     124           0 : bool Decompressor::decompress( const CompressorResult& input, void* const out,
     125             :                                uint64_t pvpOut[4], const uint64_t flags )
     126             : {
     127           0 :     LBASSERT( uses( input.compressor ));
     128           0 :     LBASSERT( !input.chunks.empty( ));
     129             : 
     130           0 :     if( !uses( input.compressor ) || input.chunks.empty( ))
     131           0 :         return false;
     132             : 
     133           0 :     const size_t num = input.chunks.size();
     134           0 :     const void** in = static_cast< const void** >( alloca( num *
     135           0 :                                                            sizeof( void* )));
     136           0 :     uint64_t* inSizes = static_cast< uint64_t* >( alloca( num *
     137           0 :                                                           sizeof( uint64_t )));
     138           0 :     for( size_t i = 0; i < num; ++i )
     139             :     {
     140           0 :         in[i] = input.chunks[i].data;
     141           0 :         inSizes[i] = input.chunks[i].getNumBytes();
     142             :     }
     143             : 
     144             :     impl_->plugin->decompress( impl_->instance, impl_->info.name, in, inSizes,
     145           0 :                                num, out, pvpOut, flags );
     146           0 :     return true;
     147             : }
     148             : 
     149             : 
     150           0 : void Decompressor::decompress( const void* const* in,
     151             :                                const uint64_t* const inSizes,
     152             :                                const unsigned numInputs, void* const out,
     153             :                                uint64_t pvpOut[4], const uint64_t flags )
     154             : {
     155             :     impl_->plugin->decompress( impl_->instance, impl_->info.name, in, inSizes,
     156           0 :                                numInputs, out, pvpOut, flags );
     157           0 : }
     158             : 
     159         304 : void Decompressor::decompress( const void* const* in,
     160             :                                const uint64_t* const inSizes,
     161             :                                const unsigned numInputs, void* const out,
     162             :                                uint64_t outDim[2] )
     163             : {
     164             :     impl_->plugin->decompress( impl_->instance, impl_->info.name, in, inSizes,
     165         304 :                                numInputs, out, outDim, EQ_COMPRESSOR_DATA_1D );
     166         304 : }
     167          87 : }

Generated by: LCOV version 1.10