LCOV - code coverage report
Current view: top level - pression/compressor - compressor.cpp (source / functions) Hit Total Coverage
Test: Pression Lines: 66 95 69.5 %
Date: 2016-12-06 05:44:58 Functions: 17 24 70.8 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2009-2010, Cedric Stalder <cedric.stalder@gmail.com>
       3             :  *               2009-2015, Stefan Eilemann <eile@equalizergraphics.com>
       4             :  *
       5             :  * This library is free software; you can redistribute it and/or modify it under
       6             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       7             :  * by the Free Software Foundation.
       8             :  *
       9             :  * This library is distributed in the hope that it will be useful, but WITHOUT
      10             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      11             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      12             :  * details.
      13             :  *
      14             :  * You should have received a copy of the GNU Lesser General Public License
      15             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      16             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      17             :  */
      18             : 
      19             : #include "compressor.h"
      20             : 
      21             : namespace pression
      22             : {
      23             : namespace plugin
      24             : {
      25             : namespace
      26             : {
      27             : typedef std::vector< Compressor::Functions > Compressors;
      28             : static Compressors* _functions;
      29             : 
      30         740 : const Compressor::Functions& _findFunctions( const unsigned name )
      31             : {
      32       13912 :     for( const Compressor::Functions& functions : *_functions )
      33       13912 :         if( functions.name == name )
      34         740 :             return functions;
      35             : 
      36           0 :     assert( 0 ); // UNREACHABLE
      37             :     return _functions->front();
      38             : }
      39             : }
      40             : 
      41         185 : Compressor::Compressor()
      42         185 :     : _nResults( 0 )
      43         185 : {}
      44             : 
      45         370 : Compressor::~Compressor()
      46             : {
      47         553 :     for ( size_t i = 0; i < _results.size(); i++ )
      48         368 :         delete ( _results[i] );
      49             : 
      50         185 :     _results.clear();
      51         185 : }
      52             : 
      53          40 : Compressor::Functions::Functions( const unsigned name_,
      54             :                                   GetInfo_t getInfo_,
      55             :                                   NewCompressor_t newCompressor_,
      56             :                                   NewCompressor_t newDecompressor_,
      57             :                                   Decompress_t decompress_,
      58          40 :                                   IsCompatible_t isCompatible_ )
      59             :         : name( name_ )
      60             :         , getInfo( getInfo_ )
      61             :         , newCompressor( newCompressor_ )
      62             :         , newDecompressor( newDecompressor_ )
      63             :         , decompress( decompress_ )
      64          40 :         , isCompatible( isCompatible_ )
      65          40 : {}
      66             : 
      67          40 : void Compressor::registerEngine( const Compressor::Functions& functions )
      68             : {
      69          40 :     if( !_functions ) // resolve 'static initialization order fiasco'
      70           1 :         _functions = new Compressors;
      71          40 :     _functions->push_back( functions );
      72          40 : }
      73             : 
      74         370 : void Compressor::compress( const void* const inData, const eq_uint64_t* inDims,
      75             :                            const eq_uint64_t flags )
      76             : {
      77         370 :     const bool useAlpha = !(flags & EQ_COMPRESSOR_IGNORE_ALPHA);
      78         740 :     const eq_uint64_t nPixels = (flags & EQ_COMPRESSOR_DATA_1D) ?
      79         740 :                                   inDims[1]: inDims[1] * inDims[3];
      80             : 
      81         370 :     compress( inData, nPixels, useAlpha );
      82         370 : }
      83             : 
      84             : }
      85             : }
      86             : 
      87           1 : size_t EqCompressorGetNumCompressors()
      88             : {
      89           1 :     if( !pression::plugin::_functions )
      90           0 :         pression::plugin::_functions = new pression::plugin::Compressors;
      91           1 :     return pression::plugin::_functions->size();
      92             : }
      93             : 
      94          40 : void EqCompressorGetInfo( const size_t n, EqCompressorInfo* const info )
      95             : {
      96          40 :     assert( pression::plugin::_functions->size() > n );
      97          40 :     (*pression::plugin::_functions)[ n ].getInfo( info );
      98          40 : }
      99             : 
     100         185 : void* EqCompressorNewCompressor( const unsigned name )
     101             : {
     102             :     const pression::plugin::Compressor::Functions& functions =
     103         185 :         pression::plugin::_findFunctions( name );
     104             : 
     105         185 :     return functions.newCompressor( name );
     106             : }
     107             : 
     108         185 : void EqCompressorDeleteCompressor( void* const compressor )
     109             : {
     110         185 :     delete reinterpret_cast< pression::plugin::Compressor* >( compressor );
     111         185 : }
     112             : 
     113         185 : void* EqCompressorNewDecompressor( const unsigned name )
     114             : {
     115             :     const pression::plugin::Compressor::Functions& functions =
     116         185 :         pression::plugin::_findFunctions( name );
     117             : 
     118         185 :     return functions.newDecompressor( name );
     119             : }
     120             : 
     121           0 : void EqCompressorDeleteDecompressor( void* const decompressor )
     122             : {
     123           0 :     delete reinterpret_cast< pression::plugin::Compressor* >( decompressor );
     124           0 : }
     125             : 
     126         370 : void EqCompressorCompress( void* const ptr, const unsigned, void* const in,
     127             :                            const eq_uint64_t* inDims, const eq_uint64_t flags )
     128             : {
     129         370 :     assert( ptr );
     130             :     reinterpret_cast< pression::plugin::Compressor* >( ptr )->
     131         370 :         compress( in, inDims, flags );
     132         370 : }
     133             : 
     134         185 : unsigned EqCompressorGetNumResults( void* const ptr, const unsigned )
     135             : {
     136         185 :     assert( ptr );
     137             :     pression::plugin::Compressor* compressor =
     138         185 :         reinterpret_cast< pression::plugin::Compressor* >( ptr );
     139         185 :     return compressor->getNResults();
     140             : }
     141             : 
     142         368 : void EqCompressorGetResult( void* const ptr, const unsigned, const unsigned i,
     143             :                             void** const out, eq_uint64_t* const outSize )
     144             : {
     145         368 :     assert( ptr );
     146             :     pression::plugin::Compressor* compressor =
     147         368 :         reinterpret_cast< pression::plugin::Compressor* >( ptr );
     148         368 :     pression::plugin::Compressor::Result* result = compressor->getResults()[ i ];
     149             : 
     150         368 :     *out = result->getData();
     151         368 :     *outSize = result->getSize();
     152         368 :     assert( result->getMaxSize() >= result->getSize( ));
     153         368 :     assert( *outSize != 0 );
     154         368 : }
     155             : 
     156             : 
     157         370 : void EqCompressorDecompress( void* const decompressor, const unsigned name,
     158             :                              const void* const* in,
     159             :                              const eq_uint64_t* const inSizes,
     160             :                              const unsigned nInputs,
     161             :                              void* const out, eq_uint64_t* const outDims,
     162             :                              const eq_uint64_t flags )
     163             : {
     164             :     const pression::plugin::Compressor::Functions& functions =
     165         370 :         pression::plugin::_findFunctions( name );
     166         370 :     functions.decompress( in, inSizes, nInputs, out, outDims, flags,
     167         370 :                           decompressor );
     168         370 : }
     169             : 
     170           0 : bool EqCompressorIsCompatible( const unsigned     name,
     171             :                                const GLEWContext* glewContext )
     172             : {
     173             :     const pression::plugin::Compressor::Functions& functions =
     174           0 :         pression::plugin::_findFunctions( name );
     175             : 
     176           0 :     if ( functions.isCompatible == 0 )
     177             :     {
     178           0 :         assert( false );
     179             :         return false;
     180             :     }
     181             : 
     182           0 :     return functions.isCompatible( glewContext );
     183             : }
     184             : 
     185           0 : void EqCompressorDownload( void* const ptr, const unsigned,
     186             :                            const GLEWContext* glewContext,
     187             :                            const eq_uint64_t inDims[4], const unsigned source,
     188             :                            const eq_uint64_t flags, eq_uint64_t outDims[4],
     189             :                            void** out )
     190             : {
     191           0 :     assert( ptr );
     192             :     pression::plugin::Compressor* compressor =
     193           0 :         reinterpret_cast< pression::plugin::Compressor* >( ptr );
     194           0 :     compressor->download( glewContext, inDims, source, flags, outDims, out );
     195           0 : }
     196             : 
     197             : 
     198           0 : void EqCompressorUpload( void* const ptr, const unsigned,
     199             :                          const GLEWContext* glewContext, const void* buffer,
     200             :                          const eq_uint64_t inDims[4], const eq_uint64_t flags,
     201             :                          const eq_uint64_t outDims[4],
     202             :                          const unsigned destination )
     203             : {
     204           0 :     assert( ptr );
     205             :     pression::plugin::Compressor* compressor =
     206           0 :         reinterpret_cast< pression::plugin::Compressor* >( ptr );
     207             :     compressor->upload( glewContext, buffer, inDims, flags, outDims,
     208           0 :                         destination );
     209           0 : }
     210             : 
     211             : 
     212           0 : void EqCompressorStartDownload( void* const ptr, const unsigned /*name*/,
     213             :                                 const GLEWContext* glewContext,
     214             :                                 const eq_uint64_t inDims[4],
     215             :                                 const unsigned source, const eq_uint64_t flags )
     216             : {
     217           0 :     assert( ptr );
     218             :     pression::plugin::Compressor* compressor =
     219           0 :         reinterpret_cast< pression::plugin::Compressor* >( ptr );
     220           0 :     compressor->startDownload( glewContext, inDims, source, flags );
     221           0 : }
     222             : 
     223           0 : void EqCompressorFinishDownload( void* const ptr, const unsigned /*name*/,
     224             :                                  const GLEWContext* glewContext,
     225             :                                  const eq_uint64_t inDims[4],
     226             :                                  const unsigned source, const eq_uint64_t flags,
     227             :                                  eq_uint64_t outDims[4], void** out )
     228             : {
     229           0 :     assert( ptr );
     230             :     pression::plugin::Compressor* compressor =
     231           0 :         reinterpret_cast< pression::plugin::Compressor* >( ptr );
     232             :     compressor->finishDownload( glewContext, inDims, source, flags, outDims,
     233           0 :                                out );
     234           3 : }

Generated by: LCOV version 1.11