TuttleOFX  1
ConvolutionPluginFactory.cpp
Go to the documentation of this file.
00001 #include "ConvolutionPluginFactory.hpp"
00002 #include "ConvolutionPlugin.hpp"
00003 #include "ConvolutionDefinitions.hpp"
00004 
00005 #include <ofxImageEffect.h>
00006 
00007 namespace tuttle {
00008 namespace plugin {
00009 namespace convolution {
00010 
00011 /**
00012  * @brief Function called to describe the plugin main features.
00013  * @param[in, out] desc Effect descriptor
00014  */
00015 void ConvolutionPluginFactory::describe( OFX::ImageEffectDescriptor& desc )
00016 {
00017         desc.setLabels(
00018                 "TuttleConvolution",
00019                 "Convolution",
00020                 "Convolution" );
00021         desc.setPluginGrouping( "tuttle/image/process/filter" );
00022         
00023         desc.setDescription(
00024 "A convolution is defined as the integral of the product of the two functions"
00025 "after one is reversed and shifted."
00026 "\n"
00027 "\n"
00028 "In mathematics and, in particular, functional analysis, convolution is a"
00029 "mathematical operation on two functions f and g, producing a third function"
00030 "that is typically viewed as a modified version of one of the original functions. "
00031 "Convolution is similar to cross-correlation. It has applications that include"
00032 "probability, statistics, computer vision, image and signal processing,"
00033 "electrical engineering, and differential equations."
00034 "\n"
00035 "The convolution can be defined for functions on groups other than Euclidean"
00036 "space. In particular, the circular convolution can be defined for periodic"
00037 "functions (that is, functions on the circle), and the discrete convolution"
00038 "can be defined for functions on the set of integers. These generalizations of"
00039 "the convolution have applications in the field of numerical analysis and"
00040 "numerical linear algebra, and in the design and implementation of finite"
00041 "impulse response filters in signal processing."
00042 "\n"
00043 "\n"
00044 "http://en.wikipedia.org/wiki/Convolution"
00045 );
00046 
00047 
00048         // add the supported contexts, only filter at the moment
00049         desc.addSupportedContext( OFX::eContextFilter );
00050         desc.addSupportedContext( OFX::eContextGeneral );
00051 
00052         // add supported pixel depths
00053         desc.addSupportedBitDepth( OFX::eBitDepthUByte );
00054         desc.addSupportedBitDepth( OFX::eBitDepthUShort );
00055         desc.addSupportedBitDepth( OFX::eBitDepthFloat );
00056 
00057         // plugin flags
00058         desc.setSupportsTiles( kSupportTiles );
00059         desc.setRenderThreadSafety( OFX::eRenderFullySafe );
00060 }
00061 
00062 /**
00063  * @brief Function called to describe the plugin controls and features.
00064  * @param[in, out]   desc       Effect descriptor
00065  * @param[in]        context    Application context
00066  */
00067 void ConvolutionPluginFactory::describeInContext( OFX::ImageEffectDescriptor& desc,
00068                                                   OFX::EContext               context )
00069 {
00070         OFX::ClipDescriptor* srcClip = desc.defineClip( kOfxImageEffectSimpleSourceClipName );
00071         srcClip->addSupportedComponent( OFX::ePixelComponentRGBA );
00072         srcClip->addSupportedComponent( OFX::ePixelComponentRGB );
00073         srcClip->addSupportedComponent( OFX::ePixelComponentAlpha );
00074         srcClip->setSupportsTiles( kSupportTiles );
00075 
00076         // Create the mandated output clip
00077         OFX::ClipDescriptor* dstClip = desc.defineClip( kOfxImageEffectOutputClipName );
00078         dstClip->addSupportedComponent( OFX::ePixelComponentRGBA );
00079         dstClip->addSupportedComponent( OFX::ePixelComponentRGB );
00080         dstClip->addSupportedComponent( OFX::ePixelComponentAlpha );
00081         dstClip->setSupportsTiles( kSupportTiles );
00082 
00083         OFX::Int2DParamDescriptor* size = desc.defineInt2DParam( kParamSize );
00084         size->setLabel( "Size" );
00085         size->setDefault( 3, 3 );
00086         //      size->setIncrement( 2, 2 );
00087         size->setRange( 3, 3, kParamSizeMax, kParamSizeMax );
00088 
00089         OFX::ChoiceParamDescriptor* border = desc.defineChoiceParam( kParamBorder );
00090         border->setLabel( "Border" );
00091         border->appendOption( kParamBorderMirror );
00092         border->appendOption( kParamBorderConstant );
00093         border->appendOption( kParamBorderBlack );
00094         border->appendOption( kParamBorderPadded );
00095         
00096         for( unsigned int y = 0; y < kParamSizeMax; ++y )
00097         {
00098                 for( unsigned int x = 0; x < kParamSizeMax; ++x )
00099                 {
00100                         const std::string name( getCoefName( y, x ) );
00101                         OFX::DoubleParamDescriptor* coef = desc.defineDoubleParam( name );
00102                         coef->setLabel( name );
00103                         coef->setDisplayRange( -10.0, 10.0 );
00104                         coef->setDefault( 0.0 );
00105                 }
00106         }
00107 }
00108 
00109 /**
00110  * @brief Function called to create a plugin effect instance
00111  * @param[in] handle  Effect handle
00112  * @param[in] context Application context
00113  * @return  plugin instance
00114  */
00115 OFX::ImageEffect* ConvolutionPluginFactory::createInstance( OfxImageEffectHandle handle,
00116                                                             OFX::EContext        context )
00117 {
00118         return new ConvolutionPlugin( handle );
00119 }
00120 
00121 }
00122 }
00123 }