compressor/compressor.cpp

00001 
00002 /* Copyright (c) 2009, Cedric Stalder <cedric.stalder@gmail.com> 
00003  *               2009, Stefan Eilemann <eile@equalizergraphics.com>
00004  *
00005  * This library is free software; you can redistribute it and/or modify it under
00006  * the terms of the GNU Lesser General Public License version 2.1 as published
00007  * by the Free Software Foundation.
00008  *  
00009  * This library is distributed in the hope that it will be useful, but WITHOUT
00010  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00012  * details.
00013  * 
00014  * You should have received a copy of the GNU Lesser General Public License
00015  * along with this library; if not, write to the Free Software Foundation, Inc.,
00016  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00017  */
00018 
00019 #include "compressor.h"
00020 
00021 #include "compressorRLE4B.h"
00022 #include "compressorRLE4HF.h"
00023 #include "compressorRLE4BU.h"
00024 #include "compressorRLEU.h"
00025 
00026 namespace eq
00027 {
00028 namespace plugin
00029 {
00030 namespace
00031 {
00032     Compressor::Functions _functions[] =
00033     {   
00034         eq::plugin::CompressorRLE4B::getFunctions(),
00035         eq::plugin::CompressorDiffRLE4B::getFunctions(),
00036         eq::plugin::CompressorRLE4HF::getFunctions(),
00037         eq::plugin::CompressorRLE4BU::getFunctions(),
00038         eq::plugin::CompressorRLEU::getFunctions(),
00039 #if 0
00040         eq::plugin::CompressorRLEByte::getFunctions(),
00041         eq::plugin::CompressorRLE3B::getFunctions(),
00042         eq::plugin::CompressorRLE4F::getFunctions(),
00043 #endif
00044         Compressor::Functions()
00045     };
00046 
00047     Compressor::Functions& _findFunctions( const unsigned name )
00048     {
00049         for( size_t i = 0; true; ++i )
00050         {
00051             if( _functions[i].name == name )
00052                 return _functions[i];
00053 
00054             if( _functions[i].name == 0 )
00055             {
00056                 assert( 0 ); // UNREACHABLE
00057                 return _functions[i];
00058             }
00059         }
00060 
00061         assert( 0 ); // UNREACHABLE
00062         return _functions[0];
00063     }
00064 }
00065 
00066 Compressor::Compressor()
00067         : _nResults( 0 )
00068 {}
00069 
00070 Compressor::~Compressor()
00071 {
00072     for ( size_t i = 0; i < _results.size(); i++ )
00073         delete ( _results[i] );
00074 
00075     _results.clear();
00076 }
00077 
00078 Compressor::Functions::Functions()
00079         : name( 0 )
00080         , getInfo( 0 )
00081         , newCompressor( 0 )
00082         , decompress( 0 )
00083 {}
00084     
00085 }
00086 }
00087 
00088 size_t EqCompressorGetNumCompressors()
00089 {
00090     return sizeof( eq::plugin::_functions ) /
00091            sizeof( eq::plugin::Compressor::Functions ) - 1;
00092 }
00093            
00094 void EqCompressorGetInfo( const size_t n, EqCompressorInfo* const info )
00095 {
00096     return eq::plugin::_functions[ n ].getInfo( info );
00097 }
00098 
00099 void* EqCompressorNewCompressor( const unsigned name )
00100 {
00101     const eq::plugin::Compressor::Functions& functions = 
00102         eq::plugin::_findFunctions( name );
00103     return functions.newCompressor( );
00104 }
00105 
00106 void EqCompressorDeleteCompressor( void* const compressor )
00107 {
00108     delete reinterpret_cast< eq::plugin::Compressor* >( compressor );
00109 }
00110 
00111 void* EqCompressorNewDecompressor( const unsigned name ) 
00112 {
00113     return 0;
00114 }
00115 
00116 void EqCompressorDeleteDecompressor( void* const decompressor ) 
00117 {
00118     assert( decompressor == 0 );
00119     /* nop */
00120 }
00121 
00122 void EqCompressorCompress( void* const ptr, const unsigned name,
00123                            void* const in, const eq_uint64_t* inDims,
00124                            const eq_uint64_t flags )
00125 {
00126     const bool useAlpha = !(flags & EQ_COMPRESSOR_IGNORE_MSE);
00127     const eq_uint64_t nPixels = (flags & EQ_COMPRESSOR_DATA_1D) ?
00128                                   inDims[1]: inDims[1] * inDims[3];
00129 
00130     eq::plugin::Compressor* compressor = 
00131         reinterpret_cast< eq::plugin::Compressor* >( ptr );
00132     compressor->compress( in, nPixels, useAlpha );
00133 }
00134 
00135 unsigned EqCompressorGetNumResults( void* const ptr,
00136                                     const unsigned name )
00137 {
00138     eq::plugin::Compressor* compressor = 
00139         reinterpret_cast< eq::plugin::Compressor* >( ptr );
00140     return compressor->getNResults();
00141 }
00142 
00143 void EqCompressorGetResult( void* const ptr, const unsigned name,
00144                             const unsigned i, void** const out, 
00145                             eq_uint64_t* const outSize )
00146 {
00147     eq::plugin::Compressor* compressor = 
00148         reinterpret_cast< eq::plugin::Compressor* >( ptr );
00149     eq::plugin::Compressor::Result* result = compressor->getResults()[ i ];
00150     
00151     *out = result->getData();
00152     *outSize = result->getSize();
00153     assert( result->getMaxSize() >= result->getSize( ));
00154 }
00155 
00156 
00157 void EqCompressorDecompress( void* const decompressor, const unsigned name,
00158                              const void* const* in,
00159                              const eq_uint64_t* const inSizes,
00160                              const unsigned nInputs,
00161                              void* const out, eq_uint64_t* const outDims,
00162                              const eq_uint64_t flags )
00163 {
00164     const bool useAlpha = !(flags & EQ_COMPRESSOR_IGNORE_MSE);
00165     const eq_uint64_t nPixels = ( flags & EQ_COMPRESSOR_DATA_1D) ?
00166                            outDims[1] : outDims[1] * outDims[3];
00167 
00168     eq::plugin::Compressor::Functions& functions = 
00169         eq::plugin::_findFunctions( name );
00170     functions.decompress( in, inSizes, nInputs, out, nPixels, useAlpha );
00171 }
Generated on Sat Feb 6 12:59:50 2010 for Equalizer 0.9.1 by  doxygen 1.6.1