1 #ifndef _ofxsImageEffect_H_
2 #define _ofxsImageEffect_H_
3 /*
4 OFX Support Library, a library that skins the OFX plug-in API with C++ classes.
5 Copyright (C) 2004-2005 The Open Effects Association Ltd
6 Author Bruno Nicoletti bruno@thefoundry.co.uk
7 
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10 
11 * Redistributions of source code must retain the above copyright notice,
12 this list of conditions and the following disclaimer.
13 * Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16 * Neither the name The Open Effects Association Ltd, nor the names of its
17 contributors may be used to endorse or promote products derived from this
18 software without specific prior written permission.
19 
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
24 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
27 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 The Open Effects Association Ltd
32 1 Wardour St
33 London W1D 6PA
34 England
35 
36 
37 
38 */
39 
40 /** @file This file contains core code that wraps OFX 'objects' with C++ classes.
41 
42 This file only holds code that is visible to a plugin implementation, and so hides much
43 of the direct OFX objects and any library side only functions.
44 */
45 #include <map>
46 #include <string>
47 #include <sstream> // stringstream
48 #include <memory>
49 #include "ofxsParam.h"
50 #include "ofxsInteract.h"
51 #ifdef OFX_EXTENSIONS_VEGAS
52 #if defined(WIN32) || defined(WIN64)
53 #include "ofxsHWNDInteract.h"
54 #endif
55 #endif
56 #include "ofxsMessage.h"
57 #include "ofxProgress.h"
58 #include "ofxTimeLine.h"
59 #ifdef OFX_EXTENSIONS_VEGAS
60 #include "ofxSonyVegas.h"
61 #endif
62 #include "ofxParametricParam.h"
63 #ifdef OFX_EXTENSIONS_NUKE
64 #include "nuke/camera.h"
65 #include "nuke/fnOfxExtensions.h"
66 #include "nuke/fnPublicOfxExtensions.h"
67 #endif
68 #ifdef OFX_EXTENSIONS_TUTTLE
69 #include "tuttle/ofxReadWrite.h"
70 #endif
71 #ifdef OFX_EXTENSIONS_NATRON
72 #include "ofxNatron.h"
73 #endif
74 
75 /** @brief Nasty macro used to define empty protected copy ctors and assign ops */
76 #define mDeclareProtectedAssignAndCC(CLASS) \
77   CLASS &operator=(const CLASS &) {assert(false); return *this;}	\
78   CLASS(const CLASS &) {assert(false); }
79 #define mDeclareProtectedAssignAndCCBase(CLASS,BASE) \
80   CLASS &operator=(const CLASS &) {assert(false); return *this;}	\
81   CLASS(const CLASS &c) : BASE(c) {assert(false); }
82 
83 namespace OFX
84 {
85   namespace Private
86   {
87     OfxStatus mainEntryStr(const char    *actionRaw,
88       const void    *handleRaw,
89       OfxPropertySetHandle   inArgsRaw,
90       OfxPropertySetHandle   outArgsRaw,
91       const char* plugname);
92 
93     OfxStatus customParamInterpolationV1Entry(
94       const void*            handleRaw,
95       OfxPropertySetHandle   inArgsRaw,
96       OfxPropertySetHandle   outArgsRaw);
97   }
98 }
99 
100 
101 /** @brief The core 'OFX Support' namespace, used by plugin implementations. All code for these are defined in the common support libraries.
102 */
103 namespace OFX {
104   /** forward class declarations */
105   class ClipDescriptor;
106   class ImageEffectDescriptor;
107 
108   class Image;
109   class Clip;
110   class ImageEffect;
111   class ImageMemory;
112 
113   /** @brief Enumerates the contexts a plugin can be used in */
114   enum ContextEnum {eContextNone,
115     eContextGenerator,
116     eContextFilter,
117     eContextTransition,
118     eContextPaint,
119     eContextGeneral,
120     eContextRetimer,
121 #ifdef OFX_EXTENSIONS_TUTTLE
122     eContextReader,
123     eContextWriter,
124 #endif
125 #ifdef OFX_EXTENSIONS_NATRON
126     eContextTracker
127 #endif
128   };
129 
130   /** @brief Enumerates the pixel depths supported */
131   enum BitDepthEnum {eBitDepthNone, /**< @brief bit depth that indicates no data is present */
132     eBitDepthUByte,
133     eBitDepthUShort,
134     eBitDepthHalf,
135     eBitDepthFloat,
136     eBitDepthCustom, ///< some non standard bit depth
137 #ifdef OFX_EXTENSIONS_VEGAS
138     eBitDepthUByteBGRA,   /// added support for sony vegas bgra ordered pixels
139     eBitDepthUShortBGRA,
140     eBitDepthFloatBGRA,
141 #endif
142   };
143 
144   /** @brief Enumerates the component types supported */
145   enum PixelComponentEnum {ePixelComponentNone,
146     ePixelComponentRGBA,
147     ePixelComponentRGB,
148     ePixelComponentAlpha,
149 #ifdef OFX_EXTENSIONS_NUKE
150     ePixelComponentMotionVectors,
151     ePixelComponentStereoDisparity,
152 #endif
153 #ifdef OFX_EXTENSIONS_NATRON
154     ePixelComponentXY,
155 #endif
156     ePixelComponentCustom ///< some non standard pixel type
157   };
158 
159 #ifdef OFX_EXTENSIONS_NUKE
160   enum PassThroughLevelEnum {
161     //all planes not specified in output by the getClipComponents action will not be visible by effects down-stream
162     ePassThroughLevelBlockAllNonRenderedPlanes = 0,
163 
164     //all planes not specified in output by the getClipComponents action will be pass-through from the input pass-through clip
165     ePassThroughLevelPassThroughNonRenderedPlanes = 1,
166 
167     //all planes requested by the host are rendered, regardless of the getClipComponents action.
168     //In this mode, the render action will be called once
169     //for every plane (instead of a single time with all planes in parameter) and the plug-in is expected to use the regular
170     //image effect suite, i.e: clipGetImage. The pixel components property of the image returned by clipGetImage is expected to
171     //match what is returned by the pixel components property of the clip. This value is useful for instance for Transform effects:
172     //all planes will be transformed with minimalist changes to the plug-in code.
173     ePassThroughLevelRenderAllRequestedPlanes = 2
174   };
175 
176   enum ViewInvarianceLevelEnum {
177 
178     // All views produced are different from each other
179     eViewInvarianceAllViewsVariant = 0,
180 
181     // All views are similar except for pass-through planes
182     eViewInvarianceOnlyPassThroughPlanesVariant,
183 
184     // Result is similar across all views
185     eViewInvarianceAllViewsInvariant,
186   };
187 #endif
188 
189   /** @brief Enumerates the ways a fielded image can be extracted from a clip */
190   enum FieldExtractionEnum {eFieldExtractBoth,   /**< @brief extract both fields */
191     eFieldExtractSingle, /**< @brief extracts a single field, so you have a half height image */
192     eFieldExtractDoubled /**< @brief extracts a single field, but doubles up the field, so you have a full height image */
193   };
194 
195   /** @brief Enumerates the kind of render thread safety a plugin has */
196   enum RenderSafetyEnum {eRenderUnsafe,       /**< @brief can only render a single instance at any one time */
197     eRenderInstanceSafe, /**< @brief can call a single render on an instance, but can render multiple instances simultaneously */
198     eRenderFullySafe     /**< @brief can call render any number of times on an instance, and render multiple instances simultaneously */
199   };
200 
201   /** @brief Enumerates the fields present in an image */
202   enum FieldEnum {eFieldNone,   /**< @brief unfielded image */
203     eFieldBoth,   /**< @brief fielded image with both fields present */
204     eFieldLower,  /**< @brief only the spatially lower field is present */
205     eFieldUpper,  /**< @brief only the spatially upper field is present  */
206     eFieldSingle, /**< @brief image that consists of a single field, and so is half height  */
207     eFieldDoubled /**< @brief image that consists of a single field, but each scan line is double, and so is full height  */
208   };
209 
210 #ifdef OFX_EXTENSIONS_VEGAS
211   /** @brief Enumerates the pixel order in an image */
212   enum PixelOrderEnum {
213     ePixelOrderRGBA,   /**< @brief pixel order is RGBA (ofx typical) */
214     ePixelOrderBGRA    /**< @brief pixel order is BGRA (added for Sony Vegas) */
215   };
216 #endif
217 
218   enum PreMultiplicationEnum { eImageOpaque,          /**< @brief the image is opaque and so has no premultiplication state */
219     eImagePreMultiplied,   /**< @brief the image is premultiplied by it's alpha */
220     eImageUnPreMultiplied, /**< @brief the image is unpremultiplied */
221   };
222 
223 #ifdef OFX_EXTENSIONS_VEGAS
224   /** @brief Enumerates the vegas contexts a plugin is being used in */
225   enum VegasRenderQualityEnum {
226     eVegasRenderQualityUnknown,
227     eVegasRenderQualityDraft,
228     eVegasRenderQualityPreview,
229     eVegasRenderQualityGood,
230     eVegasRenderQualityBest
231     };
232 
233   /** @brief Enumerates the vegas contexts a plugin is being used in */
234   enum VegasContextEnum {
235     eVegasContextUnknown,
236     eVegasContextMedia,
237     eVegasContextTrack,
238     eVegasContextEvent,
239     eVegasContextEventFadeIn,
240     eVegasContextEventFadeOut,
241     eVegasContextProject,
242     eVegasContextGenerator
243     };
244 
245   /** @brief Enumerates the hint for vegas to display thumbnails */
246   enum VegasPresetThumbnailEnum {
247     eVegasPresetThumbnailDefault,
248     eVegasPresetThumbnailSolidImage,
249     eVegasPresetThumbnailImageWithAlpha
250     };
251 #endif
252 
253   enum NativeOriginEnum {
254     eNativeOriginBottomLeft,
255     eNativeOriginTopLeft,
256     eNativeOriginCenter
257   };
258 
259 #ifdef OFX_EXTENSIONS_NATRON
260 
261   enum ShortcutModifierEnum
262   {
263     eShortcutModifierNone = 0x0,
264     eShortcutModifierShift = 0x1,
265     eShortcutModifierCtrl = 0x2,
266     eShortcutModifierAlt = 0x4,
267     eShortcutModifierMeta = 0x8,
268   };
269 
270 #endif
271 
272   /** @brief turns a field string into and enum */
273   FieldEnum mapStrToFieldEnum(const std::string &str)  OFX_THROW(std::invalid_argument);
274 
275 #ifdef OFX_EXTENSIONS_VEGAS
276   /** @brief map a std::string to a RenderQuality */
277   VegasRenderQualityEnum mapToVegasRenderQualityEnum(const std::string &s) OFX_THROW(std::invalid_argument);
278 
279   /** @brief map a std::string to a context */
280   VegasContextEnum mapToVegasContextEnum(const std::string &s) OFX_THROW(std::invalid_argument);
281 #endif
282 
283   ////////////////////////////////////////////////////////////////////////////////
284   /** @brief map a std::string to a context enum */
285   ContextEnum mapToContextEnum(const std::string &s) OFX_THROW(std::invalid_argument);
286 
287   const char* mapContextEnumToStr(ContextEnum context) OFX_THROW(std::invalid_argument);
288 
289   const char* mapMessageTypeEnumToStr(OFX::Message::MessageTypeEnum type);
290 
291   OFX::Message::MessageReplyEnum mapToMessageReplyEnum(OfxStatus stat);
292 
293   InstanceChangeReason mapToInstanceChangedReason(const std::string &s) OFX_THROW(std::invalid_argument);
294 
295   BitDepthEnum mapStrToBitDepthEnum(const std::string &str) OFX_THROW(std::invalid_argument);
296 
297   const char* mapBitDepthEnumToStr(BitDepthEnum bitDepth) OFX_THROW(std::invalid_argument);
298 
299   PixelComponentEnum mapStrToPixelComponentEnum(const std::string &str) OFX_THROW(std::invalid_argument);
300 
301   const char* mapPixelComponentEnumToStr(PixelComponentEnum pixelComponent) OFX_THROW(std::invalid_argument);
302 
303 #if defined(OFX_EXTENSIONS_NATRON)
304   /** @brief extract a custom Natron plane defined in the multi-plane extension from the kOfxImageEffectPropComponents property value, @see getPixelComponentsProperty() */
305  bool extractCustomPlane(const std::string& comp, std::string* layerName, std::string* layerLabel, std::string* channelsLabel, std::vector<std::string>* channels);
306 #endif
307 
308   class PluginFactory
309   {
310   public:
311     /** @brief virtual destructor */
~PluginFactory()312     virtual ~PluginFactory() {};
load()313     virtual void load() {}
unload()314     virtual void unload() {}
315     virtual void describe(OFX::ImageEffectDescriptor &desc) = 0;
316     virtual void describeInContext(OFX::ImageEffectDescriptor &desc, ContextEnum context) = 0;
317     virtual ImageEffect* createInstance(OfxImageEffectHandle handle, ContextEnum context) = 0;
318     virtual const std::string& getID() const = 0;
319     virtual const std::string& getUID() const = 0;
320     virtual unsigned int getMajorVersion() const = 0;
321     virtual unsigned int getMinorVersion() const = 0;
322     virtual OfxPluginEntryPoint* getMainEntry() = 0;
323   };
324 
325   template<class FACTORY>
326   class FactoryMainEntryHelper
327   {
328   protected:
getHelperID()329     const std::string& getHelperID() const { return _id; }
getHelperMajorVersion()330     unsigned int getHelperMajorVersion() const  { return  _maj; }
getHelperMinorVersion()331     unsigned int getHelperMinorVersion() const  { return  _min; }
toString(unsigned int val)332     std::string toString(unsigned int val)
333     {
334       std::ostringstream ss;
335       ss << val;
336       return ss.str();
337     }
FactoryMainEntryHelper(const std::string & id,unsigned int maj,unsigned int min)338     FactoryMainEntryHelper(const std::string& id, unsigned int maj, unsigned int min): _id(id), _maj(maj), _min(min)
339     {
340       assert(uid().empty()); // constructor should only be called once
341       uid() = id + toString(maj) + toString(min);
342     }
getHelperUID()343     const std::string& getHelperUID() const { return uid(); }
mainEntry(const char * action,const void * handle,OfxPropertySetHandle in,OfxPropertySetHandle out)344     static OfxStatus mainEntry(const char *action, const void* handle, OfxPropertySetHandle in, OfxPropertySetHandle out)
345     {
346       return OFX::Private::mainEntryStr(action, handle, in, out, uid().c_str());
347     }
348 
349   private:
uid()350     static std::string& uid() {
351       // _uid can not be a static class member, because in that case it may be
352       // initialized after the constructor is called (plugin factories are declared as global variables).
353 
354       // since only one instance of FactoryMainEntryHelp<FACTORY> is constructed
355       // (see the assert() above), there is no deinitialization order issue.
356       // see https://isocpp.org/wiki/faq/ctors#construct-on-first-use-v2
357       static std::string _uid;
358       return _uid;
359     }
360     std::string _id;
361     unsigned int _maj;
362     unsigned int _min;
363   };
364 
365   template<class FACTORY>
366   class PluginFactoryHelper : public FactoryMainEntryHelper<FACTORY>, public PluginFactory
367   {
368   public:
PluginFactoryHelper(const std::string & id,unsigned int maj,unsigned int min)369     PluginFactoryHelper(const std::string& id, unsigned int maj, unsigned int min): FactoryMainEntryHelper<FACTORY>(id, maj, min)
370     {}
getMainEntry()371     OfxPluginEntryPoint* getMainEntry() { return FactoryMainEntryHelper<FACTORY>::mainEntry; }
getID()372     const std::string& getID() const { return FactoryMainEntryHelper<FACTORY>::getHelperID(); }
getUID()373     const std::string& getUID() const { return FactoryMainEntryHelper<FACTORY>::getHelperUID(); }
getMajorVersion()374     unsigned int getMajorVersion() const { return FactoryMainEntryHelper<FACTORY>::getHelperMajorVersion(); }
getMinorVersion()375     unsigned int getMinorVersion() const { return FactoryMainEntryHelper<FACTORY>::getHelperMinorVersion(); }
376   };
377 
378 #define mDeclarePluginFactory(CLASS, LOADFUNCDEF, UNLOADFUNCDEF) \
379   class CLASS : public OFX::PluginFactoryHelper<CLASS> \
380   { \
381   public: \
382   CLASS(const std::string& id, unsigned int verMaj, unsigned int verMin):OFX::PluginFactoryHelper<CLASS>(id, verMaj, verMin){} \
383   virtual void load() LOADFUNCDEF ;\
384   virtual void unload() UNLOADFUNCDEF ;\
385   virtual void describe(OFX::ImageEffectDescriptor &desc); \
386   virtual void describeInContext(OFX::ImageEffectDescriptor &desc, OFX::ContextEnum context); \
387   virtual OFX::ImageEffect* createInstance(OfxImageEffectHandle handle, OFX::ContextEnum context); \
388   };
389 
390   /** @brief Declare a plugin factory with a template majorVersion parameters.
391    *
392    * Allows an easy definition of multiple versions of the same plugin, for backward compatibility.
393    * Keep in mind that the members of PluginFactoryHelper must be accessed through this->,
394    * because when a class template derives from a base class template, the base members are
395    * not visible in the derived class template definition. (This makes sense; until you specialize,
396    * there is no class, and so there are no members. Explicit specializations can always change
397    * the meaning of any given template class.)
398    */
399 #define mDeclarePluginFactoryVersioned(CLASS, LOADFUNCDEF, UNLOADFUNCDEF) \
400   template<unsigned int majorVersion> \
401   class CLASS : public OFX::PluginFactoryHelper<CLASS<majorVersion> > \
402   { \
403   public: \
404   CLASS<majorVersion>(const std::string& id, unsigned int verMin):OFX::PluginFactoryHelper<CLASS>(id, majorVersion, verMin){} \
405   virtual void load() LOADFUNCDEF ;\
406   virtual void unload() UNLOADFUNCDEF ;\
407   virtual void describe(OFX::ImageEffectDescriptor &desc); \
408   virtual void describeInContext(OFX::ImageEffectDescriptor &desc, OFX::ContextEnum context); \
409   virtual OFX::ImageEffect* createInstance(OfxImageEffectHandle handle, OFX::ContextEnum context); \
410   };
411 
412   typedef std::vector<PluginFactory*> PluginFactoryArray;
413   struct PluginFactories {
plugIDsPluginFactories414     static OFX::PluginFactoryArray& plugIDs() {
415       // Use a static variable in a member function to make sure plugIDs is initialized before PluginFactories.
416       // This is OK, since s_plugIDs is not used in the PluginFactories destructor.
417       // see https://isocpp.org/wiki/faq/ctors#construct-on-first-use-v2
418       static OFX::PluginFactoryArray _plugIDs;
419       return _plugIDs;
420     }
PluginFactoriesPluginFactories421     PluginFactories(PluginFactory* pf) { plugIDs().push_back(pf); }
422   };
423 #define mRegisterPluginFactoryInstance(pf) static OFX::PluginFactories mypluginfactory_##pf(&pf);
424 
425   /** @brief Fetch's a suite from the host and logs errors
426 
427   All the standard suites are fetched by the support code, you should use this
428   to fetch any extra non-standard suites.
429   */
430   const void * fetchSuite(const char *suiteName, int suiteVersion, bool optional = false);
431 
432   ////////////////////////////////////////////////////////////////////////////////
433   /** @brief A class that lists all the properties of a host */
434   struct ImageEffectHostDescription {
435   public :
436     int APIVersionMajor;
437     int APIVersionMinor;
438     std::string hostName;
439     std::string hostLabel;
440     int versionMajor;
441     int versionMinor;
442     int versionMicro;
443     std::string versionLabel;
444     bool hostIsBackground;
445     bool supportsOverlays;
446     bool supportsMultiResolution;
447     bool supportsTiles;
448     bool temporalClipAccess;
449     bool supportsMultipleClipDepths;
450     bool supportsMultipleClipPARs;
451     bool supportsSetableFrameRate;
452     bool supportsSetableFielding;
453     int sequentialRender;
454     bool supportsStringAnimation;
455     bool supportsCustomInteract;
456     bool supportsChoiceAnimation;
457 #ifdef OFX_EXTENSIONS_RESOLVE
458     bool supportsStrChoiceAnimation;
459 #endif
460     bool supportsBooleanAnimation;
461     bool supportsCustomAnimation;
462     void* osHandle;
463     bool supportsParametricParameter;
464     bool supportsParametricAnimation;
465     bool supportsRenderQualityDraft;
466     NativeOriginEnum nativeOrigin;
467 #ifdef OFX_EXTENSIONS_RESOLVE
468     bool supportsOpenCLRender;
469     bool supportsCudaRender;
470 #endif
471 #ifdef OFX_SUPPORTS_OPENGLRENDER
472     bool supportsOpenGLRender;
473 #endif
474 #ifdef OFX_EXTENSIONS_NUKE
475     bool supportsCamera;
476     bool canTransform;
477     bool isMultiPlanar;
478 #endif
479     int maxParameters;
480     int maxPages;
481     int pageRowCount;
482     int pageColumnCount;
483     typedef std::vector<PixelComponentEnum> PixelComponentArray;
484     PixelComponentArray _supportedComponents;
485     typedef std::vector<ContextEnum> ContextArray;
486     ContextArray _supportedContexts;
487     typedef std::vector<BitDepthEnum> PixelDepthArray;
488     PixelDepthArray _supportedPixelDepths;
489     bool supportsProgressSuite;
490     bool supportsTimeLineSuite;
491     bool supportsMessageSuiteV2;
492 #ifdef OFX_EXTENSIONS_NATRON
493     bool isNatron;
494     bool supportsDynamicChoices;
495     bool supportsCascadingChoices;
496     bool supportsChannelSelector;
497     bool canDistort;
498 
499     struct NativeOverlayHandle
500     {
501       // Uniquely identifies the overlay handle in the host
502       std::string identifier;
503 
504       // A vector of parameters, where each parameter contains a pair <parameterHint, parameterType>
505       // The parameterHint is a hint of the host as to what kind of parameter should be used for that role
506       // The parameterType allows the host to contrain which parameter type should be passed to the native overlay handle
507       std::vector<std::pair<std::string,std::string> > parameters;
508     };
509     std::vector<NativeOverlayHandle> nativeInteracts;
510 #endif
511 
512   public:
513     bool supportsPixelComponent(const PixelComponentEnum component) const;
514     bool supportsBitDepth( const BitDepthEnum bitDepth) const;
515     bool supportsContext(const ContextEnum context) const;
516 
517     /** @return default pixel depth supported by host application. */
518     BitDepthEnum getDefaultPixelDepth() const;
519 
520     /** @return default pixel component supported by host application. */
521     PixelComponentEnum getDefaultPixelComponent() const;
522   };
523 
524 
525   /// retrieve the host description
526   ImageEffectHostDescription* getImageEffectHostDescription();
527 
528   ////////////////////////////////////////////////////////////////////////////////
529   /** @brief Wraps up a clip */
530   class ClipDescriptor {
531   protected :
532     mDeclareProtectedAssignAndCC(ClipDescriptor);
ClipDescriptor(void)533     ClipDescriptor(void) {assert(false);}
534 
535   protected :
536     /** @brief name of the clip */
537     std::string _clipName;
538 
539     /** @brief properties for this clip */
540     PropertySet _clipProps;
541 
542   protected :
543     /** @brief hidden constructor */
544     ClipDescriptor(const std::string &name, OfxPropertySetHandle props);
545 
546     friend class ImageEffectDescriptor;
547 
548   public :
getPropertySet()549     const PropertySet &getPropertySet() const {return _clipProps;}
550 
getPropertySet()551     PropertySet &getPropertySet() {return _clipProps;}
552 
553     /** @brief returns the clip name */
getName(void)554     const std::string &getName(void) const {return _clipName;}
555 
556     /** @brief set the label properties */
557     void setLabel(const std::string &label);
558 
559     /** @brief set the label properties */
560     void setLabels(const std::string &label, const std::string &shortLabel, const std::string &longLabel);
561 
562 #ifdef OFX_EXTENSIONS_NATRON
563     /** @brief set the secretness of the clip, defaults to false */
564     void setIsSecret(bool v);
565 
566     /** @brief set the clip hint */
567     void setHint(const std::string &hint);
568 
569     /** @brief set the clip label and hint */
570     void setLabelAndHint(const std::string &label, const std::string &hint);
571 
572     /** @brief say whether this clip may contain images with a distortion function attached */
573     void setCanDistort(bool v);
574 #endif
575 
576     /** @brief set how fielded images are extracted from the clip defaults to eFieldExtractDoubled */
577     void setFieldExtraction(FieldExtractionEnum v);
578 
579     /** @brief set which components are supported, defaults to none set, this must be called at least once! */
580     void addSupportedComponent(PixelComponentEnum v);
581 
582     /** @brief set which components are supported. This version adds by the raw C-string label, allowing you to add
583     custom component types */
584     void addSupportedComponent(const std::string &comp);
585 
586     /** @brief say whether we are going to do random temporal access on this clip, defaults to false */
587     void setTemporalClipAccess(bool v);
588 
589     /** @brief say whether if the clip is optional, defaults to false */
590     void setOptional(bool v);
591 
592     /** @brief say whether this clip supports tiling, defaults to true */
593     void setSupportsTiles(bool v);
594 
595     /** @brief say whether this clip is a 'mask', so the host can know to replace with a roto or similar, defaults to false */
596     void setIsMask(bool v);
597 
598 #ifdef OFX_EXTENSIONS_NUKE
599     /** @brief say whether this clip may contain images with a transform attached */
600     void setCanTransform(bool v);
601 #endif
602   };
603 
604 #ifdef OFX_EXTENSIONS_NUKE
605   ////////////////////////////////////////////////////////////////////////////////
606   /** @brief Wraps up a camera */
607   class CameraDescriptor {
608   protected :
609     mDeclareProtectedAssignAndCC(CameraDescriptor);
CameraDescriptor(void)610     CameraDescriptor(void) {assert(false);}
611 
612   protected :
613     /** @brief name of the camera */
614     std::string _cameraName;
615 
616     /** @brief properties for this camera */
617     PropertySet _cameraProps;
618 
619   protected :
620     /** @brief hidden constructor */
621     CameraDescriptor(const std::string &name, OfxPropertySetHandle props);
622 
623     friend class ImageEffectDescriptor;
624 
625   public :
getPropertySet()626     const PropertySet &getPropertySet() const {return _cameraProps;}
627 
getPropertySet()628     PropertySet &getPropertySet() {return _cameraProps;}
629 
630     /** @brief returns the camera name */
getName(void)631     const std::string &getName(void) const {return _cameraName;}
632 
633     /** @brief set the label properties */
634     void setLabel(const std::string &label);
635 
636     /** @brief set the label properties */
637     void setLabels(const std::string &label, const std::string &shortLabel, const std::string &longLabel);
638 
639 #ifdef OFX_EXTENSIONS_NATRON
640     /** @brief set the secretness of the camera, defaults to false */
641     void setIsSecret(bool v);
642 
643     /** @brief set the camera hint */
644     void setHint(const std::string &hint);
645 
646     /** @brief set the camera label and hint */
647     void setLabelAndHint(const std::string &label, const std::string &hint);
648 #endif
649 
650     /** @brief say whether if the camera is optional, defaults to false */
651     void setOptional(bool v);
652   };
653 #endif
654 
655   ////////////////////////////////////////////////////////////////////////////////
656   /** @brief Wraps up an effect descriptor, used in the describe actions */
657   class ImageEffectDescriptor : public ParamSetDescriptor
658   {
659   protected :
660     mDeclareProtectedAssignAndCCBase(ImageEffectDescriptor,ParamSetDescriptor);
ImageEffectDescriptor(void)661     ImageEffectDescriptor(void) {assert(false);}
662 
663   protected :
664     /** @brief The effect handle */
665     OfxImageEffectHandle _effectHandle;
666 
667     /** @brief properties for this effect */
668     PropertySet _effectProps;
669 
670     /** @brief Set of all previously defined clips, defined on demand */
671     std::map<std::string, ClipDescriptor *> _definedClips;
672 
673 #ifdef OFX_EXTENSIONS_NUKE
674     /** @brief Set of all previously defined clips, defined on demand */
675     std::map<std::string, CameraDescriptor *> _definedCameras;
676 #endif
677 
678     /** @brief Set of strings for clip preferences action (stored in here so the array persists and can be used in a property name)*/
679     std::map<std::string, std::string> _clipComponentsPropNames;
680     std::map<std::string, std::string> _clipDepthPropNames;
681     std::map<std::string, std::string> _clipPARPropNames;
682     std::map<std::string, std::string> _clipROIPropNames;
683     std::map<std::string, std::string> _clipFrameRangePropNames;
684 #ifdef OFX_EXTENSIONS_NUKE
685     std::map<std::string, std::string> _clipPlanesPropNames;
686     std::map<std::string, std::string> _clipFrameViewsPropNames;
687 #endif
688 
689     auto_ptr<EffectOverlayDescriptor> _overlayDescriptor;
690 #ifdef OFX_EXTENSIONS_VEGAS
691 #if defined(WIN32) || defined(WIN64)
692     auto_ptr<HWNDInteractDescriptor>  _hwndInteractDescriptor;
693 #endif // #if defined(WIN32) || defined(WIN64)
694 #endif
695   public :
696     /** @brief ctor */
697     ImageEffectDescriptor(OfxImageEffectHandle handle);
698 
699     /** @brief dtor */
700     ~ImageEffectDescriptor();
701 
getPropertySet()702     const PropertySet &getPropertySet() const {return _effectProps;}
703 
getPropertySet()704     PropertySet &getPropertySet() {return _effectProps;}
705 
706     /** @brief, set the label properties in a plugin */
707     void setLabel(const std::string &label);
708 
709     /** @brief, set the label properties in a plugin */
710     void setLabels(const std::string &label, const std::string &shortLabel, const std::string &longLabel);
711 
712     /** @brief, set the version properties in a plugin */
713     void setVersion(int major, int minor, int micro, int build, const std::string &versionLabel);
714 
715     /** @brief Set the plugin grouping, defaults to "" */
716     void setPluginGrouping(const std::string &group);
717 
718     /** @brief Set the plugin description, defaults to "" */
719     void setPluginDescription(const std::string &description, bool validate = true);
720 
721     /** @brief Add a context to those supported, defaults to none, must be called at least once */
722     void addSupportedContext(ContextEnum v);
723 
724     /** @brief Add a pixel depth to those supported, defaults to none, must be called at least once */
725     void addSupportedBitDepth(BitDepthEnum v);
726 
727     /** @brief Add a pixel depth to those supported for OpenGL rendering, defaults to all */
728     void addSupportedOpenGLBitDepth(BitDepthEnum v);
729 
730 #ifdef OFX_EXTENSIONS_TUTTLE
731     /** @brief Add a file extension to those supported, defaults to none */
732     void addSupportedExtension(const std::string& extension);
733     void addSupportedExtensions(const std::vector<std::string>& extensions);
734     void addSupportedExtensions(const char* extensions[]); // NULL-terminated array of char*
735     void setPluginEvaluation(double evaluation);
736 #endif
737 
738     /** @brief Is the plugin single instance only ? defaults to false */
739     void setSingleInstance(bool v);
740 
741     /** @brief Does the plugin expect the host to perform per frame SMP threading defaults to true */
742     void setHostFrameThreading(bool v);
743 
744     /** @brief Does the plugin support multi resolution images, defaults to true */
745     void setSupportsMultiResolution(bool v);
746 
747     /** @brief set the instance to be sequentially renderred, this should have been part of clip preferences! */
748     void setSequentialRender(bool v);
749 
750     /** @brief Have we informed the host we want to be seqentially renderred ? */
751     bool getSequentialRender(void) const;
752 
753     /** @brief Does the plugin support image tiling, defaults to true */
754     void setSupportsTiles(bool v);
755 
756     /** @brief Does the plugin handle render quality, defaults to false */
757     void setSupportsRenderQuality(bool v);
758 
759     /** @brief Does the plugin perform temporal clip access, defaults to false */
760     void setTemporalClipAccess(bool v);
761 
762     /** @brief Does the plugin want to have render called twice per frame in all circumanstances for fielded images ? defaults to true */
763     void setRenderTwiceAlways(bool v);
764 
765     /** @brief Does the plugin support inputs and output clips of differing depths, defaults to false */
766     void setSupportsMultipleClipDepths(bool v);
767 
768     /** @brief Does the plugin support inputs and output clips of pixel aspect ratios, defaults to false */
769     void setSupportsMultipleClipPARs(bool v);
770 
771     /** @brief How thread safe is the plugin, defaults to eRenderInstanceSafe */
772     void setRenderThreadSafety(RenderSafetyEnum v);
773 
774 #ifdef OFX_EXTENSIONS_NATRON
775     /** @brief Indicates if the plug-in can make use of multiple CPU threads within a single call
776      of the kOfxImageEffectActionRender action, for instance by using the multi-thread suite.*/
777     void setUsesMultiThreading(bool isMultiThreaded);
778 #endif
779 
780     /** @brief If the slave  param changes the clip preferences need to be re-evaluated */
781     void addClipPreferencesSlaveParam(ParamDescriptor &p);
782 
783 #ifdef OFX_EXTENSIONS_RESOLVE
784     /** @brief Does the plugin support OpenCL Render, defaults to false */
785     void setSupportsOpenCLRender(bool v);
786 
787     /** @brief Does the plugin support CUDA Render, defaults to false */
788     void setSupportsCudaRender(bool v);
789 #endif
790 
791 #ifdef OFX_SUPPORTS_OPENGLRENDER
792     /** @brief Does the plugin support OpenGL accelerated rendering (but is also capable of CPU rendering) ? */
793     void setSupportsOpenGLRender(bool v);
794 
795     /** @brief Does the plugin require OpenGL accelerated rendering ? */
796     void setNeedsOpenGLRender(bool v);
797     void addOpenGLBitDepth(BitDepthEnum bitDepth);
798 #endif
799 
800 #ifdef OFX_EXTENSIONS_VEGAS
801     /** @brief Add a guid upgrade path, defaults to none, must be called at least once */
802     void addVegasUpgradePath(const std::string &guidString);
803 
804     /** @brief sets the path to a help file, defaults to none, must be called at least once */
805     void setHelpPath(const std::string &helpPathString);
806 
807     /** @brief sets the context ID to a help file if it's a .chm file, defaults to none, must be called at least once */
808     void setHelpContextID(int helpContextID);
809 
810     void setPresetThumbnailHint(VegasPresetThumbnailEnum thumbnailHint);
811 #endif
812 
813 #ifdef OFX_EXTENSIONS_NUKE
814       /** @brief indicate that a plugin or host can handle transform effects */
815       void setCanTransform(bool v);
816 
817       /** @brief Indicates that a host or plugin can fetch more than a type of image from a clip*/
818       void setIsMultiPlanar(bool v);
819 
820       /** @brief Plugin indicates to the host that it should pass through any planes not modified by the plugin*/
821       void setPassThroughForNotProcessedPlanes(PassThroughLevelEnum v);
822 
823       /** @brief Indicates to the host that the plugin is view aware, in which case it will have to use the view calls*/
824       void setIsViewAware(bool v);
825 
826       /** @brief Indicates to the host that a view aware plugin produces the same image independent of the view being rendered*/
827       void setIsViewInvariant(ViewInvarianceLevelEnum v);
828 #endif
829 
830 #ifdef OFX_EXTENSIONS_NATRON
831       /** @brief Indicates if the host may add a mask that will be handled automatically. */
832       void setHostMaskingEnabled(bool enabled);
833 
834       /** @brief Indicates if the host may add a "Mix" double parameter that will dissolve
835         between the source image at 0 and the full effect at 1. */
836       void setHostMixingEnabled(bool enabled);
837 
838       /** @brief Indicates if the plug-in description is written in markdown or plain-text otherwise. */
839       void setDescriptionIsMarkdown(bool markdown);
840 
841       /** @brief The current selection rectangle drawn by the user on the host viewport.
842 
843        This property is refreshed whenever calling the kOfxActionInstanceChanged action
844        for the parameter kNatronOfxParamSelectionRectangleState to let the plug-in a change
845        to correctly synchronized its selection.
846        */
847       OfxRectI getSelectionRectangle();
848 
849       /** @brief Add a parameter that will be visible in a toolbar in the viewport of the host application. */
850       void addInViewportParam(const std::string& paramName);
851 
852       /** @brief Add a shortcut for the given parameter and set its default value. The host could then display this shortcut in an editor. */
853       void setDefaultParamInViewportShortcut(const std::string& paramName, int symbolKey, ShortcutModifierEnum modifiers);
854 
855       /** @brief Add a native overlay interact for the given parameters.
856 
857        This should be called in describeInContext().
858        It sets the properties kOfxParamPropUseHostOverlayHandle on each parameter,
859        and kNatronOfxPropNativeOverlays on the effect descriptor. */
860       void addNativeOverlayInteractForParameters(const std::string& interactType, const std::list<ParamDescriptor*>& parameters);
861 #endif
862 
863     /** @brief Create a clip, only callable from describe in context
864 
865     The returned clip \em must not be deleted by the client code. This is all managed by the ImageEffectDescriptor itself.
866     */
867     ClipDescriptor *defineClip(const std::string &name);
868 
869 #ifdef OFX_EXTENSIONS_NUKE
870     /** @brief Create a camera, only callable from describe in context
871 
872     The returned camera \em must not be deleted by the client code. This is all managed by the ImageEffectDescriptor itself.
873     */
874     CameraDescriptor *defineCamera(const std::string &name);
875 #endif
876 
877     /** @brief Access to the string maps needed for runtime properties. Because the char array must persist after the call,
878     we need these to be stored in the descriptor, which is only deleted on unload.*/
879 
getClipComponentPropNames()880     const std::map<std::string, std::string>& getClipComponentPropNames() const { return _clipComponentsPropNames; }
getClipDepthPropNames()881     const std::map<std::string, std::string>& getClipDepthPropNames() const { return _clipDepthPropNames; }
getClipPARPropNames()882     const std::map<std::string, std::string>& getClipPARPropNames() const { return _clipPARPropNames; }
getClipROIPropNames()883     const std::map<std::string, std::string>& getClipROIPropNames() const { return _clipROIPropNames; }
getClipFrameRangePropNames()884     const std::map<std::string, std::string>& getClipFrameRangePropNames() const { return _clipFrameRangePropNames; }
885 #ifdef OFX_EXTENSIONS_NUKE
getClipPlanesPropNames()886     const std::map<std::string, std::string>& getClipPlanesPropNames() const { return _clipPlanesPropNames; }
getClipFrameViewsPropNames()887     const std::map<std::string, std::string>& getClipFrameViewsPropNames() const { return _clipFrameViewsPropNames; }
888 #endif
889 
890     /** @brief override this to create an interact for the effect */
891     virtual void setOverlayInteractDescriptor(EffectOverlayDescriptor* desc);
892 
893 #ifdef OFX_EXTENSIONS_VEGAS
894 #if defined(WIN32) || defined(WIN64)
895     /** @brief override this to create an hwnd interact for the effect */
896     virtual void setHWNDInteractDescriptor(HWNDInteractDescriptor* desc);
897 #endif // #if defined(WIN32) || defined(WIN64)
898 #endif
899 #ifdef OFX_EXTENSIONS_NATRON
900   /** @brief indicate that a plugin or host can handle distortion function effects */
901   void setCanDistort(bool v);
902 
903   /** @brief indicate if the host may add a channel selector */
904   void setChannelSelector(PixelComponentEnum v);
905 
906   /** @brief indicate that the plugin is deprecated */
907   void setIsDeprecated(bool v);
908 
909   /** @brief say whether all the planes listed on the output clip in the getClipComponents action should preferably be rendered
910     at once or not (e.g: optical flow plug-in that could produce bw/fw planes at once)*/
911   void setRenderAllPlanes(bool enabled);
912 #endif
913   };
914 
915   ////////////////////////////////////////////////////////////////////////////////
916   /** @brief Wraps up an image */
917   class ImageBase {
918   protected :
919     /** @brief the handle that holds this image */
920     PropertySet _imageProps;
921 
922     /** @brief friend so we get access to ctor */
923     //friend class Clip;
924 
925     PixelComponentEnum _pixelComponents;     /**< @brief get the components in the image */
926     int       _pixelComponentCount;
927     int       _rowBytes;                     /**< @brief the number of bytes per scanline */
928     int       _pixelBytes;                   /**< @brief the number of bytes per pixel */
929     BitDepthEnum _pixelDepth;                 /**< @brief get the pixel depth */
930     PreMultiplicationEnum _preMultiplication; /**< @brief premultiplication on the image */
931     OfxRectI  _regionOfDefinition;           /**< @brief the RoD in pixel coordinates, this may be more or less than the bounds! */
932     OfxRectI  _bounds;                       /**< @brief the bounds on the pixel data */
933     double    _pixelAspectRatio;             /**< @brief the pixel aspect ratio */
934     FieldEnum _field;                        /**< @brief which field this represents */
935     std::string _uniqueID;                   /**< @brief the unique ID of this image */
936     OfxPointD _renderScale;                  /**< @brief any scaling factor applied to the image */
937 #ifdef OFX_EXTENSIONS_NUKE
938     double _transform[9];                    /**< @brief a 2D transform to apply to the image */
939     bool _transformIsIdentity;
940 #endif
941 #ifdef OFX_EXTENSIONS_NATRON
942     OfxInverseDistortionFunctionV1 _inverseDistortionFunction;
943     const void* _inverseDistortionFunctionData;
944 #endif
945 
946   public :
947     /** @brief ctor */
948     ImageBase(OfxPropertySetHandle props);
949 
950     /** @brief dtor */
951     virtual ~ImageBase();
952 
getPropertySet()953     const PropertySet &getPropertySet() const {return _imageProps;}
954 
getPropertySet()955     PropertySet &getPropertySet() {return _imageProps;}
956 
957     /** @brief get the pixel depth */
getPixelDepth(void)958     BitDepthEnum getPixelDepth(void) const {return _pixelDepth;}
959 
960     /** @brief get the components in the image */
getPixelComponents(void)961     PixelComponentEnum getPixelComponents(void) const { return _pixelComponents;}
962 
963     /** @brief get the number of components in the image */
getPixelComponentCount(void)964     int getPixelComponentCount(void) const { return _pixelComponentCount; }
965 
966     /** @brief get the string representing the pixel components */
getPixelComponentsProperty(void)967     std::string getPixelComponentsProperty(void) const { return _imageProps.propGetString(kOfxImageEffectPropComponents);}
968 
969     /** @brief premultiplication on the image */
getPreMultiplication(void)970     PreMultiplicationEnum getPreMultiplication(void) const { return _preMultiplication;}
971 
972     /** @brief get the scale factor that has been applied to this image */
getRenderScale(void)973     const OfxPointD& getRenderScale(void) const { return _renderScale;}
974 
975     /** @brief get the scale factor that has been applied to this image */
getPixelAspectRatio(void)976     double getPixelAspectRatio(void) const { return _pixelAspectRatio;}
977 
978     /** @brief get the region of definition (in pixel coordinates) of this image */
getRegionOfDefinition(void)979     const OfxRectI& getRegionOfDefinition(void) const { return _regionOfDefinition;}
980 
981     /** @brief get the bounds on the image data (in pixel coordinates) of this image */
getBounds(void)982     const OfxRectI& getBounds(void) const { return _bounds;}
983 
984     /** @brief get the row bytes, may be negative */
getRowBytes(void)985     int getRowBytes(void) const { return _rowBytes;}
986 
987     /** @brief get the number of bytes per pixel */
getPixelBytes(void)988     int getPixelBytes(void) const { return _pixelBytes;}
989 
990     /** @brief get the fielding of this image */
getField(void)991     FieldEnum getField(void) const { return _field;}
992 
993     /** @brief the unique ID of this image */
getUniqueIdentifier(void)994     const std::string& getUniqueIdentifier(void) const { return _uniqueID;}
995 
996 #ifdef OFX_EXTENSIONS_NUKE
997     /** @brief the 2D transform attached to this image. */
getTransform(double t[9])998     void getTransform(double t[9]) const { for (int i = 0; i < 9; ++i) { t[i] = _transform[i]; } }
999 
1000     /** @brief is the transform identity? */
getTransformIsIdentity()1001     bool getTransformIsIdentity() const { return _transformIsIdentity; }
1002 #endif
1003 
1004 #ifdef OFX_EXTENSIONS_NATRON
1005     /** @brief the 2D distortion function attached to this image. */
getInverseDistortionFunction(const void ** distortionFunctionData)1006     OfxInverseDistortionFunctionV1 getInverseDistortionFunction(const void** distortionFunctionData) const {
1007       *distortionFunctionData = _inverseDistortionFunctionData;
1008       return _inverseDistortionFunction;
1009     }
1010 #endif
1011   };
1012 
1013   ////////////////////////////////////////////////////////////////////////////////
1014   /** @brief Wraps up an image */
1015   class Image : public ImageBase {
1016   protected :
1017     void     *_pixelData;                    /**< @brief the base address of the image */
1018 
1019   public :
1020     /** @brief ctor */
1021     Image(OfxPropertySetHandle props);
1022 
1023     /** @brief dtor */
1024     virtual ~Image();
1025 
1026     /** @brief get the pixel data for this image */
getPixelData(void)1027     void *getPixelData(void) { return _pixelData;}
1028 
1029     /** @brief get the pixel data for this image */
getPixelData(void)1030     const void *getPixelData(void) const { return _pixelData;}
1031 
1032     /** @brief return a pixel pointer, returns NULL if (x,y) is outside the image bounds
1033 
1034     x and y are in pixel coordinates
1035 
1036     If the components are custom, then this will return NULL as the support code
1037     can't know the pixel size to do the work.
1038     */
1039     void *getPixelAddress(int x, int y);
1040 
1041     /** @brief return a pixel pointer, returns NULL if (x,y) is outside the image bounds
1042 
1043     x and y are in pixel coordinates
1044 
1045     If the components are custom, then this will return NULL as the support code
1046     can't know the pixel size to do the work.
1047     */
1048     const void *getPixelAddress(int x, int y) const;
1049 
1050     /** @brief return a pixel pointer, returns the nearest pixel if (x,y) is outside the image bounds
1051 
1052     x and y are in pixel coordinates
1053 
1054     If the components are custom, then this will return NULL as the support code
1055     can't know the pixel size to do the work.
1056     */
1057     void *getPixelAddressNearest(int x, int y);
1058 
1059     /** @brief return a pixel pointer, returns the nearest pixel if (x,y) is outside the image bounds
1060 
1061     x and y are in pixel coordinates
1062 
1063     If the components are custom, then this will return NULL as the support code
1064     can't know the pixel size to do the work.
1065     */
1066     const void *getPixelAddressNearest(int x, int y) const;
1067   };
1068 
1069   ////////////////////////////////////////////////////////////////////////////////
1070   /** @brief Wraps up an OpenGL texture */
1071   class Texture : public ImageBase {
1072   protected :
1073     int _index;
1074     int _target;
1075 
1076   public :
1077     /** @brief ctor */
1078     Texture(OfxPropertySetHandle props);
1079 
1080     /** @brief dtor */
1081     virtual ~Texture();
1082 
1083     /** @brief get OpenGL texture id (cast to GLuint) */
getIndex()1084     inline int getIndex() const {return _index;}
1085 
1086     /** @brief get OpenGL texture target (cast to GLenum) */
getTarget()1087     inline int getTarget() const {return _target;}
1088   };
1089 
1090   ////////////////////////////////////////////////////////////////////////////////
1091   /** @brief Wraps up a clip instance */
1092   class Clip {
1093   protected :
1094     mDeclareProtectedAssignAndCC(Clip);
1095 
1096     /** @brief name of the clip */
1097     std::string _clipName;
1098 
1099     /** @brief properties for this clip */
1100     PropertySet _clipProps;
1101 
1102     /** @brief handle for this clip */
1103     OfxImageClipHandle _clipHandle;
1104 
1105     /** @brief effect instance that owns this clip */
1106     ImageEffect *_effect;
1107 
1108     /** @brief hidden constructor */
1109     Clip(ImageEffect *effect, const std::string &name, OfxImageClipHandle handle, OfxPropertySetHandle props);
1110 
1111     /** @brief so one can be made */
1112     friend class ImageEffect;
1113 
1114 #ifdef OFX_EXTENSIONS_VEGAS
1115     PixelOrderEnum _pixelOrder;              /**< @brief the pixel order */
1116 #endif
1117 
1118   public :
1119     /// get the underlying property set on this clip
getPropertySet()1120     const PropertySet &getPropertySet() const {return _clipProps;}
1121 
1122     /// get the underlying property set on this clip
getPropertySet()1123     PropertySet &getPropertySet() {return _clipProps;}
1124 
1125     /** @brief returns the clip name */
getName(void)1126     const std::string &getName(void) const {return _clipName;}
1127 
1128 #ifdef OFX_EXTENSIONS_NATRON
1129     /** @brief set the label property in a clip */
1130     void setLabel(const std::string &label);
1131 
1132     /** @brief set the label properties in a clip */
1133     void setLabels(const std::string &label, const std::string &shortLabel, const std::string &longLabel);
1134 
1135     /** @brief set the secretness of the clip, defaults to false */
1136     void setIsSecret(bool v);
1137 
1138     /** @brief set the clip hint */
1139     void setHint(const std::string &hint);
1140 
1141     /** @brief set the clip hint */
1142     void setLabelAndHint(const std::string &label, const std::string &hint);
1143 
1144     /* @brief Get the clip format in pixel coordinates */
1145     void getFormat(OfxRectI &format) const;
1146 #endif
1147 
1148     /// get the OFX clip handle
getHandle()1149     OfxImageClipHandle getHandle() {return _clipHandle;}
1150 
1151     /** @brief get the name */
name(void)1152     const std::string &name(void) const {return _clipName;}
1153 
1154     /** @brief fetch the label */
1155     void getLabel(std::string &label) const;
1156 
1157     /** @brief fetch the labels */
1158     void getLabels(std::string &label, std::string &shortLabel, std::string &longLabel) const;
1159 
1160     /** @brief what is the pixel depth images will be given to us as */
1161     BitDepthEnum getPixelDepth(void) const;
1162 
1163     /** @brief what is the components images will be given to us as */
1164     PixelComponentEnum getPixelComponents(void) const;
1165 
1166     /** @brief get the number of components in the image */
1167     int getPixelComponentCount(void) const;
1168 
1169     /** @brief get the string representing the pixel components */
getPixelComponentsProperty(void)1170     std::string getPixelComponentsProperty(void) const { return _clipProps.propGetString(kOfxImageEffectPropComponents);}
1171 
1172     /** @brief what is the actual pixel depth of the clip */
1173     BitDepthEnum getUnmappedPixelDepth(void) const;
1174 
1175     /** @brief what is the component type of the clip */
1176     PixelComponentEnum getUnmappedPixelComponents(void) const;
1177 
1178     /** @brief get the string representing the pixel components */
getUnmappedPixelComponentsProperty(void)1179     std::string getUnmappedPixelComponentsProperty(void) const { return _clipProps.propGetString(kOfxImageClipPropUnmappedComponents);}
1180 
1181     /** @brief get the components in the image */
1182     PreMultiplicationEnum getPreMultiplication(void) const;
1183 
1184     /** @brief which spatial field comes first temporally */
1185     FieldEnum getFieldOrder(void) const;
1186 
1187     /** @brief is the clip connected */
1188     bool isConnected(void) const;
1189 
1190     /** @brief can the clip be continuously sampled */
1191     bool hasContinuousSamples(void) const;
1192 
1193     /** @brief get the scale factor that has been applied to this clip */
1194     double getPixelAspectRatio(void) const;
1195 
1196     /** @brief get the frame rate, in frames per second on this clip, after any clip preferences have been applied */
1197     double getFrameRate(void) const;
1198 
1199     /** @brief return the range of frames over which this clip has images, after any clip preferences have been applied */
1200     OfxRangeD getFrameRange(void) const;
1201 
1202     /** @brief get the frame rate, in frames per second on this clip, before any clip preferences have been applied */
1203     double getUnmappedFrameRate(void) const;
1204 
1205     /** @brief return the range of frames over which this clip has images, before any clip preferences have been applied */
1206     OfxRangeD getUnmappedFrameRange(void) const;
1207 
1208     /** @brief get the RoD for this clip in the cannonical coordinate system */
1209     OfxRectD getRegionOfDefinition(double t);
1210 
1211 #ifdef OFX_EXTENSIONS_RESOLVE
1212     /** @brief is the clip for thumbnail */
1213     bool isForThumbnail(void) const;
1214 #endif
1215 
1216 #ifdef OFX_EXTENSIONS_NUKE
1217 
1218     /** @brief get the RoD for this clip in the cannonical coordinate system for the given view */
1219     OfxRectD getRegionOfDefinition(double t, int view);
1220 
1221     /** @brief fetch an image for the given plane and view
1222 
1223     When finished with, the client code must delete the image.
1224 
1225     If the same image is fetched twice, it must be deleted in each case, they will not be the same pointer.
1226     */
1227     Image* fetchImagePlane(double t, int view, const char* plane);
1228 
1229     /** @brief fetch an image plane, with a specific region in cannonical coordinates
1230 
1231     When finished with, the client code must delete the image.
1232 
1233     If the same image is fetched twice, it must be deleted in each case, they will not be the same pointer.
1234     */
1235     Image* fetchImagePlane(double t, int view, const char* plane, const OfxRectD& bounds);
1236 
1237     /** @brief fetch an image for the given plane and view
1238 
1239     When finished with, the client code must delete the image.
1240 
1241     If the same image is fetched twice, it must be deleted in each case, they will not be the same pointer.
1242     */
1243     Image* fetchImagePlane(double t, const char* plane);
1244 
1245     /** @brief fetch an image plane, with a specific region in cannonical coordinates
1246 
1247     When finished with, the client code must delete the image.
1248 
1249     If the same image is fetched twice, it must be deleted in each case, they will not be the same pointer.
1250     */
1251     Image* fetchImagePlane(double t, const char* plane, const OfxRectD& bounds);
1252 
1253     /** @brief Indicates the planes present on a clip.*/
1254     void getPlanesPresent(std::vector<std::string>* components) const;
1255 
1256 #endif
1257 
1258 #ifdef OFX_EXTENSIONS_VEGAS
1259     /** @brief get the pixel order of this image */
1260     PixelOrderEnum getPixelOrder(void) const;
1261 #endif
1262 
1263     /** @brief fetch an image
1264 
1265     When finished with, the client code must delete the image.
1266 
1267     If the same image is fetched twice, it must be deleted in each case, they will not be the same pointer.
1268     */
1269     Image *fetchImage(double t);
1270 
1271 #if defined(OFX_EXTENSIONS_VEGAS) || defined(OFX_EXTENSIONS_NUKE)
1272     /** @brief fetch an image
1273 
1274     When finished with, the client code must delete the image.
1275 
1276     If the same image is fetched twice, it must be deleted in each case, they will not be the same pointer.
1277     */
1278     Image *fetchStereoscopicImage(double t, int view);
1279 #endif
1280 
1281     /** @brief fetch an image, with a specific region in cannonical coordinates
1282 
1283     When finished with, the client code must delete the image.
1284 
1285     If the same image is fetched twice, it must be deleted in each case, they will not be the same pointer.
1286     */
1287     Image *fetchImage(double t, const OfxRectD &bounds);
1288 
1289     /** @brief fetch an image, with a specific region in cannonical coordinates
1290 
1291     When finished with, the client code must delete the image.
1292 
1293     If the same image is fetched twice, it must be deleted in each case, they will not be the same pointer.
1294     */
fetchImage(double t,const OfxRectD * bounds)1295     Image *fetchImage(double t, const OfxRectD *bounds)
1296     {
1297       if(bounds)
1298         return fetchImage(t, *bounds);
1299       else
1300         return fetchImage(t);
1301     }
1302 
1303 #ifdef OFX_SUPPORTS_OPENGLRENDER
1304     Texture *loadTexture(double t, BitDepthEnum format = eBitDepthNone, const OfxRectD *region = NULL);
1305 #endif
1306   };
1307 
1308 #ifdef OFX_EXTENSIONS_NUKE
1309   ////////////////////////////////////////////////////////////////////////////////
1310   /** @brief Wraps up a camera instance */
1311   class Camera {
1312   protected :
1313     mDeclareProtectedAssignAndCC(Camera);
1314 
1315     /** @brief name of the camera */
1316     std::string _cameraName;
1317 
1318     /** @brief properties for this camera */
1319     PropertySet _cameraProps;
1320 
1321     /** @brief handle for this camera */
1322     NukeOfxCameraHandle _cameraHandle;
1323 
1324     /** @brief effect instance that owns this camera */
1325     ImageEffect *_effect;
1326 
1327     /** @brief hidden constructor */
1328     Camera(ImageEffect *effect, const std::string &name, NukeOfxCameraHandle handle, OfxPropertySetHandle props);
1329 
1330     /** @brief so one can be made */
1331     friend class ImageEffect;
1332 
1333   public :
1334     /// get the underlying property set on this camera
getPropertySet()1335     const PropertySet &getPropertySet() const {return _cameraProps;}
1336 
1337     /// get the underlying property set on this camera
getPropertySet()1338     PropertySet &getPropertySet() {return _cameraProps;}
1339 
1340     /** @brief returns the camera name */
getName(void)1341     const std::string &getName(void) const {return _cameraName;}
1342 
1343 #ifdef OFX_EXTENSIONS_NATRON
1344     /** @brief set the label property in a camera */
1345     void setLabel(const std::string &label);
1346 
1347     /** @brief set the label properties in a camera */
1348     void setLabels(const std::string &label, const std::string &shortLabel, const std::string &longLabel);
1349 
1350     /** @brief set the secretness of the camera, defaults to false */
1351     void setIsSecret(bool v);
1352 
1353     /** @brief set the camera hint */
1354     void setHint(const std::string &hint);
1355 
1356     /** @brief set the camera hint */
1357     void setLabelAndHint(const std::string &label, const std::string &hint);
1358 #endif
1359 
1360     /// get the OFX camera handle
getHandle()1361     NukeOfxCameraHandle getHandle() {return _cameraHandle;}
1362 
1363     /** @brief get the name */
name(void)1364     const std::string &name(void) const {return _cameraName;}
1365 
1366     /** @brief fetch the label */
1367     void getLabel(std::string &label) const;
1368 
1369     /** @brief fetch the labels */
1370     void getLabels(std::string &label, std::string &shortLabel, std::string &longLabel) const;
1371 
1372     /** @brief is the camera connected */
1373     bool isConnected(void) const;
1374 
1375     /** @brief Get an arbitrary camera parameter for a given time and view
1376 
1377      \arg camera       - the handle of the camera, as obtained from cameraGetHandle
1378      \arg time         - the time to evaluate the parameter for
1379      \arg view         - the view to evaluate the parameter for
1380      \arg paramName    - parameter name to look up (matches name of knob in Nuke, see defines at top of \ref ofxCamera.h)
1381      \arg baseReturnAddress - base address to store the evaluated result
1382      \arg returnSize   - the number of doubles at the baseReturnAddress
1383      */
1384     void getParameter(const char* paramName, double time, int view, double* baseReturnAddress, int returnSize) const;
1385   };
1386 #endif
1387 
1388   ////////////////////////////////////////////////////////////////////////////////
1389   /** @brief Class that skins image memory allocation */
1390   class ImageMemory {
1391   protected :
1392     OfxImageMemoryHandle _handle;
1393 
1394   public :
1395     /** @brief ctor */
1396     ImageMemory(size_t nBytes, ImageEffect *associatedEffect = 0);
1397 
1398     /** @brief dtor */
1399     ~ImageMemory();
1400 
1401     /** @brief lock the memory and return a pointer to it */
1402     void *lock(void);
1403 
1404     /** @brief unlock the memory */
1405     void unlock(void);
1406   };
1407 
1408   ////////////////////////////////////////////////////////////////////////////////
1409   /** @brief POD struct to pass rendering arguments into @ref ImageEffect::render */
1410   struct RenderArguments {
1411     double    time;
1412     OfxPointD renderScale;
1413     OfxRectI  renderWindow;
1414     FieldEnum fieldToRender;
1415 #ifdef OFX_EXTENSIONS_RESOLVE
1416     bool      isEnabledOpenCLRender;
1417     bool      isEnabledCudaRender;
1418     void*     pOpenCLCmdQ;
1419 #endif
1420 #ifdef OFX_SUPPORTS_OPENGLRENDER
1421     bool      openGLEnabled;
1422 #ifdef OFX_EXTENSIONS_NATRON
1423     void*     openGLContextData;
1424 #endif
1425 #endif
1426 #ifdef OFX_EXTENSIONS_VEGAS
1427     int         viewsToRender;      /// default is 1, for stereoscopic 3d: 2
1428 #endif
1429 #if defined(OFX_EXTENSIONS_VEGAS) || defined(OFX_EXTENSIONS_NUKE)
1430     int         renderView;         /// default is 0, for s3d left eye: 0, right eye: 1
1431 #endif
1432 #ifdef OFX_EXTENSIONS_VEGAS
1433     VegasRenderQualityEnum renderQuality;
1434 #endif
1435     bool      sequentialRenderStatus;
1436     bool      interactiveRenderStatus;
1437     bool      renderQualityDraft;
1438 #ifdef OFX_EXTENSIONS_NUKE
1439     std::list<std::string> planes;
1440 #endif
1441   };
1442 
1443   /** @brief POD struct to pass rendering arguments into @ref OFX::ImageEffect::isIdentity */
1444   struct IsIdentityArguments {
1445     double    time;
1446     OfxPointD renderScale;
1447     OfxRectI  renderWindow;
1448     FieldEnum fieldToRender;
1449 #ifdef OFX_EXTENSIONS_NUKE
1450     int view;
1451     std::string plane;
1452 #endif
1453   };
1454 
1455   /** @brief POD struct to pass arguments into  @ref OFX::ImageEffect::beginSequenceRender */
1456   struct BeginSequenceRenderArguments {
1457     OfxRangeD frameRange;
1458     double    frameStep;
1459     bool      isInteractive;
1460     OfxPointD renderScale;
1461 #ifdef OFX_EXTENSIONS_RESOLVE
1462     bool      isEnabledOpenCLRender;
1463     bool      isEnabledCudaRender;
1464     void*     pOpenCLCmdQ;
1465 #endif
1466 #ifdef OFX_SUPPORTS_OPENGLRENDER
1467     bool      openGLEnabled;
1468 #ifdef OFX_EXTENSIONS_NATRON
1469     void*     openGLContextData;
1470 #endif
1471 #endif
1472     bool      sequentialRenderStatus;
1473     bool      interactiveRenderStatus;
1474     bool      renderQualityDraft;
1475 #ifdef OFX_EXTENSIONS_NUKE
1476     int view;
1477 #endif
1478   };
1479 
1480   /** @brief POD struct to pass arguments into  @ref OFX::ImageEffect::endSequenceRender */
1481   struct EndSequenceRenderArguments {
1482     bool      isInteractive;
1483     OfxPointD renderScale;
1484 #ifdef OFX_EXTENSIONS_RESOLVE
1485     bool      isEnabledOpenCLRender;
1486     bool      isEnabledCudaRender;
1487     void*     pOpenCLCmdQ;
1488 #endif
1489 #ifdef OFX_SUPPORTS_OPENGLRENDER
1490     bool      openGLEnabled;
1491 #ifdef OFX_EXTENSIONS_NATRON
1492     void*     openGLContextData;
1493 #endif
1494 #endif
1495     bool      sequentialRenderStatus;
1496     bool      interactiveRenderStatus;
1497     bool      renderQualityDraft;
1498 #ifdef OFX_EXTENSIONS_NUKE
1499     int view;
1500 #endif
1501   };
1502 
1503   /** @brief POD struct to pass arguments into  @ref OFX::ImageEffect::getRegionOfDefinition */
1504   struct RegionOfDefinitionArguments {
1505     double    time;
1506     OfxPointD renderScale;
1507 #ifdef OFX_EXTENSIONS_NUKE
1508     int view;
1509 #endif
1510   };
1511 
1512   /** @brief POD struct to pass arguments into @ref OFX::ImageEffect::getRegionsOfInterest */
1513   struct RegionsOfInterestArguments {
1514     double    time;
1515     OfxPointD renderScale;
1516     OfxRectD  regionOfInterest;
1517 #ifdef OFX_EXTENSIONS_NUKE
1518     int view;
1519 #endif
1520   };
1521 
1522 #ifdef OFX_EXTENSIONS_VEGAS
1523   /** @brief POD struct to pass arguments into @ref OFX::ImageEffect::upliftVegasKeyframes */
1524   class SonyVegasUpliftArguments {
1525   protected:
1526       /** @brief properties for this clip */
1527       PropertySet _argProps;
1528 
1529   public:
1530 
1531       SonyVegasUpliftArguments(PropertySet args);
1532 
1533       std::string  guidUplift;
1534       int          keyframeCount;
1535       void*        commonData;
1536       int          commonDataSize;
1537 
1538       void*  getKeyframeData     (int keyframeIndex) const;
1539       int    getKeyframeDataSize (int keyframeIndex) const;
1540       double getKeyframeTime     (int keyframeIndex) const;
1541       VegasInterpolationEnum getKeyframeInterpolation (int keyframeIndex) const;
1542   };
1543 #endif
1544 
1545 #ifdef OFX_EXTENSIONS_NUKE
1546   /** @brief POD struct to pass arguments into @ref OFX::ImageEffect::getTransform */
1547   struct TransformArguments {
1548     double    time;
1549     OfxPointD renderScale;
1550     FieldEnum fieldToRender;
1551     bool      renderQualityDraft;
1552     int       renderView;
1553   };
1554 #endif
1555 
1556 #ifdef OFX_EXTENSIONS_NATRON
1557   /** @brief POD struct to pass arguments into @ref OFX::ImageEffect::getInverseDistortion */
1558   struct DistortionArguments {
1559     double    time;
1560     OfxPointD renderScale;
1561     FieldEnum fieldToRender;
1562     bool      renderQualityDraft;
1563     int       renderView;
1564   };
1565 #endif
1566 
1567   /** @brief Class used to set regions of interest on a clip in @ref OFX::ImageEffect::getRegionsOfInterest
1568 
1569   This is a base class, the actual class is private and you don't need to see the glue involved.
1570   */
1571   class RegionOfInterestSetter {
1572   public :
1573     /** @brief virtual destructor */
~RegionOfInterestSetter()1574     virtual ~RegionOfInterestSetter() {}
1575 
1576     /** @brief function to set the RoI of a clip, pass in the clip to set the RoI of, and the RoI itself */
1577     virtual void setRegionOfInterest(const Clip &clip, const OfxRectD &RoI) = 0;
1578   };
1579 
1580   /** @brief POD struct to pass arguments into @ref OFX::ImageEffect::getFramesNeeded */
1581   struct FramesNeededArguments {
1582     double    time;
1583   };
1584 
1585   /** @brief Class used to set the frames needed to render a single frame of a clip in @ref OFX::ImageEffect::getFramesNeeded
1586 
1587   This is a base class, the actual class is private and you don't need to see the glue involved.
1588   */
1589   class FramesNeededSetter {
1590   public :
1591     /** @brief virtual destructor */
~FramesNeededSetter()1592     virtual ~FramesNeededSetter() {}
1593 
1594     /** @brief function to set the frames needed on a clip, the range is min <= time <= max */
1595     virtual void setFramesNeeded(const Clip &clip, const OfxRangeD &range) = 0;
1596   };
1597 
1598 #ifdef OFX_EXTENSIONS_NUKE
1599   struct ClipComponentsArguments {
1600     double time;
1601     int view;
1602   };
1603 
1604   class ClipComponentsSetter {
1605 
1606       OFX::PropertySet _outArgs;
1607       bool _doneSomething;
1608       typedef std::map<std::string, std::string> StringStringMap;
1609       const StringStringMap& _clipPlanesPropNames;
1610       std::map<std::string,std::vector<std::string> > _clipPlanes;
1611 
1612       const std::string& extractValueForName(const StringStringMap& m, const std::string& name);
1613 
1614   public:
1615 
ClipComponentsSetter(OFX::PropertySet props,const StringStringMap & clipPlanesPropNames)1616       ClipComponentsSetter(OFX::PropertySet props,
1617                            const StringStringMap& clipPlanesPropNames)
1618       : _outArgs(props)
1619       , _doneSomething(false)
1620       , _clipPlanesPropNames(clipPlanesPropNames)
1621       , _clipPlanes()
1622       {
1623 
1624       }
1625 
1626       bool setOutProperties();
1627 
1628       /**
1629        * @brief Pass a plane name defined in SupportExt/ofxsMultiPlane.h
1630        **/
1631       void addClipPlane(Clip& clip, const std::string& comps);
1632 
1633       //Pass NULL into clip for non pass-through
1634       void setPassThroughClip(const Clip* clip,double time,int view);
1635 
1636   };
1637 
1638   struct FrameViewsNeededArguments {
1639       double time;
1640       int view;
1641   };
1642 
1643   class FrameViewsNeededSetter {
1644       OFX::PropertySet _outArgs;
1645       bool _doneSomething;
1646       typedef std::map<std::string, std::string> StringStringMap;
1647       const StringStringMap& _clipFrameViewsPropnames;
1648 
1649       // For each clip and for each view a vector of ranges
1650       std::map<std::string, std::map<int, std::vector<OfxRangeD> > > _frameViews;
1651 
1652       const std::string& extractValueForName(const StringStringMap& m, const std::string& name);
1653   public:
1654 
FrameViewsNeededSetter(OFX::PropertySet props,const StringStringMap & clipFrameViewsPropNames)1655       FrameViewsNeededSetter(OFX::PropertySet props,
1656                              const StringStringMap& clipFrameViewsPropNames)
1657       : _outArgs(props)
1658       , _doneSomething(false)
1659       , _clipFrameViewsPropnames(clipFrameViewsPropNames)
1660       , _frameViews()
1661       {}
1662 
1663       bool setOutProperties();
1664 
1665       void addFrameViewsNeeded(const Clip& clip,const OfxRangeD &range, int view);
1666 
1667   };
1668 #endif
1669 
1670   /** @brief Class used to set the clip preferences of the effect.
1671   */
1672   class ClipPreferencesSetter {
1673     OFX::PropertySet outArgs_;
1674     bool doneSomething_;
1675     typedef std::map<std::string, std::string> StringStringMap;
1676     const StringStringMap& clipDepthPropNames_;
1677     const StringStringMap& clipComponentPropNames_;
1678     const StringStringMap& clipPARPropNames_;
1679     const std::string& extractValueForName(const StringStringMap& m, const std::string& name);
1680   public :
ClipPreferencesSetter(OFX::PropertySet props,const StringStringMap & depthPropNames,const StringStringMap & componentPropNames,const StringStringMap & PARPropNames)1681     ClipPreferencesSetter( OFX::PropertySet props,
1682       const StringStringMap& depthPropNames,
1683       const StringStringMap& componentPropNames,
1684       const StringStringMap& PARPropNames)
1685       : outArgs_(props)
1686       , doneSomething_(false)
1687       , clipDepthPropNames_(depthPropNames)
1688       , clipComponentPropNames_(componentPropNames)
1689       , clipPARPropNames_(PARPropNames)
1690     {}
1691 
didSomething(void)1692     bool didSomething(void) const {return doneSomething_;}
1693 
1694     /** @brief, force the host to set a clip's mapped component type to be \em comps.
1695 
1696     Only callable on non optional clips in all contexts. Must set comps to be one of the types the effect says it supports on the given clip.
1697 
1698     See the OFX API documentation for the default values of this.
1699     */
1700     void setClipComponents(Clip &clip, PixelComponentEnum comps);
1701 
1702     /** @brief, force the host to set a clip's mapped bit depth be \em bitDepth
1703 
1704     Only callable if the OFX::ImageEffectHostDescription::supportsMultipleClipDepths is true.
1705 
1706     See the OFX API documentation for the default values of this.
1707     */
1708     void setClipBitDepth(Clip &clip, BitDepthEnum bitDepth);
1709 
1710     /** @brief, force the host to set a clip's mapped Pixel Aspect Ratio to be \em PAR
1711 
1712     Only callable if the OFX::ImageEffectHostDescription::supportsMultipleClipPARs is true.
1713 
1714     Default is up to the host, generally based on the input clips.
1715 
1716     Not supported by most host applications.
1717     */
1718     void setPixelAspectRatio(Clip &clip, double PAR);
1719 
1720     /** @brief Allows an effect to change the output frame rate
1721 
1722     Only callable if OFX::ImageEffectHostDescription::supportsSetableFrameRate is true.
1723 
1724     Default is controlled by the host, typically the framerate of the input clips.
1725     */
1726     void setOutputFrameRate(double v);
1727 
1728     /** @brief Set the premultiplication state of the output clip.
1729 
1730     Defaults to the premultiplication state of ???
1731     */
1732     void setOutputPremultiplication(PreMultiplicationEnum v);
1733 
1734     /** @brief Set whether the effect can be continuously sampled.
1735 
1736     Defaults to false.
1737     */
1738     void setOutputHasContinuousSamples(bool v);
1739 
1740     /** @brief Sets whether the effect will produce different images in all frames, even if the no params or input images are varying (eg: a noise generator).
1741 
1742     Defaults to false.
1743     */
1744     void setOutputFrameVarying(bool v);
1745 
1746     /** @brief Sets the output fielding
1747 
1748     Default is host dependent, must be one of
1749     - eFieldNone,
1750     - eFieldLower,
1751     - eFieldUpper
1752     */
1753     void setOutputFielding(FieldEnum v);
1754 
1755 #ifdef OFX_EXTENSIONS_NATRON
1756     /** @brief Sets the output format in pixel coordinates.
1757      Default to first non optional input clip format
1758      */
1759     void setOutputFormat(const OfxRectI& format);
1760 #endif
1761   };
1762 
1763   /** @brief POD data structure passing in the instance changed args */
1764   struct InstanceChangedArgs {
1765     InstanceChangeReason reason;      /**< @brief why did it change */
1766     double               time;        /**< time of the change */
1767     OfxPointD            renderScale; /**< the renderscale on the instance */
1768   };
1769 
1770   /** @brief struct to pass arguments into @ref OFX::ImageEffect::interpolateCustomParam.
1771   It is non-POD (it contains std::string), but it is passed as const ref, so that does
1772   not matter */
1773   struct InterpolateCustomArgs {
1774     double      time;
1775     std::string value1;
1776     std::string value2;
1777     double      keytime1;
1778     double      keytime2;
1779     double      amount;
1780   };
1781 
1782   ////////////////////////////////////////////////////////////////////////////////
1783   /** @brief Wraps up an effect instance, plugin implementations need to inherit from this */
1784   class ImageEffect : public ParamSet
1785   {
1786   protected :
1787     mDeclareProtectedAssignAndCCBase(ImageEffect,ParamSet);
1788 
1789   private :
1790     /** @brief to get access to the effect handle without exposing it generally via a function */
1791     friend class ImageMemory;
1792 
1793     /** @brief The effect handle */
1794     OfxImageEffectHandle _effectHandle;
1795 
1796     /** @brief properties for this clip */
1797     PropertySet _effectProps;
1798 
1799     /** @brief the context of the effect */
1800     ContextEnum _context;
1801 
1802     /** @brief Set of all previously fetched clips, defined on demand */
1803     std::map<std::string, Clip *> _fetchedClips;
1804 
1805 #ifdef OFX_EXTENSIONS_NUKE
1806     /** @brief Set of all previously fetched cameras, defined on demand */
1807     std::map<std::string, Camera *> _fetchedCameras;
1808 #endif
1809 
1810     /** @brief the overlay interacts that are open on this image effect */
1811     std::list<OverlayInteract *> _overlayInteracts;
1812 
1813     /** @brief cached result of whether progress start succeeded. */
1814     bool _progressStartSuccess;
1815   public :
1816     /** @brief ctor */
1817     ImageEffect(OfxImageEffectHandle handle);
1818 
1819     /** @brief dtor */
1820     virtual ~ImageEffect();
1821 
getPropertySet()1822     const PropertySet &getPropertySet() const {return _effectProps;}
1823 
getPropertySet()1824     PropertySet &getPropertySet() {return _effectProps;}
1825 
1826 
getHandle(void)1827     OfxImageEffectHandle getHandle(void) const {return _effectHandle;}
1828 
1829     /** @brief the context this effect was instantiate in */
1830     ContextEnum getContext(void) const;
1831 
1832 #ifdef OFX_EXTENSIONS_VEGAS
1833     /** @brief the Vegas context this effect exists in */
1834     VegasContextEnum getVegasContext(void);
1835 #endif
1836 
1837     /** @brief size of the project */
1838     OfxPointD getProjectSize(void) const;
1839 
1840     /** @brief origin of the project */
1841     OfxPointD getProjectOffset(void) const;
1842 
1843     /** @brief extent of the project */
1844     OfxPointD getProjectExtent(void) const;
1845 
1846     /** @brief pixel aspect ratio of the project */
1847     double getProjectPixelAspectRatio(void) const;
1848 
1849     /** @brief how long does the effect last */
1850     double getEffectDuration(void) const;
1851 
1852     /** @brief the frame rate of the project */
1853     double getFrameRate(void) const;
1854 
1855     /** @brief is the instance currently being interacted with */
1856     bool isInteractive(void) const;
1857 
1858     /** @brief set the instance to be sequentially renderred, this should have been part of clip preferences! */
1859     void setSequentialRender(bool v);
1860 
1861     /** @brief Have we informed the host we want to be seqentially renderred ? */
1862     bool getSequentialRender(void) const;
1863 
1864     /** @brief Does the plugin support image tiling ? Can only be called from changedParam or changedClip. */
1865     void setSupportsTiles(bool v);
1866 
1867     /** @brief Have we informed the host we support image tiling ? */
1868     bool getSupportsTiles(void) const;
1869 
1870     /** @brief get plugin file path */
getPluginFilePath(void)1871     std::string getPluginFilePath(void) { return _effectProps.propGetString(kOfxPluginPropFilePath); }
1872 
1873 #ifdef OFX_EXTENSIONS_NUKE
1874     /** @brief indicate that a plugin or host can handle transform effects */
1875     void setCanTransform(bool v);
1876 
1877     bool getCanTransform() const;
1878 #endif
1879 
1880 #ifdef OFX_EXTENSIONS_NATRON
1881     /** @brief indicate that a plugin or host can handle distortion function effects */
1882     void setCanDistort(bool v);
1883 
1884     bool getCanDistort() const;
1885 
1886     /** @brief Returns a list of planes that were created by the user on the host side*/
1887     void getExtraneousPlanesCreated(std::vector<std::string>* planes) const;
1888 #endif
1889 
1890 #ifdef OFX_SUPPORTS_OPENGLRENDER
1891     /** @brief Does the plugin support OpenGL accelerated rendering (but is also capable of CPU rendering) ? Can only be called from changedParam or changedClip (OFX 1.4). */
1892     void setSupportsOpenGLRender(bool v);
1893 #endif
1894 
1895     /** @brief notify host that the internal data structures need syncing back to parameters for persistence and so on.  This is reset by the host after calling SyncPrivateData. */
1896     void setParamSetNeedsSyncing();
1897 
1898     OFX::Message::MessageReplyEnum sendMessage(OFX::Message::MessageTypeEnum type, const std::string& id, const std::string& msg, bool throwIfMissing = false);
1899 
1900     OFX::Message::MessageReplyEnum setPersistentMessage(OFX::Message::MessageTypeEnum type, const std::string& id, const std::string& msg, bool throwIfMissing = false);
1901     OFX::Message::MessageReplyEnum clearPersistentMessage(bool throwIfMissing = false);
1902 
1903 #ifdef OFX_SUPPORTS_DIALOG
1904     /** @brief Request the host to send a kOfxActionDialog to the plugin from its UI thread. */
1905     void requestDialog(OfxPropertySetHandle inArgs, void *instanceData);
1906 
1907     /** @brief Inform the host of redraw event so it can redraw itself */
1908     void notifyRedrawPending(OfxPropertySetHandle inArgs);
1909 #endif
1910 
1911     /** @brief Fetch the named clip from this instance
1912 
1913     The returned clip \em must not be deleted by the client code. This is all managed by the ImageEffect itself.
1914     */
1915     Clip *fetchClip(const std::string &name);
1916 
1917 #ifdef OFX_EXTENSIONS_NUKE
1918     /** @brief Fetch the named camera from this instance
1919 
1920     The returned camera param \em must not be deleted by the client code. This is all managed by the ImageEffect itself.
1921     */
1922     Camera* fetchCamera(const std::string& name);
1923 #endif
1924 
1925     /** @brief does the host want us to abort rendering? */
1926     bool abort(void) const;
1927 
1928     /** @brief adds a new interact to the set of interacts open on this effect */
1929     void addOverlayInteract(OverlayInteract *interact);
1930 
1931     /** @brief removes an interact to the set of interacts open on this effect */
1932     void removeOverlayInteract(OverlayInteract *interact);
1933 
1934     /** @brief force all overlays on this interact to be redrawn */
1935     void redrawOverlays(void);
1936 
1937 #ifdef OFX_SUPPORTS_OPENGLRENDER
1938     bool flushOpenGLResources(void);
1939 #endif
1940 
1941     ////////////////////////////////////////////////////////////////////////////////
1942     // these are actions that need to be overridden by a plugin that implements an effect host
1943 
1944     /** @brief The purge caches action, a request for an instance to free up as much memory as possible in low memory situations */
1945     virtual void purgeCaches(void);
1946 
1947     /** @brief The sync private data action, called when the effect needs to sync any private data to persistent parameters */
1948     virtual void syncPrivateData(void);
1949 
1950     /** @brief client render function, this is one of the few that must be overridden */
1951     virtual void render(const RenderArguments &args) = 0;
1952 
1953     /** @brief client begin sequence render function */
1954     virtual void beginSequenceRender(const BeginSequenceRenderArguments &args);
1955 
1956     /** @brief client end sequence render function */
1957     virtual void endSequenceRender(const EndSequenceRenderArguments &args);
1958 
1959     /** @brief client is identity function, returns the clip and time for the identity function
1960 
1961     If the effect would do no processing for the given param set and render arguments, then this
1962     function should return true and set the \em identityClip pointer to point to the clip that is the identity
1963     and \em identityTime to be the time at which to access the clip for the identity operation.
1964     */
1965     virtual bool isIdentity(const IsIdentityArguments &args, Clip * &identityClip, double &identityTime
1966 #ifdef OFX_EXTENSIONS_NUKE
1967     , int& view
1968     , std::string& plane
1969 #endif
1970     );
1971 
1972     /** @brief The get RoD action.
1973 
1974     If the effect wants change the rod from the default value (which is the union of RoD's of all input clips)
1975     it should set the \em rod argument and return true.
1976 
1977     This is all in cannonical coordinates.
1978     */
1979     virtual bool getRegionOfDefinition(const RegionOfDefinitionArguments &args, OfxRectD &rod);
1980 
1981     /** @brief the get region of interest action
1982 
1983     If the effect wants change its region of interest on any input clip from the default values (which is the same as the RoI in the arguments)
1984     it should do so by calling the OFX::RegionOfInterestSetter::setRegionOfInterest function on the \em rois argument.
1985 
1986     Note, everything is in \em cannonical \em coordinates.
1987     */
1988     virtual void getRegionsOfInterest(const RegionsOfInterestArguments &args, RegionOfInterestSetter &rois);
1989 
1990     /** @brief the get frames needed action
1991 
1992     If the effect wants change the frames needed on an input clip from the default values (which is the same as the frame to be renderred)
1993     it should do so by calling the OFX::FramesNeededSetter::setFramesNeeded function on the \em frames argument.
1994     */
1995     virtual void getFramesNeeded(const FramesNeededArguments &args, FramesNeededSetter &frames);
1996 
1997     /** @brief get the clip preferences */
1998     virtual void getClipPreferences(ClipPreferencesSetter &clipPreferences);
1999 
2000   protected:
2001 
2002     /** @brief To be used in the implementatino of getClipPreferences to retrieve the default values of the properties on the output clip.
2003      On some hosts, properties results may be cached. getClipPreferences is the action used to compute properties on the source clip and the output clip,
2004      however if in the implementation of getClipPreferences the code attempts to read one of those properties on the output clip this resolves in undefined
2005      behavior in the spec.
2006      To ensure that a plug-in may get the default properties before getClipPreferences is called, you may use the functions below
2007      */
2008     PixelComponentEnum getDefaultOutputClipComponents();
2009     BitDepthEnum getDefaultBitdepth();
2010 
2011   public:
2012 
2013     /** @brief the effect is about to be actively edited by a user, called when the first user interface is opened on an instance */
2014     virtual void beginEdit(void);
2015 
2016     /** @brief the effect is no longer being edited by a user, called when the last user interface is closed on an instance */
2017     virtual void endEdit(void);
2018 
2019     /** @brief the effect is about to have some values changed */
2020     virtual void beginChanged(InstanceChangeReason reason);
2021 
2022     /** @brief called when a param has just had its value changed */
2023     virtual void changedParam(const InstanceChangedArgs &args, const std::string &paramName);
2024 
2025     /** @brief called when a clip has just been changed in some way (a rewire maybe) */
2026     virtual void changedClip(const InstanceChangedArgs &args, const std::string &clipName);
2027 
2028     /** @brief the effect has just had some values changed */
2029     virtual void endChanged(InstanceChangeReason reason);
2030 
2031 #ifdef OFX_SUPPORTS_DIALOG
2032     /** @brief called in the host's UI thread after a plugin has requested a dialog @see requestDialog() */
2033     virtual void dialog(void *userData);
2034 #endif
2035 
2036 #ifdef OFX_EXTENSIONS_VEGAS
2037     /** @brief Vegas requires conversion of keyframe data */
2038     virtual void upliftVegasKeyframes(const SonyVegasUpliftArguments &upliftInfo);
2039 
2040     /** @brief Vegas invokes about dialog */
2041     virtual bool invokeAbout();
2042 
2043     /** @brief Vegas invokes help dialog */
2044     virtual bool invokeHelp();
2045 #endif
2046 
2047 #ifdef OFX_EXTENSIONS_NUKE
2048     /** @brief get the needed input components and produced output components*/
2049     virtual OfxStatus getClipComponents(const ClipComponentsArguments& args, ClipComponentsSetter& clipComponents);
2050 
2051     /** @brief get the frame/views needed for input clips*/
2052     virtual void getFrameViewsNeeded(const FrameViewsNeededArguments& args, FrameViewsNeededSetter& frameViews);
2053 
2054     /** @brief recover a transform matrix from an effect */
2055     virtual bool getTransform(const TransformArguments &args, Clip * &transformClip, double transformMatrix[9]);
2056 
2057     /** @brief Returns the textual representation of a view*/
2058     std::string getViewName(int viewIndex) const;
2059 
2060     /** @brief Returns the number of views*/
2061     int getViewCount() const;
2062 #endif
2063 
2064 #ifdef OFX_EXTENSIONS_NATRON
2065     /** @brief Implement if you effect can apply a 2D distortion.
2066      In the generic form, the distortion function pointer must be set and a pointer to the data that should be passed back
2067      to the function. A free function must also be provided to free the data once the host does not need them any more.
2068      This let a chance to the host to concatenate distortion effects together filter only once.
2069      @param distortionFunctionDataSizeHintInBytes This should indicate the size in bytes of the data held by distortionFunctionData.
2070      Since distortionFunctionData may contain the result of heavy computations (such as a STMap), the host will attempt to cache these data.
2071      However the void* does not indicate much to the host as to "how heavy" these datas are in its cache, so this parameter should hint
2072      the host of the size of these datas in bytes.
2073 
2074      If the effect distortion can be represented as a 3x3 matrix, then leave the function pointer to NULL and fill the transform matrix.
2075      This will enable the host to better concatenate the distortion in such cases where 3x3 matrices can be multiplied together instead
2076      of multiplying the transformation matrices for each pixel.
2077      */
2078     virtual bool getInverseDistortion(const DistortionArguments &args, Clip * &transformClip, double transformMatrix[9],
2079                                OfxInverseDistortionFunctionV1* distortionFunction,
2080                                void** distortionFunctionData,
2081                                int* distortionFunctionDataSizeHintInBytes,
2082                                OfxInverseDistortionDataFreeFunctionV1* freeDataFunction);
2083 #endif
2084 
2085     /** @brief called when a custom param needs to be interpolated */
2086     virtual std::string interpolateCustomParam(const InterpolateCustomArgs &args, const std::string &paramName);
2087 
2088     /** @brief what is the time domain of this effect, valid only in the general context
2089 
2090     return true is range was set, otherwise the default (the union of the time domain of all input clips) is used
2091     */
2092     virtual bool getTimeDomain(OfxRangeD &range);
2093 
2094 #ifdef OFX_SUPPORTS_OPENGLRENDER
2095     /** @brief OpenGL context attached (returns context-specific data if createContextData, or NULL if the plugin does not support multiple contexts) */
2096     virtual void* contextAttached(bool createContextData);
2097 
2098     /** @brief OpenGL context detached */
2099     virtual void contextDetached(void* contextData);
2100 #endif
2101 
2102     /// Start doing progress.
2103     void progressStart(const std::string &message, const std::string &messageid = "");
2104 
2105     /// finish yer progress
2106     void progressEnd();
2107 
2108     /// set the progress to some level of completion, returns
2109     /// false if you should abandon processing, true to continue
2110     bool progressUpdate(double t);
2111 
2112     /// get the current time on the timeline. This is not necessarily the same
2113     /// time as being passed to an action (eg render)
2114     double timeLineGetTime();
2115 
2116     /// set the timeline to a specific time
2117     void timeLineGotoTime(double t);
2118 
2119     /// get the first and last times available on the effect's timeline
2120     void timeLineGetBounds(double &t1, double &t2);
2121   };
2122 
2123 
2124   ////////////////////////////////////////////////////////////////////////////////
2125   /** @brief The OFX::Plugin namespace. All the functions in here needs to be defined by each plugin that uses the support libs.
2126   */
2127   namespace Plugin {
2128     /** @brief Plugin side function used to identify the plugin to the support library.
2129 
2130      This was obsoleted by automatic plugin registration, using the macro mRegisterPluginFactoryInstance:
2131      static BasicExamplePluginFactory p("net.sf.openfx.basicPlugin", 1, 0);
2132      mRegisterPluginFactoryInstance(p)
2133      */
2134     void getPluginIDs(OFX::PluginFactoryArray &id);
2135 
2136     /// If the client has defined its own exception type, allow it to catch it in the main function
2137 #ifdef OFX_CLIENT_EXCEPTION_TYPE
2138     OfxStatus catchException(OFX_CLIENT_EXCEPTION_TYPE &ex);
2139 #endif
2140   };
2141 
2142 };
2143 
2144 // undeclare the protected assign and CC macro
2145 #undef mDeclareProtectedAssignAndCC
2146 #undef mDeclareProtectedAssignAndCCBase
2147 
2148 #endif
2149