TuttleOFX  1
BasicKeyerPlugin.cpp
Go to the documentation of this file.
00001 #include "BasicKeyerPlugin.hpp"
00002 #include "BasicKeyerProcess.hpp"
00003 #include "BasicKeyerAlgorithm.hpp"
00004 #include "BasicKeyerDefinitions.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 //#include <boost/algorithm/string/classification.hpp>
00013 
00014 namespace tuttle {
00015 namespace plugin {
00016 namespace basicKeyer {
00017 
00018 using namespace boost::gil;
00019 
00020 BasicKeyerPlugin::BasicKeyerPlugin( OfxImageEffectHandle handle )
00021         : ImageEffectGilPlugin( handle )
00022 {
00023         _paramMode     = fetchChoiceParam( kParamMode );
00024         _paramNbPoints = fetchIntParam( kParamNbPoints );
00025 
00026         _paramPoints.reserve( kMaxNbPoints );
00027         _paramColors.reserve( kMaxNbPoints );
00028         for( unsigned int i = 0; i < kMaxNbPoints; ++i )
00029         {
00030                 _paramPoints.push_back( fetchDouble2DParam( getPointParamName( i ) ) );
00031                 _paramColors.push_back( fetchRGBAParam( getColorParamName( i ) ) );
00032         }
00033 
00034         changedParam( _instanceChangedArgs, kParamNbPoints ); // init IsSecret property for each point/color param
00035 }
00036 
00037 template<class View>
00038 BasicKeyerProcessParams<View> BasicKeyerPlugin::getProcessParams() const
00039 {
00040         BasicKeyerProcessParams<View> params;
00041 
00042         Double2DParamVector::const_iterator it_point = _paramPoints.begin();
00043         RGBAParamVector::const_iterator it_color     = _paramColors.begin();
00044         unsigned int nbPoints                        = boost::numeric_cast<unsigned int>( _paramNbPoints->getValue() );
00045         for( unsigned int i = 0;
00046              i < nbPoints;
00047              ++i, ++it_point, ++it_color )
00048         {
00049                 OfxPointD p = ( *it_point )->getValue();
00050                 params._points.push_back( Point2( p.x, p.y ) );
00051                 OfxRGBAColourD c = ( *it_color )->getValue();
00052                 params._colors.push_back( rgba32f_pixel_t( c.r, c.g, c.b, c.a ) );
00053         }
00054         return params;
00055 }
00056 
00057 /*
00058    void BasicKeyerPlugin::process()
00059    {
00060     OFX::EPixelComponent dstComponents = _clipDst->getPixelComponents( );
00061     switch( dstComponents )
00062     {
00063         case OFX::ePixelComponentRGBA:
00064             processComponents<rgba_t>();
00065             return;
00066         case OFX::ePixelComponentAlpha:
00067             processComponents<gray_t>();
00068             return;
00069         case OFX::ePixelComponentCustom:
00070         case OFX::ePixelComponentNone:
00071             return;
00072     }
00073    }
00074 
00075    template<typename ColorSpace>
00076    void BasicKeyerPlugin::processComponents()
00077    {
00078     OFX::EBitDepth dstBitDepth = _clipDst->getPixelDepth( );
00079     switch( dstBitDepth )
00080     {
00081         case OFX::eBitDepthUByte :
00082         {
00083             processBitDepth<ColorSpace, bits8_t> p( *this );
00084             return;
00085         }
00086         case OFX::eBitDepthUShort :
00087         {
00088             processBitDepth<ColorSpace, bits16_t> p( *this );
00089             return;
00090         }
00091         case OFX::eBitDepthFloat :
00092         {
00093             processBitDepth<ColorSpace, bits32f_t> p( *this );
00094             return;
00095         }
00096         case OFX::eBitDepthNone :
00097             TUTTLE_LOG_FATALERROR( "BitDepthNone not recognize." );
00098             return;
00099         case OFX::eBitDepthCustom :
00100             TUTTLE_LOG_FATALERROR( "BitDepthCustom not recognize." );
00101             return;
00102     }
00103    }
00104 
00105    template<typename ColorSpace, typename BitDepth>
00106    void BasicKeyerPlugin::processBitDepth()
00107    {
00108     typedef pixel<BitDepth, layout<ColorSpace> > Pixel;
00109     typedef view_from_pixel<Pixel>::type View;
00110 
00111     BasicKeyerProcess<View> p( *this );
00112     p.setupAndProcess( args );
00113    }
00114  */
00115 
00116 /**
00117  * @brief The overridden render function
00118  * @param[in]   args     Rendering parameters
00119  */
00120 void BasicKeyerPlugin::render( const OFX::RenderArguments& args )
00121 {
00122         // instantiate the render code based on the pixel depth of the dst clip
00123         OFX::EBitDepth bitDepth         = _clipDst->getPixelDepth();
00124         OFX::EPixelComponent components = _clipDst->getPixelComponents();
00125 
00126         switch( components )
00127         {
00128                 case OFX::ePixelComponentRGBA:
00129                 {
00130                         doGilRender<BasicKeyerProcess, false, boost::gil::rgba_layout_t>( *this, args, bitDepth );
00131                         return;
00132                 }
00133                 case OFX::ePixelComponentRGB:
00134                 case OFX::ePixelComponentAlpha:
00135                 case OFX::ePixelComponentCustom:
00136                 case OFX::ePixelComponentNone:
00137                 {
00138                         BOOST_THROW_EXCEPTION( exception::Unsupported()
00139                                 << exception::user() + "Pixel components (" + mapPixelComponentEnumToString(components) + ") not supported by the plugin." );
00140                 }
00141         }
00142         BOOST_THROW_EXCEPTION( exception::Unknown() );
00143 }
00144 
00145 void BasicKeyerPlugin::changedParam( const OFX::InstanceChangedArgs& args, const std::string& paramName )
00146 {
00147         if( paramName == kParamNbPoints )
00148         {
00149                 const unsigned int nbPoints            = boost::numeric_cast<unsigned int>( _paramNbPoints->getValue() );
00150                 Double2DParamVector::iterator it_point = _paramPoints.begin();
00151                 RGBAParamVector::iterator it_color     = _paramColors.begin();
00152                 for( unsigned int i = 0; i < nbPoints; ++i, ++it_point, ++it_color )
00153                 {
00154                         ( *it_point )->setIsSecret( false );
00155                         ( *it_color )->setIsSecret( false );
00156                 }
00157                 for( unsigned int i = nbPoints; i < kMaxNbPoints; ++i, ++it_point, ++it_color )
00158                 {
00159                         ( *it_point )->setIsSecret( true );
00160                         ( *it_color )->setIsSecret( true );
00161                 }
00162                 changedParam( _instanceChangedArgs, kParamMode );
00163         }
00164         else if( paramName == kParamMode )
00165         {
00166                 const unsigned int nbPoints            = boost::numeric_cast<unsigned int>( _paramNbPoints->getValue() );
00167                 EParamMode mode                        = static_cast<EParamMode>( _paramMode->getValue() );
00168                 Double2DParamVector::iterator it_point = _paramPoints.begin();
00169                 RGBAParamVector::iterator it_color     = _paramColors.begin();
00170                 switch( mode )
00171                 {
00172                         case eParamModeColor:
00173                                 for( unsigned int i = 0; i < kMaxNbPoints; ++i, ++it_point, ++it_color )
00174                                 {
00175                                         ( *it_point )->setIsSecret( true );
00176                                         ( *it_color )->setEnabled( true );
00177                                 }
00178                                 break;
00179                         case eParamModePosition:
00180                                 for( unsigned int i = 0; i < kMaxNbPoints; ++i, ++it_color )
00181                                 {
00182                                         ( *it_color )->setEnabled( false );
00183                                 }
00184                                 for( unsigned int i = 0; i < nbPoints; ++i, ++it_point )
00185                                 {
00186                                         ( *it_point )->setIsSecret( false );
00187                                 }
00188                                 break;
00189                 }
00190         }
00191         /*
00192         else if( boost::starts_with( paramName, kParamPoint ) )
00193         {
00194                 try
00195                 {
00196                         unsigned int n            = boost::lexical_cast<unsigned int>( paramName.c_str() + kParamPoint.size() );
00197                         OFX::Double2DParam* param = _paramPoints[n];
00198                         OfxPointD p               = param->getValue();
00199                         if( n < 2 )
00200                         {
00201                                 // A, B
00202                         }
00203                         else
00204                         {
00205                                 //
00206                         }
00207                 }
00208                 catch( boost::bad_lexical_cast& )
00209                 {}
00210         }
00211         */
00212 
00213 }
00214 
00215 }
00216 }
00217 }