TuttleOFX  1
BlurPlugin.cpp
Go to the documentation of this file.
00001 #include "BlurPlugin.hpp"
00002 #include "BlurProcess.hpp"
00003 #include "BlurDefinitions.hpp"
00004 
00005 #include <terry/point/operations.hpp>
00006 
00007 #include <boost/gil/gil_all.hpp>
00008 
00009 namespace tuttle {
00010 namespace plugin {
00011 namespace blur {
00012 
00013 BlurPlugin::BlurPlugin( OfxImageEffectHandle handle )
00014         : ImageEffectGilPlugin( handle )
00015 {
00016         _paramSize   = fetchDouble2DParam( kParamSize );
00017         _paramBorder = fetchChoiceParam( kParamBorder );
00018         _paramNormalizedKernel = fetchBooleanParam( kParamNormalizedKernel );
00019         _paramKernelEpsilon = fetchDoubleParam( kParamKernelEpsilon );
00020 }
00021 
00022 BlurProcessParams<BlurPlugin::Scalar> BlurPlugin::getProcessParams( const OfxPointD& renderScale ) const
00023 {
00024         using namespace terry::filter;
00025         
00026         BlurProcessParams<Scalar> params;
00027         params._size   = ofxToGil( _paramSize->getValue() ) * ofxToGil( renderScale  );
00028         params._border = static_cast<EParamBorder>( _paramBorder->getValue() );
00029 
00030         const bool normalizedKernel = _paramNormalizedKernel->getValue();
00031         const double kernelEpsilon = _paramKernelEpsilon->getValue();
00032 
00033         params._gilKernelX = buildGaussian1DKernel<Scalar>( params._size.x, normalizedKernel, kernelEpsilon );
00034         params._gilKernelY = buildGaussian1DKernel<Scalar>( params._size.y, normalizedKernel, kernelEpsilon );
00035         
00036         params._boundary_option = convolve_option_extend_mirror;
00037         switch( params._border )
00038         {
00039                 case eParamBorderMirror:
00040                         params._boundary_option = convolve_option_extend_mirror;
00041                         break;
00042                 case eParamBorderConstant:
00043                         params._boundary_option = convolve_option_extend_constant;
00044                         break;
00045                 case eParamBorderBlack:
00046                         params._boundary_option = convolve_option_extend_zero;
00047                         break;
00048                 case eParamBorderPadded:
00049                         params._boundary_option = convolve_option_extend_padded;
00050                         break;
00051                 case eParamBorderNo:
00052                         params._boundary_option = convolve_option_extend_mirror;
00053                         break;
00054         }
00055         return params;
00056 }
00057 
00058 /*
00059    void BlurPlugin::changedParam( const OFX::InstanceChangedArgs &args, const std::string &paramName )
00060    {
00061     if( paramName == kHelpButton )
00062     {
00063         sendMessage( OFX::Message::eMessageMessage,
00064                      "", // No XML resources
00065                      kHelpString );
00066     }
00067    }
00068  */
00069 
00070 bool BlurPlugin::getRegionOfDefinition( const OFX::RegionOfDefinitionArguments& args, OfxRectD& rod )
00071 {
00072         OfxRectD srcRod = _clipSrc->getCanonicalRod( args.time );
00073 
00074         BlurProcessParams<Scalar> params = getProcessParams();
00075 
00076         switch( params._border )
00077         {
00078                 case eParamBorderPadded:
00079                         rod.x1 = srcRod.x1 + params._gilKernelX.left_size();
00080                         rod.y1 = srcRod.y1 + params._gilKernelY.left_size();
00081                         rod.x2 = srcRod.x2 - params._gilKernelX.right_size();
00082                         rod.y2 = srcRod.y2 - params._gilKernelY.right_size();
00083                         return true;
00084                 case eParamBorderBlack:
00085                 case eParamBorderConstant:
00086                 case eParamBorderMirror:
00087                         rod.x1 = srcRod.x1 - params._gilKernelX.left_size();
00088                         rod.y1 = srcRod.y1 - params._gilKernelY.left_size();
00089                         rod.x2 = srcRod.x2 + params._gilKernelX.right_size();
00090                         rod.y2 = srcRod.y2 + params._gilKernelY.right_size();
00091                         return true;
00092                 case eParamBorderNo:
00093                         return false; // don't modify the source image RoD
00094         }
00095         BOOST_ASSERT(false);
00096         return false;
00097 }
00098 
00099 void BlurPlugin::getRegionsOfInterest( const OFX::RegionsOfInterestArguments& args, OFX::RegionOfInterestSetter& rois )
00100 {
00101         BlurProcessParams<Scalar> params = getProcessParams();
00102         OfxRectD srcRod                  = _clipSrc->getCanonicalRod( args.time );
00103 
00104         OfxRectD srcRoi;
00105         srcRoi.x1 = srcRod.x1 - params._gilKernelX.left_size();
00106         srcRoi.y1 = srcRod.y1 - params._gilKernelY.left_size();
00107         srcRoi.x2 = srcRod.x2 + params._gilKernelX.right_size();
00108         srcRoi.y2 = srcRod.y2 + params._gilKernelY.right_size();
00109         rois.setRegionOfInterest( *_clipSrc, srcRoi );
00110 }
00111 
00112 bool BlurPlugin::isIdentity( const OFX::RenderArguments& args, OFX::Clip*& identityClip, double& identityTime )
00113 {
00114         BlurProcessParams<Scalar> params = getProcessParams( args.renderScale );
00115         if( params._size.x != 0 || params._size.y != 0 )
00116                 return false;
00117 
00118         identityClip = _clipSrc;
00119         identityTime = args.time;
00120         return true;
00121 }
00122 
00123 /**
00124  * @brief The overridden render function
00125  * @param[in]   args     Rendering parameters
00126  */
00127 void BlurPlugin::render( const OFX::RenderArguments& args )
00128 {
00129         doGilRender<BlurProcess>( *this, args );
00130 }
00131 
00132 }
00133 }
00134 }