TuttleOFX  1
OfxhImageEffectSuite.cpp
Go to the documentation of this file.
00001 #include "OfxhImageEffectSuite.hpp"
00002 #include "OfxhImageEffectNode.hpp"
00003 
00004 namespace tuttle {
00005 namespace host {
00006 namespace ofx {
00007 namespace imageEffect {
00008 
00009 namespace {
00010 
00011 OfxStatus getPropertySet( OfxImageEffectHandle  h1,
00012                           OfxPropertySetHandle* h2 )
00013 {
00014         OfxhImageEffectNodeBase* effectBase = reinterpret_cast<OfxhImageEffectNodeBase*>( h1 );
00015 
00016         if( !effectBase || !effectBase->verifyMagic() )
00017         {
00018                 return kOfxStatErrBadHandle;
00019         }
00020 
00021         *h2 = effectBase->getProperties().getHandle();
00022         return kOfxStatOK;
00023 }
00024 
00025 OfxStatus getParamSet( OfxImageEffectHandle h1,
00026                        OfxParamSetHandle*   h2 )
00027 {
00028         imageEffect::OfxhImageEffectNodeBase* effectBase = reinterpret_cast<imageEffect::OfxhImageEffectNodeBase*>( h1 );
00029 
00030         if( !effectBase || !effectBase->verifyMagic() )
00031         {
00032                 return kOfxStatErrBadHandle;
00033         }
00034 
00035         imageEffect::OfxhImageEffectNodeDescriptor* effectDescriptor = dynamic_cast<imageEffect::OfxhImageEffectNodeDescriptor*>( effectBase );
00036 
00037         if( effectDescriptor )
00038         {
00039                 *h2 = effectDescriptor->getParamSetHandle();
00040                 return kOfxStatOK;
00041         }
00042 
00043         imageEffect::OfxhImageEffectNode* effectInstance = dynamic_cast<imageEffect::OfxhImageEffectNode*>( effectBase );
00044 
00045         if( effectInstance )
00046         {
00047                 *h2 = effectInstance->getParamSetHandle();
00048                 return kOfxStatOK;
00049         }
00050 
00051         return kOfxStatErrBadHandle;
00052 }
00053 
00054 OfxStatus clipDefine( OfxImageEffectHandle  h1,
00055                       const char*           name,
00056                       OfxPropertySetHandle* h2 )
00057 {
00058         imageEffect::OfxhImageEffectNodeBase* effectBase = reinterpret_cast<imageEffect::OfxhImageEffectNodeBase*>( h1 );
00059 
00060         if( !effectBase || !effectBase->verifyMagic() )
00061         {
00062                 return kOfxStatErrBadHandle;
00063         }
00064 
00065         imageEffect::OfxhImageEffectNodeDescriptor* effectDescriptor = dynamic_cast<imageEffect::OfxhImageEffectNodeDescriptor*>( effectBase );
00066 
00067         if( effectDescriptor )
00068         {
00069                 attribute::OfxhClipImageDescriptor* clip = effectDescriptor->defineClip( name );
00070                 *h2 = clip->getPropHandle();
00071                 return kOfxStatOK;
00072         }
00073 
00074         return kOfxStatErrBadHandle;
00075 }
00076 
00077 OfxStatus clipGetPropertySet( OfxImageClipHandle    clip,
00078                               OfxPropertySetHandle* propHandle )
00079 {
00080         attribute::OfxhClipImage* clipInstance = reinterpret_cast<attribute::OfxhClipImage*>( clip );
00081 
00082         if( !clipInstance || !clipInstance->verifyMagic() )
00083         {
00084                 return kOfxStatErrBadHandle;
00085         }
00086 
00087         if( clipInstance )
00088         {
00089                 *propHandle = clipInstance->getPropHandle();
00090                 return kOfxStatOK;
00091         }
00092 
00093         return kOfxStatErrBadHandle;
00094 }
00095 
00096 OfxStatus clipGetImage( OfxImageClipHandle    h1,
00097                         OfxTime               time,
00098                         OfxRectD*             h2,
00099                         OfxPropertySetHandle* h3 )
00100 {
00101         attribute::OfxhClipImage* clipInstance = reinterpret_cast<attribute::OfxhClipImage*>( h1 );
00102 
00103         if( !clipInstance || !clipInstance->verifyMagic() )
00104         {
00105                 return kOfxStatErrBadHandle;
00106         }
00107 
00108         OfxhImage* image = clipInstance->getImage( time, h2 );
00109         if( !image )
00110         {
00111                 h3 = NULL;
00112                 return kOfxStatFailed;
00113         }
00114 
00115         image->addReference( OfxhImage::eReferenceOwnerPlugin );
00116         *h3 = image->getPropHandle(); // a pointer to the base class cast into OfxPropertySetHandle
00117 
00118         return kOfxStatOK;
00119 }
00120 
00121 OfxStatus clipReleaseImage( OfxPropertySetHandle h1 )
00122 {
00123         property::OfxhSet* pset = reinterpret_cast<property::OfxhSet*>( h1 );
00124 
00125         if( !pset || !pset->verifyMagic() )
00126         {
00127                 return kOfxStatErrBadHandle;
00128         }
00129 
00130         OfxhImage* image = dynamic_cast<OfxhImage*>( pset );
00131         if( !image )
00132         {
00133                 return kOfxStatErrBadHandle;
00134         }
00135         // clip::image has a virtual destructor for derived classes
00136         image->releaseReference( OfxhImage::eReferenceOwnerPlugin );
00137         return kOfxStatOK;
00138 }
00139 
00140 OfxStatus clipGetHandle( OfxImageEffectHandle  imageEffect,
00141                          const char*           name,
00142                          OfxImageClipHandle*   clip,
00143                          OfxPropertySetHandle* propertySet )
00144 {
00145         imageEffect::OfxhImageEffectNodeBase* effectBase = reinterpret_cast<imageEffect::OfxhImageEffectNodeBase*>( imageEffect );
00146 
00147         if( !effectBase || !effectBase->verifyMagic() )
00148         {
00149                 return kOfxStatErrBadHandle;
00150         }
00151 
00152         imageEffect::OfxhImageEffectNode* effectInstance = reinterpret_cast<imageEffect::OfxhImageEffectNode*>( effectBase );
00153 
00154         if( effectInstance )
00155         {
00156                 attribute::OfxhClipImage& instance = effectInstance->getClip( name );
00157                 *clip = instance.getOfxImageClipHandle();
00158                 if( propertySet )
00159                         *propertySet = instance.getPropHandle();
00160                 return kOfxStatOK;
00161         }
00162 
00163         return kOfxStatErrBadHandle;
00164 }
00165 
00166 OfxStatus clipGetRegionOfDefinition( OfxImageClipHandle clip,
00167                                      OfxTime            time,
00168                                      OfxRectD*          bounds )
00169 {
00170         attribute::OfxhClipImage* clipInstance = reinterpret_cast<attribute::OfxhClipImage*>( clip );
00171 
00172         if( !clipInstance || !clipInstance->verifyMagic() )
00173         {
00174                 return kOfxStatErrBadHandle;
00175         }
00176 
00177         if( clipInstance )
00178         {
00179                 *bounds = clipInstance->fetchRegionOfDefinition( time );
00180                 return kOfxStatOK;
00181         }
00182 
00183         return kOfxStatErrBadHandle;
00184 }
00185 
00186 // should processing be aborted?
00187 
00188 int abort( OfxImageEffectHandle imageEffect )
00189 {
00190         imageEffect::OfxhImageEffectNodeBase* effectBase = reinterpret_cast<imageEffect::OfxhImageEffectNodeBase*>( imageEffect );
00191 
00192         if( !effectBase || !effectBase->verifyMagic() )
00193         {
00194                 return kOfxStatErrBadHandle;
00195         }
00196 
00197         imageEffect::OfxhImageEffectNode* effectInstance = dynamic_cast<imageEffect::OfxhImageEffectNode*>( effectBase );
00198 
00199         if( effectInstance )
00200                 return effectInstance->abort();
00201         else
00202                 return kOfxStatErrBadHandle;
00203 }
00204 
00205 OfxStatus imageMemoryAlloc( OfxImageEffectHandle  instanceHandle,
00206                             size_t                nBytes,
00207                             OfxImageMemoryHandle* memoryHandle )
00208 {
00209         imageEffect::OfxhImageEffectNodeBase* effectBase = reinterpret_cast<imageEffect::OfxhImageEffectNodeBase*>( instanceHandle );
00210         imageEffect::OfxhImageEffectNode* effectInstance = reinterpret_cast<imageEffect::OfxhImageEffectNode*>( effectBase );
00211         OfxhMemory* memory;
00212 
00213         if( effectInstance )
00214         {
00215 
00216                 if( !effectInstance->verifyMagic() )
00217                 {
00218                         return kOfxStatErrBadHandle;
00219                 }
00220 
00221                 memory = effectInstance->imageMemoryAlloc( nBytes );
00222         }
00223         else
00224         {
00225                 memory = new OfxhMemory;
00226                 memory->alloc( nBytes );
00227         }
00228 
00229         *memoryHandle = memory->getHandle();
00230         return kOfxStatOK;
00231 }
00232 
00233 OfxStatus imageMemoryFree( OfxImageMemoryHandle memoryHandle )
00234 {
00235         OfxhMemory* memoryInstance = reinterpret_cast<OfxhMemory*>( memoryHandle );
00236 
00237         if( memoryInstance && memoryInstance->verifyMagic() )
00238         {
00239                 memoryInstance->freeMem();
00240                 delete memoryInstance;
00241                 return kOfxStatOK;
00242         }
00243         else
00244                 return kOfxStatErrBadHandle;
00245 }
00246 
00247 OfxStatus imageMemoryLock( OfxImageMemoryHandle memoryHandle,
00248                            void**               returnedPtr )
00249 {
00250         OfxhMemory* memoryInstance = reinterpret_cast<OfxhMemory*>( memoryHandle );
00251 
00252         if( memoryInstance && memoryInstance->verifyMagic() )
00253         {
00254                 memoryInstance->lock();
00255                 *returnedPtr = memoryInstance->getPtr();
00256                 return kOfxStatOK;
00257         }
00258 
00259         return kOfxStatErrBadHandle;
00260 }
00261 
00262 OfxStatus imageMemoryUnlock( OfxImageMemoryHandle memoryHandle )
00263 {
00264         OfxhMemory* memoryInstance = reinterpret_cast<OfxhMemory*>( memoryHandle );
00265 
00266         if( memoryInstance && memoryInstance->verifyMagic() )
00267         {
00268                 memoryInstance->unlock();
00269                 return kOfxStatOK;
00270         }
00271 
00272         return kOfxStatErrBadHandle;
00273 }
00274 
00275 struct OfxImageEffectSuiteV1 gImageEffectSuite =
00276 {
00277         getPropertySet,
00278         getParamSet,
00279         clipDefine,
00280         clipGetHandle,
00281         clipGetPropertySet,
00282         clipGetImage,
00283         clipReleaseImage,
00284         clipGetRegionOfDefinition,
00285         abort,
00286         imageMemoryAlloc,
00287         imageMemoryFree,
00288         imageMemoryLock,
00289         imageMemoryUnlock
00290 };
00291 
00292 }
00293 
00294 void* getImageEffectSuite( const int version )
00295 {
00296         if( version == 1 )
00297                 return &gImageEffectSuite;
00298         return NULL;
00299 }
00300 
00301 }
00302 }
00303 }
00304 }
00305