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