00001 #ifndef _ofxsImageEffect_H_
00002 #define _ofxsImageEffect_H_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00045 #include <map>
00046 #include <string>
00047 #include <sstream>
00048 #include "ofxsParam.h"
00049 #include "ofxsInteract.h"
00050 #include "ofxsMessage.h"
00051 #include "ofxProgress.h"
00052 #include "ofxTimeLine.h"
00053
00055 #define mDeclareProtectedAssignAndCC(CLASS) \
00056 CLASS &operator=(const CLASS &v1) {assert(false); return *this;} \
00057 CLASS(const CLASS &v) {assert(false); }
00058
00059 namespace OFX
00060 {
00061 namespace Private
00062 {
00063 OfxStatus mainEntryStr(const char *actionRaw,
00064 const void *handleRaw,
00065 OfxPropertySetHandle inArgsRaw,
00066 OfxPropertySetHandle outArgsRaw,
00067 const char* plugname);
00068 }
00069 }
00070
00071
00074 namespace OFX {
00076 class ClipDescriptor;
00077 class ImageEffectDescriptor;
00078
00079 class Image;
00080 class Clip;
00081 class ImageEffect;
00082 class ImageMemory;
00083
00085 enum ContextEnum {eContextNone,
00086 eContextGenerator,
00087 eContextFilter,
00088 eContextTransition,
00089 eContextPaint,
00090 eContextGeneral,
00091 eContextRetimer};
00092
00094 enum BitDepthEnum {eBitDepthNone,
00095 eBitDepthUByte,
00096 eBitDepthUShort,
00097 eBitDepthFloat,
00098 eBitDepthCustom
00099 };
00100
00102 enum PixelComponentEnum {ePixelComponentNone,
00103 ePixelComponentRGBA,
00104 ePixelComponentAlpha,
00105 ePixelComponentCustom
00106 };
00107
00109 enum FieldExtractionEnum {eFieldExtractBoth,
00110 eFieldExtractSingle,
00111 eFieldExtractDoubled
00112 };
00113
00115 enum RenderSafetyEnum {eRenderUnsafe,
00116 eRenderInstanceSafe,
00117 eRenderFullySafe
00118 };
00119
00121 enum FieldEnum {eFieldNone,
00122 eFieldBoth,
00123 eFieldLower,
00124 eFieldUpper
00125 };
00126
00127 enum PreMultiplicationEnum { eImageOpaque,
00128 eImagePreMultiplied,
00129 eImageUnPreMultiplied,
00130 };
00131
00132
00133 class PluginFactory
00134 {
00135 public:
00136 virtual void load() {}
00137 virtual void unload() {}
00138 virtual void describe(OFX::ImageEffectDescriptor &desc) = 0;
00139 virtual void describeInContext(OFX::ImageEffectDescriptor &desc, ContextEnum context) = 0;
00140 virtual ImageEffect* createInstance(OfxImageEffectHandle handle, ContextEnum context) = 0;
00141 virtual const std::string& getID() const = 0;
00142 virtual const std::string& getUID() const = 0;
00143 virtual unsigned int getMajorVersion() const = 0;
00144 virtual unsigned int getMinorVersion() const = 0;
00145 virtual OfxPluginEntryPoint* getMainEntry() = 0;
00146 };
00147
00148 template<class FACTORY>
00149 class FactoryMainEntryHelper
00150 {
00151 protected:
00152 const std::string& getHelperID() const { return _id; }
00153 unsigned int getHelperMajorVersion() const { return _maj; }
00154 unsigned int getHelperMinorVersion() const { return _min; }
00155 std::string toString(unsigned int val)
00156 {
00157 std::ostringstream ss;
00158 ss << val;
00159 return ss.str();
00160 }
00161 FactoryMainEntryHelper(const std::string& id, unsigned int maj, unsigned int min): _id(id), _maj(maj), _min(min)
00162 {
00163 _uid = id + toString(maj) + toString(min);
00164 }
00165 const std::string& getHelperUID() const { return _uid; }
00166 static OfxStatus mainEntry(const char *action, const void* handle, OfxPropertySetHandle in, OfxPropertySetHandle out)
00167 {
00168 return OFX::Private::mainEntryStr(action, handle, in, out, _uid.c_str());
00169 }
00170 static std::string _uid;
00171 std::string _id;
00172 unsigned int _maj;
00173 unsigned int _min;
00174 };
00175 template<class T> std::string OFX::FactoryMainEntryHelper<T>::_uid;
00176
00177 template<class FACTORY>
00178 class PluginFactoryHelper : public FactoryMainEntryHelper<FACTORY>, public PluginFactory
00179 {
00180 public:
00181 PluginFactoryHelper(const std::string& id, unsigned int maj, unsigned int min): FactoryMainEntryHelper<FACTORY>(id, maj, min)
00182 {}
00183 OfxPluginEntryPoint* getMainEntry() { return FactoryMainEntryHelper<FACTORY>::mainEntry; }
00184 const std::string& getID() const { return FactoryMainEntryHelper<FACTORY>::getHelperID(); }
00185 const std::string& getUID() const { return FactoryMainEntryHelper<FACTORY>::getHelperUID(); }
00186 unsigned int getMajorVersion() const { return FactoryMainEntryHelper<FACTORY>::getHelperMajorVersion(); }
00187 unsigned int getMinorVersion() const { return FactoryMainEntryHelper<FACTORY>::getHelperMinorVersion(); }
00188 };
00189
00190 #define mDeclarePluginFactory(CLASS, LOADFUNCDEF, UNLOADFUNCDEF) \
00191 class CLASS : public OFX::PluginFactoryHelper<CLASS> \
00192 { \
00193 public: \
00194 CLASS(const std::string& id, unsigned int verMaj, unsigned int verMin):OFX::PluginFactoryHelper<CLASS>(id, verMaj, verMin){} \
00195 virtual void load() LOADFUNCDEF ;\
00196 virtual void unload() UNLOADFUNCDEF ;\
00197 virtual void describe(OFX::ImageEffectDescriptor &desc); \
00198 virtual void describeInContext(OFX::ImageEffectDescriptor &desc, OFX::ContextEnum context); \
00199 virtual OFX::ImageEffect* createInstance(OfxImageEffectHandle handle, OFX::ContextEnum context); \
00200 };
00201
00202 typedef std::vector<PluginFactory*> PluginFactoryArray;
00203
00209 void * fetchSuite(char *suiteName, int suiteVersion, bool optional = false);
00210
00212
00213 struct ImageEffectHostDescription {
00214 public :
00215 std::string hostName;
00216 bool hostIsBackground;
00217 bool supportsOverlays;
00218 bool supportsMultiResolution;
00219 bool supportsTiles;
00220 bool temporalClipAccess;
00221 bool supportsMultipleClipDepths;
00222 bool supportsMultipleClipPARs;
00223 bool supportsSetableFrameRate;
00224 bool supportsSetableFielding;
00225 bool supportsStringAnimation;
00226 bool supportsCustomInteract;
00227 bool supportsChoiceAnimation;
00228 bool supportsBooleanAnimation;
00229 bool supportsCustomAnimation;
00230 int maxParameters;
00231 int maxPages;
00232 int pageRowCount;
00233 int pageColumnCount;
00234 typedef std::vector<PixelComponentEnum> PixelComponentArray;
00235 PixelComponentArray _supportedComponents;
00236 typedef std::vector<ContextEnum> ContextArray;
00237 ContextArray _supportedContexts;
00238 typedef std::vector<BitDepthEnum> PixelDepthArray;
00239 PixelDepthArray _supportedPixelDepths;
00240 bool supportsProgressSuite;
00241 bool supportsTimeLineSuite;
00242 };
00243
00244
00246 ImageEffectHostDescription* getImageEffectHostDescription();
00247
00249
00250 class ClipDescriptor {
00251 protected :
00252 mDeclareProtectedAssignAndCC(ClipDescriptor);
00253 ClipDescriptor(void) {assert(false);}
00254
00255 protected :
00257 std::string _clipName;
00258
00260 PropertySet _clipProps;
00261
00262 protected :
00264 ClipDescriptor(const std::string &name, OfxPropertySetHandle props);
00265
00266 friend class ImageEffectDescriptor;
00267
00268 public :
00269 const PropertySet &getPropertySet() const {return _clipProps;}
00270
00271 PropertySet &getPropertySet() {return _clipProps;}
00272
00273
00275 void setLabels(const std::string &label, const std::string &shortLabel, const std::string &longLabel);
00276
00278 void setFieldExtraction(FieldExtractionEnum v);
00279
00281 void addSupportedComponent(PixelComponentEnum v);
00282
00285 void addSupportedComponent(const std::string &comp);
00286
00288 void setTemporalClipAccess(bool v);
00289
00291 void setOptional(bool v);
00292
00294 void setSupportsTiles(bool v);
00295
00297 void setIsMask(bool v);
00298 };
00299
00301
00302 class ImageEffectDescriptor : public ParamSetDescriptor
00303 {
00304 protected :
00305 mDeclareProtectedAssignAndCC(ImageEffectDescriptor);
00306 ImageEffectDescriptor(void) {assert(false);}
00307
00308 protected :
00310 OfxImageEffectHandle _effectHandle;
00311
00313 PropertySet _effectProps;
00314
00316 std::map<std::string, ClipDescriptor *> _definedClips;
00317
00319 std::map<std::string, std::string> _clipComponentsPropNames;
00320 std::map<std::string, std::string> _clipDepthPropNames;
00321 std::map<std::string, std::string> _clipPARPropNames;
00322 std::map<std::string, std::string> _clipROIPropNames;
00323 std::map<std::string, std::string> _clipFrameRangePropNames;
00324
00325 std::auto_ptr<EffectOverlayDescriptor> _overlayDescriptor;
00326 public :
00328 ImageEffectDescriptor(OfxImageEffectHandle handle);
00329
00331 ~ImageEffectDescriptor();
00332
00333 const PropertySet &getPropertySet() const {return _effectProps;}
00334
00335 PropertySet &getPropertySet() {return _effectProps;}
00336
00338 void setLabels(const std::string &label, const std::string &shortLabel, const std::string &longLabel);
00339
00341 void setPluginGrouping(const std::string &group);
00342
00344 void addSupportedContext(ContextEnum v);
00345
00347 void addSupportedBitDepth(BitDepthEnum v);
00348
00350 void setSingleInstance(bool v);
00351
00353 void setHostFrameThreading(bool v);
00354
00356 void setSupportsMultiResolution(bool v);
00357
00359 void setSupportsTiles(bool v);
00360
00362 void setTemporalClipAccess(bool v);
00363
00365 void setRenderTwiceAlways(bool v);
00366
00368 void setSupportsMultipleClipDepths(bool v);
00369
00371 void setSupportsMultipleClipPARs(bool v);
00372
00374 void setRenderThreadSafety(RenderSafetyEnum v);
00375
00377 void addClipPreferencesSlaveParam(ParamDescriptor &p);
00378
00383 ClipDescriptor *defineClip(const std::string &name);
00384
00388 const std::map<std::string, std::string>& getClipComponentPropNames() const { return _clipComponentsPropNames; }
00389 const std::map<std::string, std::string>& getClipDepthPropNames() const { return _clipDepthPropNames; }
00390 const std::map<std::string, std::string>& getClipPARPropNames() const { return _clipPARPropNames; }
00391 const std::map<std::string, std::string>& getClipROIPropNames() const { return _clipROIPropNames; }
00392 const std::map<std::string, std::string>& getClipFrameRangePropNames() const { return _clipFrameRangePropNames; }
00393
00395 virtual void setOverlayInteractDescriptor(EffectOverlayDescriptor* desc);
00396 };
00397
00399
00400 class Image {
00401 protected :
00403 PropertySet _imageProps;
00404
00406 friend class Clip;
00407
00408 void *_pixelData;
00409 PixelComponentEnum _pixelComponents;
00410 int _rowBytes;
00411 int _pixelBytes;
00412 BitDepthEnum _pixelDepth;
00413 PreMultiplicationEnum _preMultiplication;
00414 OfxRectI _regionOfDefinition;
00415 OfxRectI _bounds;
00416 double _pixelAspectRatio;
00417 FieldEnum _field;
00418 std::string _uniqueID;
00419 OfxPointD _renderScale;
00421 public :
00423 Image(OfxPropertySetHandle props);
00424
00426 virtual ~Image();
00427
00428 const PropertySet &getPropertySet() const {return _imageProps;}
00429
00430 PropertySet &getPropertySet() {return _imageProps;}
00431
00433 BitDepthEnum getPixelDepth(void) const {return _pixelDepth;}
00434
00436 PixelComponentEnum getPixelComponents(void) const { return _pixelComponents;}
00437
00439 std::string getPixelComponentsProperty(void) const { return _imageProps.propGetString(kOfxImageEffectPropComponents);}
00440
00442 PreMultiplicationEnum getPreMultiplication(void) const { return _preMultiplication;}
00443
00445 OfxPointD getRenderScale(void) const { return _renderScale;}
00446
00448 double getPixelAspectRatio(void) const { return _pixelAspectRatio;}
00449
00451 void *getPixelData(void) const { return _pixelData;}
00452
00454 OfxRectI getRegionOfDefinition(void) const { return _regionOfDefinition;}
00455
00457 OfxRectI getBounds(void) const { return _bounds;}
00458
00460 int getRowBytes(void) const { return _rowBytes;}
00461
00463 FieldEnum getField(void) const { return _field;}
00464
00466 std::string getUniqueIdentifier(void) const { return _uniqueID;}
00467
00475 void *getPixelAddress(int x, int y);
00476 };
00477
00479
00480 class Clip {
00481 protected :
00482 mDeclareProtectedAssignAndCC(Clip);
00483
00485 std::string _clipName;
00486
00488 PropertySet _clipProps;
00489
00491 OfxImageClipHandle _clipHandle;
00492
00494 ImageEffect *_effect;
00495
00497 Clip(ImageEffect *effect, const std::string &name, OfxImageClipHandle handle, OfxPropertySetHandle props);
00498
00500 friend class ImageEffect;
00501
00502 public :
00504 const PropertySet &getPropertySet() const {return _clipProps;}
00505
00507 PropertySet &getPropertySet() {return _clipProps;}
00508
00510 OfxImageClipHandle getHandle() {return _clipHandle;}
00511
00513 const std::string &name(void) const {return _clipName;}
00514
00516 void getLabels(std::string &label, std::string &shortLabel, std::string &longLabel) const;
00517
00519 BitDepthEnum getPixelDepth(void) const;
00520
00522 PixelComponentEnum getPixelComponents(void) const;
00523
00525 std::string getPixelComponentsProperty(void) const { return _clipProps.propGetString(kOfxImageEffectPropComponents);}
00526
00528 BitDepthEnum getUnmappedPixelDepth(void) const;
00529
00531 PixelComponentEnum getUnmappedPixelComponents(void) const;
00532
00534 std::string getUnmappedPixelComponentsProperty(void) const { return _clipProps.propGetString(kOfxImageClipPropUnmappedComponents);}
00535
00537 PreMultiplicationEnum getPreMultiplication(void) const;
00538
00540 FieldEnum getFieldOrder(void) const;
00541
00543 bool isConnected(void) const;
00544
00546 bool hasContinuousSamples(void) const;
00547
00549 double getPixelAspectRatio(void) const;
00550
00552 double getFrameRate(void) const;
00553
00555 OfxRangeD getFrameRange(void) const;
00556
00558 double getUnmappedFrameRate(void) const;
00559
00561 OfxRangeD getUnmappedFrameRange(void) const;
00562
00564 OfxRectD getRegionOfDefinition(double t);
00565
00572 Image *fetchImage(double t);
00573
00580 Image *fetchImage(double t, OfxRectD bounds);
00581
00588 Image *fetchImage(double t, OfxRectD *bounds)
00589 {
00590 if(bounds)
00591 return fetchImage(t, *bounds);
00592 else
00593 return fetchImage(t);
00594 }
00595 };
00596
00598
00599 class ImageMemory {
00600 protected :
00601 OfxImageMemoryHandle _handle;
00602
00603 public :
00605 ImageMemory(size_t nBytes, ImageEffect *associatedEffect = 0);
00606
00608 ~ImageMemory();
00609
00611 void *lock(void);
00612
00614 void unlock(void);
00615 };
00616
00618
00619 struct RenderArguments {
00620 double time;
00621 OfxPointD renderScale;
00622 OfxRectI renderWindow;
00623 FieldEnum fieldToRender;
00624 };
00625
00627 struct BeginSequenceRenderArguments {
00628 OfxRangeD frameRange;
00629 double frameStep;
00630 bool isInteractive;
00631 OfxPointD renderScale;
00632 };
00633
00635 struct EndSequenceRenderArguments {
00636 bool isInteractive;
00637 OfxPointD renderScale;
00638 };
00639
00641 struct RegionOfDefinitionArguments {
00642 double time;
00643 OfxPointD renderScale;
00644 };
00645
00647 struct RegionsOfInterestArguments {
00648 double time;
00649 OfxPointD renderScale;
00650 OfxRectD regionOfInterest;
00651 };
00652
00657 class RegionOfInterestSetter {
00658 public :
00660 virtual void setRegionOfInterest(const Clip &clip, const OfxRectD &RoI) = 0;
00661 };
00662
00664 struct FramesNeededArguments {
00665 double time;
00666 };
00667
00672 class FramesNeededSetter {
00673 public :
00675 virtual void setFramesNeeded(const Clip &clip, const OfxRangeD &range) = 0;
00676 };
00677
00680 class ClipPreferencesSetter {
00681 OFX::PropertySet outArgs_;
00682 bool doneSomething_;
00683 typedef std::map<std::string, std::string> StringStringMap;
00684 const StringStringMap& clipDepthPropNames_;
00685 const StringStringMap& clipComponentPropNames_;
00686 const StringStringMap& clipPARPropNames_;
00687 const std::string& extractValueForName(const StringStringMap& m, const std::string& name);
00688 public :
00689 ClipPreferencesSetter( OFX::PropertySet props,
00690 const StringStringMap& depthPropNames,
00691 const StringStringMap& componentPropNames,
00692 const StringStringMap& PARPropNames)
00693 : outArgs_(props)
00694 , doneSomething_(false)
00695 , clipDepthPropNames_(depthPropNames)
00696 , clipComponentPropNames_(componentPropNames)
00697 , clipPARPropNames_(PARPropNames)
00698 {}
00699
00700 bool didSomething(void) const {return doneSomething_;}
00701
00708 void setClipComponents(Clip &clip, PixelComponentEnum comps);
00709
00716 void setClipBitDepth(Clip &clip, BitDepthEnum bitDepth);
00717
00726 void setPixelAspectRatio(Clip &clip, double PAR);
00727
00734 void setOutputFrameRate(double v);
00735
00740 void setOutputPremultiplication(PreMultiplicationEnum v);
00741
00746 void setOutputHasContinousSamples(bool v);
00747
00752 void setOutputFrameVarying(bool v);
00753
00761 void setOutputFielding(FieldEnum v);
00762 };
00763
00765 struct InstanceChangedArgs {
00766 InstanceChangeReason reason;
00767 double time;
00768 OfxPointD renderScale;
00769 };
00770
00772
00773 class ImageEffect : public ParamSet
00774 {
00775 protected :
00776 mDeclareProtectedAssignAndCC(ImageEffect);
00777
00778 private :
00780 friend class ImageMemory;
00781
00783 OfxImageEffectHandle _effectHandle;
00784
00786 PropertySet _effectProps;
00787
00789 ContextEnum _context;
00790
00792 std::map<std::string, Clip *> _fetchedClips;
00793
00795 std::list<OverlayInteract *> _overlayInteracts;
00796
00798 bool _progressStartSuccess;
00799 public :
00801 ImageEffect(OfxImageEffectHandle handle);
00802
00804 virtual ~ImageEffect();
00805
00806 const PropertySet &getPropertySet() const {return _effectProps;}
00807
00808 PropertySet &getPropertySet() {return _effectProps;}
00809
00810
00811 OfxImageEffectHandle getHandle(void) const {return _effectHandle;}
00812
00814 ContextEnum getContext(void) const;
00815
00817 OfxPointD getProjectSize(void) const;
00818
00820 OfxPointD getProjectOffset(void) const;
00821
00823 OfxPointD getProjectExtent(void) const;
00824
00826 double getProjectPixelAspectRatio(void) const;
00827
00829 double getEffectDuration(void) const;
00830
00832 double getFrameRate(void) const;
00833
00835 bool isInteractive(void) const;
00836
00838 void setSequentialRender(bool v);
00839
00841 bool getSequentialRender(void) const;
00842
00843 OFX::Message::MessageReplyEnum sendMessage(OFX::Message::MessageTypeEnum type, const std::string& id, const std::string& msg);
00844
00849 Clip *fetchClip(const std::string &name);
00850
00852 bool abort(void) const;
00853
00855 void addOverlayInteract(OverlayInteract *interact);
00856
00858 void removeOverlayInteract(OverlayInteract *interact);
00859
00861 void redrawOverlays(void);
00862
00864
00865
00867 virtual void purgeCaches(void);
00868
00870 virtual void syncPrivateData(void);
00871
00873 virtual void render(const RenderArguments &args) = 0;
00874
00876 virtual void beginSequenceRender(const BeginSequenceRenderArguments &args);
00877
00879 virtual void endSequenceRender(const EndSequenceRenderArguments &args);
00880
00887 virtual bool isIdentity(const RenderArguments &args, Clip * &identityClip, double &identityTime);
00888
00896 virtual bool getRegionOfDefinition(const RegionOfDefinitionArguments &args, OfxRectD &rod);
00897
00905 virtual void getRegionsOfInterest(const RegionsOfInterestArguments &args, RegionOfInterestSetter &rois);
00906
00912 virtual void getFramesNeeded(const FramesNeededArguments &args, FramesNeededSetter &frames);
00913
00915 virtual void getClipPreferences(ClipPreferencesSetter &clipPreferences);
00916
00918 virtual void beginEdit(void);
00919
00921 virtual void endEdit(void);
00922
00924 virtual void beginChanged(InstanceChangeReason reason);
00925
00927 virtual void changedParam(const InstanceChangedArgs &args, const std::string ¶mName);
00928
00930 virtual void changedClip(const InstanceChangedArgs &args, const std::string &clipName);
00931
00933 virtual void endChanged(InstanceChangeReason reason);
00934
00939 virtual bool getTimeDomain(OfxRangeD &range);
00940
00942 void progressStart(const std::string &message);
00943
00945 void progressEnd();
00946
00949 bool progressUpdate(double t);
00950
00953 double timeLineGetTime();
00954
00956 void timeLineGotoTime(double t);
00957
00959 void timeLineGetBounds(double &t1, double &t2);
00960 };
00961
00962
00964
00966 namespace Plugin {
00968 void getPluginID(OFX::PluginFactoryArray &id);
00969
00971 #ifdef OFX_CLIENT_EXCEPTION_TYPE
00972 OfxStatus catchException(OFX_CLIENT_EXCEPTION_TYPE &ex);
00973 #endif
00974 };
00975
00976 };
00977
00978
00979 #undef mDeclareProtectedAssignAndCC
00980
00981 #endif