TuttleOFX  1
ColorSuppressPlugin.cpp
Go to the documentation of this file.
00001 #include "ColorSuppressPlugin.hpp"
00002 #include "ColorSuppressProcess.hpp"
00003 #include "ColorSuppressDefinitions.hpp"
00004 
00005 #include <tuttle/common/utils/global.hpp>
00006 
00007 #include <ofxsImageEffect.h>
00008 #include <ofxsMultiThread.h>
00009 
00010 #include <boost/gil/gil_all.hpp>
00011 
00012 
00013 namespace tuttle {
00014 namespace plugin {
00015 namespace colorSuppress {
00016 
00017 using namespace boost::gil;
00018 
00019 ColorSuppressPlugin::ColorSuppressPlugin( OfxImageEffectHandle handle )
00020 : ImageEffectGilPlugin( handle )
00021 {
00022         _paramApplyOn = fetchChoiceParam( kParamApplyOn );
00023         _paramRedRate = fetchDoubleParam( kParamRedSuppressRate );
00024         _paramGreenRate = fetchDoubleParam( kParamGreenSuppressRate );
00025         _paramBlueRate = fetchDoubleParam( kParamBlueSuppressRate );
00026         _paramCyanRate = fetchDoubleParam( kParamCyanSuppressRate );
00027         _paramMagentaRate = fetchDoubleParam( kParamMagentaSuppressRate );
00028         _paramYellowRate = fetchDoubleParam( kParamYellowSuppressRate );
00029         _paramPreserveLuma = fetchBooleanParam( kParamPreserveLuma );
00030         _paramObeyAlpha = fetchBooleanParam( kParamObeyAlpha );
00031 }
00032 
00033 ColorSuppressProcessParams ColorSuppressPlugin::getProcessParams() const
00034 {
00035         ColorSuppressProcessParams params;
00036 
00037         params.output = static_cast<EOutputType>(_paramApplyOn->getValue());
00038         params.red = _paramRedRate->getValue();
00039         params.blue = _paramBlueRate->getValue();
00040         params.green = _paramGreenRate->getValue();
00041         params.cyan = _paramCyanRate->getValue();
00042         params.magenta = _paramMagentaRate->getValue();
00043         params.yellow = _paramYellowRate->getValue();
00044         params.preserveLuma = _paramPreserveLuma->getValue();
00045         params.obeyAlpha = _paramObeyAlpha->getValue();
00046         return params;
00047 }
00048 
00049 /**
00050  * @brief The overridden render function
00051  * @param[in]   args     Rendering parameters
00052  */
00053 void ColorSuppressPlugin::render( const OFX::RenderArguments &args )
00054 {
00055     // instantiate the render code based on the pixel depth of the dst clip
00056     const OFX::EBitDepth dstBitDepth = _clipDst->getPixelDepth( );
00057     const OFX::EPixelComponent dstComponents = _clipDst->getPixelComponents( );
00058 
00059     // do the rendering
00060     if( dstComponents == OFX::ePixelComponentRGBA )
00061     {
00062         switch( dstBitDepth )
00063         {
00064             case OFX::eBitDepthUByte :
00065             {
00066                                 BOOST_THROW_EXCEPTION( exception::BitDepthMismatch()
00067                                         << exception::user( "Colorsuppress: BitDepthCustom not supported" ) );
00068                 break;
00069             }
00070             case OFX::eBitDepthUShort :
00071             {
00072                                 BOOST_THROW_EXCEPTION( exception::BitDepthMismatch()
00073                                         << exception::user( "Colorsuppress: BitDepthCustom not supported" ) );
00074                 break;
00075             }
00076             case OFX::eBitDepthFloat :
00077             {
00078                                 doGilRender<ColorSuppressProcess, false, boost::gil::rgba_layout_t, boost::gil::bits32f>( *this, args );
00079                 break;
00080             }
00081             case OFX::eBitDepthNone :
00082             case OFX::eBitDepthCustom :
00083                                 BOOST_THROW_EXCEPTION( exception::BitDepthMismatch()
00084                                         << exception::user( "Colorsuppress: BitDepthCustom not recognize" ) );
00085                 return;
00086         }
00087     }
00088 }
00089 
00090 void ColorSuppressPlugin::changedParam( const OFX::InstanceChangedArgs &args, const std::string &paramName )
00091 {
00092     if( paramName == kParamApplyOn )
00093     {
00094                 switch( getOutputType() )
00095                 {
00096                         case eOutputTypeImage:
00097                         case eOutputTypeAlphaImage:
00098                                 _paramPreserveLuma->setEnabled( true );
00099                                 break;
00100                         case eOutputTypeAlpha:
00101                                 _paramPreserveLuma->setEnabled( false );
00102                                 break;
00103                 }
00104     }
00105 }
00106 
00107 }
00108 }
00109 }
00110 
00111