TuttleOFX  1
LutPlugin.cpp
Go to the documentation of this file.
00001 #include "LutPlugin.hpp"
00002 #include "LutProcess.hpp"
00003 #include "LutDefinitions.hpp"
00004 
00005 #include <boost/filesystem/operations.hpp>
00006 #include <boost/gil/gil_all.hpp>
00007 #include <boost/filesystem.hpp>
00008 
00009 namespace bfs = boost::filesystem;
00010 
00011 namespace tuttle {
00012 namespace plugin {
00013 namespace lut {
00014 
00015 using namespace boost::gil;
00016 
00017 LutPlugin::LutPlugin( OfxImageEffectHandle handle )
00018         : ImageEffectGilPlugin( handle )
00019 {
00020         _sFilename = fetchStringParam( kTuttlePluginFilename );
00021 }
00022 
00023 /**
00024  * @brief The overridden render function
00025  * @param[in]   args     Rendering parameters
00026  */
00027 void LutPlugin::render( const OFX::RenderArguments& args )
00028 {
00029         if( !_lutReader.readOk() )
00030         {
00031                 std::string str;
00032                 _sFilename->getValue( str );
00033                 if( ! bfs::exists( str ) )
00034                 {
00035                         BOOST_THROW_EXCEPTION( exception::FileNotExist()
00036                                 << exception::filename(str) );
00037                 }
00038                 if( ! _lutReader.read( str ) )
00039                 {
00040                         BOOST_THROW_EXCEPTION( exception::File()
00041                                 << exception::user( "Unable to read lut file." ) );
00042                 }
00043                 _lut3D.reset( new TetraInterpolator(), _lutReader );
00044         }
00045         if( !_lutReader.readOk() )
00046         {
00047                 BOOST_THROW_EXCEPTION( exception::Unknown() );
00048         }
00049         doGilRender<LutProcess>( *this, args );
00050 }
00051 
00052 void LutPlugin::changedParam( const OFX::InstanceChangedArgs& args, const std::string& paramName )
00053 {
00054         if( paramName == kTuttlePluginFilename )
00055         {
00056                 std::string str;
00057                 _sFilename->getValue( str );
00058                 if( bfs::exists( str ) )
00059                 {
00060                         if( ! _lutReader.read( str ) )
00061                         {
00062                                 BOOST_THROW_EXCEPTION( exception::File() << exception::user( "Unable to read lut file..." ) );
00063                         }
00064                         _lut3D.reset( new TetraInterpolator(), _lutReader );
00065                 }
00066         }
00067 }
00068 
00069 }
00070 }
00071 }