TuttleOFX  1
main.cpp
Go to the documentation of this file.
00001 #include <tuttle/common/utils/global.hpp>
00002 
00003 #include <tuttle/host/Graph.hpp>
00004 
00005 void sam_terminate( void )
00006 {
00007         TUTTLE_LOG_ERROR( "[buffer example] Sorry, Sam has encountered a fatal error." );
00008         TUTTLE_LOG_ERROR( "[buffer example] Please report this bug." );
00009         exit( -1 );
00010 }
00011 
00012 void sam_unexpected( void )
00013 {
00014         TUTTLE_LOG_ERROR( "[buffer example] Sorry, Sam has encountered a fatal error." );
00015         TUTTLE_LOG_ERROR( "[buffer example] Please report this bug." );
00016         BOOST_THROW_EXCEPTION( std::runtime_error( "Sorry, Sam has encountered an unexpected exception.\nPlease report this bug." ) );
00017 }
00018 
00019 int main( int argc, char** argv )
00020 {
00021         boost::shared_ptr<tuttle::common::formatters::Formatter> formatter( tuttle::common::formatters::Formatter::get() );
00022         boost::shared_ptr<tuttle::common::Color>                 color( tuttle::common::Color::get() );
00023         formatter->init_logging();
00024         color->disable();
00025         
00026         std::set_terminate( &sam_terminate );
00027         std::set_unexpected( &sam_unexpected );
00028         try
00029         {
00030                 using namespace tuttle::host;
00031                 TUTTLE_LOG_INFO( "[buffer example] Preload plugin" );
00032                 // core().getPluginCache().addDirectoryToPath( "/path/to/plugins" );
00033                 // core().getPluginCache().scanPluginFiles();
00034                 core().preload();
00035 
00036                 TUTTLE_TLOG( TUTTLE_INFO, core().getImageEffectPluginCache() );
00037 
00038                 TUTTLE_LOG_INFO( "[buffer example] Preload done" );
00039 
00040                 TUTTLE_LOG_INFO( "[buffer example] Create plugins" );
00041                 Graph g;
00042                 //              Graph::Node& read1   = g.createNode( "tuttle.ffmpegreader" );
00043                 Graph::Node& read1    = g.createNode( "tuttle.pngreader" );
00044                 Graph::Node& read2    = g.createNode( "tuttle.oiioreader" );
00045                 Graph::Node& read3    = g.createNode( "tuttle.exrreader" );
00046                 Graph::Node& bitdepth = g.createNode( "tuttle.bitdepth" );
00047                 Graph::Node& invert1  = g.createNode( "tuttle.invert" );
00048                 /*Graph::Node& invert2 = */ g.createNode( "tuttle.invert" );
00049                 /*Graph::Node& invert2 = */ g.createNode( "tuttle.invert" );
00050                 Graph::Node& invert2 = g.createNode( "tuttle.invert" );
00051                 Graph::Node& blur1   = g.createNode( "tuttle.blur" );
00052                 Graph::Node& invert4 = g.createNode( "tuttle.invert" );
00053                 //      Graph::Node& crop1   = g.createNode( "tuttle.crop" );
00054                 Graph::Node& merge1    = g.createNode( "tuttle.merge" );
00055                 Graph::Node& bitdepth1 = g.createNode( "tuttle.bitdepth" );
00056 
00057                 
00058                 TUTTLE_LOG_INFO( "[buffer example] Set plugins parameters" );
00059                 // Setup parameters
00060                 //              read1.getParam( "filename" ).setValue( "data/input1.avi" );
00061                 read1.getParam( "filename" ).setValue( "data/input.png" );
00062                 read2.getParam( "filename" ).setValue( "data/input.dpx" );
00063                 read3.getParam( "filename" ).setValue( "data/input.exr" );
00064                 bitdepth.getParam( "outputBitDepth" ).setValue( 3 );
00065                 TUTTLE_LOG_VAR( TUTTLE_INFO, bitdepth.getParam( "outputBitDepth" ).getStringValue() );
00066                 blur1.getParam( "size" ).setValue( 6.5, 15.0 );
00067                 //              blur1.getParam( "size" ).setAtIndex( 65.43, 1 );
00068                 //      crop1.getParam( "Down" ).setValue( 400 );
00069 
00070                 TUTTLE_LOG_INFO( "[buffer example] Connect plugins" );
00071                 g.connect( read1, bitdepth );
00072                 g.connect( bitdepth, invert1 );
00073                 g.connect( invert1, invert2 );
00074                 g.connect( invert2, blur1 );
00075                 g.connect( invert1, invert4 );
00076 
00077                 g.connect( invert1, bitdepth1 );
00078                 g.connect( bitdepth1, merge1.getAttribute( "A" ) );
00079                 g.connect( read3, merge1.getAttribute( "B" ) );
00080 
00081                 TUTTLE_LOG_INFO( "[buffer example] Process" );
00082                 std::list<std::string> outputs;
00083                 outputs.push_back( merge1.getName() );
00084                 outputs.push_back( invert1.getName() );
00085                 
00086                 memory::MemoryCache outputCache;
00087                 g.compute( outputCache, outputs );
00088                 
00089                 TUTTLE_LOG_INFO( "[buffer example] Finish" );
00090                 TUTTLE_LOG_VAR( TUTTLE_INFO, invert1.getName() );
00091                 memory::CACHE_ELEMENT img = outputCache.get( invert1.getName(), 0 );
00092 
00093                 if( ! img.get() )
00094                 {
00095                         TUTTLE_LOG_ERROR( "[buffer example] No buffer..." );
00096                         return 1;
00097                 }
00098                 TUTTLE_LOG_INFO( "[buffer example] Print Buffer Status" );
00099                 ofx::imageEffect::EBitDepth bd = img->getBitDepth();
00100                 ofx::imageEffect::EPixelComponent pc = img->getComponentsType();
00101                 OfxRectI bounds = img->getBounds();
00102 
00103                 TUTTLE_LOG_VAR( TUTTLE_INFO, mapBitDepthEnumToString( bd ) );
00104                 TUTTLE_LOG_VAR( TUTTLE_INFO, mapPixelComponentEnumToString( pc ) );
00105                 TUTTLE_LOG_VAR4( TUTTLE_INFO, bounds.x1, bounds.y1, bounds.x2, bounds.y2 );
00106                 TUTTLE_LOG_VAR( TUTTLE_INFO, img->getClipName() );
00107                 //TUTTLE_LOG_VAR( img->getPixelData() );
00108         }
00109         catch( tuttle::exception::Common& e )
00110         {
00111                 TUTTLE_LOG_ERROR( "Tuttle Exception : main de sam." );
00112                 TUTTLE_LOG_ERROR( boost::diagnostic_information( e ) );
00113         }
00114         catch(... )
00115         {
00116                 TUTTLE_LOG_ERROR( "Exception ... : main de sam." );
00117                 TUTTLE_LOG_ERROR( boost::current_exception_diagnostic_information() );
00118 
00119         }
00120 
00121         return 0;
00122 }
00123