TuttleOFX  1
IdKeyerPlugin.cpp
Go to the documentation of this file.
00001 #include "IdKeyerPlugin.hpp"
00002 #include "IdKeyerProcess.hpp"
00003 #include "IdKeyerAlgorithm.hpp"
00004 #include "IdKeyerDefinitions.hpp"
00005 
00006 #include <tuttle/plugin/global.hpp>
00007 #include <ofxsImageEffect.h>
00008 #include <ofxsMultiThread.h>
00009 
00010 #include <boost/gil/gil_all.hpp>
00011 #include <boost/algorithm/string/predicate.hpp>
00012 
00013 namespace tuttle {
00014 namespace plugin {
00015 namespace idKeyer {
00016 
00017 using namespace terry;
00018 
00019 IdKeyerPlugin::IdKeyerPlugin( OfxImageEffectHandle handle )
00020         : ImageEffectGilPlugin( handle )
00021 {
00022         _paramNbPoints  = fetchIntParam( kParamNbPoints );
00023         _paramUseAlpha  = fetchBooleanParam( kParamUseAlpha );
00024         _paramTolerance = fetchDoubleParam( kParamTolerance );
00025         
00026         _paramColors.reserve( kMaxNbPoints );
00027         for( size_t i = 0; i < kMaxNbPoints; ++i )
00028         {
00029                 _paramColors.push_back( fetchRGBAParam( getColorParamName( i ) ) );
00030         }
00031 
00032         changedParam( _instanceChangedArgs, kParamNbPoints );
00033 }
00034 
00035 template<class View>
00036 IdKeyerProcessParams<View> IdKeyerPlugin::getProcessParams() const
00037 {
00038         IdKeyerProcessParams<View> params;
00039 
00040         params._useAlpha  = _paramUseAlpha->getValue();
00041         params._tolerance = _paramTolerance->getValue();
00042         
00043         RGBAParamVector::const_iterator it_color     = _paramColors.begin();
00044 
00045         size_t nbPoints = boost::numeric_cast<size_t>( _paramNbPoints->getValue() );
00046 
00047         for( size_t i = 0; i < nbPoints; ++i, ++it_color )
00048         {
00049                 OfxRGBAColourD c = ( *it_color )->getValue();
00050                 params._colors.push_back( rgba32f_pixel_t( c.r, c.g, c.b, c.a ) );
00051 
00052                 //TUTTLE_LOG_WARNING( "key color " <<  c.r << ", " <<  c.g << ", " <<  c.b << ", " << c.a );
00053         }
00054         return params;
00055 }
00056 
00057 /**
00058  * @brief The overridden render function
00059  * @param[in]   args     Rendering parameters
00060  */
00061 void IdKeyerPlugin::render( const OFX::RenderArguments& args )
00062 {
00063         // instantiate the render code based on the pixel depth of the dst clip
00064         OFX::EBitDepth bitDepth         = _clipDst->getPixelDepth();
00065         OFX::EPixelComponent components = _clipDst->getPixelComponents();
00066 
00067         switch( components )
00068         {
00069                 case OFX::ePixelComponentRGBA:
00070                 {
00071                         doGilRender<IdKeyerProcess, false, boost::gil::rgba_layout_t>( *this, args, bitDepth );
00072                         return;
00073                 }
00074                 case OFX::ePixelComponentRGB:
00075                 case OFX::ePixelComponentAlpha:
00076                 case OFX::ePixelComponentCustom:
00077                 case OFX::ePixelComponentNone:
00078                 {
00079                         BOOST_THROW_EXCEPTION( exception::Unsupported()
00080                                 << exception::user() + "Pixel components (" + mapPixelComponentEnumToString(components) + ") not supported by the plugin." );
00081                 }
00082         }
00083         BOOST_THROW_EXCEPTION( exception::Unknown() );
00084 }
00085 
00086 void IdKeyerPlugin::changedParam( const OFX::InstanceChangedArgs& args, const std::string& paramName )
00087 {
00088         if( paramName == kParamNbPoints )
00089         {
00090                 const size_t              nbPoints = boost::numeric_cast<size_t>( _paramNbPoints->getValue() );
00091                 RGBAParamVector::iterator it_color = _paramColors.begin();
00092                 for( size_t i = 0; i < kMaxNbPoints; ++i, ++it_color )
00093                 {
00094                         ( *it_color )->setIsSecret( i < nbPoints ? false : true );
00095                 }
00096         }
00097 }
00098 
00099 }
00100 }
00101 }