TuttleOFX  1
TuttleOFX/libraries/tuttle/src/tuttle/plugin/context/GeneratorPlugin.cpp
Go to the documentation of this file.
00001 #include "GeneratorPlugin.hpp"
00002 #include <boost/numeric/conversion/cast.hpp>
00003 
00004 namespace tuttle {
00005 namespace plugin {
00006 
00007 using boost::numeric_cast;
00008 
00009 GeneratorPlugin::GeneratorPlugin( OfxImageEffectHandle handle )
00010         : OFX::ImageEffect( handle )
00011 {
00012         _clipSrc                = fetchClip         ( kOfxImageEffectSimpleSourceClipName );
00013         _clipDst                = fetchClip         ( kOfxImageEffectOutputClipName );
00014         _paramExplicitConv      = fetchChoiceParam  ( kParamGeneratorExplicitConversion );
00015         _paramComponents        = fetchChoiceParam  ( kTuttlePluginChannel );
00016 
00017         _paramMode              = fetchChoiceParam  ( kParamMode );
00018         _paramFormat            = fetchChoiceParam  ( kParamFormat );
00019         _paramSize              = fetchInt2DParam   ( kParamSize );
00020         _paramSizeWidth         = fetchIntParam     ( kParamSizeWidth );
00021         _paramSizeHeight        = fetchIntParam     ( kParamSizeHeight );
00022         _paramSizeOrientation   = fetchChoiceParam  ( kParamSizeOrientation );
00023         _paramSizeSpecificRatio = fetchBooleanParam ( kParamSizeSpecificRatio );
00024         _paramSizeRatioValue    = fetchDoubleParam  ( kParamSizeRatioValue );
00025 
00026         updateVisibleTools();
00027 }
00028 
00029 void GeneratorPlugin::updateVisibleTools()
00030 {
00031         OFX::InstanceChangedArgs args( this->timeLineGetTime() );
00032         changedParam( args, kParamMode );
00033         //changedParam( args, kParamSizeKeepRatio );
00034         changedParam( args, kParamSizeOrientation );
00035 }
00036 
00037 GeneratorPlugin::~GeneratorPlugin()
00038 {}
00039 
00040 void GeneratorPlugin::changedParam( const OFX::InstanceChangedArgs& args, const std::string& paramName )
00041 {
00042         if( paramName == kParamMode )
00043         {
00044                 switch( _paramMode->getValue() )
00045                 {
00046                         case eParamModeFormat:
00047                         {
00048                                 _paramSize              -> setIsSecretAndDisabled( true );
00049                                 _paramSizeWidth         -> setIsSecretAndDisabled( true );
00050                                 _paramSizeHeight        -> setIsSecretAndDisabled( true );
00051                                 _paramSizeOrientation   -> setIsSecretAndDisabled( true );
00052                                 _paramSizeSpecificRatio -> setIsSecretAndDisabled( true );
00053                                 _paramSizeRatioValue    -> setIsSecretAndDisabled( true );
00054 
00055                                 _paramFormat            -> setIsSecretAndDisabled( false );
00056                                 break;
00057                         }
00058                         case eParamModeSize:
00059                         {
00060                                 const bool                  specificRatio   = _paramSizeSpecificRatio->getValue();
00061                                 const EParamSizeOrientation orientation = static_cast<EParamSizeOrientation>(_paramSizeOrientation->getValue());
00062 
00063                                 _paramFormat            -> setIsSecretAndDisabled( true );
00064                                 _paramSizeSpecificRatio -> setIsSecretAndDisabled( false );
00065 
00066                                 _paramSizeWidth         -> setIsSecretAndDisabled( ! specificRatio || orientation != eParamSizeOrientationX );
00067                                 _paramSizeHeight        -> setIsSecretAndDisabled( ! specificRatio || orientation != eParamSizeOrientationY );
00068                                 _paramSizeOrientation   -> setIsSecretAndDisabled( ! specificRatio );
00069                                 _paramSizeRatioValue    -> setIsSecretAndDisabled( ! specificRatio );
00070 
00071                                 _paramSize              -> setIsSecretAndDisabled( specificRatio );
00072                                 break;
00073                         }
00074                 }
00075         }
00076         else if( paramName == kParamFormat && args.reason == OFX::eChangeUserEdit )
00077         {
00078                 std::size_t width  = 0;
00079                 std::size_t height = 0;
00080                 getFormatResolution( static_cast<EParamFormat>(_paramFormat->getValue()), width, height );
00081 
00082                 _paramMode            -> setValue( eParamModeFormat );
00083                 _paramSize            -> setValue( numeric_cast<int>(width), numeric_cast<int>(height) );
00084                 _paramSizeWidth       -> setValue( numeric_cast<int>(width) );
00085                 _paramSizeHeight      -> setValue( numeric_cast<int>(height) );
00086         }
00087         else if( paramName == kParamSize && args.reason == OFX::eChangeUserEdit )
00088         {
00089                 const OfxPointI s = _paramSize->getValue();
00090 
00091                 _paramMode->setValue( eParamModeSize );
00092                 _paramSizeWidth       -> setValue( s.x );
00093                 _paramSizeHeight      -> setValue( s.y );
00094         }
00095         else if( paramName == kParamSizeSpecificRatio && args.reason == OFX::eChangeUserEdit )
00096         {
00097                 const bool                  specificRatio   = _paramSizeSpecificRatio->getValue();
00098                 const EParamSizeOrientation orientation = static_cast<EParamSizeOrientation>(_paramSizeOrientation->getValue());
00099 
00100                 _paramSizeWidth       -> setIsSecretAndDisabled( ! specificRatio || orientation != eParamSizeOrientationX );
00101                 _paramSizeHeight      -> setIsSecretAndDisabled( ! specificRatio || orientation != eParamSizeOrientationY );
00102                 _paramSizeOrientation -> setIsSecretAndDisabled( ! specificRatio );
00103                 _paramSizeRatioValue  -> setIsSecretAndDisabled( ! specificRatio );
00104                 _paramSize            -> setIsSecretAndDisabled( specificRatio );
00105         }
00106         else if( paramName == kParamSizeOrientation && args.reason == OFX::eChangeUserEdit )
00107         {
00108                 const bool                  specificRatio   = _paramSizeSpecificRatio->getValue();
00109                 const EParamSizeOrientation orientation = static_cast<EParamSizeOrientation>(_paramSizeOrientation->getValue());
00110 
00111                 _paramSizeWidth       -> setIsSecretAndDisabled( ! specificRatio || orientation != eParamSizeOrientationX );
00112                 _paramSizeHeight      -> setIsSecretAndDisabled( ! specificRatio || orientation != eParamSizeOrientationY );
00113         }
00114         else if( paramName == kParamSizeWidth && args.reason == OFX::eChangeUserEdit )
00115         {
00116                 _paramMode              -> setValue( eParamModeSize );
00117                 _paramSizeSpecificRatio -> setValue( true );
00118                 _paramSizeRatioValue    -> setIsSecretAndDisabled( false );
00119                 _paramSizeOrientation   -> setValue( eParamSizeOrientationX );
00120 
00121                 _paramSize              -> setValue( _paramSizeWidth->getValue(), _paramSize->getValue().y );
00122         }
00123         else if( paramName == kParamSizeHeight && args.reason == OFX::eChangeUserEdit )
00124         {
00125                 _paramMode              -> setValue( eParamModeSize );
00126                 _paramSizeSpecificRatio -> setValue( true );
00127                 _paramSizeRatioValue    -> setIsSecretAndDisabled( false );
00128                 _paramSizeOrientation   -> setValue( eParamSizeOrientationY );
00129 
00130                 _paramSize              -> setValue( _paramSize->getValue().x, _paramSizeHeight->getValue() );
00131         }
00132 }
00133 
00134 void GeneratorPlugin::getClipPreferences( OFX::ClipPreferencesSetter& clipPreferences )
00135 {
00136         clipPreferences.setOutputFrameVarying( true );
00137 
00138         switch( getExplicitConversion() )
00139         {
00140                 case eParamGeneratorExplicitConversionByte:
00141                 {
00142                         clipPreferences.setClipBitDepth( *this->_clipDst, OFX::eBitDepthUByte );
00143                         break;
00144                 }
00145                 case eParamGeneratorExplicitConversionShort:
00146                 {
00147                         clipPreferences.setClipBitDepth( *this->_clipDst, OFX::eBitDepthUShort );
00148                         break;
00149                 }
00150                 case eParamGeneratorExplicitConversionFloat:
00151                 {
00152                         clipPreferences.setClipBitDepth( *this->_clipDst, OFX::eBitDepthFloat );
00153                         break;
00154                 }
00155                 case eParamGeneratorExplicitConversionAuto:
00156                 {
00157                         if( _clipSrc->isConnected() )
00158                         {
00159                                 switch( _clipSrc->getPixelDepth() )
00160                                 {
00161                                         case OFX::eBitDepthUByte:
00162                                                 clipPreferences.setClipBitDepth( *this->_clipDst, OFX::eBitDepthUByte );
00163                                                 break;
00164                                         case OFX::eBitDepthUShort:
00165                                                 clipPreferences.setClipBitDepth( *this->_clipDst, OFX::eBitDepthUShort );
00166                                                 break;
00167                                         case OFX::eBitDepthFloat:
00168                                                 clipPreferences.setClipBitDepth( *this->_clipDst, OFX::eBitDepthFloat );
00169                                                 break;
00170                                         case OFX::eBitDepthCustom:
00171                                         case OFX::eBitDepthNone:
00172                                                 break;
00173                                 }
00174                         }
00175                         else
00176                         {
00177                                 clipPreferences.setClipBitDepth( *this->_clipDst, OFX::eBitDepthFloat );
00178                         }
00179                 }
00180         }
00181 
00182         if( _clipSrc->isConnected() )
00183         {
00184                 switch( _clipSrc->getPixelComponents() )
00185                 {
00186                         case OFX::ePixelComponentAlpha:
00187                                 clipPreferences.setClipComponents( *this->_clipDst, OFX::ePixelComponentAlpha );
00188                                 break;
00189                         case OFX::ePixelComponentRGB:
00190                                 clipPreferences.setClipComponents( *this->_clipDst, OFX::ePixelComponentRGB );
00191                                 break;
00192                         case OFX::ePixelComponentRGBA:
00193                                 clipPreferences.setClipComponents( *this->_clipDst, OFX::ePixelComponentRGBA );
00194                                 break;
00195                         default: break;
00196                 }
00197                 clipPreferences.setPixelAspectRatio( *this->_clipDst, _clipSrc->getPixelAspectRatio() );
00198         }
00199         else
00200         {
00201                 switch( _paramComponents->getValue() )
00202                 {
00203                         case eParamGeneratorComponentsAlpha:
00204                         {
00205                                 clipPreferences.setClipComponents( *this->_clipDst, OFX::ePixelComponentAlpha );
00206                                 break;
00207                         }
00208                         case eParamGeneratorComponentsRGB:
00209                         {
00210                                 clipPreferences.setClipComponents( *this->_clipDst, OFX::ePixelComponentRGB );
00211                                 break;
00212                         }
00213                         case eParamGeneratorComponentsRGBA:
00214                         {
00215                                 clipPreferences.setClipComponents( *this->_clipDst, OFX::ePixelComponentRGBA );
00216                                 break;
00217                         }
00218                 }
00219                 clipPreferences.setPixelAspectRatio( *this->_clipDst, 1.0 );
00220         }
00221 }
00222 
00223 bool GeneratorPlugin::getTimeDomain( OfxRangeD& range )
00224 {
00225         if( _clipSrc->isConnected() )
00226                 return false;
00227         range.min = kOfxFlagInfiniteMin;
00228         range.max = kOfxFlagInfiniteMax;
00229         return true;
00230 }
00231 
00232 bool GeneratorPlugin::getRegionOfDefinition( const OFX::RegionOfDefinitionArguments& args, OfxRectD& rod )
00233 {
00234         using namespace boost::gil;
00235 
00236         if( _clipSrc->isConnected() )
00237         {
00238                 using namespace boost::gil;
00239         
00240                 const OfxRectD srcRod = _clipSrc->getCanonicalRod( args.time );
00241                 
00242                 rod = srcRod;
00243                 return true;
00244         }
00245         
00246         switch(_paramMode->getValue())
00247         {
00248                 case eParamModeFormat :
00249                 {
00250                         std::size_t width = 0;
00251                         std::size_t height = 0;
00252                         getFormatResolution( static_cast<EParamFormat>(_paramFormat->getValue()), width, height );
00253                         rod.x1 = 0;
00254                         rod.y1 = 0;
00255                         rod.x2 = width > 0 ? width : 0;
00256                         rod.y2 = height > 0 ? height : 0;
00257 
00258                         return true;
00259                 }
00260                 case eParamModeSize :
00261                 {
00262                         std::size_t sizex = 0;
00263                         std::size_t sizey = 0;
00264                         if( _paramSizeSpecificRatio->getValue() )
00265                         {
00266                                 if( _paramSizeOrientation->getValue() == eParamSizeOrientationX )
00267                                 {
00268                                         sizex   = _paramSizeWidth->getValue();
00269                                         sizey   = sizex / _paramSizeRatioValue->getValue();
00270                                 }
00271                                 else // direction == eParamSizeY
00272                                 {
00273                                         sizey   = _paramSizeHeight->getValue();
00274                                         sizex   = _paramSizeRatioValue->getValue() * sizey;
00275                                 }
00276                         }
00277                         else
00278                         {
00279                                 const OfxPointI s = _paramSize->getValue();
00280                                 sizex = s.x;
00281                                 sizey = s.y;
00282                         }
00283 
00284                         rod.x1 = 0;
00285                         rod.y1 = 0;
00286                         rod.x2 = sizex > 0 ? sizex : 0;
00287                         rod.y2 = sizey > 0 ? sizey : 0;
00288 
00289                         return true;
00290                 }
00291         }
00292 
00293         return false;
00294 }
00295 
00296 }
00297 }