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 {}
00068 
00069 Compressor::~Compressor()
00070 {
00071     for ( size_t i = 0; i < _results.size(); i++ )
00072         delete ( _results[i] );
00073 
00074     _results.clear();
00075 }
00076 
00077 Compressor::Functions::Functions()
00078         : name( 0 )
00079         , getInfo( 0 )
00080         , newCompressor( 0 )
00081         , decompress( 0 )
00082 {}
00083     
00084 }
00085 }
00086 
00087 size_t EqCompressorGetNumCompressors()
00088 {
00089     return sizeof( eq::plugin::_functions ) /
00090            sizeof( eq::plugin::Compressor::Functions ) - 1;
00091 }
00092            
00093 void EqCompressorGetInfo( const size_t n, EqCompressorInfo* const info )
00094 {
00095     return eq::plugin::_functions[ n ].getInfo( info );
00096 }
00097 
00098 void* EqCompressorNewCompressor( const unsigned name )
00099 {
00100     const eq::plugin::Compressor::Functions& functions = 
00101         eq::plugin::_findFunctions( name );
00102     return functions.newCompressor( );
00103 }
00104 
00105 void EqCompressorDeleteCompressor( void* const compressor )
00106 {
00107     delete reinterpret_cast< eq::plugin::Compressor* >( compressor );
00108 }
00109 
00110 void* EqCompressorNewDecompressor( const unsigned name ) 
00111 {
00112     return 0;
00113 }
00114 
00115 void EqCompressorDeleteDecompressor( void* const decompressor ) 
00116 {
00117     assert( decompressor == 0 );
00118     /* nop */
00119 }
00120 
00121 void EqCompressorCompress( void* const ptr, const unsigned name,
00122                            void* const in, const eq_uint64_t* inDims,
00123                            const eq_uint64_t flags )
00124 {
00125     const bool useAlpha = !(flags & EQ_COMPRESSOR_IGNORE_MSE);
00126     const eq_uint64_t nPixels = (flags & EQ_COMPRESSOR_DATA_1D) ?
00127                                   inDims[1]: inDims[1] * inDims[3];
00128 
00129     eq::plugin::Compressor* compressor = 
00130         reinterpret_cast< eq::plugin::Compressor* >( ptr );
00131     compressor->compress( in, nPixels, useAlpha );
00132 }
00133 
00134 unsigned EqCompressorGetNumResults( void* const ptr,
00135                                     const unsigned name )
00136 {
00137     eq::plugin::Compressor* compressor = 
00138         reinterpret_cast< eq::plugin::Compressor* >( ptr );
00139     return compressor->getResults().size();
00140 }
00141 
00142 void EqCompressorGetResult( void* const ptr, const unsigned name,
00143                             const unsigned i, void** const out, 
00144                             eq_uint64_t* const outSize )
00145 {
00146     eq::plugin::Compressor* compressor = 
00147         reinterpret_cast< eq::plugin::Compressor* >( ptr );
00148     eq::plugin::Compressor::Result* result = compressor->getResults()[ i ];
00149     
00150     *out = result->getData();
00151     *outSize = result->getSize();
00152     assert( result->getMaxSize() >= result->getSize( ));
00153 }
00154 
00155 
00156 void EqCompressorDecompress( void* const decompressor, const unsigned name,
00157                              const void* const* in,
00158                              const eq_uint64_t* const inSizes,
00159                              const unsigned nInputs,
00160                              void* const out, eq_uint64_t* const outDims,
00161                              const eq_uint64_t flags )
00162 {
00163     const bool useAlpha = !(flags & EQ_COMPRESSOR_IGNORE_MSE);
00164     const eq_uint64_t nPixels = ( flags & EQ_COMPRESSOR_DATA_1D) ?
00165                            outDims[1] : outDims[1] * outDims[3];
00166 
00167     eq::plugin::Compressor::Functions& functions = 
00168         eq::plugin::_findFunctions( name );
00169     functions.decompress( in, inSizes, nInputs, out, nPixels, useAlpha );
00170 }
Generated on Mon Aug 10 18:58:32 2009 for Equalizer 0.9 by  doxygen 1.5.8