TuttleOFX  1
TuttleOFX/libraries/tuttle/src/tuttle/host/ofx/attribute/OfxhClipImage.hpp
Go to the documentation of this file.
00001 #ifndef _TUTTLE_HOST_OFX_ATTRIBUTE_CLIPIMAGE_HPP_
00002 #define _TUTTLE_HOST_OFX_ATTRIBUTE_CLIPIMAGE_HPP_
00003 
00004 #include "OfxhClip.hpp"
00005 #include "OfxhClipImageDescriptor.hpp"
00006 
00007 #include <tuttle/host/ofx/OfxhImage.hpp>
00008 
00009 #include <tuttle/common/ofx/imageEffect.hpp>
00010 
00011 #include <boost/serialization/serialization.hpp>
00012 #include <boost/serialization/nvp.hpp>
00013 #include <boost/serialization/export.hpp>
00014 #include <boost/ptr_container/ptr_vector.hpp>
00015 
00016 namespace tuttle {
00017 namespace host {
00018 namespace ofx {
00019 
00020 namespace imageEffect {
00021 using namespace ::tuttle::ofx::imageEffect;
00022 class OfxhImageEffectNode;
00023 class OfxhImageEffectNodeDescriptor;
00024 }
00025 namespace attribute {
00026 
00027 /**
00028  * @brief a clip image instance
00029  */
00030 class OfxhClipImage
00031         : public attribute::OfxhClip
00032         , virtual public OfxhClipImageAccessor
00033 {
00034 public:
00035         typedef OfxhClipImage This;
00036 
00037 public:
00038         OfxhClipImage( const attribute::OfxhClipImageDescriptor& desc );
00039         OfxhClipImage( const OfxhClipImage& other );
00040 
00041         virtual ~OfxhClipImage() {}
00042 
00043         bool operator==( const This& other ) const
00044         {
00045                 if( OfxhClip::operator!=( other ) )
00046                         return false;
00047                 return true;
00048         }
00049 
00050         bool operator!=( const This& other ) const { return !This::operator==( other ); }
00051 
00052         virtual OfxhClipImage* clone() const                    = 0;
00053         virtual std::string    getConnectedClipFullName() const = 0; ///< @todo tuttle: remove this!
00054         virtual std::string    getClipIdentifier() const = 0;
00055 
00056         /**
00057          * get a handle on the clip descriptor for the C api
00058          */
00059         OfxImageClipHandle getOfxImageClipHandle() const
00060         {
00061                 return ( OfxImageClipHandle ) this;
00062         }
00063 
00064         /**
00065          * @brief fetch depth of all chromatic component in this clip
00066          *
00067          *   kOfxBitDepthNone (implying a clip is unconnected, not valid for an image)
00068          *   kOfxBitDepthByte
00069          *   kOfxBitDepthShort
00070          *   kOfxBitDepthFloat
00071          */
00072         const std::string& getBitDepthString() const
00073         {
00074                 return getProperties().getStringProperty( kOfxImageEffectPropPixelDepth );
00075         }
00076 
00077         /**
00078          * @brief fetch depth of all chromatic component in this clip
00079          *
00080          * 0 (implying a clip is unconnected, not valid for an image),
00081          * 8,
00082          * 16,
00083          * 32
00084          */
00085         imageEffect::EBitDepth getBitDepth() const
00086         {
00087                 const std::string& s = getBitDepthString();
00088 
00089                 return imageEffect::mapBitDepthStringToEnum( s );
00090         }
00091         
00092         std::size_t getBitDepthMemorySize() const
00093         {
00094                 return imageEffect::bitDepthMemorySize( getBitDepth() );
00095         }
00096         
00097         std::size_t getPixelMemorySize() const
00098         {
00099                 return getBitDepthMemorySize() * getNbComponents();
00100         }
00101 
00102         /** set the current pixel depth
00103          * called by clip preferences action
00104          */
00105         void setBitDepthString( const std::string& s, const property::EModifiedBy modifiedBy = property::eModifiedByHost )
00106         {
00107                 property::String& prop = getEditableProperties().fetchLocalStringProperty( kOfxImageEffectPropPixelDepth );
00108 
00109                 prop.setValue( s, 0, modifiedBy );
00110         }
00111 
00112         void setBitDepth( const imageEffect::EBitDepth bitDepth, const property::EModifiedBy modifiedBy = property::eModifiedByHost )
00113         {
00114                 setBitDepthString( mapBitDepthEnumToString( bitDepth ), modifiedBy );
00115         }
00116 
00117         void setBitDepthStringIfUpper( const std::string& s )
00118         {
00119                 property::String& prop = getEditableProperties().fetchLocalStringProperty( kOfxImageEffectPropPixelDepth );
00120 
00121                 if( ofx::imageEffect::mapBitDepthStringToEnum( s ) > getBitDepth() ) // we can increase the bit depth but not decrease
00122                         prop.setValue( s );
00123         }
00124 
00125         void setBitDepthStringIfUpperAndNotModifiedByPlugin( const std::string& s )
00126         {
00127                 property::String& prop = getEditableProperties().fetchLocalStringProperty( kOfxImageEffectPropPixelDepth );
00128 
00129                 if( prop.getModifiedBy() != property::eModifiedByPlugin && // if not modified by plugin
00130                     ofx::imageEffect::mapBitDepthStringToEnum( s ) > getBitDepth() ) // we can increase the bit depth but not decrease
00131                         prop.setValue( s );
00132         }
00133 
00134         /** Pixel Aspect Ratio
00135          *  The pixel aspect ratio of a clip or image.
00136          */
00137         const double getPixelAspectRatio() const
00138         {
00139                 return getProperties().getDoubleProperty( kOfxImagePropPixelAspectRatio );
00140         }
00141 
00142         /**
00143          * set the current pixel aspect ratio
00144          * called by clip preferences action
00145          */
00146         void setPixelAspectRatio( const double& s, const property::EModifiedBy modifiedBy )
00147         {
00148                 property::Double& prop = getEditableProperties().fetchLocalDoubleProperty( kOfxImagePropPixelAspectRatio );
00149 
00150                 prop.setValue( s, 0, modifiedBy );
00151         }
00152 
00153         /** Components that can be fetched from this clip -
00154          *
00155          *  kOfxImageComponentNone (implying a clip is unconnected, not valid for an image)
00156          *  kOfxImageComponentRGBA
00157          *  kOfxImageComponentAlpha
00158          *  and any custom ones you may think of
00159          */
00160         const std::string& getComponentsString() const
00161         {
00162                 return getProperties().getStringProperty( kOfxImageEffectPropComponents );
00163         }
00164 
00165         /** Components that can be fetched from this clip -
00166          *
00167          *  kOfxImageComponentNone (implying a clip is unconnected, not valid for an image)
00168          *  kOfxImageComponentRGBA
00169          *  kOfxImageComponentRGB
00170          *  kOfxImageComponentAlpha
00171          *  and any custom ones you may think of
00172          */
00173         const imageEffect::EPixelComponent getComponents() const
00174         {
00175                 return imageEffect::mapPixelComponentStringToEnum( getComponentsString() );
00176         }
00177 
00178         /**
00179          * Number of values for this Components.
00180          */
00181         const std::size_t getNbComponents() const
00182         {
00183                 return imageEffect::numberOfComponents( getComponents() );
00184         }
00185 
00186         /**
00187          * set the current set of components
00188          * called by clip preferences action
00189          */
00190         void setComponentsString( const std::string& s, const property::EModifiedBy modifiedBy = property::eModifiedByHost )
00191         {
00192                 property::String& prop = getEditableProperties().fetchLocalStringProperty( kOfxImageEffectPropComponents );
00193 
00194                 prop.setValue( s, 0, modifiedBy );
00195         }
00196         void setComponents( const imageEffect::EPixelComponent& comp, const property::EModifiedBy modifiedBy = property::eModifiedByHost )
00197         {
00198                 setComponentsString( imageEffect::mapPixelComponentEnumToString( comp ), modifiedBy );
00199         }
00200         
00201         void setComponentsStringIfNotModifiedByPlugin( const std::string& s )
00202         {
00203                 property::String& prop = getEditableProperties().fetchLocalStringProperty( kOfxImageEffectPropComponents );
00204 
00205                 if( prop.getModifiedBy() != property::eModifiedByPlugin )
00206                         prop.setValue( s );
00207         }
00208 
00209         /** Get the Raw Unmapped Pixel Depth from the host for chromatic planes
00210          *
00211          *  @returns
00212          *     - kOfxBitDepthNone (implying a clip is unconnected image)
00213          *     - kOfxBitDepthByte
00214          *     - kOfxBitDepthShort
00215          *     - kOfxBitDepthFloat
00216          */
00217         virtual const std::string& getUnmappedBitDepth() const //= 0;
00218         {
00219                 return getProperties().getStringProperty( kOfxImageClipPropUnmappedPixelDepth );
00220         }
00221 
00222         /** Get the Raw Unmapped Components from the host
00223          *
00224          *  @returns
00225          *      - kOfxImageComponentNone (implying a clip is unconnected, not valid for an image)
00226          *      - kOfxImageComponentRGBA
00227          *      - kOfxImageComponentAlpha
00228          */
00229         virtual const std::string& getUnmappedComponents() const //= 0;
00230         {
00231                 return getProperties().getStringProperty( kOfxImageClipPropUnmappedComponents );
00232         }
00233 
00234         /** PreMultiplication -
00235          *
00236          *  kOfxImageOpaque - the image is opaque and so has no premultiplication state
00237          *  kOfxImagePreMultiplied - the image is premultiplied by it's alpha
00238          *  kOfxImageUnPreMultiplied - the image is unpremultiplied
00239          */
00240         virtual const std::string& getPremult() const //= 0;
00241         {
00242                 return getProperties().getStringProperty( kOfxImageEffectPropPreMultiplication );
00243         }
00244 
00245         /** Frame Rate -
00246          *
00247          *  The frame rate of a clip or instance's project.
00248          */
00249         virtual double getFrameRate() const //= 0;
00250         {
00251                 return getProperties().getDoubleProperty( kOfxImageEffectPropFrameRate );
00252         }
00253 
00254         /** Frame Range (startFrame, endFrame) -
00255          *
00256          *  The frame range over which a clip has images.
00257          */
00258         virtual void getFrameRange( double& startFrame, double& endFrame ) const //= 0;
00259         {
00260                 startFrame = getProperties().getDoubleProperty( kOfxImageEffectPropFrameRange, 0 );
00261                 endFrame   = getProperties().getDoubleProperty( kOfxImageEffectPropFrameRange, 1 );
00262         }
00263         
00264         OfxRangeD getFrameRange() const
00265         {
00266                 OfxRangeD frameRange;
00267                 getFrameRange( frameRange.min, frameRange.max );
00268                 return frameRange;
00269         }
00270 
00271         /**  Field Order - Which spatial field occurs temporally first in a frame.
00272          *  @returns
00273          *   - kOfxImageFieldNone - the clip material is unfielded
00274          *   - kOfxImageFieldLower - the clip material is fielded, with image rows 0,2,4.... occuring first in a frame
00275          *   - kOfxImageFieldUpper - the clip material is fielded, with image rows line 1,3,5.... occuring first in a frame
00276          */
00277         virtual const std::string& getFieldOrder() const //= 0;
00278         {
00279                 return getProperties().getStringProperty( kOfxImageClipPropFieldOrder );
00280         }
00281 
00282         /**
00283          * @todo tuttle: This function has been added here. Why was it not before?
00284          */
00285         virtual const std::string& getFieldExtraction() const //= 0;
00286         {
00287                 return getProperties().getStringProperty( kOfxImageClipPropFieldExtraction );
00288         }
00289 
00290         /** Unmapped Frame Rate -
00291          *
00292          *  The unmaped frame range over which an output clip has images.
00293          */
00294         virtual const double getUnmappedFrameRate() const //= 0;
00295         {
00296                 return getProperties().getDoubleProperty( kOfxImageEffectPropUnmappedFrameRate );
00297         }
00298 
00299         /** Unmapped Frame Range -
00300          *
00301          *  The unmaped frame range over which an output clip has images.
00302          */
00303         virtual void getUnmappedFrameRange( double& unmappedStartFrame, double& unmappedEndFrame ) const //= 0;
00304         {
00305                 unmappedStartFrame = getProperties().getDoubleProperty( kOfxImageEffectPropUnmappedFrameRange, 0 );
00306                 unmappedEndFrame   = getProperties().getDoubleProperty( kOfxImageEffectPropUnmappedFrameRange, 1 );
00307         }
00308 
00309         /** Continuous Samples -
00310          *
00311          *  0 if the images can only be sampled at discreet times (eg: the clip is a sequence of frames),
00312          *  1 if the images can only be sampled continuously (eg: the clip is infact an animating roto spline and can be rendered anywhen).
00313          */
00314         virtual const bool getContinuousSamples() const //= 0;
00315         {
00316                 return getProperties().getDoubleProperty( kOfxImageClipPropContinuousSamples ) != 0;
00317         }
00318 
00319         /**  override this to fill in the image at the given time.
00320          *  The bounds of the image on the image plane should be
00321          *  'appropriate', typically the value returned in getRegionsOfInterest
00322          *  on the effect instance. Outside a render call, the optionalBounds should
00323          *  be 'appropriate' for the.
00324          *  If bounds is not null, fetch the indicated section of the canonical image plane.
00325          */
00326         virtual tuttle::host::ofx::imageEffect::OfxhImage* getImage( const OfxTime time, const OfxRectD* optionalBounds = NULL ) = 0;
00327 
00328         /// override this to return the rod on the clip
00329         virtual OfxRectD fetchRegionOfDefinition( const OfxTime time ) const = 0;
00330 
00331         /** given the colour component, find the nearest set of supported colour components
00332          *  override this for extra wierd custom component depths
00333          */
00334         virtual const std::string& findSupportedComp( const std::string& s ) const;
00335 };
00336 
00337 #ifndef SWIG
00338 /**
00339  * @brief to make ClipImageInstance clonable (for use in boost::ptr_container)
00340  */
00341 inline OfxhClipImage* new_clone( const OfxhClipImage& a )
00342 {
00343         return a.clone();
00344 }
00345 
00346 #endif
00347 
00348 }
00349 }
00350 }
00351 }
00352 
00353 #ifndef SWIG
00354 // force boost::is_virtual_base_of value (used by boost::serialization)
00355 namespace boost {
00356 template<>
00357 struct is_virtual_base_of<tuttle::host::ofx::attribute::OfxhClip, tuttle::host::ofx::attribute::OfxhClipImage>: public mpl::true_ {};
00358 }
00359 #endif
00360 
00361 #endif