1 2 /* 3 Software License : 4 5 Copyright (c) 2007-2009, The Open Effects Association Ltd. All Rights Reserved. 6 7 Redistribution and use in source and binary forms, with or without 8 modification, are permitted provided that the following conditions are met: 9 10 * Redistributions of source code must retain the above copyright notice, 11 this list of conditions and the following disclaimer. 12 * Redistributions in binary form must reproduce the above copyright notice, 13 this list of conditions and the following disclaimer in the documentation 14 and/or other materials provided with the distribution. 15 * Neither the name The Open Effects Association Ltd, nor the names of its 16 contributors may be used to endorse or promote products derived from this 17 software without specific prior written permission. 18 19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 23 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #ifndef OFX_CLIP_H 32 #define OFX_CLIP_H 33 34 #include "ofxImageEffect.h" 35 #include "ofxhUtilities.h" 36 37 namespace OFX { 38 39 namespace Host { 40 41 namespace ImageEffect { 42 // forward declarations 43 class Image; 44 class Instance; 45 # ifdef OFX_SUPPORTS_OPENGLRENDER 46 class Texture; 47 # endif 48 49 /// Base to both descriptor and instance it 50 /// is used to basically fetch common properties 51 /// by function name 52 class ClipBase { 53 protected : 54 Property::Set _properties; 55 56 public : 57 /// base ctor, for a descriptor 58 ClipBase(); 59 ~ClipBase()60 virtual ~ClipBase() { } 61 62 /// ctor, when copy constructing an instance from a descripto 63 explicit ClipBase(const ClipBase &other); 64 65 /// name of the clip getName()66 const std::string &getName() const 67 { 68 return _properties.getStringProperty(kOfxPropName); 69 } 70 71 /// name of the clip 72 const std::string &getShortLabel() const; 73 74 /// name of the clip 75 const std::string &getLabel() const; 76 77 /// name of the clip 78 const std::string &getLongLabel() const; 79 80 # ifdef OFX_EXTENSIONS_NATRON 81 /// doc of the clip 82 const std::string &getHint() const; 83 84 /// is the clip secret 85 bool isSecret() const; 86 # endif 87 88 /// return a std::vector of supported comp 89 const std::vector<std::string> &getSupportedComponents() const; 90 91 /// is the given component supported 92 bool isSupportedComponent(const std::string &comp) const; 93 94 /// does the clip do random temporal access 95 bool temporalAccess() const; 96 97 /// is the clip optional 98 bool isOptional() const; 99 100 /// is the clip a nominal 'mask' clip 101 bool isMask() const; 102 103 /// how does this clip like fielded images to be presented to it 104 const std::string &getFieldExtraction() const; 105 106 /// is the clip a nominal 'mask' clip 107 bool supportsTiles() const; 108 109 #ifdef OFX_EXTENSIONS_NUKE 110 /// can a kFnOfxPropMatrix2D be attached to images on this clip 111 bool canTransform() const; 112 #endif 113 114 #ifdef OFX_EXTENSIONS_NATRON 115 // can a distortion function be attached to images on this clip 116 bool canDistort() const; 117 #endif 118 119 /// get property set, const version 120 const Property::Set &getProps() const; 121 122 /// get property set , non const version 123 Property::Set &getProps(); 124 125 /// get a handle on the properties of the clip descriptor for the C api 126 OfxPropertySetHandle getPropHandle() const; 127 128 /// get a handle on the clip descriptor/instance for the C api 129 OfxImageClipHandle getHandle() const; 130 verifyMagic()131 virtual bool verifyMagic() { 132 return true; 133 } 134 }; 135 136 /// a clip descriptor 137 class ClipDescriptor : public ClipBase { 138 public: 139 /// constructor 140 ClipDescriptor(const std::string &name); 141 142 /// is the clip an output clip isOutput()143 bool isOutput() const {return getName() == kOfxImageEffectOutputClipName; } 144 }; 145 146 /// a clip instance 147 class ClipInstance : public ClipBase 148 , protected Property::GetHook 149 , protected Property::NotifyHook { 150 protected: 151 ImageEffect::Instance* _effectInstance; ///< image effect instance 152 bool _isOutput; ///< are we the output clip 153 std::string _pixelDepth; ///< what is the bit depth we is at. Set during the clip prefernces action. 154 std::string _components; ///< what components do we have. Set during the clip prefernces action. 155 156 public: 157 ClipInstance(ImageEffect::Instance* effectInstance, ClipDescriptor& desc); 158 159 # ifdef OFX_EXTENSIONS_NATRON 160 // callback which should set secret state as appropriate 161 virtual void setSecret(); 162 163 /// callback which should update label 164 virtual void setLabel(); 165 166 /// callback which should update hint 167 virtual void setHint(); 168 # endif 169 170 /// is the clip an output clip isOutput()171 bool isOutput() const {return _isOutput;} 172 173 /// notify override properties 174 virtual void notify(const std::string &name, bool isSingle, int indexOrN) OFX_EXCEPTION_SPEC; 175 176 /// get hook override 177 virtual void reset(const std::string &name) OFX_EXCEPTION_SPEC; 178 179 // get the virtuals for viewport size, pixel scale, background colour 180 virtual double getDoubleProperty(const std::string &name, int index) const OFX_EXCEPTION_SPEC; 181 182 // get the virtuals for viewport size, pixel scale, background colour 183 virtual void getDoublePropertyN(const std::string &name, double *values, int count) const OFX_EXCEPTION_SPEC; 184 185 // get the virtuals for viewport size, pixel scale, background colour 186 virtual int getIntProperty(const std::string &name, int index) const OFX_EXCEPTION_SPEC; 187 188 // get the virtuals for viewport size, pixel scale, background colour 189 virtual void getIntPropertyN(const std::string &name, int *values, int count) const OFX_EXCEPTION_SPEC; 190 191 // get the virtuals for viewport size, pixel scale, background colour 192 virtual const std::string &getStringProperty(const std::string &name, int index) const OFX_EXCEPTION_SPEC; 193 194 // fetch multiple values in a multi-dimension property 195 virtual void getStringPropertyN(const std::string &name, const char** values, int count) const OFX_EXCEPTION_SPEC; 196 197 // get hook virtuals 198 virtual int getDimension(const std::string &name) const OFX_EXCEPTION_SPEC; 199 200 // instance changed action 201 OfxStatus instanceChangedAction(const std::string &why, 202 OfxTime time, 203 OfxPointD renderScale); 204 205 // properties of an instance that are live 206 207 /// Pixel Depth - fetch depth of all chromatic component in this clip 208 /// 209 /// kOfxBitDepthNone (implying a clip is unconnected, not valid for an image) 210 /// kOfxBitDepthByte 211 /// kOfxBitDepthShort 212 /// kOfxBitDepthHalf 213 /// kOfxBitDepthFloat 214 virtual const std::string &getPixelDepth() const; 215 216 /// set the current pixel depth 217 /// called by clip preferences action 218 void setPixelDepth(const std::string &s); 219 220 /// Components that can be fetched from this clip - 221 /// 222 /// kOfxImageComponentNone (implying a clip is unconnected, not valid for an image) 223 /// kOfxImageComponentRGBA 224 /// kOfxImageComponentRGB 225 /// kOfxImageComponentAlpha 226 /// and any custom ones you may think of 227 virtual const std::string &getComponents() const; 228 229 /// set the current set of components 230 /// called by clip preferences action 231 virtual void setComponents(const std::string &s); 232 233 #ifdef OFX_EXTENSIONS_NUKE 234 /// Returns the components present on the effect. Much like getComponents() it can also 235 /// return components from other planes. 236 /// Returns a vector since the function getStringPropertyN does not exist. Only getStringProperty 237 /// with an index exists. 238 virtual const std::vector<std::string>& getComponentsPresent() const OFX_EXCEPTION_SPEC; 239 240 #endif 241 242 /// Get the Raw Unmapped Pixel Depth from the host for chromatic planes 243 /// 244 /// \returns 245 /// - kOfxBitDepthNone (implying a clip is unconnected image) 246 /// - kOfxBitDepthByte 247 /// - kOfxBitDepthShort 248 /// - kOfxBitDepthHalf 249 /// - kOfxBitDepthFloat 250 virtual const std::string &getUnmappedBitDepth() const = 0; 251 252 /// Get the Raw Unmapped Components from the host 253 /// 254 /// \returns 255 /// - kOfxImageComponentNone (implying a clip is unconnected, not valid for an image) 256 /// - kOfxImageComponentRGBA 257 /// - kOfxImageComponentAlpha 258 virtual const std::string &getUnmappedComponents() const = 0; 259 260 // PreMultiplication - 261 // 262 // kOfxImageOpaque - the image is opaque and so has no premultiplication state 263 // kOfxImagePreMultiplied - the image is premultiplied by it's alpha 264 // kOfxImageUnPreMultiplied - the image is unpremultiplied 265 virtual const std::string &getPremult() const = 0; 266 267 #ifdef OFX_EXTENSIONS_NATRON 268 // Format - 269 // The format of the clip or image (in pixel coordinates) 270 virtual OfxRectI getFormat() const = 0; 271 #endif 272 273 // Pixel Aspect Ratio - 274 // 275 // The pixel aspect ratio of a clip or image. 276 virtual double getAspectRatio() const = 0; 277 278 // Frame Rate - 279 // 280 // The frame rate of a clip or instance's project. 281 virtual double getFrameRate() const = 0; 282 283 // Frame Range (startFrame, endFrame) - 284 // 285 // The frame range over which a clip has images. 286 virtual void getFrameRange(double &startFrame, double &endFrame) const = 0; 287 288 /// Field Order - Which spatial field occurs temporally first in a frame. 289 /// \returns 290 /// - kOfxImageFieldNone - the clip material is unfielded 291 /// - kOfxImageFieldLower - the clip material is fielded, with image rows 0,2,4.... occuring first in a frame 292 /// - kOfxImageFieldUpper - the clip material is fielded, with image rows line 1,3,5.... occuring first in a frame 293 virtual const std::string &getFieldOrder() const = 0; 294 295 // Connected - 296 // 297 // Says whether the clip is actually connected at the moment. 298 virtual bool getConnected() const = 0; 299 300 // Unmapped Frame Rate - 301 // 302 // The unmapped frame rate. 303 virtual double getUnmappedFrameRate() const = 0; 304 305 // Unmapped Frame Range - 306 // 307 // The unmapped frame range over which an output clip has images. 308 virtual void getUnmappedFrameRange(double &unmappedStartFrame, double &unmappedEndFrame) const = 0; 309 310 // Continuous Samples - 311 // 312 // 0 if the images can only be sampled at discreet times (eg: the clip is a sequence of frames), 313 // 1 if the images can only be sampled continuously (eg: the clip is infact an animating roto spline and can be rendered anywhen). 314 virtual bool getContinuousSamples() const = 0; 315 316 /// override this to fill in the image at the given time. 317 /// The bounds of the image on the image plane should be 318 /// 'appropriate', typically the value returned in getRegionsOfInterest 319 /// on the effect instance. Outside a render call, the optionalBounds should 320 /// be 'appropriate' for the. 321 /// If bounds is not null, fetch the indicated section of the canonical image plane. 322 virtual ImageEffect::Image* getImage(OfxTime time, const OfxRectD *optionalBounds) = 0; 323 324 # ifdef OFX_EXTENSIONS_NUKE 325 326 /// override this to fill in the given image plane at the given time. 327 /// The bounds of the image on the image plane should be 328 /// 'appropriate', typically the value returned in getRegionsOfInterest 329 /// on the effect instance. 330 /// Outside a render call, the optionalBounds should 331 /// be 'appropriate' for the image. 332 /// If bounds is not null, fetch the indicated section of the canonical image plane. 333 /// 334 /// This function implements both V1 of the image plane suite and V2. In the V1 the parameter view was not present and 335 /// will be passed -1, indicating that you should on your own retrieve the correct index of the view at which the render called was issues 336 /// by using thread local storage. In V2 the view index will be correctly set with a value >= 0. 337 /// 338 virtual ImageEffect::Image* getImagePlane(OfxTime time, int view, const std::string& plane,const OfxRectD *optionalBounds) = 0; 339 340 /// override this to return the rod on the clip for the given view 341 virtual OfxRectD getRegionOfDefinition(OfxTime time, int view) const = 0; 342 343 # endif 344 345 # ifdef OFX_SUPPORTS_OPENGLRENDER 346 /// override this to fill in the OpenGL texture at the given time. 347 /// The bounds of the image on the image plane should be 348 /// 'appropriate', typically the value returned in getRegionsOfInterest 349 /// on the effect instance. Outside a render call, the optionalBounds should 350 /// be 'appropriate' for the. 351 /// If bounds is not null, fetch the indicated section of the canonical image plane. 352 virtual ImageEffect::Texture* loadTexture(OfxTime time, const char *format, const OfxRectD *optionalBounds) = 0; 353 # endif 354 # ifdef OFX_EXTENSIONS_VEGAS 355 /// override this to fill in the image at the given time from a specific view 356 /// (using the standard callback gets you the current view being rendered, @see getImage). 357 /// The bounds of the image on the image plane should be 358 /// 'appropriate', typically the value returned in getRegionsOfInterest 359 /// on the effect instance. Outside a render call, the optionalBounds should 360 /// be 'appropriate' for the. 361 /// If bounds is not null, fetch the indicated section of the canonical image plane. 362 virtual ImageEffect::Image* getStereoscopicImage(OfxTime time, int view, const OfxRectD *optionalBounds) = 0; 363 # endif 364 365 # if defined(OFX_EXTENSIONS_VEGAS) || defined(OFX_EXTENSIONS_NUKE) 366 /// override this to set the view to be returned by getImage() 367 /// This is called by Instance::renderAction() for each clip, before calling 368 /// kOfxImageEffectActionRender on the Instance. 369 /// The view number has to be stored in the Clip, so this is typically not thread-safe, 370 /// except if thread-local storage is used. 371 virtual void setView(int view) = 0; 372 # endif 373 374 /// override this to return the rod on the clip 375 virtual OfxRectD getRegionOfDefinition(OfxTime time) const = 0; 376 377 /// given the colour component, find the nearest set of supported colour components 378 /// override this for extra wierd custom component depths 379 virtual const std::string &findSupportedComp(const std::string &s) const; 380 }; 381 382 383 /// instance of an image inside an image effect 384 class ImageBase : public Property::Set { 385 protected : 386 /// called during ctors to get bits from the clip props into ours 387 void getClipBits(ClipInstance& instance); 388 int _referenceCount; ///< reference count on this image 389 390 public: 391 // default constructor 392 virtual ~ImageBase(); 393 394 /// basic ctor, makes empty property set but sets not value 395 ImageBase(); 396 397 /// construct from a clip instance, but leave the 398 /// filling it to the calling code via the propery set 399 explicit ImageBase(ClipInstance& instance); 400 401 // Render Scale (renderScaleX,renderScaleY) - 402 // 403 // The proxy render scale currently being applied. 404 // ------ 405 // Bounds (bx1,by1,bx2,by2) - 406 // 407 // The bounds of an image's pixels. The bounds, in PixelCoordinates, are of the 408 // addressable pixels in an image's data pointer. The order of the values is 409 // x1, y1, x2, y2. X values are x1 <= X < x2 Y values are y1 <= Y < y2 410 // ------ 411 // ROD (rodx1,rody1,rodx2,rody2) - 412 // 413 // The full region of definition. The ROD, in PixelCoordinates, are of the 414 // addressable pixels in an image's data pointer. The order of the values is 415 // x1, y1, x2, y2. X values are x1 <= X < x2 Y values are y1 <= Y < y2 416 // ------ 417 // Row Bytes - 418 // 419 // The number of bytes in a row of an image. 420 // ------ 421 // Field - 422 // 423 // kOfxImageFieldNone - the image is an unfielded frame 424 // kOfxImageFieldBoth - the image is fielded and contains both interlaced fields 425 // kOfxImageFieldLower - the image is fielded and contains a single field, being the lower field (rows 0,2,4...) 426 // kOfxImageFieldUpper - the image is fielded and contains a single field, being the upper field (rows 1,3,5...) 427 // ------ 428 // Unique Identifier - 429 // 430 // Uniquely labels an image. This is host set and allows a plug-in to differentiate between images. This is 431 // especially useful if a plugin caches analysed information about the image (for example motion vectors). The 432 // plugin can label the cached information with this identifier. If a user connects a different clip to the 433 // analysed input, or the image has changed in some way then the plugin can detect this via an identifier change 434 // and re-evaluate the cached information. 435 436 // construction based on clip instance 437 ImageBase(ClipInstance& instance, // construct from clip instance taking pixel depth, components, pre mult and aspect ratio 438 double renderScaleX, 439 double renderScaleY, 440 const OfxRectI &bounds, 441 const OfxRectI &rod, 442 int rowBytes, 443 std::string field, 444 std::string uniqueIdentifier); 445 446 // OfxImageClipHandle getHandle(); getPropHandle()447 OfxPropertySetHandle getPropHandle() const { return Property::Set::getHandle(); } 448 449 /// get the bounds of the pixels in memory 450 OfxRectI getBounds() const; 451 452 /// get the full region of this image 453 OfxRectI getROD() const; 454 455 /// release the reference count, which, if zero, deletes this 456 void releaseReference(); 457 458 /// add a reference to this image addReference()459 void addReference() {_referenceCount++;} 460 }; 461 462 /// instance of an image inside an image effect 463 class Image : public ImageBase { 464 public: 465 // default constructor 466 virtual ~Image(); 467 468 /// basic ctor, makes empty property set but sets not value 469 Image(); 470 471 /// construct from a clip instance, but leave the 472 /// filling it to the calling code via the propery set 473 explicit Image(ClipInstance& instance); 474 475 // Render Scale (renderScaleX,renderScaleY) - 476 // 477 // The proxy render scale currently being applied. 478 // ------ 479 // Data - 480 // 481 // The pixel data pointer of an image. 482 // ------ 483 // Bounds (bx1,by1,bx2,by2) - 484 // 485 // The bounds of an image's pixels. The bounds, in PixelCoordinates, are of the 486 // addressable pixels in an image's data pointer. The order of the values is 487 // x1, y1, x2, y2. X values are x1 <= X < x2 Y values are y1 <= Y < y2 488 // ------ 489 // ROD (rodx1,rody1,rodx2,rody2) - 490 // 491 // The full region of definition. The ROD, in PixelCoordinates, are of the 492 // addressable pixels in an image's data pointer. The order of the values is 493 // x1, y1, x2, y2. X values are x1 <= X < x2 Y values are y1 <= Y < y2 494 // ------ 495 // Row Bytes - 496 // 497 // The number of bytes in a row of an image. 498 // ------ 499 // Field - 500 // 501 // kOfxImageFieldNone - the image is an unfielded frame 502 // kOfxImageFieldBoth - the image is fielded and contains both interlaced fields 503 // kOfxImageFieldLower - the image is fielded and contains a single field, being the lower field (rows 0,2,4...) 504 // kOfxImageFieldUpper - the image is fielded and contains a single field, being the upper field (rows 1,3,5...) 505 // ------ 506 // Unique Identifier - 507 // 508 // Uniquely labels an image. This is host set and allows a plug-in to differentiate between images. This is 509 // especially useful if a plugin caches analysed information about the image (for example motion vectors). The 510 // plugin can label the cached information with this identifier. If a user connects a different clip to the 511 // analysed input, or the image has changed in some way then the plugin can detect this via an identifier change 512 // and re-evaluate the cached information. 513 514 // construction based on clip instance 515 Image(ClipInstance& instance, // construct from clip instance taking pixel depth, components, pre mult and aspect ratio 516 double renderScaleX, 517 double renderScaleY, 518 void* data, 519 const OfxRectI &bounds, 520 const OfxRectI &rod, 521 int rowBytes, 522 std::string field, 523 std::string uniqueIdentifier); 524 }; 525 526 # ifdef OFX_SUPPORTS_OPENGLRENDER 527 /// instance of an OpenGL texture inside an image effect 528 class Texture : public ImageBase { 529 public: 530 // default constructor 531 virtual ~Texture(); 532 533 /// basic ctor, makes empty property set but sets not value 534 Texture(); 535 536 /// construct from a clip instance, but leave the 537 /// filling it to the calling code via the propery set 538 explicit Texture(ClipInstance& instance); 539 540 // Render Scale (renderScaleX,renderScaleY) - 541 // 542 // The proxy render scale currently being applied. 543 // ------ 544 // Index - 545 // 546 // The texture id (cast to GLuint). 547 // ------ 548 // Target - 549 // 550 // The texture target (cast to GLenum). 551 // ------ 552 // Bounds (bx1,by1,bx2,by2) - 553 // 554 // The bounds of an image's pixels. The bounds, in PixelCoordinates, are of the 555 // addressable pixels in an image's data pointer. The order of the values is 556 // x1, y1, x2, y2. X values are x1 <= X < x2 Y values are y1 <= Y < y2 557 // ------ 558 // ROD (rodx1,rody1,rodx2,rody2) - 559 // 560 // The full region of definition. The ROD, in PixelCoordinates, are of the 561 // addressable pixels in an image's data pointer. The order of the values is 562 // x1, y1, x2, y2. X values are x1 <= X < x2 Y values are y1 <= Y < y2 563 // ------ 564 // Row Bytes - 565 // 566 // The number of bytes in a row of an image. 567 // ------ 568 // Field - 569 // 570 // kOfxImageFieldNone - the image is an unfielded frame 571 // kOfxImageFieldBoth - the image is fielded and contains both interlaced fields 572 // kOfxImageFieldLower - the image is fielded and contains a single field, being the lower field (rows 0,2,4...) 573 // kOfxImageFieldUpper - the image is fielded and contains a single field, being the upper field (rows 1,3,5...) 574 // ------ 575 // Unique Identifier - 576 // 577 // Uniquely labels an image. This is host set and allows a plug-in to differentiate between images. This is 578 // especially useful if a plugin caches analysed information about the image (for example motion vectors). The 579 // plugin can label the cached information with this identifier. If a user connects a different clip to the 580 // analysed input, or the image has changed in some way then the plugin can detect this via an identifier change 581 // and re-evaluate the cached information. 582 583 // construction based on clip instance 584 Texture(ClipInstance& instance, // construct from clip instance taking pixel depth, components, pre mult and aspect ratio 585 double renderScaleX, 586 double renderScaleY, 587 int index, 588 int target, 589 const OfxRectI &bounds, 590 const OfxRectI &rod, 591 int rowBytes, 592 std::string field, 593 std::string uniqueIdentifier); 594 }; 595 # endif 596 } // Memory 597 598 } // Host 599 600 } // OFX 601 602 #endif // OFX_CLIP_H 603