TuttleOFX
1
|
00001 #ifndef _TUTTLE_HOST_IMAGEEFFECTNODE_HPP_ 00002 #define _TUTTLE_HOST_IMAGEEFFECTNODE_HPP_ 00003 00004 #include "INode.hpp" 00005 00006 #include <tuttle/host/attribute/Param.hpp> 00007 #include <tuttle/host/attribute/ClipImage.hpp> 00008 #include <tuttle/host/graph/ProcessVertexData.hpp> 00009 #include <tuttle/host/graph/ProcessVertexAtTimeData.hpp> 00010 00011 #include <tuttle/host/ofx/OfxhImageEffectNode.hpp> 00012 00013 #include <boost/numeric/conversion/cast.hpp> 00014 00015 namespace tuttle { 00016 namespace host { 00017 00018 class ImageEffectNode : public INode 00019 , public ofx::imageEffect::OfxhImageEffectNode 00020 { 00021 public: 00022 typedef ImageEffectNode This; 00023 00024 public: 00025 ImageEffectNode( ofx::imageEffect::OfxhImageEffectPlugin& plugin, 00026 ofx::imageEffect::OfxhImageEffectNodeDescriptor& desc, 00027 const std::string& context ); 00028 00029 ImageEffectNode( const ImageEffectNode& other ); 00030 00031 ~ImageEffectNode(); 00032 00033 std::string getLabel() const { return ofx::imageEffect::OfxhImageEffectNodeBase::getLabel(); } 00034 const std::string& getName() const { return ofx::imageEffect::OfxhImageEffectNodeBase::getName(); } 00035 void setName( const std::string& name ) { return ofx::imageEffect::OfxhImageEffectNodeBase::setName(name); } 00036 std::size_t getNbParams() const { return ofx::attribute::OfxhParamSet::getNbParams(); } 00037 const ofx::attribute::OfxhParam& getParam( const std::string& name ) const { return ofx::attribute::OfxhParamSet::getParam( name ); } 00038 ofx::attribute::OfxhParam& getParam( const std::string& name ) { return ofx::attribute::OfxhParamSet::getParam( name ); } 00039 const ofx::attribute::OfxhParam& getParamByScriptName( const std::string& name, const bool acceptPartialName = false ) const { return ofx::attribute::OfxhParamSet::getParamByScriptName( name, acceptPartialName ); } 00040 ofx::attribute::OfxhParam& getParamByScriptName( const std::string& name, const bool acceptPartialName = false ) { return ofx::attribute::OfxhParamSet::getParamByScriptName( name, acceptPartialName ); } 00041 const ofx::attribute::OfxhParam& getParam( const std::size_t index ) const { return ofx::attribute::OfxhParamSet::getParam( index ); } 00042 ofx::attribute::OfxhParam& getParam( const std::size_t index ) { return ofx::attribute::OfxhParamSet::getParam( index ); } 00043 00044 const ofx::property::OfxhSet& getProperties() const { return ofx::imageEffect::OfxhImageEffectNodeBase::getProperties(); } 00045 ofx::property::OfxhSet& getEditableProperties() { return ofx::imageEffect::OfxhImageEffectNodeBase::getEditableProperties(); } 00046 00047 std::vector<int> getVersion() const 00048 { 00049 // don't works on many plugins 00050 //return getProperties().fetchIntProperty( kOfxPropVersion ).getValues(); 00051 // so get values from plugin 00052 std::vector<int> v; 00053 v.push_back( getDescriptor().getPlugin().getVersionMajor() ); 00054 v.push_back( getDescriptor().getPlugin().getVersionMinor() ); 00055 return v; 00056 } 00057 00058 ImageEffectNode* clone() const 00059 { 00060 return new ImageEffectNode( *this ); 00061 } 00062 00063 bool operator==( const INode& other ) const; 00064 bool operator==( const ImageEffectNode& other ) const; 00065 00066 const ENodeType getNodeType() const { return eNodeTypeImageEffect; } 00067 00068 void connect( const INode& sourceEffect, attribute::Attribute& attr ); 00069 00070 attribute::ClipImage& getClip( const std::string& name, const bool acceptPartialName = false ) { return dynamic_cast<attribute::ClipImage&>( ofx::attribute::OfxhClipImageSet::getClip( name, acceptPartialName ) ); } 00071 const attribute::ClipImage& getClip( const std::string& name, const bool acceptPartialName = false ) const { return dynamic_cast<const attribute::ClipImage&>( ofx::attribute::OfxhClipImageSet::getClip( name, acceptPartialName ) ); } 00072 00073 attribute::ClipImage& getOutputClip() { return getClip( kOfxImageEffectOutputClipName ); } 00074 const attribute::ClipImage& getOutputClip() const { return getClip( kOfxImageEffectOutputClipName ); } 00075 00076 attribute::Attribute& getAttribute( const std::string& name ) { return getClip( name ); } 00077 attribute::Attribute& getSingleInputAttribute(); 00078 00079 const attribute::Attribute& getSingleInputAttribute() const { return const_cast<ImageEffectNode*>( this )->getSingleInputAttribute(); } 00080 00081 ofx::attribute::OfxhParamSet& getParamSet() { return *this; } 00082 const ofx::attribute::OfxhParamSet& getParamSet() const { return *this; } 00083 00084 ofx::attribute::OfxhClipImageSet& getClipImageSet() { return *this; } 00085 const ofx::attribute::OfxhClipImageSet& getClipImageSet() const { return *this; } 00086 00087 std::size_t getLocalHashAtTime( const OfxTime time ) const; 00088 00089 OfxRectD getRegionOfDefinition( const OfxTime time ) const 00090 { 00091 return getData(time)._apiImageEffect._renderRoD; 00092 } 00093 00094 OfxRangeD getTimeDomain() const 00095 { 00096 return getData()._timeDomain; 00097 } 00098 00099 void debugOutputImage( const OfxTime time ) const; 00100 00101 OfxRangeD getDefaultTimeDomain() const; 00102 00103 /// @group Implementation of INode virtual functions 00104 /// @{ 00105 OfxRangeD computeTimeDomain(); 00106 00107 void setup1(); 00108 void setup2_reverse(); 00109 void setup3(); 00110 00111 void beginSequence( graph::ProcessVertexData& vData ); 00112 00113 INode::ClipTimesSetMap getTimesNeeded( const OfxTime time ) const { return OfxhImageEffectNode::getFramesNeeded(time); } 00114 00115 void preProcess1( graph::ProcessVertexAtTimeData& vData ); 00116 void preProcess2_reverse( graph::ProcessVertexAtTimeData& vData ); 00117 00118 bool isIdentity( const graph::ProcessVertexAtTimeData& vData, std::string& clip, OfxTime& time ) const; 00119 void preProcess_infos( const graph::ProcessVertexAtTimeData& vData, const OfxTime time, graph::ProcessVertexAtTimeInfo& nodeInfos ) const; 00120 void process( graph::ProcessVertexAtTimeData& vData ); 00121 void postProcess( graph::ProcessVertexAtTimeData& vData ); 00122 00123 void endSequence( graph::ProcessVertexData& vData ); 00124 /// @} 00125 00126 std::ostream& print( std::ostream& os ) const; 00127 00128 friend std::ostream& operator<<( std::ostream& os, const This& v ); 00129 00130 00131 //////////////////////////////////////////////////////////////////////////////// 00132 //////////////////////////////////////////////////////////////////////////////// 00133 //////////////////////////////////////////////////////////////////////////////// 00134 // overridden for imageEffect::OfxhImageEffectNode 00135 00136 /// get default output fielding. This is passed into the clip prefs action 00137 /// and might be mapped (if the host allows such a thing) 00138 inline const std::string& getDefaultOutputFielding() const { return _defaultOutputFielding; } 00139 00140 /** 00141 * @return 1 to abort processing 00142 */ 00143 int abort(); 00144 00145 /** 00146 * Allocating memory using the memoryPool 00147 */ 00148 ofx::OfxhMemory* newMemoryInstance( size_t nBytes ); 00149 00150 /// make a clip 00151 ofx::attribute::OfxhClipImage* newClipImage( const ofx::attribute::OfxhClipImageDescriptor& descriptor ); 00152 00153 #ifndef SWIG 00154 /// vmessage 00155 void vmessage( const char* type, 00156 const char* id, 00157 const char* format, 00158 va_list args ) const OFX_EXCEPTION_SPEC; 00159 #endif 00160 00161 // The size of the current project in canonical coordinates. 00162 // The size of a project is a sub set of the kOfxImageEffectPropProjectExtent. For example a 00163 // project may be a PAL SD project, but only be a letter-box within that. The project size is 00164 // the size of this sub window. 00165 void getProjectSize( double& xSize, double& ySize ) const; 00166 00167 // The offset of the current project in canonical coordinates. 00168 // The offset is related to the kOfxImageEffectPropProjectSize and is the offset from the origin 00169 // of the project 'subwindow'. For example for a PAL SD project that is in letterbox form, the 00170 // project offset is the offset to the bottom left hand corner of the letter box. The project 00171 // offset is in canonical coordinates. 00172 void getProjectOffset( double& xOffset, double& yOffset ) const; 00173 00174 // The extent of the current project in canonical coordinates. 00175 // The extent is the size of the 'output' for the current project. See ProjectCoordinateSystems 00176 // for more infomation on the project extent. The extent is in canonical coordinates and only 00177 // returns the top right position, as the extent is always rooted at 0,0. For example a PAL SD 00178 // project would have an extent of 768, 576. 00179 void getProjectExtent( double& xSize, double& ySize ) const; 00180 00181 // The pixel aspect ratio of the current project 00182 double getProjectPixelAspectRatio() const; 00183 00184 // The pixel components type of the current project 00185 const std::string getProjectPixelComponentsType() const; 00186 00187 // The pixel bit depth of the current project 00188 const std::string getProjectBitDepth() const; 00189 00190 // The duration of the effect 00191 // This contains the duration of the plug-in effect, in frames. 00192 double getEffectDuration() const; 00193 00194 /// This is called whenever a param is changed by the plugin so that 00195 /// the recursive instanceChangedAction will be fed the correct frame 00196 double getFrameRecursive() const; 00197 00198 /// This is called whenever a param is changed by the plugin so that 00199 /// the recursive instanceChangedAction will be fed the correct 00200 /// renderScale 00201 void getRenderScaleRecursive( double& x, double& y ) const; 00202 00203 /// Create a parameter instance 00204 ofx::attribute::OfxhParam* newParam( const ofx::attribute::OfxhParamDescriptor& Descriptor ) OFX_EXCEPTION_SPEC; 00205 00206 //////////////////////////////////////////////////////////////////////////////// 00207 //////////////////////////////////////////////////////////////////////////////// 00208 //////////////////////////////////////////////////////////////////////////////// 00209 // overridden for Param::SetInstance 00210 00211 /// Triggered when the plug-in calls OfxParameterSuiteV1::paramEditBegin 00212 /// 00213 /// Client host code needs to implement this 00214 void editBegin( const std::string& name ) OFX_EXCEPTION_SPEC; 00215 00216 /// Triggered when the plug-in calls OfxParameterSuiteV1::paramEditEnd 00217 /// 00218 /// Client host code needs to implement this 00219 void editEnd() OFX_EXCEPTION_SPEC; 00220 00221 //////////////////////////////////////////////////////////////////////////////// 00222 //////////////////////////////////////////////////////////////////////////////// 00223 //////////////////////////////////////////////////////////////////////////////// 00224 // overridden for OfxhIProgress 00225 00226 /// Start doing progress. 00227 void progressStart( const std::string& message ); 00228 00229 /// finish yer progress 00230 void progressEnd(); 00231 00232 /// set the progress to some level of completion, 00233 /// returns true if you should abandon processing, false to continue 00234 bool progressUpdate( const double t ); 00235 00236 //////////////////////////////////////////////////////////////////////////////// 00237 //////////////////////////////////////////////////////////////////////////////// 00238 //////////////////////////////////////////////////////////////////////////////// 00239 // overridden for OfxhITimeLine 00240 00241 /// get the current time on the timeline. This is not necessarily the same 00242 /// time as being passed to an action (eg render) 00243 double timelineGetTime(); 00244 00245 /// set the timeline to a specific time 00246 void timelineGotoTime( double t ); 00247 00248 /// get the first and last times available on the effect's timeline 00249 void timelineGetBounds( double& t1, double& t2 ); 00250 00251 const OfxRangeD& getEffectFrameRange() const 00252 { 00253 return getData()._renderTimeRange; 00254 } 00255 00256 void beginSequenceRenderAction( OfxTime startFrame, 00257 OfxTime endFrame, 00258 double step, 00259 bool interactive, 00260 OfxPointD renderScale ) OFX_EXCEPTION_SPEC; 00261 00262 private: 00263 void checkClipsConnected() const; 00264 00265 void initComponents(); 00266 void initInputClipsPixelAspectRatio(); 00267 void initPixelAspectRatio(); 00268 void initInputClipsFps(); 00269 void initFps(); 00270 00271 void maximizeBitDepthFromReadsToWrites(); 00272 void maximizeBitDepthFromWritesToReads(); 00273 void coutBitDepthConnections() const; 00274 void validInputClipsConnections() const; 00275 00276 /// our clip is pretending to be progressive PAL SD, so return kOfxImageFieldNone 00277 std::string _defaultOutputFielding; 00278 00279 }; 00280 00281 } 00282 } 00283 00284 #endif