TuttleOFX
1
|
00001 #include <ofxsImageEffect.h> 00002 00003 namespace tuttle { 00004 00005 template <class ParamType> 00006 class ParamMathPlugin : public OFX::ParamEffect 00007 { 00008 enum EOperation 00009 { 00010 eMultiply, 00011 eDivide, 00012 eAddition, 00013 eSubtraction, 00014 eModulo, 00015 }; 00016 00017 public: 00018 ParamMathPlugin( OfxParamEffectHandle handle ) 00019 { 00020 _operation = fetchChoice( "operation" ); 00021 _a = fetch<ParamType>( "a" ); 00022 _b = fetch<ParamType>( "b" ); 00023 _output = fetch<ParamType>( "output" ); 00024 } 00025 00026 public: 00027 void process( const OFX::RenderArguments& args ) 00028 { 00029 // test valeurs min/max ? 00030 switch( static_cast<EOperation>( _operation.value() ) ) 00031 { 00032 case eParamMathMultiply: 00033 _output->setValue( _a->value() * _b->value() ); 00034 return; 00035 case eParamMathDivide: 00036 if( b->value() == 0 ) 00037 { 00038 _output->setValue( 0 ); 00039 return; 00040 } 00041 _output->setValue( _a->value() / _b->value() ); 00042 return; 00043 case eAddition: 00044 _output->setValue( _a->value() + _b->value() ); 00045 return; 00046 case eSubtraction: 00047 _output->setValue( _a->value() - _b->value() ); 00048 return; 00049 case eModulo: 00050 _output->setValue( _a->value() % _b->value() ); 00051 return; 00052 } 00053 _output->setValue( 0 ); 00054 } 00055 00056 protected: 00057 OFX::ChoiceParam* _operation; 00058 ParamType* _a; 00059 ParamType* _b; 00060 ParamType* _output; 00061 }; 00062 00063 mDeclarePluginFactory( ParamMathPluginFactory<DoubleParam>, {}, {} 00064 ); 00065 mDeclarePluginFactory( ParamMathPluginFactory<IntParam>, {}, {} 00066 ); 00067 00068 template <class ParamType> 00069 void ParamMathPluginFactory::describe( OFX::ImageEffectDescriptor& desc ) 00070 { 00071 desc.setLabels( "TuttleMathParam", "MathParam", 00072 "Math Param" ); 00073 desc.setPluginGrouping( "tuttle/param" ); 00074 00075 OFX::ChoiceParamDescriptor* op = desc.defineChoiceParam( "operation" ); 00076 op->appendOption( "Multiply" ); 00077 op->appendOption( "Divide" ); 00078 op->appendOption( "Addition" ); 00079 op->appendOption( "Subtraction" ); 00080 op->appendOption( "Modulo" ); 00081 op->setDefault( 0 ); 00082 00083 OFX::Descriptor<ParamType>* a = desc.define<ParamType>( "a" ); 00084 OFX::Descriptor<ParamType>* b = desc.define<ParamType>( "b" ); 00085 OFX::Descriptor<ParamType>* output = desc.define<ParamType>( "Output" ); 00086 } 00087 00088 template <class ParamType> 00089 OFX::ParamEffect* ParamMathPluginFactory::createInstance( OfxImageEffectHandle handle ) 00090 { 00091 return new ParamMathPlugin( handle ); 00092 } 00093 00094 } 00095 00096 namespace OFX 00097 { 00098 namespace Plugin 00099 { 00100 void getPluginIDs( OFX::PluginFactoryArray& ids ) 00101 { 00102 static tuttle::ParamMathPluginFactory<DoubleParam> d( "tuttle.parammath.double", 0, 0 ); 00103 static tuttle::ParamMathPluginFactory<IntParam> i( "tuttle.parammath.int", 0, 0 ); 00104 ids.push_back( &d ); 00105 ids.push_back( &i ); 00106 } 00107 00108 } 00109 } 00110