TuttleOFX
1
|
00001 #include "CTLPlugin.hpp" 00002 #include "CTLProcess.hpp" 00003 #include "CTLDefinitions.hpp" 00004 00005 #include <boost/gil/gil_all.hpp> 00006 #include <boost/algorithm/string/split.hpp> 00007 00008 #include <fstream> 00009 #include <boost/filesystem/path.hpp> 00010 00011 namespace tuttle { 00012 namespace plugin { 00013 namespace ctl { 00014 00015 00016 CTLPlugin::CTLPlugin( OfxImageEffectHandle handle ) 00017 : ImageEffectGilPlugin( handle ) 00018 { 00019 _paramInput = fetchChoiceParam ( kParamChooseInput ); 00020 _paramCode = fetchStringParam ( kParamCTLCode ); 00021 _paramFile = fetchStringParam ( kTuttlePluginFilename ); 00022 _paramUpdateRender = fetchPushButtonParam ( kParamChooseInputCodeUpdate ); 00023 00024 changedParam ( _instanceChangedArgs, kParamChooseInput ); 00025 } 00026 00027 CTLProcessParams<CTLPlugin::Scalar> CTLPlugin::getProcessParams( const OfxPointD& renderScale ) const 00028 { 00029 using namespace boost::filesystem; 00030 CTLProcessParams<Scalar> params; 00031 params._inputType = static_cast<EParamChooseInput>( _paramInput->getValue() ); 00032 switch( params._inputType ) 00033 { 00034 case eParamChooseInputCode: 00035 { 00036 params._module = "inputCode"; 00037 params._code = _paramCode->getValue(); 00038 break; 00039 } 00040 case eParamChooseInputFile: 00041 { 00042 // std::ifstream f( _paramFile->getValue().c_str(), std::ios::in ); 00043 // std::getline( f, params._code, '\0' ); 00044 // split( params._paths, paths, is_any_of(":;"), token_compress_on ); 00045 const path filename = path( _paramFile->getValue() ); 00046 params._module = filename.stem().string(); 00047 params._paths.push_back( filename.parent_path().string() ); 00048 break; 00049 } 00050 } 00051 return params; 00052 } 00053 00054 void CTLPlugin::changedParam( const OFX::InstanceChangedArgs &args, const std::string ¶mName ) 00055 { 00056 if( paramName == kParamChooseInput ) 00057 { 00058 EParamChooseInput input = static_cast<EParamChooseInput>( _paramInput->getValue() ); 00059 switch( input ) 00060 { 00061 case eParamChooseInputCode: 00062 { 00063 _paramCode -> setIsSecretAndDisabled( false ); 00064 _paramUpdateRender -> setIsSecretAndDisabled( false ); 00065 _paramFile -> setIsSecretAndDisabled( true ); 00066 break; 00067 } 00068 case eParamChooseInputFile: 00069 { 00070 _paramCode -> setIsSecretAndDisabled( true ); 00071 _paramUpdateRender -> setIsSecretAndDisabled( true ); 00072 _paramFile -> setIsSecretAndDisabled( false ); 00073 break; 00074 } 00075 } 00076 } 00077 else if( paramName == kParamCTLCode ) 00078 { 00079 _paramInput->setValue( eParamChooseInputCode ); 00080 } 00081 else if( paramName == kTuttlePluginFilename ) 00082 { 00083 _paramInput->setValue( eParamChooseInputFile ); 00084 } 00085 } 00086 00087 bool CTLPlugin::getRegionOfDefinition( const OFX::RegionOfDefinitionArguments& args, OfxRectD& rod ) 00088 { 00089 OfxRectD srcRod = _clipSrc->getCanonicalRod( args.time ); 00090 00091 rod.x1 = srcRod.x1; 00092 rod.y1 = srcRod.y1; 00093 rod.x2 = srcRod.x2; 00094 rod.y2 = srcRod.y2; 00095 00096 return false; 00097 } 00098 00099 bool CTLPlugin::isIdentity( const OFX::RenderArguments& args, OFX::Clip*& identityClip, double& identityTime ) 00100 { 00101 // CTLProcessParams<Scalar> params = getProcessParams(); 00102 // if( params._in == params._out ) 00103 // { 00104 // identityClip = _clipSrc; 00105 // identityTime = args.time; 00106 // return true; 00107 // } 00108 return false; 00109 } 00110 00111 /** 00112 * @brief The overridden render function 00113 * @param[in] args Rendering parameters 00114 */ 00115 void CTLPlugin::render( const OFX::RenderArguments &args ) 00116 { 00117 // instantiate the render code based on the pixel depth of the dst clip 00118 OFX::EBitDepth bitDepth = _clipDst->getPixelDepth(); 00119 OFX::EPixelComponent components = _clipDst->getPixelComponents(); 00120 00121 switch( components ) 00122 { 00123 case OFX::ePixelComponentRGBA: 00124 { 00125 doGilRender<CTLProcess, false, boost::gil::rgba_layout_t>( *this, args, bitDepth ); 00126 return; 00127 } 00128 case OFX::ePixelComponentRGB: 00129 case OFX::ePixelComponentAlpha: 00130 case OFX::ePixelComponentCustom: 00131 case OFX::ePixelComponentNone: 00132 { 00133 BOOST_THROW_EXCEPTION( exception::Unsupported() 00134 << exception::user() + "Pixel components (" + mapPixelComponentEnumToString(components) + ") not supported by the plugin." ); 00135 } 00136 } 00137 BOOST_THROW_EXCEPTION( exception::Unknown() ); 00138 } 00139 00140 00141 } 00142 } 00143 }